feat(xai): normalize xAI input reasoning items and enhance test cases

- Added `normalizeXAIInputReasoningItems` to clean up `input` reasoning items, removing null `content` and `encrypted_content` fields.
- Updated `xai_executor` test cases to validate input normalization and reasoning item handling.
This commit is contained in:
Luis Pater
2026-05-17 04:51:17 +08:00
parent 088ab33df8
commit ddd10539ad
2 changed files with 52 additions and 2 deletions
+32
View File
@@ -500,6 +500,7 @@ func (e *XAIExecutor) prepareResponsesRequest(ctx context.Context, req cliproxye
body, _ = sjson.DeleteBytes(body, "safety_identifier")
body, _ = sjson.DeleteBytes(body, "stream_options")
body = normalizeXAITools(body)
body = normalizeXAIInputReasoningItems(body)
body = normalizeCodexInstructions(body)
body = sanitizeXAIResponsesBody(body, baseModel)
@@ -704,6 +705,37 @@ func normalizeXAITools(body []byte) []byte {
return updated
}
func normalizeXAIInputReasoningItems(body []byte) []byte {
input := gjson.GetBytes(body, "input")
if !input.Exists() || !input.IsArray() {
return body
}
updated := body
for i, item := range input.Array() {
if item.Get("type").String() != "reasoning" {
continue
}
contentPath := fmt.Sprintf("input.%d.content", i)
if content := gjson.GetBytes(updated, contentPath); content.Exists() && content.Type == gjson.Null {
updatedBody, errDel := sjson.DeleteBytes(updated, contentPath)
if errDel != nil {
return body
}
updated = updatedBody
}
encryptedContentPath := fmt.Sprintf("input.%d.encrypted_content", i)
if encryptedContent := gjson.GetBytes(updated, encryptedContentPath); encryptedContent.Exists() && encryptedContent.Type == gjson.Null {
updatedBody, errDel := sjson.DeleteBytes(updated, encryptedContentPath)
if errDel != nil {
return body
}
updated = updatedBody
}
}
return updated
}
func removeXAIEncryptedReasoningInclude(body []byte) []byte {
include := gjson.GetBytes(body, "include")
if !include.Exists() || !include.IsArray() {