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

@@ -0,0 +1,131 @@
import { describe, expect, it, vi } from "vitest";
import type { RuntimeEnv } from "../runtime.js";
import type { WizardPrompter } from "../wizard/prompts.js";
const mocks = vi.hoisted(() => ({
promptAuthChoiceGrouped: vi.fn(),
applyAuthChoice: vi.fn(),
promptModelAllowlist: vi.fn(),
promptDefaultModel: vi.fn(),
promptCustomApiConfig: vi.fn(),
}));
vi.mock("../agents/auth-profiles.js", () => ({
ensureAuthProfileStore: vi.fn(() => ({
version: 1,
profiles: {},
})),
}));
vi.mock("./auth-choice-prompt.js", () => ({
promptAuthChoiceGrouped: mocks.promptAuthChoiceGrouped,
}));
vi.mock("./auth-choice.js", () => ({
applyAuthChoice: mocks.applyAuthChoice,
resolvePreferredProviderForAuthChoice: vi.fn(() => undefined),
}));
vi.mock("./model-picker.js", async (importActual) => {
const actual = await importActual<typeof import("./model-picker.js")>();
return {
...actual,
promptModelAllowlist: mocks.promptModelAllowlist,
promptDefaultModel: mocks.promptDefaultModel,
};
});
vi.mock("./onboard-custom.js", () => ({
promptCustomApiConfig: mocks.promptCustomApiConfig,
}));
import { promptAuthConfig } from "./configure.gateway-auth.js";
function makeRuntime(): RuntimeEnv {
return {
log: vi.fn(),
error: vi.fn(),
exit: vi.fn(),
};
}
const noopPrompter = {} as WizardPrompter;
describe("promptAuthConfig", () => {
it("prunes Kilo provider models to selected allowlist entries", async () => {
mocks.promptAuthChoiceGrouped.mockResolvedValue("kilocode-api-key");
mocks.applyAuthChoice.mockResolvedValue({
config: {
agents: {
defaults: {
model: { primary: "kilocode/anthropic/claude-opus-4.6" },
},
},
models: {
providers: {
kilocode: {
baseUrl: "https://api.kilo.ai/api/gateway/",
api: "openai-completions",
models: [
{ id: "anthropic/claude-opus-4.6", name: "Claude Opus 4.6" },
{ id: "minimax/minimax-m2.5:free", name: "MiniMax M2.5 (Free)" },
],
},
},
},
},
});
mocks.promptModelAllowlist.mockResolvedValue({
models: ["kilocode/anthropic/claude-opus-4.6"],
});
const result = await promptAuthConfig({}, makeRuntime(), noopPrompter);
expect(result.models?.providers?.kilocode?.models?.map((model) => model.id)).toEqual([
"anthropic/claude-opus-4.6",
]);
expect(Object.keys(result.agents?.defaults?.models ?? {})).toEqual([
"kilocode/anthropic/claude-opus-4.6",
]);
});
it("does not mutate non-Kilo provider models when allowlist contains Kilo entries", async () => {
mocks.promptAuthChoiceGrouped.mockResolvedValue("kilocode-api-key");
mocks.applyAuthChoice.mockResolvedValue({
config: {
agents: {
defaults: {
model: { primary: "kilocode/anthropic/claude-opus-4.6" },
},
},
models: {
providers: {
kilocode: {
baseUrl: "https://api.kilo.ai/api/gateway/",
api: "openai-completions",
models: [
{ id: "anthropic/claude-opus-4.6", name: "Claude Opus 4.6" },
{ id: "minimax/minimax-m2.5:free", name: "MiniMax M2.5 (Free)" },
],
},
minimax: {
baseUrl: "https://api.minimax.io/anthropic",
api: "anthropic-messages",
models: [{ id: "MiniMax-M2.1", name: "MiniMax M2.1" }],
},
},
},
},
});
mocks.promptModelAllowlist.mockResolvedValue({
models: ["kilocode/anthropic/claude-opus-4.6"],
});
const result = await promptAuthConfig({}, makeRuntime(), noopPrompter);
expect(result.models?.providers?.kilocode?.models?.map((model) => model.id)).toEqual([
"anthropic/claude-opus-4.6",
]);
expect(result.models?.providers?.minimax?.models?.map((model) => model.id)).toEqual([
"MiniMax-M2.1",
]);
});
});

View File

@@ -8,6 +8,7 @@ import {
applyModelAllowlist,
applyModelFallbacksFromSelection,
applyPrimaryModel,
pruneKilocodeProviderModelsToAllowlist,
promptDefaultModel,
promptModelAllowlist,
} from "./model-picker.js";
@@ -126,6 +127,7 @@ export async function promptAuthConfig(
});
if (allowlistSelection.models) {
next = applyModelAllowlist(next, allowlistSelection.models);
next = pruneKilocodeProviderModelsToAllowlist(next, allowlistSelection.models);
next = applyModelFallbacksFromSelection(next, allowlistSelection.models);
}
}

View File

@@ -3,6 +3,7 @@ import type { OpenClawConfig } from "../config/config.js";
import {
applyModelAllowlist,
applyModelFallbacksFromSelection,
pruneKilocodeProviderModelsToAllowlist,
promptDefaultModel,
promptModelAllowlist,
} from "./model-picker.js";
@@ -60,6 +61,18 @@ function createSelectAllMultiselect() {
return vi.fn(async (params) => params.options.map((option: { value: string }) => option.value));
}
function makeProviderModel(id: string, name: string) {
return {
id,
name,
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 200000,
maxTokens: 8192,
};
}
describe("promptDefaultModel", () => {
it("supports configuring vLLM during onboarding", async () => {
loadModelCatalog.mockResolvedValue([
@@ -249,3 +262,60 @@ describe("applyModelFallbacksFromSelection", () => {
});
});
});
describe("pruneKilocodeProviderModelsToAllowlist", () => {
it("keeps only selected model definitions in provider configs", () => {
const config = {
models: {
providers: {
kilocode: {
baseUrl: "https://api.kilo.ai/api/gateway/",
api: "openai-completions",
models: [
makeProviderModel("anthropic/claude-opus-4.6", "Claude Opus 4.6"),
makeProviderModel("minimax/minimax-m2.5:free", "MiniMax M2.5 (Free)"),
],
},
},
},
} as OpenClawConfig;
const next = pruneKilocodeProviderModelsToAllowlist(config, [
"kilocode/anthropic/claude-opus-4.6",
]);
expect(next.models?.providers?.kilocode?.models?.map((model) => model.id)).toEqual([
"anthropic/claude-opus-4.6",
]);
});
it("does not modify non-kilo provider model catalogs", () => {
const config = {
models: {
providers: {
kilocode: {
baseUrl: "https://api.kilo.ai/api/gateway/",
api: "openai-completions",
models: [makeProviderModel("anthropic/claude-opus-4.6", "Claude Opus 4.6")],
},
minimax: {
baseUrl: "https://api.minimax.io/anthropic",
api: "anthropic-messages",
models: [makeProviderModel("MiniMax-M2.5", "MiniMax M2.5")],
},
},
},
} as OpenClawConfig;
const next = pruneKilocodeProviderModelsToAllowlist(config, [
"kilocode/anthropic/claude-opus-4.6",
]);
expect(next.models?.providers?.kilocode?.models?.map((model) => model.id)).toEqual([
"anthropic/claude-opus-4.6",
]);
expect(next.models?.providers?.minimax?.models?.map((model) => model.id)).toEqual([
"MiniMax-M2.5",
]);
});
});

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[],

View File

@@ -21,6 +21,17 @@ import {
} from "./onboard-auth.models.js";
const emptyCfg: OpenClawConfig = {};
const KILOCODE_MODEL_IDS = [
"anthropic/claude-opus-4.6",
"z-ai/glm-5:free",
"minimax/minimax-m2.5:free",
"anthropic/claude-sonnet-4.5",
"openai/gpt-5.2",
"google/gemini-3-pro-preview",
"google/gemini-3-flash-preview",
"x-ai/grok-code-fast-1",
"moonshotai/kimi-k2.5",
];
describe("Kilo Gateway provider config", () => {
describe("constants", () => {
@@ -68,6 +79,33 @@ describe("Kilo Gateway provider config", () => {
expect(modelIds).toContain(KILOCODE_DEFAULT_MODEL_ID);
});
it("surfaces the full Kilo model catalog", () => {
const result = applyKilocodeProviderConfig(emptyCfg);
const provider = result.models?.providers?.kilocode;
const modelIds = provider?.models?.map((m) => m.id) ?? [];
for (const modelId of KILOCODE_MODEL_IDS) {
expect(modelIds).toContain(modelId);
}
});
it("appends missing catalog models to existing Kilo provider config", () => {
const result = applyKilocodeProviderConfig({
models: {
providers: {
kilocode: {
baseUrl: KILOCODE_BASE_URL,
api: "openai-completions",
models: [buildKilocodeModelDefinition()],
},
},
},
});
const modelIds = result.models?.providers?.kilocode?.models?.map((m) => m.id) ?? [];
for (const modelId of KILOCODE_MODEL_IDS) {
expect(modelIds).toContain(modelId);
}
});
it("sets Kilo Gateway alias in agent default models", () => {
const result = applyKilocodeProviderConfig(emptyCfg);
const agentModel = result.agents?.defaults?.models?.[KILOCODE_DEFAULT_MODEL_REF];

View File

@@ -4,6 +4,7 @@ import {
HUGGINGFACE_MODEL_CATALOG,
} from "../agents/huggingface-models.js";
import {
buildKilocodeProvider,
buildKimiCodingProvider,
buildQianfanProvider,
buildXiaomiProvider,
@@ -60,12 +61,10 @@ import {
applyProviderConfigWithModelCatalog,
} from "./onboard-auth.config-shared.js";
import {
buildKilocodeModelDefinition,
buildMistralModelDefinition,
buildZaiModelDefinition,
buildMoonshotModelDefinition,
buildXaiModelDefinition,
KILOCODE_DEFAULT_MODEL_ID,
MISTRAL_BASE_URL,
MISTRAL_DEFAULT_MODEL_ID,
QIANFAN_BASE_URL,
@@ -447,15 +446,14 @@ export function applyKilocodeProviderConfig(cfg: OpenClawConfig): OpenClawConfig
alias: models[KILOCODE_DEFAULT_MODEL_REF]?.alias ?? "Kilo Gateway",
};
const defaultModel = buildKilocodeModelDefinition();
const kilocodeModels = buildKilocodeProvider().models ?? [];
return applyProviderConfigWithDefaultModel(cfg, {
return applyProviderConfigWithModelCatalog(cfg, {
agentModels: models,
providerId: "kilocode",
api: "openai-completions",
baseUrl: KILOCODE_BASE_URL,
defaultModel,
defaultModelId: KILOCODE_DEFAULT_MODEL_ID,
catalogModels: kilocodeModels,
});
}