feat(responses): 归一化 OpenRouter 非标准 reasoning 形态为 OpenAI 规范 - #290
Open
yukaidi1220 wants to merge 4 commits into
Open
feat(responses): 归一化 OpenRouter 非标准 reasoning 形态为 OpenAI 规范#290yukaidi1220 wants to merge 4 commits into
yukaidi1220 wants to merge 4 commits into
Conversation
OpenRouter 的 Responses API 把思考文本放在非标准 content[reasoning_text] (summary 留空),流式发 response.reasoning_text.* 事件而非规范的 response.reasoning_summary_*,按规范实现的客户端(Codex CLI 等)看不到思考过程。 新增 converters 三个形状触发的归一化入口(标准上游零改动、幂等),接入 Responses 透传流式主路 runResponsesFold、兜底逐行中继 processLine 与 非流式 ConvertToResponsesResponse;content_index 同步迁移为 summary_index。
Author
|
我没测在在最新版上生没生效!因为新版本相较于v2.9.37变化太大,我不会用了。补丁应用在v2.9.37版本上是正常的。 |
- compact_local.go V1 本地压缩透传分支接入 NormalizeOpenRouterReasoningSSELine: OpenRouter 非标准 reasoning_text.* / content_part(reasoning_text) 归一化后 恰好落入 shouldSkipCompactStreamEvent 现有过滤清单,修复思考增量泄漏进 compact 流(responses 渠道原生 compact 失败回退本地压缩为常态路径) - helpers.go knownTypes 补全标准事件:content_part.added/.done、output_text.done、 output_json.done、refusal.delta/.done、audio(.transcript).done——这些高频标准 事件此前会被误判 unknown,导致空流诊断文案被 seenUnknown 分支抢占失真 (仅影响诊断日志,不影响 commit/failover 判定;v2.9.37 原版既有缺口) - 补充两组回归测试:归一化后过滤行为 + 标准事件名白名单
- stream.go:203 preflight循环对OpenRouter原始行调用NormalizeOpenRouterReasoningSSELine - stream_processor.go: HasResponsesSemanticContent增加reasoning_text.delta/.done和reasoning_summary_text.delta - helpers.go: firstUnknownResponsesEventType knownTypes表补全reasoning_text事件 - 测试文件补充新增事件类型的回归用例 根因:preflight循环未归一化导致OpenRouter非标准reasoning事件被误判为空流
…light - Remove isRetryableResponsesError gate: all upstream error events (response.error/response.failed) now wrap with ErrEmptyStreamResponse to trigger key/channel failover during preflight - Blacklisted errors (API key invalid, etc.) still fail immediately - Comment out unused isRetryableResponsesError function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
OpenRouter 的 Responses API 实现与 OpenAI 规范有系统性偏差,导致按规范实现的客户端(Codex CLI 等)看不到思考过程:
content[]的reasoning_textpart(summary[]留空)summary[]的summary_textpartresponse.reasoning_text.delta/.done事件response.reasoning_summary_text.*/response.reasoning_summary_part.*content_part事件携带reasoning_textpartsummary_textpartcontent_index/summary_index字段方案
新增
backend-go/internal/converters/responses_reasoning_normalize.go,提供三个形状触发的归一化入口:NormalizeOpenRouterReasoningEvent— 流式 SSE 单事件归一化NormalizeOpenRouterReasoningSSELine— 兜底逐行中继路径NormalizeOpenRouterReasoningResponseBody— 非流式响应体归一化接入点:
handlers/responses/fold.gorunResponsesFold事件循环统一归一化handlers/responses/stream.goprocessLineproviders/responses.goConvertToResponsesResponse设计要点:
content_index同步迁移为summary_index;仅在 summary 为空且 content 全为 reasoning_text 时才改写,不吞并其他内容测试
converters/responses_reasoning_normalize_test.go:三种形状的单元测试(238 行)handlers/responses/fold_openrouter_reasoning_test.go:流式 fold 路径集成测试(SSE 帧序列断言)providers/responses_openrouter_reasoning_test.go:非流式转换路径测试分支上已通过
go test ./...。说明