Repository navigation
fix: 按 MIME 转换 Anthropic 媒体并安全拒绝非法载荷(部分修复) - #984
Merged
ranxi2001 merged 8 commits intoNov 21, 2026
Merged
Conversation
Choose image/document blocks from supported data URI MIME types, decode plain text documents, and return safe local 400 errors for unsupported or malformed media on OpenAI compatibility routes. Preserve shared document consumers and legacy URL handling. Refs #981
Validate Anthropic-target Chat media before generic tool/function flattening and retain supported structured tool output. Keep the existing converter default permissive for Gemini and Antigravity, opting actual Anthropic forwarding into strict MIME checks. Refs #981
Use API-key Gemini accounts for both media compatibility entry points, matching native request roots and JSON/SSE responses. Keep Antigravity wrapped upstream SSE and add Chat OAuth plus Responses OAuth rejection controls without changing production guards or media assertions. Refs #981
…lation Initialize media handler keys with the documented long-context default, assert the shared Gemini document carrier for Antigravity Gemini targets, and exclude only the candidate-only dependent media fixtures from complete historical RED overlays. Refs #981
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.
合并前验收,当前提交
3209eb3359b31f34d2c8fc4bca82c21148ad0d6f。 本 PR 交付 #981 的 MIME 转换和本地拒绝部分。PNG、JPEG、GIF、WebP、PDF 和纯文本按 MIME 转换,兼容上游原生音视频开关继续由 #981 跟踪。测试修复
6e10e4043将工具媒体用例的模拟上游改为 HTTPS,保留生产 URL 校验。当前提交已整合 production 的 #971 和 #986。执行gh pr checks 984 -R ranxi2001/sub2api核对 63 项通过、12 项按工作流条件跳过。覆盖 Chat 和 Responses 的媒体转换、流式及非流式工具结果和后端单元测试。CI 结果本轮维护由 Codex(GPT-6,环境未提供完整模型 ID 和推理强度)定位 CI 失败、修复测试、复核代码和最终检查。以下保留作者的历史记录。
2026-11-21 exact-head CI repair
bd84e0f28: initialize media handler keys with documented AllowLongContext=true default; preserve the real restricted-key production guard and all MIME/upstream/billing assertions. Correct Antigravity Gemini-target assertions to inspect the existing serialized document carrier including exact MIME/data rather than incorrectly expecting inlineData for unsupported document types.新增具名回归(全部本地 NOT RUN):
TestGatewayAnthropicChatToolMediaRejectsBeforeFlattening、TestNativeAnthropicChatToolMediaRejectsBeforeFlattening、TestChatAnthropicToolMediaPreservesParallelAndStringOutputs、TestResponsesToAnthropicMediaPolicyDefaultsRemainCompatible、TestGeminiCompatibilityMediaPolicyIsTargetScoped、TestAntigravityCompatibilityMediaPolicyIsTargetScoped、TestGeminiCompatibilityMediaPolicyOAuthControls。前置校验拒绝真实carrier而非普通字符串;支持媒体保留tool/function配对;strict仅四个实际Anthropic出口启用,其余Gemini/Antigravity保留permissive carrier。原生audio/video opt-in未实现,Refs #981,不关闭Issue。披露:父级核实Codex原writer rollout
gpt-6.1-sol/ultra,fast仅requested;继承的Codex只读子Agent实际ID/强度未知。Hermes父级及两轮只读独审gpt-6.1-sol,推理强度未知(接口未提供)。独审只读,父级发布与remoteCI验收,未运行本地动态检查/生产/付费请求。以下保留模板与初片范围;其旧候选SHA仅为历史源码检查,不代替当前head执行证据。解决的问题与行为变化
/v1/chat/completions、/v1/responses在 image/file 字段收到视频、音频等 data URI 时,仅按字段生成 image/document,MIME 原样照搬,可能收到上游 400;旧模型的转换失败还可能退化为通用服务端错误。400 invalid_request_error。关联记录与来源
981、anthropic media,均无结果。管理员新功能提示
NewFeatureBadge展示位置:不适用,无 UI 入口。复现与验收
ranxi2001/sub2api,baseproduction,基线04478a2e1a658c03c8632fc79e28255ef354c094;候选32438a39c47b25b50d7df3d5066ac1cf02c00e54。仅使用虚构数据编写回归,未进行生产复现。backend/internal/handler/gateway_anthropic_media_test.go、backend/internal/pkg/apicompat/responses_to_anthropic_media_test.go、backend/internal/pkg/antigravity/tool_result_images_test.go、backend/internal/service/gateway_anthropic_media_test.go。尚未覆盖真实兼容供应商原生音视频能力。协议、调度或传输改动补充
routes/gateway.go→GatewayHandler.ChatCompletions/Responses→GatewayService.ForwardAsChatCompletions/ForwardAsResponses→ Chat→Responses(仅 Chat)→ResponsesToAnthropicRequest→ MIME helper;CN native Anthropic 路径使用同一转换器。{"type":"input_image","image_url":"data:video/mp4;base64,c3ludGhldGlj"}→ 本地 400;input_file携带 image/png → image;input_image携带 PDF → document。invalid_request_error,消息仅包含固定文本,不拼接输入 MIME/URI/正文;新失败不产生上游 request ID 或 usage。实际验证
git diff --check、git diff --cached --checkgit diff HEAD^ HEAD --checkTestGatewayAnthropicMediaHandlersTestResponsesToAnthropicMediaMIMEBlocks、TestResponsesToAnthropicMediaRejectsSafely、TestResponsesToAnthropicMediaURLPolicy、TestResponsesToAnthropicToolMediaRejectsSafely、TestResponsesToAnthropicMediaLeavesTextUntouchedTestResponsesPlainDocumentSurvivesAnthropicBridge、TestGeminiDocumentsSurviveAnthropicMIMEBridge首次未满足的验收门槛为当前 head 远程定向回归执行及候选编译;具名新回归尚未运行。当前仅交付可审查源码增量;Draft 可先发布,不以等待大套件阻塞。
兼容性与运行影响
文档与用户可见变化
客户端得到明确的本地媒体格式错误;受支持媒体按 MIME 生成合法块。本次不新增设置页或音视频理解能力。原生兼容上游 opt-in 需明确供应商版本、schema、能力边界及隔离验证,仍属于 #981 后续范围;不关闭 Issue。提交、PR、Release 与生产部署状态分别披露。
Agent 使用声明
/root:唯一源码与提交 writer;问题分析、回归源码、实现及本正文。运行环境标识 GPT-6;完整部署模型 ID、推理强度不可获取,均为未知。brief 请求gpt-6.1-sol/ultra/ fast,不能据此声称实际交付配置一致。/root/media_readonly_review:只读链路/调用者/原生能力审计,无修改和动态检查;继承父模型设置,完整 ID/强度未知。后续复核请求因工具载荷缺失未执行。/root/static_review:未完成实质复核,工具载荷缺失;无修改或检查。继承父模型设置,完整 ID/强度未知。提交前自查