mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
a6d718d0fc
The Claude/Codex format-transform non-stream branch returned an opaque 422 "Failed to parse upstream response" whenever a 2xx upstream body was not valid JSON. The common case: MaaS gateways force-stream a stream:false request and return an SSE body with a non-SSE Content-Type, defeating the header-only is_sse() check. On serde failure, sniff for SSE and aggregate the chunks into a single JSON, then run the existing converter so clients still receive a valid non-stream response. - chat_sse_to_response_value: aggregate chat.completion.chunk SSE (content / reasoning / refusal / tool_calls / legacy function_call), tool_calls index-keyed via BTreeMap to avoid unbounded densification, first-wins finish_reason, message-snapshot override, completeness and error-event guards; synthesize an id when the upstream omits one - responses_sse_to_response_value: process the residual trailing block, tolerating truncation and skipping it once a completed event was seen - enrich remaining parse failures with content-type / content-encoding / body-snippet diagnostics - deflate: try zlib (RFC 9110) before raw; keep the content-encoding header for unsupported encodings - gate zero-usage rows on the Claude transform path