diff --git a/README.md b/README.md index 2e1fccf..56c3467 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ These are captures of real Electron interactions with a temporary Git workspace - Group existing local folders into named workspaces and discover Pi sessions by their original working directory. - Start, stop, steer, resume, and fork sessions; preview history before launching Pi. - Browse linked session archives and branch entries; preview and continue the selected path. -- Render streamed Markdown, thinking, and expandable tool output. +- Render streamed Markdown, thinking, and expandable tool output with on-demand image previews. - Browse files, review diffs, stage changes, and commit. - Discover workspace and global skills, switch models, and save model and reasoning defaults per workspace. - Switch roots while sessions run in the background; retain per-root drafts, views and model defaults. diff --git a/docs/pidex-architecture.md b/docs/pidex-architecture.md index 79877aa..5c608b7 100644 --- a/docs/pidex-architecture.md +++ b/docs/pidex-architecture.md @@ -85,6 +85,8 @@ Per-root views, new-session/history drafts, unsaved settings drafts, open tabs, Markdown and tool output use native browser layout. ResizeObserver supplies actual row heights, including expanded thinking and tools. Width changes and font readiness invalidate measurements. Observer work is scheduled through animation frames to avoid resize feedback loops. +Tool results retain inline PNG, JPEG, GIF and WebP images alongside text in both saved history and live events. Each image loads through a separate disclosure control and fits within the card width and 320 pixels in height. Unsupported formats and decoding failures show an explanation. Text copies, exports and handoff drafts include numbered image notices without image bytes. + Active sessions initially open at the end. Appends and row growth follow the tail when the reader is near the bottom. Upward wheel or keyboard navigation and pointer interaction cancel a pending automatic scroll. History previews start at the beginning. Selected text ranges and keyboard-focused rows remain mounted while scrolling; tool/thinking expansion survives row recycling within the view. ![Long transcript in the Electron test fixture](assets/workbench-long-session.png) diff --git a/src/renderer/components/WorkbenchControls.tsx b/src/renderer/components/WorkbenchControls.tsx index 6e90ab5..a788549 100644 --- a/src/renderer/components/WorkbenchControls.tsx +++ b/src/renderer/components/WorkbenchControls.tsx @@ -10,7 +10,7 @@ import { import { BracketButton } from './BracketButton'; import { FigureFrame } from './FigureFrame'; import { Markdown } from './Markdown'; -import { toolStatus, type Entry } from '../timeline'; +import { toolStatus, type Entry, type ToolImage } from '../timeline'; import type { ModelInfo, SlashCommand } from '../api'; const icons = import.meta.glob('../assets/workbench/*.svg', { @@ -478,11 +478,51 @@ function ToolDiffSection({ ); } -function ToolTextSection({ title, text, stateKey, expanded }: { +function ToolImagePreview({ image, stateKey, expanded }: { + image: ToolImage; + stateKey: string; + expanded: Map; +}) { + const id = useId(); + const [open, setOpen] = useState(() => expanded.get(stateKey) ?? false); + const [failedSource, setFailedSource] = useState(null); + return ( +
+ + +
+ ); +} + +function ToolTextSection({ title, text, stateKey, expanded, images = [] }: { title: string; text: string; stateKey: string; expanded: Map; + images?: ToolImage[]; }) { const [showAll, setShowAll] = useState(false); const [showEnd, setShowEnd] = useState( @@ -537,6 +577,14 @@ function ToolTextSection({ title, text, stateKey, expanded }: { )} + {images.map((image) => ( + + ))} ); } @@ -599,6 +647,7 @@ export const TranscriptRow = memo(function TranscriptRow({ title="Output" stateKey={`${entry.key}:output`} expanded={expanded} + images={entry.images} text={ entry.output || (entry.running ? 'Waiting for output…' : 'No output.') diff --git a/src/renderer/timeline.ts b/src/renderer/timeline.ts index c525d1b..6a671e5 100644 --- a/src/renderer/timeline.ts +++ b/src/renderer/timeline.ts @@ -1,4 +1,5 @@ type ToolLine = { text: string; tone?: 'add' | 'del' | 'dim' }; +type ToolImage = { number: number; source: string }; type Entry = | { key: string; kind: 'user'; text: string } @@ -13,6 +14,7 @@ type Entry = oldText?: string; newText?: string; output: string; + images?: ToolImage[]; running: boolean; ok: boolean; interrupted?: boolean; @@ -101,12 +103,29 @@ function toolDiff( return undefined; } -function resultText(content: unknown): string { - if (!Array.isArray(content)) return ''; - return content - .filter(p => p && p.type === 'text' && typeof p.text === 'string') - .map(p => (p as { text: string }).text) - .join('\n'); +function resultOutput(content: unknown): { output: string; images: ToolImage[] } { + const text: string[] = []; + const images: ToolImage[] = []; + let imageNumber = 0; + for (const part of Array.isArray(content) ? content : []) { + if (!part || typeof part !== 'object') continue; + const block = part as Record; + if (block.type === 'text' && typeof block.text === 'string') text.push(block.text); + if (block.type !== 'image') continue; + const number = ++imageNumber; + // Only inline raster data may reach an img src. Never load a tool-supplied + // URL or active document format such as SVG. + if ( + typeof block.mimeType === 'string' && /^image\/(png|jpeg|gif|webp)$/.test(block.mimeType) && + typeof block.data === 'string' && /^[A-Za-z0-9+/]+={0,2}$/.test(block.data) + ) { + images.push({ number, source: `data:${block.mimeType};base64,${block.data}` }); + text.push(`Image ${number} (${block.mimeType}). Image data is omitted from text copies and exports.`); + } else { + text.push(`Image ${number} cannot be previewed (unsupported format or invalid image data).`); + } + } + return { output: text.join('\n'), images }; } function entriesFromMessages(messages: unknown[]): Entry[] { @@ -154,7 +173,7 @@ function entriesFromMessages(messages: unknown[]): Entry[] { if (m.role === 'toolResult' && m.toolCallId) { const tool = tools.get(m.toolCallId); if (tool) { - tool.output = resultText(m.content); + Object.assign(tool, resultOutput(m.content)); tool.ok = m.isError !== true; tool.interrupted = false; } @@ -244,7 +263,7 @@ function applyEvent( const idx = next.findIndex(e => e.kind === 'tool' && e.toolId === event.toolCallId); if (idx !== -1) { const partial = event.partialResult as { content?: unknown } | undefined; - next[idx] = { ...next[idx], output: resultText(partial?.content) } as Entry; + next[idx] = { ...next[idx], ...resultOutput(partial?.content) } as Entry; } break; } @@ -254,7 +273,7 @@ function applyEvent( const result = event.result as { content?: unknown } | undefined; next[idx] = { ...next[idx], - output: resultText(result?.content), + ...resultOutput(result?.content), running: false, ok: event.isError !== true, interrupted: false, @@ -273,4 +292,4 @@ function toolStatus(entry: Extract): string { } export { entriesFromMessages, applyEvent, toolStatus }; -export type { Entry, ToolLine }; +export type { Entry, ToolLine, ToolImage }; diff --git a/src/renderer/workbench.css b/src/renderer/workbench.css index 6c13d52..7fad3d4 100644 --- a/src/renderer/workbench.css +++ b/src/renderer/workbench.css @@ -837,6 +837,15 @@ html[data-reduced-motion='true'] .wb-shell *::after { white-space: pre-wrap; overflow-wrap: anywhere; } +.wb-tool-image img { + display: block; + max-width: calc(100% - 24px); + max-height: 320px; + width: auto; + height: auto; + object-fit: contain; + margin: 0 12px 12px; +} .wb-tool-diff { padding: 8px 0 12px; max-height: 320px; diff --git a/tests/e2e/tool-preview.test.ts b/tests/e2e/tool-preview.test.ts index f58459c..86f804c 100644 --- a/tests/e2e/tool-preview.test.ts +++ b/tests/e2e/tool-preview.test.ts @@ -118,6 +118,30 @@ describe('bounded tool previews in Electron', () => { ]; await fs.writeFile(path.join(archives, `${tool}.jsonl`), records.map((r) => JSON.stringify(r)).join('\n')); } + const image = await fs.readFile(path.join(root, 'docs/assets/banner.png'), 'base64'); + for (const broken of [false, true]) { + const name = broken ? 'broken-image' : 'image'; + const records = [ + { type: 'session', version: 3, id: name, cwd: project, timestamp: new Date().toISOString() }, + { type: 'message', id: 'task', parentId: null, message: { + role: 'user', content: [{ type: 'text', text: broken ? 'Inspect broken image output' : 'Inspect image output' }], + } }, + { type: 'message', id: 'call', parentId: 'task', message: { + role: 'assistant', content: [{ type: 'toolCall', id: 'read', name: 'read', arguments: { path: 'banner.png' } }], + } }, + { type: 'message', id: 'result', parentId: 'call', message: { + role: 'toolResult', toolCallId: 'read', toolName: 'read', + content: broken ? [ + { type: 'image', mimeType: 'image/png', data: 'YnJva2Vu' }, + { type: 'image', mimeType: 'image/svg+xml', data: 'PHN2Zz4=' }, + ] : [ + { type: 'text', text: 'Pidex banner preview' }, + { type: 'image', mimeType: 'image/png', data: image }, + ], + } }, + ]; + await fs.writeFile(path.join(archives, `${name}.jsonl`), records.map((r) => JSON.stringify(r)).join('\n')); + } app = await electron.launch({ executablePath: require('electron'), args: ['.'], @@ -145,6 +169,87 @@ describe('bounded tool previews in Electron', () => { if (fixture) await fs.rm(fixture, { recursive: true, force: true }); }); + it('previews saved tool images on demand at desktop and minimum window sizes', async () => { + await page.getByRole('tree', { name: 'Session archives', exact: true }) + .getByRole('treeitem', { name: /Inspect image output/ }).click(); + const card = page.locator('.wb-tool'); + await card.locator('summary').click(); + await card.getByText('Pidex banner preview', { exact: false }).waitFor(); + expect(await card.getByText('No output.', { exact: true }).count()).toBe(0); + expect(await card.getByRole('img', { name: 'Tool output image 1' }).count()).toBe(0); + await card.getByRole('button', { name: 'Show image 1' }).focus(); + await page.keyboard.press('Enter'); + const image = card.getByRole('img', { name: 'Tool output image 1' }); + await expect.poll(() => image.evaluate((img: HTMLImageElement) => img.complete && img.naturalWidth > 0)).toBe(true); + // The image and its controls may need separate frames on a short display. + await card.locator('summary').scrollIntoViewIfNeeded(); + await page.screenshot({ path: path.join(root, '.tmp/proof/tool-image-controls.png'), scale: 'css' }); + await page.screenshot({ path: path.join(shots, 'tool-image-controls.png'), scale: 'css' }); + const capture = async (name: string) => { + await image.scrollIntoViewIfNeeded(); + const bounds = await image.boundingBox(); + expect(bounds?.height).toBeLessThanOrEqual(320); + expect(await page.evaluate(() => document.body.scrollWidth <= innerWidth)).toBe(true); + const screenshot = await page.screenshot({ scale: 'css' }); + await Promise.all([ + fs.writeFile(path.join(root, '.tmp/proof', name), screenshot), + fs.writeFile(path.join(shots, name), screenshot), + ]); + }; + await capture('tool-image-desktop.png'); + await resizeWindow(900, 600); + await capture('tool-image-narrow.png'); + await card.getByRole('button', { name: 'Copy output' }).click(); + await card.getByText('Output copied.', { exact: true }).waitFor(); + expect(await app.evaluate(({ clipboard }) => clipboard.readText())).toBe( + 'Pidex banner preview\nImage 1 (image/png). Image data is omitted from text copies and exports.', + ); + await page.getByRole('button', { name: 'Copy context', exact: true }).click(); + await page.getByRole('status').filter({ hasText: 'Context copied.' }).waitFor(); + const exported = await app.evaluate(({ clipboard }) => clipboard.readText()); + expect(exported).toContain('Image data is omitted from text copies and exports.'); + expect(exported).not.toContain('data:image'); + await card.getByRole('button', { name: 'Output details' }).click(); + await card.getByRole('button', { name: 'Output details' }).click(); + await card.getByRole('button', { name: 'Hide image 1' }).click(); + expect(await image.count()).toBe(0); + await resizeWindow(1280, 1100); + }); + + it('explains broken and unsupported saved images while keeping the tool result readable', async () => { + await page.getByRole('tree', { name: 'Session archives', exact: true }) + .getByRole('treeitem', { name: /Inspect broken image output/ }).click(); + const card = page.locator('.wb-tool'); + await card.locator('summary').click(); + await card.getByText(/Image 2 cannot be previewed/).waitFor(); + expect(await card.getByRole('button', { name: 'Show image 2' }).count()).toBe(0); + await card.getByRole('button', { name: 'Show image 1' }).click(); + const failure = card.getByRole('status').filter({ hasText: 'Image 1 could not be displayed.' }); + await failure.waitFor(); + await failure.scrollIntoViewIfNeeded(); + await page.screenshot({ path: path.join(root, '.tmp/proof/tool-image-unavailable.png'), scale: 'css' }); + await page.screenshot({ path: path.join(shots, 'tool-image-unavailable.png'), scale: 'css' }); + expect(errors).toEqual([]); + }); + + it('keeps an opened image visible when a live tool result replaces its partial snapshot', async () => { + await page.getByRole('button', { name: 'New session', exact: true }).click(); + await page.getByLabel('Message pi').fill('Inspect tool image fixture'); + await page.getByRole('button', { name: 'Send', exact: true }).click(); + const card = page.locator('.wb-tool'); + await card.locator('summary').click(); + await card.getByRole('button', { name: 'Show image 1' }).click(); + await card.getByText('Final image preview', { exact: false }).waitFor(); + await card.locator('summary').getByText('Done', { exact: true }).waitFor(); + const image = card.getByRole('img', { name: 'Tool output image 1' }); + await expect.poll(() => image.evaluate((img: HTMLImageElement) => img.complete && img.naturalWidth > 0)).toBe(true); + await image.scrollIntoViewIfNeeded(); + await page.screenshot({ path: path.join(root, '.tmp/proof/tool-image-live.png'), scale: 'css' }); + await page.screenshot({ path: path.join(shots, 'tool-image-live.png'), scale: 'css' }); + expect(errors).toEqual([]); + await page.getByRole('button', { name: /^Sessions/ }).click(); + }); + it.each(['write', 'edit'])('bounds a long %s line and keeps the footer painted through native window resizing', async (tool) => { await page.getByRole('tree', { name: 'Session archives', exact: true }) .getByRole('treeitem', { name: new RegExp(`Inspect long ${tool} input`) }).click(); diff --git a/tests/fixtures/pi-rpc.cjs b/tests/fixtures/pi-rpc.cjs index 8cfcded..acbaa3f 100755 --- a/tests/fixtures/pi-rpc.cjs +++ b/tests/fixtures/pi-rpc.cjs @@ -275,6 +275,26 @@ readline.createInterface({ input: process.stdin }).on('line', (line) => { reply(); streaming = true; event('agent_start'); + if (command.message === 'Inspect tool image fixture') { + const image = { + type: 'image', mimeType: 'image/png', + data: fs.readFileSync(path.join(__dirname, '../../docs/assets/banner.png'), 'base64'), + }; + event('tool_execution_start', { + toolCallId: 'read-image', toolName: 'read', args: { path: 'banner.png' }, + }); + event('tool_execution_update', { + toolCallId: 'read-image', partialResult: { content: [{ type: 'text', text: 'Streaming image preview' }, image] }, + }); + timers.push(setTimeout(() => { + event('tool_execution_end', { + toolCallId: 'read-image', result: { content: [{ type: 'text', text: 'Final image preview' }, image] }, + }); + streaming = false; + event('agent_end'); + }, 1500)); + break; + } if (command.message === 'Start interrupted tool fixture') { event('tool_execution_start', { toolCallId: 'interrupted-build', toolName: 'bash', args: { command: 'build-project' }, diff --git a/tests/integration/ToolCard.test.tsx b/tests/integration/ToolCard.test.tsx index ff7a0aa..6775821 100644 --- a/tests/integration/ToolCard.test.tsx +++ b/tests/integration/ToolCard.test.tsx @@ -1,7 +1,7 @@ import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'; import { act, render, cleanup, fireEvent } from '@testing-library/react'; import { TOOL_TEXT_PREVIEW_LIMIT, TranscriptRow } from '../../src/renderer/components/WorkbenchControls'; -import type { Entry } from '../../src/renderer/timeline'; +import { entriesFromMessages, type Entry } from '../../src/renderer/timeline'; const toolEntry: Extract = { key: 'tool-1', @@ -19,6 +19,69 @@ describe(' tool card', () => { beforeEach(() => cleanup()); afterEach(() => vi.useRealTimers()); + it('loads images on demand, keeps them independent and restores disclosure after row recycling', async () => { + const writeText = vi.fn().mockResolvedValue(undefined); + Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true }); + const [entry] = entriesFromMessages([ + { role: 'assistant', content: [{ type: 'toolCall', id: 'image', name: 'read' }] }, + { role: 'toolResult', toolCallId: 'image', content: [ + { type: 'text', text: 'Screen capture' }, + { type: 'image', mimeType: 'image/png', data: 'aW1hZ2U=' }, + { type: 'image', mimeType: 'image/png', data: 'c2Vjb25k' }, + ] }, + ]); + const expanded = new Map([[entry.key, true]]); + const view = render(); + expect(view.queryByRole('img', { name: /Tool output image/ })).toBeNull(); + expect(view.getByRole('button', { name: 'Show image 1' })).toHaveAttribute('aria-expanded', 'false'); + fireEvent.click(view.getByRole('button', { name: 'Show image 1' })); + expect(view.getByRole('img', { name: 'Tool output image 1' })).toHaveAttribute('src', 'data:image/png;base64,aW1hZ2U='); + expect(view.queryByRole('img', { name: 'Tool output image 2' })).toBeNull(); + fireEvent.click(view.getByRole('button', { name: 'Copy output' })); + await vi.waitFor(() => expect(writeText).toHaveBeenCalledExactlyOnceWith( + 'Screen capture\nImage 1 (image/png). Image data is omitted from text copies and exports.\nImage 2 (image/png). Image data is omitted from text copies and exports.', + )); + fireEvent.click(view.getByRole('button', { name: 'Output details' })); + expect(view.container.querySelector('img[alt="Tool output image 1"]')).toBeNull(); + fireEvent.click(view.getByRole('button', { name: 'Output details' })); + expect(view.getByRole('img', { name: 'Tool output image 1' })).toBeTruthy(); + view.unmount(); + const recycled = render(); + expect(recycled.getByRole('img', { name: 'Tool output image 1' })).toBeTruthy(); + fireEvent.click(recycled.getByRole('button', { name: 'Hide image 1' })); + expect(recycled.queryByRole('img', { name: 'Tool output image 1' })).toBeNull(); + expect(recycled.getByText('Screen capture', { exact: false })).toBeTruthy(); + }); + + it('explains a broken image and allows a replacement streamed image to load', () => { + const entry = { + ...toolEntry, output: 'Screenshot follows', + images: [{ number: 1, source: 'data:image/png;base64,YnJva2Vu' }], + }; + const expanded = new Map([[entry.key, true]]); + const view = render(); + fireEvent.click(view.getByRole('button', { name: 'Show image 1' })); + fireEvent.error(view.getByRole('img', { name: 'Tool output image 1' })); + expect(view.getByRole('status').textContent).toContain('Image 1 could not be displayed.'); + expect(view.getByText('Screenshot follows')).toBeTruthy(); + view.rerender( { + const [entry] = entriesFromMessages([ + { role: 'assistant', content: [{ type: 'toolCall', id: 'image', name: 'read' }] }, + { role: 'toolResult', toolCallId: 'image', content: [{ type: 'image', mimeType: 'image/svg+xml', data: 'PHN2Zz4=' }] }, + ]); + const view = render(); + expect(view.getByText(/Image 1 cannot be previewed/)).toBeTruthy(); + expect(view.queryByText('No output.')).toBeNull(); + expect(view.queryByRole('button', { name: 'Show image 1' })).toBeNull(); + }); + it.each(['input', 'output'] as const)('reports a failed %s copy while collapsed and allows retrying the complete text', async (section) => { const writeText = vi.fn().mockRejectedValueOnce(new Error('Clipboard denied')).mockResolvedValue(undefined); Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true }); diff --git a/tests/unit/export-session.test.ts b/tests/unit/export-session.test.ts index 2dc9ead..8b494ac 100644 --- a/tests/unit/export-session.test.ts +++ b/tests/unit/export-session.test.ts @@ -3,7 +3,7 @@ import { sessionExportFilename, sessionExportMarkdown, } from '../../src/renderer/export-session'; -import type { Entry } from '../../src/renderer/timeline'; +import { entriesFromMessages, type Entry } from '../../src/renderer/timeline'; const exportedAt = new Date('2026-11-08T01:02:03.000Z'); @@ -20,6 +20,24 @@ const bashDone: Extract = { }; describe('sessionExportMarkdown', () => { + it('exports image result notices and accompanying text without inline image data', () => { + const markdown = sessionExportMarkdown({ + title: 'Inspect an image', cwd: '/repo/app', model: '', exportedAt, + entries: entriesFromMessages([ + { role: 'assistant', content: [{ type: 'toolCall', id: 'read', name: 'read', arguments: { path: 'view.png' } }] }, + { role: 'toolResult', toolCallId: 'read', content: [ + { type: 'text', text: 'The current screen' }, + { type: 'image', mimeType: 'image/png', data: 'aW1hZ2U=' }, + ] }, + ]), + }); + expect(markdown).toContain('The current screen'); + expect(markdown).toContain('Image 1 (image/png). Image data is omitted from text copies and exports.'); + expect(markdown).not.toContain('No output.'); + expect(markdown).not.toContain('aW1hZ2U='); + expect(markdown).not.toContain('data:image'); + }); + it('writes the full conversation with context and tool input', () => { const markdown = sessionExportMarkdown({ title: 'Fix the export', diff --git a/tests/unit/timeline.test.ts b/tests/unit/timeline.test.ts index 81710d3..2771492 100644 --- a/tests/unit/timeline.test.ts +++ b/tests/unit/timeline.test.ts @@ -3,6 +3,61 @@ import { entriesFromMessages, applyEvent } from '../../src/renderer/timeline'; import type { Entry } from '../../src/renderer/timeline'; describe('entriesFromMessages', () => { + it('keeps text and numbered image notices in saved tool results without copying image bytes', () => { + const [entry] = entriesFromMessages([ + { role: 'assistant', content: [{ type: 'toolCall', id: 'image', name: 'read', arguments: { path: 'screen.png' } }] }, + { role: 'toolResult', toolCallId: 'image', content: [ + { type: 'text', text: 'Screenshot follows' }, + { type: 'image', mimeType: 'image/png', data: 'aW1hZ2U=' }, + { type: 'text', text: 'Another view' }, + { type: 'image', mimeType: 'image/jpeg', data: 'c2Vjb25k' }, + ] }, + ]); + expect(entry).toMatchObject({ + output: 'Screenshot follows\nImage 1 (image/png). Image data is omitted from text copies and exports.\nAnother view\nImage 2 (image/jpeg). Image data is omitted from text copies and exports.', + images: [ + { number: 1, source: 'data:image/png;base64,aW1hZ2U=' }, + { number: 2, source: 'data:image/jpeg;base64,c2Vjb25k' }, + ], + running: false, interrupted: false, ok: true, + }); + }); + + it('explains unsupported and malformed images without treating them as empty output or URLs', () => { + const [entry] = entriesFromMessages([ + { role: 'assistant', content: [{ type: 'toolCall', id: 'image', name: 'read' }] }, + { role: 'toolResult', toolCallId: 'image', content: [ + null, 'ignored', { type: 'image', mimeType: 'image/svg+xml', data: 'PHN2Zz4=' }, + { type: 'image', mimeType: 'image/png', data: 'https://example.com/image.png' }, + { type: 'image', mimeType: 'image/png', data: '' }, + { type: 'image', mimeType: 'image/png' }, + { type: 'image', mimeType: 'image/webp', data: 'd2VicA==' }, + ] }, + ]); + expect(entry).toMatchObject({ + output: [1, 2, 3, 4].map((n) => `Image ${n} cannot be previewed (unsupported format or invalid image data).`).join('\n') + + '\nImage 5 (image/webp). Image data is omitted from text copies and exports.', + images: [{ number: 5, source: 'data:image/webp;base64,d2VicA==' }], + }); + }); + + it('replaces image snapshots during streaming and clears them when the final result has text only', () => { + let entries = applyEvent([], { type: 'tool_execution_start', toolCallId: 'image', toolName: 'read' }).entries; + const content = [{ type: 'image', mimeType: 'image/gif', data: 'Z2lm' }]; + entries = applyEvent(entries, { type: 'tool_execution_update', toolCallId: 'image', partialResult: { content } }).entries; + expect(entries[0]).toMatchObject({ + output: 'Image 1 (image/gif). Image data is omitted from text copies and exports.', + images: [{ number: 1, source: 'data:image/gif;base64,Z2lm' }], running: true, + }); + entries = applyEvent(entries, { type: 'tool_execution_end', toolCallId: 'image', result: { content } }).entries; + expect(entries[0]).toMatchObject({ images: [{ number: 1, source: 'data:image/gif;base64,Z2lm' }], running: false }); + entries = applyEvent(entries, { + type: 'tool_execution_end', toolCallId: 'image', isError: true, + result: { content: [{ type: 'text', text: 'Image capture failed' }] }, + }).entries; + expect(entries[0]).toMatchObject({ output: 'Image capture failed', images: [], ok: false }); + }); + it('returns no entries for empty input', () => { expect(entriesFromMessages([])).toEqual([]); });