(messages: Message[])
| 5164 | * the API rejects them with a 400. |
| 5165 | */ |
| 5166 | export function stripSignatureBlocks(messages: Message[]): Message[] { |
| 5167 | let changed = false |
| 5168 | const result = messages.map(msg => { |
| 5169 | if (msg.type !== 'assistant') return msg |
| 5170 | |
| 5171 | const content = msg.message.content |
| 5172 | if (!Array.isArray(content)) return msg |
| 5173 | |
| 5174 | const filtered = content.filter(block => { |
| 5175 | if (isThinkingBlock(block)) return false |
| 5176 | if (feature('CONNECTOR_TEXT')) { |
| 5177 | if (isConnectorTextBlock(block)) return false |
| 5178 | } |
| 5179 | return true |
| 5180 | }) |
| 5181 | if (filtered.length === content.length) return msg |
| 5182 | |
| 5183 | // Strip to [] even for thinking-only messages. Streaming yields each |
| 5184 | // content block as a separate same-id AssistantMessage (claude.ts:2150), |
| 5185 | // so a thinking-only singleton here is usually a split sibling that |
| 5186 | // mergeAssistantMessages (2232) rejoins with its text/tool_use partner. |
| 5187 | // If we returned the original message, the stale signature would survive |
| 5188 | // the merge. Empty content is absorbed by merge; true orphans are handled |
| 5189 | // by the empty-content placeholder path in normalizeMessagesForAPI. |
| 5190 | |
| 5191 | changed = true |
| 5192 | return { |
| 5193 | ...msg, |
| 5194 | message: { ...msg.message, content: filtered }, |
| 5195 | } as typeof msg |
| 5196 | }) |
| 5197 | |
| 5198 | return changed ? result : messages |
| 5199 | } |
| 5200 | |
| 5201 | /** |
| 5202 | * Creates a tool use summary message for SDK emission. |
no test coverage detected