fix: validate google live thinking budget · openclaw/openclaw@22515ee
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -329,6 +329,38 @@ describe("buildGoogleRealtimeVoiceProvider", () => {
|
329 | 329 | expect(lastConnectParams().config).not.toHaveProperty("realtimeInputConfig"); |
330 | 330 | }); |
331 | 331 | |
| 332 | +it("drops malformed thinking budgets before connecting", async () => { |
| 333 | +const provider = buildGoogleRealtimeVoiceProvider(); |
| 334 | +const bridge = provider.createBridge({ |
| 335 | +providerConfig: { |
| 336 | +apiKey: "gemini-key", |
| 337 | +thinkingBudget: 24_576.5, |
| 338 | +}, |
| 339 | +onAudio: vi.fn(), |
| 340 | +onClearAudio: vi.fn(), |
| 341 | +}); |
| 342 | + |
| 343 | +await bridge.connect(); |
| 344 | + |
| 345 | +expect(lastConnectParams().config).not.toHaveProperty("thinkingConfig"); |
| 346 | +}); |
| 347 | + |
| 348 | +it("passes Google Live dynamic thinking budget through", async () => { |
| 349 | +const provider = buildGoogleRealtimeVoiceProvider(); |
| 350 | +const bridge = provider.createBridge({ |
| 351 | +providerConfig: { |
| 352 | +apiKey: "gemini-key", |
| 353 | +thinkingBudget: -1, |
| 354 | +}, |
| 355 | +onAudio: vi.fn(), |
| 356 | +onClearAudio: vi.fn(), |
| 357 | +}); |
| 358 | + |
| 359 | +await bridge.connect(); |
| 360 | + |
| 361 | +expect(lastConnectParams().config.thinkingConfig).toEqual({ thinkingBudget: -1 }); |
| 362 | +}); |
| 363 | + |
332 | 364 | it("creates constrained browser sessions for Google Live Talk", async () => { |
333 | 365 | const provider = buildGoogleRealtimeVoiceProvider(); |
334 | 366 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -184,6 +184,15 @@ function asNonNegativeInteger(value: unknown): number | undefined {
|
184 | 184 | return number !== undefined && Number.isSafeInteger(number) && number >= 0 ? number : undefined; |
185 | 185 | } |
186 | 186 | |
| 187 | +function asGoogleRealtimeThinkingBudget(value: unknown): number | undefined { |
| 188 | +const budget = asFiniteNumber(value); |
| 189 | +return budget !== undefined && |
| 190 | +Number.isSafeInteger(budget) && |
| 191 | +(budget === -1 || (budget >= 0 && budget <= 24_576)) |
| 192 | + ? budget |
| 193 | + : undefined; |
| 194 | +} |
| 195 | + |
187 | 196 | function resolveGoogleRealtimeProviderConfigRecord( |
188 | 197 | config: Record<string, unknown>, |
189 | 198 | ): Record<string, unknown> | undefined { |
@@ -226,7 +235,7 @@ function normalizeProviderConfig(
|
226 | 235 | sessionResumption: asBoolean(raw?.sessionResumption), |
227 | 236 | contextWindowCompression: asBoolean(raw?.contextWindowCompression), |
228 | 237 | thinkingLevel: asThinkingLevel(raw?.thinkingLevel), |
229 | | -thinkingBudget: asFiniteNumber(raw?.thinkingBudget), |
| 238 | +thinkingBudget: asGoogleRealtimeThinkingBudget(raw?.thinkingBudget), |
230 | 239 | }; |
231 | 240 | } |
232 | 241 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。