惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
V
V2EX
美团技术团队
H
Help Net Security
月光博客
月光博客
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
U
Unit 42
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
A
About on SuperTechFans
博客园 - Franky
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
人人都是产品经理
人人都是产品经理
博客园 - 司徒正美
MyScale Blog
MyScale Blog
B
Blog
雷峰网
雷峰网
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
T
The Blog of Author Tim Ferriss

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
feat(webchat): add server-side dictation (#76021) · openc...
steipete · 2026-05-03 · via Recent Commits to openclaw:main

@@ -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+

});