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): show a waiting tool call as its line and a hand icon
Elian Doran6588ccad41aa
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex ebd9de1f08..a2966d65f9 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2695,7 +2695,6 @@"tool_approval_prompt": "Allow this tool call?","tool_approval_allow": "Allow","tool_approval_deny": "Deny",- "tool_approval_pending": "waiting for approval","tool_approval_declined": "denied"},"sidebar_chat": {diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.cssindex c665fa9163..160aaed19e 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css@@ -67,8 +67,7 @@overflow-wrap: anywhere;}-.llm-chat-tool-call-streaming,-.llm-chat-tool-call-input {+.llm-chat-tool-call-streaming {margin: 0;max-height: 300px;overflow: auto;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 155ec01197..46a5bff1c0 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@@ -781,14 +781,15 @@ describe("ToolCallCard", () => {const buttons = (target: HTMLElement) =>[ ...target.querySelectorAll<HTMLButtonElement>(".llm-chat-tool-approval button") ];- it("opens a waiting call on its input, and answers it from the buttons below", () => {+ it("shows a waiting call with nothing to preview as its line, and answers it from the buttons below", () => {const answer = vi.fn();const target = renderCard([ PENDING ], answer);- const line = target.querySelector<HTMLDetailsElement>("details.llm-chat-tool-call");- expect(line?.open).toBe(true);- expect(JSON.parse(line?.querySelector(".llm-chat-tool-call-input")?.textContent ?? "null")).toEqual(PENDING.input);- expect(line?.querySelector(".llm-chat-tool-call-approval-badge")?.textContent).toBe("llm_chat.tool_approval_pending");+ const line = target.querySelector(".llm-chat-tool-call-pending > .llm-chat-tool-call");+ expect(line?.classList.contains("expandable-line")).toBe(true);+ expect(line?.querySelector("pre")).toBeNull();+ expect(line?.querySelector(".llm-chat-tool-call-approval-badge")).toBeNull();+ expect(line?.querySelector(".bxs-hand")).not.toBeNull();const [ deny, allow ] = buttons(target);expect([ deny?.textContent?.trim(), allow?.textContent?.trim() ]).toEqual([ "llm_chat.tool_approval_deny", "llm_chat.tool_approval_allow" ]);@@ -798,12 +799,12 @@ describe("ToolCallCard", () => {expect(answer).toHaveBeenLastCalledWith("c1", false);});- it("shows what a waiting writing call would write instead of its raw input", () => {+ it("opens a waiting writing call on what it would write", () => {const target = renderCard([ {id: "c1", toolName: "create_note", input: { parentNoteId: "p", title: "T", type: "code", mime: "text/plain", content: "hello" }, approval: "pending"} ], vi.fn());expect(target.querySelector(".code-block-stub")?.textContent).toBe("hello");- expect(target.querySelector(".llm-chat-tool-call-input")).toBeNull();+ expect(target.querySelector<HTMLDetailsElement>("details.llm-chat-tool-call")?.open).toBe(true);expect(buttons(target)).toHaveLength(2);});diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsxindex 5cdf65aa33..719216cf11 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx@@ -122,7 +122,7 @@ function toolNameIcon(toolName: string): string {}function toolCallIcon(toolCall: ToolCall) {- if (toolCall.approval === "pending") return "bx bx-help-circle";+ if (toolCall.approval === "pending") return "bx bxs-hand";if (toolCall.approval === "declined") return "bx bx-block";if (isFailedToolCall(toolCall)) return "bx bx-error-circle";if (!toolCall.result) return "bx bx-loader-alt bx-spin";@@ -192,11 +192,9 @@ function ToolCallLabel({ toolCall, view }: { toolCall: ToolCall; view: ToolCallV</span>)}{view?.summary && <span className="llm-chat-tool-call-result-count">{view.summary}</span>}- {toolCall.approval && (+ {toolCall.approval === "declined" && (<span className="llm-chat-tool-call-approval-badge">- {toolCall.approval === "pending"- ? t("llm_chat.tool_approval_pending")- : t("llm_chat.tool_approval_declined")}+ {t("llm_chat.tool_approval_declined")}</span>)}{hasError && <span className="llm-chat-tool-call-error-badge">{t("llm_chat.tool_error")}</span>}@@ -260,10 +258,6 @@ function ToolCallDisclosure({ toolCall }: { toolCall: ToolCall }) {const editedNoteId = typeof toolCall.input.noteId === "string" ? toolCall.input.noteId : undefined;const errorMessage = hasError && toolCall.result ? getErrorMessage(toolCall.result) : null;const view = isStreamingInput ? null : getToolCallView(toolCall);- // A waiting call with nothing else to show what it would do shows its input.- const pendingInput = isPending && !noteContentEdits && !view?.body- ? JSON.stringify(toolCall.input, null, 2)- : null;const className = `llm-chat-tool-call ${hasError ? "llm-chat-tool-call-error" : ""}`;const icon = toolCallIcon(toolCall);@@ -272,7 +266,7 @@ function ToolCallDisclosure({ toolCall }: { toolCall: ToolCall }) {const open = isPending|| (noteContentEdits ? isSmallEdit(noteContentEdits) : isStreamingInput || undefined);- if (!isStreamingInput && !noteContentEdits && !errorMessage && !view?.body && !pendingInput) {+ if (!isStreamingInput && !noteContentEdits && !errorMessage && !view?.body) {return (<div className={`expandable-line ${className}`}><div className="expandable-line-header">@@ -301,7 +295,6 @@ function ToolCallDisclosure({ toolCall }: { toolCall: ToolCall }) {)}{errorMessage && <p className="llm-chat-tool-call-error-message">{errorMessage}</p>}{view?.body}- {pendingInput && <pre className="llm-chat-tool-call-input">{pendingInput}</pre>}</ExpandableSection>);}@@ -330,7 +323,7 @@ function ToolCallGroupSection({ toolCalls }: { toolCalls: ToolCall[] }) {const anyError = toolCalls.some(isFailedToolCall);const searchProvider = readSearchProvider(first);- const icon = anyAwaitingApproval ? "bx bx-help-circle"+ const icon = anyAwaitingApproval ? "bx bxs-hand": anyPending ? "bx bx-loader-alt bx-spin": searchProvider && toolCalls.every(tc => readSearchProvider(tc)?.type === searchProvider.type)? <SearchProviderIcon {...searchProvider} />diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.htmlindex 90fe18ccba..26ec30502a 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html@@ -264,10 +264,10 @@appears under it until the next part of the reply arrives.</p><h4>Approving tool calls</h4><p>Before the AI runs a tool, the chat asks whether to allow it. The tool's- line opens on what the call would do (the text it would write, the changes- of an edit, or else the values it would send to the tool), with <em>Allow</em> and <em>Deny</em> buttons- below it and <em>waiting for approval</em> beside the tool's name. The reply- waits until you answer.</p>+ line is marked with a <span class="tn-icon bx bxs-hand"></span> icon and+ has <em>Allow</em> and <em>Deny</em> buttons below it. When the call would+ write to a note, the line opens on the text it would write or the changes+ of an edit. The reply waits until you answer.</p><ul><li>To let the call run, press <em>Allow</em>.</li><li>To refuse it, press <em>Deny</em>. The AI is told that you declined, anddiff --git a/docs/User Guide/User Guide/AI.md b/docs/User Guide/User Guide/AI.mdindex a2e778acb2..60a4108f3b 100644--- a/docs/User Guide/User Guide/AI.md+++ b/docs/User Guide/User Guide/AI.md@@ -158,7 +158,7 @@ When the reply stops moving for a couple of seconds while the AI is still at wor#### Approving tool calls-Before the AI runs a tool, the chat asks whether to allow it. The tool's line opens on what the call would do (the text it would write, the changes of an edit, or else the values it would send to the tool), with _Allow_ and _Deny_ buttons below it and _waiting for approval_ beside the tool's name. The reply waits until you answer.+Before the AI runs a tool, the chat asks whether to allow it. The tool's line is marked with a <span class="tn-icon bx bxs-hand"></span> icon and has _Allow_ and _Deny_ buttons below it. When the call would write to a note, the line opens on the text it would write or the changes of an edit. The reply waits until you answer.* To let the call run, press _Allow_.* To refuse it, press _Deny_. The AI is told that you declined, and its reply carries on without the call, which is marked _denied_.