( toolUseId: string, )
| 4476 | * or the tool call already has a tool_result. |
| 4477 | */ |
| 4478 | export async function findUnresolvedToolUse( |
| 4479 | toolUseId: string, |
| 4480 | ): Promise<AssistantMessage | null> { |
| 4481 | try { |
| 4482 | const transcriptPath = getTranscriptPath() |
| 4483 | const { messages } = await loadTranscriptFile(transcriptPath) |
| 4484 | |
| 4485 | let toolUseMessage = null |
| 4486 | |
| 4487 | // Find the tool use but make sure there's not also a result |
| 4488 | for (const message of messages.values()) { |
| 4489 | if (message.type === 'assistant') { |
| 4490 | const content = message.message.content |
| 4491 | if (Array.isArray(content)) { |
| 4492 | for (const block of content) { |
| 4493 | if (block.type === 'tool_use' && block.id === toolUseId) { |
| 4494 | toolUseMessage = message |
| 4495 | break |
| 4496 | } |
| 4497 | } |
| 4498 | } |
| 4499 | } else if (message.type === 'user') { |
| 4500 | const content = message.message.content |
| 4501 | if (Array.isArray(content)) { |
| 4502 | for (const block of content) { |
| 4503 | if ( |
| 4504 | block.type === 'tool_result' && |
| 4505 | block.tool_use_id === toolUseId |
| 4506 | ) { |
| 4507 | // Found tool result, bail out |
| 4508 | return null |
| 4509 | } |
| 4510 | } |
| 4511 | } |
| 4512 | } |
| 4513 | } |
| 4514 | |
| 4515 | return toolUseMessage |
| 4516 | } catch { |
| 4517 | return null |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | /** |
| 4522 | * Gets all session JSONL files in a project directory with their stats. |
no test coverage detected