feat(codex): support non-streaming adaptation via SSE buffering with toggle setting - #2843
feat(codex): support non-streaming adaptation via SSE buffering with toggle setting#2843dahetaoa wants to merge 3 commits into
Conversation
…ream Codex upstream requires streaming for /responses endpoint. This change implements buffering of SSE events until 'response.completed' to support non-streaming client requests.
- Implement codex.non_stream_adapter_enabled setting (default true). - Make the SSE buffering logic in Codex adaptor conditional based on the setting. - Add frontend UI for Codex model settings. - Fix Codex channel test logic to properly detect and build requests.
WalkthroughThis pull request introduces Codex API type support with non-stream adapter functionality, including early API type detection for endpoint routing, SSE-to-JSON conversion for non-stream clients, settings infrastructure for configuration, and corresponding UI components for management. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Controller as Controller<br/>(Routing)
participant Adaptor as Codex<br/>Adaptor
participant Upstream as Codex<br/>Upstream
participant Handler as SSE<br/>Handler
Client->>Controller: Non-stream<br/>Codex request
Controller->>Adaptor: Route request
Adaptor->>Adaptor: NonStreamAdapterEnabled?
alt Non-stream mode enabled
Adaptor->>Upstream: Force upstream<br/>streaming (Accept: text/event-stream)
Upstream-->>Handler: SSE stream
Handler->>Handler: Parse SSE events<br/>(response.completed)
Handler->>Handler: Extract JSON<br/>response body
Handler->>Handler: Sanitize headers<br/>(remove content headers)
Handler-->>Client: Single JSON<br/>response
else Stream passthrough
Upstream-->>Client: SSE stream
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
暂时不考虑这个非流转流的操作,可能会被用于分发,可能会违反OpenAI相关的政策,这个是给个人用户使用的。 |
Codex2api本身就违反OpenAI相关政策了,更何况newapi早就被用于商业分发了.... 我觉得做都做了不如做全,至少比留一个半成品好 |
这个半成品本身就是刻意只允许在codex能用通,其他地方不支持使用。 |
功能描述
Codex 后端的
/responses接口原生仅支持流式 (SSE) 响应。本 PR 通过在 Relay 层缓冲 SSE 事件的方式,实现了对非流式请求的适配支持。主要改动
response.completed事件,然后拼接成完整的 JSON 响应返回给客户端。codex.non_stream_adapter_enabled配置项(默认开启)。依赖关系
此 PR 基于 #2826(Header 优化),建议在前者合并后进行 Review。
Summary by CodeRabbit
New Features
Tests