Config: expand Kilo catalog and persist selected Kilo models (#24921)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: f5a7e1a385
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Gustavo Madeira Santana
2026-02-23 21:17:37 -05:00
committed by GitHub
parent 6c441ea797
commit 5239b55c0a
14 changed files with 668 additions and 21 deletions

View File

@@ -102,6 +102,34 @@ 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;
@@ -521,6 +549,66 @@ 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[],