Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(llm_chat): keep a tool call that waits for approval out of a group
Elian Doran0d51b1a6407d
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.spec.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.spec.tsxindex 3d8427fa64..75c28a2c86 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.spec.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.spec.tsx@@ -842,9 +842,13 @@ describe("ToolCallCard", () => {expect(buttons(target)).toHaveLength(2);});- it("opens a group holding a waiting call, and offers no buttons outside the streaming reply", () => {- const target = renderCard([ { ...PENDING, id: "c0", approval: undefined, result: "{}" }, PENDING ]);- expect(target.querySelector<HTMLDetailsElement>("details.llm-chat-tool-call-group")?.open).toBe(true);+ it("keeps a waiting call out of the group of its tool, and offers no buttons outside the streaming reply", () => {+ const done = (id: string): ToolCall => ({ ...PENDING, id, approval: undefined, result: "{}" });+ const target = renderCard([ done("c0"), done("c1"), PENDING, { ...PENDING, id: "c2", approval: undefined } ]);+ const lines = [ ...(target.querySelector(".llm-chat-tool-calls")?.children ?? []) ];+ expect(lines.map(line => line.classList.contains("llm-chat-tool-call-group"))).toEqual([ true, false, false ]);+ expect(lines[1]?.classList.contains("llm-chat-tool-call-pending")).toBe(true);+ expect(target.querySelector(".llm-chat-tool-call-group .llm-chat-tool-call-pending")).toBeNull();expect(target.querySelector(".llm-chat-tool-approval")).toBeNull();});diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsxindex fd443071f1..be12957485 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx@@ -339,12 +339,10 @@ function ToolCallDebugButton({ toolCall }: { toolCall: ToolCall }) {function ToolCallGroupSection({ toolCalls }: { toolCalls: ToolCall[] }) {const first = toolCalls[0];const anyPending = toolCalls.some(tc => !tc.result);- const anyAwaitingApproval = toolCalls.some(tc => tc.approval === "pending");const anyError = toolCalls.some(isFailedToolCall);const searchProvider = readSearchProvider(first);- const icon = anyAwaitingApproval ? "bx bxs-hand"- : anyPending ? "bx bx-loader-alt bx-spin"+ const icon = anyPending ? "bx bx-loader-alt bx-spin": searchProvider && toolCalls.every(tc => readSearchProvider(tc)?.type === searchProvider.type)? <SearchProviderIcon {...searchProvider} />: toolNameIcon(first.toolName);@@ -363,7 +361,6 @@ function ToolCallGroupSection({ toolCalls }: { toolCalls: ToolCall[] }) {icon={icon}label={label}className="llm-chat-tool-call llm-chat-tool-call-group"- open={anyAwaitingApproval || undefined}>{toolCalls.map((tc, idx) => (<ToolCallSection key={tc.id ?? idx} toolCall={tc} />@@ -372,12 +369,17 @@ function ToolCallGroupSection({ toolCalls }: { toolCalls: ToolCall[] }) {);}-/** Group consecutive tool calls that share the same tool name. Singletons pass through unchanged. */+/**+ * Group consecutive tool calls that share the same tool name. Singletons pass through unchanged, and+ * a call that waits for approval stays out of any group.+ */function groupByToolName(toolCalls: ToolCall[]): Array<ToolCall | ToolCall[]> {const groups: Array<ToolCall | ToolCall[]> = [];for (const tc of toolCalls) {const last = groups[groups.length - 1];- if (Array.isArray(last) && last[0].toolName === tc.toolName) {+ if (tc.approval === "pending" || (last && !Array.isArray(last) && last.approval === "pending")) {+ groups.push(tc);+ } else if (Array.isArray(last) && last[0].toolName === tc.toolName) {last.push(tc);} else if (last && !Array.isArray(last) && last.toolName === tc.toolName) {groups[groups.length - 1] = [last, tc];