diff --git a/api/app/clients/AnthropicClient.js b/api/app/clients/AnthropicClient.js index ebd94ca9b1..8943c00afe 100644 --- a/api/app/clients/AnthropicClient.js +++ b/api/app/clients/AnthropicClient.js @@ -1,5 +1,5 @@ +const { ProxyAgent } = require('undici'); const Anthropic = require('@anthropic-ai/sdk'); -const { HttpsProxyAgent } = require('https-proxy-agent'); const { Constants, ErrorTypes, @@ -193,7 +193,7 @@ class AnthropicClient extends BaseClient { }; if (this.options.proxy) { - options.httpAgent = new HttpsProxyAgent(this.options.proxy); + options.httpAgent = new ProxyAgent(this.options.proxy); } if (this.options.reverseProxyUrl) { diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js index 8c58d70f70..238ff533ea 100644 --- a/api/app/clients/OpenAIClient.js +++ b/api/app/clients/OpenAIClient.js @@ -1,6 +1,6 @@ const OpenAI = require('openai'); +const { ProxyAgent } = require('undici'); const { OllamaClient } = require('./OllamaClient'); -const { HttpsProxyAgent } = require('https-proxy-agent'); const { SplitStreamHandler } = require('@librechat/agents'); const { Constants, @@ -674,8 +674,7 @@ class OpenAIClient extends BaseClient { } if (this.options.proxy) { - configOptions.httpAgent = new HttpsProxyAgent(this.options.proxy); - configOptions.httpsAgent = new HttpsProxyAgent(this.options.proxy); + configOptions.httpAgent = new ProxyAgent(this.options.proxy); } const { req, res, debug } = this.options; @@ -1173,7 +1172,7 @@ ${convo} } if (this.options.proxy) { - opts.httpAgent = new HttpsProxyAgent(this.options.proxy); + opts.httpAgent = new ProxyAgent(this.options.proxy); } /** @type {TAzureConfig | undefined} */ diff --git a/api/app/clients/generators.js b/api/app/clients/generators.js index 4d3988bf34..3455942528 100644 --- a/api/app/clients/generators.js +++ b/api/app/clients/generators.js @@ -1,3 +1,4 @@ +const { fetch } = require('undici'); const { GraphEvents } = require('@librechat/agents'); const { logger, sendEvent } = require('~/config'); @@ -15,12 +16,15 @@ function createFetch({ directEndpoint = false, reverseProxyUrl = '' }) { * @param {RequestInit} [init] - Optional init options for the request. * @returns {Promise} - A promise that resolves to the response of the fetch request. */ - return async (_url, init) => { + return async (_url, { agent, ...init }) => { let url = _url; if (directEndpoint) { url = reverseProxyUrl; } logger.debug(`Making request to ${url}`); + if (agent != null) { + init.dispatcher = agent; + } if (typeof Bun !== 'undefined') { return await fetch(url, init); } diff --git a/api/package.json b/api/package.json index 433fb03e5a..1d6effb7b7 100644 --- a/api/package.json +++ b/api/package.json @@ -108,6 +108,7 @@ "tiktoken": "^1.0.15", "traverse": "^0.6.7", "ua-parser-js": "^1.0.36", + "undici": "^7.8.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1", "youtube-transcript": "^1.2.1", diff --git a/package-lock.json b/package-lock.json index c17ccc6a14..0b0d5fa62a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -124,6 +124,7 @@ "tiktoken": "^1.0.15", "traverse": "^0.6.7", "ua-parser-js": "^1.0.36", + "undici": "^7.8.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1", "youtube-transcript": "^1.2.1", @@ -40965,6 +40966,14 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "node_modules/undici": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.8.0.tgz", + "integrity": "sha512-vFv1GA99b7eKO1HG/4RPu2Is3FBTWBrmzqzO0mz+rLxN3yXkE4mqRcb8g8fHxzX4blEysrNZLqg5RbJLqX5buA==", + "engines": { + "node": ">=20.18.1" + } + }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",