Configure HTTPS agent for proxies (#775)

- Some workflows require you to route openAI API traffic through a proxy
- See
https://github.com/openai/openai-node/tree/v4?tab=readme-ov-file#configuring-an-https-agent-eg-for-proxies
for more details

---------

Co-authored-by: Thibault Sottiaux <tibo@openai.com>
Co-authored-by: Fouad Matin <fouad@openai.com>
This commit is contained in:
anup-openai
2025-05-02 12:08:13 -07:00
committed by GitHub
parent b864cc3810
commit f6b1ce2e3a
3 changed files with 26 additions and 0 deletions

View File

@@ -34,6 +34,7 @@
"fast-npm-meta": "^0.4.2", "fast-npm-meta": "^0.4.2",
"figures": "^6.1.0", "figures": "^6.1.0",
"file-type": "^20.1.0", "file-type": "^20.1.0",
"https-proxy-agent": "^7.0.6",
"ink": "^5.2.0", "ink": "^5.2.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"marked": "^15.0.7", "marked": "^15.0.7",

View File

@@ -29,6 +29,7 @@ import {
setSessionId, setSessionId,
} from "../session.js"; } from "../session.js";
import { handleExecCommand } from "./handle-exec-command.js"; import { handleExecCommand } from "./handle-exec-command.js";
import { HttpsProxyAgent } from "https-proxy-agent";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
import OpenAI, { APIConnectionTimeoutError } from "openai"; import OpenAI, { APIConnectionTimeoutError } from "openai";
@@ -38,6 +39,9 @@ const RATE_LIMIT_RETRY_WAIT_MS = parseInt(
10, 10,
); );
// See https://github.com/openai/openai-node/tree/v4?tab=readme-ov-file#configuring-an-https-agent-eg-for-proxies
const PROXY_URL = process.env["HTTPS_PROXY"];
export type CommandConfirmation = { export type CommandConfirmation = {
review: ReviewDecision; review: ReviewDecision;
applyPatch?: ApplyPatchCommand | undefined; applyPatch?: ApplyPatchCommand | undefined;
@@ -314,6 +318,7 @@ export class AgentLoop {
: {}), : {}),
...(OPENAI_PROJECT ? { "OpenAI-Project": OPENAI_PROJECT } : {}), ...(OPENAI_PROJECT ? { "OpenAI-Project": OPENAI_PROJECT } : {}),
}, },
httpAgent: PROXY_URL ? new HttpsProxyAgent(PROXY_URL) : undefined,
...(timeoutMs !== undefined ? { timeout: timeoutMs } : {}), ...(timeoutMs !== undefined ? { timeout: timeoutMs } : {}),
}); });

20
pnpm-lock.yaml generated
View File

@@ -52,6 +52,9 @@ importers:
file-type: file-type:
specifier: ^20.1.0 specifier: ^20.1.0
version: 20.4.1 version: 20.4.1
https-proxy-agent:
specifier: ^7.0.6
version: 7.0.6
ink: ink:
specifier: ^5.2.0 specifier: ^5.2.0
version: 5.2.0(@types/react@18.3.20)(react@18.3.1) version: 5.2.0(@types/react@18.3.20)(react@18.3.1)
@@ -680,6 +683,10 @@ packages:
engines: {node: '>=0.4.0'} engines: {node: '>=0.4.0'}
hasBin: true hasBin: true
agent-base@7.1.3:
resolution: {integrity: sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw==}
engines: {node: '>= 14'}
agentkeepalive@4.6.0: agentkeepalive@4.6.0:
resolution: {integrity: sha512-kja8j7PjmncONqaTsB8fQ+wE2mSU2DJ9D4XKoJ5PFWIdRMa6SLSN1ff4mOr4jCbfRSsxR4keIiySJU0N9T5hIQ==} resolution: {integrity: sha512-kja8j7PjmncONqaTsB8fQ+wE2mSU2DJ9D4XKoJ5PFWIdRMa6SLSN1ff4mOr4jCbfRSsxR4keIiySJU0N9T5hIQ==}
engines: {node: '>= 8.0.0'} engines: {node: '>= 8.0.0'}
@@ -1383,6 +1390,10 @@ packages:
highlight.js@10.7.3: highlight.js@10.7.3:
resolution: {integrity: sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==} resolution: {integrity: sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==}
https-proxy-agent@7.0.6:
resolution: {integrity: sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==}
engines: {node: '>= 14'}
human-signals@5.0.0: human-signals@5.0.0:
resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==} resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==}
engines: {node: '>=16.17.0'} engines: {node: '>=16.17.0'}
@@ -2920,6 +2931,8 @@ snapshots:
acorn@8.14.1: {} acorn@8.14.1: {}
agent-base@7.1.3: {}
agentkeepalive@4.6.0: agentkeepalive@4.6.0:
dependencies: dependencies:
humanize-ms: 1.2.1 humanize-ms: 1.2.1
@@ -3784,6 +3797,13 @@ snapshots:
highlight.js@10.7.3: {} highlight.js@10.7.3: {}
https-proxy-agent@7.0.6:
dependencies:
agent-base: 7.1.3
debug: 4.4.0
transitivePeerDependencies:
- supports-color
human-signals@5.0.0: {} human-signals@5.0.0: {}
humanize-ms@1.2.1: humanize-ms@1.2.1: