Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

feat: @filename source references with click-to-preview

nash_su97975ae15340
diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsx
index e8ecf2e9..6d53d0c4 100644
--- a/src/components/chat/chat-message.tsx
+++ b/src/components/chat/chat-message.tsx
@@ -75,6 +75,10 @@ function MarkdownContent({ content }: { content: string }) {
const pageName = href.slice("wikilink:".length)
return <WikiLink pageName={pageName}>{children}</WikiLink>
}
+ if (href?.startsWith("sourceref:")) {
+ const fileName = href.slice("sourceref:".length)
+ return <SourceRef fileName={fileName} />
+ }
return <a href={href} {...props} target="_blank" rel="noopener noreferrer">{children}</a>
},
// Compact code blocks
@@ -90,18 +94,54 @@ function MarkdownContent({ content }: { content: string }) {
}
/**
- * Convert [[wikilink]] syntax to markdown links that our custom renderer can handle.
- * [[page-name]] → [page-name](wikilink:page-name)
- * [[page-name|display text]] → [display text](wikilink:page-name)
+ * Process special link syntax in LLM responses:
+ * - [[page-name]] → [page-name](wikilink:page-name)
+ * - @filename.pdf → [@filename.pdf](sourceref:filename.pdf)
*/
function processWikiLinks(text: string): string {
- return text.replace(
+ // Process [[wikilinks]]
+ let result = text.replace(
/\[\[([^\]|]+?)(?:\|([^\]]+?))?\]\]/g,
(_match, pageName: string, displayText?: string) => {
const display = displayText?.trim() || pageName.trim()
return `[${display}](wikilink:${pageName.trim()})`
}
)
+
+ // Process @filename references (but not inside markdown links or code blocks)
+ // Match @filename at word boundary, supporting extensions like .pdf, .md, .txt
+ result = result.replace(
+ /(?<!\[)@([\w.-]+\.[\w]+)/g,
+ (_match, fileName: string) => {
+ return `[@${fileName}](sourceref:${fileName})`
+ }
+ )
+
+ return result
+}
+
+function SourceRef({ fileName }: { fileName: string }) {
+ const project = useWikiStore((s) => s.project)
+ const setSelectedFile = useWikiStore((s) => s.setSelectedFile)
+ const setActiveView = useWikiStore((s) => s.setActiveView)
+
+ const handleClick = useCallback(() => {
+ if (!project) return
+ const path = `${project.path}/raw/sources/${fileName}`
+ setSelectedFile(path)
+ setActiveView("wiki")
+ }, [project, fileName, setSelectedFile, setActiveView])
+
+ return (
+ <button
+ onClick={handleClick}
+ className="inline-flex items-center gap-0.5 rounded bg-accent/50 px-1.5 py-0.5 text-xs font-medium text-primary hover:bg-accent"
+ title={`Open source: ${fileName}`}
+ >
+ <span className="text-muted-foreground">@</span>
+ {fileName}
+ </button>
+ )
}
function WikiLink({ pageName, children }: { pageName: string; children: React.ReactNode }) {
diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsx
index 6807655b..b107e3f7 100644
--- a/src/components/chat/chat-panel.tsx
+++ b/src/components/chat/chat-panel.tsx
@@ -68,10 +68,11 @@ export function ChatPanel() {
"",
"## Citation Rules (CRITICAL)",
"- Your answers are derived from the user's uploaded source documents.",
- "- At the end of your answer, under '**References:**', list ONLY the actual source files (from the Source Files list below) that your answer draws from.",
- "- Use the exact file names from the list. NEVER invent file names.",
+ "- At the end of your answer, under '**References:**', list the source files your answer draws from.",
+ "- Reference format: use @filename exactly as listed below (e.g., @2603.25723v1.pdf). One per line.",
+ "- Use the EXACT original file names. NEVER rename, paraphrase, or invent file names.",
"- If the wiki doesn't have enough information to answer, say so honestly.",
- "- You may use [[wikilink]] syntax to reference wiki pages listed in the index.",
+ "- You may also use [[wikilink]] syntax to reference wiki pages in the index.",
"",
"Use markdown formatting for clarity.",
"",