fix(webui): accept end/error phases in tool trace rendering

Tool call events only displayed at phase=start, but progress_hook sends end/error phases after agent execution. Accept all three phases with call_id deduplication to prevent duplicate rendering.

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Wayne Heng 2026-05-18 17:55:28 +08:00
parent d4ade8f680
commit d7122a13d3

View File

@ -39,12 +39,24 @@ export function formatToolCallTrace(call: unknown): string | null {
return `${name}()`;
}
const VALID_PHASES = new Set(["start", "end", "error"]);
export function toolTraceLinesFromEvents(events: unknown): string[] {
if (!Array.isArray(events)) return [];
const seen = new Set<string>();
return events
.filter((event) => {
if (!event || typeof event !== "object") return false;
return (event as { phase?: unknown }).phase === "start";
const phase = (event as { phase?: unknown }).phase;
if (!(phase && typeof phase === "string" && VALID_PHASES.has(phase))) {
return false;
}
const callId = (event as { call_id?: unknown }).call_id;
if (callId && typeof callId === "string") {
if (seen.has(callId)) return false;
seen.add(callId);
}
return true;
})
.map(formatToolCallTrace)
.filter((trace): trace is string => !!trace);