Skip to content

fix(proxy): 非流式客户端聚合上游 SSE 为单条 Responses JSON - #3

Merged
wthsama merged 1 commit into
mainfrom
release
Oct 15, 2026
Merged

wthsama merged 1 commit into
mainfrom
release

Conversation

@wthsama

@wthsama wthsama commented Oct 15, 2026

Copy link
Copy Markdown
Owner

问题

Codex 上游只回 SSE(normalizeBody 强制上游 stream:true,响应恒设 text/event-stream)。非流式客户端(未显式 stream:true)拿到的 SSE 体被 OpenAI SDK 当作字符串返回,调用方访问 .choices / .output 抛 AttributeError。

实际影响:经 new-api 渠道 4(codex-bridge)调用 gpt-* 的非流式调用方(如 BiliNote)笔记生成全部失败。

改动

  • src/proxy.js:非流式请求把上游 response.completed(含 response.done / response.incomplete)事件聚合为单条 Responses JSON 返回;无 completed 事件时按 response.output_text.delta 兜底合成。流式请求行为不变。
  • test/smoke.js:拆分流式(SSE 透传)与非流式(JSON 聚合)两条断言。

验证

  • npm test:ALL TESTS PASSED。
  • 端到端(new-api 192.168.5.21:3010,模型 gpt-5.6-luna):stream:false → 200 application/json + chat.completion;stream:true → 200 text/event-stream 不变。
  • BiliNote 实跑:PENDING → TRANSCRIBING → SUCCESS。

Codex 上游只回 SSE,非流式客户端拿到的 SSE 体被 OpenAI SDK 当作字符串返回,
访问 .choices/.output 即报 AttributeError。非流式请求(未显式 stream:true)
现聚合 response.completed 事件为单条 Responses JSON 返回;流式请求行为不变。
@wthsama
wthsama merged commit 034f317 into main Oct 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant