import { DisplayMessage } from '../types/index.js'; /** * Convert SDK Message[] into flat DisplayMessage[] for UI. * * Critical invariants: * * 1. **Index parity with the source array**: `display[i]` corresponds to * `messages[i]`. Callers (useAgent) attach `_toolCalls` / `_uiPanels` / * `_attachments` from the raw message by index, so we MUST NOT skip * messages — empty turns become empty-text DisplayMessages (which the UI * renders as blank but preserved so tool-call metadata stays aligned). * * 2. **toolUse and toolResult are first-class**: previously we flattened * toolUse blocks into ugly `*[tool: name]*` placeholder text, which * destroyed the input payload and broke pairing with toolResult. Now we * extract them into a proper `toolCalls: ToolCallInfo[]` on the * DisplayMessage, so ToolCallBubble can show full input/output. * * 3. **render_ui is re-materialized from toolUse input**: the `render_ui` * tool's input IS the HTML/CSS/JS of the panel. On re-hydration from IDB * (new tab, page reload), `_uiPanels` may be absent but the toolUse * blocks survive — so we rebuild `uiPanels` from them. That's how the * UI panels survive forever, not just within the live stream. * * 4. **Text extraction preserves ordering**: toolUse/toolResult blocks are * NOT inlined as text. They become siblings of the message via * toolCalls/uiPanels. Text remains text. */ declare function toDisplayMessages(messages: any[]): DisplayMessage[]; /** * Serialize agent.messages safely for IndexedDB. * * Preserves: * - text blocks verbatim * - toolUse blocks with full input payload (so render_ui can be rehydrated) * - toolResult blocks with toolUseId + status + content * - image/document blocks (binary → base64) * - our hack metadata: _toolCalls, _uiPanels, _attachments */ declare function serializeMessages(messages: any[]): any[]; export { serializeMessages, toDisplayMessages };