fix: handle sjson errors in codex tool normalization

This commit is contained in:
Junyi Du
2026-03-19 03:36:06 +08:00
parent be2dd60ee7
commit 8f421de532

View File

@@ -95,13 +95,17 @@ func normalizeCodexBuiltinTools(rawJSON []byte) []byte {
for i := 0; i < len(toolArray); i++ {
typePath := fmt.Sprintf("tools.%d.type", i)
if gjson.GetBytes(result, typePath).String() == "web_search_preview" {
result, _ = sjson.SetBytes(result, typePath, "web_search")
if updated, err := sjson.SetBytes(result, typePath, "web_search"); err == nil {
result = updated
}
}
}
}
if gjson.GetBytes(result, "tool_choice.type").String() == "web_search_preview" {
result, _ = sjson.SetBytes(result, "tool_choice.type", "web_search")
if updated, err := sjson.SetBytes(result, "tool_choice.type", "web_search"); err == nil {
result = updated
}
}
return result