chore(provider): remove unused pruning functions

This commit is contained in:
Gustavo Madeira Santana
2026-02-23 21:30:59 -05:00
parent 4032390572
commit 207ec7cfae
4 changed files with 4 additions and 162 deletions

View File

@@ -102,34 +102,6 @@ function normalizeModelKeys(values: string[]): string[] {
return next;
}
function splitModelKey(value: string): { provider: string; modelId: string } | null {
const key = String(value ?? "").trim();
const slashIndex = key.indexOf("/");
if (slashIndex <= 0 || slashIndex >= key.length - 1) {
return null;
}
const provider = normalizeProviderId(key.slice(0, slashIndex));
const modelId = key.slice(slashIndex + 1).trim();
if (!provider || !modelId) {
return null;
}
return { provider, modelId };
}
function selectedModelIdsByProvider(modelKeys: string[]): Map<string, Set<string>> {
const out = new Map<string, Set<string>>();
for (const key of modelKeys) {
const split = splitModelKey(key);
if (!split) {
continue;
}
const existing = out.get(split.provider) ?? new Set<string>();
existing.add(split.modelId.toLowerCase());
out.set(split.provider, existing);
}
return out;
}
function addModelSelectOption(params: {
entry: {
provider: string;
@@ -549,66 +521,6 @@ export function applyModelAllowlist(cfg: OpenClawConfig, models: string[]): Open
};
}
export function pruneKilocodeProviderModelsToAllowlist(
cfg: OpenClawConfig,
selectedModels: string[],
): OpenClawConfig {
const normalized = normalizeModelKeys(selectedModels);
if (normalized.length === 0) {
return cfg;
}
const providers = cfg.models?.providers;
if (!providers) {
return cfg;
}
const selectedByProvider = selectedModelIdsByProvider(normalized);
// Keep this scoped to Kilo Gateway: do not mutate other providers here.
const selectedKilocodeIds = selectedByProvider.get("kilocode");
if (!selectedKilocodeIds || selectedKilocodeIds.size === 0) {
return cfg;
}
let mutated = false;
const nextProviders: NonNullable<OpenClawConfig["models"]>["providers"] = { ...providers };
for (const [providerIdRaw, providerConfig] of Object.entries(providers)) {
if (!providerConfig || !Array.isArray(providerConfig.models)) {
continue;
}
const providerId = normalizeProviderId(providerIdRaw);
if (providerId !== "kilocode") {
continue;
}
const filteredModels = providerConfig.models.filter((model) =>
selectedKilocodeIds.has(
String(model.id ?? "")
.trim()
.toLowerCase(),
),
);
if (filteredModels.length === providerConfig.models.length) {
continue;
}
mutated = true;
nextProviders[providerIdRaw] = {
...providerConfig,
models: filteredModels,
};
}
if (!mutated) {
return cfg;
}
return {
...cfg,
models: {
mode: cfg.models?.mode ?? "merge",
providers: nextProviders,
},
};
}
export function applyModelFallbacksFromSelection(
cfg: OpenClawConfig,
selection: string[],