Skip to content

Commit 3c23457

Browse files
authored
fix(kilocode): restore known default router pricing (#129546)
1 parent a8d5350 commit 3c23457

2 files changed

Lines changed: 73 additions & 11 deletions

File tree

‎extensions/kilocode/provider-models.test.ts‎

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({
1313
}),
1414
}));
1515

16-
import { discoverKilocodeModels, KILOCODE_MODELS_URL } from "./provider-models.js";
16+
import {
17+
discoverKilocodeModels,
18+
KILOCODE_DEFAULT_COST,
19+
KILOCODE_MODELS_URL,
20+
} from "./provider-models.js";
1721

1822
type MockKilocodeFetch = ((url: string, init?: RequestInit) => Promise<Response>) & {
1923
mock: { calls: unknown[][] };
@@ -188,6 +192,69 @@ describe("discoverKilocodeModels (fetch path)", () => {
188192
});
189193
});
190194

195+
it.each([
196+
{
197+
label: "negative routing rates with missing cache prices",
198+
pricing: { prompt: "-1", completion: "-1" },
199+
cacheRead: 0,
200+
cacheWrite: 0,
201+
},
202+
{
203+
label: "unknown routing rates with valid cache prices",
204+
pricing: {
205+
prompt: "unavailable",
206+
completion: "-1",
207+
input_cache_read: "0.0000003",
208+
input_cache_write: "0.00000375",
209+
},
210+
cacheRead: 0.3,
211+
cacheWrite: 3.75,
212+
},
213+
])(
214+
"preserves known default-model pricing for $label",
215+
async ({ pricing, cacheRead, cacheWrite }) => {
216+
const mockFetch = vi.fn().mockResolvedValue(
217+
jsonResponse({
218+
data: [
219+
makeAutoModel({ pricing }),
220+
makeGatewayModel({
221+
id: "kilo-auto/frontier",
222+
pricing: { prompt: "-1", completion: "-1" },
223+
}),
224+
makeGatewayModel({
225+
id: "kilo-auto/free",
226+
pricing: {
227+
prompt: "0",
228+
completion: "0",
229+
input_cache_read: "0",
230+
input_cache_write: "0",
231+
},
232+
}),
233+
],
234+
}),
235+
);
236+
237+
await withFetchPathTest(mockFetch, async () => {
238+
const models = await discoverKilocodeModels();
239+
240+
expect(requireModelById(models, "kilo-auto/balanced").cost).toEqual({
241+
input: KILOCODE_DEFAULT_COST.input,
242+
output: KILOCODE_DEFAULT_COST.output,
243+
cacheRead,
244+
cacheWrite,
245+
});
246+
for (const id of ["kilo-auto/frontier", "kilo-auto/free"]) {
247+
expect(requireModelById(models, id).cost).toEqual({
248+
input: 0,
249+
output: 0,
250+
cacheRead: 0,
251+
cacheWrite: 0,
252+
});
253+
}
254+
});
255+
},
256+
);
257+
191258
it("falls back to static catalog on network error", async () => {
192259
const mockFetch = vi.fn().mockRejectedValue(new Error("network error"));
193260
await withFetchPathTest(mockFetch, async () => {

‎extensions/kilocode/provider-models.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,9 @@ interface GatewayModelEntry {
7070
supported_parameters?: string[];
7171
}
7272

73-
function toPricePerMillion(perToken: string | undefined): number {
74-
if (!perToken) {
75-
return 0;
76-
}
73+
function toPricePerMillion(perToken: string | undefined, fallback = 0): number {
7774
const num = Number(perToken);
78-
if (!Number.isFinite(num) || num < 0) {
79-
return 0;
80-
}
81-
return num * 1_000_000;
75+
return Number.isFinite(num) && num >= 0 ? num * 1_000_000 : fallback;
8276
}
8377

8478
function parseModality(entry: GatewayModelEntry): Array<"text" | "image"> {
@@ -101,14 +95,15 @@ function parseReasoning(entry: GatewayModelEntry): boolean {
10195
}
10296

10397
function toModelDefinition(entry: GatewayModelEntry): ModelDefinitionConfig {
98+
const fallbackCost = entry.id === KILOCODE_DEFAULT_MODEL_ID ? KILOCODE_DEFAULT_COST : undefined;
10499
return {
105100
id: entry.id,
106101
name: entry.name || entry.id,
107102
reasoning: parseReasoning(entry),
108103
input: parseModality(entry),
109104
cost: {
110-
input: toPricePerMillion(entry.pricing.prompt),
111-
output: toPricePerMillion(entry.pricing.completion),
105+
input: toPricePerMillion(entry.pricing.prompt, fallbackCost?.input),
106+
output: toPricePerMillion(entry.pricing.completion, fallbackCost?.output),
112107
cacheRead: toPricePerMillion(entry.pricing.input_cache_read),
113108
cacheWrite: toPricePerMillion(entry.pricing.input_cache_write),
114109
},

0 commit comments

Comments
 (0)