* Concatenate two content block arrays, appending `\n` to a's last text block * when the seam is text-text. The API concatenates adjacent text blocks in a * user message without a separator, so two queued prompts `"2 + 2"` + * `"3 + 3"` would otherwise reach the model as `"2 + 23 + 3"`. * * Blo
( a: ContentBlockParam[], b: ContentBlockParam[], )
| 2503 | * when b is an SR-wrapped attachment. |
| 2504 | */ |
| 2505 | function joinTextAtSeam( |
| 2506 | a: ContentBlockParam[], |
| 2507 | b: ContentBlockParam[], |
| 2508 | ): ContentBlockParam[] { |
| 2509 | const lastA = a.at(-1) |
| 2510 | const firstB = b[0] |
| 2511 | if (lastA?.type === 'text' && firstB?.type === 'text') { |
| 2512 | return [...a.slice(0, -1), { ...lastA, text: lastA.text + '\n' }, ...b] |
| 2513 | } |
| 2514 | return [...a, ...b] |
| 2515 | } |
| 2516 | |
| 2517 | type ToolResultContentItem = Extract< |
| 2518 | ToolResultBlockParam['content'], |