fix(chat): keep tool totals neutral and count individual errors
This commit is contained in:
@@ -235,6 +235,11 @@ export function toolCallCount(parts) {
|
||||
return (parts ?? []).filter((part) => part?.type === PART_TOOL).length;
|
||||
}
|
||||
|
||||
/** Errors belong to individual calls, not the entire turn's tool total. */
|
||||
export function toolFailureCount(parts) {
|
||||
return (parts ?? []).filter((part) => part?.type === PART_TOOL && toolFailed(part.state)).length;
|
||||
}
|
||||
|
||||
/** True while any tool call in [parts] is still in flight. */
|
||||
export function toolsRunning(parts) {
|
||||
return (parts ?? []).some((part) => toolRunning(part));
|
||||
|
||||
@@ -163,7 +163,7 @@ import {
|
||||
toolCallsAnnouncement,
|
||||
toolCallsLabel,
|
||||
toolDetail,
|
||||
toolFailed,
|
||||
toolFailureCount,
|
||||
toolLabel,
|
||||
toolLongRunning,
|
||||
toolRunning,
|
||||
@@ -3517,24 +3517,26 @@ function renderChatToolChip(turn, { streaming = false, elapsedMillis = () => 0 }
|
||||
if (parts.length === 0) return null;
|
||||
const count = toolCallCount(turn.parts);
|
||||
const running = streaming && toolsRunning(turn.parts);
|
||||
const failed = parts.some((part) => toolFailed(part.state));
|
||||
const errors = toolFailureCount(turn.parts);
|
||||
const errorLabel = errors === 1 ? "1 error" : `${errors} errors`;
|
||||
const long = running && parts.some((part) => toolRunning(part) && toolLongRunning(elapsedMillis(part)));
|
||||
const chip = h("button", {
|
||||
class: `chip chat-tool-chip${failed ? " chat-tool-chip-failed" : ""}`,
|
||||
class: "chat-tool-chip",
|
||||
type: "button",
|
||||
"aria-label": toolCallsAnnouncement(count),
|
||||
"aria-label": `${toolCallsAnnouncement(count)}${errors ? `, ${errorLabel}` : ""}`,
|
||||
"aria-expanded": "false",
|
||||
"aria-haspopup": "dialog",
|
||||
});
|
||||
const currentTool = running ? parts.filter((part) => toolRunning(part)).at(-1) ?? null : null;
|
||||
chip.append(
|
||||
h("span", {
|
||||
class: `chat-tool-icon${failed ? " chat-tool-icon-failed" : ""}`,
|
||||
class: "chat-tool-icon",
|
||||
"aria-hidden": "true",
|
||||
text: failed ? "\u26a0" : "\u29c9",
|
||||
text: "\u29c9",
|
||||
}),
|
||||
);
|
||||
chip.append(h("span", { class: "chat-tool-label", text: toolCallsLabel(count) }));
|
||||
if (errors) chip.append(h("span", { class: "chat-tool-error-count", text: `· ${errorLabel}` }));
|
||||
if (currentTool) {
|
||||
const detail = toolDetail(currentTool);
|
||||
const name = toolLabel(currentTool);
|
||||
|
||||
Reference in New Issue
Block a user