fix(openai,codex): build stream errors via ojson.Doc and preserve SSE status

- Build OpenAI Responses stream error and failed chunks directly through ojson.Doc with single-exit serialization, supporting scalar error strings without map mutations.
- Preserve valid top-level and body envelope HTTP error status codes when normalizing typeless Codex SSE failures and Responses SSE frames.
- Normalize scalar and blank WebSocket error fields purely via ojson.Doc.
This commit is contained in:
sususu98
2026-11-16 13:50:58 +08:00
parent 20df0c25b2
commit 80e8350c95
7 changed files with 180 additions and 172 deletions

View File

@@ -91,9 +91,16 @@ func buildCodexWebsocketErrorPayload(payload []byte, status int) []byte {
}
fillBlankErrorMessage := func() {
if node := doc.Get("error"); node.Type == ojson.String && strings.TrimSpace(node.String()) != "" {
_ = doc.Set("error", map[string]any{"message": node.String()})
return
if node := doc.Get("error"); !node.IsObject() {
scalar := ""
if node.Type != ojson.Null && strings.TrimSpace(node.String()) != "" {
scalar = node.String()
}
_ = doc.SetRawBytes("error", []byte(`{}`))
if scalar != "" {
_ = doc.Set("error.message", scalar)
return
}
}
if strings.TrimSpace(doc.Get("error.message").String()) != "" {
return