import { type Command, CommandError } from '../../src/core/commands/Command'; import type { ToolHost, ToolResult } from '../../src/editor/agent/agentTools'; import type { AgentView } from '../../src/editor/agent/agentView'; import type { StepTarget } from '../../src/editor/agent/commandCatalog'; import type { SceneFixture } from '../helpers'; /** The editor behind the agent's tools, as the tests drive it: the fixture's project and undo stack. */ export function hostFor(fixture: SceneFixture, deleteAnswer: string | null = null, follows = false) { const asked: string[][] = []; const shown: StepTarget[] = []; const host: ToolHost = { view: () => ({ play: 'editing' }) as AgentView, screenshot: () => Promise.resolve({ data: '', width: 0, height: 0 }), project: () => fixture.project, execute: (command: Command) => { try { fixture.stack.execute(command); return null; } catch (error) { if (error instanceof CommandError) return error.message; throw error; } }, confirmDeletes: (ids) => { asked.push([...ids]); return Promise.resolve(deleteAnswer); }, open: () => null, select: () => null, play: () => null, undo: () => { const label = fixture.stack.undoLabel; if (label !== null) fixture.stack.undo(); return label; }, redo: () => { const label = fixture.stack.redoLabel; if (label !== null) fixture.stack.redo(); return label; }, follows: () => follows, show: (focus) => shown.push(focus), }; return { host, asked, shown }; } export const text = (result: ToolResult) => result.content.map((item) => (item.type === 'text' ? item.text : '')).join('\n');