feat(ai-provider): route provider HTTP through proxy-aware net.fetch#16207
Open
DeJeune wants to merge 1 commit into
Open
feat(ai-provider): route provider HTTP through proxy-aware net.fetch#16207DeJeune wants to merge 1 commit into
DeJeune wants to merge 1 commit into
Conversation
Add a composable `customFetch` (Electron `net.fetch`) and install it as the default base fetch in `providerToAiSdkConfig`. `net.fetch` runs on Chromium's network stack, so it honours the app proxy configured by ProxyManager via session.setProxy()/app.setProxy() — unlike Node's globalThis.fetch (undici). `settings.fetch ??= customFetch` preserves provider-specific fetch wrappers: the CherryAI request-signing wrapper now composes onto customFetch instead of the global fetch, and the HTTP-trace wrapper layers on top — keeping the proxy as the innermost network call in every case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: suyao <sy20010504@gmail.com>
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.
What this PR does
Before this PR:
globalThis.fetch(undici). The app proxy reached them only through the undici global-dispatcher patch inNodeProxyController, and provider-specific fetch wrappers (e.g. CherryAI request signing) called the globalfetchdirectly.After this PR:
customFetchbuilt on Electronnet.fetchis added and installed as the default base fetch for every provider config inproviderToAiSdkConfig(settings.fetch ??= customFetch).net.fetchruns on Chromium's network stack, so requests honour the app proxy configured byProxyManagerviasession.setProxy()/app.setProxy().customFetchinstead of being replaced: the CherryAI signing wrapper now callscustomFetch, and the dev-mode HTTP-trace wrapper layers above it — the proxy-awarenet.fetchstays the innermost network call in every case.N/A
Why we need it and why it was done in this way
Routing AI provider traffic through
net.fetchmakes the configured app proxy apply on Chromium's network stack (PAC / SOCKS / auth handled natively, consistent with the rest of the app'snet.fetchusage), rather than depending solely on the symbol-based undici dispatcher patch.The following tradeoffs were made:
customFetchis the innermost base; higher layers (provider signing, HTTP trace) wrap it. Installed via??=so a provider that ships its own fetch wrapper is preserved, not clobbered.The following alternatives were considered:
providerSettings.fetch = customFetch— would clobber provider wrappers such as CherryAI request signing.Links to places where the discussion took place: N/A
Breaking changes
None.
Special notes for your reviewer
The custom image transports (dmxapi / ppio / ovms) that call bare
fetch(...)directly are intentionally out of scope — they still proxy via the undici dispatcher patch. This PR unifies the provider-config fetch path only.Checklist
This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.
mainfor active development,v1for v1 maintenance fixes/gh-pr-review,gh pr diff, or GitHub UI) before requesting review from othersRelease note