feat(api): add Codex client models support for OpenAI API

- Introduced Codex client models framework in `openai` package.
- Added JSON-based model definitions (`codex_client_models.json`) for Codex, including metadata, reasoning levels, and configuration options.
- Implemented handlers to load, clone, and build Codex client models with support for visibility overrides and metadata application.
- Enabled sorting and prioritization of models based on configuration or runtime criteria.
- Added utility functions for managing and validating model attributes.
This commit is contained in:
Luis Pater
2026-05-17 04:48:34 +08:00
parent 53d1fd6c5c
commit 088ab33df8
7 changed files with 1092 additions and 1 deletions
+57
View File
@@ -31,6 +31,11 @@ var xaiDataTag = []byte("data:")
const (
xaiImageHandlerType = "openai-image"
xaiVideoHandlerType = "openai-video"
xaiCustomToolType = "custom"
xaiFunctionToolType = "function"
xaiImageGenerationToolType = "image_generation"
xaiToolSearchType = "tool_search"
xaiWebSearchToolType = "web_search"
xaiImagesGenerationsPath = "/images/generations"
xaiImagesEditsPath = "/images/edits"
xaiDefaultImageEndpointPath = xaiImagesGenerationsPath
@@ -494,6 +499,7 @@ func (e *XAIExecutor) prepareResponsesRequest(ctx context.Context, req cliproxye
body, _ = sjson.DeleteBytes(body, "prompt_cache_retention")
body, _ = sjson.DeleteBytes(body, "safety_identifier")
body, _ = sjson.DeleteBytes(body, "stream_options")
body = normalizeXAITools(body)
body = normalizeCodexInstructions(body)
body = sanitizeXAIResponsesBody(body, baseModel)
@@ -647,6 +653,57 @@ func sanitizeXAIResponsesBody(body []byte, model string) []byte {
return body
}
func normalizeXAITools(body []byte) []byte {
tools := gjson.GetBytes(body, "tools")
if !tools.Exists() || !tools.IsArray() {
return body
}
changed := false
filtered := []byte(`[]`)
for _, tool := range tools.Array() {
toolType := tool.Get("type").String()
if toolType == xaiToolSearchType || toolType == xaiImageGenerationToolType {
changed = true
continue
}
raw := []byte(tool.Raw)
if toolType == xaiCustomToolType {
if tool.Get("name").String() == "apply_patch" {
changed = true
continue
}
updatedTool, errSet := sjson.SetBytes(raw, "type", xaiFunctionToolType)
if errSet != nil {
return body
}
raw = updatedTool
changed = true
}
if toolType == xaiWebSearchToolType && tool.Get("external_web_access").Exists() {
updatedTool, errDel := sjson.DeleteBytes(raw, "external_web_access")
if errDel != nil {
return body
}
raw = updatedTool
changed = true
}
updated, errSet := sjson.SetRawBytes(filtered, "-1", raw)
if errSet != nil {
return body
}
filtered = updated
}
if !changed {
return body
}
updated, errSet := sjson.SetRawBytes(body, "tools", filtered)
if errSet != nil {
return body
}
return updated
}
func removeXAIEncryptedReasoningInclude(body []byte) []byte {
include := gjson.GetBytes(body, "include")
if !include.Exists() || !include.IsArray() {