Skip to content

fix: apply v3.4.0 code-review follow-ups (usage layering, endpoint tables, tool-result media) - #47

Merged
tzzs merged 4 commits into
mainfrom
fix/review-3.4.0-followups
Sep 20, 2026
Merged

tzzs merged 4 commits into
mainfrom
fix/review-3.4.0-followups

Conversation

@tzzs

@tzzs tzzs commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Summary

落地 v3.4.0(PR #45)双轴 code review 中 Standards 轴的全部可修项;Spec 轴无发现,发布元数据无需改动。

  • 核心层越权解析 provider 字段(硬伤 1):streaming/common.ts 不再直接读 total_tokens/cached_tokens;字段表全部归还 providers/usage/openai.ts,usageCapture 经协议映射器存 total/cached(CLAUDE.md 架构约束)
  • 注释/文档失同步(硬伤 2、3):forwardWithRetry 注释补 408;docs/architecture.md 补 GET /v1/models/{id}、POST /v1/messages/count_tokens、并发闸、408 重试码;CLAUDE.md/accessor 名同步
  • 死代码:删除零调用的 withCacheTokens、argsOf、cacheTokensOf 与 UsageCapture.raw
  • Repeated Switches / Duplicated Code:ENDPOINT_SPECS 的 finish/failure 三元链改为 protocol 键映射表(failure 三端点共用一张 FAILURE_BY_PROTOCOL)
  • Divergent Change:estimateInputTokens/IMAGE_TOKEN_ESTIMATE 从 server.ts 移入 convert/shared.ts
  • 修复不彻底的 tool-result 图片(b70e9fb 声称覆盖所有协议但 Anthropic 上游方向漏了):新增 toolResultBlocks(),toAnthropicRequest 与 toAnthropicRequestFromChat 的 tool 输出块数组不再 JSON.stringify 成文本,图片映射回 Anthropic tool_result image blocks,并补 3 个回归测试
  • Mysterious Name:specFor → endpointSpec;json.ts 的 parse 访问器更名为 parseJson(含文档引用)

有意跳过:(input, model, provider) Data Clump——会波及 convert/ 全部公开函数签名与既有测试,属判断题级churn,收益不抵风险。

Test plan

  • npm run typecheck 通过
  • npm run lint 通过
  • npm test 399/399 通过(含 3 个新增 tool_result 图片回归测试)
  • CI 绿后合入 main(与开着的 Release PR chore(main): release 3.4.0 #45 无冲突:本 PR 只动 src/test/docs,不碰版本号与 CHANGELOG)

🤖 Generated with Claude Code via Qoder

…pers

The core layer kept parsing provider payloads itself — a raw
`total_tokens`/`cached_tokens` read in streaming/common.ts — against the
CLAUDE.md architecture rule. Both field lists move into
providers/usage/openai.ts, the capture stores the mapped total, and the
dead withCacheTokens/argsOf paths are removed.
toAnthropicRequest and toAnthropicRequestFromChat still JSON.stringify'd
tool-output block arrays — the exact ~1.37M-character screenshot mistake
toolResultContent() documents for the other direction. A new
toolResultBlocks() maps Chat/Responses text and image parts back to
Anthropic tool_result blocks. The count_tokens token estimator moves from
server.ts into convert/shared.ts alongside the payload logic it reads.
The per-endpoint finish/failure ternary cascades become
protocol-keyed lookup tables (failures shared via one map), the resolved
spec reads as endpointSpec, and json.ts's parse accessor is renamed
parseJson to match its call sites. Docs and comments (retry status set,
new endpoints, concurrency gate) are synced with the shipped behavior.
…elds

input/model/provider traveled together through proxyRequest and all nine
endpoint payload builders, so every signature re-stated the same route.
Binding them into a RequestContext lets the payload seam pass one value
and proxyRequest hand its caller back the same context it resolved.
@tzzs
tzzs merged commit e228f93 into main Sep 20, 2026
20 checks passed
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.

1 participant