fix(google): guard realtime browser session expiries · openclaw/openclaw@7ad2ebb
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -100,6 +100,7 @@ describe("buildGoogleRealtimeVoiceProvider", () => {
|
100 | 100 | |
101 | 101 | afterEach(() => { |
102 | 102 | vi.useRealTimers(); |
| 103 | +vi.restoreAllMocks(); |
103 | 104 | for (const key of ENV_KEYS) { |
104 | 105 | const value = envSnapshot[key]; |
105 | 106 | if (value === undefined) { |
@@ -452,6 +453,20 @@ describe("buildGoogleRealtimeVoiceProvider", () => {
|
452 | 453 | ]); |
453 | 454 | }); |
454 | 455 | |
| 456 | +it("rejects browser session expiry outside Date range", async () => { |
| 457 | +vi.spyOn(Date, "now").mockReturnValue(8_640_000_000_000_001); |
| 458 | +const provider = buildGoogleRealtimeVoiceProvider(); |
| 459 | + |
| 460 | +await expect( |
| 461 | +provider.createBrowserSession?.({ |
| 462 | +providerConfig: { |
| 463 | +apiKey: "gemini-key", |
| 464 | +}, |
| 465 | +}), |
| 466 | +).rejects.toThrow("Google realtime browser session expiry is outside the supported Date range"); |
| 467 | +expect(createTokenMock).not.toHaveBeenCalled(); |
| 468 | +}); |
| 469 | + |
455 | 470 | it("can opt out of Google Live session resumption and context compression", async () => { |
456 | 471 | const provider = buildGoogleRealtimeVoiceProvider(); |
457 | 472 | const bridge = provider.createBridge({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ import type {
|
16 | 16 | ThinkingConfig, |
17 | 17 | TurnCoverage, |
18 | 18 | } from "@google/genai"; |
| 19 | +import { timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime"; |
19 | 20 | import type { OpenClawConfig } from "openclaw/plugin-sdk/provider-onboard"; |
20 | 21 | import type { |
21 | 22 | RealtimeVoiceAudioFormat, |
@@ -857,6 +858,11 @@ async function createGoogleRealtimeBrowserSession(
|
857 | 858 | const voice = req.voice ?? config.voice ?? GOOGLE_REALTIME_DEFAULT_VOICE; |
858 | 859 | const expiresAtMs = Date.now() + GOOGLE_REALTIME_BROWSER_SESSION_TTL_MS; |
859 | 860 | const newSessionExpiresAtMs = Date.now() + GOOGLE_REALTIME_BROWSER_NEW_SESSION_TTL_MS; |
| 861 | +const expireTime = timestampMsToIsoString(expiresAtMs); |
| 862 | +const newSessionExpireTime = timestampMsToIsoString(newSessionExpiresAtMs); |
| 863 | +if (!expireTime || !newSessionExpireTime) { |
| 864 | +throw new Error("Google realtime browser session expiry is outside the supported Date range"); |
| 865 | +} |
860 | 866 | const ai = createGoogleGenAI({ |
861 | 867 | apiKey, |
862 | 868 | httpOptions: { |
@@ -866,8 +872,8 @@ async function createGoogleRealtimeBrowserSession(
|
866 | 872 | const token = await ai.authTokens.create({ |
867 | 873 | config: { |
868 | 874 | uses: 1, |
869 | | -expireTime: new Date(expiresAtMs).toISOString(), |
870 | | -newSessionExpireTime: new Date(newSessionExpiresAtMs).toISOString(), |
| 875 | + expireTime, |
| 876 | + newSessionExpireTime, |
871 | 877 | liveConnectConstraints: { |
872 | 878 | model, |
873 | 879 | config: buildGoogleLiveConnectConfig({ |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。