The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a stopped reply keeps its stopped mark when its stored copy folds into the tool bubble
Tekniumac013c58c934
diff --git a/apps/desktop/src/lib/chat-messages.stopped-tool-fold.test.ts b/apps/desktop/src/lib/chat-messages.stopped-tool-fold.test.tsnew file mode 100644index 00000000000..56da1eb8ad9--- /dev/null+++ b/apps/desktop/src/lib/chat-messages.stopped-tool-fold.test.ts@@ -0,0 +1,39 @@+import { describe, expect, it } from 'vitest'++import type { SessionMessage } from '@/types/hermes'++import { chatMessageText, toChatMessages } from './chat-messages'++// A turn stopped after a tool round is stored as narration + tool call, the+// tool result, then the interrupted partial. The partial folds into the tool+// bubble on read; the stored copy that replaces the live one (any refresh)+// must still say the reply was stopped.+describe('stopped reply folded into its tool bubble', () => {+ const rows: SessionMessage[] = [+ { id: 1, role: 'user', content: 'look it up', timestamp: 1 },+ {+ id: 2,+ role: 'assistant',+ content: 'Looking.',+ timestamp: 2,+ tool_calls: [{ id: 'call-1', type: 'function', function: { name: 'terminal', arguments: '{}' } }]+ },+ { id: 3, role: 'tool', content: 'ok', tool_call_id: 'call-1', timestamp: 3 },+ { id: 4, role: 'assistant', content: 'The answer is', timestamp: 4, display_metadata: '{"interrupted": true}' }+ ]++ it('keeps the stopped mark of the interrupted row it absorbs', () => {+ const replies = toChatMessages(rows).filter(message => message.role === 'assistant')++ expect(replies).toHaveLength(1)+ expect(chatMessageText(replies[0])).toContain('The answer is')+ expect(replies[0].interrupted).toBe(true)+ })++ it('leaves a finished tool turn unmarked', () => {+ const finished = rows.map(row => (row.id === 4 ? { ...row, display_metadata: undefined } : row))+ const replies = toChatMessages(finished).filter(message => message.role === 'assistant')++ expect(replies.map(message => message.interrupted)).toEqual([undefined])+ })+})diff --git a/apps/desktop/src/lib/chat-messages/hydration.ts b/apps/desktop/src/lib/chat-messages/hydration.tsindex 57a7883e26b..54d0abc026d 100644--- a/apps/desktop/src/lib/chat-messages/hydration.ts+++ b/apps/desktop/src/lib/chat-messages/hydration.ts@@ -244,6 +244,22 @@ function messageInterrupted(metadata: SessionMessage['display_metadata']): boolereturn parseDisplayMetadata(metadata)?.interrupted === true}+/** An assistant row read into the tool bubble before it. A reply stopped after a+ * tool round folds in here, and its row still says the reply was stopped. */+function foldIntoToolBubble(+ bubble: ChatMessage,+ message: SessionMessage,+ parts: ChatMessagePart[],+ durableComplete: boolean | undefined+): void {+ bubble.parts = [...bubble.parts, ...parts]+ bubble.durableComplete = durableComplete++ if (messageInterrupted(message.display_metadata)) {+ bubble.interrupted = true+ }+}+function messageReactions(metadata: SessionMessage['display_metadata']): MessageReaction[] {const reactions = parseDisplayMetadata(metadata)?.reactions@@ -587,8 +603,7 @@ export function toChatMessages(messages: SessionMessage[]): ChatMessage[] {const activeHasToolCall = Boolean(activeAssistant?.parts.some(part => part.type === 'tool-call'))if (activeAssistant && (currentHasToolCall || activeHasToolCall)) {- activeAssistant.parts = [...activeAssistant.parts, ...parts]- activeAssistant.durableComplete = durableComplete+ foldIntoToolBubble(activeAssistant, message, parts, durableComplete)activeAssistant.timestamp = earliestTimestamp(activeAssistant.timestamp,message.timestamp,