History

fix(claude translator): guard tool schema properties

lollipopkit🏳️‍⚧️ committed 12 months ago

Commit c73b3fa1 parent 772fa691 file · +20 −1Browse files

Unified · Split

internal/translator/codex/claude/codex_claude_request.go+20−1
@@ -204,7 +204,7 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool) · 203 unmodified lines
204 }204 }
205 tool, _ = sjson.Set(tool, "name", name)205 tool, _ = sjson.Set(tool, "name", name)
206 }206 }
207 tool, _ = sjson.SetRaw(tool, "parameters", toolResult.Get("input_schema").Raw)207 tool, _ = sjson.SetRaw(tool, "parameters", normalizeToolParameters(toolResult.Get("input_schema").Raw))
208 tool, _ = sjson.Delete(tool, "input_schema")208 tool, _ = sjson.Delete(tool, "input_schema")
209 tool, _ = sjson.Delete(tool, "parameters.$schema")209 tool, _ = sjson.Delete(tool, "parameters.$schema")
210 tool, _ = sjson.Set(tool, "strict", false)210 tool, _ = sjson.Set(tool, "strict", false)
@@ -334,3 +334,22 @@ func buildReverseMapFromClaudeOriginalToShort(original []byte) map[string]string · 123 unmodified lines
334 }334 }
335 return m335 return m
336}336}
337
338// normalizeToolParameters ensures object schemas contain at least an empty properties map.
339func 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}