fix: validate kilocode model token metadata · openclaw/openclaw@aa09f44
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -239,6 +239,40 @@ describe("discoverKilocodeModels (fetch path)", () => {
|
239 | 239 | } |
240 | 240 | }); |
241 | 241 | |
| 242 | +it("falls back from malformed live token metadata", async () => { |
| 243 | +const mockFetch = vi.fn().mockResolvedValue({ |
| 244 | +ok: true, |
| 245 | +json: () => |
| 246 | +Promise.resolve({ |
| 247 | +data: [ |
| 248 | +makeGatewayModel({ |
| 249 | +id: "some/bad-window", |
| 250 | +context_length: -1, |
| 251 | +top_provider: { max_completion_tokens: 8192.5 }, |
| 252 | +}), |
| 253 | +makeGatewayModel({ |
| 254 | +id: "some/bad-output", |
| 255 | +context_length: Number.POSITIVE_INFINITY, |
| 256 | +top_provider: { max_completion_tokens: 0 }, |
| 257 | +}), |
| 258 | +], |
| 259 | +}), |
| 260 | +}); |
| 261 | + |
| 262 | +await withFetchPathTest(mockFetch, async () => { |
| 263 | +const models = await discoverKilocodeModels(); |
| 264 | + |
| 265 | +expect(requireModelById(models, "some/bad-window")).toMatchObject({ |
| 266 | +contextWindow: 1000000, |
| 267 | +maxTokens: 128000, |
| 268 | +}); |
| 269 | +expect(requireModelById(models, "some/bad-output")).toMatchObject({ |
| 270 | +contextWindow: 1000000, |
| 271 | +maxTokens: 128000, |
| 272 | +}); |
| 273 | +}); |
| 274 | +}); |
| 275 | + |
242 | 276 | it("ensures kilo/auto is present even when API doesn't return it", async () => { |
243 | 277 | const mockFetch = vi.fn().mockResolvedValue({ |
244 | 278 | ok: true, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,10 @@ import {
|
5 | 5 | fetchWithSsrFGuard, |
6 | 6 | ssrfPolicyFromHttpBaseUrlAllowedHostname, |
7 | 7 | } from "openclaw/plugin-sdk/ssrf-runtime"; |
8 | | -import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime"; |
| 8 | +import { |
| 9 | +asPositiveSafeInteger, |
| 10 | +normalizeLowercaseStringOrEmpty, |
| 11 | +} from "openclaw/plugin-sdk/string-coerce-runtime"; |
9 | 12 | |
10 | 13 | const log = createSubsystemLogger("kilocode-models"); |
11 | 14 | |
@@ -113,8 +116,10 @@ function toModelDefinition(entry: GatewayModelEntry): ModelDefinitionConfig {
|
113 | 116 | cacheRead: toPricePerMillion(entry.pricing.input_cache_read), |
114 | 117 | cacheWrite: toPricePerMillion(entry.pricing.input_cache_write), |
115 | 118 | }, |
116 | | -contextWindow: entry.context_length || KILOCODE_DEFAULT_CONTEXT_WINDOW, |
117 | | -maxTokens: entry.top_provider?.max_completion_tokens ?? KILOCODE_DEFAULT_MAX_TOKENS, |
| 119 | +contextWindow: asPositiveSafeInteger(entry.context_length) ?? KILOCODE_DEFAULT_CONTEXT_WINDOW, |
| 120 | +maxTokens: |
| 121 | +asPositiveSafeInteger(entry.top_provider?.max_completion_tokens) ?? |
| 122 | +KILOCODE_DEFAULT_MAX_TOKENS, |
118 | 123 | }; |
119 | 124 | } |
120 | 125 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。