| 140 | * block[0] means they're silently ignored for [text, image] content. |
| 141 | */ |
| 142 | export function prependPathRefs( |
| 143 | content: string | Array<ContentBlockParam>, |
| 144 | prefix: string, |
| 145 | ): string | Array<ContentBlockParam> { |
| 146 | if (!prefix) return content |
| 147 | if (typeof content === 'string') return prefix + content |
| 148 | const i = content.findLastIndex(b => b.type === 'text') |
| 149 | if (i !== -1) { |
| 150 | const b = content[i]! |
| 151 | if (b.type === 'text') { |
| 152 | return [ |
| 153 | ...content.slice(0, i), |
| 154 | { ...b, text: prefix + b.text }, |
| 155 | ...content.slice(i + 1), |
| 156 | ] |
| 157 | } |
| 158 | } |
| 159 | // No text block — append one at the end so it's last. |
| 160 | return [...content, { type: 'text', text: prefix.trimEnd() }] |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Convenience: extract + resolve + prepend. No-op when the message has no |