* Serializes a tool_use block to text for token counting. * Approximates how the API sees the tool call.
(block: Anthropic.Messages.ToolUseBlockParam)
| 11 | * Approximates how the API sees the tool call. |
| 12 | */ |
| 13 | function serializeToolUse(block: Anthropic.Messages.ToolUseBlockParam): string { |
| 14 | const parts = [`Tool: ${block.name}`] |
| 15 | if (block.input !== undefined) { |
| 16 | try { |
| 17 | parts.push(`Arguments: ${JSON.stringify(block.input)}`) |
| 18 | } catch { |
| 19 | parts.push(`Arguments: [serialization error]`) |
| 20 | } |
| 21 | } |
| 22 | return parts.join("\n") |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Serializes a tool_result block to text for token counting. |