(target: StreamedMessagePart, source: StreamedMessagePart)
| 139 | * Returns `true` if the merge was performed, `false` otherwise. |
| 140 | */ |
| 141 | export function mergeInPlace(target: StreamedMessagePart, source: StreamedMessagePart): boolean { |
| 142 | // TextPart + TextPart |
| 143 | if (target.type === 'text' && source.type === 'text') { |
| 144 | target.text += source.text; |
| 145 | return true; |
| 146 | } |
| 147 | |
| 148 | // ThinkPart + ThinkPart |
| 149 | if (target.type === 'think' && source.type === 'think') { |
| 150 | if (target.encrypted !== undefined) { |
| 151 | return false; |
| 152 | } |
| 153 | target.think += source.think; |
| 154 | if (source.encrypted !== undefined) { |
| 155 | target.encrypted = source.encrypted; |
| 156 | } |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | // ToolCall + ToolCallPart |
| 161 | if (target.type === 'function' && source.type === 'tool_call_part') { |
| 162 | if (source.argumentsPart !== null) { |
| 163 | target.arguments = |
| 164 | target.arguments === null |
| 165 | ? source.argumentsPart |
| 166 | : target.arguments + source.argumentsPart; |
| 167 | } |
| 168 | return true; |
| 169 | } |
| 170 | |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Extract the concatenated text from a message's content parts. |
no outgoing calls
no test coverage detected