Skip to content

Commit 83153cd

Browse files
committed
fix: use of proxy, use undici
1 parent a326c18 commit 83153cd

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

api/app/clients/AnthropicClient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
const { ProxyAgent } = require('undici');
12
const Anthropic = require('@anthropic-ai/sdk');
2-
const { HttpsProxyAgent } = require('https-proxy-agent');
33
const {
44
Constants,
55
ErrorTypes,
@@ -193,7 +193,7 @@ class AnthropicClient extends BaseClient {
193193
};
194194

195195
if (this.options.proxy) {
196-
options.httpAgent = new HttpsProxyAgent(this.options.proxy);
196+
options.httpAgent = new ProxyAgent(this.options.proxy);
197197
}
198198

199199
if (this.options.reverseProxyUrl) {

api/app/clients/OpenAIClient.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const OpenAI = require('openai');
2+
const { ProxyAgent } = require('undici');
23
const { OllamaClient } = require('./OllamaClient');
3-
const { HttpsProxyAgent } = require('https-proxy-agent');
44
const { SplitStreamHandler } = require('@librechat/agents');
55
const {
66
Constants,
@@ -674,8 +674,7 @@ class OpenAIClient extends BaseClient {
674674
}
675675

676676
if (this.options.proxy) {
677-
configOptions.httpAgent = new HttpsProxyAgent(this.options.proxy);
678-
configOptions.httpsAgent = new HttpsProxyAgent(this.options.proxy);
677+
configOptions.httpAgent = new ProxyAgent(this.options.proxy);
679678
}
680679

681680
const { req, res, debug } = this.options;
@@ -1173,7 +1172,7 @@ ${convo}
11731172
}
11741173

11751174
if (this.options.proxy) {
1176-
opts.httpAgent = new HttpsProxyAgent(this.options.proxy);
1175+
opts.httpAgent = new ProxyAgent(this.options.proxy);
11771176
}
11781177

11791178
/** @type {TAzureConfig | undefined} */

api/app/clients/generators.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { fetch } = require('undici');
12
const { GraphEvents } = require('@librechat/agents');
23
const { logger, sendEvent } = require('~/config');
34

@@ -15,12 +16,15 @@ function createFetch({ directEndpoint = false, reverseProxyUrl = '' }) {
1516
* @param {RequestInit} [init] - Optional init options for the request.
1617
* @returns {Promise<Response>} - A promise that resolves to the response of the fetch request.
1718
*/
18-
return async (_url, init) => {
19+
return async (_url, { agent, ...init }) => {
1920
let url = _url;
2021
if (directEndpoint) {
2122
url = reverseProxyUrl;
2223
}
2324
logger.debug(`Making request to ${url}`);
25+
if (agent != null) {
26+
init.dispatcher = agent;
27+
}
2428
if (typeof Bun !== 'undefined') {
2529
return await fetch(url, init);
2630
}

api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"tiktoken": "^1.0.15",
109109
"traverse": "^0.6.7",
110110
"ua-parser-js": "^1.0.36",
111+
"undici": "^7.8.0",
111112
"winston": "^3.11.0",
112113
"winston-daily-rotate-file": "^4.7.1",
113114
"youtube-transcript": "^1.2.1",

package-lock.json

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

0 commit comments

Comments
 (0)