Add Responses-to-Anthropic Moon Bridge port#285
Conversation
KilimiaoSix
left a comment
There was a problem hiding this comment.
本次不通过,建议先修复以下问题后再合并:
-
crates/service/src/gateway/upstream/protocol/aggregate_api.rsL818-L823:Claude 聚合 API bridge 硬编码/v1/messages,但默认 Claude provider URL 是https://api.anthropic.com/v1,build_upstream_url会把路径追加到 base path 上,实际变成/v1/v1/messages。这里同时绕过了用户配置的candidate.action,默认 Claude 聚合 API 会直接打错地址。 -
crates/service/src/gateway/upstream/protocol/aggregate_api.rsL575-L606:新 bridge 走通用build_aggregate_api_request,只转发 OpenAI 请求头并默认加Authorization: Bearer,没有补anthropic-version,默认 auth 也没有x-api-key。Anthropic Messages API 运行时请求会因为缺少必需 header/auth 失败;probe 路径已有 Claude 专用 header,但运行时路径没有同步。 -
crates/service/src/gateway/observability/http_bridge/delivery.rsL2280-L2290:ResponsesFromAnthropicMessages的流式分支没有使用旁边适配器都用的respond_streaming_chunked,而是直接request.respond(Response::new(...))。这绕过了现有按 read chunk flush 的 SSE 发送路径,可能导致客户端收不到低延迟流式输出。 -
crates/service/src/gateway/protocol_adapter/request_router.rsL57-L65、L657-L675:reasoning.effort=high会生成budget_tokens=8192,但max_tokens默认只有4096;用户显式传更小max_output_tokens时也会触发。Anthropic extended thinking 要求 thinking budget 与max_tokens合法匹配,这类请求会被上游校验拒绝。
我在独立 worktree 上验证过:
cargo check -p codexmanager-service --libcargo test -p codexmanager-service responses_from_anthropic --libcargo test -p codexmanager-service responses_request_rewrites --libcargo test -p codexmanager-service bridge_tests --lib
这些现有/新增测试通过,但未覆盖上述生产路径问题。
1ae57c8 to
28c3662
Compare
|
@KilimiaoSix 已按 review 的 4 个点补了独立修复提交 修复内容:
验证: |
Summary
This PR ports the Responses-to-Anthropic bridge from the fork into the current upstream
main.The goal is to provide a Moon Bridge-style compatibility path for clients that send OpenAI Responses API requests while the selected aggregate upstream is configured as an Anthropic/Claude-compatible provider, especially DeepSeek's official Anthropic API endpoint:
ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic/v1/responsesto/v1/messagesWhat Changed
ResponsesFromAnthropicMessagesresponse adapter./v1/responsestraffic and bridges them to/v1/messages.modelstreammax_output_tokens/max_tokens->max_tokensinstructions/ system or developer input ->systemmessages[].content[].textfunction_call-> Anthropictool_usefunction_call_output-> Anthropictool_resulttools[].input_schematool_choice-> Anthropictool_choicereasoning.effort-> Anthropicthinkingtool_useblocks in the finalresponse.completed.response.output, so downstream Responses clients can derive tool execution from the terminal response object.imageblocks because DeepSeek's Anthropic API compatibility documentation marks image content as unsupported.Moon Bridge Port Scope
This is a port of the Moon Bridge-style bridge pattern for Codex Manager's gateway architecture:
/v1/responses.The implementation is intentionally integrated with Codex Manager's existing gateway layers:
Current Compatibility
Covered:
https://api.deepseek.com/anthropic/v1/messagesKnown follow-up gaps before claiming complete Moon Bridge parity:
thinkingresponse blocks are not fully mapped into Responses reasoning output.server_tool_useandweb_search_tool_resultresponse blocks are not fully mapped into Responses output items yet.Validation
Ran:
Notes:
pnpm run build:desktopwas run fromapps/after installing missing frontend dependencies withpnpm install.cargo fmt --checkcurrently reports formatting differences in unrelated upstream files fromqxcnm/main; this PR only checks the bridge-related Rust files to avoid mixing unrelated formatting churn into the Moon Bridge port.