fix: route Anthropic SDK clients through guarded transport#101357
Conversation
Co-authored-by: wangmiao0668000666 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98a684caaf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const fetchOptions = | ||
| /^kimi(?:-|$)/.test(model.provider) && thinkingEnabled | ||
| ? { sanitizeSse: false as const } | ||
| : undefined; | ||
| const fetch = getAiTransportHost().buildModelFetch(model, undefined, fetchOptions); |
There was a problem hiding this comment.
Preserve Kimi sanitizer bypass for payload-patched thinking
When Kimi Anthropic thinking is enabled via the shipped plugin's extraParams.thinking wrapper rather than via options.reasoning, this check stays false because the wrapper only adds payload.thinking in onPayload (extensions/kimi-coding/stream.ts, covered by extensions/kimi-coding/stream.test.ts), and onPayload runs after this client/fetch is built. In that configuration (extraParams: { thinking: "enabled" } with the session thinking level still off), the new guarded SDK fetch uses the default SSE sanitizer even though the sibling Anthropic transport documents that Kimi thinking streams must pass sanitizeSse: false or they can stall before the text block (src/agents/anthropic-transport-stream.ts).
Useful? React with 👍 / 👎.
|
Merged via squash.
|
Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
Related: #100550
AI-assisted: Codex
What Problem This Solves
Fixes an issue where Anthropic-compatible requests from GitHub Copilot, Microsoft Foundry, Anthropic OAuth/API-key clients, Kimi, and Amazon Bedrock Mantle could bypass OpenClaw's guarded model transport when the Anthropic SDK created the HTTP request.
Why This Change Was Made
Every Anthropic SDK client now receives the host-built guarded fetch, matching the existing Cloudflare and extracted Anthropic transport paths. Kimi thinking streams retain their required SSE sanitizer bypass, and Mantle uses the public provider transport runtime seam.
User Impact
Anthropic-compatible provider routes now consistently receive OpenClaw's request policy, response normalization, and managed stream cleanup instead of depending on the SDK's default fetch. Provider auth and request payload behavior are unchanged.
Evidence
21d919deb801939d185e548cb70268b05045ebf9: the real-SDK loopback test failed because the host fetch recorded zero calls.31432bf10160512956573c8010b0d1bb5cdf75f2: 61 core Anthropic tests and 11 Mantle tests passed. The loopback test exercised the real Anthropic SDK over HTTP and verified Copilot, Foundry, OAuth, API-key, and Kimi auth/request paths.pnpm check:changedon Blacksmith Testboxtbx_01kwxc5vmckc01qzmfff04chka: core/plugin typechecks, lint, dependency guards, import-cycle checks, and boundary checks passed..agents/skills/autoreview/scripts/autoreview --mode local --engine codex --model gpt-5.5 --thinking high: clean, no accepted/actionable findings.Dependency contract checked against
@anthropic-ai/sdksdk-v0.109.1:ClientOptions.fetchis the supported constructor seam and request dispatch uses that configured fetch.