Skip to content

Commit a838c68

Browse files
steipeteshushushv
andauthored
feat(talk): add Gemini Live video (#109719)
Stream bounded browser camera frames directly to Gemini Live and keep camera media off the Gateway. Add lifecycle, function-calling, fake-camera E2E, and live-smoke coverage. Co-authored-by: shushushu <[email protected]>
1 parent 08987d8 commit a838c68

15 files changed

Lines changed: 914 additions & 163 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
f6306d8082be6dcde00435a02db2a5cf46f0983fccb8ed6a39a60f1931546fce plugin-sdk-api-baseline.json
2-
7c11aba346798e6db5be30a9b61141d1904a09764ea029656fd0fca79929df61 plugin-sdk-api-baseline.jsonl
1+
4440586f2797bc47ac5085d962feaab844d921acaba4e3b2f754c76f70a4f1a5 plugin-sdk-api-baseline.json
2+
88ab286e2484b5178a5447cd880372c773a11f3bf3a73a54759aa5bff55f5957 plugin-sdk-api-baseline.jsonl

‎docs/web/control-ui.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ The macOS app keeps its native link-browser sidebar for links clicked in the das
392392

393393
The Talk control itself is the microphone button in the composer toolbar. Its caret lists **System default** and every microphone exposed by the browser, including USB, Bluetooth, and virtual inputs. The selected device ID stays browser-local and is never sent to the Gateway; if that exact device disappears, Talk asks you to choose another input instead of silently recording from a different microphone. While Talk is live, the microphone button becomes a pill showing the live input-level meter; clicking it stops voice input, and hovering it reveals the stop glyph. Screen readers announce `Connecting voice input...`, `Listening...`, or `Asking OpenClaw...` while a realtime tool call is consulting the configured larger model through `talk.client.toolCall`. Stopping a running agent response stays a separate square **Stop** control next to the pill.
394394

395-
**Video Talk** is available for OpenAI Realtime WebRTC sessions. Click the camera button, allow camera and microphone access, and confirm the local preview. When the model needs visual context, `describe_view` captures one JPEG frame and sends it directly over the existing browser-to-OpenAI Realtime data channel; camera frames do not pass through the Gateway. Stopping Talk closes the preview and releases both media tracks. Google Live remains voice-only in the Control UI.
395+
**Video Talk** is available for OpenAI Realtime WebRTC and Google Live browser sessions. Click the camera button, allow camera and microphone access, and confirm the local preview. OpenAI sends one bounded JPEG frame over its browser data channel when `describe_view` requests visual context. Google Live sends bounded JPEG frames directly from the browser to the provider at the supported maximum of one frame per second and answers `describe_view` function calls with the camera-stream state. Camera frames never pass through the Gateway. Stopping Talk closes the preview and releases both media tracks. See Google's [Live API capabilities](https://ai.google.dev/gemini-api/docs/live-api/capabilities#video) and [function-calling guide](https://ai.google.dev/gemini-api/docs/live-api/tools) for the provider wire contracts.
396396

397-
Maintainer live smoke: `OPENAI_API_KEY=... GEMINI_API_KEY=... node --import tsx scripts/dev/realtime-talk-live-smoke.ts` verifies the OpenAI backend WebSocket bridge, OpenAI browser WebRTC SDP exchange, Google Live constrained-token browser WebSocket setup, and the Gateway relay browser adapter with fake microphone media. The command prints provider status only and does not log secrets.
397+
Maintainer live smoke: `OPENAI_API_KEY=... GEMINI_API_KEY=... node --import tsx scripts/dev/realtime-talk-live-smoke.ts` verifies the OpenAI backend WebSocket bridge, OpenAI browser WebRTC SDP exchange, Google Live constrained-token browser setup with a JPEG frame and `describe_view` function roundtrip, and the Gateway relay browser adapter with fake microphone media. The command prints provider status only and does not log secrets.
398398

399399
</Accordion>
400400
<Accordion title="Stop and abort">

‎extensions/openai/realtime-voice-provider.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ describe("buildOpenAIRealtimeVoiceProvider", () => {
304304
supportsBargeIn: true,
305305
handlesInputAudioBargeIn: true,
306306
supportsToolCalls: true,
307+
supportsVideoFrames: true,
307308
});
308309
});
309310

‎extensions/openai/realtime-voice-provider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ export function buildOpenAIRealtimeVoiceProvider(): RealtimeVoiceProviderPlugin
15601560
supportsBargeIn: true,
15611561
handlesInputAudioBargeIn: true,
15621562
supportsToolCalls: true,
1563+
supportsVideoFrames: true,
15631564
},
15641565
resolveConfig: ({ rawConfig }) => normalizeProviderConfig(rawConfig),
15651566
isConfigured: ({ cfg, providerConfig }) => {

‎scripts/dev/realtime-talk-live-smoke.ts‎

Lines changed: 118 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -450,54 +450,55 @@ async function smokeOpenAIWebRtc(browser: Browser, apiKey: string): Promise<Smok
450450
}
451451
}
452452

453-
async function createGoogleLiveToken(apiKey: string): Promise<string> {
454-
const { GoogleGenAI, Modality } = await import("@google/genai");
455-
const ai = new GoogleGenAI({
456-
apiKey,
457-
httpOptions: { apiVersion: "v1alpha" },
458-
});
459-
const now = Date.now();
460-
const token = await ai.authTokens.create({
461-
config: {
462-
uses: 1,
463-
expireTime: new Date(now + 30 * 60 * 1000).toISOString(),
464-
newSessionExpireTime: new Date(now + 60 * 1000).toISOString(),
465-
liveConnectConstraints: {
466-
model: GOOGLE_REALTIME_MODEL,
467-
config: {
468-
responseModalities: [Modality.AUDIO],
469-
speechConfig: {
470-
voiceConfig: {
471-
prebuiltVoiceConfig: { voiceName: GOOGLE_REALTIME_VOICE },
472-
},
473-
},
474-
systemInstruction: "OpenClaw browser Talk live smoke.",
475-
inputAudioTranscription: {},
476-
outputAudioTranscription: {},
477-
},
478-
},
479-
},
480-
});
481-
const name = token.name?.trim();
482-
if (!name) {
483-
throw new Error("Google Live auth token response did not include a token name");
484-
}
485-
return name;
486-
}
487-
488453
async function smokeGoogleLiveBrowserWs(browser: Browser, apiKey: string): Promise<SmokeResult> {
489454
try {
490-
const token = await createGoogleLiveToken(apiKey);
455+
const { REALTIME_VOICE_DESCRIBE_VIEW_TOOL } =
456+
await import("../../src/talk/describe-view-tool.ts");
457+
const { buildGoogleRealtimeVoiceProvider } =
458+
await import("../../extensions/google/realtime-voice-provider.ts");
459+
const provider = buildGoogleRealtimeVoiceProvider();
460+
const session = await provider.createBrowserSession?.({
461+
cfg: {},
462+
providerConfig: {
463+
apiKey,
464+
model: GOOGLE_REALTIME_MODEL,
465+
voice: GOOGLE_REALTIME_VOICE,
466+
},
467+
model: GOOGLE_REALTIME_MODEL,
468+
voice: GOOGLE_REALTIME_VOICE,
469+
instructions:
470+
"OpenClaw browser Video Talk live smoke. After receiving a visual frame and request, call describe_view exactly once.",
471+
tools: [REALTIME_VOICE_DESCRIBE_VIEW_TOOL],
472+
});
473+
if (
474+
!session ||
475+
session.transport !== "provider-websocket" ||
476+
session.protocol !== "google-live-bidi"
477+
) {
478+
throw new Error("Google Live provider did not create a browser WebSocket session");
479+
}
491480
const page = await browser.newPage();
492481
await page.evaluate("globalThis.__name = (fn) => fn");
493482
const result = await page.evaluate(
494-
async ({ model, tokenName, websocketUrl }) => {
483+
async ({
484+
initialMessage,
485+
tokenName,
486+
websocketUrl,
487+
}: {
488+
initialMessage: unknown;
489+
tokenName: string;
490+
websocketUrl: string;
491+
}) => {
495492
const debug: {
496493
opened: boolean;
497494
messages: string[];
498495
close?: { code: number; reason: string };
499496
error: boolean;
500497
} = { opened: false, messages: [], error: false };
498+
let setupComplete = false;
499+
let videoFrameSent = false;
500+
let describeViewCalled = false;
501+
let functionResponseSent = false;
501502
const dataToText = async (data: unknown): Promise<string> => {
502503
if (typeof data === "string") {
503504
return data;
@@ -520,27 +521,78 @@ async function smokeGoogleLiveBrowserWs(browser: Browser, apiKey: string): Promi
520521
);
521522
ws.addEventListener("open", () => {
522523
debug.opened = true;
523-
ws.send(
524-
JSON.stringify({
525-
setup: {
526-
model: model.startsWith("models/") ? model : `models/${model}`,
527-
generationConfig: { responseModalities: ["AUDIO"] },
528-
inputAudioTranscription: {},
529-
outputAudioTranscription: {},
530-
},
531-
}),
532-
);
524+
ws.send(JSON.stringify(initialMessage));
533525
});
534526
ws.addEventListener("message", (event) => {
535527
void (async () => {
536528
const text = await dataToText(event.data);
537529
debug.messages.push(text.slice(0, 300));
538-
const message = JSON.parse(text) as { setupComplete?: unknown };
539-
if (!message.setupComplete) {
530+
const message = JSON.parse(text) as {
531+
setupComplete?: unknown;
532+
serverContent?: unknown;
533+
toolCall?: {
534+
functionCalls?: Array<{ id?: string; name?: string }>;
535+
};
536+
};
537+
if (message.setupComplete) {
538+
setupComplete = true;
539+
const canvas = document.createElement("canvas");
540+
canvas.width = 8;
541+
canvas.height = 8;
542+
const context = canvas.getContext("2d");
543+
if (!context) {
544+
throw new Error("Google Live smoke could not create a camera fixture");
545+
}
546+
context.fillStyle = "#2f81f7";
547+
context.fillRect(0, 0, canvas.width, canvas.height);
548+
const frame = canvas.toDataURL("image/jpeg", 0.7).split(",")[1];
549+
if (!frame) {
550+
throw new Error("Google Live smoke camera fixture was empty");
551+
}
552+
ws.send(
553+
JSON.stringify({
554+
realtimeInput: { video: { data: frame, mimeType: "image/jpeg" } },
555+
}),
556+
);
557+
videoFrameSent = true;
558+
ws.send(
559+
JSON.stringify({
560+
realtimeInput: { text: "Call describe_view now for the visual frame." },
561+
}),
562+
);
540563
return;
541564
}
542-
window.clearTimeout(timeout);
543-
resolve({ setupComplete: true, readyState: ws.readyState });
565+
const describeView = message.toolCall?.functionCalls?.find(
566+
(call) => call.name === "describe_view" && call.id,
567+
);
568+
if (describeView?.id) {
569+
describeViewCalled = true;
570+
ws.send(
571+
JSON.stringify({
572+
toolResponse: {
573+
functionResponses: [
574+
{
575+
id: describeView.id,
576+
name: "describe_view",
577+
response: { ok: true, cameraStreamActive: true },
578+
},
579+
],
580+
},
581+
}),
582+
);
583+
functionResponseSent = true;
584+
return;
585+
}
586+
if (message.serverContent && functionResponseSent) {
587+
window.clearTimeout(timeout);
588+
resolve({
589+
setupComplete,
590+
videoFrameSent,
591+
describeViewCalled,
592+
functionResponseAccepted: true,
593+
readyState: ws.readyState,
594+
});
595+
}
544596
})().catch((error: unknown) => {
545597
window.clearTimeout(timeout);
546598
reject(toLintErrorObject(error, "Non-Error rejection"));
@@ -564,16 +616,26 @@ async function smokeGoogleLiveBrowserWs(browser: Browser, apiKey: string): Promi
564616
return value;
565617
},
566618
{
567-
model: GOOGLE_REALTIME_MODEL,
568-
tokenName: token,
569-
websocketUrl: GOOGLE_LIVE_WS_URL,
619+
initialMessage: session.initialMessage ?? { setup: {} },
620+
tokenName: session.clientSecret,
621+
websocketUrl: session.websocketUrl || GOOGLE_LIVE_WS_URL,
570622
},
571623
);
572624
await page.close();
573625
return {
574626
name: "google-live-browser-ws",
575-
ok: result.setupComplete === true,
576-
details: { model: GOOGLE_REALTIME_MODEL, setupComplete: result.setupComplete === true },
627+
ok:
628+
result.setupComplete === true &&
629+
result.videoFrameSent === true &&
630+
result.describeViewCalled === true &&
631+
result.functionResponseAccepted === true,
632+
details: {
633+
model: GOOGLE_REALTIME_MODEL,
634+
setupComplete: result.setupComplete === true,
635+
videoFrameSent: result.videoFrameSent === true,
636+
describeViewCalled: result.describeViewCalled === true,
637+
functionResponseAccepted: result.functionResponseAccepted === true,
638+
},
577639
};
578640
} catch (error) {
579641
return { name: "google-live-browser-ws", ok: false, details: { error: shortError(error) } };

‎src/gateway/server-methods/talk-client.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export const talkClientHandlers: GatewayRequestHandlers = {
9595
}
9696
const transport =
9797
normalizeOptionalLowercaseString(typedParams.transport) ?? realtimeConfig.transport;
98+
const wantsCameraFrames = typedParams.capabilities?.includes("camera-frame") === true;
9899
if (transport === "managed-room") {
99100
respond(
100101
false,
@@ -112,7 +113,9 @@ export const talkClientHandlers: GatewayRequestHandlers = {
112113
undefined,
113114
errorShape(
114115
ErrorCodes.INVALID_REQUEST,
115-
`talk.client.create is client-owned; use talk.session.create for gateway-relay`,
116+
wantsCameraFrames
117+
? "gateway-relay does not support browser video frames"
118+
: `talk.client.create is client-owned; use talk.session.create for gateway-relay`,
116119
),
117120
);
118121
return;
@@ -125,17 +128,24 @@ export const talkClientHandlers: GatewayRequestHandlers = {
125128
defaultModel: realtimeConfig.model,
126129
noRegisteredProviderMessage: "No realtime voice provider registered",
127130
});
131+
if (wantsCameraFrames && resolution.provider.capabilities?.supportsVideoFrames !== true) {
132+
respond(
133+
false,
134+
undefined,
135+
errorShape(
136+
ErrorCodes.INVALID_REQUEST,
137+
`Realtime provider ${resolution.provider.id} does not support browser video frames`,
138+
),
139+
);
140+
return;
141+
}
128142
const launchOptions = buildRealtimeVoiceLaunchOptions({
129143
requested: typedParams,
130144
defaults: realtimeConfig,
131145
});
132146
if (resolution.provider.createBrowserSession && transport !== "gateway-relay") {
133147
const tools = [REALTIME_VOICE_AGENT_CONSULT_TOOL, REALTIME_VOICE_AGENT_CONTROL_TOOL];
134-
if (
135-
resolution.provider.id === "openai" &&
136-
transport === "webrtc" &&
137-
typedParams.capabilities?.includes("camera-frame")
138-
) {
148+
if (wantsCameraFrames) {
139149
tools.push(REALTIME_VOICE_DESCRIBE_VIEW_TOOL);
140150
}
141151
const session = await resolution.provider.createBrowserSession({
@@ -146,6 +156,7 @@ export const talkClientHandlers: GatewayRequestHandlers = {
146156
...launchOptions,
147157
});
148158
if (
159+
(session.transport === "webrtc" || session.transport === "provider-websocket") &&
149160
!isUnsupportedBrowserWebRtcSession(session) &&
150161
(!transport || session.transport === transport)
151162
) {

0 commit comments

Comments
 (0)