Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/app/api/runtimes/[id]/talk/realtime/relay/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }),
Expand Down Expand Up @@ -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." },
Expand Down
16 changes: 16 additions & 0 deletions src/app/api/runtimes/[id]/talk/realtime/relay/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string>((resolve, reject) => {
const timer = setTimeout(() => {
Expand Down
Loading