Skip to content

Commit e7e8b82

Browse files
authored
🤖 fix: respect HTTP_PROXY env vars for network requests (#871)
Switch from undici `Agent` to `EnvHttpProxyAgent` to automatically respect `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables. **Benefits:** - Enables debugging/inspection via proxy tools like mitmproxy - Supports corporate network environments that require proxying The `EnvHttpProxyAgent` inherits all the same timeout configuration (`bodyTimeout: 0`, `headersTimeout: 0`) to prevent `BodyTimeoutError` on long-running reasoning model pauses. _Generated with `mux`_
1 parent 4cae00f commit e7e8b82

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/node/services/aiService.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ import type {
4444
} from "@/common/types/stream";
4545
import { applyToolPolicy, type ToolPolicy } from "@/common/utils/tools/toolPolicy";
4646
import { MockScenarioPlayer } from "./mock/mockScenarioPlayer";
47-
import { Agent } from "undici";
47+
import { EnvHttpProxyAgent, type Dispatcher } from "undici";
4848

4949
// Export a standalone version of getToolsForModel for use in backend
5050

5151
// Create undici agent with unlimited timeouts for AI streaming requests.
5252
// Safe because users control cancellation via AbortSignal from the UI.
53-
const unlimitedTimeoutAgent = new Agent({
53+
// Uses EnvHttpProxyAgent to automatically respect HTTP_PROXY, HTTPS_PROXY,
54+
// and NO_PROXY environment variables for debugging/corporate network support.
55+
const unlimitedTimeoutAgent = new EnvHttpProxyAgent({
5456
bodyTimeout: 0, // No timeout - prevents BodyTimeoutError on long reasoning pauses
5557
headersTimeout: 0, // No timeout for headers
5658
});
5759

5860
// Extend RequestInit with undici-specific dispatcher property (Node.js only)
59-
type RequestInitWithDispatcher = RequestInit & { dispatcher?: InstanceType<typeof Agent> };
61+
type RequestInitWithDispatcher = RequestInit & { dispatcher?: Dispatcher };
6062

6163
/**
6264
* Default fetch function with unlimited timeouts for AI streaming.

0 commit comments

Comments
 (0)