diff --git a/eslint.config.mjs b/eslint.config.mjs index fb235290..1b7ad4e4 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -74,7 +74,7 @@ export default [ // obsidianmd: defer to follow-up PRs "obsidianmd/vault/iterate": "error", - "obsidianmd/prefer-active-doc": "off", + "obsidianmd/prefer-active-doc": "error", "obsidianmd/object-assign": "off", "obsidianmd/ui/sentence-case": "off", "obsidianmd/no-unsupported-api": "off", diff --git a/src/components/chat-components/RelevantNotes.tsx b/src/components/chat-components/RelevantNotes.tsx index 117f432a..43926fd1 100644 --- a/src/components/chat-components/RelevantNotes.tsx +++ b/src/components/chat-components/RelevantNotes.tsx @@ -112,7 +112,7 @@ function RelevantNote({ const loadContent = useCallback(async () => { if (fileContent) return; // Don't load if we already have content - const file = app.vault.getAbstractFileByPath(note.document.path); + const file = app.vault.getAbstractFileByPath(note.note.path); if (file instanceof TFile) { const content = await app.vault.cachedRead(file); @@ -128,7 +128,7 @@ function RelevantNote({ // Take first 1000 characters as preview setFileContent(cleanContent.slice(0, 1000) + (cleanContent.length > 1000 ? "..." : "")); } - }, [fileContent, note.document.path]); + }, [fileContent, note.note.path]); useEffect(() => { if (isOpen) { @@ -161,7 +161,7 @@ function RelevantNote({ { - const file = app.vault.getAbstractFileByPath(note.document.path); + const file = app.vault.getAbstractFileByPath(note.note.path); if (file instanceof TFile) { handleDragStart(e, file); } @@ -179,9 +179,9 @@ function RelevantNote({ } }} className="tw-block tw-w-full tw-truncate tw-text-sm tw-font-bold tw-text-normal" - title={`${note.document.title} - drag to insert wikilink`} + title={`${note.note.title} - drag to insert wikilink`} > - {note.document.title} + {note.note.title} @@ -198,7 +198,7 @@ function RelevantNote({ - {note.document.path} + {note.note.path} {fileContent && ( @@ -243,11 +243,11 @@ function RelevantNotePopover({ children: React.ReactNode; }) { return ( - + {children} - {note.document.title} - {note.document.path} + {note.note.title} + {note.note.path} {relevantNotes.map((note) => ( addToChat(note.document.title)} + onAddToChat={() => addToChat(note.note.title)} onNavigateToNote={(openInNewLeaf: boolean) => - navigateToNote(note.document.path, openInNewLeaf) + navigateToNote(note.note.path, openInNewLeaf) } > { - const file = app.vault.getAbstractFileByPath(note.document.path); + const file = app.vault.getAbstractFileByPath(note.note.path); if (file instanceof TFile) { handleDragStart(e, file); } }} className="tw-max-w-40 tw-text-xs tw-text-muted hover:tw-cursor-pointer hover:tw-bg-interactive-hover" - title={`${note.document.title} - drag to insert wikilink`} + title={`${note.note.title} - drag to insert wikilink`} > - {note.document.title} + {note.note.title} ))} @@ -411,10 +411,10 @@ export const RelevantNotes = memo( {relevantNotes.map((note) => ( addToChat(note.document.title)} + key={note.note.path} + onAddToChat={() => addToChat(note.note.title)} onNavigateToNote={(openInNewLeaf: boolean) => - navigateToNote(note.document.path, openInNewLeaf) + navigateToNote(note.note.path, openInNewLeaf) } /> ))} diff --git a/src/search/findRelevantNotes.test.ts b/src/search/findRelevantNotes.test.ts index eb4e1b9d..8b5a5662 100644 --- a/src/search/findRelevantNotes.test.ts +++ b/src/search/findRelevantNotes.test.ts @@ -177,14 +177,14 @@ describe("findRelevantNotes", () => { const result = await findRelevantNotes({ filePath: "source.md" }); - expect(result.map((entry) => entry.document.path)).toEqual([ + expect(result.map((entry) => entry.note.path)).toEqual([ "second.md", "first.md", "linked-only.md", ]); - expect( - result.find((entry) => entry.document.path === "second.md")?.metadata.similarityScore - ).toBe(0.82); + expect(result.find((entry) => entry.note.path === "second.md")?.metadata.similarityScore).toBe( + 0.82 + ); expect(mockGetDb).toHaveBeenCalledTimes(1); expect(mockGetDocsByEmbedding).toHaveBeenCalledTimes(2); expect(mockSearchRelated).not.toHaveBeenCalled(); @@ -224,10 +224,10 @@ describe("findRelevantNotes", () => { const result = await findRelevantNotes({ filePath: "source.md" }); - expect(result.map((entry) => entry.document.path)).toEqual(["beta.md", "alpha.md"]); - expect( - result.find((entry) => entry.document.path === "alpha.md")?.metadata.similarityScore - ).toBe(0.6); + expect(result.map((entry) => entry.note.path)).toEqual(["beta.md", "alpha.md"]); + expect(result.find((entry) => entry.note.path === "alpha.md")?.metadata.similarityScore).toBe( + 0.6 + ); expect(mockGetDb).not.toHaveBeenCalled(); expect(mockGetDocumentsByPath).not.toHaveBeenCalled(); expect(mockSearchRelated).toHaveBeenCalledTimes(1); @@ -259,7 +259,7 @@ describe("findRelevantNotes", () => { const result = await findRelevantNotes({ filePath: "source.md" }); - expect(result.map((e) => e.document.path)).toEqual(["alpha.md"]); + expect(result.map((e) => e.note.path)).toEqual(["alpha.md"]); expect(result[0].metadata.similarityScore).toBe(0.75); // Orama path not taken (no embeddings); Miyo called as fallback expect(mockGetDocsByEmbedding).not.toHaveBeenCalled(); @@ -289,7 +289,7 @@ describe("findRelevantNotes", () => { const result = await findRelevantNotes({ filePath: "source.md" }); expect(result).toHaveLength(1); - expect(result[0].document.path).toBe("linked-only.md"); + expect(result[0].note.path).toBe("linked-only.md"); expect(result[0].metadata.similarityScore).toBeUndefined(); expect(result[0].metadata.hasOutgoingLinks).toBe(true); expect(mockGetDocumentsByPath).not.toHaveBeenCalled(); diff --git a/src/search/findRelevantNotes.ts b/src/search/findRelevantNotes.ts index 75dee2d3..094dd55a 100644 --- a/src/search/findRelevantNotes.ts +++ b/src/search/findRelevantNotes.ts @@ -276,7 +276,7 @@ function mergeScoreMaps( } export type RelevantNoteEntry = { - document: { + note: { path: string; title: string; }; @@ -327,7 +327,7 @@ export async function findRelevantNotes({ return null; } return { - document: { + note: { path, title: file.basename, },