mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 16:14:05 +00:00
fix(google): bound realtime browser session expiry
This commit is contained in:
@@ -467,6 +467,20 @@ describe("buildGoogleRealtimeVoiceProvider", () => {
|
||||
expect(createTokenMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects browser session creation while the process clock is invalid", async () => {
|
||||
vi.spyOn(Date, "now").mockReturnValue(Number.NaN);
|
||||
const provider = buildGoogleRealtimeVoiceProvider();
|
||||
|
||||
await expect(
|
||||
provider.createBrowserSession?.({
|
||||
providerConfig: {
|
||||
apiKey: "gemini-key",
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("Google realtime browser session expiry is outside the supported Date range");
|
||||
expect(createTokenMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("can opt out of Google Live session resumption and context compression", async () => {
|
||||
const provider = buildGoogleRealtimeVoiceProvider();
|
||||
const bridge = provider.createBridge({
|
||||
|
||||
@@ -16,7 +16,10 @@ import type {
|
||||
ThinkingConfig,
|
||||
TurnCoverage,
|
||||
} from "@google/genai";
|
||||
import { timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
|
||||
import {
|
||||
resolveExpiresAtMsFromDurationMs,
|
||||
timestampMsToIsoString,
|
||||
} from "openclaw/plugin-sdk/number-runtime";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/provider-onboard";
|
||||
import type {
|
||||
RealtimeVoiceAudioFormat,
|
||||
@@ -856,11 +859,17 @@ async function createGoogleRealtimeBrowserSession(
|
||||
|
||||
const model = req.model ?? config.model ?? GOOGLE_REALTIME_DEFAULT_MODEL;
|
||||
const voice = req.voice ?? config.voice ?? GOOGLE_REALTIME_DEFAULT_VOICE;
|
||||
const expiresAtMs = Date.now() + GOOGLE_REALTIME_BROWSER_SESSION_TTL_MS;
|
||||
const newSessionExpiresAtMs = Date.now() + GOOGLE_REALTIME_BROWSER_NEW_SESSION_TTL_MS;
|
||||
const nowMs = Date.now();
|
||||
const expiresAtMs = resolveExpiresAtMsFromDurationMs(GOOGLE_REALTIME_BROWSER_SESSION_TTL_MS, {
|
||||
nowMs,
|
||||
});
|
||||
const newSessionExpiresAtMs = resolveExpiresAtMsFromDurationMs(
|
||||
GOOGLE_REALTIME_BROWSER_NEW_SESSION_TTL_MS,
|
||||
{ nowMs },
|
||||
);
|
||||
const expireTime = timestampMsToIsoString(expiresAtMs);
|
||||
const newSessionExpireTime = timestampMsToIsoString(newSessionExpiresAtMs);
|
||||
if (!expireTime || !newSessionExpireTime) {
|
||||
if (expiresAtMs === undefined || !expireTime || !newSessionExpireTime) {
|
||||
throw new Error("Google realtime browser session expiry is outside the supported Date range");
|
||||
}
|
||||
const ai = createGoogleGenAI({
|
||||
|
||||
Reference in New Issue
Block a user