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