chatStreamEvent gained a Failed bool, set from ToolCallEvent.Err != "" -- the field the rest of the codebase already treats as authoritative -- rather than the browser sniffing summary.startsWith "failed:" on rendered text. A successful tool whose own output starts with that literal string (a grep hit, a log line read back) was being styled as a failed step.
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
import { el } from "../base/dom.js";
|
|
|
|
// Tool activity is rendered into its own list inside the assistant bubble
|
|
// rather than folded into the reply text: the text node is replaced wholesale
|
|
// on every streamed frame, and again on the final reply, so anything written
|
|
// into it is lost the next time the answer grows.
|
|
//
|
|
// The list is part of the bubble from the start (see assistantBubble) and
|
|
// sits above the reply, matching the shape the same turn takes in Telegram:
|
|
// the work first, then the answer built from it.
|
|
export function appendToolCall(host, event) {
|
|
const name = event?.tool ?? "";
|
|
if (!host || !name) return null;
|
|
|
|
const parameters = event.parameters ?? "";
|
|
const summary = event.text ?? "";
|
|
const line = el(
|
|
"div.chat-tool",
|
|
el("span.chat-tool-icon", "🔧"),
|
|
el("span.chat-tool-name", name),
|
|
parameters && el("code.chat-tool-parameters", parameters),
|
|
el("span.chat-tool-summary", summary),
|
|
);
|
|
// A failure reads as a completed step unless it is marked as one. Styled
|
|
// from the structured `failed` field the server sends, not by sniffing
|
|
// the summary text: a successful tool can print output that itself starts
|
|
// with "failed:" (e.g. a grep hit, a log line), which a string prefix
|
|
// check would misread as the tool call itself having failed.
|
|
if (event.failed) line.className = "chat-tool failed";
|
|
|
|
toolList(host).append(line);
|
|
return line;
|
|
}
|
|
|
|
// toolList returns the bubble's tool list. A bubble built elsewhere may not
|
|
// have one, in which case the list is appended rather than dropped -- tool
|
|
// activity out of position still beats tool activity nowhere.
|
|
function toolList(host) {
|
|
const existing = host.querySelector(".chat-tools");
|
|
if (existing) return existing;
|
|
const list = el("div.chat-tools");
|
|
host.append(list);
|
|
return list;
|
|
}
|