Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(chat): delete individual messages (Discord #81)

purple99bcca400249
diff --git a/src/components/chat/MessageBubble.tsx b/src/components/chat/MessageBubble.tsx
index f2d45448..ccd85b9d 100644
--- a/src/components/chat/MessageBubble.tsx
+++ b/src/components/chat/MessageBubble.tsx
@@ -1,5 +1,5 @@
import { motion } from 'framer-motion'
-import { User, Copy, Check, Pencil, RefreshCw, X, Wrench } from 'lucide-react'
+import { User, Copy, Check, Pencil, RefreshCw, X, Wrench, Trash2 } from 'lucide-react'
import { useState, useRef, useEffect, useMemo } from 'react'
import { MarkdownRenderer } from './MarkdownRenderer'
import { ThinkingBlock } from './ThinkingBlock'
@@ -35,6 +35,7 @@ export function MessageBubble({ message, onRegenerate, onEdit, pendingApprovalId
const [copied, setCopied] = useState(false)
const [isEditing, setIsEditing] = useState(false)
const [editContent, setEditContent] = useState('')
+ const [confirmDelete, setConfirmDelete] = useState(false)
const editRef = useRef<HTMLTextAreaElement>(null)
const isUser = message.role === 'user'
@@ -43,6 +44,7 @@ export function MessageBubble({ message, onRegenerate, onEdit, pendingApprovalId
// agent mode on. Detect the JSON pattern and show a one-click "Enable
// agent" banner instead of leaving the user staring at a JSON dump.
const activeConversationId = useChatStore((s) => s.activeConversationId)
+ const deleteMessage = useChatStore((s) => s.deleteMessage)
const isAgentActive = useAgentModeStore((s) =>
activeConversationId ? s.agentModeActive[activeConversationId] ?? false : false
)
@@ -115,6 +117,19 @@ export function MessageBubble({ message, onRegenerate, onEdit, pendingApprovalId
setEditContent('')
}
+ // Two-step delete (D#81): first click arms (icon turns red), second within 3s
+ // removes the single message. Guards against an accidental one-click nuke of a
+ // line the user meant to keep.
+ const handleDelete = () => {
+ if (!activeConversationId) return
+ if (!confirmDelete) {
+ setConfirmDelete(true)
+ setTimeout(() => setConfirmDelete(false), 3000)
+ return
+ }
+ deleteMessage(activeConversationId, message.id)
+ }
+
return (
<motion.div
className={'flex gap-2 px-3 py-1 group ' + (isUser ? 'flex-row-reverse' : '')}
@@ -335,6 +350,9 @@ export function MessageBubble({ message, onRegenerate, onEdit, pendingApprovalId
{copied ? <Check size={12} className="text-green-500" /> : <Copy size={12} />}
</button>
{!isUser && <SpeakerButton text={message.content} />}
+ <button onClick={handleDelete} className={'p-1 rounded-md transition-colors hover:bg-gray-100 dark:hover:bg-white/10 ' + (confirmDelete ? 'text-red-500' : 'text-gray-400 dark:text-gray-500 hover:text-red-500')} aria-label="Delete message" title={confirmDelete ? 'Click again to delete' : 'Delete message'}>
+ <Trash2 size={12} />
+ </button>
</div>
)}
diff --git a/src/stores/chatStore.ts b/src/stores/chatStore.ts
index 5d3faa76..ab4bb88a 100644
--- a/src/stores/chatStore.ts
+++ b/src/stores/chatStore.ts
@@ -48,6 +48,10 @@ interface ChatState {
updateMessageAgentBlocks: (conversationId: string, messageId: string, blocks: AgentBlock[]) => void
updateMessageArtifacts: (conversationId: string, messageId: string, artifacts: ChatArtifact[]) => void
deleteMessagesAfter: (conversationId: string, messageId: string) => void
+ /** Remove a single message by id (D#81). Leaves the rest of the thread intact,
+ * so the user can prune one line from the model's context without nuking the
+ * whole chat or truncating everything after it. */
+ deleteMessage: (conversationId: string, messageId: string) => void
getActiveConversation: () => Conversation | undefined
searchConversations: (query: string) => Conversation[]
/** Bulk-import conversations from an exported backup (konata 2026-06-28: the
@@ -244,6 +248,19 @@ export const useChatStore = create<ChatState>()(
}),
})),
+ deleteMessage: (conversationId, messageId) =>
+ set((state) => ({
+ conversations: state.conversations.map((c) =>
+ c.id === conversationId
+ ? {
+ ...c,
+ messages: c.messages.filter((m) => m.id !== messageId),
+ updatedAt: Date.now(),
+ }
+ : c
+ ),
+ })),
+
getActiveConversation: () => {
const { conversations, activeConversationId } = get()
return conversations.find((c) => c.id === activeConversationId)