chore(provider): remove unused pruning functions
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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[],
|
||||
|
||||
Reference in New Issue
Block a user