Skip to content

Commit 0165b6c

Browse files
committed
feat: support http proxy
1 parent cec8489 commit 0165b6c

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"commander": "^14.0.0",
5353
"dotenv": "^17.0.1",
5454
"execa": "9.3.1",
55+
"undici": "^7.11.0",
5556
"zod": "^3.25.74"
5657
},
5758
"devDependencies": {

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/code_review/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { stdout } from 'node:process';
22
import { inspect } from 'node:util';
33
import { writeFile } from 'node:fs/promises';
4+
import { fetch, ProxyAgent } from 'undici';
45
import { streamText } from 'ai';
56
import { createOpenAI } from '@ai-sdk/openai';
67
import { createDeepSeek } from '@ai-sdk/deepseek';
@@ -9,7 +10,7 @@ import { createAnthropic } from '@ai-sdk/anthropic';
910
import { createGoogleGenerativeAI } from '@ai-sdk/google';
1011
import type { CodeReviewOptions, CodeReviewResult, CompletionStats } from '../types';
1112
import { getUserPrompt, getSystemPrompt } from './prompts/index';
12-
import { usageToString, statsToString, runCmd } from './utils';
13+
import { usageToString, statsToString, runCmd, getHttpProxyUrl } from './utils';
1314
import { tools } from './tools';
1415

1516
export async function codeReview(options: CodeReviewOptions): Promise<CodeReviewResult> {
@@ -48,6 +49,7 @@ export async function codeReview(options: CodeReviewOptions): Promise<CodeReview
4849
};
4950

5051
// init provider
52+
const httpProxyUrl = getHttpProxyUrl();
5153
const providerInst = (
5254
provider === 'openai'
5355
? createOpenAI
@@ -63,6 +65,11 @@ export async function codeReview(options: CodeReviewOptions): Promise<CodeReview
6365
)({
6466
apiKey,
6567
baseURL: baseUrl,
68+
fetch: (req, options) =>
69+
fetch(req as string, {
70+
...options,
71+
dispatcher: httpProxyUrl ? new ProxyAgent(httpProxyUrl) : undefined,
72+
}),
6673
});
6774

6875
// generate review result

src/code_review/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { env } from 'node:process';
12
import { execa, ExecaError } from 'execa';
23
import type { CompletionUsage, CompletionStats } from '../types';
34

@@ -55,3 +56,7 @@ export async function runCmd(file: string, args: string[]) {
5556
}
5657
}
5758
}
59+
60+
export function getHttpProxyUrl() {
61+
return env.https_proxy || env.HTTPS_PROXY || env.http_proxy || env.HTTP_PROXY;
62+
}

0 commit comments

Comments
 (0)