Repository navigation
refactor: 按策略拆分上游请求准备与多协议非流式格式化 - #16
Merged
Merged
Conversation
hawklithm
changed the base branch from
fix/domestic-developer-role-compat
to
main
October 22, 2026 16:23
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.
目的
在不修改业务逻辑与对外协议契约的前提下,对代理的上游请求准备与非流式响应格式化进行职责分离。避免对高风险 SSE/DSML 状态机做大改,采用能够独立验证的渐进式重构。
依赖 PR #15 的
role_compat.py,故本 PR 暂以fix/domestic-developer-role-compat为基线,仅显示结构性改动;待 #15 合并后可将本 PR 的 base 改为main。设计模式及重构内容
Builder + 组合策略(
upstream_request.py)ChatRequestPreparer负责构建上游 URL、规范化请求、保留客户端 stream 选项、添加认证与 SSE Headers;DomesticDeveloperRolePolicy负责国内站developer → system兼容;InternationalConversationHeaderPolicy负责国际站会话标识 Headers;tool_choice规范化 → 网关角色适配 → 可选脱敏 → 上游流式参数 → Headers → 网关会话 Headers。codebuddy.aiURL 匹配逻辑、异常降级与诊断事件,不趁重构修改网关判定契约。Strategy / Registry(
protocol_response.py)convert_nonstream中的 OpenAI、Anthropic、Responses 结构转换拆为独立格式化策略;convert_nonstream旧调用入口,保留 ID 生成、工具参数 JSON 解析/失败退化、模型来源、usage、stop_reason 和未知协议原样返回等契约。Controller 瘦身(
__main__.py)测试和文档
test_upstream_request_pipeline.py、test_protocol_response_strategies.py的精确行为测试;docs/refactor-request-response-boundaries.md。验证
0600权限断言,与本次代码重构无关。compileall通过,Git whitespace 检查通过,无新运行时依赖。审查提示
本 PR 只做有限的“请求准备 + 非流式输出”结构重构,不宣称全面完成项目的架构改造。后续如果要进一步拆分模型目录、长生命周期 Session 或 SSE 状态机,应先补充针对它们的 characterization / 契约测试,分别提交。
此 PR 尚未合并,也没有重启本机正在运行的代理。