Skip to content

fix: preserve images in cross-protocol tool results - #62

Merged
jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
ai-daming:codex/fix-tool-result-images
Oct 14, 2026
Merged

jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
ai-daming:codex/fix-tool-result-images

Conversation

@ai-daming

Copy link
Copy Markdown
Contributor

问题与修复

工具结果包含图片时,跨协议转换会把整个内容数组序列化为字符串,导致图片成为 Base64 文字,模型无法正常识图且输入 token 膨胀。关联 #60。

  • 复用现有内容解析器与 bridgeBlock,仅规范化含图工具结果,保留原有纯文本和同协议透传路径。
  • 转 Chat 时保留工具回复,用工具调用 ID 和图片编号标记图片位置;所有工具回复输出完后追加对应用户图片消息,沿用现有工具调用排序。
  • 转 Responses / Anthropic 时输出各自的原生工具图片数组,保持图文顺序。
  • 缺失或冲突图片来源、含图结果夹杂不支持的内容块会明确报错,不静默丢图或退回字符串化。不新增文件引用解析或图片下载。

验证

  • go test -race ./...、go vet ./...、本机构建和 Linux amd64 交叉编译通过。
  • 回归测试覆盖多图、图文混合、工具结果乱序、连续工具轮次、普通用户图片、输入不变、同协议透传、纯文本及非法输入。
  • 12 组本地 HTTP 假上游检查:Anthropic/Responses 入口 × Chat/Responses/Anthropic 上游 × 流式/非流式;检查实际路径、图片保留及上游拒绝的错误传播,并验证跨协议非法图片不出站。
  • 已在自有实例试部署:Messages、Responses 两种入口调用 deepseek-v4.1-flash,两张图片按工具 B、A 乱序返回,均正确读出 A 的 BLUE 42 和 B 的 RED 73。

已知边界

Chat 的图片归属通过文字标记表达,属于兼容转换,不保证与原生工具图片完全等价。

gpt-6-luna 原生 Responses 的顺序工具图片测试通过;乱序时能读图但会答反归属,同协议透传对照也复现。因此本 PR 不声称解决该模型的乱序关联问题,也没有修改原生 Responses 的排序规则。真实 Anthropic 上游未验证,已覆盖对应转换与 HTTP 转发检查。

jasonxu114514 added a commit that referenced this pull request Oct 14, 2026
@jasonxu114514
jasonxu114514 merged commit 3fad1c6 into jasonxu114514:main Oct 14, 2026
jasonxu114514 added a commit that referenced this pull request Oct 14, 2026
SK-DEV-AI added a commit to SK-DEV-AI/opencode2api that referenced this pull request Oct 15, 2026
…ver-key usage)

Takes upstream f8e996d/be91f86/0204ca1 (client fingerprint + inference
endpoint + genuine tools), jasonxu114514#59 anon cooldown lockup, jasonxu114514#63 token floor,
jasonxu114514#64 whole-attempt deadline, jasonxu114514#62 tool images, jasonxu114514#58 server-key usage
split, jasonxu114514#65/jasonxu114514#66 models surface, plus our merged jasonxu114514#76/jasonxu114514#77/jasonxu114514#78.

Kept local (fork-owned, still no upstream equivalent): zero-delivery
replay + length rescue + SSE heartbeat + stop/tail census (stream
lanes), offline no_upstream_contact probe guard, single-marshal Zen
shaping with paid-model gate, tcp4 dial + TLS resumption, RandomID
math/rand fallback, cancel-detached refresh fix (PR jasonxu114514#80 superseded by
maintainer feedback; kept locally pending lifetime-context rework).
Telemetry takes upstream's session-burn + server-key split with their
LRU session cap (better than our smallest-first); CloneMap takes
upstream's merged comment. Metrics ring test retargeted at upstream's
concrete ring types. doUpstream keeps upstream's 3-value signature;
replay uses a new doUpstreamCounted wrapper for continuous legs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants