package helps import ( "fmt" "github.com/tidwall/gjson" "github.com/tidwall/sjson" ) // SanitizeCodexResponseInputNamespaces removes namespaces from tool-call // history items that the Codex Responses endpoint rejects. func SanitizeCodexResponseInputNamespaces(body []byte) []byte { items := gjson.GetBytes(body, "input") if !items.IsArray() { return body } for index, item := range items.Array() { itemType := item.Get("type").String() if itemType != "function_call" && itemType != "custom_tool_call" { continue } updated, errDelete := sjson.DeleteBytes(body, fmt.Sprintf("input.%d.namespace", index)) if errDelete == nil { body = updated } } return body }