(msg: NavigableMessage)
| 407 | return t; |
| 408 | } |
| 409 | export function copyTextOf(msg: NavigableMessage): string { |
| 410 | switch (msg.type) { |
| 411 | case 'user': |
| 412 | { |
| 413 | const b = msg.message.content[0]; |
| 414 | return b?.type === 'text' ? stripSystemReminders(b.text) : ''; |
| 415 | } |
| 416 | case 'assistant': |
| 417 | { |
| 418 | const b = msg.message.content[0]; |
| 419 | if (b?.type === 'text') return b.text; |
| 420 | const tc = toolCallOf(msg); |
| 421 | return tc ? PRIMARY_INPUT[tc.name]?.extract(tc.input) ?? '' : ''; |
| 422 | } |
| 423 | case 'grouped_tool_use': |
| 424 | return msg.results.map(toolResultText).filter(Boolean).join('\n\n'); |
| 425 | case 'collapsed_read_search': |
| 426 | return msg.messages.flatMap(m => m.type === 'user' ? [toolResultText(m)] : m.type === 'grouped_tool_use' ? m.results.map(toolResultText) : []).filter(Boolean).join('\n\n'); |
| 427 | case 'system': |
| 428 | if ('content' in msg) return msg.content; |
| 429 | if ('error' in msg) return String(msg.error); |
| 430 | return msg.subtype; |
| 431 | case 'attachment': |
| 432 | { |
| 433 | const a = msg.attachment; |
| 434 | if (a.type === 'queued_command') { |
| 435 | const p = a.prompt; |
| 436 | return typeof p === 'string' ? p : p.flatMap(b => b.type === 'text' ? [b.text] : []).join('\n'); |
| 437 | } |
| 438 | return `[${a.type}]`; |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | function toolResultText(r: NormalizedUserMessage): string { |
| 443 | const b = r.message.content[0]; |
| 444 | if (b?.type !== 'tool_result') return ''; |
no test coverage detected