fix(discord): reject malformed realtime consult calls · openclaw/openclaw@baeedaa
khoek
·
2026-06-16
·
via Recent Commits to openclaw:main
File tree
extensions/discord/src/voice
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2390,6 +2390,49 @@ describe("DiscordVoiceManager", () => {
|
2390 | 2390 | ); |
2391 | 2391 | }); |
2392 | 2392 | |
| 2393 | +it("rejects malformed realtime consult tool calls without crashing Discord voice", async () => { |
| 2394 | +const manager = createManager({ |
| 2395 | +groupPolicy: "open", |
| 2396 | +voice: { |
| 2397 | +enabled: true, |
| 2398 | +mode: "agent-proxy", |
| 2399 | +realtime: { provider: "openai" }, |
| 2400 | +}, |
| 2401 | +}); |
| 2402 | + |
| 2403 | +await manager.join({ guildId: "g1", channelId: "1001" }); |
| 2404 | +const bridgeParams = lastRealtimeBridgeParams() as |
| 2405 | +| { |
| 2406 | +onToolCall?: ( |
| 2407 | +event: { |
| 2408 | +itemId: string; |
| 2409 | +callId: string; |
| 2410 | +name: string; |
| 2411 | +args: unknown; |
| 2412 | +}, |
| 2413 | +session: typeof realtimeSessionMock, |
| 2414 | +) => void; |
| 2415 | +} |
| 2416 | +| undefined; |
| 2417 | + |
| 2418 | +expect(() => |
| 2419 | +bridgeParams?.onToolCall?.( |
| 2420 | +{ |
| 2421 | +itemId: "item-empty-consult", |
| 2422 | +callId: "call-empty-consult", |
| 2423 | +name: "openclaw_agent_consult", |
| 2424 | +args: {}, |
| 2425 | +}, |
| 2426 | +realtimeSessionMock, |
| 2427 | +), |
| 2428 | +).not.toThrow(); |
| 2429 | + |
| 2430 | +expect(agentCommandMock).not.toHaveBeenCalled(); |
| 2431 | +expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-empty-consult", { |
| 2432 | +error: "question required", |
| 2433 | +}); |
| 2434 | +}); |
| 2435 | + |
2393 | 2436 | it("does not require speaker context for internal exact-speech consults", async () => { |
2394 | 2437 | const manager = createManager({ |
2395 | 2438 | groupPolicy: "open", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1124,7 +1124,17 @@ export class DiscordRealtimeVoiceSession implements VoiceRealtimeSession {
|
1124 | 1124 | session.submitToolResult(callId, { text: exactSpeechText }); |
1125 | 1125 | return; |
1126 | 1126 | } |
1127 | | -const consultMessage = buildRealtimeVoiceAgentConsultChatMessage(event.args); |
| 1127 | +let consultMessage: string; |
| 1128 | +try { |
| 1129 | +consultMessage = buildRealtimeVoiceAgentConsultChatMessage(event.args); |
| 1130 | +} catch (error) { |
| 1131 | +const message = formatErrorMessage(error); |
| 1132 | +logger.warn( |
| 1133 | +`discord voice: realtime consult rejected malformed args call=${callId || "unknown"}: ${message}`, |
| 1134 | +); |
| 1135 | +session.submitToolResult(callId, { error: message }); |
| 1136 | +return; |
| 1137 | +} |
1128 | 1138 | logger.info( |
1129 | 1139 | `discord voice: realtime consult requested call=${callId || "unknown"} voiceSession=${this.params.entry.voiceSessionKey} supervisorSession=${this.params.entry.route.sessionKey} agent=${this.params.entry.route.agentId} question=${formatRealtimeLogPreview(consultMessage)}`, |
1130 | 1140 | ); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。