| 604 | } |
| 605 | |
| 606 | function lastUserText(history: readonly { role: string; content: readonly unknown[] }[]): string { |
| 607 | const message = history.findLast((item) => item.role === 'user'); |
| 608 | if (message === undefined) return ''; |
| 609 | return message.content |
| 610 | .map((part) => { |
| 611 | if ( |
| 612 | part !== null && |
| 613 | typeof part === 'object' && |
| 614 | (part as { type?: unknown }).type === 'text' |
| 615 | ) { |
| 616 | const text = (part as { text?: unknown }).text; |
| 617 | return typeof text === 'string' ? text : ''; |
| 618 | } |
| 619 | return ''; |
| 620 | }) |
| 621 | .join(''); |
| 622 | } |
| 623 | |
| 624 | function toolResultText(history: readonly { role: string; content: readonly unknown[] }[]): string { |
| 625 | return history |