Skip to content

Commit 04066d2

Browse files
committed
feat: add browser realtime talk
1 parent d42069b commit 04066d2

26 files changed

Lines changed: 765 additions & 45 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Docs: https://docs.openclaw.ai
77
### Changes
88

99
- Control UI/chat: add a Steer action on queued messages so a browser follow-up can be injected into the active run without retyping it.
10+
- Control UI/Talk: add browser WebRTC realtime voice sessions backed by OpenAI Realtime, with Gateway-minted ephemeral client secrets and `openclaw_agent_consult` handoff to the full OpenClaw agent.
1011
- Agents/tools: add optional per-call `timeoutMs` support for image, video, music, and TTS generation tools so agents can extend provider request timeouts only when a specific generation needs it.
1112
- Agents/subagents: add optional forked context for native `sessions_spawn` runs so agents can let a child inherit the requester transcript when needed, while keeping clean isolated sessions as the default; includes prompt guidance, context-engine hook metadata, docs, and QA coverage.
1213
- Codex harness: add structured debug logging for embedded harness selection decisions so `/status` stays simple while gateway logs explain auto-selection and Pi fallback reasons. (#70760) Thanks @100yenadmin.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
793ed905cb0ba93b9a2f8c2c85c3cfb4d194dd9263353e74952bf9e382b03dc2 plugin-sdk-api-baseline.json
2-
032e7fd6f48344c9b3b98fd3e877e6d30cab92ed9a39dd309796cf1f0220820f plugin-sdk-api-baseline.jsonl
1+
96905c33f4498446f612ae17dee6affdf84ef0e2e5a0f25bf7191c315f5b826f plugin-sdk-api-baseline.json
2+
d8eb6331562fde29531eaac18409bb7fabcc70623bf25395f8e5710a49765f0f plugin-sdk-api-baseline.jsonl

‎docs/providers/openai.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ API-enabled model such as `openai/gpt-5.4` for `OPENAI_API_KEY` setups.
2525

2626
## OpenClaw feature coverage
2727

28-
| OpenAI capability | OpenClaw surface | Status |
29-
| ------------------------- | ------------------------------------------------------ | ------------------------------------------------------ |
30-
| Chat / Responses | `openai/<model>` model provider | Yes |
31-
| Codex subscription models | `openai-codex/<model>` with `openai-codex` OAuth | Yes |
32-
| Codex app-server harness | `openai/<model>` with `embeddedHarness.runtime: codex` | Yes |
33-
| Server-side web search | Native OpenAI Responses tool | Yes, when web search is enabled and no provider pinned |
34-
| Images | `image_generate` | Yes |
35-
| Videos | `video_generate` | Yes |
36-
| Text-to-speech | `messages.tts.provider: "openai"` / `tts` | Yes |
37-
| Batch speech-to-text | `tools.media.audio` / media understanding | Yes |
38-
| Streaming speech-to-text | Voice Call `streaming.provider: "openai"` | Yes |
39-
| Realtime voice | Voice Call `realtime.provider: "openai"` | Yes |
40-
| Embeddings | memory embedding provider | Yes |
28+
| OpenAI capability | OpenClaw surface | Status |
29+
| ------------------------- | ---------------------------------------------------------- | ------------------------------------------------------ |
30+
| Chat / Responses | `openai/<model>` model provider | Yes |
31+
| Codex subscription models | `openai-codex/<model>` with `openai-codex` OAuth | Yes |
32+
| Codex app-server harness | `openai/<model>` with `embeddedHarness.runtime: codex` | Yes |
33+
| Server-side web search | Native OpenAI Responses tool | Yes, when web search is enabled and no provider pinned |
34+
| Images | `image_generate` | Yes |
35+
| Videos | `video_generate` | Yes |
36+
| Text-to-speech | `messages.tts.provider: "openai"` / `tts` | Yes |
37+
| Batch speech-to-text | `tools.media.audio` / media understanding | Yes |
38+
| Streaming speech-to-text | Voice Call `streaming.provider: "openai"` | Yes |
39+
| Realtime voice | Voice Call `realtime.provider: "openai"` / Control UI Talk | Yes |
40+
| Embeddings | memory embedding provider | Yes |
4141

4242
## Getting started
4343

‎docs/web/control-ui.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ locale picker lives in the Gateway Access card, not under Appearance.
105105
## What it can do (today)
106106

107107
- Chat with the model via Gateway WS (`chat.history`, `chat.send`, `chat.abort`, `chat.inject`)
108+
- Talk to OpenAI Realtime directly from the browser via WebRTC. The Gateway
109+
mints a short-lived Realtime client secret with `talk.realtime.session`; the
110+
browser sends microphone audio directly to OpenAI and relays
111+
`openclaw_agent_consult` tool calls back through `chat.send` for the larger
112+
configured OpenClaw model.
108113
- Stream tool calls + live tool output cards in Chat (agent events)
109114
- Channels: built-in plus bundled/external plugin channels status, QR login, and per-channel config (`channels.status`, `web.login.*`, `config.patch`)
110115
- Instances: presence list + refresh (`system-presence`)
@@ -151,6 +156,10 @@ Cron jobs panel notes:
151156
- `chat.history` also strips display-only inline directive tags from visible assistant text (for example `[[reply_to_*]]` and `[[audio_as_voice]]`), plain-text tool-call XML payloads (including `<tool_call>...</tool_call>`, `<function_call>...</function_call>`, `<tool_calls>...</tool_calls>`, `<function_calls>...</function_calls>`, and truncated tool-call blocks), and leaked ASCII/full-width model control tokens, and omits assistant entries whose whole visible text is only the exact silent token `NO_REPLY` / `no_reply`.
152157
- `chat.inject` appends an assistant note to the session transcript and broadcasts a `chat` event for UI-only updates (no agent run, no channel delivery).
153158
- The chat header model and thinking pickers patch the active session immediately through `sessions.patch`; they are persistent session overrides, not one-turn-only send options.
159+
- Talk mode uses the registered realtime voice provider. Configure OpenAI with
160+
`talk.provider: "openai"` plus `talk.providers.openai.apiKey`, or reuse the
161+
Voice Call realtime provider config. The browser never receives the standard
162+
OpenAI API key; it receives only the ephemeral Realtime client secret.
154163
- Stop:
155164
- Click **Stop** (calls `chat.abort`)
156165
- While a run is active, normal follow-ups queue. Click **Steer** on a queued message to inject that follow-up into the running turn.

‎extensions/google-meet/src/agent-consult.ts‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { randomUUID } from "node:crypto";
22
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
33
import type { PluginRuntime, RuntimeLogger } from "openclaw/plugin-sdk/plugin-runtime";
4-
import type { RealtimeVoiceTool } from "openclaw/plugin-sdk/realtime-voice";
4+
import {
5+
REALTIME_VOICE_AGENT_CONSULT_TOOL,
6+
REALTIME_VOICE_AGENT_CONSULT_TOOL_NAME,
7+
type RealtimeVoiceTool,
8+
} from "openclaw/plugin-sdk/realtime-voice";
59
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
610
import type { GoogleMeetConfig, GoogleMeetToolPolicy } from "./config.js";
711

@@ -11,32 +15,8 @@ type AgentPayload = {
1115
isReasoning?: boolean;
1216
};
1317

14-
export const GOOGLE_MEET_AGENT_CONSULT_TOOL_NAME = "openclaw_agent_consult";
15-
16-
export const GOOGLE_MEET_AGENT_CONSULT_TOOL: RealtimeVoiceTool = {
17-
type: "function",
18-
name: GOOGLE_MEET_AGENT_CONSULT_TOOL_NAME,
19-
description:
20-
"Ask the full OpenClaw agent for deeper reasoning, current information, or tool-backed help before speaking in the meeting.",
21-
parameters: {
22-
type: "object",
23-
properties: {
24-
question: {
25-
type: "string",
26-
description: "The concrete question or task the meeting participant asked.",
27-
},
28-
context: {
29-
type: "string",
30-
description: "Optional relevant meeting context or transcript summary.",
31-
},
32-
responseStyle: {
33-
type: "string",
34-
description: "Optional style hint for the spoken answer.",
35-
},
36-
},
37-
required: ["question"],
38-
},
39-
};
18+
export const GOOGLE_MEET_AGENT_CONSULT_TOOL_NAME = REALTIME_VOICE_AGENT_CONSULT_TOOL_NAME;
19+
export const GOOGLE_MEET_AGENT_CONSULT_TOOL = REALTIME_VOICE_AGENT_CONSULT_TOOL;
4020

4121
export function resolveGoogleMeetRealtimeTools(policy: GoogleMeetToolPolicy): RealtimeVoiceTool[] {
4222
return policy === "none" ? [] : [GOOGLE_MEET_AGENT_CONSULT_TOOL];

‎extensions/google-meet/src/config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { REALTIME_VOICE_AGENT_CONSULT_TOOL_NAME } from "openclaw/plugin-sdk/realtime-voice";
12
import {
23
normalizeOptionalLowercaseString,
34
normalizeOptionalString,
@@ -94,8 +95,7 @@ export const DEFAULT_GOOGLE_MEET_AUDIO_OUTPUT_COMMAND = [
9495
"-",
9596
] as const;
9697

97-
export const DEFAULT_GOOGLE_MEET_REALTIME_INSTRUCTIONS =
98-
"You are joining a private Google Meet as an OpenClaw agent. Keep spoken replies brief and natural. When a question needs deeper reasoning, current information, or tools, call openclaw_agent_consult before answering.";
98+
export const DEFAULT_GOOGLE_MEET_REALTIME_INSTRUCTIONS = `You are joining a private Google Meet as an OpenClaw agent. Keep spoken replies brief and natural. When a question needs deeper reasoning, current information, or tools, call ${REALTIME_VOICE_AGENT_CONSULT_TOOL_NAME} before answering.`;
9999

100100
export const DEFAULT_GOOGLE_MEET_CONFIG: GoogleMeetConfig = {
101101
enabled: true,

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

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
} from "openclaw/plugin-sdk/proxy-capture";
77
import type {
88
RealtimeVoiceBridge,
9+
RealtimeVoiceBrowserSession,
10+
RealtimeVoiceBrowserSessionCreateRequest,
911
RealtimeVoiceBridgeCreateRequest,
1012
RealtimeVoiceProviderConfig,
1113
RealtimeVoiceProviderPlugin,
@@ -59,6 +61,8 @@ type OpenAIRealtimeVoiceBridgeConfig = RealtimeVoiceBridgeCreateRequest & {
5961
azureApiVersion?: string;
6062
};
6163

64+
const OPENAI_REALTIME_DEFAULT_MODEL = "gpt-realtime-1.5";
65+
6266
type RealtimeEvent = {
6367
type: string;
6468
delta?: string;
@@ -117,7 +121,7 @@ function base64ToBuffer(b64: string): Buffer {
117121
}
118122

119123
class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {
120-
private static readonly DEFAULT_MODEL = "gpt-realtime-1.5";
124+
private static readonly DEFAULT_MODEL = OPENAI_REALTIME_DEFAULT_MODEL;
121125
private static readonly MAX_RECONNECT_ATTEMPTS = 5;
122126
private static readonly BASE_RECONNECT_DELAY_MS = 1000;
123127
private static readonly CONNECT_TIMEOUT_MS = 10_000;
@@ -579,6 +583,77 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {
579583
}
580584
}
581585

586+
function readStringField(value: unknown, key: string): string | undefined {
587+
if (!value || typeof value !== "object") {
588+
return undefined;
589+
}
590+
const raw = (value as Record<string, unknown>)[key];
591+
return typeof raw === "string" && raw.trim() ? raw.trim() : undefined;
592+
}
593+
594+
async function createOpenAIRealtimeBrowserSession(
595+
req: RealtimeVoiceBrowserSessionCreateRequest,
596+
): Promise<RealtimeVoiceBrowserSession> {
597+
const config = normalizeProviderConfig(req.providerConfig);
598+
const apiKey = config.apiKey || process.env.OPENAI_API_KEY;
599+
if (!apiKey) {
600+
throw new Error("OpenAI API key missing");
601+
}
602+
if (config.azureEndpoint || config.azureDeployment) {
603+
throw new Error("OpenAI Realtime browser sessions do not support Azure endpoints yet");
604+
}
605+
606+
const model = req.model ?? config.model ?? OPENAI_REALTIME_DEFAULT_MODEL;
607+
const voice = (req.voice ?? config.voice ?? "alloy") as OpenAIRealtimeVoice;
608+
const session: Record<string, unknown> = {
609+
type: "realtime",
610+
model,
611+
instructions: req.instructions,
612+
audio: {
613+
output: { voice },
614+
},
615+
};
616+
if (req.tools && req.tools.length > 0) {
617+
session.tools = req.tools;
618+
session.tool_choice = "auto";
619+
}
620+
621+
const response = await fetch("https://api.openai.com/v1/realtime/client_secrets", {
622+
method: "POST",
623+
headers: {
624+
Authorization: `Bearer ${apiKey}`,
625+
"Content-Type": "application/json",
626+
},
627+
body: JSON.stringify({ session }),
628+
});
629+
if (!response.ok) {
630+
const detail = await response.text().catch(() => "");
631+
throw new Error(
632+
`OpenAI Realtime browser session failed (${response.status}): ${detail || response.statusText}`,
633+
);
634+
}
635+
const payload = (await response.json()) as unknown;
636+
const nestedSecret =
637+
payload && typeof payload === "object"
638+
? (payload as Record<string, unknown>).client_secret
639+
: undefined;
640+
const clientSecret = readStringField(payload, "value") ?? readStringField(nestedSecret, "value");
641+
if (!clientSecret) {
642+
throw new Error("OpenAI Realtime browser session did not return a client secret");
643+
}
644+
const expiresAt =
645+
payload && typeof payload === "object"
646+
? (payload as Record<string, unknown>).expires_at
647+
: undefined;
648+
return {
649+
provider: "openai",
650+
clientSecret,
651+
model,
652+
voice,
653+
...(typeof expiresAt === "number" ? { expiresAt } : {}),
654+
};
655+
}
656+
582657
export function buildOpenAIRealtimeVoiceProvider(): RealtimeVoiceProviderPlugin {
583658
return {
584659
id: "openai",
@@ -607,6 +682,7 @@ export function buildOpenAIRealtimeVoiceProvider(): RealtimeVoiceProviderPlugin
607682
azureApiVersion: config.azureApiVersion,
608683
});
609684
},
685+
createBrowserSession: createOpenAIRealtimeBrowserSession,
610686
};
611687
}
612688

‎src/gateway/method-scopes.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const METHOD_SCOPE_GROUPS: Record<OperatorScope, readonly string[]> = {
125125
"agent.wait",
126126
"wake",
127127
"talk.mode",
128+
"talk.realtime.session",
128129
"talk.speak",
129130
"tts.enable",
130131
"tts.disable",

‎src/gateway/protocol/index.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ import {
5252
TalkConfigParamsSchema,
5353
type TalkConfigResult,
5454
TalkConfigResultSchema,
55+
type TalkRealtimeSessionParams,
56+
TalkRealtimeSessionParamsSchema,
57+
type TalkRealtimeSessionResult,
58+
TalkRealtimeSessionResultSchema,
5559
type TalkSpeakParams,
5660
TalkSpeakParamsSchema,
5761
type TalkSpeakResult,
@@ -428,6 +432,12 @@ export const validateWizardStatusParams = ajv.compile<WizardStatusParams>(Wizard
428432
export const validateTalkModeParams = ajv.compile<TalkModeParams>(TalkModeParamsSchema);
429433
export const validateTalkConfigParams = ajv.compile<TalkConfigParams>(TalkConfigParamsSchema);
430434
export const validateTalkConfigResult = ajv.compile<TalkConfigResult>(TalkConfigResultSchema);
435+
export const validateTalkRealtimeSessionParams = ajv.compile<TalkRealtimeSessionParams>(
436+
TalkRealtimeSessionParamsSchema,
437+
);
438+
export const validateTalkRealtimeSessionResult = ajv.compile<TalkRealtimeSessionResult>(
439+
TalkRealtimeSessionResultSchema,
440+
);
431441
export const validateTalkSpeakParams = ajv.compile<TalkSpeakParams>(TalkSpeakParamsSchema);
432442
export const validateTalkSpeakResult = ajv.compile<TalkSpeakResult>(TalkSpeakResultSchema);
433443
export const validateChannelsStatusParams = ajv.compile<ChannelsStatusParams>(
@@ -616,6 +626,8 @@ export {
616626
WizardStatusResultSchema,
617627
TalkConfigParamsSchema,
618628
TalkConfigResultSchema,
629+
TalkRealtimeSessionParamsSchema,
630+
TalkRealtimeSessionResultSchema,
619631
TalkSpeakParamsSchema,
620632
TalkSpeakResultSchema,
621633
ChannelsStatusParamsSchema,
@@ -720,6 +732,8 @@ export type {
720732
WizardStatusResult,
721733
TalkConfigParams,
722734
TalkConfigResult,
735+
TalkRealtimeSessionParams,
736+
TalkRealtimeSessionResult,
723737
TalkSpeakParams,
724738
TalkSpeakResult,
725739
TalkModeParams,

‎src/gateway/protocol/schema/channels.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ export const TalkSpeakParamsSchema = Type.Object(
3636
{ additionalProperties: false },
3737
);
3838

39+
export const TalkRealtimeSessionParamsSchema = Type.Object(
40+
{
41+
sessionKey: Type.Optional(Type.String()),
42+
provider: Type.Optional(Type.String()),
43+
model: Type.Optional(Type.String()),
44+
voice: Type.Optional(Type.String()),
45+
instructions: Type.Optional(Type.String()),
46+
},
47+
{ additionalProperties: false },
48+
);
49+
50+
export const TalkRealtimeSessionResultSchema = Type.Object(
51+
{
52+
provider: NonEmptyString,
53+
clientSecret: NonEmptyString,
54+
model: Type.Optional(Type.String()),
55+
voice: Type.Optional(Type.String()),
56+
expiresAt: Type.Optional(Type.Number()),
57+
},
58+
{ additionalProperties: false },
59+
);
60+
3961
const talkProviderFieldSchemas = {
4062
apiKey: Type.Optional(SecretInputSchema),
4163
};

0 commit comments

Comments
 (0)