From 207ec7cfae47b7da291adb6d0c673e8019af021f Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Mon, 23 Feb 2026 21:30:59 -0500 Subject: [PATCH] chore(provider): remove unused pruning functions --- ...re.gateway-auth.prompt-auth-config.test.ts | 6 +- src/commands/configure.gateway-auth.ts | 2 - src/commands/model-picker.test.ts | 70 --------------- src/commands/model-picker.ts | 88 ------------------- 4 files changed, 4 insertions(+), 162 deletions(-) diff --git a/src/commands/configure.gateway-auth.prompt-auth-config.test.ts b/src/commands/configure.gateway-auth.prompt-auth-config.test.ts index 26ebe1e3d..e866f92e5 100644 --- a/src/commands/configure.gateway-auth.prompt-auth-config.test.ts +++ b/src/commands/configure.gateway-auth.prompt-auth-config.test.ts @@ -52,7 +52,7 @@ function makeRuntime(): RuntimeEnv { const noopPrompter = {} as WizardPrompter; describe("promptAuthConfig", () => { - it("prunes Kilo provider models to selected allowlist entries", async () => { + it("keeps Kilo provider models while applying allowlist defaults", async () => { mocks.promptAuthChoiceGrouped.mockResolvedValue("kilocode-api-key"); mocks.applyAuthChoice.mockResolvedValue({ config: { @@ -82,13 +82,14 @@ describe("promptAuthConfig", () => { const result = await promptAuthConfig({}, makeRuntime(), noopPrompter); expect(result.models?.providers?.kilocode?.models?.map((model) => model.id)).toEqual([ "anthropic/claude-opus-4.6", + "minimax/minimax-m2.5:free", ]); 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 () => { + it("does not mutate provider model catalogs when allowlist is set", async () => { mocks.promptAuthChoiceGrouped.mockResolvedValue("kilocode-api-key"); mocks.applyAuthChoice.mockResolvedValue({ config: { @@ -123,6 +124,7 @@ describe("promptAuthConfig", () => { const result = await promptAuthConfig({}, makeRuntime(), noopPrompter); expect(result.models?.providers?.kilocode?.models?.map((model) => model.id)).toEqual([ "anthropic/claude-opus-4.6", + "minimax/minimax-m2.5:free", ]); expect(result.models?.providers?.minimax?.models?.map((model) => model.id)).toEqual([ "MiniMax-M2.1", diff --git a/src/commands/configure.gateway-auth.ts b/src/commands/configure.gateway-auth.ts index 479f9e7d8..d39f6ef62 100644 --- a/src/commands/configure.gateway-auth.ts +++ b/src/commands/configure.gateway-auth.ts @@ -8,7 +8,6 @@ import { applyModelAllowlist, applyModelFallbacksFromSelection, applyPrimaryModel, - pruneKilocodeProviderModelsToAllowlist, promptDefaultModel, promptModelAllowlist, } from "./model-picker.js"; @@ -127,7 +126,6 @@ export async function promptAuthConfig( }); if (allowlistSelection.models) { next = applyModelAllowlist(next, allowlistSelection.models); - next = pruneKilocodeProviderModelsToAllowlist(next, allowlistSelection.models); next = applyModelFallbacksFromSelection(next, allowlistSelection.models); } } diff --git a/src/commands/model-picker.test.ts b/src/commands/model-picker.test.ts index 7ea42e5d3..76ced67ba 100644 --- a/src/commands/model-picker.test.ts +++ b/src/commands/model-picker.test.ts @@ -3,7 +3,6 @@ import type { OpenClawConfig } from "../config/config.js"; import { applyModelAllowlist, applyModelFallbacksFromSelection, - pruneKilocodeProviderModelsToAllowlist, promptDefaultModel, promptModelAllowlist, } from "./model-picker.js"; @@ -61,18 +60,6 @@ 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([ @@ -262,60 +249,3 @@ 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", - ]); - }); -}); diff --git a/src/commands/model-picker.ts b/src/commands/model-picker.ts index c843d6372..db7942103 100644 --- a/src/commands/model-picker.ts +++ b/src/commands/model-picker.ts @@ -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> { - const out = new Map>(); - for (const key of modelKeys) { - const split = splitModelKey(key); - if (!split) { - continue; - } - const existing = out.get(split.provider) ?? new Set(); - 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["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[],