* Normalizes tool inputs in assistant message content for SDK consumption. * Specifically injects plan content into ExitPlanModeV2 tool inputs since * the V2 tool reads plan from file instead of input, but SDK users expect * tool_input.plan to exist.
( message: AssistantMessage, )
| 258 | * tool_input.plan to exist. |
| 259 | */ |
| 260 | function normalizeAssistantMessageForSDK( |
| 261 | message: AssistantMessage, |
| 262 | ): AssistantMessage['message'] { |
| 263 | const content = message.message.content |
| 264 | if (!Array.isArray(content)) { |
| 265 | return message.message |
| 266 | } |
| 267 | |
| 268 | const normalizedContent = content.map((block): BetaContentBlock => { |
| 269 | if (block.type !== 'tool_use') { |
| 270 | return block |
| 271 | } |
| 272 | |
| 273 | if (block.name === EXIT_PLAN_MODE_V2_TOOL_NAME) { |
| 274 | const plan = getPlan() |
| 275 | if (plan) { |
| 276 | return { |
| 277 | ...block, |
| 278 | input: { ...(block.input as Record<string, unknown>), plan }, |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | return block |
| 284 | }) |
| 285 | |
| 286 | return { |
| 287 | ...message.message, |
| 288 | content: normalizedContent, |
| 289 | } |
| 290 | } |
| 291 |
no test coverage detected