Add initial ChunkToolCall handling in Anthropic provider

- Implement functionality to send an initial ChunkToolCall with the event's ID and function name, aligning with OpenAI's format for tool name resolution.
- Enhance message tracking by incrementing the chunk count after sending the tool call data, improving the overall message handling process in the streamWithRetry function.
This commit is contained in:
Max 2026-02-15 21:30:52 +08:00
parent 71eab0689e
commit a8fc21d070

View file

@ -362,6 +362,23 @@ func (p *Provider) streamWithRetry(ctx *context.Context, messages []context.Mess
Index: event.Index,
}
startToolCallMessage(msgTracker, toolCallInfo, handler)
// Send initial ChunkToolCall with id and function name
// to match OpenAI format so CUI can resolve tool name from stored chunks
if handler != nil {
toolCallData, _ := jsoniter.Marshal([]map[string]interface{}{
{
"index": event.Index,
"id": event.ContentBlock.ID,
"type": "function",
"function": map[string]interface{}{
"name": event.ContentBlock.Name,
},
},
})
handler(message.ChunkToolCall, toolCallData)
incrementChunk(msgTracker)
}
}
}