Skip to content

Commit 68359ca

Browse files
feat(webchat): add server-side dictation (#76021)
Summary: - This PR adds WebChat server-side dictation through a new authenticated `chat.transcribeAudio` Gateway RPC, MediaRecorder composer controls, docs/changelog updates, and focused gateway/UI tests. - Reproducibility: yes. Current main reproduces the missing feature by inspection: the Gateway method list, write scopes, docs, and WebChat voice-control test have no `chat.transcribeAudio` server-dictation path. ClawSweeper fixups: - Included follow-up commit: feat(webchat): add server-side dictation - Included follow-up commit: fix(clawsweeper): address review for automerge-openclaw-openclaw-7602… Validation: - ClawSweeper review passed for head 8505713. - Required merge gates passed before the squash merge. Prepared head SHA: 8505713 Review: #76021 (comment) Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
1 parent 15bbf4f commit 68359ca

23 files changed

Lines changed: 847 additions & 23 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Docs: https://docs.openclaw.ai
145145
- Anthropic-compatible streams: recover text deltas that arrive before their matching content block, so Kimi Code and similar providers do not finish as empty `incomplete_result` replies. Fixes #76007. Thanks @vliuyt.
146146
- fix(infra): block workspace state-directory env override [AI]. (#75940) Thanks @pgondhi987.
147147
- MCP/OpenAI: normalize parameter-free tool schemas whose top-level object `properties` is missing, null, or invalid before sending tools to OpenAI, so MCP tools without params stay usable. Fixes #75362. Thanks @tolkonepiu and @SymbolStar.
148+
- Control UI/WebChat: add server-side chat-draft microphone dictation via the existing audio transcription pipeline, avoiding browser Web Speech while keeping provider credentials on the Gateway. Fixes #47311. Thanks @jmomford.
148149
- TTS: honor explicit short `[[tts:text]]...[[/tts:text]]` blocks while keeping untagged short auto-TTS suppressed, so tagged voice replies are synthesized instead of being dropped as empty voice-only payloads. Fixes #73758. Thanks @yfge.
149150
- Hooks/doctor: warn when `hooks.transformsDir` points outside the canonical hooks transform directory, so invalid workspace skill paths get a direct recovery hint before the Gateway crash-loops. Fixes #75853. Thanks @midobk.
150151
- Proxy/audio: convert standard `FormData` bodies before proxy-backed undici fetches, so audio transcription and multipart uploads no longer send `[object FormData]` when `HTTP_PROXY` or `HTTPS_PROXY` is configured. Fixes #48554. Thanks @dco5.

‎docs/nodes/audio.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ title: "Audio and voice notes"
1717
5. On success, it replaces `Body` with an `[Audio]` block and sets `{{Transcript}}`.
1818
- **Command parsing**: When transcription succeeds, `CommandBody`/`RawBody` are set to the transcript so slash commands still work.
1919
- **Verbose logging**: In `--verbose`, we log when transcription runs and when it replaces the body.
20+
- **Control UI dictation**: The Chat composer can send a browser-recorded microphone clip to `chat.transcribeAudio`. That Gateway RPC writes the clip to a temporary local file, runs this same audio transcription pipeline, returns draft text to the browser, and deletes the temporary file. It does not create an agent run by itself.
2021

2122
## Auto-detection (default)
2223

‎docs/web/control-ui.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Imported themes are stored only in the current browser profile. They are not wri
9696
<AccordionGroup>
9797
<Accordion title="Chat and Talk">
9898
- Chat with the model via Gateway WS (`chat.history`, `chat.send`, `chat.abort`, `chat.inject`).
99+
- Dictate into the Chat composer with server-side STT (`chat.transcribeAudio`). The browser records a short microphone clip and sends it to the Gateway, which runs the configured `tools.media.audio` transcription pipeline and returns draft text without exposing provider credentials to the browser.
99100
- Talk through browser realtime sessions. OpenAI uses direct WebRTC, Google Live uses a constrained one-use browser token over WebSocket, and backend-only realtime voice plugins use the Gateway relay transport. The relay keeps provider credentials on the Gateway while the browser streams microphone PCM through `talk.realtime.relay*` RPCs and sends `openclaw_agent_consult` tool calls back through `chat.send` for the larger configured OpenClaw model.
100101
- Stream tool calls + live tool output cards in Chat (agent events).
101102

@@ -149,6 +150,7 @@ Imported themes are stored only in the current browser profile. They are not wri
149150
<AccordionGroup>
150151
<Accordion title="Send and history semantics">
151152
- `chat.send` is **non-blocking**: it acks immediately with `{ runId, status: "started" }` and the response streams via `chat` events.
153+
- `chat.transcribeAudio` is a one-shot dictation helper for Chat drafts. It accepts browser-recorded base64 audio, keeps uploads below the Gateway WebSocket frame limit, writes a temporary local file, runs media-understanding audio transcription with the active Gateway config, returns `{ text, provider, model }`, and removes the temporary file. It does not create an agent run and is separate from realtime Talk.
152154
- Chat uploads accept images plus non-video files. Images keep the native image path; other files are stored as managed media and shown in history as attachment links.
153155
- Re-sending with the same `idempotencyKey` returns `{ status: "in_flight" }` while running, and `{ status: "ok" }` after completion.
154156
- `chat.history` responses are size-bounded for UI safety. When transcript entries are too large, Gateway may truncate long text fields, omit heavy metadata blocks, and replace oversized messages with a placeholder (`[chat.history omitted: message too large]`).

‎docs/web/webchat.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Status: the macOS/iOS SwiftUI chat UI talks directly to the Gateway WebSocket.
2222

2323
## How it works (behavior)
2424

25-
- The UI connects to the Gateway WebSocket and uses `chat.history`, `chat.send`, and `chat.inject`.
25+
- The UI connects to the Gateway WebSocket and uses `chat.history`, `chat.send`, `chat.inject`, and `chat.transcribeAudio`.
2626
- `chat.history` is bounded for stability: Gateway may truncate long text fields, omit heavy metadata, and replace oversized entries with `[chat.history omitted: message too large]`.
2727
- `chat.history` follows the active transcript branch for modern append-only session files, so abandoned rewrite branches and superseded prompt copies are not rendered in WebChat.
2828
- Control UI remembers the backing Gateway `sessionId` returned by `chat.history` and includes it on follow-up `chat.send` calls, so reconnects and page refreshes continue the same stored conversation unless the user starts or resets a session.
@@ -37,6 +37,7 @@ Status: the macOS/iOS SwiftUI chat UI talks directly to the Gateway WebSocket.
3737
and assistant entries whose whole visible text is only the exact silent
3838
token `NO_REPLY` / `no_reply` are omitted.
3939
- Reasoning-flagged reply payloads (`isReasoning: true`) are excluded from WebChat assistant content, transcript replay text, and audio content blocks, so thinking-only payloads do not surface as visible assistant messages or playable audio.
40+
- `chat.transcribeAudio` powers server-side dictation in the Control UI chat composer. The browser records microphone audio, sends it as base64 to the Gateway, and the Gateway runs the configured `tools.media.audio` pipeline. The returned transcript is inserted into the draft; no agent run is started until the user sends it.
4041
- `chat.inject` appends an assistant note directly to the transcript and broadcasts it to the UI (no agent run).
4142
- Aborted runs can keep partial assistant output visible in the UI.
4243
- Gateway persists aborted partial assistant text into transcript history when buffered output exists, and marks those entries with abort metadata.

‎scripts/openclaw-npm-release-check.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,14 @@ function isNpmExecPath(value: string): boolean {
427427
return /^npm(?:-cli)?(?:\.(?:c?js|cmd|exe))?$/.test(basename(value).toLowerCase());
428428
}
429429

430-
export function resolveNpmCommandInvocation(
431-
params: {
432-
npmExecPath?: string;
433-
nodeExecPath?: string;
434-
platform?: NodeJS.Platform;
435-
} = {},
436-
): { command: string; args: string[] } {
437-
const npmExecPath = params.npmExecPath ?? process.env.npm_execpath;
438-
const nodeExecPath = params.nodeExecPath ?? process.execPath;
439-
const npmCommand = (params.platform ?? process.platform) === "win32" ? "npm.cmd" : "npm";
430+
export function resolveNpmCommandInvocation(params?: {
431+
npmExecPath?: string;
432+
nodeExecPath?: string;
433+
platform?: NodeJS.Platform;
434+
}): { command: string; args: string[] } {
435+
const npmExecPath = params === undefined ? process.env.npm_execpath : params.npmExecPath;
436+
const nodeExecPath = params?.nodeExecPath ?? process.execPath;
437+
const npmCommand = (params?.platform ?? process.platform) === "win32" ? "npm.cmd" : "npm";
440438

441439
if (typeof npmExecPath === "string" && npmExecPath.length > 0 && isNpmExecPath(npmExecPath)) {
442440
return { command: nodeExecPath, args: [npmExecPath] };

‎src/gateway/method-scopes.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ const METHOD_SCOPE_GROUPS: Record<OperatorScope, readonly string[]> = {
151151
"tools.invoke",
152152
"chat.send",
153153
"chat.abort",
154+
"chat.transcribeAudio",
154155
"sessions.create",
155156
"sessions.send",
156157
"sessions.steer",

‎src/gateway/server-methods-list.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ const BASE_METHODS = [
155155
"chat.history",
156156
"chat.abort",
157157
"chat.send",
158+
"chat.transcribeAudio",
158159
];
159160

160161
export function listGatewayMethods(): string[] {

‎src/gateway/server-methods.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { agentHandlers } from "./server-methods/agent.js";
1212
import { agentsHandlers } from "./server-methods/agents.js";
1313
import { artifactsHandlers } from "./server-methods/artifacts.js";
1414
import { channelsHandlers } from "./server-methods/channels.js";
15+
import { chatTranscribeAudioHandlers } from "./server-methods/chat-transcribe-audio.js";
1516
import { chatHandlers } from "./server-methods/chat.js";
1617
import { commandsHandlers } from "./server-methods/commands.js";
1718
import { configHandlers } from "./server-methods/config.js";
@@ -85,6 +86,7 @@ export const coreGatewayHandlers: GatewayRequestHandlers = {
8586
...healthHandlers,
8687
...channelsHandlers,
8788
...chatHandlers,
89+
...chatTranscribeAudioHandlers,
8890
...commandsHandlers,
8991
...cronHandlers,
9092
...deviceHandlers,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { transcribeAudioFile } from "../../media-understanding/runtime.js";
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import fs from "node:fs/promises";
2+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+
import { ErrorCodes } from "../protocol/index.js";
4+
import { MAX_PAYLOAD_BYTES } from "../server-constants.js";
5+
6+
const mocks = vi.hoisted(() => ({
7+
transcribeAudioFile: vi.fn(async () => ({
8+
text: "hello from audio",
9+
provider: "openai",
10+
model: "gpt-4o-transcribe",
11+
})),
12+
}));
13+
14+
vi.mock("../../media-understanding/runtime.js", () => ({
15+
transcribeAudioFile:
16+
mocks.transcribeAudioFile as typeof import("../../media-understanding/runtime.js").transcribeAudioFile,
17+
}));
18+
19+
describe("chatTranscribeAudioHandlers", () => {
20+
beforeEach(() => {
21+
mocks.transcribeAudioFile.mockReset();
22+
mocks.transcribeAudioFile.mockResolvedValue({
23+
text: "hello from audio",
24+
provider: "openai",
25+
model: "gpt-4o-transcribe",
26+
});
27+
});
28+
29+
afterEach(() => {
30+
vi.restoreAllMocks();
31+
});
32+
33+
it("keeps the decoded audio cap below the base64 WebSocket frame limit", async () => {
34+
const { MAX_CHAT_TRANSCRIBE_AUDIO_BYTES } = await import("./chat-transcribe-audio.js");
35+
const base64Bytes = Math.ceil(MAX_CHAT_TRANSCRIBE_AUDIO_BYTES / 3) * 4;
36+
37+
expect(base64Bytes + 64 * 1024).toBeLessThanOrEqual(MAX_PAYLOAD_BYTES);
38+
expect(MAX_CHAT_TRANSCRIBE_AUDIO_BYTES).toBeLessThan(20 * 1024 * 1024);
39+
});
40+
41+
it("transcribes uploaded chat dictation audio through media understanding", async () => {
42+
const { chatTranscribeAudioHandlers } = await import("./chat-transcribe-audio.js");
43+
const respond = vi.fn();
44+
45+
await chatTranscribeAudioHandlers["chat.transcribeAudio"]({
46+
params: {
47+
audioDataUrl: `data:audio/webm;base64,${Buffer.from("audio").toString("base64")}`,
48+
},
49+
respond,
50+
context: { getRuntimeConfig: () => ({ tools: { media: {} } }) },
51+
} as never);
52+
53+
expect(mocks.transcribeAudioFile).toHaveBeenCalledWith(
54+
expect.objectContaining({
55+
cfg: { tools: { media: {} } },
56+
mime: "audio/webm",
57+
}),
58+
);
59+
const call = (mocks.transcribeAudioFile.mock.calls as unknown as Array<[{ filePath?: string }]>)
60+
.at(0)
61+
?.at(0);
62+
const filePath = call?.filePath;
63+
expect(filePath).toMatch(/dictation\.webm$/);
64+
await expect(fs.stat(filePath ?? "")).rejects.toMatchObject({ code: "ENOENT" });
65+
expect(respond).toHaveBeenCalledWith(true, {
66+
text: "hello from audio",
67+
provider: "openai",
68+
model: "gpt-4o-transcribe",
69+
});
70+
});
71+
72+
it("returns INVALID_REQUEST for missing audio payloads", async () => {
73+
const { chatTranscribeAudioHandlers } = await import("./chat-transcribe-audio.js");
74+
const respond = vi.fn();
75+
76+
await chatTranscribeAudioHandlers["chat.transcribeAudio"]({
77+
params: {},
78+
respond,
79+
context: { getRuntimeConfig: () => ({}) },
80+
} as never);
81+
82+
expect(respond).toHaveBeenCalledWith(
83+
false,
84+
undefined,
85+
expect.objectContaining({
86+
code: ErrorCodes.INVALID_REQUEST,
87+
message: expect.stringContaining("requires audioDataUrl or audioBase64"),
88+
}),
89+
);
90+
expect(mocks.transcribeAudioFile).not.toHaveBeenCalled();
91+
});
92+
93+
it("returns UNAVAILABLE when no transcription provider is configured", async () => {
94+
mocks.transcribeAudioFile.mockResolvedValue({
95+
text: undefined,
96+
decision: {
97+
capability: "audio",
98+
outcome: "skipped",
99+
attachments: [{ attempts: [] }],
100+
},
101+
} as never);
102+
const { chatTranscribeAudioHandlers } = await import("./chat-transcribe-audio.js");
103+
const respond = vi.fn();
104+
105+
await chatTranscribeAudioHandlers["chat.transcribeAudio"]({
106+
params: {
107+
audioBase64: Buffer.from("audio").toString("base64"),
108+
mimeType: "audio/ogg",
109+
},
110+
respond,
111+
context: { getRuntimeConfig: () => ({}) },
112+
} as never);
113+
114+
expect(respond).toHaveBeenCalledWith(
115+
false,
116+
undefined,
117+
expect.objectContaining({
118+
code: ErrorCodes.UNAVAILABLE,
119+
message: expect.stringContaining("No audio transcription provider"),
120+
}),
121+
);
122+
});
123+
});

0 commit comments

Comments
 (0)