Skip to content

The agent that grows with you

fix(tui): render a resumed multipart user turn

Teknium1feabd8dc540
diff --git a/ui-tui/src/__tests__/canonicalMultipartResumeRows.test.ts b/ui-tui/src/__tests__/canonicalMultipartResumeRows.test.ts
new file mode 100644
index 00000000000..9e6ef29640f
--- /dev/null
+++ b/ui-tui/src/__tests__/canonicalMultipartResumeRows.test.ts
@@ -0,0 +1,15 @@
+import { expect, it } from 'vitest'
+
+import { canonicalResult } from '../canonicalGateway.js'
+import { toTranscriptMessages } from '../domain/messages.js'
+
+// N94: a resumed canonical snapshot whose user row is multipart (text + image parts) still renders
+// that user turn; `content` stays on the row for /undo targeting.
+it('a multipart user row survives the canonical resume projection', () => {
+ const content = [{ type: 'text', text: 'what is in this picture?' }, { type: 'image_url', image_url: { url: 'data:image/png;base64,AA' } }]
+ const snapshot = canonicalResult('session.resume', { session_id: 's', stored_session_id: 's', authority_epoch: 1, execution_generation: 0,
+ messages: [{ role: 'user', content }, { role: 'assistant', content: 'a cat' }], info: {} })
+ expect(snapshot.messages[0].content).toEqual(content)
+ const rows = toTranscriptMessages(snapshot.messages)
+ expect(rows.map(row => [row.role, row.text])).toEqual([['user', 'what is in this picture?\n[image]'], ['assistant', 'a cat']])
+})
diff --git a/ui-tui/src/canonicalGateway.ts b/ui-tui/src/canonicalGateway.ts
index e3e37bf0bc6..7a64dbbd277 100644
--- a/ui-tui/src/canonicalGateway.ts
+++ b/ui-tui/src/canonicalGateway.ts
@@ -50,7 +50,7 @@ export function canonicalResult(method: string, value: any, request: Record<stri
// live events render, making reconnect depend on catching the final delta.
const messages = Array.isArray(value.messages) ? value.messages.map((row: any) =>
row && typeof row === 'object'
- ? { ...row, text: row.content, name: row.tool_name }
+ ? { ...row, text: rowText(row.content), name: row.tool_name }
: row) : value.messages
return { ...value, messages, info: { ...value.info, stored_session_id: value.stored_session_id,
@@ -61,6 +61,15 @@ export function canonicalResult(method: string, value: any, request: Record<stri
return value
}
+// A stored multipart row (`content` is a parts list) as display text: text parts joined, an image
+// part as `[image]` (N94). `content` itself stays on the row for /undo targeting.
+function rowText(content: unknown): unknown {
+ if (!Array.isArray(content)) { return content }
+
+ return content.map(part => typeof part === 'string' ? part : typeof part?.text === 'string' ? part.text
+ : part?.type ? (String(part.type).includes('image') ? '[image]' : `[${part.type}]`) : '').filter(Boolean).join('\n')
+}
+
// The authority's durable FIFO rows (`pending` on snapshots and session.info
// fanout) projected onto the client's receipt shape: one translation, so the
// queue panel, the receipt matcher and Desktop all read the same list.