Tau RPC: resolve on agent_end

This commit is contained in:
Peter Steinberger
2025-12-03 09:39:26 +00:00
parent 86d707ad51
commit 394c751d7d
2 changed files with 21 additions and 1 deletions

View File

@@ -67,6 +67,25 @@ class TauRpcClient {
if (!this.pending) return;
this.buffer.push(line);
this.pending?.onEvent?.(line);
// If Tau signals the full prompt/response cycle is finished, resolve immediately.
try {
const evt = JSON.parse(line) as { type?: string };
if (evt?.type === "agent_end") {
if (this.idleTimer) clearTimeout(this.idleTimer);
const pending = this.pending;
this.pending = undefined;
const out = this.buffer.join("\n");
this.buffer = [];
this.seenAssistantEnd = false;
clearTimeout(pending.timer);
pending.resolve({ stdout: out, stderr: this.stderr, code: 0 });
return;
}
} catch {
// ignore malformed/non-JSON lines
}
// Streamed JSON arrives line-by-line; mark when an assistant message finishes
// and resolve after a short idle to capture any follow-up events (e.g. tools)
// that belong to the same turn.