* Get the tool name, input, and search/read info from a message if it's a collapsible tool use. * Returns null if the message is not a collapsible tool use.
( msg: RenderableMessage, tools: Tools, behavior?: CollapseBehavior, )
| 308 | * Returns null if the message is not a collapsible tool use. |
| 309 | */ |
| 310 | function getCollapsibleToolInfo( |
| 311 | msg: RenderableMessage, |
| 312 | tools: Tools, |
| 313 | behavior?: CollapseBehavior, |
| 314 | ): { |
| 315 | name: string |
| 316 | input: unknown |
| 317 | isSearch: boolean |
| 318 | isRead: boolean |
| 319 | isList: boolean |
| 320 | isREPL: boolean |
| 321 | isMemoryWrite: boolean |
| 322 | isAbsorbedSilently: boolean |
| 323 | mcpServerName?: string |
| 324 | isBash?: boolean |
| 325 | } | null { |
| 326 | if (msg.type === 'assistant') { |
| 327 | const content = msg.message.content[0] |
| 328 | const info = |
| 329 | content?.type === 'tool_use' && content.name |
| 330 | ? getToolSearchOrReadInfo(content.name, content.input, tools, behavior) |
| 331 | : null |
| 332 | if (info && content?.type === 'tool_use') { |
| 333 | return { name: content.name, input: content.input, ...info } |
| 334 | } |
| 335 | } |
| 336 | if (msg.type === 'grouped_tool_use') { |
| 337 | // For grouped tool uses, check the first message's input |
| 338 | const firstContent = msg.messages[0]?.message.content[0] |
| 339 | const info = |
| 340 | firstContent?.type === 'tool_use' |
| 341 | ? getToolSearchOrReadInfo( |
| 342 | msg.toolName, |
| 343 | firstContent.input, |
| 344 | tools, |
| 345 | behavior, |
| 346 | ) |
| 347 | : null |
| 348 | if (info && firstContent?.type === 'tool_use') { |
| 349 | return { name: msg.toolName, input: firstContent.input, ...info } |
| 350 | } |
| 351 | } |
| 352 | return null |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Check if a message is assistant text that should break a group. |
no test coverage detected