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: delete conversation file on disk + regenerate response button
nash_su56aabf42a345
diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsxindex eaef7511..eddec531 100644--- a/src/components/chat/chat-message.tsx+++ b/src/components/chat/chat-message.tsx@@ -98,9 +98,11 @@ function flattenNames(nodes: FileNode[]): string[] {interface ChatMessageProps {message: DisplayMessage+ isLastAssistant?: boolean+ onRegenerate?: () => void}-export function ChatMessage({ message }: ChatMessageProps) {+export function ChatMessage({ message, isLastAssistant, onRegenerate }: ChatMessageProps) {const isUser = message.role === "user"const isSystem = message.role === "system"const isAssistant = message.role === "assistant"@@ -138,8 +140,20 @@ export function ChatMessage({ message }: ChatMessageProps) {)}</div>{isAssistant && <CitedReferencesPanel content={message.content} savedReferences={message.references} />}- {isAssistant && (- <SaveToWikiButton content={message.content} visible={hovered} />+ {isAssistant && hovered && (+ <div className="flex items-center gap-1">+ <SaveToWikiButton content={message.content} visible={true} />+ {isLastAssistant && onRegenerate && (+ <button+ type="button"+ onClick={onRegenerate}+ className="inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors"+ title="Regenerate this response"+ >+ 🔄 Regenerate+ </button>+ )}+ </div>)}</div></div>diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsxindex f00d4674..0b9648b8 100644--- a/src/components/chat/chat-panel.tsx+++ b/src/components/chat/chat-panel.tsx@@ -7,7 +7,7 @@ import { useChatStore, chatMessagesToLLM } from "@/stores/chat-store"import { useWikiStore } from "@/stores/wiki-store"import { streamChat, type ChatMessage as LLMMessage } from "@/lib/llm-client"import { executeIngestWrites } from "@/lib/ingest"-import { listDirectory, readFile, writeFile } from "@/commands/fs"+import { listDirectory, readFile, writeFile, deleteFile } from "@/commands/fs"import { searchWiki } from "@/lib/search"import { buildRetrievalGraph, getRelatedNodes } from "@/lib/graph-relevance"import { useReviewStore } from "@/stores/review-store"@@ -87,6 +87,11 @@ function ConversationSidebar() {onClick={(e) => {e.stopPropagation()deleteConversation(conv.id)+ // Delete persisted chat file+ const proj = useWikiStore.getState().project+ if (proj) {+ deleteFile(`${proj.path}/.llm-wiki/chats/${conv.id}.json`).catch(() => {})+ }}}><Trash2 className="h-3 w-3" />@@ -122,6 +127,7 @@ export function ChatPanel() {const appendStreamToken = useChatStore((s) => s.appendStreamToken)const finalizeStream = useChatStore((s) => s.finalizeStream)const createConversation = useChatStore((s) => s.createConversation)+ const removeLastAssistantMessage = useChatStore((s) => s.removeLastAssistantMessage)const maxHistoryMessages = useChatStore((s) => s.maxHistoryMessages)// Derive active messages via selector to re-render on message changes@@ -348,6 +354,31 @@ export function ChatPanel() {abortRef.current = null}, [])+ const handleRegenerate = useCallback(async () => {+ if (isStreaming) return+ // Find the last user message in active conversation+ const active = useChatStore.getState().getActiveMessages()+ const lastUserMsg = [...active].reverse().find((m) => m.role === "user")+ if (!lastUserMsg) return+ // Remove the last assistant reply, then re-send+ removeLastAssistantMessage()+ // Small delay to let state update+ await new Promise((r) => setTimeout(r, 50))+ // Trigger send with the same text (handleSend will add a new user message,+ // so also remove the original to avoid duplication)+ // Actually: just call handleSend — but it adds a user message. To avoid dupe,+ // we remove the last user message too and let handleSend re-add it.+ const store = useChatStore.getState()+ const updatedActive = store.getActiveMessages()+ const lastUser = [...updatedActive].reverse().find((m) => m.role === "user")+ if (lastUser) {+ useChatStore.setState((s) => ({+ messages: s.messages.filter((m) => m.id !== lastUser.id),+ }))+ }+ handleSend(lastUserMsg.content)+ }, [isStreaming, removeLastAssistantMessage, handleSend])+const handleWriteToWiki = useCallback(async () => {if (!project) returntry {@@ -386,9 +417,19 @@ export function ChatPanel() {className="flex-1 overflow-y-auto px-3 py-2"><div className="flex flex-col gap-3">- {activeMessages.map((msg) => (- <ChatMessage key={msg.id} message={msg} />- ))}+ {activeMessages.map((msg, idx) => {+ // Check if this is the last assistant message+ const isLastAssistant = msg.role === "assistant" &&+ !activeMessages.slice(idx + 1).some((m) => m.role === "assistant")+ return (+ <ChatMessage+ key={msg.id}+ message={msg}+ isLastAssistant={isLastAssistant && !isStreaming}+ onRegenerate={isLastAssistant ? handleRegenerate : undefined}+ />+ )+ })}{isStreaming && <StreamingMessage content={streamingContent} />}<div ref={bottomRef} /></div>diff --git a/src/stores/chat-store.ts b/src/stores/chat-store.tsindex f47188ff..b15e9f7b 100644--- a/src/stores/chat-store.ts+++ b/src/stores/chat-store.ts@@ -49,6 +49,7 @@ interface ChatState {setIngestSource: (path: string | null) => voidclearMessages: () => voidsetMaxHistoryMessages: (n: number) => void+ removeLastAssistantMessage: () => void // for regenerate: remove last assistant reply// HelpersgetActiveMessages: () => DisplayMessage[]@@ -205,6 +206,20 @@ export const useChatStore = create<ChatState>((set, get) => ({setMaxHistoryMessages: (maxHistoryMessages) => set({ maxHistoryMessages }),+ removeLastAssistantMessage: () =>+ set((state) => {+ const activeId = state.activeConversationId+ if (!activeId) return state+ const activeMessages = state.messages.filter((m) => m.conversationId === activeId)+ // Find last assistant message+ const lastAssistantIdx = [...activeMessages].reverse().findIndex((m) => m.role === "assistant")+ if (lastAssistantIdx === -1) return state+ const msgToRemove = activeMessages[activeMessages.length - 1 - lastAssistantIdx]+ return {+ messages: state.messages.filter((m) => m.id !== msgToRemove.id),+ }+ }),+getActiveMessages: () => {const { messages, activeConversationId } = get()if (!activeConversationId) return []