diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index 6b1be74a..4bb5d27e 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Fixed `cacheRetention` option not being passed through in `buildBaseOptions` ([#1154](https://github.com/badlogic/pi-mono/issues/1154)) +- Fixed OAuth login/refresh not using HTTP proxy settings (`HTTP_PROXY`, `HTTPS_PROXY` env vars) ([#1132](https://github.com/badlogic/pi-mono/issues/1132)) ## [0.50.9] - 2026-02-01 diff --git a/packages/ai/src/stream.ts b/packages/ai/src/stream.ts index b1d27e62..fdb4494b 100644 --- a/packages/ai/src/stream.ts +++ b/packages/ai/src/stream.ts @@ -1,4 +1,5 @@ import "./providers/register-builtins.js"; +import "./utils/http-proxy.js"; import { getApiProvider } from "./api-registry.js"; import type { @@ -14,15 +15,6 @@ import type { export { getEnvApiKey } from "./env-api-keys.js"; -// Set up http proxy according to env variables for `fetch` based SDKs in Node.js. -// Bun has builtin support for this. -if (typeof process !== "undefined" && process.versions?.node) { - import("undici").then((m) => { - const { EnvHttpProxyAgent, setGlobalDispatcher } = m; - setGlobalDispatcher(new EnvHttpProxyAgent()); - }); -} - function resolveApiProvider(api: Api) { const provider = getApiProvider(api); if (!provider) { diff --git a/packages/ai/src/utils/http-proxy.ts b/packages/ai/src/utils/http-proxy.ts new file mode 100644 index 00000000..1102e875 --- /dev/null +++ b/packages/ai/src/utils/http-proxy.ts @@ -0,0 +1,13 @@ +/** + * Set up HTTP proxy according to env variables for `fetch` based SDKs in Node.js. + * Bun has builtin support for this. + * + * This module should be imported early by any code that needs proxy support for fetch(). + * ES modules are cached, so importing multiple times is safe - setup only runs once. + */ +if (typeof process !== "undefined" && process.versions?.node) { + import("undici").then((m) => { + const { EnvHttpProxyAgent, setGlobalDispatcher } = m; + setGlobalDispatcher(new EnvHttpProxyAgent()); + }); +} diff --git a/packages/ai/src/utils/oauth/index.ts b/packages/ai/src/utils/oauth/index.ts index 1077d748..a4bb5892 100644 --- a/packages/ai/src/utils/oauth/index.ts +++ b/packages/ai/src/utils/oauth/index.ts @@ -9,6 +9,9 @@ * - Antigravity (Gemini 3, Claude, GPT-OSS via Google Cloud) */ +// Set up HTTP proxy for fetch() calls (respects HTTP_PROXY, HTTPS_PROXY env vars) +import "../http-proxy.js"; + // Anthropic export { anthropicOAuthProvider, loginAnthropic, refreshAnthropicToken } from "./anthropic.js"; // GitHub Copilot