Skip to content

Feat/proxy support#337

Open
xsgeng wants to merge 10 commits into
MoonshotAI:mainfrom
xsgeng:feat/proxy-support
Open

Feat/proxy support#337
xsgeng wants to merge 10 commits into
MoonshotAI:mainfrom
xsgeng:feat/proxy-support

Conversation

@xsgeng
Copy link
Copy Markdown

@xsgeng xsgeng commented Jun 2, 2026

Related Issue

Resolve #104 #203

Problem

no proxy support

What changed

Support HTTP_PROXY, HTTPS_PROXY, and NO_PROXY for LLM and OAuth requests.

  • Uses undici's EnvHttpProxyAgent when proxy env vars are set; otherwise uses global fetch with no overhead.
  • Applied to all LLM providers (OpenAI, Anthropic, Kimi) and OAuth flows.
  • NO_PROXY defaults to localhost,127.0.0.1 when not set.
  • Added tests and bilingual docs.

Why: undici is already a dependency in both kosong and oauth, so this adds proxy support without new dependencies. The helper is duplicated across the two packages (they don't depend on each other) with cross-reference comments to keep them in sync.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 2, 2026

🦋 Changeset detected

Latest commit: bb1c554

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/kosong Minor
@moonshot-ai/kimi-code-oauth Minor
@moonshot-ai/kimi-code Minor
@moonshot-ai/agent-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c083ff53a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kosong/src/proxy.ts Outdated
Comment thread packages/oauth/src/open-platform.ts Outdated
Comment thread docs/en/configuration/env-vars.md Outdated
Comment thread packages/kosong/package.json Outdated
xsgeng added 4 commits June 2, 2026 20:48
Undici's EnvHttpProxyAgent ignores uppercase NO_PROXY when both
cases exist, so our explicit override must match that precedence.
Otherwise hosts listed in lowercase no_proxy are still proxied.

Add regression tests for the mixed-case scenario.
The interactive login flow in auth.ts was passing raw global fetch to
fetchOpenPlatformModels, bypassing the proxy-aware default. In
proxy-only environments the initial key verification would fail even
though later refresh paths work.

Make fetchOpenPlatformModels' fetchImpl parameter optional so callers
that omit it (or pass undefined) automatically get getProxyFetch().
6.21.0 is in the affected range for GHSA-cxrh-j4jr-qwg3.
Because the new proxy helper imports undici on LLM/OAuth paths and
clients can be pointed at custom URLs, users would inherit known
vulnerabilities unnecessarily.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb1c554e45

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pnpm-lock.yaml
Comment on lines +328 to +329
specifier: 6.21.0
version: 6.21.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Refresh the lockfile to match the patched undici range

The lockfile importer still records undici as specifier: 6.21.0/version: 6.21.0 even though the corresponding packages/kosong/package.json entry now declares ^6.21.2 (and the same mismatch exists for packages/oauth). In the CI/frozen-lockfile context, pnpm treats a lockfile that is out of sync with the manifest as an install failure, and if installed from this lockfile it also keeps resolving the older 6.21.0 release instead of the patched range; please regenerate pnpm-lock.yaml after the package.json change.

Useful? React with 👍 / 👎.

process.env['https_proxy'];

if (!hasProxy) {
proxyFetch = fetch;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don’t cache unproxied fetch across global replacements

When no proxy variables are set, this caches whichever globalThis.fetch is present on the first call and reuses it forever. Existing OAuth tests and SDK consumers stub or replace globalThis.fetch per call/test; after the first request, later requests in the same process still go through the stale stub instead of the current global fetch, whereas the old direct fetch(...) path always honored the replacement. Return fetch directly in the no-proxy branch (or use the same dynamic-global delegation as the proxy wrapper), and mirror the fix in packages/kosong/src/proxy.ts.

Useful? React with 👍 / 👎.

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.

http_proxy support

1 participant