From f765c2641cdc68701943e2786f2b979689b98b12 Mon Sep 17 00:00:00 2001 From: Roger Chappel Date: Thu, 21 May 2026 17:09:34 +1000 Subject: [PATCH] fix: keep realtime consults pending --- .../[id]/talk/realtime/relay/route.test.ts | 15 +++++++++++++-- .../runtimes/[id]/talk/realtime/relay/route.ts | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/app/api/runtimes/[id]/talk/realtime/relay/route.test.ts b/src/app/api/runtimes/[id]/talk/realtime/relay/route.test.ts index f2dbf9b..9a45309 100644 --- a/src/app/api/runtimes/[id]/talk/realtime/relay/route.test.ts +++ b/src/app/api/runtimes/[id]/talk/realtime/relay/route.test.ts @@ -109,7 +109,7 @@ describe("POST /api/runtimes/[id]/talk/realtime/relay", () => { expect(realtimeRelayCancelOutput).toHaveBeenCalledWith("relay_1", "barge-in"); }); - it("delegates realtime tool calls to OpenClaw and submits the final result", async () => { + it("delegates realtime tool calls to OpenClaw and keeps the relay waiting for the final result", async () => { let gatewayHandler: ((payload: unknown) => void) | null = null; const client = { realtimeClientToolCall: vi.fn().mockResolvedValue({ runId: "run_1" }), @@ -164,7 +164,18 @@ describe("POST /api/runtimes/[id]/talk/realtime/relay", () => { result: { ok: true }, }, }); - expect(client.realtimeRelayToolResult).toHaveBeenCalledWith({ + expect(client.realtimeRelayToolResult).toHaveBeenNthCalledWith(1, { + relaySessionId: "relay_1", + callId: "call_1", + result: { + status: "working", + tool: "openclaw_agent_consult", + message: + "Tell the person briefly that you are checking, then wait for the final OpenClaw result before answering with the actual result.", + }, + options: { willContinue: true }, + }); + expect(client.realtimeRelayToolResult).toHaveBeenNthCalledWith(2, { relaySessionId: "relay_1", callId: "call_1", result: { result: "The repo is a CrewCMD app." }, diff --git a/src/app/api/runtimes/[id]/talk/realtime/relay/route.ts b/src/app/api/runtimes/[id]/talk/realtime/relay/route.ts index c184307..8539052 100644 --- a/src/app/api/runtimes/[id]/talk/realtime/relay/route.ts +++ b/src/app/api/runtimes/[id]/talk/realtime/relay/route.ts @@ -124,6 +124,13 @@ async function runRealtimeToolCall( const runId = firstString(toolCall.runId, toolCall.idempotencyKey); if (!runId) throw new Error("OpenClaw realtime tool call did not return a run id"); + await client.realtimeRelayToolResult({ + relaySessionId: params.relaySessionId, + callId: params.callId, + result: buildRealtimeToolWorkingResult(), + options: { willContinue: true }, + }); + const text = await waitForChatFinal(client, runId); const result = await client.realtimeRelayToolResult({ relaySessionId: params.relaySessionId, @@ -145,6 +152,15 @@ async function runRealtimeToolCall( } } +function buildRealtimeToolWorkingResult() { + return { + status: "working", + tool: "openclaw_agent_consult", + message: + "Tell the person briefly that you are checking, then wait for the final OpenClaw result before answering with the actual result.", + }; +} + function waitForChatFinal(client: GatewayClient, runId: string, timeoutMs = 110_000) { return new Promise((resolve, reject) => { const timer = setTimeout(() => {