(events)
| 677 | * the main thread — intermediate narration would flood the citation set. |
| 678 | */ |
| 679 | export function finalAnswerText(events) { |
| 680 | const answers = events.filter((e) => e.type === 'result' && typeof e.result === 'string').map((e) => e.result); |
| 681 | if (answers.length) return answers.join('\n\n'); |
| 682 | let last = ''; |
| 683 | for (const ev of events) { |
| 684 | if (ev.type !== 'assistant' || (ev.parent_tool_use_id ?? null) !== null) continue; |
| 685 | const text = (ev.message?.content || []).filter((b) => b.type === 'text').map((b) => b.text || '').join(''); |
| 686 | if (text.trim()) last = text; |
| 687 | } |
| 688 | return last; |
| 689 | } |
| 690 | |
| 691 | /** The allocation block, as printed under a run and reused by aggregators. */ |
| 692 | export function formatAllocation(s, indent = ' ') { |
no test coverage detected