streamAdapter adapts the Anthropic stream to our interface
| 17 | |
| 18 | // streamAdapter adapts the Anthropic stream to our interface |
| 19 | type streamAdapter struct { |
| 20 | retryableStream[anthropic.MessageStreamEventUnion] |
| 21 | |
| 22 | trackUsage bool |
| 23 | toolCall bool |
| 24 | stopReason anthropic.StopReason |
| 25 | // toolIDByBlock maps a content block index to its tool_use block ID. |
| 26 | // Anthropic emits each tool_use in its own content block; subsequent |
| 27 | // input_json_delta events carry the block index (not the tool ID), so |
| 28 | // we must remember the ID per block to route partial JSON correctly |
| 29 | // when multiple tool calls stream in parallel. |
| 30 | toolIDByBlock map[int64]string |
| 31 | } |
| 32 | |
| 33 | func (c *Client) newStreamAdapter(stream *ssestream.Stream[anthropic.MessageStreamEventUnion], trackUsage bool) *streamAdapter { |
| 34 | return &streamAdapter{ |
nothing calls this directly
no outgoing calls
no test coverage detected