fix: validate lmstudio configured token metadata · openclaw/openclaw@4287cd2
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ import {
|
10 | 10 | fetchLmstudioModels, |
11 | 11 | } from "./models.fetch.js"; |
12 | 12 | import { |
| 13 | +normalizeLmstudioConfiguredCatalogEntry, |
13 | 14 | normalizeLmstudioProviderConfig, |
14 | 15 | resolveLmstudioInferenceBase, |
15 | 16 | resolveLmstudioReasoningCompat, |
@@ -133,6 +134,32 @@ describe("lmstudio-models", () => {
|
133 | 134 | }); |
134 | 135 | }); |
135 | 136 | |
| 137 | +it("drops malformed configured catalog token metadata", () => { |
| 138 | +expect( |
| 139 | +normalizeLmstudioConfiguredCatalogEntry({ |
| 140 | +id: "bad-window", |
| 141 | +contextWindow: Number.POSITIVE_INFINITY, |
| 142 | +contextTokens: 4096.5, |
| 143 | +}), |
| 144 | +).toMatchObject({ |
| 145 | +id: "bad-window", |
| 146 | +contextWindow: undefined, |
| 147 | +contextTokens: undefined, |
| 148 | +}); |
| 149 | + |
| 150 | +expect( |
| 151 | +normalizeLmstudioConfiguredCatalogEntry({ |
| 152 | +id: "bad-tokens", |
| 153 | +contextWindow: -1, |
| 154 | +contextTokens: 0, |
| 155 | +}), |
| 156 | +).toMatchObject({ |
| 157 | +id: "bad-tokens", |
| 158 | +contextWindow: undefined, |
| 159 | +contextTokens: undefined, |
| 160 | +}); |
| 161 | +}); |
| 162 | + |
136 | 163 | it("resolves reasoning capability for supported and unsupported options", () => { |
137 | 164 | expect(resolveLmstudioReasoningCapability({ capabilities: undefined })).toBe(false); |
138 | 165 | expect( |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ import {
|
7 | 7 | SELF_HOSTED_DEFAULT_COST, |
8 | 8 | SELF_HOSTED_DEFAULT_MAX_TOKENS, |
9 | 9 | } from "openclaw/plugin-sdk/provider-setup"; |
10 | | -import { uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime"; |
| 10 | +import { asPositiveSafeInteger, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime"; |
11 | 11 | import { LMSTUDIO_DEFAULT_BASE_URL, LMSTUDIO_DEFAULT_LOAD_CONTEXT_LENGTH } from "./defaults.js"; |
12 | 12 | |
13 | 13 | export type LmstudioModelWire = { |
@@ -365,14 +365,8 @@ export function normalizeLmstudioConfiguredCatalogEntry(
|
365 | 365 | } |
366 | 366 | const id = record.id.trim(); |
367 | 367 | const name = typeof record.name === "string" && record.name.trim().length > 0 ? record.name : id; |
368 | | -const contextWindow = |
369 | | -typeof record.contextWindow === "number" && record.contextWindow > 0 |
370 | | - ? record.contextWindow |
371 | | - : undefined; |
372 | | -const contextTokens = |
373 | | -typeof record.contextTokens === "number" && record.contextTokens > 0 |
374 | | - ? record.contextTokens |
375 | | - : undefined; |
| 368 | +const contextWindow = asPositiveSafeInteger(record.contextWindow); |
| 369 | +const contextTokens = asPositiveSafeInteger(record.contextTokens); |
376 | 370 | const reasoning = typeof record.reasoning === "boolean" ? record.reasoning : undefined; |
377 | 371 | const input = Array.isArray(record.input) |
378 | 372 | ? record.input.filter( |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。