mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-12-03 23:54:36 +08:00
fix(codex): default missing Claude tool input arguments
- Normalize omitted or blank Claude tool_use input to an empty JSON object string for Codex. - Add a regression test that verifies the argument value and its JSON string type. Closes: #7939
This commit is contained in:
@@ -401,7 +401,11 @@ func convertClaudeRequestToCodex(modelName string, inputRawJSON []byte, stream,
|
||||
}
|
||||
_ = functionCallMessageDoc.Set("name", name)
|
||||
}
|
||||
_ = functionCallMessageDoc.Set("arguments", messageContentResult.Get("input").Raw)
|
||||
arguments := strings.TrimSpace(messageContentResult.Get("input").Raw)
|
||||
if arguments == "" {
|
||||
arguments = "{}"
|
||||
}
|
||||
_ = functionCallMessageDoc.Set("arguments", arguments)
|
||||
inputItems = append(inputItems, functionCallMessageDoc.Bytes())
|
||||
case "tool_reference":
|
||||
if len(pendingSystemReminders) > 0 {
|
||||
|
||||
@@ -45,6 +45,24 @@ func TestConvertClaudeRequestToCodex_MaxOutputTokens(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertClaudeRequestToCodex_DefaultsMissingToolInputToEmptyObject(t *testing.T) {
|
||||
input := []byte(`{"model":"test-model","messages":[{"role":"assistant","content":[{"type":"tool_use","id":"call_1","name":"get_time"}]}]}`)
|
||||
|
||||
out, errConvert := ConvertClaudeRequestToCodex("test-model", input, false)
|
||||
if errConvert != nil {
|
||||
t.Fatalf("ConvertClaudeRequestToCodex() error = %v", errConvert)
|
||||
}
|
||||
|
||||
functionCall := ojson.GetBytesNoCopy(out, `input.#(type=="function_call")`)
|
||||
arguments := functionCall.Get("arguments")
|
||||
if arguments.Type != ojson.String {
|
||||
t.Fatalf("function_call.arguments type = %v, want string; item=%s", arguments.Type, functionCall.Raw)
|
||||
}
|
||||
if got := arguments.String(); got != "{}" {
|
||||
t.Fatalf("function_call.arguments = %q, want %q; item=%s", got, "{}", functionCall.Raw)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertClaudeRequestToCodex_SystemMessageScenarios(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user