Merge branch 'router-for-me:main' into my-fix

This commit is contained in:
AhDEV
2026-05-06 16:41:14 +08:00
committed by GitHub
81 changed files with 4470 additions and 1903 deletions
@@ -236,7 +236,7 @@ func convertOpenAIStreamingChunkToAnthropic(rawJSON []byte, param *ConvertOpenAI
// Handle function name
if function := toolCall.Get("function"); function.Exists() {
if name := function.Get("name"); name.Exists() {
if name := function.Get("name"); name.Exists() && name.String() != "" {
accumulator.Name = util.MapToolName(param.ToolNameMap, name.String())
stopThinkingContentBlock(param, &results)
@@ -0,0 +1,41 @@
package claude
import (
"bytes"
"context"
"testing"
)
func TestConvertOpenAIResponseToClaude_StreamIgnoresNullToolNameDelta(t *testing.T) {
originalRequest := []byte(`{"stream":true}`)
var param any
firstChunks := ConvertOpenAIResponseToClaude(
context.Background(),
"test-model",
originalRequest,
nil,
[]byte(`data: {"id":"chatcmpl_1","model":"test-model","created":1,"choices":[{"index":0,"delta":{"role":"assistant","tool_calls":[{"index":0,"id":"call_1","type":"function","function":{"name":"read_file","arguments":""}}]},"finish_reason":null}]}`),
&param,
)
firstOutput := bytes.Join(firstChunks, nil)
if !bytes.Contains(firstOutput, []byte(`"name":"read_file"`)) {
t.Fatalf("expected first chunk to start read_file tool block, got %s", string(firstOutput))
}
secondChunks := ConvertOpenAIResponseToClaude(
context.Background(),
"test-model",
originalRequest,
nil,
[]byte(`data: {"id":"chatcmpl_1","model":"test-model","created":1,"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"name":null,"arguments":"{\"path\":\"/tmp/a\"}"}}]},"finish_reason":null}]}`),
&param,
)
secondOutput := bytes.Join(secondChunks, nil)
if bytes.Contains(secondOutput, []byte(`content_block_start`)) {
t.Fatalf("did not expect null tool name delta to start a new content block, got %s", string(secondOutput))
}
if bytes.Contains(secondOutput, []byte(`"name":""`)) {
t.Fatalf("did not expect null tool name delta to emit an empty tool name, got %s", string(secondOutput))
}
}