Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🚀 refactor: Use Undici Instead of Node-Fetch, prevent Event Close, add Index (#3052)
Danny Avila4416f69a9b29
diff --git a/api/app/clients/BaseClient.js b/api/app/clients/BaseClient.jsindex f2b3e7c59b..0f2cd03468 100644--- a/api/app/clients/BaseClient.js+++ b/api/app/clients/BaseClient.js@@ -1,5 +1,6 @@const crypto = require('crypto');-const fetch = require('node-fetch');+const { fetch } = require('undici');+const nodeFetch = require('node-fetch');const { supportsBalanceCheck, Constants } = require('librechat-data-provider');const { getConvo, getMessages, saveMessage, updateMessage, saveConvo } = require('~/models');const { addSpaceIfNeeded, isEnabled } = require('~/server/utils');@@ -69,6 +70,9 @@ class BaseClient {url = this.options.reverseProxyUrl;}logger.debug(`Making request to ${url}`);+ if (typeof Bun !== 'undefined') {+ return await nodeFetch(url, init);+ }return await fetch(url, init);}diff --git a/api/models/schema/messageSchema.js b/api/models/schema/messageSchema.jsindex d9a6dfb939..3e89a5caa9 100644--- a/api/models/schema/messageSchema.js+++ b/api/models/schema/messageSchema.js@@ -11,6 +11,7 @@ const messageSchema = mongoose.Schema(},conversationId: {type: String,+ index: true,required: true,meiliIndex: true,},diff --git a/client/src/hooks/SSE/useSSE.ts b/client/src/hooks/SSE/useSSE.tsindex 02cc63020d..8c9eae93cd 100644--- a/client/src/hooks/SSE/useSSE.ts+++ b/client/src/hooks/SSE/useSSE.ts@@ -604,7 +604,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {events.onerror = function (e: MessageEvent) {console.log('error in server stream.');startupConfig?.checkBalance && balanceQuery.refetch();- events.close();let data: TResData | undefined = undefined;try {