fix: print the running tool once, not twice (#17)

This commit was merged in pull request #17.
This commit is contained in:
2026-10-05 09:49:39 +00:00
parent 26e05dea5b
commit ff99778e5d
7 changed files with 198 additions and 34 deletions
+19 -1
View File
@@ -1,4 +1,4 @@
import type { ChatTurn, ThreadMessage } from "./types";
import type { ChatTurn, ThreadMessage, ToolActivity } from "./types";
/**
* Flattens stored turns into the flat message list the transcript renders.
@@ -15,6 +15,20 @@ export interface LiveState {
thinking: string;
/** Activity line, e.g. "Searching the web". Only meaningful mid-turn. */
status?: string;
/** The tool being waited on right now, which supersedes the plain status when present. */
activity?: ToolActivity;
}
/**
* One line describing a tool that is running.
*
* Says "the same call again" rather than showing a bare count, because a number
* on its own reads as progress. This is the visible half of the loop guard in
* `agent.ts`, and the only warning the user gets before a turn is cut short.
*/
export function describeActivity(activity: ToolActivity): string {
if (activity.count <= 1) return activity.label;
return `${activity.label} · the same call again (${activity.count})`;
}
export function buildThread(turns: ChatTurn[], live: LiveState): ThreadMessage[] {
@@ -43,6 +57,10 @@ export function buildThread(turns: ChatTurn[], live: LiveState): ThreadMessage[]
// Only while there is nothing to read yet. Once tokens land, the
// placeholder it feeds is gone anyway.
status: isLive && text.length === 0 ? live.status : undefined,
// The tool, on the other hand, is worth naming even after the answer has
// started arriving: a tool that begins mid-answer would otherwise be
// invisible, which was the original complaint about hidden tool calls.
activity: isLive ? live.activity : undefined,
// Only a question carries attachments, so the answer never has one.
attachments: [],
});