( toolUseId: string, )
| 4744 | * or the tool call already has a tool_result. |
| 4745 | */ |
| 4746 | export async function findUnresolvedToolUse( |
| 4747 | toolUseId: string, |
| 4748 | ): Promise<AssistantMessage | null> { |
| 4749 | try { |
| 4750 | const transcriptPath = getTranscriptPath() |
| 4751 | const { messages } = await loadTranscriptFile(transcriptPath) |
| 4752 | |
| 4753 | let toolUseMessage = null |
| 4754 | |
| 4755 | // Find the tool use but make sure there's not also a result |
| 4756 | for (const message of messages.values()) { |
| 4757 | if (message.type === 'assistant') { |
| 4758 | const content = message.message.content |
| 4759 | if (Array.isArray(content)) { |
| 4760 | for (const block of content) { |
| 4761 | if (block.type === 'tool_use' && block.id === toolUseId) { |
| 4762 | toolUseMessage = message |
| 4763 | break |
| 4764 | } |
| 4765 | } |
| 4766 | } |
| 4767 | } else if (message.type === 'user') { |
| 4768 | const content = message.message.content |
| 4769 | if (Array.isArray(content)) { |
| 4770 | for (const block of content) { |
| 4771 | if ( |
| 4772 | block.type === 'tool_result' && |
| 4773 | block.tool_use_id === toolUseId |
| 4774 | ) { |
| 4775 | // Found tool result, bail out |
| 4776 | return null |
| 4777 | } |
| 4778 | } |
| 4779 | } |
| 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | return toolUseMessage |
| 4784 | } catch { |
| 4785 | return null |
| 4786 | } |
| 4787 | } |
| 4788 | |
| 4789 | /** |
| 4790 | * Gets all session JSONL files in a project directory with their stats. |
no test coverage detected