* 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[], )
| 2512 | * when b is an SR-wrapped attachment. |
| 2513 | */ |
| 2514 | function joinTextAtSeam( |
| 2515 | a: ContentBlockParam[], |
| 2516 | b: ContentBlockParam[], |
| 2517 | ): ContentBlockParam[] { |
| 2518 | const lastA = a.at(-1) |
| 2519 | const firstB = b[0] |
| 2520 | if (lastA?.type === 'text' && firstB?.type === 'text') { |
| 2521 | return [...a.slice(0, -1), { ...lastA, text: lastA.text + '\n' }, ...b] |
| 2522 | } |
| 2523 | return [...a, ...b] |
| 2524 | } |
| 2525 | |
| 2526 | type ToolResultContentItem = Extract< |
| 2527 | ToolResultBlockParam['content'], |