Files
CLIProxyAPI/internal/runtime/executor/helps/codex_response_event.go
sususu98 20df0c25b2 fix(codex): preserve string errors and recognize untyped failures
Normalize string websocket errors without discarding their messages. Recognize untyped and body-wrapped failures across SSE, websocket, and duplex paths while retaining status, headers, and sequence numbers.

Cover transport and format combinations, replay invalidation, credential status precedence, and Responses framing with regression tests.
2026-11-16 12:28:56 +08:00

31 lines
965 B
Go

package helps
import (
"strings"
"github.com/MoeForge/moego/ojson"
)
// CodexResponseEventType recognizes error envelopes that omit the event type.
// Explicit event types remain authoritative so output and metadata cannot be
// mistaken for a terminal failure merely because they contain an error field.
func CodexResponseEventType(payload []byte) string {
if eventType := strings.TrimSpace(ojson.GetBytesNoCopy(payload, "type").String()); eventType != "" {
return eventType
}
if !ojson.ValidBytes(payload) {
return ""
}
for _, path := range []string{"error", "body.error", "response.error"} {
node := ojson.GetBytesNoCopy(payload, path)
if node.IsObject() || node.Type == ojson.String && strings.TrimSpace(node.String()) != "" {
return "error"
}
}
if strings.TrimSpace(ojson.GetBytesNoCopy(payload, "code").String()) != "" &&
strings.TrimSpace(ojson.GetBytesNoCopy(payload, "message").String()) != "" {
return "error"
}
return ""
}