Skip to content

Commit faa483b

Browse files
authored
Merge pull request #257 from lollipopkit/main
fix(claude translator): guard tool schema properties
2 parents f0711be + c73b3fa commit faa483b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

internal/translator/codex/claude/codex_claude_request.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
204204
}
205205
tool, _ = sjson.Set(tool, "name", name)
206206
}
207-
tool, _ = sjson.SetRaw(tool, "parameters", toolResult.Get("input_schema").Raw)
207+
tool, _ = sjson.SetRaw(tool, "parameters", normalizeToolParameters(toolResult.Get("input_schema").Raw))
208208
tool, _ = sjson.Delete(tool, "input_schema")
209209
tool, _ = sjson.Delete(tool, "parameters.$schema")
210210
tool, _ = sjson.Set(tool, "strict", false)
@@ -334,3 +334,22 @@ func buildReverseMapFromClaudeOriginalToShort(original []byte) map[string]string
334334
}
335335
return m
336336
}
337+
338+
// normalizeToolParameters ensures object schemas contain at least an empty properties map.
339+
func normalizeToolParameters(raw string) string {
340+
raw = strings.TrimSpace(raw)
341+
if raw == "" || raw == "null" || !gjson.Valid(raw) {
342+
return `{"type":"object","properties":{}}`
343+
}
344+
schema := raw
345+
result := gjson.Parse(raw)
346+
schemaType := result.Get("type").String()
347+
if schemaType == "" {
348+
schema, _ = sjson.Set(schema, "type", "object")
349+
schemaType = "object"
350+
}
351+
if schemaType == "object" && !result.Get("properties").Exists() {
352+
schema, _ = sjson.SetRaw(schema, "properties", `{}`)
353+
}
354+
return schema
355+
}

0 commit comments

Comments
 (0)