diff --git a/internal/translator/gemini/claude/gemini_claude_response.go b/internal/translator/gemini/claude/gemini_claude_response.go index 90e1c501..379f137c 100644 --- a/internal/translator/gemini/claude/gemini_claude_response.go +++ b/internal/translator/gemini/claude/gemini_claude_response.go @@ -25,8 +25,7 @@ type Params struct { HasFirstResponse bool ResponseType int ResponseIndex int - HasContent bool // Tracks whether any content (text, thinking, or tool use) has been output - CurrentToolName string // Tracks the current function name for streaming limits + HasContent bool // Tracks whether any content (text, thinking, or tool use) has been output } // toolUseIDCounter provides a process-wide unique counter for tool use identifiers. @@ -234,7 +233,6 @@ func ConvertGeminiResponseToClaude(_ context.Context, _ string, originalRequestR } (*param).(*Params).ResponseType = 3 (*param).(*Params).HasContent = true - (*param).(*Params).CurrentToolName = fcName } } } diff --git a/internal/util/gemini_schema.go b/internal/util/gemini_schema.go index 8b7b0372..dd8d1c67 100644 --- a/internal/util/gemini_schema.go +++ b/internal/util/gemini_schema.go @@ -222,21 +222,30 @@ func flattenTypeArrays(jsonStr string) string { continue } - hasNull, firstType := false, "" + hasNull := false + var nonNullTypes []string for _, item := range res.Array() { s := item.String() if s == "null" { hasNull = true - } else if firstType == "" { - firstType = s + } else if s != "" { + nonNullTypes = append(nonNullTypes, s) } } - if firstType == "" { - firstType = "string" + + firstType := "string" + if len(nonNullTypes) > 0 { + firstType = nonNullTypes[0] } jsonStr, _ = sjson.Set(jsonStr, p, firstType) + parentPath := trimSuffix(p, ".type") + if len(nonNullTypes) > 1 { + hint := "Accepts: " + strings.Join(nonNullTypes, " | ") + jsonStr = appendHint(jsonStr, parentPath, hint) + } + if hasNull { parts := strings.Split(p, ".") if len(parts) >= 3 && parts[len(parts)-3] == "properties" { diff --git a/internal/util/gemini_schema_test.go b/internal/util/gemini_schema_test.go index 3baa48ea..a17cfb86 100644 --- a/internal/util/gemini_schema_test.go +++ b/internal/util/gemini_schema_test.go @@ -451,6 +451,26 @@ func TestCleanJSONSchemaForGemini_SingleEnumNoHint(t *testing.T) { } } +func TestCleanJSONSchemaForGemini_MultipleNonNullTypes(t *testing.T) { + input := `{ + "type": "object", + "properties": { + "value": { + "type": ["string", "integer", "boolean"] + } + } + }` + + result := CleanJSONSchemaForGemini(input) + + if !strings.Contains(result, "Accepts:") { + t.Errorf("Expected multiple types hint, got: %s", result) + } + if !strings.Contains(result, "string") || !strings.Contains(result, "integer") || !strings.Contains(result, "boolean") { + t.Errorf("Expected all types in hint, got: %s", result) + } +} + func compareJSON(t *testing.T, expectedJSON, actualJSON string) { var expMap, actMap map[string]interface{} errExp := json.Unmarshal([]byte(expectedJSON), &expMap)