( toolUseId: string, )
| 4588 | * or the tool call already has a tool_result. |
| 4589 | */ |
| 4590 | export async function findUnresolvedToolUse( |
| 4591 | toolUseId: string, |
| 4592 | ): Promise<AssistantMessage | null> { |
| 4593 | try { |
| 4594 | const transcriptPath = getTranscriptPath() |
| 4595 | const { messages } = await loadTranscriptFile(transcriptPath) |
| 4596 | |
| 4597 | let toolUseMessage = null |
| 4598 | |
| 4599 | // Find the tool use but make sure there's not also a result |
| 4600 | for (const message of messages.values()) { |
| 4601 | if (message.type === 'assistant') { |
| 4602 | const content = message.message!.content |
| 4603 | if (Array.isArray(content)) { |
| 4604 | for (const block of content as Array<{ type: string; id: string }>) { |
| 4605 | if (block.type === 'tool_use' && block.id === toolUseId) { |
| 4606 | toolUseMessage = message |
| 4607 | break |
| 4608 | } |
| 4609 | } |
| 4610 | } |
| 4611 | } else if (message.type === 'user') { |
| 4612 | const content = message.message!.content |
| 4613 | if (Array.isArray(content)) { |
| 4614 | for (const block of content as Array<{ |
| 4615 | type: string |
| 4616 | tool_use_id: string |
| 4617 | }>) { |
| 4618 | if ( |
| 4619 | block.type === 'tool_result' && |
| 4620 | block.tool_use_id === toolUseId |
| 4621 | ) { |
| 4622 | // Found tool result, bail out |
| 4623 | return null |
| 4624 | } |
| 4625 | } |
| 4626 | } |
| 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | return toolUseMessage as AssistantMessage | null |
| 4631 | } catch { |
| 4632 | return null |
| 4633 | } |
| 4634 | } |
| 4635 | |
| 4636 | /** |
| 4637 | * Gets all session JSONL files in a project directory with their stats. |
no test coverage detected