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): name the attribute a delete_attribute call would delete
Elian Doranb722d6085a33
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 f64d93ad84..3d8427fa64 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@@ -16,7 +16,7 @@ vi.mock("react-i18next", () => ({const mocks = vi.hoisted(() => ({triggerEvent: vi.fn(),openInAppHelpFromUrl: vi.fn(),- notes: {} as Record<string, { type: string; mime: string }>+ notes: {} as Record<string, { type: string; mime: string; getOwnedAttributes?: () => object[] }>}));vi.mock("../../../components/app_context.js", () => ({ default: { triggerEvent: mocks.triggerEvent } }));vi.mock("../../../services/utils.js", async (importOriginal) => ({@@ -520,6 +520,25 @@ describe("ToolCallCard", () => {expect(ref?.querySelector(".llm-chat-tool-call-created-title")?.textContent).toBe("Draft");});+ it("names the attribute a delete_attribute call would delete, from the note, before the call runs", () => {+ mocks.notes = {+ n: {+ type: "text", mime: "text/html",+ getOwnedAttributes: () => [ { attributeId: "a1", type: "label", name: "iconClass", value: "bx bx-rocket" } ]+ }+ };+ const call = (id: string, attributeId: string): ToolCall => ({ id, toolName: "delete_attribute", input: { noteId: "n", attributeId } });+ const target = renderCard([ call("1", "a1"), { id: "2", toolName: "get_note", input: { noteId: "x" }, result: "{}" }, call("3", "gone") ]);+ const [ known, , unknown ] = [ ...(target.querySelector(".llm-chat-tool-calls")?.children ?? []) ];++ const pill = known?.querySelector(".llm-chat-attribute");+ expect(pill?.textContent).toBe("#iconClass=\"bx bx-rocket\"");+ expect(pill?.classList.contains("llm-chat-attribute-deleted")).toBe(true);+ expect(unknown?.querySelector(".llm-chat-attribute")).toBeNull();+ expect(unknown?.querySelector(".note-link-stub")?.textContent).toBe("n");+ mocks.notes = {};+ });+it("names the title a rename would give, after the note link, before the call runs", () => {const target = renderCard([ { id: "1", toolName: "rename_note", input: { noteId: "n", newTitle: "New" } } ]);const newTitle = target.querySelector(".llm-chat-tool-call-new-title");diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.tsxindex a9dbec17a3..4cf8c76b1e 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.tsx@@ -73,6 +73,13 @@ export function getToolCallView(toolCall: ToolCall): ToolCallView | null {: null;}+ if (toolCall.toolName === "delete_attribute" && !toolCall.result) {+ const { noteId, attributeId } = toolCall.input;+ return typeof noteId === "string" && typeof attributeId === "string"+ ? { lead: <OwnedAttributePill noteId={noteId} attributeId={attributeId} deleted /> }+ : null;+ }+if (!toolCall.result) return null;switch (toolCall.toolName) {@@ -577,6 +584,22 @@ function AttributePill({ type, name, value, deleted }: NoteMetaAttribute & { delreturn <span className={className}>#{name}{value && `=${formatValue(value)}`}</span>;}+/**+ * The pill of an attribute of `noteId` as froca holds it, for a call whose input names the attribute+ * only by its ID. Nothing shows when the note does not own the attribute.+ */+function OwnedAttributePill({ noteId, attributeId, deleted }: {+ noteId: string;+ attributeId: string;+ deleted?: boolean;+}) {+ const note = useNote(noteId);+ const attribute = note?.getOwnedAttributes().find(attr => attr.attributeId === attributeId);+ if (!attribute) return null;+ const { type, name, value } = attribute;+ return <AttributePill type={type} name={name} value={value} deleted={deleted} />;+}+function parseAttributeList(result: string): NoteMetaAttribute[] | null {const parsed = parseJson(result);if (!Array.isArray(parsed)) return null;