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: Remove Dead Helpers, Classes and Dependencies From packages/api (#17118)
Marco Berettaecd6943194be
diff --git a/api/server/controllers/agents/__tests__/responses.unit.spec.js b/api/server/controllers/agents/__tests__/responses.unit.spec.jsindex 36823a6406..15d9fea185 100644--- a/api/server/controllers/agents/__tests__/responses.unit.spec.js+++ b/api/server/controllers/agents/__tests__/responses.unit.spec.js@@ -263,7 +263,6 @@ jest.mock('@librechat/api', () => ({jest.requireActual('@librechat/api').resolveAdmittedCodeEnvironmentDecision(...args),resolvePersistableCodeEnvironmentDecision: (...args) =>jest.requireActual('@librechat/api').resolvePersistableCodeEnvironmentDecision(...args),- getCodeWorkspaceSelections: jest.fn(),createMCPRuntimeRequestBody: ({messageId,conversationId,@@ -702,9 +701,6 @@ describe('createResponse controller', () => {async (stream) => {const api = require('@librechat/api');const db = require('~/models');- api.getCodeWorkspaceSelections.mockReturnValueOnce([- { environmentId: 'machine', workspaceId: 'stale-project' },- ]);api.validateResponseRequest.mockReturnValueOnce({request: {model: 'agent-123',@@ -725,7 +721,6 @@ describe('createResponse controller', () => {expect.anything(),);expect(db.saveConvo.mock.calls.at(-1)[1]).not.toHaveProperty('codeWorkspaces');- expect(api.getCodeWorkspaceSelections).not.toHaveBeenCalled();},);diff --git a/api/server/services/Files/provision.js b/api/server/services/Files/provision.jsindex 32311cc500..8c2eb618bb 100644--- a/api/server/services/Files/provision.js+++ b/api/server/services/Files/provision.js@@ -18,6 +18,5 @@ module.exports = {loadCodeApiKey: (...args) => getService().loadCodeApiKey(...args),provisionToCodeEnv: (...args) => getService().provisionToCodeEnv(...args),provisionToVectorDB: (...args) => getService().provisionToVectorDB(...args),- checkCodeEnvFileAlive: (...args) => getService().checkCodeEnvFileAlive(...args),checkSessionsAlive: (...args) => getService().checkSessionsAlive(...args),};diff --git a/api/utils/tokens.spec.js b/api/utils/tokens.spec.jsindex 8ac3f7e908..e401b94f91 100644--- a/api/utils/tokens.spec.js+++ b/api/utils/tokens.spec.js@@ -5,7 +5,6 @@ const {matchModelName,processModelData,getModelMaxTokens,- maxOutputTokensMap,findMatchingPattern,} = require('@librechat/api');@@ -591,49 +590,6 @@ describe('getModelMaxTokens', () => {maxTokensMap[EModelEndpoint.openAI]['glm-4.5-air'],);});-- test('should return correct max output tokens for GPT-5 models', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- const gpt5Models = [- 'gpt-5',- 'gpt-5.1',- 'gpt-5.2',- 'gpt-5.3',- 'gpt-5.4',- 'gpt-5.4-pro',- 'gpt-5.5',- 'gpt-5.5-pro',- 'gpt-5.6',- 'gpt-5.6-terra',- 'gpt-5.6-luna',- 'gpt-5-mini',- 'gpt-5-nano',- 'gpt-5-pro',- 'gpt-5.2-pro',- ];- for (const model of gpt5Models) {- expect(getModelMaxOutputTokens(model)).toBe(maxOutputTokensMap[EModelEndpoint.openAI][model]);- expect(getModelMaxOutputTokens(model, EModelEndpoint.openAI)).toBe(- maxOutputTokensMap[EModelEndpoint.openAI][model],- );- expect(getModelMaxOutputTokens(model, EModelEndpoint.azureOpenAI)).toBe(- maxOutputTokensMap[EModelEndpoint.azureOpenAI][model],- );- }- });-- test('should return correct max output tokens for GPT-OSS models', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- ['gpt-oss-20b', 'gpt-oss-120b'].forEach((model) => {- expect(getModelMaxOutputTokens(model)).toBe(maxOutputTokensMap[EModelEndpoint.openAI][model]);- expect(getModelMaxOutputTokens(model, EModelEndpoint.openAI)).toBe(- maxOutputTokensMap[EModelEndpoint.openAI][model],- );- expect(getModelMaxOutputTokens(model, EModelEndpoint.azureOpenAI)).toBe(- maxOutputTokensMap[EModelEndpoint.azureOpenAI][model],- );- });- });});describe('findMatchingPattern - longest match wins', () => {@@ -1060,45 +1016,6 @@ describe('Meta Models Tests', () => {});});- describe('DeepSeek Max Output Tokens', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');-- test('should return correct max output tokens for deepseek-chat', () => {- const expected = maxOutputTokensMap[EModelEndpoint.openAI]['deepseek-chat'];- expect(getModelMaxOutputTokens('deepseek-chat')).toBe(expected);- expect(getModelMaxOutputTokens('deepseek-chat', EModelEndpoint.openAI)).toBe(expected);- expect(getModelMaxOutputTokens('deepseek-chat', EModelEndpoint.custom)).toBe(expected);- });-- test('should return correct max output tokens for deepseek-reasoner', () => {- const expected = maxOutputTokensMap[EModelEndpoint.openAI]['deepseek-reasoner'];- expect(getModelMaxOutputTokens('deepseek-reasoner')).toBe(expected);- expect(getModelMaxOutputTokens('deepseek-reasoner', EModelEndpoint.openAI)).toBe(expected);- expect(getModelMaxOutputTokens('deepseek-reasoner', EModelEndpoint.custom)).toBe(expected);- });-- test('should return correct max output tokens for deepseek-r1', () => {- const expected = maxOutputTokensMap[EModelEndpoint.openAI]['deepseek-r1'];- expect(getModelMaxOutputTokens('deepseek-r1')).toBe(expected);- expect(getModelMaxOutputTokens('deepseek-r1', EModelEndpoint.openAI)).toBe(expected);- });-- test('should return correct max output tokens for deepseek base pattern', () => {- const expected = maxOutputTokensMap[EModelEndpoint.openAI]['deepseek'];- expect(getModelMaxOutputTokens('deepseek')).toBe(expected);- expect(getModelMaxOutputTokens('deepseek-v3')).toBe(expected);- });-- test('should handle DeepSeek models with provider prefixes for max output tokens', () => {- expect(getModelMaxOutputTokens('deepseek/deepseek-chat')).toBe(- maxOutputTokensMap[EModelEndpoint.openAI]['deepseek-chat'],- );- expect(getModelMaxOutputTokens('openrouter/deepseek-reasoner')).toBe(- maxOutputTokensMap[EModelEndpoint.openAI]['deepseek-reasoner'],- );- });- });-describe('processModelData with Meta models', () => {test('should process Meta model data correctly', () => {const input = {@@ -1447,13 +1364,6 @@ describe('Claude Model Tests', () => {);});- it('should return correct max output tokens for Claude Opus 4.6 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxOutputTokens('claude-opus-4-6', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-opus-4-6'],- );- });-it('should handle Claude Opus 4.6 model name variations', () => {const modelVariations = ['claude-opus-4-6',@@ -1497,13 +1407,6 @@ describe('Claude Model Tests', () => {);});- it('should return correct max output tokens for Claude Opus 4.7 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxOutputTokens('claude-opus-4-7', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-opus-4-7'],- );- });-it('should match model names correctly for Claude Opus 4.7', () => {const modelVariations = ['claude-opus-4-7',@@ -1528,13 +1431,6 @@ describe('Claude Model Tests', () => {);});- it('should return correct max output tokens for Claude Opus 4.8 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxOutputTokens('claude-opus-4-8', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-opus-4-8'],- );- });-it('should match model names correctly for Claude Opus 4.8', () => {const modelVariations = ['claude-opus-4-8',@@ -1559,13 +1455,6 @@ describe('Claude Model Tests', () => {);});- it('should return correct max output tokens for Claude Opus 5 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxOutputTokens('claude-opus-5', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-opus-5'],- );- });-it('should match model names correctly for Claude Opus 5', () => {const modelVariations = ['claude-opus-5',@@ -1590,13 +1479,6 @@ describe('Claude Model Tests', () => {);});- it('should return correct max output tokens for Claude Fable 5 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxOutputTokens('claude-fable-5', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-fable-5'],- );- });-it('should match model names correctly for Claude Fable 5', () => {const modelVariations = ['claude-fable-5',@@ -1621,13 +1503,6 @@ describe('Claude Model Tests', () => {);});- it('should return correct max output tokens for Claude Mythos 5 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxOutputTokens('claude-mythos-5', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-mythos-5'],- );- });-it('should match model names correctly for Claude Mythos 5', () => {const modelVariations = ['claude-mythos-5',@@ -1650,14 +1525,6 @@ describe('Claude Model Tests', () => {expect(getModelMaxTokens('claude-mythos-5-1', EModelEndpoint.anthropic)).toBe(1000000);});- it('should return correct max output tokens for Claude Fable 5.1 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(maxOutputTokensMap[EModelEndpoint.anthropic]['claude-fable-5-1']).toBe(128000);- expect(maxOutputTokensMap[EModelEndpoint.anthropic]['claude-mythos-5-1']).toBe(128000);- expect(getModelMaxOutputTokens('claude-fable-5-1', EModelEndpoint.anthropic)).toBe(128000);- expect(getModelMaxOutputTokens('claude-mythos-5-1', EModelEndpoint.anthropic)).toBe(128000);- });-it('should match model names correctly for Claude Fable 5.1 without collapsing to Fable 5', () => {const modelVariations = ['claude-fable-5-1',@@ -1692,16 +1559,6 @@ describe('Claude Model Tests', () => {);});- it('should return correct max output tokens for Claude Sonnet 4.6 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxOutputTokens('claude-sonnet-4-6', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-sonnet-4-6'],- );- expect(getModelMaxOutputTokens('claude-sonnet-4.6', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-sonnet-4.6'],- );- });-it('should return correct context length for Claude Sonnet 4.7+ aliases (1M)', () => {['claude-sonnet-4-7',@@ -1721,37 +1578,6 @@ describe('Claude Model Tests', () => {expect(getModelMaxTokens('anthropic.claude-4-10-sonnet', EModelEndpoint.bedrock)).toBe(1000000);});- it('should return correct max output tokens for Claude Sonnet 4.7+ aliases (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- [- 'claude-sonnet-4-7',- 'claude-sonnet-4.7',- 'claude-sonnet-4-8',- 'claude-sonnet-4.8',- 'claude-sonnet-4-9',- 'claude-sonnet-4.9',- 'claude-sonnet-4-10',- 'claude-sonnet-4.10',- 'claude-4-10-sonnet',- 'claude-4.10-sonnet',- ].forEach((model) => {- expect(getModelMaxOutputTokens(model, EModelEndpoint.anthropic)).toBe(128000);- });- });-- it('should not treat dated Claude Sonnet 4 IDs as Claude Sonnet 4.6+ aliases', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxTokens('claude-sonnet-4-20250514', EModelEndpoint.anthropic)).toBe(- maxTokensMap[EModelEndpoint.anthropic]['claude-sonnet-4'],- );- expect(getModelMaxOutputTokens('claude-sonnet-4-20250514', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-sonnet-4'],- );- expect(getModelMaxTokens('claude-4-20250514-sonnet', EModelEndpoint.bedrock)).toBe(- maxTokensMap[EModelEndpoint.bedrock]['claude-4'],- );- });-it('should keep double-digit Claude Sonnet 4 minor names when matching models', () => {expect(matchModelName('claude-sonnet-4-10', EModelEndpoint.anthropic)).toBe('claude-sonnet-4-10',@@ -1808,16 +1634,6 @@ describe('Claude Model Tests', () => {);});- it('should return correct max output tokens for Claude Sonnet 5 (128K)', () => {- const { getModelMaxOutputTokens } = require('@librechat/api');- expect(getModelMaxOutputTokens('claude-sonnet-5', EModelEndpoint.anthropic)).toBe(- maxOutputTokensMap[EModelEndpoint.anthropic]['claude-sonnet-5'],- );- expect(getModelMaxOutputTokens('claude-sonnet-5', EModelEndpoint.anthropic)).toBe(- getModelMaxOutputTokens('claude-sonnet-4-6', EModelEndpoint.anthropic),- );- });-it('should not match Claude Sonnet 5 against Claude Sonnet 4 keys', () => {const modelVariations = ['claude-sonnet-5',diff --git a/bun.lock b/bun.lockindex ec43f44d27..3c7a846f73 100644--- a/bun.lock+++ b/bun.lock@@ -301,7 +301,6 @@},"devDependencies": {"@babel/preset-env": "^7.29.5",- "@babel/preset-react": "^7.18.6","@babel/preset-typescript": "^7.21.0","@langchain/langgraph": "^1.4.5","@types/bun": "^1.2.15",@@ -312,7 +311,6 @@"@types/multer": "^1.4.13","@types/node": "^24.12.4","@types/node-fetch": "^2.6.13",- "@types/react": "^18.2.18","@types/sanitize-html": "^2.16.1","@types/supertest": "^7.2.0","@types/yauzl": "^2.10.3",@@ -346,9 +344,7 @@"@aws-sdk/credential-providers": "^3.1045.0","@aws-sdk/s3-request-presigner": "^3.758.0","@azure/identity": "^4.13.1",- "@azure/search-documents": "^12.0.0","@azure/storage-blob": "^12.30.0",- "@google/genai": "^2.8.0","@keyv/redis": "^4.3.3","@librechat/agents": "^3.6.0","@librechat/data-schemas": "*",diff --git a/eslint.config.mjs b/eslint.config.mjsindex d857a6cafb..6385ae062e 100644--- a/eslint.config.mjs+++ b/eslint.config.mjs@@ -471,7 +471,7 @@ export default [files: ['**/*.ts', '**/*.tsx'],// Package, E2E, and root integration tests are not part of the client// TypeScript project. They still get the recommended rules above.- ignores: ['packages/**/*', 'client/vite.config.ts', 'e2e/**/*', 'src/tests/**/*'],+ ignores: ['packages/**/*', 'client/vite.config.ts', 'e2e/**/*'],plugins: {'@typescript-eslint': typescriptEslintEslintPlugin,jest: fixupPluginRules(jest),diff --git a/package-lock.json b/package-lock.jsonindex 4d0be82cc5..2ad9e6814d 100644--- a/package-lock.json+++ b/package-lock.json@@ -40740,7 +40740,6 @@},"devDependencies": {"@babel/preset-env": "^7.29.5",- "@babel/preset-react": "^7.18.6","@babel/preset-typescript": "^7.21.0","@langchain/langgraph": "^1.4.5","@types/bun": "^1.2.15",@@ -40752,7 +40751,6 @@"@types/multer": "^1.4.13","@types/node": "^24.12.4","@types/node-fetch": "^2.6.13",- "@types/react": "^18.2.18","@types/sanitize-html": "^2.16.1","@types/supertest": "^7.2.0","@types/yauzl": "^2.10.3",@@ -40787,9 +40785,7 @@"@aws-sdk/credential-providers": "^3.1045.0","@aws-sdk/s3-request-presigner": "^3.758.0","@azure/identity": "^4.13.1",- "@azure/search-documents": "^12.0.0","@azure/storage-blob": "^12.30.0",- "@google/genai": "^2.8.0","@keyv/redis": "5.1.6","@librechat/agents": "^4.0.4","@librechat/data-schemas": "*",diff --git a/packages/api/package.json b/packages/api/package.jsonindex 28c6d9c586..ea8eb193ff 100644--- a/packages/api/package.json+++ b/packages/api/package.json@@ -48,11 +48,7 @@"b:build:dev": "bun run b:clean && bun run tsdown && bun run openapi:copy","openapi:generate": "cross-env TS_NODE_PROJECT=tsconfig.openapi.json ts-node -r tsconfig-paths/register src/openapi/generate.ts --write","openapi:test": "node openapi/router.smoke.cjs",- "openapi:check": "cross-env TS_NODE_PROJECT=tsconfig.openapi.json ts-node -r tsconfig-paths/register src/openapi/generate.ts --check",- "start:everything-sse": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/examples/everything/sse.ts",- "start:everything": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/demo/everything.ts",- "start:filesystem": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/demo/filesystem.ts",- "start:servers": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/demo/servers.ts"+ "openapi:check": "cross-env TS_NODE_PROJECT=tsconfig.openapi.json ts-node -r tsconfig-paths/register src/openapi/generate.ts --check"},"repository": {"type": "git",@@ -66,7 +62,6 @@"homepage": "https://librechat.ai","devDependencies": {"@babel/preset-env": "^7.29.5",- "@babel/preset-react": "^7.18.6","@babel/preset-typescript": "^7.21.0","@langchain/langgraph": "^1.4.5","@types/bun": "^1.2.15",@@ -78,7 +73,6 @@"@types/multer": "^1.4.13","@types/node": "^24.12.4","@types/node-fetch": "^2.6.13",- "@types/react": "^18.2.18","@types/sanitize-html": "^2.16.1","@types/supertest": "^7.2.0","@types/yauzl": "^2.10.3",@@ -116,9 +110,7 @@"@aws-sdk/credential-providers": "^3.1045.0","@aws-sdk/s3-request-presigner": "^3.758.0","@azure/identity": "^4.13.1",- "@azure/search-documents": "^12.0.0","@azure/storage-blob": "^12.30.0",- "@google/genai": "^2.8.0","@keyv/redis": "5.1.6","@librechat/agents": "^4.0.4","@librechat/data-schemas": "*",diff --git a/packages/api/src/agents/__tests__/estimateMediaTokensForMessage.spec.ts b/packages/api/src/agents/__tests__/estimateMediaTokensForMessage.spec.tsdeleted file mode 100644index 1e4077fb9a..0000000000--- a/packages/api/src/agents/__tests__/estimateMediaTokensForMessage.spec.ts+++ /dev/null@@ -1,308 +0,0 @@-import { estimateMediaTokensForMessage } from '../client';--jest.mock('@librechat/agents', () => ({- ...jest.requireActual('@librechat/agents'),- extractImageDimensions: jest.fn((data: string) => {- if (data.includes('VALID_PNG')) {- return { width: 800, height: 600 };- }- return null;- }),- estimateAnthropicImageTokens: jest.fn((w: number, h: number) => Math.ceil((w * h) / 750)),- estimateOpenAIImageTokens: jest.fn((w: number, h: number) => Math.ceil((w * h) / 512) + 85),-}));--const fakeTokenCount = (text: string) => Math.ceil(text.length / 4);--describe('estimateMediaTokensForMessage', () => {- describe('non-array content', () => {- it('returns 0 for string content', () => {- expect(estimateMediaTokensForMessage('hello', false)).toBe(0);- });-- it('returns 0 for null', () => {- expect(estimateMediaTokensForMessage(null, false)).toBe(0);- });-- it('returns 0 for undefined', () => {- expect(estimateMediaTokensForMessage(undefined, true)).toBe(0);- });-- it('returns 0 for a number', () => {- expect(estimateMediaTokensForMessage(42, false)).toBe(0);- });- });-- describe('empty and malformed arrays', () => {- it('returns 0 for an empty array', () => {- expect(estimateMediaTokensForMessage([], false)).toBe(0);- });-- it('skips null entries', () => {- expect(estimateMediaTokensForMessage([null, undefined], false)).toBe(0);- });-- it('skips entries without a string type', () => {- expect(estimateMediaTokensForMessage([{ type: 123 }, { text: 'hi' }], false)).toBe(0);- });-- it('skips text-only blocks (not media)', () => {- expect(estimateMediaTokensForMessage([{ type: 'text', text: 'hi' }], false)).toBe(0);- });- });-- describe('image_url blocks', () => {- it('falls back to 1024 for a remote URL (non-data)', () => {- const content = [{ type: 'image_url', image_url: 'https://example.com/img.png' }];- expect(estimateMediaTokensForMessage(content, false)).toBe(1024);- });-- it('falls back to 1024 when image_url is an object with non-data URL', () => {- const content = [{ type: 'image_url', image_url: { url: 'https://example.com/img.png' } }];- expect(estimateMediaTokensForMessage(content, true)).toBe(1024);- });-- it('falls back to 1024 when base64 data cannot be decoded', () => {- const content = [{ type: 'image_url', image_url: 'data:image/png;base64,SHORT' }];- expect(estimateMediaTokensForMessage(content, false)).toBe(1024);- });-- it('estimates tokens from decoded dimensions (OpenAI path)', () => {- const content = [- { type: 'image_url', image_url: 'data:image/png;base64,VALID_PNG_LONG_DATA' },- ];- const result = estimateMediaTokensForMessage(content, false);- expect(result).toBeGreaterThan(0);- expect(result).not.toBe(1024);- });-- it('estimates tokens from decoded dimensions (Claude path)', () => {- const content = [- { type: 'image_url', image_url: { url: 'data:image/png;base64,VALID_PNG_LONG_DATA' } },- ];- const result = estimateMediaTokensForMessage(content, true);- expect(result).toBeGreaterThan(0);- expect(result).not.toBe(1024);- });- });-- describe('image blocks (Anthropic format)', () => {- it('falls back to 1024 when source is not base64', () => {- const content = [{ type: 'image', source: { type: 'url', data: 'https://example.com' } }];- expect(estimateMediaTokensForMessage(content, true)).toBe(1024);- });-- it('falls back to 1024 when dimensions cannot be extracted', () => {- const content = [{ type: 'image', source: { type: 'base64', data: 'INVALID' } }];- expect(estimateMediaTokensForMessage(content, true)).toBe(1024);- });-- it('estimates tokens from valid base64 image data', () => {- const content = [{ type: 'image', source: { type: 'base64', data: 'VALID_PNG' } }];- const result = estimateMediaTokensForMessage(content, true);- expect(result).toBeGreaterThan(0);- expect(result).not.toBe(1024);- });- });-- describe('image_file blocks', () => {- it('falls back to 1024 (no base64 extraction path)', () => {- const content = [{ type: 'image_file', file_id: 'file-abc' }];- expect(estimateMediaTokensForMessage(content, false)).toBe(1024);- });- });-- describe('document blocks - LangChain format (source_type)', () => {- it('counts tokens for text source_type with getTokenCount', () => {- const content = [- {- type: 'document',- source_type: 'text',- text: 'a'.repeat(400),- },- ];- expect(estimateMediaTokensForMessage(content, false, fakeTokenCount)).toBe(100);- });-- it('falls back to length/4 without getTokenCount', () => {- const content = [- {- type: 'document',- source_type: 'text',- text: 'a'.repeat(400),- },- ];- expect(estimateMediaTokensForMessage(content, false)).toBe(100);- });-- it('estimates PDF pages for base64 source_type with application/pdf mime', () => {- const pdfData = 'x'.repeat(150_000);- const content = [- {- type: 'document',- source_type: 'base64',- data: pdfData,- mime_type: 'application/pdf',- },- ];- const result = estimateMediaTokensForMessage(content, false);- expect(result).toBe(2 * 1500);- });-- it('uses Claude PDF rate when isClaude is true', () => {- const pdfData = 'x'.repeat(150_000);- const content = [- {- type: 'document',- source_type: 'base64',- data: pdfData,- mime_type: 'application/pdf',- },- ];- const result = estimateMediaTokensForMessage(content, true);- expect(result).toBe(2 * 2000);- });-- it('defaults to PDF estimation for empty mime_type', () => {- const pdfData = 'x'.repeat(10);- const content = [- {- type: 'document',- source_type: 'base64',- data: pdfData,- mime_type: '',- },- ];- const result = estimateMediaTokensForMessage(content, false);- expect(result).toBe(1 * 1500);- });-- it('handles image/* mime inside base64 source_type', () => {- const content = [- {- type: 'document',- source_type: 'base64',- data: 'VALID_PNG',- mime_type: 'image/png',- },- ];- const result = estimateMediaTokensForMessage(content, true);- expect(result).toBeGreaterThan(0);- expect(result).not.toBe(1024);- });-- it('falls back to 1024 for undecodable image in base64 source_type', () => {- const content = [- {- type: 'document',- source_type: 'base64',- data: 'BAD_DATA',- mime_type: 'image/jpeg',- },- ];- expect(estimateMediaTokensForMessage(content, false)).toBe(1024);- });-- it('falls back to URL_DOCUMENT_FALLBACK_TOKENS for unrecognized source_type', () => {- const content = [{ type: 'document', source_type: 'url' }];- expect(estimateMediaTokensForMessage(content, false)).toBe(2000);- });- });-- describe('document blocks - Anthropic format (source object)', () => {- it('counts tokens for text source type with getTokenCount', () => {- const content = [- {- type: 'document',- source: { type: 'text', data: 'a'.repeat(800) },- },- ];- expect(estimateMediaTokensForMessage(content, true, fakeTokenCount)).toBe(200);- });-- it('falls back to length/4 for text source without getTokenCount', () => {- const content = [- {- type: 'document',- source: { type: 'text', data: 'a'.repeat(800) },- },- ];- expect(estimateMediaTokensForMessage(content, true)).toBe(200);- });-- it('estimates PDF pages for base64 source with application/pdf', () => {- const pdfData = 'x'.repeat(225_000);- const content = [- {- type: 'document',- source: { type: 'base64', data: pdfData, media_type: 'application/pdf' },- },- ];- const result = estimateMediaTokensForMessage(content, true);- expect(result).toBe(3 * 2000);- });-- it('returns URL fallback for url source type', () => {- const content = [- {- type: 'document',- source: { type: 'url' },- },- ];- expect(estimateMediaTokensForMessage(content, false)).toBe(2000);- });-- it('handles content source type with nested images', () => {- const content = [- {- type: 'document',- source: {- type: 'content',- content: [- { type: 'image', source: { type: 'base64', data: 'VALID_PNG' } },- { type: 'image', source: { type: 'base64', data: 'UNDECODABLE' } },- ],- },- },- ];- const result = estimateMediaTokensForMessage(content, true);- expect(result).toBeGreaterThan(1024);- });-- it('falls back to URL_DOCUMENT_FALLBACK_TOKENS when source has unknown type', () => {- const content = [{ type: 'document', source: { type: 'unknown_format' } }];- expect(estimateMediaTokensForMessage(content, false)).toBe(2000);- });- });-- describe('file blocks', () => {- it('uses same logic as document for file type blocks', () => {- const content = [- {- type: 'file',- source_type: 'text',- text: 'a'.repeat(120),- },- ];- expect(estimateMediaTokensForMessage(content, false, fakeTokenCount)).toBe(30);- });-- it('falls back to URL_DOCUMENT_FALLBACK_TOKENS for file without source info', () => {- const content = [{ type: 'file' }];- expect(estimateMediaTokensForMessage(content, false)).toBe(2000);- });- });-- describe('mixed content arrays', () => {- it('sums tokens across multiple media blocks', () => {- const content = [- { type: 'text', text: 'hello' },- { type: 'image_url', image_url: 'https://example.com/img.png' },- { type: 'image_file', file_id: 'f1' },- { type: 'document', source: { type: 'url' } },- ];- const result = estimateMediaTokensForMessage(content, false);- expect(result).toBe(1024 + 1024 + 2000);- });- });-});diff --git a/packages/api/src/agents/__tests__/initialize.test.ts b/packages/api/src/agents/__tests__/initialize.test.tsindex 143e4c95d8..6d12b44d5e 100644--- a/packages/api/src/agents/__tests__/initialize.test.ts+++ b/packages/api/src/agents/__tests__/initialize.test.ts@@ -110,9 +110,7 @@ jest.mock('~/endpoints', () => ({}));jest.mock('~/files', () => ({- filterFilesByEndpointConfig: jest.fn(() => []),filterFilesByEndpointRuntimeConfig: jest.fn(() => []),- isLegacyFileUploadUX: jest.fn(() => false),}));jest.mock('~/prompts', () => ({diff --git a/packages/api/src/agents/avatars.spec.ts b/packages/api/src/agents/avatars.spec.tsindex cbcc483612..2495d4660a 100644--- a/packages/api/src/agents/avatars.spec.ts+++ b/packages/api/src/agents/avatars.spec.ts@@ -11,7 +11,6 @@ import {AVATAR_REFRESH_BATCH_SIZE,MAX_AVATAR_REFRESH_AGENTS,applyCachedAvatarUrl,- getAvatarRefreshCoveredIds,mergeAvatarRefreshCacheEntry,refreshListAvatars,resolveAvatarRefresh,@@ -603,8 +602,8 @@ describe('refreshListAvatars', () => {);expect(Object.keys(boundedEntry.coveredIds)).toHaveLength(defaultCoverageLimit);- expect(getAvatarRefreshCoveredIds(boundedEntry, 1)).not.toContain('agent0');- expect(getAvatarRefreshCoveredIds(boundedEntry, 1)).toContain('agent1000');+ expect(Object.keys(boundedEntry.coveredIds)).not.toContain('agent0');+ expect(Object.keys(boundedEntry.coveredIds)).toContain('agent1000');const { cache } = createRefreshCache();const now = jest.spyOn(Date, 'now').mockReturnValue(1);diff --git a/packages/api/src/agents/avatars.ts b/packages/api/src/agents/avatars.tsindex 0ea9652d32..f7576fcdf8 100644--- a/packages/api/src/agents/avatars.ts+++ b/packages/api/src/agents/avatars.ts@@ -124,11 +124,6 @@ const getAvatarRefreshCoverage = ();};-export const getAvatarRefreshCoveredIds = (entry: unknown, now: number = Date.now()): string[] =>- Object.keys(getAvatarRefreshCoverage(entry, now, 0)).filter(- (id) => getCachedAvatarFilepath(entry, id) != null,- );-const getAvatarRefreshCacheTtl = (entry: AvatarRefreshCacheEntry,now: number,diff --git a/packages/api/src/agents/client.ts b/packages/api/src/agents/client.tsindex 16e3e7fa38..86b0ad37b0 100644--- a/packages/api/src/agents/client.ts+++ b/packages/api/src/agents/client.ts@@ -300,35 +300,6 @@ function estimateDocumentBlockTokens(return URL_DOCUMENT_FALLBACK_TOKENS;}-/**- * Estimates token cost for image and document blocks in a message's- * content array. Covers: image_url, image, image_file, document, file.- */-export function estimateMediaTokensForMessage(- content: unknown,- isClaude: boolean,- getTokenCount?: (text: string) => number,-): number {- if (!Array.isArray(content)) {- return 0;- }- let tokens = 0;- for (const block of content as ContentBlock[]) {- if (block == null || typeof block !== 'object' || typeof block.type !== 'string') {- continue;- }- const type = block.type;- if (type === 'image_url' || type === 'image' || type === 'image_file') {- tokens += estimateImageBlockTokens(block, isClaude);- continue;- }- if (type === 'document' || type === 'file') {- tokens += estimateDocumentBlockTokens(block, isClaude, getTokenCount);- }- }- return tokens;-}-/*** Single-pass token counter for formatted messages (plain objects with role/content/name).* Handles text, tool_call, image, and document content types in one iteration,diff --git a/packages/api/src/agents/compaction.spec.ts b/packages/api/src/agents/compaction.spec.tsindex f67c70e75c..e58602c77f 100644--- a/packages/api/src/agents/compaction.spec.ts+++ b/packages/api/src/agents/compaction.spec.ts@@ -27,7 +27,6 @@ import {resolveFailedTurnContent,resolveCheckpointMessage,resolveFinalizedCompactionTurn,- restoreCompactionSemanticIndex,restoreCompactionSemanticIndexSnapshot,stripUnusableSummaryParts,getLatestEventActorSummary,@@ -83,7 +82,9 @@ describe('compaction semantic index continuation projection', () => {},],});- expect(restoreCompactionSemanticIndex(projection)).toEqual(projection?.entries);+ expect(restoreCompactionSemanticIndexSnapshot(projection)?.entries).toEqual(+ projection?.entries,+ );});it('preserves cumulative omission counts across JSON persistence', () => {@@ -135,9 +136,9 @@ describe('compaction semantic index continuation projection', () => {providedEntryCount: 1,} as ICompactionSemanticIndexProjection;- expect(restoreCompactionSemanticIndex(malformed)).toBeUndefined();- expect(restoreCompactionSemanticIndex(oversized)).toBeUndefined();- expect(restoreCompactionSemanticIndex(corrupt)).toBeUndefined();+ expect(restoreCompactionSemanticIndexSnapshot(malformed)?.entries).toBeUndefined();+ expect(restoreCompactionSemanticIndexSnapshot(oversized)?.entries).toBeUndefined();+ expect(restoreCompactionSemanticIndexSnapshot(corrupt)?.entries).toBeUndefined();expect(restoreCompactionSemanticIndexSnapshot(impossibleCount)).toBeUndefined();expect(createCompactionSemanticIndexProjection(oversized.entries)).toBeUndefined();});diff --git a/packages/api/src/agents/compaction.ts b/packages/api/src/agents/compaction.tsindex 1a50151e4a..dbe7780b96 100644--- a/packages/api/src/agents/compaction.ts+++ b/packages/api/src/agents/compaction.ts@@ -918,9 +918,3 @@ export function restoreCompactionSemanticIndexSnapshot(providedEntryCount: projection.providedEntryCount ?? entries.length,});}--export function restoreCompactionSemanticIndex(- projection: ICompactionSemanticIndexProjection | null | undefined,-): CompactionSemanticIndex | undefined {- return restoreCompactionSemanticIndexSnapshot(projection)?.entries;-}diff --git a/packages/api/src/agents/digest/tree.ts b/packages/api/src/agents/digest/tree.tsindex 0eee1253f7..874d83f92b 100644--- a/packages/api/src/agents/digest/tree.ts+++ b/packages/api/src/agents/digest/tree.ts@@ -442,20 +442,6 @@ export function snapshotActivitySummary(task: SubagentTaskSnapshot): ActivitySum: boundActivitySummary(decorated.activitySummary);}-/** Copies a snapshot's bounded decorations onto a rebuilt snapshot. */-export function carryActivity(- from: SubagentTaskSnapshot,- to: SubagentTaskSnapshot,-): ActivitySnapshot {- const activity = snapshotActivity(from);- const activitySummary = snapshotActivitySummary(from);- return {- ...to,- ...(activity == null ? {} : { activity }),- ...(activitySummary == null ? {} : { activitySummary }),- };-}-/** Current SDK results can persist a failure as a completed message, so a* completed status is re-checked against the same verdict the live recorder uses. */const projectionStatus = (diff --git a/packages/api/src/agents/execution.spec.ts b/packages/api/src/agents/execution.spec.tsindex a935f6060d..ffaf28af2d 100644--- a/packages/api/src/agents/execution.spec.ts+++ b/packages/api/src/agents/execution.spec.ts@@ -8,7 +8,6 @@ import {captureCodeExecutionApprovalBinding,codeExecutionAuthHeaders,codeExecutionHeaders,- getCodeWorkspaceSelections,resolveCodeExecutionContext,resolveCodeExecutionWorkspaceSelections,} from './execution';@@ -825,31 +824,6 @@ describe('stateful code approval target binding', () => {]),).not.toThrow();});-- it('persists only the environment/workspace pair, not live capabilities', () => {- expect(getCodeWorkspaceSelections([context()])).toEqual([- { environmentId: 'environment-a', workspaceId: 'project-a' },- ]);- });-- it('retains graph ownership when removing live workspace capabilities', () => {- const owned = context();- owned.codeWorkspace!.agentIds = ['agent-a'];- expect(getCodeWorkspaceSelections([owned])).toEqual([- { environmentId: 'environment-a', workspaceId: 'project-a', agentIds: ['agent-a'] },- ]);- });-- it.each(['source', 'isolated'] as const)(- 'retains the %s checkout when stripping live capabilities',- (checkout) => {- const selected = context();- selected.codeWorkspace!.checkout = checkout;- expect(getCodeWorkspaceSelections([selected])).toEqual([- { environmentId: 'environment-a', workspaceId: 'project-a', checkout },- ]);- },- );});describe('codeExecutionAuthHeaders', () => {diff --git a/packages/api/src/agents/execution.ts b/packages/api/src/agents/execution.tsindex 60279b7472..fe2f2ad0b4 100644--- a/packages/api/src/agents/execution.ts+++ b/packages/api/src/agents/execution.ts@@ -73,36 +73,6 @@ export interface CodeExecutionContext {};}-/** Removes live capability data before a workspace binding is persisted. */-export function getCodeWorkspaceSelections(- contexts: Array<- | Pick<CodeExecutionContext, 'environmentId' | 'environmentType' | 'codeWorkspace'>- | null- | undefined- >,-): CodeWorkspaceSelection[] | undefined {- const selections = new Map<string, CodeWorkspaceSelection>();- for (const context of contexts) {- const workspace = context?.codeWorkspace;- if (- context?.environmentType !== 'attached' ||- context.environmentId == null ||- workspace == null ||- workspace.environmentId !== context.environmentId- ) {- continue;- }- selections.set(workspace.environmentId, {- environmentId: workspace.environmentId,- workspaceId: workspace.workspaceId,- ...(workspace.checkout == null ? {} : { checkout: workspace.checkout }),- ...(workspace.agentIds == null ? {} : { agentIds: [...workspace.agentIds] }),- });- }- if (selections.size === 0) return undefined;- return [...selections.values()].sort((a, b) => a.environmentId.localeCompare(b.environmentId));-}-type CodeExecutionApprovalAgent = {id?: string | null;codeExecutionContext?: CodeExecutionContext | null;diff --git a/packages/api/src/agents/handlers.ts b/packages/api/src/agents/handlers.tsindex 3044b2e229..1627d769b8 100644--- a/packages/api/src/agents/handlers.ts+++ b/packages/api/src/agents/handlers.ts@@ -1,6 +1,6 @@import yaml from 'js-yaml';import { Types } from 'mongoose';-import { GraphEvents, Constants, ToolEndHandler } from '@librechat/agents';+import { Constants, ToolEndHandler } from '@librechat/agents';import {logger,normalizeSkillFrontmatterKeys,@@ -7860,15 +7860,3 @@ export function createToolExecuteHandler(options: ToolExecuteOptions): EventHand},};}--/**- * Creates a handlers object that includes ON_TOOL_EXECUTE.- * Can be merged with other handler objects.- */-export function createToolExecuteHandlers(- options: ToolExecuteOptions,-): Record<string, EventHandler> {- return {- [GraphEvents.ON_TOOL_EXECUTE]: createToolExecuteHandler(options),- };-}diff --git a/packages/api/src/agents/hitl/answers.spec.ts b/packages/api/src/agents/hitl/answers.spec.tsindex 9cd0aa876d..85a7a6b457 100644--- a/packages/api/src/agents/hitl/answers.spec.ts+++ b/packages/api/src/agents/hitl/answers.spec.ts@@ -16,7 +16,6 @@ import {applyRetainedAnswers,prepareRetainedAnswerInvocationMessages,RETAINED_ANSWERS_MESSAGE_ID,- buildRetainedAnswersContext,collectRetainedAnswers,orderConversationBranch,reachesBranchRoot,@@ -372,7 +371,10 @@ describe('resolveRetainedAnswersConfig', () => {});});-describe('buildRetainedAnswersContext', () => {+describe('retained answers context', () => {+ const buildRetainedAnswersContext = async (+ input: Parameters<typeof prepareRetainedAnswers>[0],+ ): Promise<string | undefined> => (await prepareRetainedAnswers(input)).block;const answered = askPart(batchRequest, JSON.stringify({ answers: { environment: 'staging' } }));const summary = {type: ContentTypes.SUMMARY,diff --git a/packages/api/src/agents/hitl/answers.ts b/packages/api/src/agents/hitl/answers.tsindex e4b2e67e67..46440468a4 100644--- a/packages/api/src/agents/hitl/answers.ts+++ b/packages/api/src/agents/hitl/answers.ts@@ -463,22 +463,6 @@ async function buildContext({return renderRetainedAnswers(sets, resolved.maxTokens, countTokens);}-/**- * The retained-answers block for one turn, or `undefined` when there is nothing- * to carry or the block could not be built: a failure here costs the turn its- * carried answers, never the turn, and is logged once per occurrence.- */-export async function buildRetainedAnswersContext(- input: RetainedAnswersContextInput,-): Promise<string | undefined> {- try {- return await buildContext(input);- } catch (error) {- logger.warn('[retainedAnswers] Block unavailable for this turn', getSafeErrorMetadata(error));- return undefined;- }-}-/*** Exact counting is limited to retained context. The general prompt counter's* 4 KiB byte-estimate shortcut would discard answers that fit the token budget.diff --git a/packages/api/src/agents/hitl/policy.spec.ts b/packages/api/src/agents/hitl/policy.spec.tsindex a27a63b293..5f3b0fba55 100644--- a/packages/api/src/agents/hitl/policy.spec.ts+++ b/packages/api/src/agents/hitl/policy.spec.ts@@ -5,11 +5,8 @@ import {resolveToolApprovalPolicy,isHITLEnabled,healToolApprovalPolicy,- collectAliasMatcherNames,- buildAliasMatcherPattern,mapToolApprovalPolicy,buildToolApprovalPayload,- buildAskUserQuestionPayload,buildPendingAction,isToolApprovalPayloadValid,toClientPendingAction,@@ -269,26 +266,6 @@ describe('buildToolApprovalPayload', () => {});});-describe('buildAskUserQuestionPayload', () => {- test('produces an ask_user_question-discriminated payload', () => {- const payload = buildAskUserQuestionPayload({- question: 'Which environment?',- options: [- { label: 'Staging', value: 'staging' },- { label: 'Production', value: 'production' },- ],- });- expect(payload.type).toBe('ask_user_question');- expect(payload.question.question).toBe('Which environment?');- expect(payload.question.options).toHaveLength(2);- });-- test('options are optional', () => {- const payload = buildAskUserQuestionPayload({ question: 'Free-form?' });- expect(payload.question.options).toBeUndefined();- });-});-describe('buildPendingAction', () => {const ctx = {streamId: 'stream-1',@@ -1168,35 +1145,6 @@ describe('healToolApprovalPolicy reverse direction', () => {});});-describe('collectAliasMatcherNames', () => {- const aliases = [- { name: 'search_mcp_acme', aliasName: 'acme_search_mcp_acme' },- { name: 'acme_list_mcp_acme', aliasName: 'list_mcp_acme' },- ];-- it('returns names whose alias matches the regex while the name does not', () => {- expect(collectAliasMatcherNames('^acme_search_mcp_acme$', aliases)).toEqual([- 'search_mcp_acme',- ]);- expect(collectAliasMatcherNames('^list_mcp_acme$', aliases)).toEqual(['acme_list_mcp_acme']);- });-- it('skips names the matcher already matches and invalid patterns', () => {- expect(collectAliasMatcherNames('_mcp_acme$', aliases)).toEqual([]);- expect(collectAliasMatcherNames('(unclosed', aliases)).toEqual([]);- expect(collectAliasMatcherNames(undefined, aliases)).toEqual([]);- });-- it('builds an anchored exact-name pattern with escaped names', () => {- const pattern = buildAliasMatcherPattern(['a.b_mcp_acme', 'c_mcp_acme']);- const regex = new RegExp(pattern);- expect(regex.test('a.b_mcp_acme')).toBe(true);- expect(regex.test('axb_mcp_acme')).toBe(false);- expect(regex.test('c_mcp_acme')).toBe(true);- expect(regex.test('xc_mcp_acme')).toBe(false);- });-});-test.each([{ mode: 'dontAsk' as const },{ mode: 'dontAsk' as const, allow: ['query*'] },diff --git a/packages/api/src/agents/hitl/policy.ts b/packages/api/src/agents/hitl/policy.tsindex 31a556d41a..2db29004cb 100644--- a/packages/api/src/agents/hitl/policy.ts+++ b/packages/api/src/agents/hitl/policy.ts@@ -235,45 +235,6 @@ export function healToolApprovalPolicy(};}-function escapeRegExp(value: string): string {- return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');-}--/**- * Names whose OTHER spelling matches a programmatic hook's regex matcher- * while their own name does not — the hook must also fire for these or its- * argument-, user-, or tenant-specific deny/ask decisions are silently- * skipped for renamed tools. Mirrors the SDK's unanchored `new RegExp(pattern)`- * matcher semantics; an invalid pattern matches nothing there, so it aliases- * nothing here.- */-export function collectAliasMatcherNames(- matcher: string | undefined,- aliases: readonly MCPToolAlias[],-): string[] {- if (!matcher || aliases.length === 0) {- return [];- }- let regex: RegExp;- try {- regex = new RegExp(matcher);- } catch {- return [];- }- const names: string[] = [];- for (const { name, aliasName } of aliases) {- if (name !== aliasName && !regex.test(name) && regex.test(aliasName)) {- names.push(name);- }- }- return names;-}--/** Anchored exact-name pattern for the alias-matched names of one hook matcher. */-export function buildAliasMatcherPattern(names: readonly string[]): string {- return `^(?:${names.map(escapeRegExp).join('|')})$`;-}-export function mapToolApprovalPolicy(policy: TToolApprovalPolicy | undefined,): ToolPolicyConfig | undefined {@@ -369,16 +330,6 @@ export function isToolApprovalPayloadValid(payload: Agents.ToolApprovalInterruptreturn true;}-/** Build an ask-user-question interrupt payload. */-export function buildAskUserQuestionPayload(- question: Agents.AskUserQuestionRequest,-): Agents.AskUserQuestionInterruptPayload {- return {- type: 'ask_user_question',- question,- };-}-/** Job-context fields wrapped around a {@link Agents.HumanInterruptPayload}. */export interface PendingActionContext {streamId: string;diff --git a/packages/api/src/agents/intent.spec.ts b/packages/api/src/agents/intent.spec.tsindex 762bd9a1c1..27dd8bed06 100644--- a/packages/api/src/agents/intent.spec.ts+++ b/packages/api/src/agents/intent.spec.ts@@ -5,7 +5,6 @@ import {NATIVE_INTENT_TOOL_NAMES,isIntentEligibleToolName,hasIntentArg,- readIntentArg,stripIntentArg,injectIntentParam,stripIntentFromToolDefinitions,@@ -71,17 +70,11 @@ describe('isIntentEligibleToolName', () => {});});-describe('hasIntentArg / readIntentArg / stripIntentArg', () => {- it('detects and reads the arg on object and stringified args', () => {+describe('hasIntentArg / stripIntentArg', () => {+ it('detects the arg on object and stringified args', () => {expect(hasIntentArg({ [INTENT_ARG]: 'Searching for OAuth handling' })).toBe(true);expect(hasIntentArg({})).toBe(false);expect(hasIntentArg('{"intent":"Searching"}')).toBe(true);- expect(readIntentArg({ [INTENT_ARG]: 'Searching for OAuth handling' })).toBe(- 'Searching for OAuth handling',- );- expect(readIntentArg({ [INTENT_ARG]: ' ' })).toBeUndefined();- expect(readIntentArg({ [INTENT_ARG]: 42 })).toBeUndefined();- expect(readIntentArg('not json')).toBeUndefined();});it('strips the arg without mutating the original', () => {diff --git a/packages/api/src/agents/intent.ts b/packages/api/src/agents/intent.tsindex fce00bb253..a7b945dbf6 100644--- a/packages/api/src/agents/intent.ts+++ b/packages/api/src/agents/intent.ts@@ -118,16 +118,6 @@ export function hasIntentArg(args: unknown): boolean {return obj != null && INTENT_ARG in obj;}-/** Reads the model-authored intent from tool-call args (handles stringified args). */-export function readIntentArg(args: unknown): string | undefined {- const value = coerceArgsObject(args)?.[INTENT_ARG];- if (typeof value !== 'string') {- return undefined;- }- const trimmed = value.trim();- return trimmed === '' ? undefined : trimmed;-}-/*** Returns the args without the injected `intent` key so a tool that did not* declare the parameter never receives it. Parses stringified JSON objectdiff --git a/packages/api/src/agents/listingAvatars.spec.ts b/packages/api/src/agents/listingAvatars.spec.tsindex a6735be150..76836eb073 100644--- a/packages/api/src/agents/listingAvatars.spec.ts+++ b/packages/api/src/agents/listingAvatars.spec.ts@@ -1,27 +1,4 @@-import { FileSources } from 'librechat-data-provider';-import {- isFullAgentListAvatarCacheEntry,- getAgentListAvatarRefreshKey,- refreshAgentListAvatarsBeforePage,- refreshManagedAgentListPageAvatars,-} from './listingAvatars';-import { MAX_AVATAR_REFRESH_AGENTS } from './avatars';--const visible = { id: 'agent-visible', avatar: { source: FileSources.s3, filepath: 'old.jpg' } };-const nextPage = { id: 'agent-next', avatar: { source: FileSources.s3, filepath: 'next.jpg' } };-const local = { id: 'agent-local', avatar: { source: FileSources.local, filepath: 'local.jpg' } };--function params() {- return {- accessibleIds: null,- agents: [visible, local],- cachedEntry: null,- refreshS3Url: jest.fn().mockResolvedValue('signed-visible.jpg'),- cacheSet: jest.fn().mockResolvedValue(undefined),- cacheKey: 'user:tenant:avatars',- ttl: 1800,- };-}+import { getAgentListAvatarRefreshKey } from './listingAvatars';describe('Agent listing avatar scope', () => {it('uses the same tenant-qualified key for listing and upload, including legacy users', () => {@@ -33,140 +10,4 @@ describe('Agent listing avatar scope', () => {);expect(getAgentListAvatarRefreshKey({ id: 'alice' })).toBe('alice::agents_avatar_refresh');});-- it('does not load every tenant avatar before a manager list query', async () => {- const refreshAll = jest.fn().mockResolvedValue({ urlCache: { 'agent-visible': 'signed.jpg' } });- await expect(refreshAgentListAvatarsBeforePage(null, null, refreshAll)).resolves.toBeNull();- expect(refreshAll).not.toHaveBeenCalled();-- const previous = { urlCache: { 'agent-visible': 'signed.jpg' } };- await expect(refreshAgentListAvatarsBeforePage(null, previous, refreshAll)).resolves.toEqual(- previous,- );- expect(refreshAll).not.toHaveBeenCalled();- await expect(refreshAgentListAvatarsBeforePage([], null, refreshAll)).resolves.toEqual(- previous,- );- expect(refreshAll).toHaveBeenCalledTimes(1);- expect(isFullAgentListAvatarCacheEntry(previous)).toBe(true);- expect(isFullAgentListAvatarCacheEntry({ ...previous, scope: 'page' })).toBe(false);- });-- it('presigns only the manager search page without writing agent documents', async () => {- const options = params();- const result = await refreshManagedAgentListPageAvatars(options);-- expect(options.refreshS3Url).toHaveBeenCalledTimes(1);- expect(options.refreshS3Url).toHaveBeenCalledWith(visible.avatar);- expect(result?.urlCache).toEqual({ 'agent-visible': 'signed-visible.jpg' });- expect(options.cacheSet).toHaveBeenCalledWith(options.cacheKey, result, expect.any(Number));- expect(options.cacheSet.mock.calls[0][2]).toBeLessThanOrEqual(options.ttl);-- await refreshManagedAgentListPageAvatars({- ...options,- cachedEntry: result,- agents: [visible],- });- expect(options.refreshS3Url).toHaveBeenCalledTimes(1);-- await refreshManagedAgentListPageAvatars({- ...options,- cachedEntry: result,- agents: [nextPage],- });- expect(options.refreshS3Url).toHaveBeenCalledTimes(2);- });-- it('bounds each manager cache entry while retaining the newest entries', async () => {- const options = params();- const all = Array.from({ length: MAX_AVATAR_REFRESH_AGENTS + 1 }, (_, index) => ({- id: `agent-${index}`,- avatar: { source: FileSources.s3, filepath: `old-${index}.jpg` },- }));- const first = await refreshManagedAgentListPageAvatars({- ...options,- agents: all.slice(0, MAX_AVATAR_REFRESH_AGENTS),- });- const next = await refreshManagedAgentListPageAvatars({- ...options,- cachedEntry: first,- agents: all.slice(MAX_AVATAR_REFRESH_AGENTS),- });-- expect(Object.keys(next!.urlCache)).toHaveLength(MAX_AVATAR_REFRESH_AGENTS);- expect(next!.urlCache['agent-0']).toBeUndefined();- expect(next!.urlCache[`agent-${MAX_AVATAR_REFRESH_AGENTS}`]).toBe('signed-visible.jpg');- expect(options.cacheSet).toHaveBeenCalledTimes(2);- });-- it('re-signs entries after their original TTL even when later pages updated the cache', async () => {- const options = params();- const clock = jest.spyOn(Date, 'now').mockReturnValue(1000);- try {- const first = await refreshManagedAgentListPageAvatars(options);- expect(first?.expiresAt).toBe(1000 + options.ttl);- clock.mockReturnValue(1000 + options.ttl - 1);- const second = await refreshManagedAgentListPageAvatars({- ...options,- cachedEntry: first,- agents: [nextPage],- });- expect(options.cacheSet.mock.calls[1][2]).toBe(1);-- clock.mockReturnValue(1000 + options.ttl);- const renewed = await refreshManagedAgentListPageAvatars({- ...options,- cachedEntry: second,- agents: [visible],- });- expect(renewed?.expiresAt).toBe(1000 + options.ttl * 2);- expect(options.refreshS3Url).toHaveBeenCalledTimes(3);- } finally {- clock.mockRestore();- }- });-- it('re-signs when another user replaces a cached avatar', async () => {- const options = params();- const previous = await refreshManagedAgentListPageAvatars(options);- const replacement = {- id: visible.id,- avatar: { source: FileSources.s3, filepath: 'replacement.jpg' },- };- options.refreshS3Url.mockResolvedValueOnce('signed-replacement.jpg');-- const refreshed = await refreshManagedAgentListPageAvatars({- ...options,- cachedEntry: previous,- agents: [replacement],- });-- expect(options.refreshS3Url).toHaveBeenCalledTimes(2);- expect(refreshed?.urlCache[visible.id]).toBe('signed-replacement.jpg');- expect(refreshed?.avatarPaths?.[visible.id]).toBe('replacement.jpg');- expect(options.cacheSet).toHaveBeenCalledTimes(2);- });-- it('leaves an ordinary ACL viewer on the pre-query full-list refresh path', async () => {- const options = params();- const previous = { urlCache: { 'agent-visible': 'signed.jpg' } };- const result = await refreshManagedAgentListPageAvatars({- ...options,- accessibleIds: ['507f1f77bcf86cd799439011'],- cachedEntry: previous,- });- expect(result).toBe(previous);- expect(options.refreshS3Url).not.toHaveBeenCalled();- expect(options.cacheSet).not.toHaveBeenCalled();- });-- it('allows retry after an S3 failure without failing the list response', async () => {- const options = params();- options.refreshS3Url.mockRejectedValueOnce(new Error('S3 unavailable'));- const result = await refreshManagedAgentListPageAvatars(options);- expect(result?.urlCache).toEqual({});- expect(options.cacheSet).not.toHaveBeenCalled();- await refreshManagedAgentListPageAvatars({ ...options, cachedEntry: result });- expect(options.cacheSet).toHaveBeenCalledTimes(1);- });});diff --git a/packages/api/src/agents/listingAvatars.ts b/packages/api/src/agents/listingAvatars.tsindex 8be8e3bbe0..7b1db09272 100644--- a/packages/api/src/agents/listingAvatars.ts+++ b/packages/api/src/agents/listingAvatars.ts@@ -1,18 +1,3 @@-import { logger } from '@librechat/data-schemas';-import { FileSources } from 'librechat-data-provider';-import type { AgentAvatar } from 'librechat-data-provider';-import type { RefreshS3UrlFn } from './avatars';-import { AVATAR_REFRESH_BATCH_SIZE, MAX_AVATAR_REFRESH_AGENTS } from './avatars';--type AvatarRefreshEntry = {- urlCache: Record<string, string>;- /** Stored pathname corresponding to each signed page URL, used to detect avatar replacements. */- avatarPaths?: Record<string, string>;- scope?: 'page';- expiresAt?: number;-};-type ListedAgent = { id?: string; avatar?: AgentAvatar };-/** The list writer and avatar upload invalidator must always use the same tenant-scoped key. */export function getAgentListAvatarRefreshKey(user: {id: string;@@ -20,126 +5,3 @@ export function getAgentListAvatarRefreshKey(user: {}): string {return `${user.id}:${user.tenantId ?? ''}:agents_avatar_refresh`;}--function validRefreshEntry(entry: unknown): entry is AvatarRefreshEntry {- return (- entry != null &&- typeof entry === 'object' &&- 'urlCache' in entry &&- entry.urlCache != null &&- typeof entry.urlCache === 'object' &&- !Array.isArray(entry.urlCache)- );-}--export function isFullAgentListAvatarCacheEntry(entry: unknown): boolean {- return validRefreshEntry(entry) && entry.scope !== 'page';-}--/** Only ACL-scoped lists use the full-set refresh, which must finish before a cursor snapshot. */-export async function refreshAgentListAvatarsBeforePage(- accessibleIds: string[] | null,- cachedEntry: unknown,- refreshAll: () => Promise<AvatarRefreshEntry | null>,-): Promise<AvatarRefreshEntry | null> {- if (accessibleIds === null) {- return validRefreshEntry(cachedEntry) ? cachedEntry : null;- }- return refreshAll();-}--/**- * A manager has access to the whole tenant, but refreshing all of its avatars before each- * search can presign and write hundreds of unrelated agents. Refresh only the visible page.- * Do not persist these URL changes: updating `updatedAt` after taking a cursor snapshot would- * reorder later pages, and legacy users without tenant context cannot safely update by public ID.- */-export async function refreshManagedAgentListPageAvatars({- accessibleIds,- agents,- cachedEntry,- refreshS3Url,- cacheSet,- cacheKey,- ttl,-}: {- accessibleIds: string[] | null;- agents: ListedAgent[];- cachedEntry: AvatarRefreshEntry | null;- refreshS3Url: RefreshS3UrlFn;- cacheSet: (key: string, entry: AvatarRefreshEntry, ttl: number) => Promise<unknown>;- cacheKey: string;- ttl: number;-}): Promise<AvatarRefreshEntry | null> {- if (accessibleIds !== null || agents.length === 0) {- return cachedEntry;- }-- const now = Date.now();- const cachedExpiresAt = cachedEntry?.scope === 'page' ? cachedEntry.expiresAt : undefined;- const cachedPageIsFresh = typeof cachedExpiresAt === 'number' && cachedExpiresAt > now;- const urlCache = cachedPageIsFresh ? { ...cachedEntry?.urlCache } : {};- const avatarPaths = cachedPageIsFresh ? { ...cachedEntry?.avatarPaths } : {};- const expiresAt = cachedPageIsFresh ? cachedExpiresAt : now + ttl;- // A different user can replace an agent's avatar without clearing this viewer's cache.- // Never overlay a new avatar with a signed URL for an older stored pathname.- for (const agent of agents) {- if (- agent.id &&- Object.prototype.hasOwnProperty.call(urlCache, agent.id) &&- (agent.avatar?.source !== FileSources.s3 ||- !agent.avatar.filepath ||- avatarPaths[agent.id] !== agent.avatar.filepath)- ) {- delete urlCache[agent.id];- delete avatarPaths[agent.id];- }- }- const pending = agents.filter(- (agent) =>- agent.id &&- agent.avatar?.source === FileSources.s3 &&- agent.avatar.filepath &&- !Object.prototype.hasOwnProperty.call(urlCache, agent.id),- );- if (pending.length === 0) {- return cachedPageIsFresh ? { urlCache, avatarPaths, scope: 'page', expiresAt } : null;- }-- let changed = false;- for (let index = 0; index < pending.length; index += AVATAR_REFRESH_BATCH_SIZE) {- await Promise.all(- pending.slice(index, index + AVATAR_REFRESH_BATCH_SIZE).map(async (agent) => {- try {- const url = await refreshS3Url(agent.avatar!);- if (url && agent.id) {- urlCache[agent.id] = url;- avatarPaths[agent.id] = agent.avatar!.filepath!;- changed = true;- }- } catch (error) {- logger.warn('[AgentList] Failed to refresh visible avatar: %o', error);- }- }),- );- }-- if (changed) {- // A manager can visit far more agents than the full-set refresh ever loads.- // Bound one user's Redis entry to the existing avatar-refresh budget.- const cacheIds = Object.keys(urlCache);- for (const id of cacheIds.slice(0, Math.max(0, cacheIds.length - MAX_AVATAR_REFRESH_AGENTS))) {- delete urlCache[id];- delete avatarPaths[id];- }- }- const entry: AvatarRefreshEntry = { urlCache, avatarPaths, scope: 'page', expiresAt };- if (changed) {- try {- await cacheSet(cacheKey, entry, Math.max(1, expiresAt - Date.now()));- } catch (error) {- logger.warn('[AgentList] Failed to cache refreshed avatars: %o', error);- }- }- return entry;-}diff --git a/packages/api/src/agents/openai/types.ts b/packages/api/src/agents/openai/types.tsindex 623f7de9c0..a03ac3107b 100644--- a/packages/api/src/agents/openai/types.ts+++ b/packages/api/src/agents/openai/types.ts@@ -164,13 +164,6 @@ export interface ChatCompletionChunk {usage?: CompletionUsage;}-/**- * SSE event wrapper for streaming- */-export interface SSEEvent {- data: ChatCompletionChunk | '[DONE]';-}-/*** Context for building OpenAI responses*/@@ -183,14 +176,6 @@ export interface OpenAIResponseContext {created: number;}-/**- * Aggregated content for building final response- */-export interface AggregatedContent {- text: string;- toolCalls: ToolCall[];-}-/*** Error response in OpenAI format*/diff --git a/packages/api/src/agents/responses/handlers.ts b/packages/api/src/agents/responses/handlers.tsindex 83bcf34556..44deca90ac 100644--- a/packages/api/src/agents/responses/handlers.ts+++ b/packages/api/src/agents/responses/handlers.ts@@ -328,33 +328,6 @@ export function emitResponseCompleted(config: StreamHandlerConfig, usage?: Usage});}-/**- * Emit response.failed event- */-export function emitResponseFailed(- config: StreamHandlerConfig,- error: { type: string; message: string; code?: string },-): void {- const { res, context, tracker } = config;- tracker.status = 'failed';- const response = buildResponse(context, tracker, 'failed');- response.error = {- type: error.type as- | 'server_error'- | 'invalid_request'- | 'not_found'- | 'model_error'- | 'too_many_requests',- message: error.message,- code: error.code,- };- writeEvent(res, {- type: 'response.failed',- sequence_number: tracker.nextSequence(),- response,- });-}-/*** Emit response.output_item.added event for a message*/@@ -900,43 +873,3 @@ export function writeAttachmentEvent(conversation_id: options?.conversationId,});}--/* =============================================================================- * NON-STREAMING RESPONSE BUILDER- * ============================================================================= */--/**- * Build a complete non-streaming response- */-export function buildResponsesNonStreamingResponse(- context: ResponseContext,- tracker: ResponseTracker,-): Response {- return buildResponse(context, tracker, 'completed');-}--/**- * Update tracker usage from collected data- */-export function updateTrackerUsage(- tracker: ResponseTracker,- usage: {- promptTokens?: number;- completionTokens?: number;- reasoningTokens?: number;- cachedTokens?: number;- },-): void {- if (usage.promptTokens != null) {- tracker.usage.inputTokens = usage.promptTokens;- }- if (usage.completionTokens != null) {- tracker.usage.outputTokens = usage.completionTokens;- }- if (usage.reasoningTokens != null) {- tracker.usage.reasoningTokens = usage.reasoningTokens;- }- if (usage.cachedTokens != null) {- tracker.usage.cachedTokens = usage.cachedTokens;- }-}diff --git a/packages/api/src/agents/responses/index.ts b/packages/api/src/agents/responses/index.tsindex 692174a4c7..5d08279090 100644--- a/packages/api/src/agents/responses/index.ts+++ b/packages/api/src/agents/responses/index.ts@@ -125,7 +125,6 @@ export {emitResponseCreated,emitResponseInProgress,emitResponseCompleted,- emitResponseFailed,// Message eventsemitMessageItemAdded,emitMessageItemDone,@@ -152,9 +151,6 @@ export {emitAttachment,writeAttachmentEvent,type AttachmentData,- // Non-streaming- buildResponsesNonStreamingResponse,- updateTrackerUsage,} from './handlers';// Service@@ -164,7 +160,6 @@ export {isValidationFailure,// Input conversionconvertInputToMessages,- mergeMessagesWithInput,type InternalMessage,// Error responsesendResponsesErrorResponse,diff --git a/packages/api/src/agents/responses/service.ts b/packages/api/src/agents/responses/service.tsindex ccd44ba4bf..d878f13db7 100644--- a/packages/api/src/agents/responses/service.ts+++ b/packages/api/src/agents/responses/service.ts@@ -441,16 +441,6 @@ function collectFunctionCallOutputs(input: InputItem[]): Map<string, string> {return outputs;}-/**- * Merge previous conversation messages with new input- */-export function mergeMessagesWithInput(- previousMessages: InternalMessage[],- newInput: InternalMessage[],-): InternalMessage[] {- return [...previousMessages, ...newInput];-}-/* =============================================================================* ERROR RESPONSE* ============================================================================= */diff --git a/packages/api/src/agents/subagentActivity.ts b/packages/api/src/agents/subagentActivity.tsindex 4b6cfeac75..3501de1ef0 100644--- a/packages/api/src/agents/subagentActivity.ts+++ b/packages/api/src/agents/subagentActivity.ts@@ -682,11 +682,3 @@ export function createSubagentActivityStreamHandler(}};}--export const SUBAGENT_ACTIVITY_STREAM_LIMITS: Readonly<{- eventBytes: number;- labelBytes: number;-}> = Object.freeze({- eventBytes: MAX_EVENT_BYTES,- labelBytes: MAX_LABEL_BYTES,-});diff --git a/packages/api/src/agents/triggers/delivery.ts b/packages/api/src/agents/triggers/delivery.tsindex 1eb96ea30e..8253806e90 100644--- a/packages/api/src/agents/triggers/delivery.ts+++ b/packages/api/src/agents/triggers/delivery.ts@@ -4,7 +4,6 @@ import { getAgentTriggerIdempotencyKey, parseAgentTriggerEnvelope } from './enveexport const MAX_AGENT_TRIGGER_ENVELOPE_BYTES: number = 1024 * 1024;export const AGENT_TRIGGER_COALESCE_WINDOW_MS = 750;-export const MAX_AGENT_TRIGGER_BATCH_SIZE = 8;export const MAX_AGENT_TRIGGER_BATCH_BYTES: number = 512 * 1024;export interface AgentTriggerCoalesceOptions {diff --git a/packages/api/src/apiKeys/service.ts b/packages/api/src/apiKeys/service.tsindex 4038e510fb..c473a332f2 100644--- a/packages/api/src/apiKeys/service.ts+++ b/packages/api/src/apiKeys/service.ts@@ -1,92 +1,12 @@-import { createMethods } from '@librechat/data-schemas';import { ResourceType, PermissionBits, hasPermissions } from 'librechat-data-provider';-import type {- AgentApiKeyListItem,- AgentApiKeyCreateResult,- AllMethods,- IUser,-} from '@librechat/data-schemas';import type { Types } from 'mongoose';-export interface ApiKeyServiceDependencies {- validateAgentApiKey: AllMethods['validateAgentApiKey'];- createAgentApiKey: AllMethods['createAgentApiKey'];- listAgentApiKeys: AllMethods['listAgentApiKeys'];- deleteAgentApiKey: AllMethods['deleteAgentApiKey'];- getAgentApiKeyById: AllMethods['getAgentApiKeyById'];- findUser: (query: { _id: string | Types.ObjectId }) => Promise<IUser | null>;-}-export interface RemoteAgentAccessResult {hasAccess: boolean;permissions: number;agent: { _id: Types.ObjectId; [key: string]: unknown } | null;}-export class AgentApiKeyService {- private deps: ApiKeyServiceDependencies;-- constructor(deps: ApiKeyServiceDependencies) {- this.deps = deps;- }-- async validateApiKey(apiKey: string): Promise<{- userId: Types.ObjectId;- keyId: Types.ObjectId;- } | null> {- return this.deps.validateAgentApiKey(apiKey);- }-- async createApiKey(params: {- userId: string | Types.ObjectId;- name: string;- expiresAt?: Date | null;- }): Promise<AgentApiKeyCreateResult> {- return this.deps.createAgentApiKey(params);- }-- async listApiKeys(userId: string | Types.ObjectId): Promise<AgentApiKeyListItem[]> {- return this.deps.listAgentApiKeys(userId);- }-- async deleteApiKey(- keyId: string | Types.ObjectId,- userId: string | Types.ObjectId,- ): Promise<boolean> {- return this.deps.deleteAgentApiKey(keyId, userId);- }-- async getApiKeyById(- keyId: string | Types.ObjectId,- userId: string | Types.ObjectId,- ): Promise<AgentApiKeyListItem | null> {- return this.deps.getAgentApiKeyById(keyId, userId);- }-- async getUserFromApiKey(apiKey: string): Promise<IUser | null> {- const keyValidation = await this.validateApiKey(apiKey);- if (!keyValidation) {- return null;- }-- return this.deps.findUser({ _id: keyValidation.userId });- }-}--export function createApiKeyServiceDependencies(- mongoose: typeof import('mongoose'),-): ApiKeyServiceDependencies {- const methods = createMethods(mongoose);- return {- validateAgentApiKey: methods.validateAgentApiKey,- createAgentApiKey: methods.createAgentApiKey,- listAgentApiKeys: methods.listAgentApiKeys,- deleteAgentApiKey: methods.deleteAgentApiKey,- getAgentApiKeyById: methods.getAgentApiKeyById,- findUser: methods.findUser,- };-}-export interface GetRemoteAgentPermissionsDeps {getEffectivePermissions: (params: {userId: string;diff --git a/packages/api/src/auth/allowedAddresses.ts b/packages/api/src/auth/allowedAddresses.tsindex 2b701ac44b..38b2899f17 100644--- a/packages/api/src/auth/allowedAddresses.ts+++ b/packages/api/src/auth/allowedAddresses.ts@@ -35,17 +35,6 @@ export function isIPLiteral(normalized: string): boolean {return normalized.includes(':');}-/**- * Detects `host:port` and `[ipv6]:port` shapes. Bare `::1`, `[::1]`, and- * IPv6 literals with no port are not matched.- */-export function looksLikeHostPort(entry: string): boolean {- if (/^\[[^\]]+\]:\d+$/.test(entry)) return true;- const colonCount = (entry.match(/:/g) ?? []).length;- if (colonCount !== 1) return false;- return /^[^:]+:\d+$/.test(entry);-}-export function normalizePort(port: unknown): string {if (typeof port !== 'string' && typeof port !== 'number') return '';const portString = String(port).trim();diff --git a/packages/api/src/auth/credentials.eviction.spec.ts b/packages/api/src/auth/credentials.eviction.spec.tsindex db254d9422..3c574b369d 100644--- a/packages/api/src/auth/credentials.eviction.spec.ts+++ b/packages/api/src/auth/credentials.eviction.spec.ts@@ -10,7 +10,7 @@ import {buildAuthUserDocCacheKey,AUTH_USER_DOC_CACHE_TTL_MS,} from './userDocCache';-import { isTokenIssuedBeforeCredentialChange } from './credentials';+import { isTokenRetired } from './twoFactor';let mongoServer: MongoMemoryServer;const originalCacheMode = process.env.AUTH_USER_CACHE_MODE;@@ -64,10 +64,8 @@ describe('credential change with a failing auth cache', () => {throw new Error('expected a cache key');}await setCachedAuthUserDoc(store, cacheKey, user);- const oldToken = { iat: Math.floor(Date.now() / 1000) - 60 };- expect(- isTokenIssuedBeforeCredentialChange(oldToken, await getCachedAuthUserDoc(store, cacheKey)),- ).toBe(false);+ const oldToken = { issuedAt: Math.floor(Date.now() / 1000) - 60 };+ expect(isTokenRetired(oldToken, await getCachedAuthUserDoc(store, cacheKey))).toBe(false);const updated = await methods.updateUser(userId, {password: 'new-password-hash',@@ -80,6 +78,6 @@ describe('credential change with a failing auth cache', () => {expect(updated?.credentialsChangedAt).toBeInstanceOf(Date);await expect(getCachedAuthUserDoc(store, cacheKey)).resolves.toBeUndefined();const current = await methods.findUser({ openidId: 'subject-1' });- expect(isTokenIssuedBeforeCredentialChange(oldToken, current)).toBe(true);+ expect(isTokenRetired(oldToken, current)).toBe(true);}, 20_000);});diff --git a/packages/api/src/auth/credentials.spec.ts b/packages/api/src/auth/credentials.spec.tsdeleted file mode 100644index e1531b51aa..0000000000--- a/packages/api/src/auth/credentials.spec.ts+++ /dev/null@@ -1,52 +0,0 @@-import { isTokenIssuedBeforeCredentialChange } from './credentials';--const changedAt = new Date(1700000010500);--describe('isTokenIssuedBeforeCredentialChange', () => {- it('revokes nothing for an account that never changed credentials', () => {- expect(isTokenIssuedBeforeCredentialChange({ iat: 1 }, {})).toBe(false);- expect(isTokenIssuedBeforeCredentialChange({ iat: 1 }, undefined)).toBe(false);- });-- it('rejects a token minted before the change', () => {- expect(- isTokenIssuedBeforeCredentialChange({ iat: 1700000009 }, { credentialsChangedAt: changedAt }),- ).toBe(true);- });-- it('fails closed for a token minted inside the second of the change', () => {- expect(- isTokenIssuedBeforeCredentialChange({ iat: 1700000010 }, { credentialsChangedAt: changedAt }),- ).toBe(true);- });-- it('accepts a token minted after the change', () => {- expect(- isTokenIssuedBeforeCredentialChange({ iat: 1700000011 }, { credentialsChangedAt: changedAt }),- ).toBe(false);- });-- it('reads string and numeric stamps the way Mongo or a cache may hand them back', () => {- const user = { credentialsChangedAt: changedAt.toISOString() };- expect(isTokenIssuedBeforeCredentialChange({ iat: 1700000009 }, user)).toBe(true);- expect(- isTokenIssuedBeforeCredentialChange(- { iat: 1700000011 },- { credentialsChangedAt: changedAt.getTime() },- ),- ).toBe(false);- });-- it('rejects a token without a usable iat once credentials have changed', () => {- const user = { credentialsChangedAt: changedAt };- expect(isTokenIssuedBeforeCredentialChange({}, user)).toBe(true);- expect(isTokenIssuedBeforeCredentialChange(undefined, user)).toBe(true);- expect(isTokenIssuedBeforeCredentialChange({ iat: Number.NaN }, user)).toBe(true);- });-- it('ignores an unreadable stamp rather than locking the account out', () => {- expect(- isTokenIssuedBeforeCredentialChange({ iat: 1 }, { credentialsChangedAt: 'not-a-date' }),- ).toBe(false);- });-});diff --git a/packages/api/src/auth/credentials.ts b/packages/api/src/auth/credentials.tsdeleted file mode 100644index 7570557d62..0000000000--- a/packages/api/src/auth/credentials.ts+++ /dev/null@@ -1,40 +0,0 @@-/** Timestamp source a user document may carry for its last credential change. */-export type CredentialChangeStamp = Date | string | number | null;--/**- * A password reset stamps `credentialsChangedAt` on the user. Access tokens are stateless,- * so a token minted before the reset keeps verifying on signature and `exp` alone unless the- * stamp is consulted: this predicate is what makes a reset revoke outstanding access tokens.- *- * `iat` is whole seconds, so it only identifies the second a token was minted in, not its- * position inside that second. Comparing the start of the issuing second against the- * millisecond-precision stamp fails closed: a token minted in the same second as the reset is- * rejected rather than accepted. Failing open there would let an attacker holding a live token- * refresh in a tight loop, land a mint inside the reset's second and keep a full-lifetime token,- * which is the attack the stamp exists to stop. The reset request issues no token of its own, so- * the only cost is that a login completing within the same second as the reset must be retried.- */-export function isTokenIssuedBeforeCredentialChange(- payload: { iat?: number } | null | undefined,- user: { credentialsChangedAt?: CredentialChangeStamp } | null | undefined,-): boolean {- const changedAt = user?.credentialsChangedAt;- if (!changedAt) {- return false;- }-- const changedAtMs =- changedAt instanceof Date ? changedAt.getTime() : new Date(changedAt).getTime();- /** An unreadable stamp revokes nothing; treating it as a cutoff would lock the account out for good */- if (!Number.isFinite(changedAtMs)) {- return false;- }-- const issuedAt = payload?.iat;- /** Without `iat` the token cannot be shown to postdate the reset */- if (typeof issuedAt !== 'number' || !Number.isFinite(issuedAt)) {- return true;- }-- return issuedAt * 1000 < changedAtMs;-}diff --git a/packages/api/src/auth/index.ts b/packages/api/src/auth/index.tsindex 5c03a45acf..f3596d382c 100644--- a/packages/api/src/auth/index.ts+++ b/packages/api/src/auth/index.ts@@ -13,7 +13,6 @@ export * from './password';export * from './recovery';export * from './passkey';export * from './passkey/handlers';-export * from './credentials';export * from './verification';export * from './invite';export * from './codeapi';diff --git a/packages/api/src/auth/userDocCache.ts b/packages/api/src/auth/userDocCache.tsindex 9ae331ec25..c25fe0238e 100644--- a/packages/api/src/auth/userDocCache.ts+++ b/packages/api/src/auth/userDocCache.ts@@ -46,10 +46,6 @@ type UserIdInput = {let warnedAuthUserDocCacheRequiresRedis = false;-export function getAuthUserDocCacheTtlMs(): number {- return AUTH_USER_DOC_CACHE_TTL_MS;-}-function isAuthUserDocCacheRedisBacked(): boolean {return (cacheConfig.USE_REDIS &&diff --git a/packages/api/src/cache/cacheConfig.ts b/packages/api/src/cache/cacheConfig.tsindex 00cff485cd..61672c283c 100644--- a/packages/api/src/cache/cacheConfig.ts+++ b/packages/api/src/cache/cacheConfig.ts@@ -134,14 +134,6 @@ const cacheConfig: {* @default 1000*/REDIS_DELETE_CHUNK_SIZE: number;- /**- * Number of keys to update in each batch during Redis SET operations.- * In cluster mode, keys are updated individually in parallel chunks to avoid CROSSSLOT errors.- * In single-node mode, keys are updated in batches using transactions (multi/exec).- * Lower values reduce memory usage but increase number of Redis calls.- * @default 1000- */- REDIS_UPDATE_CHUNK_SIZE: number;/*** COUNT hint for Redis SCAN operations when scanning keys by pattern.* This is a hint to Redis about how many keys to scan in each iteration.@@ -216,15 +208,6 @@ const cacheConfig: {*/REDIS_DELETE_CHUNK_SIZE: math(process.env.REDIS_DELETE_CHUNK_SIZE, 1000),- /**- * Number of keys to update in each batch during Redis SET operations.- * In cluster mode, keys are updated individually in parallel chunks to avoid CROSSSLOT errors.- * In single-node mode, keys are updated in batches using transactions (multi/exec).- * Lower values reduce memory usage but increase number of Redis calls.- * @default 1000- */- REDIS_UPDATE_CHUNK_SIZE: math(process.env.REDIS_UPDATE_CHUNK_SIZE, 1000),-/*** COUNT hint for Redis SCAN operations when scanning keys by pattern.* This is a hint to Redis about how many keys to scan in each iteration.diff --git a/packages/api/src/endpoints/google/llm.ts b/packages/api/src/endpoints/google/llm.tsindex 0c3c6daa59..6a70d1c85e 100644--- a/packages/api/src/endpoints/google/llm.ts+++ b/packages/api/src/endpoints/google/llm.ts@@ -559,26 +559,6 @@ export function getGoogleConfig(}}- /*- let legacyOptions = {};- // Filter out any "examples" that are empty- legacyOptions.examples = (legacyOptions.examples ?? [])- .filter(Boolean)- .filter((obj) => obj?.input?.content !== '' && obj?.output?.content !== '');-- // If user has "examples" from legacyOptions, push them onto llmConfig- if (legacyOptions.examples?.length) {- llmConfig.examples = legacyOptions.examples.map((ex) => {- const { input, output } = ex;- if (!input?.content || !output?.content) {return undefined;}- return {- input: new HumanMessage(input.content),- output: new AIMessage(output.content),- };- }).filter(Boolean);- }- */-if (reverseProxyUrl) {(llmConfig as GoogleClientOptions).baseUrl = reverseProxyUrl;}diff --git a/packages/api/src/files/documents/html.spec.ts b/packages/api/src/files/documents/html.spec.tsindex e320abddf9..8ed4293eb0 100644--- a/packages/api/src/files/documents/html.spec.ts+++ b/packages/api/src/files/documents/html.spec.ts@@ -9,7 +9,6 @@ import {excelSheetToHtml,officeHtmlBucket,pptxToHtml,- pptxToSlideListHtml,sanitizeOfficeHtml,wordDocToHtml,} from './html';@@ -18,6 +17,21 @@ import { ZipBombError } from './zipSafety';const fixturesDir = __dirname;const readFixture = (name: string): Buffer => fs.readFileSync(path.join(fixturesDir, name));+/** Renders the text-only slide-list preview, which `pptxToHtml` selects when the CDN is disabled. */+const pptxToSlideListHtml = async (buffer: Buffer): Promise<string> => {+ const previous = process.env.OFFICE_PREVIEW_DISABLE_CDN;+ process.env.OFFICE_PREVIEW_DISABLE_CDN = 'true';+ try {+ return await pptxToHtml(buffer);+ } finally {+ if (previous === undefined) {+ delete process.env.OFFICE_PREVIEW_DISABLE_CDN;+ } else {+ process.env.OFFICE_PREVIEW_DISABLE_CDN = previous;+ }+ }+};+describe('Office HTML producers', () => {describe('wordDocToHtml', () => {/* The dispatcher chooses CDN vs mammoth by buffer size. The fixturediff --git a/packages/api/src/files/documents/html.ts b/packages/api/src/files/documents/html.tsindex 2ee0ff163b..bf5e843e7e 100644--- a/packages/api/src/files/documents/html.ts+++ b/packages/api/src/files/documents/html.ts@@ -1007,27 +1007,6 @@ function renderPptxSlidesHtml(slides: PptxSlide[]): string {return wrapAsDocument(renderPptxSlidesBody(slides), PPTX_SLIDE_LIST_CSS);}-/**- * Convert a `.pptx` buffer to a slide-list HTML document — text-only- * preview rendering each slide as a card (slide number, title, body- * bullets). Honest about NOT preserving complex visual layouts,- * charts, theming, or embedded media. Used as the safe fallback path- * when the CDN renderer is disabled, the binary exceeds the embed- * size cap, or the high-fidelity path can't be reached.- *- * Pre-flights through `assertSafeZipSize` so a zip-bomb PPTX can't blow- * up the slide-XML extraction pass.- */-export async function pptxToSlideListHtml(buffer: Buffer): Promise<string> {- await assertSafeZipSize(buffer, { name: 'pptx' });- const rawSlides = await extractPptxSlideXml(buffer);- const slides: PptxSlide[] = rawSlides.map(({ number, xml }) => {- const { title, body } = extractSlideText(xml);- return { number, title, body };- });- return renderPptxSlidesHtml(slides);-}-/* =============================================================================* PPTX CDN renderer (high-fidelity path)*@@ -1460,8 +1439,7 @@ export async function pptxToHtml(buffer: Buffer): Promise<string> {/*** Slide-list path that skips its own `assertSafeZipSize` call — used* by `pptxToHtml` after the dispatcher has already validated the- * buffer. `pptxToSlideListHtml` (public, validating) stays the entry- * point for tests and direct callers.+ * buffer.*/async function pptxToSlideListHtmlInternal(buffer: Buffer): Promise<string> {const rawSlides = await extractPptxSlideXml(buffer);diff --git a/packages/api/src/files/filter.spec.ts b/packages/api/src/files/filter.spec.tsindex f64a601719..2e988a81c3 100644--- a/packages/api/src/files/filter.spec.ts+++ b/packages/api/src/files/filter.spec.ts@@ -4,7 +4,7 @@ import { EModelEndpoint, FileSources } from 'librechat-data-provider';import type { IMongoFile } from '@librechat/data-schemas';import type { AppConfig } from '@librechat/data-schemas';import type { ServerRequest } from '~/types';-import { filterFilesByEndpointConfig, filterFilesByEndpointRuntimeConfig } from './filter';+import { filterFilesByEndpointRuntimeConfig } from './filter';describe('filterFilesByEndpointRuntimeConfig', () => {const sizedFile = (filename: string, bytes: number): IMongoFile =>@@ -90,7 +90,12 @@ describe('filterFilesByEndpointRuntimeConfig', () => {});});-describe('filterFilesByEndpointConfig', () => {+describe('filterFilesByEndpointRuntimeConfig with request config', () => {+ const filterFilesByEndpointConfig = (+ req: ServerRequest,+ params: Parameters<typeof filterFilesByEndpointRuntimeConfig>[1],+ ) => filterFilesByEndpointRuntimeConfig(req.config, params);+/** Helper to create a mock file */const createMockFile = (filename: string): IMongoFile =>({diff --git a/packages/api/src/files/filter.ts b/packages/api/src/files/filter.tsindex f6881ac134..88d183f804 100644--- a/packages/api/src/files/filter.ts+++ b/packages/api/src/files/filter.ts@@ -4,9 +4,8 @@ import {mergeFileConfig,fileConfig,} from 'librechat-data-provider';-import type { AppConfig, IMongoFile } from '@librechat/data-schemas';import type { RegexLike, TFile } from 'librechat-data-provider';-import type { ServerRequest } from '~/types';+import type { AppConfig } from '@librechat/data-schemas';/*** Checks if a MIME type is supported by the endpoint configuration@@ -21,55 +20,12 @@ function isMimeTypeSupported(mimeType: string, supportedMimeTypes?: RegexLike[])return fileConfig.checkType(mimeType, supportedMimeTypes);}-/**- * Filters out files based on endpoint configuration including:- * - Disabled status- * - File size limits- * - MIME type restrictions- * - Total size limits- * @param req - The server request object containing config- * @param params - Object containing files, endpoint, and endpointType- * @param params.files - Array of processed file documents from MongoDB- * @param params.endpoint - The endpoint name to check configuration for- * @param params.endpointType - The endpoint type to check configuration for- * @returns Filtered array of files- */-export function filterFilesByEndpointConfig(- req: ServerRequest,- params: {- files: IMongoFile[] | undefined;- endpoint?: string | null;- endpointType?: string | null;- skipTotalSizeLimit?: boolean;- preserveTextSources?: boolean;- },-): IMongoFile[] {- return filterFilesByEndpointRuntimeConfig(req.config, params);-}--/** Request-free endpoint file-policy adapter used by Agent execution hosts. */-/**- * Whether this endpoint still presents the explicit upload-destination chooser. In that- * mode the destination is the user's choice and the upload path acts on it immediately,- * so nothing may be provisioned to a service they did not select.- */-export function isLegacyFileUploadUX(- appConfig: AppConfig | undefined,- params: { endpoint?: string | null; endpointType?: string | null },-): boolean {- const endpointFileConfig = getEndpointFileConfig({- fileConfig: mergeFileConfig(appConfig?.fileConfig),- endpoint: params.endpoint,- endpointType: params.endpointType,- });- return endpointFileConfig?.legacyFileUploadUX === true;-}-type EndpointPolicyFile = Pick<TFile, 'bytes' | 'type'> & {source?: string;metadata?: { routingMimeType?: string };};+/** Request-free endpoint file-policy adapter used by Agent execution hosts. */export function filterFilesByEndpointRuntimeConfig<T extends EndpointPolicyFile>(appConfig: AppConfig | undefined,params: {diff --git a/packages/api/src/files/parse.ts b/packages/api/src/files/parse.tsindex f931ec81e2..8074669a8f 100644--- a/packages/api/src/files/parse.ts+++ b/packages/api/src/files/parse.ts@@ -21,20 +21,3 @@ export function getImageBasename(urlString: string): string {return '';}}--/**- * Extracts the basename of a file from a given URL.- *- * @param urlString - The URL string from which the file basename is to be extracted.- * @returns The basename of the file from the URL.- * Returns an empty string if the URL parsing fails.- */-export function getFileBasename(urlString: string): string {- try {- const url = new URL(urlString);- return path.basename(url.pathname);- } catch {- // If URL parsing fails, return an empty string- return '';- }-}diff --git a/packages/api/src/files/provision/service.ts b/packages/api/src/files/provision/service.tsindex e50ba1e8f7..db8b9091e8 100644--- a/packages/api/src/files/provision/service.ts+++ b/packages/api/src/files/provision/service.ts@@ -111,11 +111,6 @@ export interface ProvisionService {existingStream?: Readable;signal?: AbortSignal;}) => Promise<{ embedded: boolean; fileUpdate: ProvisionFileUpdate | null }>;- checkCodeEnvFileAlive: (params: {- file: TFile;- apiKey?: string;- req?: ServerRequest;- }) => Promise<boolean>;checkSessionsAlive: (params: {files: TFile[];apiKey?: string;@@ -193,22 +188,6 @@ export function createProvisionService({return stream;}- /** Uses managed bearer auth when available, otherwise the configured legacy API key. */- async function buildCodeApiHeaders({- apiKey,- req,- }: {- apiKey?: string;- req?: ServerRequest;- }): Promise<Record<string, string>> {- const authHeaders = await getCodeApiAuthHeaders(req);- return {- 'User-Agent': 'LibreChat/1.0',- ...(authHeaders.Authorization == null && apiKey ? { 'X-API-Key': apiKey } : {}),- ...authHeaders,- };- }-/*** Auth for a liveness probe against the route that issued the refs, matching what that* route's uploads, reads and executions send. The legacy key belongs to the default@@ -466,54 +445,6 @@ export function createProvisionService({}}- /**- * Check if a single code env file is still alive by querying its session.- *- * @param {object} params- * @param {import('librechat-data-provider').TFile} params.file - File with metadata.codeEnvRef- * @param {string} [params.apiKey] - Legacy CODE_API_KEY, when configured- * @param {object} [params.req] - Request used to mint JWT code auth, when enabled- * @returns {Promise<boolean>} true if the file is still accessible in the code env- */- async function checkCodeEnvFileAlive({- file,- apiKey,- req,- }: {- file: TFile;- apiKey?: string;- req?: ServerRequest;- }): Promise<boolean> {- const ref = file.metadata?.codeEnvRef;- if (!ref?.storage_session_id || !ref?.file_id) {- return false;- }-- try {- const baseURL = getCodeBaseURL();- const response = await getAxios()({- method: 'get',- url: `${baseURL}/files/${ref.storage_session_id}`,- params: { detail: 'summary' },- headers: await buildCodeApiHeaders({ apiKey, req }),- httpAgent: codeServerHttpAgent,- httpsAgent: codeServerHttpsAgent,- timeout: 5000,- });-- const found = (response.data as Array<{ fileId?: string }> | undefined)?.some(- (f) => f.fileId === ref.file_id,- );- return !!found;- } catch (error) {- logAxiosError({- message: `[checkCodeEnvFileAlive] Error checking file "${file.filename}": ${(error as Error).message}`,- error,- });- return false;- }- }-/*** Batch-check code env file liveness by `storage_session_id`.* Groups files by session, makes one API call per session.@@ -690,7 +621,6 @@ export function createProvisionService({loadCodeApiKey,provisionToCodeEnv,provisionToVectorDB,- checkCodeEnvFileAlive,checkSessionsAlive,};}diff --git a/packages/api/src/mcp/__tests__/ConnectionsRepository.test.ts b/packages/api/src/mcp/__tests__/ConnectionsRepository.test.tsindex bebcfd704b..5e2233d885 100644--- a/packages/api/src/mcp/__tests__/ConnectionsRepository.test.ts+++ b/packages/api/src/mcp/__tests__/ConnectionsRepository.test.ts@@ -525,13 +525,6 @@ describe('ConnectionsRepository', () => {expect(mockConnection.dispose).toHaveBeenCalled();expect(repository['connections'].has('server1')).toBe(false);});- //todo revist later when async getAll(): in packages/api/src/mcp/ConnectionsRepository.ts is refactored- it.skip('should throw error for non-existent server configuration', async () => {- await expect(repository.get('nonexistent')).rejects.toThrow(- '[MCP][nonexistent] Server not found in configuration',- );- });-it('should handle MCPConnectionFactory.create errors', async () => {const createError = new Error('Connection creation failed');(MCPConnectionFactory.create as jest.Mock).mockRejectedValue(createError);diff --git a/packages/api/src/mcp/__tests__/utils.test.ts b/packages/api/src/mcp/__tests__/utils.test.tsindex ea39bc18d8..7bc211da20 100644--- a/packages/api/src/mcp/__tests__/utils.test.ts+++ b/packages/api/src/mcp/__tests__/utils.test.ts@@ -19,7 +19,6 @@ import {toCatalogConnectionConfig,applyRequestHeaders,hasRuntimeContextPlaceholders,- getRuntimeBodyPlaceholderFields,getMissingRuntimeBodyPlaceholderFields,isUserSourced,validateMCPServerConfig,@@ -910,7 +909,7 @@ describe('getMCPRequestScope', () => {headers: { 'X-Message': `\${${envName}}` },};expect(getMCPRequestScope(config).requestScoped).toBe(true);- expect(getRuntimeBodyPlaceholderFields(config)).toEqual(['messageId']);+ expect(getMCPRequestScope(config).requiredBodyFields).toEqual(['messageId']);} finally {if (previous == null) {delete process.env[envName];@@ -939,7 +938,7 @@ describe('getMCPRequestScope', () => {expect(hasRuntimeContextPlaceholders(config)).toBe(false);expect(hasRuntimeUrlPlaceholders(config)).toBe(false);expect(getMCPRequestScope(config).requestScoped).toBe(false);- expect(getRuntimeBodyPlaceholderFields(config)).toEqual([]);+ expect(getMCPRequestScope(config).requiredBodyFields).toEqual([]);expect(getMissingRuntimeBodyPlaceholderFields(config)).toEqual([]);expect(requiresEphemeralUserConnection(config)).toBe(false);expect(requiresUserScopedConnection(config)).toBe(false);@@ -957,7 +956,7 @@ describe('getMCPRequestScope', () => {expect(hasRuntimeContextPlaceholders(config)).toBe(false);expect(hasRuntimeUrlPlaceholders(config)).toBe(false);expect(getMCPRequestScope(config).requestScoped).toBe(false);- expect(getRuntimeBodyPlaceholderFields(config)).toEqual([]);+ expect(getMCPRequestScope(config).requiredBodyFields).toEqual([]);expect(getMissingRuntimeBodyPlaceholderFields(config)).toEqual([]);expect(requiresEphemeralUserConnection(config)).toBe(false);expect(requiresUserScopedConnection(config)).toBe(false);@@ -975,7 +974,7 @@ describe('getMissingRuntimeBodyPlaceholderFields', () => {} as const;it('returns the request body fields required by trusted runtime placeholders', () => {- expect(getRuntimeBodyPlaceholderFields(config)).toEqual([+ expect(getMCPRequestScope(config).requiredBodyFields).toEqual(['messageId','parentMessageId','conversationId',diff --git a/packages/api/src/mcp/oauth/types.ts b/packages/api/src/mcp/oauth/types.tsindex 000a21c896..7a1e5348ae 100644--- a/packages/api/src/mcp/oauth/types.ts+++ b/packages/api/src/mcp/oauth/types.ts@@ -70,31 +70,6 @@ export interface OAuthClientInformation {token_endpoint_auth_method?: string;}-export interface MCPOAuthState {- /** Current step in the OAuth flow */- step: 'discovery' | 'registration' | 'authorization' | 'token_exchange' | 'complete' | 'error';- /** Server name */- serverName: string;- /** User ID */- userId: string;- /** OAuth metadata from discovery */- metadata?: OAuthMetadata;- /** Resource metadata */- resourceMetadata?: OAuthProtectedResourceMetadata;- /** Client information */- clientInfo?: OAuthClientInformation;- /** Authorization URL */- authorizationUrl?: string;- /** Code verifier for PKCE */- codeVerifier?: string;- /** State parameter for OAuth flow */- state?: string;- /** Error information */- error?: string;- /** Timestamp */- timestamp: number;-}-export interface MCPOAuthFlowMetadata extends FlowMetadata {serverName: string;userId: string;diff --git a/packages/api/src/mcp/registry/cache/ServerConfigsCacheFactory.ts b/packages/api/src/mcp/registry/cache/ServerConfigsCacheFactory.tsindex ebe19b59e3..012cd397cb 100644--- a/packages/api/src/mcp/registry/cache/ServerConfigsCacheFactory.ts+++ b/packages/api/src/mcp/registry/cache/ServerConfigsCacheFactory.ts@@ -1,45 +1,35 @@import { ServerConfigsCacheRedisAggregateKey } from './ServerConfigsCacheRedisAggregateKey';import { ServerConfigsCacheInMemory } from './ServerConfigsCacheInMemory';-import { ServerConfigsCacheRedis } from './ServerConfigsCacheRedis';import { cacheConfig } from '~/cache';-export type ServerConfigsCache =- | ServerConfigsCacheInMemory- | ServerConfigsCacheRedis- | ServerConfigsCacheRedisAggregateKey;+export type ServerConfigsCache = ServerConfigsCacheInMemory | ServerConfigsCacheRedisAggregateKey;/*** Namespace for YAML-loaded app-level MCP configs. When Redis is enabled, uses a single* aggregate key instead of per-server keys to avoid the costly SCAN + batch-GET pattern- * in {@link ServerConfigsCacheRedis.getAll} that caused 60s+ stalls under concurrent- * load (see GitHub #11624, #12408). When Redis is disabled, uses in-memory storage.+ * that caused 60s+ stalls under concurrent load (see GitHub #11624, #12408). When Redis is+ * disabled, uses in-memory storage.*/export const APP_CACHE_NAMESPACE = 'App' as const;/** Namespace for admin-defined config-override MCP server inspection results. */export const CONFIG_CACHE_NAMESPACE = 'Config' as const;-/** Namespaces that use the aggregate-key optimization to avoid SCAN+N-GETs stalls. */-const AGGREGATE_KEY_NAMESPACES = new Set<string>([APP_CACHE_NAMESPACE, CONFIG_CACHE_NAMESPACE]);-/*** Factory for creating the appropriate ServerConfigsCache implementation based on- * deployment mode and namespace.+ * deployment mode.*- * Namespaces in {@link AGGREGATE_KEY_NAMESPACES} use {@link ServerConfigsCacheRedisAggregateKey}- * when Redis is enabled — storing all configs under a single key so `getAll()` is one GET- * instead of SCAN + N GETs. Cross-instance visibility is preserved: reinspection results+ * When Redis is enabled, all configs of a namespace are stored under a single key via+ * {@link ServerConfigsCacheRedisAggregateKey}, so `getAll()` is one GET instead of+ * SCAN + N GETs. Cross-instance visibility is preserved: reinspection results* propagate through Redis automatically.- *- * Other namespaces use the standard {@link ServerConfigsCacheRedis} (per-key storage with- * SCAN-based enumeration) when Redis is enabled.*/export class ServerConfigsCacheFactory {/*** Create a ServerConfigsCache instance.*- * @param namespace - The namespace for the cache. Namespaces in {@link AGGREGATE_KEY_NAMESPACES}- * use aggregate-key Redis storage (or in-memory when Redis is disabled).+ * @param namespace - The namespace for the cache (aggregate-key Redis storage, or+ * in-memory when Redis is disabled).* @param leaderOnly - Whether write operations should only be performed by the leader.* @returns ServerConfigsCache instance*/@@ -48,10 +38,6 @@ export class ServerConfigsCacheFactory {return new ServerConfigsCacheInMemory();}- if (AGGREGATE_KEY_NAMESPACES.has(namespace)) {- return new ServerConfigsCacheRedisAggregateKey(namespace, leaderOnly);- }-- return new ServerConfigsCacheRedis(namespace, leaderOnly);+ return new ServerConfigsCacheRedisAggregateKey(namespace, leaderOnly);}}diff --git a/packages/api/src/mcp/registry/cache/ServerConfigsCacheRedis.ts b/packages/api/src/mcp/registry/cache/ServerConfigsCacheRedis.tsdeleted file mode 100644index 8483394dd4..0000000000--- a/packages/api/src/mcp/registry/cache/ServerConfigsCacheRedis.ts+++ /dev/null@@ -1,201 +0,0 @@-import { fromPairs } from 'lodash';-import { logger } from '@librechat/data-schemas';-import type Keyv from 'keyv';-import type { IServerConfigsRepositoryInterface } from '~/mcp/registry/ServerConfigsRepositoryInterface';-import type { ParsedServerConfig, AddServerResult } from '~/mcp/types';-import {- cacheConfig,- evalKeyvRedisScript,- keyvRedisClient,- observeRedisOperation,- RedisUseCases,- standardCache,-} from '~/cache';-import { PRESERVE_EMPTY_ARRAYS_LUA } from './preserveEmptyArraysLua';-import { BaseRegistryCache } from './BaseRegistryCache';--/**- * Redis-backed implementation of MCP server configurations cache for distributed deployments.- * Stores server configs in Redis with namespace isolation.- * Enables data sharing across multiple server instances in a cluster environment.- * Supports optional leader-only write operations to prevent race conditions during initialization.- * Data persists across server restarts and is accessible from any instance in the cluster.- */-const BATCH_SIZE = 100;--const PATCH_ENTRY = `-${PRESERVE_EMPTY_ARRAYS_LUA}-local encoded = redis.call('GET', KEYS[1])-if not encoded then return 0 end-local sentinel = emptyArraySentinel(encoded, ARGV[1])-local envelope = cjson.decode(protectEmptyArrays(encoded, sentinel))-if not envelope.value then return 0 end-local fields = cjson.decode(protectEmptyArrays(ARGV[1], sentinel))-if ARGV[2] ~= '' and tonumber(ARGV[2]) ~= envelope.value.updatedAt then return 0 end-if fields.resolvedInstructions and envelope.value.resolvedInstructions then return 0 end-local ttl = redis.call('PTTL', KEYS[1])-for field, value in pairs(fields) do envelope.value[field] = value end-redis.call('SET', KEYS[1], restoreEmptyArrays(cjson.encode(envelope), sentinel))-if ttl > 0 then redis.call('PEXPIRE', KEYS[1], ttl) end-return 1-`;--export class ServerConfigsCacheRedis- extends BaseRegistryCache- implements IServerConfigsRepositoryInterface-{- protected readonly cache: Keyv;- private readonly namespace: string;-- constructor(namespace: string, leaderOnly: boolean) {- super(leaderOnly);- this.namespace = namespace;- this.cache = standardCache(`${this.PREFIX}::Servers::${namespace}`);- }-- private usesRedisStore(): boolean {- const namespace = this.cache.namespace;- return (- keyvRedisClient != null &&- namespace != null &&- !cacheConfig.FORCED_IN_MEMORY_CACHE_NAMESPACES?.includes(namespace)- );- }-- private redisKey(serverName: string): string {- const prefix = cacheConfig.REDIS_KEY_PREFIX- ? `${cacheConfig.REDIS_KEY_PREFIX}${cacheConfig.GLOBAL_PREFIX_SEPARATOR}`- : '';- return `${prefix}${this.cache.namespace}:${serverName}`;- }-- public async add(serverName: string, config: ParsedServerConfig): Promise<AddServerResult> {- if (this.leaderOnly) await this.leaderCheck(`add ${this.namespace} MCP servers`);- const exists = await this.cache.has(serverName);- if (exists)- throw new Error(- `Server "${serverName}" already exists in cache. Use update() to modify existing configs.`,- );- const storedConfig = { ...config, updatedAt: Date.now() };- const success = await this.cache.set(serverName, storedConfig);- this.successCheck(`add ${this.namespace} server "${serverName}"`, success);- return { serverName, config: storedConfig };- }-- public async update(serverName: string, config: ParsedServerConfig): Promise<void> {- if (this.leaderOnly) await this.leaderCheck(`update ${this.namespace} MCP servers`);- const exists = await this.cache.has(serverName);- if (!exists)- throw new Error(- `Server "${serverName}" does not exist in cache. Use add() to create new configs.`,- );- const success = await this.cache.set(serverName, { ...config, updatedAt: Date.now() });- this.successCheck(`update ${this.namespace} server "${serverName}"`, success);- }-- public async upsert(serverName: string, config: ParsedServerConfig): Promise<void> {- if (this.leaderOnly) await this.leaderCheck(`upsert ${this.namespace} MCP servers`);- const success = await this.cache.set(serverName, { ...config, updatedAt: Date.now() });- this.successCheck(`upsert ${this.namespace} server "${serverName}"`, success);- }-- /** Merges derived fields into an existing entry without bumping `updatedAt` —- * see the interface doc: a bump would mark live connections stale. */- public async patch(- serverName: string,- fields: Partial<ParsedServerConfig>,- expectedUpdatedAt?: number,- ): Promise<boolean> {- if (this.leaderOnly) await this.leaderCheck(`patch ${this.namespace} MCP servers`);- if (this.usesRedisStore()) {- const result = await evalKeyvRedisScript(PATCH_ENTRY, {- keys: [this.redisKey(serverName)],- arguments: [- JSON.stringify(fields),- expectedUpdatedAt != null ? String(expectedUpdatedAt) : '',- ],- });- return result === 1;- }- const existing = (await this.cache.get(serverName)) as ParsedServerConfig | undefined;- if (!existing) {- return false;- }- if (expectedUpdatedAt != null && existing.updatedAt !== expectedUpdatedAt) {- return false;- }- if (fields.resolvedInstructions != null && existing.resolvedInstructions != null) {- return false;- }- const success = await this.cache.set(serverName, { ...existing, ...fields });- this.successCheck(`patch ${this.namespace} server "${serverName}"`, success);- return true;- }-- public async remove(serverName: string): Promise<void> {- if (this.leaderOnly) await this.leaderCheck(`remove ${this.namespace} MCP servers`);- const success = await this.cache.delete(serverName);- this.successCheck(`remove ${this.namespace} server "${serverName}"`, success);- }-- public async get(serverName: string): Promise<ParsedServerConfig | undefined> {- return this.cache.get(serverName);- }-- public async getAll(): Promise<Record<string, ParsedServerConfig>> {- const redisClient = keyvRedisClient;- if (!redisClient || !('scanIterator' in redisClient)) {- throw new Error('Redis client with scanIterator not available.');- }-- const startTime = Date.now();- const pattern = `*${this.cache.namespace}:*`;-- const keys = await observeRedisOperation(- 'keyv',- RedisUseCases.MCP_REGISTRY,- 'scan',- async () => {- const scannedKeys: string[] = [];- for await (const page of redisClient.scanIterator({ MATCH: pattern })) {- scannedKeys.push(...page);- }- return scannedKeys;- },- );-- if (keys.length === 0) {- logger.debug(`[ServerConfigsCacheRedis] getAll(${this.namespace}): no keys found`);- return {};- }-- /** Extract keyName from full Redis key format: "prefix::namespace:keyName" */- const keyNames = keys.map((key) => key.substring(key.lastIndexOf(':') + 1));-- const entries: Array<[string, ParsedServerConfig]> = [];-- for (let i = 0; i < keyNames.length; i += BATCH_SIZE) {- const batchEnd = Math.min(i + BATCH_SIZE, keyNames.length);- const promises: Promise<ParsedServerConfig | undefined>[] = [];-- for (let j = i; j < batchEnd; j++) {- promises.push(this.cache.get(keyNames[j]));- }-- const configs = await Promise.all(promises);-- for (let j = 0; j < configs.length; j++) {- if (configs[j]) {- entries.push([keyNames[i + j], configs[j]!]);- }- }- }-- const elapsed = Date.now() - startTime;- logger.debug(- `[ServerConfigsCacheRedis] getAll(${this.namespace}): fetched ${entries.length} configs in ${elapsed}ms`,- );-- return fromPairs(entries);- }-}diff --git a/packages/api/src/mcp/registry/cache/ServerConfigsCacheRedisAggregateKey.ts b/packages/api/src/mcp/registry/cache/ServerConfigsCacheRedisAggregateKey.tsindex dce06afa71..c6b4f2838d 100644--- a/packages/api/src/mcp/registry/cache/ServerConfigsCacheRedisAggregateKey.ts+++ b/packages/api/src/mcp/registry/cache/ServerConfigsCacheRedisAggregateKey.ts@@ -8,8 +8,7 @@ import { BaseRegistryCache } from './BaseRegistryCache';/*** Redis-backed MCP server configs cache that stores all entries under a single aggregate key.*- * Unlike {@link ServerConfigsCacheRedis} which uses SCAN + batch-GET for `getAll()`, this- * implementation stores the entire config map as a single JSON value in Redis. This makes+ * This implementation stores the entire config map as a single JSON value in Redis. This makes* `getAll()` a single O(1) GET regardless of keyspace size, eliminating the 60s+ stalls* caused by SCAN under concurrent load in large deployments (see GitHub #11624, #12408).*diff --git a/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheFactory.test.ts b/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheFactory.test.tsindex 577b878cc7..bcb6c82228 100644--- a/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheFactory.test.ts+++ b/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheFactory.test.ts@@ -1,13 +1,11 @@import { ServerConfigsCacheFactory, APP_CACHE_NAMESPACE } from '../ServerConfigsCacheFactory';import { ServerConfigsCacheRedisAggregateKey } from '../ServerConfigsCacheRedisAggregateKey';import { ServerConfigsCacheInMemory } from '../ServerConfigsCacheInMemory';-import { ServerConfigsCacheRedis } from '../ServerConfigsCacheRedis';import { cacheConfig } from '~/cache';// Mock the cache implementationsjest.mock('../ServerConfigsCacheRedisAggregateKey');jest.mock('../ServerConfigsCacheInMemory');-jest.mock('../ServerConfigsCacheRedis');// Mock the cache config modulejest.mock('~/cache', () => ({@@ -30,7 +28,6 @@ describe('ServerConfigsCacheFactory', () => {expect(cache).toBeInstanceOf(ServerConfigsCacheRedisAggregateKey);expect(ServerConfigsCacheRedisAggregateKey).toHaveBeenCalledWith(APP_CACHE_NAMESPACE, false);- expect(ServerConfigsCacheRedis).not.toHaveBeenCalled();expect(ServerConfigsCacheInMemory).not.toHaveBeenCalled();});@@ -41,17 +38,6 @@ describe('ServerConfigsCacheFactory', () => {expect(cache).toBeInstanceOf(ServerConfigsCacheInMemory);expect(ServerConfigsCacheInMemory).toHaveBeenCalledWith();- expect(ServerConfigsCacheRedis).not.toHaveBeenCalled();- expect(ServerConfigsCacheRedisAggregateKey).not.toHaveBeenCalled();- });-- it('should return ServerConfigsCacheRedis for non-App namespaces when USE_REDIS is true', () => {- cacheConfig.USE_REDIS = true;-- const cache = ServerConfigsCacheFactory.create('CustomNamespace', true);-- expect(cache).toBeInstanceOf(ServerConfigsCacheRedis);- expect(ServerConfigsCacheRedis).toHaveBeenCalledWith('CustomNamespace', true);expect(ServerConfigsCacheRedisAggregateKey).not.toHaveBeenCalled();});diff --git a/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheRedis.cache_integration.spec.ts b/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheRedis.cache_integration.spec.tsdeleted file mode 100644index 5663150160..0000000000--- a/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheRedis.cache_integration.spec.ts+++ /dev/null@@ -1,415 +0,0 @@-import { expect } from '@playwright/test';-import type { RedisClientsModule } from '~/cache/__tests__/redisClients.helper';-import { closeRedisClients } from '~/cache/__tests__/redisClients.helper';-import { ParsedServerConfig } from '~/mcp/types';--type StdioServerConfig = Extract<ParsedServerConfig, { type: 'stdio' }>;--describe('ServerConfigsCacheRedis Integration Tests', () => {- let ServerConfigsCacheRedis: typeof import('../ServerConfigsCacheRedis').ServerConfigsCacheRedis;- let keyvRedisClient: Awaited<typeof import('~/cache/redisClients')>['keyvRedisClient'];- let redisClientsModule: RedisClientsModule;-- let cache: InstanceType<typeof import('../ServerConfigsCacheRedis').ServerConfigsCacheRedis>;-- const mockConfig1: StdioServerConfig = {- type: 'stdio',- command: 'node',- args: ['server1.js'],- env: { TEST: 'value1' },- };-- const mockConfig2: StdioServerConfig = {- type: 'stdio',- command: 'python',- args: ['server2.py'],- env: { TEST: 'value2' },- };-- const mockConfig3 = {- type: 'sse',- url: 'http://localhost:3000',- requiresOAuth: true,- } as ParsedServerConfig;-- beforeAll(async () => {- // Set up environment variables for Redis (only if not already set)- process.env.USE_REDIS = process.env.USE_REDIS ?? 'true';- process.env.USE_REDIS_CLUSTER = process.env.USE_REDIS_CLUSTER ?? 'true';- process.env.REDIS_URI =- process.env.REDIS_URI ??- 'redis://127.0.0.1:7001,redis://127.0.0.1:7002,redis://127.0.0.1:7003';- process.env.REDIS_KEY_PREFIX =- process.env.REDIS_KEY_PREFIX ?? 'ServerConfigsCacheRedis-IntegrationTest';-- // Import modules after setting env vars- const cacheModule = await import('../ServerConfigsCacheRedis');- const redisClients = await import('~/cache/redisClients');-- ServerConfigsCacheRedis = cacheModule.ServerConfigsCacheRedis;- keyvRedisClient = redisClients.keyvRedisClient;- redisClientsModule = redisClients;-- // Ensure Redis is connected- if (!keyvRedisClient) throw new Error('Redis client is not initialized');-- // Wait for connection and topology discovery to complete- await redisClients.keyvRedisClientReady;- });-- beforeEach(() => {- jest.resetModules();- cache = new ServerConfigsCacheRedis('test-user', false);- });-- afterEach(async () => {- // Clean up: clear all test keys from Redis- if (keyvRedisClient && 'scanIterator' in keyvRedisClient) {- const pattern = '*ServerConfigsCacheRedis-IntegrationTest*';- const keysToDelete: string[] = [];-- // Collect all keys first- for await (const page of keyvRedisClient.scanIterator({ MATCH: pattern })) {- keysToDelete.push(...page);- }-- // Delete in parallel for cluster mode efficiency- if (keysToDelete.length > 0) {- await Promise.all(keysToDelete.map((key) => keyvRedisClient!.del(key)));- }- }- });-- afterAll(async () => {- // Close both Redis clients; pass the captured module since- // `jest.resetModules()` in beforeEach dropped it from the registry- await closeRedisClients(redisClientsModule);- });-- describe('add and get operations', () => {- it('should add and retrieve a server config', async () => {- await cache.add('server1', mockConfig1);- const result = await cache.get('server1');- expect(result).toMatchObject(mockConfig1);- });-- it('should return undefined for non-existent server', async () => {- const result = await cache.get('non-existent');- expect(result).toBeUndefined();- });-- it('should throw error when adding duplicate server', async () => {- await cache.add('server1', mockConfig1);- await expect(cache.add('server1', mockConfig2)).rejects.toThrow(- 'Server "server1" already exists in cache. Use update() to modify existing configs.',- );- });-- it('should handle multiple server configs', async () => {- await cache.add('server1', mockConfig1);- await cache.add('server2', mockConfig2);- await cache.add('server3', mockConfig3);-- const result1 = await cache.get('server1');- const result2 = await cache.get('server2');- const result3 = await cache.get('server3');-- expect(result1).toMatchObject(mockConfig1);- expect(result2).toMatchObject(mockConfig2);- expect(result3).toMatchObject(mockConfig3);- });-- it('should isolate caches by owner namespace', async () => {- const userCache = new ServerConfigsCacheRedis('user1-private', false);- const globalCache = new ServerConfigsCacheRedis('global-shared', false);-- await userCache.add('server1', mockConfig1);- await globalCache.add('server1', mockConfig2);-- const userResult = await userCache.get('server1');- const globalResult = await globalCache.get('server1');-- expect(userResult).toMatchObject(mockConfig1);- expect(globalResult).toMatchObject(mockConfig2);- });- });-- describe('patch operation', () => {- it('preserves empty arrays in a patched per-key entry', async () => {- const emptyArgsConfig: StdioServerConfig = { ...mockConfig1, args: [] };- const { config } = await cache.add('empty-arrays', emptyArgsConfig);-- await expect(- cache.patch('empty-arrays', { resolvedInstructions: 'patched' }, config.updatedAt),- ).resolves.toBe(true);-- const result = await cache.get('empty-arrays');- expect(result).toMatchObject({ args: [] });- expect(result?.resolvedInstructions).toBe('patched');- });- });-- describe('getAll operation', () => {- it('should return empty object when no servers exist', async () => {- const result = await cache.getAll();- expect(result).toMatchObject({});- });-- it('should return all server configs', async () => {- await cache.add('server1', mockConfig1);- await cache.add('server2', mockConfig2);- await cache.add('server3', mockConfig3);-- const result = await cache.getAll();- expect(result).toMatchObject({- server1: mockConfig1,- server2: mockConfig2,- server3: mockConfig3,- });- });-- it('should reflect updates in getAll', async () => {- await cache.add('server1', mockConfig1);- await cache.add('server2', mockConfig2);-- let result = await cache.getAll();- expect(Object.keys(result).length).toBe(2);-- await cache.add('server3', mockConfig3);- result = await cache.getAll();- expect(Object.keys(result).length).toBe(3);- expect(result.server3).toMatchObject(mockConfig3);- });-- it('should only return configs for the specific owner', async () => {- const userCache = new ServerConfigsCacheRedis('user1-owner', false);- const globalCache = new ServerConfigsCacheRedis('global-owner', false);-- await userCache.add('server1', mockConfig1);- await userCache.add('server2', mockConfig2);- await globalCache.add('server3', mockConfig3);-- const userResult = await userCache.getAll();- const globalResult = await globalCache.getAll();-- expect(Object.keys(userResult).length).toBe(2);- expect(Object.keys(globalResult).length).toBe(1);- expect(userResult.server1).toMatchObject(mockConfig1);- expect(userResult.server3).toBeUndefined();- expect(globalResult.server3).toMatchObject(mockConfig3);- });- });-- describe('update operation', () => {- it('should update an existing server config', async () => {- await cache.add('server1', mockConfig1);- expect(await cache.get('server1')).toMatchObject(mockConfig1);-- await cache.update('server1', mockConfig2);- const result = await cache.get('server1');- expect(result).toMatchObject(mockConfig2);- });-- it('should throw error when updating non-existent server', async () => {- await expect(cache.update('non-existent', mockConfig1)).rejects.toThrow(- 'Server "non-existent" does not exist in cache. Use add() to create new configs.',- );- });-- it('should reflect updates in getAll', async () => {- await cache.add('server1', mockConfig1);- await cache.add('server2', mockConfig2);-- await cache.update('server1', mockConfig3);- const result = await cache.getAll();- expect(result.server1).toMatchObject(mockConfig3);- expect(result.server2).toMatchObject(mockConfig2);- });-- it('should only update in the specific owner namespace', async () => {- const userCache = new ServerConfigsCacheRedis('user1-update', false);- const globalCache = new ServerConfigsCacheRedis('global-update', false);-- await userCache.add('server1', mockConfig1);- await globalCache.add('server1', mockConfig2);-- await userCache.update('server1', mockConfig3);-- expect(await userCache.get('server1')).toMatchObject(mockConfig3);- expect(await globalCache.get('server1')).toMatchObject(mockConfig2);- });- });-- describe('remove operation', () => {- it('should remove an existing server config', async () => {- await cache.add('server1', mockConfig1);- expect(await cache.get('server1')).toMatchObject(mockConfig1);-- await cache.remove('server1');- expect(await cache.get('server1')).toBeUndefined();- });-- it('should throw error when removing non-existent server', async () => {- await expect(cache.remove('non-existent')).rejects.toThrow(- 'Failed to remove test-user server "non-existent"',- );- });-- it('should remove server from getAll results', async () => {- await cache.add('server1', mockConfig1);- await cache.add('server2', mockConfig2);-- let result = await cache.getAll();- expect(Object.keys(result).length).toBe(2);-- await cache.remove('server1');- result = await cache.getAll();- expect(Object.keys(result).length).toBe(1);- expect(result.server1).toBeUndefined();- expect(result.server2).toMatchObject(mockConfig2);- });-- it('should allow re-adding a removed server', async () => {- await cache.add('server1', mockConfig1);- await cache.remove('server1');- await cache.add('server1', mockConfig3);-- const result = await cache.get('server1');- expect(result).toMatchObject(mockConfig3);- });-- it('should only remove from the specific owner namespace', async () => {- const userCache = new ServerConfigsCacheRedis('user1-remove', false);- const globalCache = new ServerConfigsCacheRedis('global-remove', false);-- await userCache.add('server1', mockConfig1);- await globalCache.add('server1', mockConfig2);-- await userCache.remove('server1');-- expect(await userCache.get('server1')).toBeUndefined();- expect(await globalCache.get('server1')).toMatchObject(mockConfig2);- });- });-- describe('getAll parallel fetching', () => {- it('should handle many configs efficiently with parallel fetching', async () => {- const testCache = new ServerConfigsCacheRedis('parallel-test', false);- const configCount = 20;-- for (let i = 0; i < configCount; i++) {- await testCache.add(`server-${i}`, {- type: 'stdio',- command: `cmd-${i}`,- args: [`arg-${i}`],- } as ParsedServerConfig);- }-- const startTime = Date.now();- const result = await testCache.getAll();- const elapsed = Date.now() - startTime;-- expect(Object.keys(result).length).toBe(configCount);- for (let i = 0; i < configCount; i++) {- expect(result[`server-${i}`]).toBeDefined();- const config = result[`server-${i}`] as { command?: string };- expect(config.command).toBe(`cmd-${i}`);- }-- expect(elapsed).toBeLessThan(5000);- });-- it('should handle concurrent getAll calls without timeout', async () => {- const testCache = new ServerConfigsCacheRedis('concurrent-test', false);-- for (let i = 0; i < 10; i++) {- await testCache.add(`server-${i}`, {- type: 'stdio',- command: `cmd-${i}`,- args: [`arg-${i}`],- } as ParsedServerConfig);- }-- const concurrentCalls = 50;- const startTime = Date.now();- const promises = Array.from({ length: concurrentCalls }, () => testCache.getAll());-- const results = await Promise.all(promises);- const elapsed = Date.now() - startTime;-- for (const result of results) {- expect(Object.keys(result).length).toBe(10);- }-- expect(elapsed).toBeLessThan(10000);- });-- it('should return consistent results across concurrent calls', async () => {- const testCache = new ServerConfigsCacheRedis('consistency-test', false);-- await testCache.add('server-a', mockConfig1);- await testCache.add('server-b', mockConfig2);- await testCache.add('server-c', mockConfig3);-- const results = await Promise.all([- testCache.getAll(),- testCache.getAll(),- testCache.getAll(),- testCache.getAll(),- testCache.getAll(),- ]);-- const firstResult = results[0];- for (const result of results) {- expect(Object.keys(result).sort()).toEqual(Object.keys(firstResult).sort());- expect(result['server-a']).toMatchObject(mockConfig1);- expect(result['server-b']).toMatchObject(mockConfig2);- expect(result['server-c']).toMatchObject(mockConfig3);- }- });-- /**- * Performance regression test for N+1 Redis fix.- *- * Before fix: getAll() used sequential GET calls inside an async loop:- * for await (key of scan) { await cache.get(key); } // N sequential calls- *- * With 30 configs and 100 concurrent requests, this would cause:- * - 100 × 30 = 3000 sequential Redis roundtrips- * - Under load, requests would queue and timeout at 60s- *- * After fix: getAll() uses Promise.all for parallel fetching:- * Promise.all(keys.map(k => cache.get(k))); // N parallel calls- *- * This test validates the fix by ensuring 100 concurrent requests- * complete in under 5 seconds - impossible with the old N+1 pattern.- */- it('should complete 100 concurrent requests in under 5s (regression test for N+1 fix)', async () => {- const testCache = new ServerConfigsCacheRedis('perf-regression-test', false);- const configCount = 30;-- for (let i = 0; i < configCount; i++) {- await testCache.add(`server-${i}`, {- type: 'stdio',- command: `cmd-${i}`,- args: [`arg-${i}`],- } as ParsedServerConfig);- }-- const concurrentRequests = 100;- const maxAllowedMs = 5000;-- const startTime = Date.now();- const promises = Array.from({ length: concurrentRequests }, () => testCache.getAll());- const results = await Promise.all(promises);- const elapsed = Date.now() - startTime;-- expect(results.length).toBe(concurrentRequests);- for (const result of results) {- expect(Object.keys(result).length).toBe(configCount);- }-- expect(elapsed).toBeLessThan(maxAllowedMs);- });- });-});diff --git a/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheRedis.perf_benchmark.manual.spec.ts b/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheRedis.perf_benchmark.manual.spec.tsdeleted file mode 100644index a0b6b0043d..0000000000--- a/packages/api/src/mcp/registry/cache/__tests__/ServerConfigsCacheRedis.perf_benchmark.manual.spec.ts+++ /dev/null@@ -1,344 +0,0 @@-/**- * Performance benchmark for ServerConfigsCacheRedis.getAll()- *- * Requires a live Redis instance. Run manually (excluded from CI):- * npx jest --config packages/api/jest.config.mjs --testPathPatterns="perf_benchmark" --coverage=false- *- * Set env vars as needed:- * USE_REDIS=true REDIS_URI=redis://localhost:6379 npx jest ...- *- * This benchmark isolates the two phases of getAll() — SCAN (key discovery) and- * batched GET (value retrieval) — to identify the actual bottleneck under load.- * It also benchmarks alternative approaches (single aggregate key, MGET) against- * the current SCAN+GET implementation.- */-import { expect } from '@playwright/test';-import type { RedisClientType } from '@redis/client';-import type { ParsedServerConfig } from '~/mcp/types';--describe('ServerConfigsCacheRedis Performance Benchmark', () => {- let ServerConfigsCacheRedis: typeof import('../ServerConfigsCacheRedis').ServerConfigsCacheRedis;- let keyvRedisClient: Awaited<typeof import('~/cache/redisClients')>['keyvRedisClient'];- let standardCache: Awaited<typeof import('~/cache')>['standardCache'];-- const PREFIX = 'perf-bench';-- const makeConfig = (i: number): ParsedServerConfig =>- ({- type: 'stdio',- command: `cmd-${i}`,- args: [`arg-${i}`, `--flag-${i}`],- env: { KEY: `value-${i}`, EXTRA: `extra-${i}` },- requiresOAuth: false,- tools: `tool_a_${i}, tool_b_${i}`,- capabilities: `{"tools":{"listChanged":true}}`,- serverInstructions: `Instructions for server ${i}`,- }) as ParsedServerConfig;-- beforeAll(async () => {- process.env.USE_REDIS = process.env.USE_REDIS ?? 'true';- process.env.USE_REDIS_CLUSTER = process.env.USE_REDIS_CLUSTER ?? 'true';- process.env.REDIS_URI =- process.env.REDIS_URI ??- 'redis://127.0.0.1:7001,redis://127.0.0.1:7002,redis://127.0.0.1:7003';- process.env.REDIS_KEY_PREFIX = process.env.REDIS_KEY_PREFIX ?? 'perf-bench-test';-- const cacheModule = await import('../ServerConfigsCacheRedis');- const redisClients = await import('~/cache/redisClients');- const cacheFactory = await import('~/cache');-- ServerConfigsCacheRedis = cacheModule.ServerConfigsCacheRedis;- keyvRedisClient = redisClients.keyvRedisClient;- standardCache = cacheFactory.standardCache;-- if (!keyvRedisClient) throw new Error('Redis client is not initialized');- await redisClients.keyvRedisClientReady;- });-- afterAll(async () => {- if (keyvRedisClient?.isOpen) await keyvRedisClient.disconnect();- });-- /** Clean up all keys matching our test prefix */- async function cleanupKeys(pattern: string): Promise<void> {- if (!keyvRedisClient || !('scanIterator' in keyvRedisClient)) return;- const keys: string[] = [];- for await (const page of keyvRedisClient.scanIterator({ MATCH: pattern })) {- keys.push(...page);- }- if (keys.length > 0) {- await Promise.all(keys.map((key) => keyvRedisClient!.del(key)));- }- }-- /** Populate a cache with N configs and return the cache instance */- async function populateCache(- namespace: string,- count: number,- ): Promise<InstanceType<typeof ServerConfigsCacheRedis>> {- const cache = new ServerConfigsCacheRedis(namespace, false);- for (let i = 0; i < count; i++) {- await cache.add(`server-${i}`, makeConfig(i));- }- return cache;- }-- /**- * Benchmark 1: Isolate SCAN vs GET phases in current getAll()- *- * Measures time spent in each phase separately to identify the bottleneck.- */- describe('Phase isolation: SCAN vs batched GET', () => {- const CONFIG_COUNTS = [5, 20, 50];-- for (const count of CONFIG_COUNTS) {- it(`should measure SCAN and GET phases separately for ${count} configs`, async () => {- const ns = `${PREFIX}-phase-${count}`;- const cache = await populateCache(ns, count);-- try {- // Get the Keyv cache instance namespace for pattern matching- const keyvCache = standardCache(`MCP::ServersRegistry::Servers::${ns}`);- const pattern = `*MCP::ServersRegistry::Servers::${ns}:*`;-- // Phase 1: SCAN only (key discovery)- const scanStart = Date.now();- const keys: string[] = [];- for await (const page of (keyvRedisClient as RedisClientType).scanIterator({- MATCH: pattern,- })) {- keys.push(...page);- }- const scanMs = Date.now() - scanStart;-- // Phase 2: Batched GET only (value retrieval via Keyv)- const keyNames = keys.map((key) => key.substring(key.lastIndexOf(':') + 1));- const BATCH_SIZE = 100;- const getStart = Date.now();- for (let i = 0; i < keyNames.length; i += BATCH_SIZE) {- const batch = keyNames.slice(i, i + BATCH_SIZE);- await Promise.all(batch.map((k) => keyvCache.get(k)));- }- const getMs = Date.now() - getStart;-- // Phase 3: Full getAll() (both phases combined)- const fullStart = Date.now();- const result = await cache.getAll();- const fullMs = Date.now() - fullStart;-- console.log(- `[${count} configs] SCAN: ${scanMs}ms | GET: ${getMs}ms | Full getAll: ${fullMs}ms | Keys found: ${keys.length}`,- );-- expect(Object.keys(result).length).toBe(count);-- // Clean up the Keyv instance- await keyvCache.clear();- } finally {- await cleanupKeys(`*${ns}*`);- }- });- }- });-- /**- * Benchmark 2: SCAN cost scales with total Redis keyspace, not just matching keys- *- * Redis SCAN iterates the entire hash table and filters by pattern. With a large- * keyspace (many non-matching keys), SCAN takes longer even if few keys match.- * This test measures SCAN time with background noise keys.- */- describe('SCAN cost vs keyspace size', () => {- it('should measure SCAN latency with background noise keys', async () => {- const ns = `${PREFIX}-noise`;- const targetCount = 10;-- // Add target configs- const cache = await populateCache(ns, targetCount);-- // Add noise keys in a different namespace to inflate the keyspace- const noiseCount = 500;- const noiseCache = standardCache(`noise-namespace-${Date.now()}`);- for (let i = 0; i < noiseCount; i++) {- await noiseCache.set(`noise-${i}`, { data: `value-${i}` });- }-- try {- const pattern = `*MCP::ServersRegistry::Servers::${ns}:*`;-- // Measure SCAN with noise- const scanStart = Date.now();- const keys: string[] = [];- for await (const page of (keyvRedisClient as RedisClientType).scanIterator({- MATCH: pattern,- })) {- keys.push(...page);- }- const scanMs = Date.now() - scanStart;-- // Measure full getAll- const fullStart = Date.now();- const result = await cache.getAll();- const fullMs = Date.now() - fullStart;-- console.log(- `[${targetCount} configs + ${noiseCount} noise keys] SCAN: ${scanMs}ms | Full getAll: ${fullMs}ms`,- );-- expect(Object.keys(result).length).toBe(targetCount);- } finally {- await noiseCache.clear();- await cleanupKeys(`*${ns}*`);- }- });- });-- /**- * Benchmark 3: Concurrent getAll() calls (simulates the actual production bottleneck)- *- * Multiple users hitting /api/mcp/* simultaneously, all triggering getAll()- * after the 5s TTL read-through cache expires.- */- describe('Concurrent getAll() under load', () => {- const CONCURRENCY_LEVELS = [1, 10, 50, 100];- const CONFIG_COUNT = 30;-- for (const concurrency of CONCURRENCY_LEVELS) {- it(`should measure ${concurrency} concurrent getAll() calls with ${CONFIG_COUNT} configs`, async () => {- const ns = `${PREFIX}-concurrent-${concurrency}`;- const cache = await populateCache(ns, CONFIG_COUNT);-- try {- const startTime = Date.now();- const promises = Array.from({ length: concurrency }, () => cache.getAll());- const results = await Promise.all(promises);- const elapsed = Date.now() - startTime;-- console.log(- `[${CONFIG_COUNT} configs x ${concurrency} concurrent] Total: ${elapsed}ms | Per-call avg: ${(elapsed / concurrency).toFixed(1)}ms`,- );-- for (const result of results) {- expect(Object.keys(result).length).toBe(CONFIG_COUNT);- }- } finally {- await cleanupKeys(`*${ns}*`);- }- });- }- });-- /**- * Benchmark 4: Alternative — Single aggregate key- *- * Instead of SCAN+GET, store all configs under one Redis key.- * getAll() becomes a single GET + JSON parse.- */- describe('Alternative: Single aggregate key', () => {- it('should compare aggregate key vs SCAN+GET for getAll()', async () => {- const ns = `${PREFIX}-aggregate`;- const configCount = 30;- const cache = await populateCache(ns, configCount);-- // Build the aggregate object- const aggregate: Record<string, ParsedServerConfig> = {};- for (let i = 0; i < configCount; i++) {- aggregate[`server-${i}`] = makeConfig(i);- }-- // Store as single key- const aggregateCache = standardCache(`aggregate-test-${Date.now()}`);- await aggregateCache.set('all', aggregate);-- try {- // Measure SCAN+GET approach- const scanStart = Date.now();- const scanResult = await cache.getAll();- const scanMs = Date.now() - scanStart;-- // Measure single-key approach- const aggStart = Date.now();- const aggResult = (await aggregateCache.get('all')) as Record<string, ParsedServerConfig>;- const aggMs = Date.now() - aggStart;-- console.log(- `[${configCount} configs] SCAN+GET: ${scanMs}ms | Single key: ${aggMs}ms | Speedup: ${(scanMs / Math.max(aggMs, 1)).toFixed(1)}x`,- );-- expect(Object.keys(scanResult).length).toBe(configCount);- expect(Object.keys(aggResult).length).toBe(configCount);-- // Concurrent comparison- const concurrency = 100;- const scanConcStart = Date.now();- await Promise.all(Array.from({ length: concurrency }, () => cache.getAll()));- const scanConcMs = Date.now() - scanConcStart;-- const aggConcStart = Date.now();- await Promise.all(Array.from({ length: concurrency }, () => aggregateCache.get('all')));- const aggConcMs = Date.now() - aggConcStart;-- console.log(- `[${configCount} configs x ${concurrency} concurrent] SCAN+GET: ${scanConcMs}ms | Single key: ${aggConcMs}ms | Speedup: ${(scanConcMs / Math.max(aggConcMs, 1)).toFixed(1)}x`,- );- } finally {- await aggregateCache.clear();- await cleanupKeys(`*${ns}*`);- }- });- });-- /**- * Benchmark 5: Alternative — Raw MGET (bypassing Keyv serialization overhead)- *- * Keyv wraps each value in { value, expires } JSON. Using raw MGET on the- * Redis client skips the Keyv layer entirely.- */- describe('Alternative: Raw MGET vs Keyv batch GET', () => {- it('should compare raw MGET vs Keyv GET for value retrieval', async () => {- const ns = `${PREFIX}-mget`;- const configCount = 30;- await populateCache(ns, configCount);-- try {- // First, discover keys via SCAN (same for both approaches)- const pattern = `*MCP::ServersRegistry::Servers::${ns}:*`;- const keys: string[] = [];- for await (const page of (keyvRedisClient as RedisClientType).scanIterator({- MATCH: pattern,- })) {- keys.push(...page);- }- expect(keys.length).toBeGreaterThan(0);-- // Approach 1: Keyv batch GET (current implementation)- const keyvCache = standardCache(`MCP::ServersRegistry::Servers::${ns}`);- const keyNames = keys.map((key) => key.substring(key.lastIndexOf(':') + 1));-- const keyvStart = Date.now();- await Promise.all(keyNames.map((k) => keyvCache.get(k)));- const keyvMs = Date.now() - keyvStart;-- // Approach 2: Raw MGET (no Keyv overhead)- const mgetStart = Date.now();- if ('mGet' in keyvRedisClient!) {- const rawValues = await (- keyvRedisClient as { mGet: (keys: string[]) => Promise<(string | null)[]> }- ).mGet(keys);- // Parse the Keyv-wrapped JSON values- rawValues.filter(Boolean).map((v) => JSON.parse(v!));- }- const mgetMs = Date.now() - mgetStart;-- console.log(- `[${configCount} configs] Keyv batch GET: ${keyvMs}ms | Raw MGET: ${mgetMs}ms | Speedup: ${(keyvMs / Math.max(mgetMs, 1)).toFixed(1)}x`,- );-- // Clean up- await keyvCache.clear();- } finally {- await cleanupKeys(`*${ns}*`);- }- });- });-});diff --git a/packages/api/src/mcp/toolsChanged.spec.ts b/packages/api/src/mcp/toolsChanged.spec.tsindex 5c7cefd9ad..60d9f2f5c7 100644--- a/packages/api/src/mcp/toolsChanged.spec.ts+++ b/packages/api/src/mcp/toolsChanged.spec.ts@@ -8,7 +8,6 @@ import {getMCPToolsChangedGeneration,renewMCPToolsChangedGeneration,reserveMCPToolsChangedRevision,- hasMCPToolsChangedHandler,cancelMCPToolsChanged,notifyMCPToolsChanged,getMCPAppToolsPublicationGeneration,@@ -30,14 +29,6 @@ describe('MCP tools-changed dispatch', () => {jest.useRealTimers();});- it('reports whether a handler is registered', () => {- expect(hasMCPToolsChangedHandler()).toBe(false);- setMCPToolsChangedHandler(jest.fn());- expect(hasMCPToolsChangedHandler()).toBe(true);- setMCPToolsChangedHandler(null);- expect(hasMCPToolsChangedHandler()).toBe(false);- });-it('derives stable app publication generations from connection-relevant config', () => {const first: ParsedServerConfig = {type: 'sse',diff --git a/packages/api/src/mcp/toolsChanged.ts b/packages/api/src/mcp/toolsChanged.tsindex 3f55072d2e..537500efa7 100644--- a/packages/api/src/mcp/toolsChanged.ts+++ b/packages/api/src/mcp/toolsChanged.ts@@ -196,10 +196,6 @@ export function setMCPToolsChangedHandler(fn: MCPToolsChangedHandler | null): vo}}-export function hasMCPToolsChangedHandler(): boolean {- return handler != null;-}-/** Registers the app-layer provider for connection-bound publication generations. */export function setMCPToolsChangedGenerationHandler(fn: MCPToolsChangedGenerationHandler | null,diff --git a/packages/api/src/mcp/types/index.ts b/packages/api/src/mcp/types/index.tsindex 9fab61eeee..4a7f679544 100644--- a/packages/api/src/mcp/types/index.ts+++ b/packages/api/src/mcp/types/index.ts@@ -10,19 +10,13 @@ import {} from 'librechat-data-provider';import type {EmbeddedResource,- ListToolsResult,ResourceLink,ImageContent,AudioContent,TextContent,Tool,} from '@modelcontextprotocol/sdk/types.js';-import type {- SearchResultData,- UIResource,- TPlugin,- TMCPAppOperationLimits,-} from 'librechat-data-provider';+import type { SearchResultData, UIResource, TMCPAppOperationLimits } from 'librechat-data-provider';import type { TokenMethods, IUser } from '@librechat/data-schemas';import type { LCTool } from '@librechat/agents';import type {@@ -70,8 +64,6 @@ export interface LCFunctionTool {}export type LCAvailableTools = Record<string, LCFunctionTool>;-export type LCManifestTool = TPlugin;-export type LCToolManifest = TPlugin[];export interface MCPPrompt {name: string;description?: string;@@ -83,7 +75,6 @@ export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'errexport type OAuthHandledSource = 'silent-refresh' | 'interactive';export type MCPTool = Tool;-export type MCPToolListResponse = ListToolsResult;export type ToolContentPart =| TextContent| ImageContentdiff --git a/packages/api/src/mcp/utils.ts b/packages/api/src/mcp/utils.tsindex 5396dbcc94..18e7a326e2 100644--- a/packages/api/src/mcp/utils.ts+++ b/packages/api/src/mcp/utils.ts@@ -469,12 +469,6 @@ export function toCatalogConnectionConfig<T extends MCPOptions>(config: T): T {return catalogConfig;}-export function getRuntimeBodyPlaceholderFields(- config: UserScopedConnectionConfig,-): Array<keyof RequestBody> {- return getMCPRequestScope(config).requiredBodyFields;-}-export function getMissingRuntimeBodyPlaceholderFields(config: UserScopedConnectionConfig,requestBody?: RequestBody,diff --git a/packages/api/src/middleware/concurrency.ts b/packages/api/src/middleware/concurrency.tsindex 6183390502..ad745a827a 100644--- a/packages/api/src/middleware/concurrency.ts+++ b/packages/api/src/middleware/concurrency.ts@@ -240,10 +240,3 @@ export function getViolationInfo(pendingRequests: number, limit: number): Violatscore: CONCURRENT_VIOLATION_SCORE,};}--/**- * Check if concurrent message limiting is enabled.- */-export function isConcurrentLimitEnabled(): boolean {- return isEnabled(LIMIT_CONCURRENT_MESSAGES);-}diff --git a/packages/api/src/middleware/messageFilterPii.spec.ts b/packages/api/src/middleware/messageFilterPii.spec.tsindex 331a29cee4..b56bd3e07e 100644--- a/packages/api/src/middleware/messageFilterPii.spec.ts+++ b/packages/api/src/middleware/messageFilterPii.spec.ts@@ -5,11 +5,7 @@ import type { Request, Response, NextFunction } from 'express';jest.mock('@librechat/data-schemas', () => ({logger: { warn: jest.fn(), error: jest.fn(), info: jest.fn(), debug: jest.fn() },}));-import {- createMessageFilterPii,- findPiiMatchInMessages,- configureMessageFilterRegexValidator,-} from './messageFilterPii';+import { createMessageFilterPii, configureMessageFilterRegexValidator } from './messageFilterPii';type CapturedResponse = { status?: number; body?: unknown };@@ -741,87 +737,6 @@ describe('messageFilterPii middleware', () => {expect(capturedRes.status).toBe(400);expect(capturedRes.body).toMatchObject({ error: 'message_filter_pii_block' });});-- it('findPiiMatchInMessages flags misconfigured on a dropped pattern under default starters', () => {- const config: MessageFilterPiiConfig = {- customPatterns: [{ id: 'dup', label: 'Duplicate', regex: '(a)\\1' }],- };- const hit = findPiiMatchInMessages([{ role: 'user', content: 'aa' }], config);- expect(hit?.misconfigured).toBe(true);- });-});--describe('findPiiMatchInMessages', () => {- it('returns null for missing or empty messages', () => {- expect(findPiiMatchInMessages(undefined, {})).toBeNull();- expect(findPiiMatchInMessages([], {})).toBeNull();- });-- it('returns null when no config is provided', () => {- expect(- findPiiMatchInMessages([{ role: 'user', content: 'sk-proj-FAKE123' }], undefined),- ).toBeNull();- });-- it('matches a system-role message (remote APIs accept caller-supplied system roles)', () => {- const hit = findPiiMatchInMessages(- [{ role: 'system', content: 'system primer with sk-proj-FAKE1234567890ABCDEF embedded' }],- {},- );- expect(hit).toEqual({ id: 'sk_prefix', label: 'sk- prefix token' });- });-- it('matches an assistant-role message (callers can include attacker-controlled history)', () => {- const hit = findPiiMatchInMessages(- [{ role: 'assistant', content: 'sk-proj-FAKE1234567890ABCDEF' }],- {},- );- expect(hit).toEqual({ id: 'sk_prefix', label: 'sk- prefix token' });- });-- it('matches a tool-role message', () => {- const hit = findPiiMatchInMessages(- [{ role: 'tool', content: 'tool reply leaking sk-proj-FAKE1234567890ABCDEF' }],- {},- );- expect(hit).toEqual({ id: 'sk_prefix', label: 'sk- prefix token' });- });-- it('matches a string-content user message', () => {- const hit = findPiiMatchInMessages(- [{ role: 'user', content: 'my key is sk-proj-FAKE1234567890ABCDEF' }],- {},- );- expect(hit).toEqual({ id: 'sk_prefix', label: 'sk- prefix token' });- });-- it('matches a content-parts user message (text part)', () => {- const hit = findPiiMatchInMessages(- [- {- role: 'user',- content: [- { type: 'image_url', image_url: { url: 'data:...' } },- { type: 'text', text: 'Authorization: Bearer abc.def.ghi' },- ],- },- ],- {},- );- expect(hit).toEqual({ id: 'bearer_header', label: 'Bearer token' });- });-- it('returns null when no user message matches', () => {- expect(findPiiMatchInMessages([{ role: 'user', content: 'hello world' }], {})).toBeNull();- });-- it('honors customPatterns from config', () => {- const hit = findPiiMatchInMessages([{ role: 'user', content: 'token ORG-DEADBEEF here' }], {- starterPatterns: [],- customPatterns: [{ id: 'org', label: 'Org token', regex: '\\bORG-[A-Z0-9]{6,}' }],- });- expect(hit).toEqual({ id: 'org', label: 'Org token' });- });});describe('configureMessageFilterRegexValidator (RE2 config-load validation)', () => {@@ -890,12 +805,4 @@ describe('configureMessageFilterRegexValidator (RE2 config-load validation)', ()expect(capturedRes.status).toBe(400);expect(capturedRes.body).toMatchObject({ error: 'message_filter_pii_block' });});-- it('findPiiMatchInMessages returns a misconfigured match when every pattern fails to compile', () => {- const hit = findPiiMatchInMessages([{ role: 'user', content: 'hello' }], {- starterPatterns: [],- customPatterns: [{ id: 'backref', label: 'Backref', regex: '(a)\\1' }],- });- expect(hit?.misconfigured).toBe(true);- });});diff --git a/packages/api/src/middleware/messageFilterPii.ts b/packages/api/src/middleware/messageFilterPii.tsindex 4d2626e0da..6e197ee873 100644--- a/packages/api/src/middleware/messageFilterPii.ts+++ b/packages/api/src/middleware/messageFilterPii.ts@@ -40,7 +40,6 @@ import {extractFileContent,extractStoredMessageContent,} from '../protection/adapters/submissions';-import { createLegacyPiiInspector, toLegacyPiiMatch } from '../protection/legacy';import { extractMessageContent } from '../protection/adapters/messages';import { extractChatContent } from '../protection/adapters/chat';import { contentFilterBlockResponse } from './contentFilter';@@ -114,34 +113,6 @@ function isLegacyPiiConfigValid(config: MessageFilterPiiConfig): boolean {return valid;}-export interface PiiMatch {- id: string;- label: string;- /** Set when a configured custom pattern cannot be enforced by the runtime engine. */- misconfigured?: boolean;-}--type ContentPart = { type?: string; text?: string; [key: string]: unknown };-type ChatLikeMessage = {- role?: string;- content?: string | ContentPart[];-};--export function findPiiMatchInMessages(- messages: ChatLikeMessage[] | undefined,- config: MessageFilterPiiConfig | undefined,-): PiiMatch | null {- if (config == null || !Array.isArray(messages) || messages.length === 0) {- return null;- }- if (!isLegacyPiiConfigValid(config)) {- return { id: '__misconfigured__', label: 'restricted value', misconfigured: true };- }- const inspector = createLegacyPiiInspector(config);- const fragments = extractMessageContent(messages);- return toLegacyPiiMatch(inspector?.inspect(fragments) ?? null);-}-export interface CreateMessageFilterPiiOptions {readonly onTraversalFailure?: LocatorTraversalReporter;getConfig: (req: ServerRequest) => MessageFilterPiiConfig | undefined;diff --git a/packages/api/src/middleware/modelBoundContent.spec.ts b/packages/api/src/middleware/modelBoundContent.spec.tsindex 17388cc3a0..67f0b3f523 100644--- a/packages/api/src/middleware/modelBoundContent.spec.ts+++ b/packages/api/src/middleware/modelBoundContent.spec.ts@@ -5,7 +5,6 @@ import {assertModelBoundContent,assertModelBoundProviderContent,collectModelBoundHistoricalFileIdState,- collectModelBoundHistoricalFileIds,createModelBoundChatModelCallback,createInitialModelBoundAdmissionCallback,hasModelBoundContentProtection,@@ -2566,7 +2565,7 @@ describe('assertModelBoundProviderContent', () => {it('collects every provider-supported historical file locator', () => {expect(- collectModelBoundHistoricalFileIds([+ collectModelBoundHistoricalFileIdState([{files: [{ file_id: 'top-file' }],attachments: [{ file_id: 'display-file' }],@@ -2578,7 +2577,7 @@ describe('assertModelBoundProviderContent', () => {{ type: 'input_file', files: [{ file_id: 'part-file' }] },],},- ]),+ ]).fileIds,).toEqual(['top-file','display-file',diff --git a/packages/api/src/prompts/protection.ts b/packages/api/src/prompts/protection.tsindex 5489da5e64..6df04e7eeb 100644--- a/packages/api/src/prompts/protection.ts+++ b/packages/api/src/prompts/protection.ts@@ -113,17 +113,6 @@ function projectStoredPromptWithPolicy<T extends PromptRecordInput>(};}-/** Reapplies current prompt policy while retaining structural management fields. */-export function projectStoredPrompt<T extends PromptRecordInput>(- prompt: T,- filters?: FiltersConfig,-): ProjectedStoredPrompt<T> {- if (filters == null || !hasPromptPolicy(filters)) {- return prompt;- }- return projectStoredPromptWithPolicy(prompt, filters);-}-/** Projects stored prompts in one pass under the current prompt policy. */export function projectStoredPrompts<T extends PromptRecordInput>(prompts: readonly T[],@@ -241,22 +230,6 @@ function projectStoredPresetWithPolicy<T extends PresetContentInput>(};}-/** Reapplies prompt and model-parameter policy to stored presets. */-export function projectStoredPreset<T extends PresetContentInput>(- preset: T,- filters?: FiltersConfig,-): ProjectedStoredPreset<T> {- if (filters == null) {- return preset;- }- const inspectPrompt = hasPromptPolicy(filters);- const inspectModelParameters = hasModelParameterPolicy(filters);- if (!inspectPrompt && !inspectModelParameters) {- return preset;- }- return projectStoredPresetWithPolicy(preset, filters, inspectPrompt, inspectModelParameters);-}-/** Projects stored presets in one pass under the current prompt/model policy. */export function projectStoredPresets<T extends PresetContentInput>(presets: readonly T[],diff --git a/packages/api/src/prompts/schemas.spec.ts b/packages/api/src/prompts/schemas.spec.tsindex f4de5af111..e9a4c2ef4e 100644--- a/packages/api/src/prompts/schemas.spec.ts+++ b/packages/api/src/prompts/schemas.spec.ts@@ -1,6 +1,5 @@import {updatePromptGroupSchema,- validatePromptGroupUpdate,safeValidatePromptPayload,safeValidatePromptGroupUpdate,} from './schemas';@@ -202,18 +201,6 @@ describe('updatePromptGroupSchema', () => {});});-describe('validatePromptGroupUpdate', () => {- it('should return validated data for valid input', () => {- const input = { name: 'Test', category: 'testing' };- const result = validatePromptGroupUpdate(input);- expect(result).toEqual(input);- });-- it('should throw ZodError for invalid input', () => {- expect(() => validatePromptGroupUpdate({ author: 'malicious-id' })).toThrow();- });-});-describe('safeValidatePromptGroupUpdate', () => {it('should return success true for valid input', () => {const result = safeValidatePromptGroupUpdate({ name: 'Test' });diff --git a/packages/api/src/prompts/schemas.ts b/packages/api/src/prompts/schemas.tsindex 508a4d2dd3..2c2940823a 100644--- a/packages/api/src/prompts/schemas.ts+++ b/packages/api/src/prompts/schemas.ts@@ -65,17 +65,6 @@ export const updatePromptGroupSchema: z.ZodObject<export type TUpdatePromptGroupSchema = z.infer<typeof updatePromptGroupSchema>;-/**- * Validates and sanitizes a prompt group update payload.- * Returns only the allowed fields, stripping any sensitive fields.- * @param data - The raw request body to validate- * @returns The validated and sanitized payload- * @throws ZodError if validation fails- */-export function validatePromptGroupUpdate(data: unknown): TUpdatePromptGroupSchema {- return updatePromptGroupSchema.parse(data);-}-/*** Safely validates a prompt group update payload without throwing.* @param data - The raw request body to validatediff --git a/packages/api/src/protection/detectors/pattern.ts b/packages/api/src/protection/detectors/pattern.tsindex f6c9cdb040..0135a21096 100644--- a/packages/api/src/protection/detectors/pattern.ts+++ b/packages/api/src/protection/detectors/pattern.ts@@ -51,10 +51,6 @@ export class PatternConfigurationError extends Error {}}-export function isPatternConfigurationError(error: unknown): error is PatternConfigurationError {- return error instanceof PatternConfigurationError;-}-export interface PatternContentInspectorResourceCost {readonly customPatterns: number;readonly validCustomPatterns: number;@@ -362,12 +358,6 @@ export function getPatternContentInspectorPreflightCost(};}-export function getPatternContentInspectorResourceCost(- config: PatternContentInspectorConfig | MessageFilterPiiConfig,-): PatternContentInspectorResourceCost {- return prepareConfig(config).cost;-}-function findingFor(pattern: Pick<CompiledPattern, 'id' | 'label'>,fragment: TextContentFragment,diff --git a/packages/api/src/protection/files.spec.ts b/packages/api/src/protection/files.spec.tsindex 8f8355d435..3957a1a6ac 100644--- a/packages/api/src/protection/files.spec.ts+++ b/packages/api/src/protection/files.spec.ts@@ -2,9 +2,7 @@ import { EToolResources, mergeFileConfig } from 'librechat-data-provider';import type { FiltersConfig } from 'librechat-data-provider';import {canInspectUploadExtractedTextAfterProcessing,- canInspectUploadTranscriptAfterProcessing,getBlockedUploadTranscriptField,- isFileFilterFieldEnabled,contentFilterUninspectableResponse,getBlockedOpaqueFileField,getBlockedUninspectableFileField,@@ -153,49 +151,6 @@ describe('file content inspection policy', () => {).toBe(true);});- it('defers transcript fail-close only to STT-supported non-assistant context uploads', () => {- expect(- canInspectUploadTranscriptAfterProcessing({- endpoint: 'agents',- toolResource: EToolResources.context,- mimeType: 'audio/webm',- sttSupported: true,- }),- ).toBe(true);- expect(- canInspectUploadTranscriptAfterProcessing({- endpoint: 'assistants',- toolResource: EToolResources.context,- mimeType: 'audio/webm',- sttSupported: true,- }),- ).toBe(false);- expect(- canInspectUploadTranscriptAfterProcessing({- endpoint: 'agents',- toolResource: EToolResources.file_search,- mimeType: 'audio/webm',- sttSupported: true,- }),- ).toBe(false);- expect(- canInspectUploadTranscriptAfterProcessing({- endpoint: 'agents',- toolResource: EToolResources.context,- mimeType: 'audio/webm',- sttSupported: false,- }),- ).toBe(false);- expect(- canInspectUploadTranscriptAfterProcessing({- endpoint: 'agents',- toolResource: EToolResources.context,- mimeType: 'text/plain',- sttSupported: true,- }),- ).toBe(false);- });-it('treats a text-delivery audio file as carrying its own transcript', () => {const coverage = getCanonicalFileInspectionCoverage({type: 'audio/mpeg',@@ -371,7 +326,6 @@ describe('file content inspection policy', () => {files: { pii: { uninspectable: 'block' } },} as FiltersConfig;- expect(isFileFilterFieldEnabled(filters, 'content')).toBe(true);expect(getBlockedUninspectableFileField(filters, ['content', 'extracted_text'])).toBe('content',);@@ -387,8 +341,6 @@ describe('file content inspection policy', () => {},} as FiltersConfig;- expect(isFileFilterFieldEnabled(filters, 'name')).toBe(true);- expect(isFileFilterFieldEnabled(filters, 'content')).toBe(false);expect(getBlockedUninspectableFileField(filters, ['content', 'transcript'])).toBeNull();expect(getBlockedUninspectableFileField(diff --git a/packages/api/src/protection/files.ts b/packages/api/src/protection/files.tsindex e406177be5..9694984b7e 100644--- a/packages/api/src/protection/files.ts+++ b/packages/api/src/protection/files.ts@@ -229,14 +229,6 @@ export function hasActiveFileFieldPolicy(return true;}-export function isFileFilterFieldEnabled(- filters: FiltersConfig | undefined,- field: FileFilterField,-): boolean {- const pii = getFilePii(filters);- return pii != null && (pii.fields == null || pii.fields.includes(field));-}-export function getBlockedUninspectableFileField(filters: FiltersConfig | undefined,fields: readonly FileFilterField[],@@ -260,20 +252,6 @@ function isAgentContextUpload(input: {return !isAssistantsEndpoint(input.endpoint) && input.toolResource === EToolResources.context;}-/** Whether a context upload has a downstream STT step that can inspect its transcript. */-export function canInspectUploadTranscriptAfterProcessing(input: {- readonly endpoint?: string;- readonly toolResource?: string;- readonly mimeType?: string;- readonly sttSupported: boolean;-}): boolean {- return (- getTranscriptApplicability(input.mimeType) === true &&- input.sttSupported &&- isAgentContextUpload(input)- );-}-/** Resolves upload-time transcript fail-close after accounting for downstream STT. */export function getBlockedUploadTranscriptField(input: {readonly filters?: FiltersConfig;diff --git a/packages/api/src/protection/legacy.spec.ts b/packages/api/src/protection/legacy.spec.tsindex 6bd2894349..4cd141bc7b 100644--- a/packages/api/src/protection/legacy.spec.ts+++ b/packages/api/src/protection/legacy.spec.ts@@ -1,223 +1,67 @@-import { logger } from '@librechat/data-schemas';-import type { MessageFilterPiiConfig } from 'librechat-data-provider';import type { TextContentFragment } from './types';-import { createLegacyPiiInspector, inspectLegacyPii, toLegacyPiiMatch } from './legacy';-import { extractMessageContent } from './adapters/messages';--jest.mock('@librechat/data-schemas', () => ({- logger: { warn: jest.fn(), error: jest.fn(), info: jest.fn(), debug: jest.fn() },-}));+import { isLegacyPiiFragment } from './legacy';function fragment(id: string,- text: string,+ field: TextContentFragment['field'] = 'text',): Extract<TextContentFragment, { readonly source: 'message' }> {return {id,- text,+ text: 'value',path: `/${id}`,source: 'message',- field: 'text',+ field,format: 'plain',treatment: 'replaceable',provenance: 'user',- };+ } as Extract<TextContentFragment, { readonly source: 'message' }>;}-describe('legacy content protection', () => {- it('returns a raw-free finding and converts it to the public legacy match', () => {- const secret = 'sk-proj-FAKE1234567890ABCDEF';- const finding = inspectLegacyPii(- [fragment('external-message.0.content', `my key is ${secret}`)],- {},- );-- expect(finding).toEqual({- detectorId: 'legacy-pattern',- ruleId: 'sk_prefix',- label: 'sk- prefix token',- source: 'message',- field: 'text',- provenance: 'user',- fragmentId: 'external-message.0.content',- fragmentPath: '/external-message.0.content',- });- expect(JSON.stringify(finding)).not.toContain(secret);- expect(toLegacyPiiMatch(finding)).toEqual({- id: 'sk_prefix',- label: 'sk- prefix token',- });+describe('isLegacyPiiFragment', () => {+ it.each([+ 'chat.text',+ 'chat.input',+ 'chat.answer',+ 'chat.quote.0',+ 'chat.decision.1.response',+ 'chat.decision.1.reason',+ 'external-message.0.content',+ 'external-message.2.part.3',+ 'stored-message.text',+ ])('inspects %s', (id) => {+ expect(isLegacyPiiFragment(fragment(id))).toBe(true);});- it('applies legacy message rules to provenance-selected stored message prose', () => {- const config: MessageFilterPiiConfig = {- starterPatterns: [],- customPatterns: [{ id: 'private', label: 'private value', regex: 'PRIVATE-VALUE' }],- };-- expect(- inspectLegacyPii([fragment('stored-message.text', 'PRIVATE-VALUE')], config),- ).toMatchObject({- ruleId: 'private',- source: 'message',- field: 'text',- });- expect(- inspectLegacyPii(- [- {- ...fragment('stored-message.name.sender', 'PRIVATE-VALUE'),- field: 'name',- },- ],- config,- ),- ).toBeNull();+ it('limits stored message fields to the ones it historically inspected', () => {+ expect(isLegacyPiiFragment(fragment('stored-message.text', 'text'))).toBe(true);+ expect(isLegacyPiiFragment(fragment('stored-message.name.sender', 'name'))).toBe(false);});it.each(['stored-message.assembled', 'stored-message.user-submitted-assembled'])(- 'applies legacy rules to split submitted prose through %s',+ 'inspects split submitted prose through %s',(id) => {- const config: MessageFilterPiiConfig = {- starterPatterns: [],- customPatterns: [{ id: 'private', label: 'private value', regex: 'PRIVATE-VALUE' }],- };- const assembled: TextContentFragment = {- ...fragment(id, 'PRIVATE-VALUE'),+ const assembled = {+ ...fragment(id),source: 'assembled_context',field: 'assembled_context',treatment: 'inspect_only',- };-- expect(- inspectLegacyPii(- [- fragment('stored-message.part.0', 'PRIVATE-'),- fragment('stored-message.part.1', 'VALUE'),- ],- config,- ),- ).toBeNull();- expect(inspectLegacyPii([assembled], config)).toMatchObject({- ruleId: 'private',- source: 'assembled_context',- field: 'assembled_context',- });+ } as TextContentFragment;+ expect(isLegacyPiiFragment(assembled)).toBe(true);},);- it('preserves candidate-first ordering when different rules match different fields', () => {- const config: MessageFilterPiiConfig = {- starterPatterns: [],- customPatterns: [- { id: 'first-rule', label: 'A value', regex: 'VALUE-A' },- { id: 'second-rule', label: 'B value', regex: 'VALUE-B' },- ],- };-- const finding = inspectLegacyPii(- [- fragment('external-message.0.content', 'VALUE-B'),- fragment('external-message.1.content', 'VALUE-A'),- ],- config,- );-- expect(finding?.ruleId).toBe('second-rule');- expect(finding?.fragmentId).toBe('external-message.0.content');- });-- it('does not read later message content after the first finding', () => {- const readLaterContent = jest.fn(() => {- throw new Error('later content should not be read');- });- const messages = [- { content: 'sk-proj-FAKE1234567890ABCDEF' },- {- get content() {- return readLaterContent();- },- },- ];- const inspector = createLegacyPiiInspector({});-- const finding = inspector?.inspect(extractMessageContent(messages));-- expect(finding?.ruleId).toBe('sk_prefix');- expect(readLaterContent).not.toHaveBeenCalled();- });-- it('keeps legacy matching limited to the fields it historically inspected', () => {- const config: MessageFilterPiiConfig = {};- const inspector = createLegacyPiiInspector(config);- const secret = 'sk-proj-FAKE1234567890ABCDEF';-- expect(- inspector?.inspect([- {- ...fragment('external-message.0.name', secret),- field: 'name',- },- {- ...fragment('external-message.0.part.0.attachment.filename', secret),- field: 'attachment_reference',- },- {- ...fragment('external-message.0.tool-call.0.arguments', secret),- source: 'tool_argument',- field: 'arguments',- },- ]),- ).toBeNull();- expect(- inspector?.inspect([- {- ...fragment('external-message.0.content', secret),- field: 'text',- },- ]),- ).not.toBeNull();- });-- it('compiles once per config identity and warns once for an invalid pattern', () => {- jest.mocked(logger.warn).mockClear();- const config = {- starterPatterns: [],- customPatterns: [{ id: 'broken', label: 'Broken', regex: '(' }],- } as MessageFilterPiiConfig;-- expect(inspectLegacyPii([], config)).toBeNull();- expect(inspectLegacyPii([], config)).toBeNull();-- expect(createLegacyPiiInspector(config)).toBe(createLegacyPiiInspector(config));- expect(logger.warn).toHaveBeenCalledTimes(1);- expect(logger.warn).toHaveBeenCalledWith(- expect.stringContaining('[messageFilter.pii] dropping invalid customPattern "broken":'),- );- });-- it('runs legacy custom patterns through the linear-time engine', () => {- jest.mocked(logger.warn).mockClear();- const nestedQuantifier = {- starterPatterns: [],- customPatterns: [{ id: 'nested', label: 'Nested', regex: '(a+)+$' }],- } as MessageFilterPiiConfig;- const nativeOnly = {- starterPatterns: [],- customPatterns: [{ id: 'lookahead', label: 'Lookahead', regex: '(?=PRIVATE)PRIVATE' }],- } as MessageFilterPiiConfig;-+ it('ignores names, attachment references and tool-call arguments', () => {+ expect(isLegacyPiiFragment(fragment('external-message.0.name', 'name'))).toBe(false);expect(- inspectLegacyPii(- [fragment('external-message.0.content', `${'a'.repeat(50_000)}!`)],- nestedQuantifier,+ isLegacyPiiFragment(+ fragment('external-message.0.part.0.attachment.filename', 'attachment_reference'),),- ).toBeNull();+ ).toBe(false);expect(- inspectLegacyPii([fragment('external-message.0.content', 'PRIVATE')], nativeOnly),- ).toBeNull();- expect(logger.warn).toHaveBeenCalledWith(- expect.stringContaining('[messageFilter.pii] dropping invalid customPattern "lookahead":'),- );+ isLegacyPiiFragment({+ ...fragment('external-message.0.tool-call.0.arguments', 'arguments'),+ source: 'tool_argument',+ } as TextContentFragment),+ ).toBe(false);});});diff --git a/packages/api/src/protection/legacy.ts b/packages/api/src/protection/legacy.tsindex 82bf14867d..f686508e92 100644--- a/packages/api/src/protection/legacy.ts+++ b/packages/api/src/protection/legacy.ts@@ -1,15 +1,4 @@-import type { MessageFilterPiiConfig } from 'librechat-data-provider';-import type { ProtectionFinding, TextContentFragment } from './types';-import { createPatternContentInspector } from './detectors/pattern';--export interface LegacyPiiMatch {- readonly id: string;- readonly label: string;-}--export interface LegacyPiiInspector {- inspect(fragments: Iterable<TextContentFragment>): ProtectionFinding | null;-}+import type { TextContentFragment } from './types';const LEGACY_STORED_MESSAGE_FIELDS = new Set(['text',@@ -20,9 +9,6 @@ const LEGACY_STORED_MESSAGE_FIELDS = new Set(['content_part',]);-const LEGACY_INSPECTOR_CACHE = new WeakMap<object, LegacyPiiInspector>();-const INACTIVE_LEGACY_CONFIGS = new WeakSet<object>();-export function isLegacyPiiFragment(fragment: TextContentFragment): boolean {if (fragment.source === 'assembled_context') {return (@@ -49,55 +35,3 @@ export function isLegacyPiiFragment(fragment: TextContentFragment): boolean {/^external-message\.\d+\.(?:content|part\.\d+)$/.test(fragment.id));}--export function createLegacyPiiInspector(- config: MessageFilterPiiConfig | undefined,-): LegacyPiiInspector | null {- if (config == null) {- return null;- }- if (INACTIVE_LEGACY_CONFIGS.has(config)) {- return null;- }- const cached = LEGACY_INSPECTOR_CACHE.get(config);- if (cached != null) {- return cached;- }- const patternInspector = createPatternContentInspector(config, { linearTime: true });- if (!patternInspector.active) {- INACTIVE_LEGACY_CONFIGS.add(config);- return null;- }- const inspector: LegacyPiiInspector = {- inspect(fragments) {- return patternInspector.inspect(- (function* legacyFragments() {- for (const fragment of fragments) {- if (isLegacyPiiFragment(fragment)) {- yield fragment;- }- }- })(),- );- },- };- LEGACY_INSPECTOR_CACHE.set(config, inspector);- return inspector;-}--export function inspectLegacyPii(- fragments: Iterable<TextContentFragment>,- config: MessageFilterPiiConfig | undefined,-): ProtectionFinding | null {- return createLegacyPiiInspector(config)?.inspect(fragments) ?? null;-}--export function toLegacyPiiMatch(finding: ProtectionFinding | null): LegacyPiiMatch | null {- if (finding == null) {- return null;- }- return {- id: finding.ruleId,- label: finding.label,- };-}diff --git a/packages/api/src/schedules/authorization/runtime.spec.ts b/packages/api/src/schedules/authorization/runtime.spec.tsindex acf24499f9..26f3ec3d65 100644--- a/packages/api/src/schedules/authorization/runtime.spec.ts+++ b/packages/api/src/schedules/authorization/runtime.spec.ts@@ -1,10 +1,6 @@import { Permissions, PermissionTypes, AgentCapabilities } from 'librechat-data-provider';import type { AppConfig, IRole, ISchedule, AgentGraphAccessContext } from '@librechat/data-schemas';-import {- createScheduleMCPRuntimeHost,- prepareScheduleMCPExecution,- initializeWithScheduleMCPExecution,-} from './runtime';+import { createScheduleMCPRuntimeHost, initializeWithScheduleMCPExecution } from './runtime';import { bindScheduledMCPInvocation, getScheduleMCPExecution } from './execution';import { executionFixture, readTool } from './execution.helper';import { createMCPRequestContext } from '~/mcp/request';@@ -287,11 +283,14 @@ it('keeps live role denial and policy removal fail-closed for enrolled schedulesit('does not construct the host for ordinary chats', async () => {const f = await setup();const getHost = jest.fn(() => f.host);- await prepareScheduleMCPExecution(+ const initialize = jest.fn().mockResolvedValue(undefined);+ await initializeWithScheduleMCPExecution({ req: { ...f.req, _isScheduledFire: false, _isAgentTrigger: false }, context: f.context },getHost,+ initialize,);expect(getHost).not.toHaveBeenCalled();+ expect(initialize).toHaveBeenCalledTimes(1);});it('does not downgrade if enrollment disappears during run preparation', async () => {@@ -580,9 +579,6 @@ it('sanitizes host construction and lineage-retention failures without masking pconst getHost = () => {throw privateError;};- await expect(- prepareScheduleMCPExecution({ req: f.req, context: f.context }, getHost),- ).rejects.toMatchObject({ failure: { reason: 'dependency_unavailable' } });await expect(initializeWithScheduleMCPExecution({ req: f.req, context: f.context }, getHost, initialize),).rejects.toMatchObject({ failure: { reason: 'dependency_unavailable' } });diff --git a/packages/api/src/schedules/authorization/runtime.ts b/packages/api/src/schedules/authorization/runtime.tsindex 0052311e84..90d32f5302 100644--- a/packages/api/src/schedules/authorization/runtime.ts+++ b/packages/api/src/schedules/authorization/runtime.ts@@ -211,20 +211,6 @@ export function createScheduleMCPRuntimeHost(};}-/** Ordinary chats do not construct scheduling dependencies or perform schedule reads. */-export async function prepareScheduleMCPExecution(- input: Parameters<ReturnType<typeof createScheduleMCPRuntimeHost>['prepare']>[0],- getHost: () => Pick<ReturnType<typeof createScheduleMCPRuntimeHost>, 'prepare'>,-): Promise<void> {- if (- input.restoredJob?.scheduleMCPCompletion === undefined &&- !isScheduleFireRequest(input.req) &&- !isScheduledMCPCompletionRequest(input.req)- )- return;- await prepareSafely(() => getHost().prepare(input), input.signal);-}-/** Ordinary startup keeps its original synchronous admission of independent reads. */export function initializeWithScheduleMCPExecution<T>(input: Parameters<ReturnType<typeof createScheduleMCPRuntimeHost>['prepare']>[0],diff --git a/packages/api/src/skills/deployment.ts b/packages/api/src/skills/deployment.tsindex ceee9d94bc..db5a121205 100644--- a/packages/api/src/skills/deployment.ts+++ b/packages/api/src/skills/deployment.ts@@ -355,10 +355,6 @@ export class DeploymentSkillRegistry {let registry = new DeploymentSkillRegistry(null, []);const warnedDeploymentNameCollisions = new Set<string>();-export function getDeploymentSkillRegistry(): DeploymentSkillRegistry {- return registry;-}-export function getDeploymentSkillIds(): Types.ObjectId[] {return registry.ids();}@@ -390,10 +386,6 @@ export function getDeploymentSkillById(id: SkillId): DeploymentSkill | null {return registry.getById(id);}-export function isDeploymentSkillFilePath(filepath: string): boolean {- return registry.hasFilePath(filepath);-}-export async function getDeploymentSkillDownloadStream(filepath: string,): Promise<NodeJS.ReadableStream> {@@ -403,12 +395,6 @@ export async function getDeploymentSkillDownloadStream(return fs.createReadStream(filepath);}-export function updateDeploymentSkillFileCodeEnvRefs(- updates: Array<{ skillId: SkillId; relativePath: string; codeEnvRef: CodeEnvRef }>,-): Array<{ skillId: SkillId; relativePath: string; codeEnvRef: CodeEnvRef }> {- return registry.updateFileCodeEnvRefs(updates);-}-export function resolveDeploymentSkillDirectory(options: LoadDeploymentSkillsOptions = {},): DirectoryResolution {diff --git a/packages/api/src/skills/import.ts b/packages/api/src/skills/import.tsindex 8d454b4fef..a4e660582f 100644--- a/packages/api/src/skills/import.ts+++ b/packages/api/src/skills/import.ts@@ -1334,48 +1334,6 @@ const MIME_MAP: Record<string, string> = {'.pdf': 'application/pdf',};-const TEXT_FILE_EXTENSIONS = new Set([- '.md',- '.txt',- '.js',- '.ts',- '.jsx',- '.tsx',- '.json',- '.yaml',- '.yml',- '.py',- '.sh',- '.css',- '.html',- '.xml',- '.csv',- '.toml',- '.ini',- '.svg',-]);--const TEXT_APPLICATION_MIMES = new Set([- 'application/json',- 'application/javascript',- 'application/xml',- 'application/x-sh',- 'application/yaml',- 'application/toml',- 'image/svg+xml',-]);--export function isTextLikeSkillFile(filename: string, mimeType?: string): boolean {- const normalizedMime = mimeType?.split(';', 1)[0]?.trim().toLowerCase();- if (normalizedMime?.startsWith('text/') === true) {- return true;- }- if (normalizedMime != null && TEXT_APPLICATION_MIMES.has(normalizedMime)) {- return true;- }- return TEXT_FILE_EXTENSIONS.has(path.extname(filename).toLowerCase());-}-export function guessMimeType(filename: string): string {return MIME_MAP[path.extname(filename).toLowerCase()] || 'application/octet-stream';}diff --git a/packages/api/src/stream/__tests__/RedisJobStore.stream_integration.spec.ts b/packages/api/src/stream/__tests__/RedisJobStore.stream_integration.spec.tsindex 6b30125830..96664ad4e0 100644--- a/packages/api/src/stream/__tests__/RedisJobStore.stream_integration.spec.ts+++ b/packages/api/src/stream/__tests__/RedisJobStore.stream_integration.spec.ts@@ -2416,68 +2416,6 @@ describe('RedisJobStore Integration Tests', () => {await store.deleteConsumerGroup(streamId, groupName);await store.destroy();});-- // TODO: Debug consumer group timing with Redis Streams- test.skip('should resume from where client left off', async () => {- if (!ioredisClient) {- return;- }-- const { RedisJobStore } = await import('../implementations/RedisJobStore');- const store = new RedisJobStore(ioredisClient);- await store.initialize();-- const streamId = `resume-test-${Date.now()}`;- await store.createJob(streamId, 'user-1', streamId);-- // Create consumer group FIRST (before adding chunks) to track delivery- const groupName = `client-resume-${Date.now()}`;- await store.createConsumerGroup(streamId, groupName, '$'); // Start from end (only new messages)-- // Add initial chunks (these will be "new" to the consumer group)- await store.appendChunk(streamId, {- event: 'on_message_delta',- data: { type: 'text', text: 'Part 1' },- });- await store.appendChunk(streamId, {- event: 'on_message_delta',- data: { type: 'text', text: 'Part 2' },- });-- // Wait for Redis to sync- await new Promise((resolve) => setTimeout(resolve, 50));-- // Client reads first batch- const firstRead = await store.readChunksFromGroup(streamId, groupName, 'consumer-1');- expect(firstRead.length).toBe(2);-- // ACK the chunks- await store.acknowledgeChunks(- streamId,- groupName,- firstRead.map((c) => c.id),- );-- // More chunks arrive while client is away- await store.appendChunk(streamId, {- event: 'on_message_delta',- data: { type: 'text', text: 'Part 3' },- });- await store.appendChunk(streamId, {- event: 'on_message_delta',- data: { type: 'text', text: 'Part 4' },- });-- // Wait for Redis to sync- await new Promise((resolve) => setTimeout(resolve, 50));-- // Client reconnects - should only get new chunks- const secondRead = await store.readChunksFromGroup(streamId, groupName, 'consumer-1');- expect(secondRead.length).toBe(2);-- await store.deleteConsumerGroup(streamId, groupName);- await store.destroy();- });});describe('TTL and Cleanup', () => {diff --git a/packages/api/src/stream/checkpoints.ts b/packages/api/src/stream/checkpoints.tsindex f62e4ecaa3..3b8b10030d 100644--- a/packages/api/src/stream/checkpoints.ts+++ b/packages/api/src/stream/checkpoints.ts@@ -3,12 +3,6 @@ import { createHash, randomUUID } from 'crypto';export const DEFAULT_CHECKPOINT_TTL_SECONDS: number = 24 * 60 * 60;const CHECKPOINT_NAMESPACE_PREFIX = 'lcg:v2:';-const SHA256_PATTERN = '[0-9a-f]{64}';-const UUID_V4_PATTERN = '[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}';-const CHECKPOINT_NAMESPACE_PATTERN = new RegExp(- `^${CHECKPOINT_NAMESPACE_PREFIX}${SHA256_PATTERN}:${UUID_V4_PATTERN}$`,-);-function checkpointOwnerHash(userId: string, tenantId?: string): string {return createHash('sha256').update(JSON.stringify([tenantId || null, userId]))@@ -24,18 +18,3 @@ export function checkpointOwnerNamespacePrefix(userId: string, tenantId?: stringexport function createCheckpointNamespace(userId: string, tenantId?: string): string {return `${checkpointOwnerNamespacePrefix(userId, tenantId)}${randomUUID()}`;}--export function isCleanupSafeCheckpointNamespace(value: unknown): value is string {- return typeof value === 'string' && CHECKPOINT_NAMESPACE_PATTERN.test(value);-}--export function checkpointNamespaceBelongsToOwner(- value: unknown,- userId: string,- tenantId?: string,-): value is string {- return (- isCleanupSafeCheckpointNamespace(value) &&- value.startsWith(checkpointOwnerNamespacePrefix(userId, tenantId))- );-}diff --git a/packages/api/src/stream/implementations/index.ts b/packages/api/src/stream/implementations/index.tsdeleted file mode 100644index 6926938a46..0000000000--- a/packages/api/src/stream/implementations/index.ts+++ /dev/null@@ -1,4 +0,0 @@-export * from './InMemoryJobStore';-export * from './InMemoryEventTransport';-export * from './RedisJobStore';-export * from './RedisEventTransport';diff --git a/packages/api/src/stream/interfaces/index.ts b/packages/api/src/stream/interfaces/index.tsdeleted file mode 100644index 5e31fb6fa3..0000000000--- a/packages/api/src/stream/interfaces/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from './IJobStore';diff --git a/packages/api/src/telemetry/logs.spec.ts b/packages/api/src/telemetry/logs.spec.tsindex 57f0fa4629..1aba2392dc 100644--- a/packages/api/src/telemetry/logs.spec.ts+++ b/packages/api/src/telemetry/logs.spec.ts@@ -1,11 +1,17 @@import { logger } from '@librechat/data-schemas';import { OpenTelemetryTransportV3 } from '@opentelemetry/winston-transport';-import { attachLogsTransport, detachLogsTransport, getLogsTransport } from './logs';+import { attachLogsTransport, detachLogsTransport } from './logs';import { getTelemetryConfig } from './config';+function getOtelTransports(): OpenTelemetryTransportV3[] {+ return logger.transports.filter(+ (transport): transport is OpenTelemetryTransportV3 =>+ transport instanceof OpenTelemetryTransportV3,+ );+}+function countOtelTransports(): number {- return logger.transports.filter((transport) => transport instanceof OpenTelemetryTransportV3)- .length;+ return getOtelTransports().length;}describe('logs transport lifecycle', () => {@@ -27,14 +33,14 @@ describe('logs transport lifecycle', () => {attachLogsTransport(config);expect(countOtelTransports()).toBe(1);- expect(getLogsTransport()?.level).toBe('warn');+ expect(getOtelTransports()[0]?.level).toBe('warn');expect(emitWarningSpy).not.toHaveBeenCalled();});it('falls back to info and warns when OTEL_LOGS_LEVEL is unknown', () => {attachLogsTransport(getTelemetryConfig({ OTEL_LOGS_ENABLED: 'true', OTEL_LOGS_LEVEL: 'loud' }));- expect(getLogsTransport()?.level).toBe('info');+ expect(getOtelTransports()[0]?.level).toBe('info');expect(emitWarningSpy).toHaveBeenCalledWith(expect.stringContaining('Ignoring unknown OTEL_LOGS_LEVEL "loud"; using "info"'),{ code: 'LIBRECHAT_OTEL' },@@ -43,13 +49,12 @@ describe('logs transport lifecycle', () => {it('removes the transport from the shared logger on detach', () => {attachLogsTransport(getTelemetryConfig({ OTEL_LOGS_ENABLED: 'true' }));- const transport = getLogsTransport();+ const transport = getOtelTransports()[0];detachLogsTransport();detachLogsTransport();expect(transport).toBeDefined();- expect(getLogsTransport()).toBeUndefined();expect(countOtelTransports()).toBe(0);expect(logger.transports).not.toContain(transport);});diff --git a/packages/api/src/telemetry/logs.ts b/packages/api/src/telemetry/logs.tsindex 1946236c73..a7b75839c0 100644--- a/packages/api/src/telemetry/logs.ts+++ b/packages/api/src/telemetry/logs.ts@@ -51,7 +51,3 @@ export function detachLogsTransport(): void {logger.remove(activeTransport);activeTransport = undefined;}--export function getLogsTransport(): OpenTelemetryTransportV3 | undefined {- return activeTransport;-}diff --git a/packages/api/src/tools/registry/definitions.ts b/packages/api/src/tools/registry/definitions.tsindex 5cd887e6d6..0f93a828e0 100644--- a/packages/api/src/tools/registry/definitions.ts+++ b/packages/api/src/tools/registry/definitions.ts@@ -472,11 +472,3 @@ const agentToolDefinitions: Record<string, ToolRegistryDefinition> = {export function getToolDefinition(toolName: string): ToolRegistryDefinition | undefined {return toolDefinitions[toolName] ?? agentToolDefinitions[toolName];}--export function getAllToolDefinitions(): ToolRegistryDefinition[] {- return [...Object.values(toolDefinitions), ...Object.values(agentToolDefinitions)];-}--export function getToolSchema(toolName: string): ExtendedJsonSchema | undefined {- return getToolDefinition(toolName)?.schema;-}diff --git a/packages/api/src/types/anthropic.ts b/packages/api/src/types/anthropic.tsindex 9c418e61db..fe9bf693b1 100644--- a/packages/api/src/types/anthropic.ts+++ b/packages/api/src/types/anthropic.ts@@ -24,10 +24,6 @@ export interface VertexAIClientOptions {projectId?: string;}-export interface ThinkingConfigDisabled {- type: 'disabled';-}-export interface ThinkingConfigEnabled {/*** Determines how many tokens Claude can use for its internal reasoning process.@@ -50,22 +46,6 @@ export interface ThinkingConfigAdaptive {display?: ThinkingDisplayWireValue;}-/**- * Configuration for enabling Claude's extended thinking.- *- * When enabled, responses include `thinking` content blocks showing Claude's- * thinking process before the final answer. Requires a minimum budget of 1,024- * tokens and counts towards your `max_tokens` limit.- *- * See- * [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)- * for details.- */-export type ThinkingConfigParam =- | ThinkingConfigEnabled- | ThinkingConfigDisabled- | ThinkingConfigAdaptive;-export type AnthropicModelOptions = Partial<Omit<AnthropicParameters, 'thinking'>> & {thinking?: AnthropicParameters['thinking'] | null;user?: string;diff --git a/packages/api/src/types/azure.ts b/packages/api/src/types/azure.tsindex d21e1e1d01..1b8405f7c8 100644--- a/packages/api/src/types/azure.ts+++ b/packages/api/src/types/azure.ts@@ -8,12 +8,3 @@ export interface AzureOptions {azureOpenAIApiVersion?: string;azureOpenAIBasePath?: string;}--/**- * Client with azure property for setting deployment name- */-export interface GenericClient {- azure: {- azureOpenAIApiDeploymentName?: string;- };-}diff --git a/packages/api/src/types/bedrock.ts b/packages/api/src/types/bedrock.tsindex c60658e33d..0de24acdcf 100644--- a/packages/api/src/types/bedrock.ts+++ b/packages/api/src/types/bedrock.ts@@ -1,6 +1,6 @@import type { BedrockRuntimeClient } from '@aws-sdk/client-bedrock-runtime';-import type { AwsCredentialIdentity } from '@aws-sdk/types';import type { BedrockConverseInput } from 'librechat-data-provider';+import type { AwsCredentialIdentity } from '@aws-sdk/types';/*** AWS credentials for Bedrock@@ -8,13 +8,6 @@ import type { BedrockConverseInput } from 'librechat-data-provider';*/export type BedrockCredentials = Partial<AwsCredentialIdentity>;-/**- * User-provided Bedrock credentials can be either AWS credentials or an API key.- */-export type BedrockUserCredentials = BedrockCredentials & {- bearerToken?: string;-};-/*** AWS Bedrock Guardrail configuration* @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_GuardrailConfiguration.html@@ -37,27 +30,6 @@ export interface GuardrailConfiguration {*/export type InferenceProfileConfig = Record<string, string>;-/**- * Configuration options for Bedrock LLM- */-export interface BedrockConfigOptions {- modelOptions?: Partial<BedrockConverseInput>;- /** AWS region for Bedrock */- region?: string;- /** Optional pre-configured Bedrock client (used with proxy) */- client?: BedrockRuntimeClient;- /** AWS credentials */- credentials?: BedrockCredentials;- /** AWS shared config profile for the SDK credential provider chain */- profile?: string;- /** Custom endpoint host for reverse proxy */- endpointHost?: string;- /** Guardrail configuration for content filtering */- guardrailConfig?: GuardrailConfiguration;- /** Inference profile ARNs keyed by model ID / friendly name */- inferenceProfiles?: InferenceProfileConfig;-}-/*** Return type for Bedrock getOptions function*/diff --git a/packages/api/src/types/mistral.ts b/packages/api/src/types/mistral.tsindex 297369bd0a..9f0d13c41d 100644--- a/packages/api/src/types/mistral.ts+++ b/packages/api/src/types/mistral.ts@@ -52,17 +52,6 @@ export interface OCRResult {usage_info: OCRUsageInfo;}-export interface MistralOCRRequest {- model: string;- image_limit?: number;- include_image_base64?: boolean;- document: {- type: 'document_url' | 'image_url';- document_url?: string;- image_url?: string;- };-}-export interface MistralOCRError {detail?: string;message?: string;diff --git a/packages/api/src/types/prompts.ts b/packages/api/src/types/prompts.tsindex 17224398da..6d0b3e4a36 100644--- a/packages/api/src/types/prompts.ts+++ b/packages/api/src/types/prompts.ts@@ -1,5 +1,4 @@import type { IPromptGroup as IPromptGroup } from '@librechat/data-schemas';-import type { Types } from 'mongoose';export interface PromptGroupsListResponse<T = IPromptGroup> {promptGroups: T[];@@ -9,16 +8,3 @@ export interface PromptGroupsListResponse<T = IPromptGroup> {has_more: boolean;after: string | null;}--export interface PromptGroupsAllResponse {- data: IPromptGroup[];-}--export interface AccessiblePromptGroupsResult {- object: 'list';- data: IPromptGroup[];- first_id: Types.ObjectId | null;- last_id: Types.ObjectId | null;- has_more: boolean;- after: string | null;-}diff --git a/packages/api/src/utils/__tests__/files.test.ts b/packages/api/src/utils/__tests__/files.test.tsindex 41332d2635..5654090ee6 100644--- a/packages/api/src/utils/__tests__/files.test.ts+++ b/packages/api/src/utils/__tests__/files.test.ts@@ -1,7 +1,7 @@+import { Readable } from 'stream';import { createReadStream } from 'fs';import { readFile, stat } from 'fs/promises';-import { Readable } from 'stream';-import { readFileAsString, readFileAsBuffer, readJsonFile } from '../files';+import { readFileAsString, readFileAsBuffer } from '../files';jest.mock('fs');jest.mock('fs/promises');@@ -280,135 +280,4 @@ describe('File utilities', () => {await expect(readFileAsBuffer(mockFilePath)).rejects.toThrow('Access denied');});});-- describe('readJsonFile', () => {- const validJson = { name: 'test', value: 123, nested: { key: 'value' } };- const jsonString = JSON.stringify(validJson);-- it('should parse valid JSON files', async () => {- (stat as jest.Mock).mockResolvedValue({ size: jsonString.length });- (readFile as jest.Mock).mockResolvedValue(jsonString);-- const result = await readJsonFile(mockFilePath);-- expect(result).toEqual(validJson);- expect(readFile).toHaveBeenCalledWith(mockFilePath, 'utf8');- });-- it('should parse JSON with provided fileSize', async () => {- const fileSize = jsonString.length;-- (readFile as jest.Mock).mockResolvedValue(jsonString);-- const result = await readJsonFile(mockFilePath, { fileSize });-- expect(result).toEqual(validJson);- expect(stat).not.toHaveBeenCalled();- });-- it('should handle JSON arrays', async () => {- const jsonArray = [1, 2, 3, { key: 'value' }];- const arrayString = JSON.stringify(jsonArray);-- (stat as jest.Mock).mockResolvedValue({ size: arrayString.length });- (readFile as jest.Mock).mockResolvedValue(arrayString);-- const result = await readJsonFile(mockFilePath);-- expect(result).toEqual(jsonArray);- });-- it('should throw on invalid JSON', async () => {- const invalidJson = '{ invalid json }';-- (stat as jest.Mock).mockResolvedValue({ size: invalidJson.length });- (readFile as jest.Mock).mockResolvedValue(invalidJson);-- await expect(readJsonFile(mockFilePath)).rejects.toThrow();- });-- it('should throw on empty file', async () => {- (stat as jest.Mock).mockResolvedValue({ size: 0 });- (readFile as jest.Mock).mockResolvedValue('');-- await expect(readJsonFile(mockFilePath)).rejects.toThrow();- });-- it('should handle large JSON files with streaming', async () => {- const largeJson = { data: 'x'.repeat(11 * 1024 * 1024) }; // >10MB- const largeJsonString = JSON.stringify(largeJson);- const fileSize = largeJsonString.length;-- (stat as jest.Mock).mockResolvedValue({ size: fileSize });-- // Create chunks for streaming- const chunks: string[] = [];- let offset = 0;- const chunkSize = 5 * 1024 * 1024; // 5MB chunks-- while (offset < largeJsonString.length) {- chunks.push(largeJsonString.slice(offset, offset + chunkSize));- offset += chunkSize;- }-- const mockStream = new Readable({- read() {- if (chunks.length > 0) {- this.push(chunks.shift());- } else {- this.push(null);- }- },- });-- (createReadStream as jest.Mock).mockReturnValue(mockStream);-- const result = await readJsonFile(mockFilePath);-- expect(result).toEqual(largeJson);- expect(createReadStream).toHaveBeenCalled();- expect(readFile).not.toHaveBeenCalled();- });-- it('should use custom stream threshold', async () => {- const customThreshold = 100;- const json = { test: 'x'.repeat(200) };- const jsonStr = JSON.stringify(json);- const fileSize = jsonStr.length;-- (stat as jest.Mock).mockResolvedValue({ size: fileSize });-- const mockStream = new Readable({- read() {- this.push(jsonStr);- this.push(null);- },- });-- (createReadStream as jest.Mock).mockReturnValue(mockStream);-- await readJsonFile(mockFilePath, { streamThreshold: customThreshold });-- expect(createReadStream).toHaveBeenCalled();- });-- it('should preserve type with generics', async () => {- interface TestType {- id: number;- name: string;- }-- const typedJson: TestType = { id: 1, name: 'test' };- const jsonString = JSON.stringify(typedJson);-- (stat as jest.Mock).mockResolvedValue({ size: jsonString.length });- (readFile as jest.Mock).mockResolvedValue(jsonString);-- const result = await readJsonFile<TestType>(mockFilePath);-- expect(result).toEqual(typedJson);- expect(result.id).toBe(1);- expect(result.name).toBe('test');- });- });});diff --git a/packages/api/src/utils/azure.spec.ts b/packages/api/src/utils/azure.spec.tsindex 5f4a769ed8..51d8383a90 100644--- a/packages/api/src/utils/azure.spec.ts+++ b/packages/api/src/utils/azure.spec.ts@@ -1,11 +1,9 @@import {- genAzureChatCompletion,getAzureCredentials,constructAzureURL,sanitizeModelName,genAzureEndpoint,} from './azure';-import type { GenericClient } from '~/types';describe('sanitizeModelName', () => {test('removes periods from the model name', () => {@@ -29,154 +27,6 @@ describe('genAzureEndpoint', () => {});});-describe('genAzureChatCompletion', () => {- // Test with both deployment name and model name provided- test('prefers model name over deployment name when both are provided and feature enabled', () => {- process.env.AZURE_USE_MODEL_AS_DEPLOYMENT_NAME = 'true';- const url = genAzureChatCompletion(- {- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiDeploymentName: 'deploymentName',- azureOpenAIApiVersion: 'v1',- },- 'modelName',- );- expect(url).toBe(- 'https://instanceName.openai.azure.com/openai/deployments/modelName/chat/completions?api-version=v1',- );- });-- // Test with only deployment name provided- test('uses deployment name when model name is not provided', () => {- const url = genAzureChatCompletion({- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiDeploymentName: 'deploymentName',- azureOpenAIApiVersion: 'v1',- });- expect(url).toBe(- 'https://instanceName.openai.azure.com/openai/deployments/deploymentName/chat/completions?api-version=v1',- );- });-- // Test with only model name provided- test('uses model name when deployment name is not provided and feature enabled', () => {- process.env.AZURE_USE_MODEL_AS_DEPLOYMENT_NAME = 'true';- const url = genAzureChatCompletion(- {- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiVersion: 'v1',- },- 'modelName',- );- expect(url).toBe(- 'https://instanceName.openai.azure.com/openai/deployments/modelName/chat/completions?api-version=v1',- );- });-- // Test with neither deployment name nor model name provided- test('throws error if neither deployment name nor model name is provided', () => {- expect(() => {- genAzureChatCompletion({- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiVersion: 'v1',- });- }).toThrow(- 'Either a model name with the `AZURE_USE_MODEL_AS_DEPLOYMENT_NAME` setting or a deployment name must be provided if `AZURE_OPENAI_BASEURL` is omitted.',- );- });-- // Test with feature disabled but model name provided- test('ignores model name and uses deployment name when feature is disabled', () => {- process.env.AZURE_USE_MODEL_AS_DEPLOYMENT_NAME = 'false';- const url = genAzureChatCompletion(- {- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiDeploymentName: 'deploymentName',- azureOpenAIApiVersion: 'v1',- },- 'modelName',- );- expect(url).toBe(- 'https://instanceName.openai.azure.com/openai/deployments/deploymentName/chat/completions?api-version=v1',- );- });-- // Test with sanitized model name- test('sanitizes model name when used in URL', () => {- process.env.AZURE_USE_MODEL_AS_DEPLOYMENT_NAME = 'true';- const url = genAzureChatCompletion(- {- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiVersion: 'v1',- },- 'model.name',- );- expect(url).toBe(- 'https://instanceName.openai.azure.com/openai/deployments/modelname/chat/completions?api-version=v1',- );- });-- // Test with client parameter and model name- test('updates client with sanitized model name when provided and feature enabled', () => {- process.env.AZURE_USE_MODEL_AS_DEPLOYMENT_NAME = 'true';- const clientMock = { azure: {} } as GenericClient;- const url = genAzureChatCompletion(- {- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiVersion: 'v1',- },- 'model.name',- clientMock,- );- expect(url).toBe(- 'https://instanceName.openai.azure.com/openai/deployments/modelname/chat/completions?api-version=v1',- );- expect(clientMock.azure.azureOpenAIApiDeploymentName).toBe('modelname');- });-- // Test with client parameter but without model name- test('does not update client when model name is not provided', () => {- const clientMock = { azure: {} } as GenericClient;- const url = genAzureChatCompletion(- {- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiDeploymentName: 'deploymentName',- azureOpenAIApiVersion: 'v1',- },- undefined,- clientMock,- );- expect(url).toBe(- 'https://instanceName.openai.azure.com/openai/deployments/deploymentName/chat/completions?api-version=v1',- );- expect(clientMock.azure.azureOpenAIApiDeploymentName).toBeUndefined();- });-- // Test with client parameter and deployment name when feature is disabled- test('does not update client when feature is disabled', () => {- process.env.AZURE_USE_MODEL_AS_DEPLOYMENT_NAME = 'false';- const clientMock = { azure: {} } as GenericClient;- const url = genAzureChatCompletion(- {- azureOpenAIApiInstanceName: 'instanceName',- azureOpenAIApiDeploymentName: 'deploymentName',- azureOpenAIApiVersion: 'v1',- },- 'modelName',- clientMock,- );- expect(url).toBe(- 'https://instanceName.openai.azure.com/openai/deployments/deploymentName/chat/completions?api-version=v1',- );- expect(clientMock.azure.azureOpenAIApiDeploymentName).toBeUndefined();- });-- // Reset environment variable after tests- afterEach(() => {- delete process.env.AZURE_USE_MODEL_AS_DEPLOYMENT_NAME;- });-});-describe('getAzureCredentials', () => {beforeEach(() => {process.env.AZURE_API_KEY = 'testApiKey';diff --git a/packages/api/src/utils/azure.ts b/packages/api/src/utils/azure.tsindex f5a9011a22..b08f4de107 100644--- a/packages/api/src/utils/azure.ts+++ b/packages/api/src/utils/azure.ts@@ -1,5 +1,4 @@-import type { AzureOptions, GenericClient } from '~/types';-import { isEnabled } from './common';+import type { AzureOptions } from '~/types';/*** Sanitizes the model name to be used in the URL by removing or replacing disallowed characters.@@ -34,52 +33,6 @@ export const genAzureEndpoint = ({return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}`;};-/**- * Generates the Azure OpenAI API chat completion endpoint URL with the API version.- * If both deploymentName and modelName are provided, modelName takes precedence.- * @param azureConfig - The Azure configuration object.- * @param azureConfig.azureOpenAIApiInstanceName - The Azure OpenAI API instance name.- * @param azureConfig.azureOpenAIApiDeploymentName - The Azure OpenAI API deployment name (optional).- * @param azureConfig.azureOpenAIApiVersion - The Azure OpenAI API version.- * @param modelName - The model name to be included in the deployment name (optional).- * @param client - The API Client class for optionally setting properties (optional).- * @returns The complete chat completion endpoint URL for the Azure OpenAI API.- * @throws Error if neither azureOpenAIApiDeploymentName nor modelName is provided.- */-export const genAzureChatCompletion = (- {- azureOpenAIApiInstanceName,- azureOpenAIApiDeploymentName,- azureOpenAIApiVersion,- }: {- azureOpenAIApiInstanceName: string;- azureOpenAIApiDeploymentName?: string;- azureOpenAIApiVersion: string;- },- modelName?: string,- client?: GenericClient,-): string => {- // Determine the deployment segment of the URL based on provided modelName or azureOpenAIApiDeploymentName- let deploymentSegment: string;- if (isEnabled(process.env.AZURE_USE_MODEL_AS_DEPLOYMENT_NAME) && modelName) {- const sanitizedModelName = sanitizeModelName(modelName);- deploymentSegment = sanitizedModelName;- if (client && typeof client === 'object') {- client.azure.azureOpenAIApiDeploymentName = sanitizedModelName;- }- } else if (azureOpenAIApiDeploymentName) {- deploymentSegment = azureOpenAIApiDeploymentName;- } else if (!process.env.AZURE_OPENAI_BASEURL) {- throw new Error(- 'Either a model name with the `AZURE_USE_MODEL_AS_DEPLOYMENT_NAME` setting or a deployment name must be provided if `AZURE_OPENAI_BASEURL` is omitted.',- );- } else {- deploymentSegment = '';- }-- return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${deploymentSegment}/chat/completions?api-version=${azureOpenAIApiVersion}`;-};-/*** Retrieves the Azure OpenAI API credentials from environment variables.* @returns An object containing the Azure OpenAI API credentials.diff --git a/packages/api/src/utils/env.spec.ts b/packages/api/src/utils/env.spec.tsindex c4597f8da9..b11e72ba81 100644--- a/packages/api/src/utils/env.spec.ts+++ b/packages/api/src/utils/env.spec.ts@@ -2,13 +2,7 @@ import { Types } from 'mongoose';import { TokenExchangeMethodEnum } from 'librechat-data-provider';import type { MCPOptions } from 'librechat-data-provider';import type { IUser } from '@librechat/data-schemas';-import {- createSafeUser,- resolveHeaders,- resolveNestedObject,- processMCPEnv,- encodeHeaderValue,-} from './env';+import { createSafeUser, resolveHeaders, processMCPEnv, encodeHeaderValue } from './env';import { applyRequestHeaders } from '~/mcp/utils';function isStdioOptions(options: MCPOptions): options is Extract<MCPOptions, { type?: 'stdio' }> {@@ -716,301 +710,6 @@ describe('resolveHeaders', () => {});});-describe('resolveNestedObject', () => {- beforeEach(() => {- process.env.TEST_API_KEY = 'test-api-key-value';- process.env.ANOTHER_VALUE = 'another-test-value';- });-- afterEach(() => {- delete process.env.TEST_API_KEY;- delete process.env.ANOTHER_VALUE;- });-- it('should preserve nested object structure', () => {- const obj = {- thinking: {- type: 'enabled',- budget_tokens: 2000,- },- anthropic_beta: ['output-128k-2025-02-19'],- max_tokens: 4096,- temperature: 0.7,- };-- const result = resolveNestedObject({ obj });-- expect(result).toEqual({- thinking: {- type: 'enabled',- budget_tokens: 2000,- },- anthropic_beta: ['output-128k-2025-02-19'],- max_tokens: 4096,- temperature: 0.7,- });- });-- it('should process placeholders in string values while preserving structure', () => {- const user = { id: 'user-123', email: '[email protected]' };- const obj = {- thinking: {- type: 'enabled',- budget_tokens: 2000,- user_context: '{{LIBRECHAT_USER_ID}}',- },- anthropic_beta: ['output-128k-2025-02-19'],- api_key: '${TEST_API_KEY}',- max_tokens: 4096,- };-- const result = resolveNestedObject({ obj, user });-- expect(result).toEqual({- thinking: {- type: 'enabled',- budget_tokens: 2000,- user_context: 'user-123',- },- anthropic_beta: ['output-128k-2025-02-19'],- api_key: 'test-api-key-value',- max_tokens: 4096,- });- });-- it('should process strings in arrays', () => {- const user = { id: 'user-123' };- const obj = {- headers: ['Authorization: Bearer ${TEST_API_KEY}', 'X-User-Id: {{LIBRECHAT_USER_ID}}'],- values: [1, 2, 3],- mixed: ['string', 42, true, '{{LIBRECHAT_USER_ID}}'],- };-- const result = resolveNestedObject({ obj, user });-- expect(result).toEqual({- headers: ['Authorization: Bearer test-api-key-value', 'X-User-Id: user-123'],- values: [1, 2, 3],- mixed: ['string', 42, true, 'user-123'],- });- });-- it('should handle deeply nested structures', () => {- const user = { id: 'user-123' };- const obj = {- level1: {- level2: {- level3: {- user_id: '{{LIBRECHAT_USER_ID}}',- settings: {- api_key: '${TEST_API_KEY}',- enabled: true,- },- },- },- },- };-- const result = resolveNestedObject({ obj, user });-- expect(result).toEqual({- level1: {- level2: {- level3: {- user_id: 'user-123',- settings: {- api_key: 'test-api-key-value',- enabled: true,- },- },- },- },- });- });-- it('should preserve all primitive types', () => {- const obj = {- string: 'text',- number: 42,- float: 3.14,- boolean_true: true,- boolean_false: false,- null_value: null,- undefined_value: undefined,- };-- const result = resolveNestedObject({ obj });-- expect(result).toEqual(obj);- });-- it('should handle empty objects and arrays', () => {- const obj = {- empty_object: {},- empty_array: [],- nested: {- also_empty: {},- },- };-- const result = resolveNestedObject({ obj });-- expect(result).toEqual(obj);- });-- it('should handle body placeholders in nested objects', () => {- const body = {- conversationId: 'conv-123',- parentMessageId: 'parent-456',- messageId: 'msg-789',- };- const obj = {- metadata: {- conversation: '{{LIBRECHAT_BODY_CONVERSATIONID}}',- parent: '{{LIBRECHAT_BODY_PARENTMESSAGEID}}',- count: 5,- },- };-- const result = resolveNestedObject({ obj, body });-- expect(result).toEqual({- metadata: {- conversation: 'conv-123',- parent: 'parent-456',- count: 5,- },- });- });-- it('should handle custom user variables in nested objects', () => {- const customUserVars = {- CUSTOM_TOKEN: 'secret-token',- REGION: 'us-west-1',- };- const obj = {- auth: {- token: '{{CUSTOM_TOKEN}}',- region: '{{REGION}}',- timeout: 3000,- },- };-- const result = resolveNestedObject({ obj, customUserVars });-- expect(result).toEqual({- auth: {- token: 'secret-token',- region: 'us-west-1',- timeout: 3000,- },- });- });-- it('should handle mixed placeholders in nested objects', () => {- const user = { id: 'user-123', email: '[email protected]' };- const customUserVars = { CUSTOM_VAR: 'custom-value' };- const body = { conversationId: 'conv-456' };-- const obj = {- config: {- user_id: '{{LIBRECHAT_USER_ID}}',- custom: '{{CUSTOM_VAR}}',- api_key: '${TEST_API_KEY}',- conversation: '{{LIBRECHAT_BODY_CONVERSATIONID}}',- nested: {- email: '{{LIBRECHAT_USER_EMAIL}}',- port: 8080,- },- },- };-- const result = resolveNestedObject({ obj, user, customUserVars, body });-- expect(result).toEqual({- config: {- user_id: 'user-123',- custom: 'custom-value',- api_key: 'test-api-key-value',- conversation: 'conv-456',- nested: {- email: '[email protected]',- port: 8080,- },- },- });- });-- it('should handle Bedrock additionalModelRequestFields example', () => {- const obj = {- thinking: {- type: 'enabled',- budget_tokens: 2000,- },- anthropic_beta: ['output-128k-2025-02-19'],- };-- const result = resolveNestedObject({ obj });-- expect(result).toEqual({- thinking: {- type: 'enabled',- budget_tokens: 2000,- },- anthropic_beta: ['output-128k-2025-02-19'],- });-- expect(typeof result.thinking).toBe('object');- expect(Array.isArray(result.anthropic_beta)).toBe(true);- expect(result.thinking).not.toBe('[object Object]');- });-- it('should return undefined when obj is undefined', () => {- const result = resolveNestedObject({ obj: undefined });- expect(result).toBeUndefined();- });-- it('should return null when obj is null', () => {- const result = resolveNestedObject({ obj: null });- expect(result).toBeNull();- });-- it('should handle arrays of objects', () => {- const user = { id: 'user-123' };- const obj = {- items: [- { name: 'item1', user: '{{LIBRECHAT_USER_ID}}', count: 1 },- { name: 'item2', user: '{{LIBRECHAT_USER_ID}}', count: 2 },- ],- };-- const result = resolveNestedObject({ obj, user });-- expect(result).toEqual({- items: [- { name: 'item1', user: 'user-123', count: 1 },- { name: 'item2', user: 'user-123', count: 2 },- ],- });- });-- it('should not modify the original object', () => {- const user = { id: 'user-123' };- const originalObj = {- thinking: {- type: 'enabled',- budget_tokens: 2000,- user_id: '{{LIBRECHAT_USER_ID}}',- },- };-- const result = resolveNestedObject({ obj: originalObj, user });-- expect(result.thinking.user_id).toBe('user-123');- expect(originalObj.thinking.user_id).toBe('{{LIBRECHAT_USER_ID}}');- });-});-describe('processMCPEnv', () => {beforeEach(() => {process.env.TEST_API_KEY = 'test-api-key-value';diff --git a/packages/api/src/utils/env.ts b/packages/api/src/utils/env.tsindex 70573ae982..a58d6949bd 100644--- a/packages/api/src/utils/env.ts+++ b/packages/api/src/utils/env.ts@@ -556,74 +556,6 @@ export function processMCPEnv(params: {return newObj;}-/**- * Recursively processes a value, replacing placeholders in strings while preserving structure- * @param value - The value to process (can be string, number, boolean, array, object, etc.)- * @param options - Processing options- * @returns The processed value with the same structure- */-function processValue(- value: unknown,- options: {- customUserVars?: Record<string, string>;- user?: IUser;- body?: RequestBody;- },-): unknown {- if (typeof value === 'string') {- return processSingleValue({- originalValue: value,- customUserVars: options.customUserVars,- user: options.user,- body: options.body,- });- }-- if (Array.isArray(value)) {- return value.map((item) => processValue(item, options));- }-- if (value !== null && typeof value === 'object') {- const processed: Record<string, unknown> = {};- for (const [key, val] of Object.entries(value)) {- processed[key] = processValue(val, options);- }- return processed;- }-- return value;-}--/**- * Recursively resolves placeholders in a nested object structure while preserving types.- * Only processes string values - leaves numbers, booleans, arrays, and nested objects intact.- *- * @param options - Configuration object- * @param options.obj - The object to process- * @param options.user - Optional user object for replacing user field placeholders- * @param options.body - Optional request body object for replacing body field placeholders- * @param options.customUserVars - Optional custom user variables to replace placeholders- * @returns The processed object with placeholders replaced in string values- */-export function resolveNestedObject<T = unknown>(options?: {- obj: T | undefined;- user?: Partial<IUser> | { id: string };- body?: RequestBody;- customUserVars?: Record<string, string>;-}): T {- const { obj, user, body, customUserVars } = options ?? {};-- if (!obj) {- return obj as T;- }-- return processValue(obj, {- customUserVars,- user: user as IUser,- body,- }) as T;-}-/*** Resolves header values by replacing user placeholders, body variables, custom variables, and environment variables.* Automatically encodes non-ASCII characters for header safety.diff --git a/packages/api/src/utils/files.ts b/packages/api/src/utils/files.tsindex 5be59b27aa..8f6ff5f118 100644--- a/packages/api/src/utils/files.ts+++ b/packages/api/src/utils/files.ts@@ -527,19 +527,3 @@ export async function readFileAsBuffer(const content = await readFile(filePath);return { content, bytes };}--/**- * Reads a JSON file asynchronously- *- * @param filePath - Path to the JSON file to read- * @param options - Options for reading the file- * @returns Promise resolving to the parsed JSON object- * @throws Error if the file cannot be read or parsed- */-export async function readJsonFile<T = unknown>(- filePath: string,- options: Omit<ReadFileOptions, 'encoding'> = {},-): Promise<T> {- const { content } = await readFileAsString(filePath, { ...options, encoding: 'utf8' });- return JSON.parse(content);-}diff --git a/packages/api/src/utils/generators.ts b/packages/api/src/utils/generators.tsindex 2466e4d3b3..951d45faa1 100644--- a/packages/api/src/utils/generators.ts+++ b/packages/api/src/utils/generators.ts@@ -1,12 +1,9 @@import fetch from 'node-fetch';+import { sleep } from '@librechat/agents';import { logger } from '@librechat/data-schemas';-import { GraphEvents, sleep } from '@librechat/agents';-import type { Response as ServerResponse } from 'express';import type { Agent as HttpsAgent } from 'node:https';import type { Agent as HttpAgent } from 'node:http';import type { URL as NodeURL } from 'node:url';-import type { ServerSentEvent } from '~/types';-import { sendEvent } from './events';type SSRFSafeAgents = {httpAgent: HttpAgent;@@ -63,35 +60,6 @@ export function createFetch({};}-/**- * Creates event handlers for stream events that don't capture client references- * @param res - The response object to send events to- * @returns Object containing handler functions- */-export function createStreamEventHandlers(res: ServerResponse): {- on_run_step: (event: ServerSentEvent) => void;- on_message_delta: (event: ServerSentEvent) => void;- on_reasoning_delta: (event: ServerSentEvent) => void;-} {- return {- [GraphEvents.ON_RUN_STEP]: function (event: ServerSentEvent): void {- if (res) {- sendEvent(res, event);- }- },- [GraphEvents.ON_MESSAGE_DELTA]: function (event: ServerSentEvent): void {- if (res) {- sendEvent(res, event);- }- },- [GraphEvents.ON_REASONING_DELTA]: function (event: ServerSentEvent): void {- if (res) {- sendEvent(res, event);- }- },- };-}-/*** @deprecated No longer used internally: stream pacing lives in* `@librechat/agents` (adaptive smoothing via `_lc_stream_delay` /diff --git a/packages/api/src/utils/oidc.ts b/packages/api/src/utils/oidc.tsindex b2516cd754..04b19f752f 100644--- a/packages/api/src/utils/oidc.ts+++ b/packages/api/src/utils/oidc.ts@@ -303,19 +303,3 @@ export function processOpenIDPlaceholders(return processedValue;}--export function createBearerAuthHeader(tokenInfo: OpenIDTokenInfo | null): string {- if (!tokenInfo || !tokenInfo.accessToken) {- return '';- }-- return `Bearer ${tokenInfo.accessToken}`;-}--export function isOpenIDAvailable(): boolean {- const openidClientId = process.env.OPENID_CLIENT_ID;- const openidClientSecret = process.env.OPENID_CLIENT_SECRET;- const openidIssuer = process.env.OPENID_ISSUER;-- return !!(openidClientId && openidClientSecret && openidIssuer);-}diff --git a/packages/api/src/utils/tokens.spec.ts b/packages/api/src/utils/tokens.spec.tsindex d1880dd517..09f6858711 100644--- a/packages/api/src/utils/tokens.spec.ts+++ b/packages/api/src/utils/tokens.spec.ts@@ -1,6 +1,6 @@import { EModelEndpoint } from 'librechat-data-provider';import type { EndpointTokenConfig } from '~/types';-import { getModelMaxTokens, getModelMaxOutputTokens, findMatchingPattern } from './tokens';+import { getModelMaxTokens, findMatchingPattern } from './tokens';describe('Bedrock OpenAI context windows', () => {const models = [@@ -87,24 +87,10 @@ describe('future Claude context windows', () => {});});-describe('getModelMaxOutputTokens partial-override fallback', () => {- const partialOverride: EndpointTokenConfig = {- 'custom-model': { prompt: 1, completion: 2, context: 32000, output: 4096 },- };-- it('falls back to the built-in map for a model absent from a partial override', () => {- const fallback = getModelMaxOutputTokens('gpt-4o', EModelEndpoint.openAI, partialOverride);- const builtin = getModelMaxOutputTokens('gpt-4o', EModelEndpoint.openAI);- expect(fallback).toBe(builtin);- expect(fallback).toBeGreaterThan(0);- });-});-describe('gpt-5.6 tiers', () => {- it('resolves 1.05M context and 128K output for every tier and the sol alias', () => {+ it('resolves 1.05M context for every tier and the sol alias', () => {for (const model of ['gpt-5.6', 'gpt-5.6-sol', 'gpt-5.6-terra', 'gpt-5.6-luna']) {expect(getModelMaxTokens(model, EModelEndpoint.openAI)).toBe(1050000);- expect(getModelMaxOutputTokens(model, EModelEndpoint.openAI)).toBe(128000);}});@@ -142,10 +128,9 @@ describe('Gemini 3.8 Flash', () => {});describe('GPT point releases', () => {- it('inherit their family context window and output limit', () => {+ it('inherit their family context window', () => {for (const model of ['gpt-6.1-sol', 'gpt-6.1-sol-2026-10-01', 'openai/gpt-6.1-sol']) {expect(getModelMaxTokens(model, EModelEndpoint.openAI)).toBe(1050000);- expect(getModelMaxOutputTokens(model, EModelEndpoint.openAI)).toBe(128000);}expect(getModelMaxTokens('gpt-6.2-astra', EModelEndpoint.openAI)).toBe(1050000);expect(getModelMaxTokens('us.openai.gpt-6.1-sol', EModelEndpoint.bedrock)).toBe(950000);@@ -168,9 +153,8 @@ describe('GPT point releases', () => {});describe('GPT-6 Astra', () => {- it('resolves 1.05M context and 128K output', () => {+ it('resolves 1.05M context', () => {expect(getModelMaxTokens('gpt-6-astra', EModelEndpoint.openAI)).toBe(1050000);- expect(getModelMaxOutputTokens('gpt-6-astra', EModelEndpoint.openAI)).toBe(128000);});it('matches its own key for snapshots and provider prefixes', () => {@@ -180,7 +164,6 @@ describe('GPT-6 Astra', () => {'gpt-6-astra-2026-04-30/openai',]) {expect(getModelMaxTokens(model, EModelEndpoint.openAI)).toBe(1050000);- expect(getModelMaxOutputTokens(model, EModelEndpoint.openAI)).toBe(128000);}});});@@ -319,7 +302,6 @@ describe('Opus 5.5 token limits', () => {'global.anthropic.claude-opus-5-5',])('resolves %s to the existing modern Claude profile', (model) => {expect(getModelMaxTokens(model)).toBe(1000000);- expect(getModelMaxOutputTokens(model)).toBe(128000);});});@@ -331,9 +313,7 @@ describe('Sonnet 5.5 token limits', () => {'global.anthropic.claude-sonnet-5-5',])('resolves %s to the modern Claude profile', (model) => {expect(getModelMaxTokens(model)).toBe(1000000);- expect(getModelMaxOutputTokens(model)).toBe(128000);expect(getModelMaxTokens(model, EModelEndpoint.anthropic)).toBe(1000000);- expect(getModelMaxOutputTokens(model, EModelEndpoint.anthropic)).toBe(128000);});});@@ -341,7 +321,6 @@ describe.each(['gpt-6-sol', 'gpt-6-luna'])('%s token limits', (model) => {it('resolves exact, snapshot, and provider-prefixed IDs', () => {for (const name of [model, `${model}-2026-09-22`, `openai/${model}`]) {expect(getModelMaxTokens(name, EModelEndpoint.openAI)).toBe(1050000);- expect(getModelMaxOutputTokens(name, EModelEndpoint.openAI)).toBe(128000);}});});diff --git a/packages/api/src/utils/tokens.ts b/packages/api/src/utils/tokens.tsindex 50a76e45ff..ad07cc13b9 100644--- a/packages/api/src/utils/tokens.ts+++ b/packages/api/src/utils/tokens.ts@@ -1,10 +1,5 @@import z from 'zod';-import {- EModelEndpoint,- supportsContext1m,- supportsOutput128k,- gptPointReleaseFamily,-} from 'librechat-data-provider';+import { EModelEndpoint, supportsContext1m, gptPointReleaseFamily } from 'librechat-data-provider';import type { EndpointTokenConfig, TokenConfig } from '~/types';/**@@ -201,10 +196,6 @@ const anthropicModels = {};const ANTHROPIC_CONTEXT_1M = 1000000;-const ANTHROPIC_OUTPUT_128K = 128000;-const ANTHROPIC_SONNET_4_6_PLUS_OUTPUT = 128000;-const ANTHROPIC_SONNET_4_6_PLUS_PATTERN =- /(?:claude-sonnet[-.]?4[-.]?(?:[6-9]|\d{2})|claude[-.]?4[-.]?(?:[6-9]|\d{2})[-.]?sonnet)(?=$|[^0-9])/;function usesAnthropicContextMap(endpoint: EModelEndpoint): boolean {return (@@ -223,23 +214,6 @@ function getAnthropicContext1m(modelName: string, endpoint: EModelEndpoint): numreturn ANTHROPIC_CONTEXT_1M;}-function getAnthropicSonnet46PlusOutput(- modelName: string,- endpoint: EModelEndpoint,-): number | undefined {- if (endpoint !== EModelEndpoint.anthropic || !ANTHROPIC_SONNET_4_6_PLUS_PATTERN.test(modelName)) {- return undefined;- }- return ANTHROPIC_SONNET_4_6_PLUS_OUTPUT;-}--function getAnthropicOutput128k(modelName: string, endpoint: EModelEndpoint): number | undefined {- if (!usesAnthropicContextMap(endpoint) || !supportsOutput128k(modelName)) {- return undefined;- }- return ANTHROPIC_OUTPUT_128K;-}-const deepseekModels = {deepseek: 128000,'deepseek-chat': 128000,@@ -520,87 +494,6 @@ export const maxTokensMap: Record<string, Record<string, number>> = {[EModelEndpoint.bedrock]: bedrockModels,};-export const modelMaxOutputs = {- o1: 32268, // -500 from max: 32,768- 'o1-mini': 65136, // -500 from max: 65,536- 'o1-preview': 32268, // -500 from max: 32,768- 'gpt-5': 128000,- 'gpt-5.1': 128000,- 'gpt-5.2': 128000,- 'gpt-5.3': 128000,- 'gpt-5.4': 128000,- 'gpt-5.4-pro': 128000,- 'gpt-5.4-mini': 128000,- 'gpt-5.4-nano': 128000,- 'gpt-5.5': 128000,- 'gpt-5.5-pro': 128000,- 'gpt-5.6': 128000,- 'gpt-5.6-terra': 128000,- 'gpt-5.6-luna': 128000,- 'gpt-6-astra': 128000,- 'gpt-6-sol': 128000,- 'gpt-6-luna': 128000,- 'chat-latest': 128000,- 'gpt-5-mini': 128000,- 'gpt-5-nano': 128000,- 'gpt-5-pro': 128000,- 'gpt-5.2-pro': 128000,- 'gpt-oss-20b': 131000,- 'gpt-oss-120b': 131000,- system_default: 32000,-};--/** Outputs from https://docs.anthropic.com/en/docs/about-claude/models/all-models#model-names */-const anthropicMaxOutputs = {- 'claude-3-haiku': 4096,- 'claude-3-sonnet': 4096,- 'claude-3-opus': 4096,- 'claude-haiku-4-5': 64000,- 'claude-sonnet-4': 64000,- 'claude-sonnet-4-6': 128000,- 'claude-sonnet-4.6': 128000,- 'claude-sonnet-4-7': 128000,- 'claude-sonnet-4.7': 128000,- 'claude-sonnet-4-8': 128000,- 'claude-sonnet-4.8': 128000,- 'claude-sonnet-4-9': 128000,- 'claude-sonnet-4.9': 128000,- 'claude-sonnet-5': 128000,- 'claude-opus-4': 32000,- 'claude-opus-4-5': 64000,- 'claude-opus-4-6': 128000,- 'claude-opus-4-7': 128000,- 'claude-opus-4-8': 128000,- 'claude-opus-5-5': 128000,- 'claude-opus-5.5': 128000,- 'claude-opus-5': 128000,- 'claude-fable-5': 128000,- 'claude-mythos-5': 128000,- 'claude-fable-5-1': 128000,- 'claude-mythos-5-1': 128000,- 'claude-3.5-sonnet': 8192,- 'claude-3-5-sonnet': 8192,- 'claude-3.7-sonnet': 128000,- 'claude-3-7-sonnet': 128000,-};--/** Outputs from https://api-docs.deepseek.com/quick_start/pricing */-const deepseekMaxOutputs = {- deepseek: 8000, // deepseek-chat default: 4K, max: 8K- 'deepseek-chat': 8000,- 'deepseek-reasoner': 64000, // default: 32K, max: 64K- 'deepseek-r1': 64000,- 'deepseek-v3': 8000,- 'deepseek.r1': 64000,-};--export const maxOutputTokensMap: Record<string, Record<string, number>> = {- [EModelEndpoint.anthropic]: anthropicMaxOutputs,- [EModelEndpoint.azureOpenAI]: modelMaxOutputs,- [EModelEndpoint.openAI]: { ...modelMaxOutputs, ...deepseekMaxOutputs },- [EModelEndpoint.custom]: { ...modelMaxOutputs, ...deepseekMaxOutputs },-};-/*** Any model-keyed map. Matching reads keys only and never inspects a value, so* the value type is deliberately open rather than a union that every caller has@@ -741,41 +634,6 @@ export function getModelMaxTokens(return getModelTokenValue(modelName, maxTokensMap[endpoint as keyof typeof maxTokensMap]);}-/**- * Retrieves the maximum output tokens for a given model name.- *- * @param modelName - The name of the model to look up.- * @param endpoint - The endpoint (default is 'openAI').- * @param [endpointTokenConfig] - Token Config for current endpoint to use for max tokens lookup- * @returns The maximum output tokens for the given model or undefined if no match is found.- */-export function getModelMaxOutputTokens(- modelName: string,- endpoint: EModelEndpoint = EModelEndpoint.openAI,- endpointTokenConfig?: EndpointTokenConfig,-): number | undefined {- /** Partial override fallback — see getModelMaxTokens */- if (endpointTokenConfig != null) {- const overrideValue = getModelTokenValue(modelName, endpointTokenConfig, 'output');- if (overrideValue != null) {- return overrideValue;- }- }- const output128kValue = getAnthropicOutput128k(modelName, endpoint);- if (output128kValue != null) {- return output128kValue;- }- const sonnet46PlusValue = getAnthropicSonnet46PlusOutput(modelName, endpoint);- if (sonnet46PlusValue != null) {- return sonnet46PlusValue;- }- return getModelTokenValue(- modelName,- maxOutputTokensMap[endpoint as keyof typeof maxOutputTokensMap],- 'output',- );-}-/*** Retrieves the model name key for a given model name input. If the exact model name isn't found,* it searches for partial matches within the model name, checking keys in reverse order.diff --git a/packages/api/tsconfig-paths-bootstrap.mjs b/packages/api/tsconfig-paths-bootstrap.mjsdeleted file mode 100644index 5b1c8bd168..0000000000--- a/packages/api/tsconfig-paths-bootstrap.mjs+++ /dev/null@@ -1,23 +0,0 @@-import path from 'path';-import { pathToFileURL } from 'url';-// @ts-ignore-import { resolve as resolveTs } from 'ts-node/esm';-import * as tsConfigPaths from 'tsconfig-paths';--// @ts-ignore-const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig(- path.resolve('./tsconfig.json'), // Updated path-);-const matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, paths);--export function resolve(specifier, context, defaultResolve) {- const match = matchPath(specifier);- if (match) {- return resolveTs(pathToFileURL(match).href, context, defaultResolve);- }- return resolveTs(specifier, context, defaultResolve);-}--// @ts-ignore-export { load, getFormat, transformSource } from 'ts-node/esm';-// node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ../../api/demo/everything.ts\ No newline at end of filediff --git a/src/tests/oidc-integration.test.ts b/src/tests/oidc-integration.test.tsdeleted file mode 100644index 654f0e7df8..0000000000--- a/src/tests/oidc-integration.test.ts+++ /dev/null@@ -1,481 +0,0 @@-import { describe, it, expect, jest, beforeEach } from '@jest/globals';-import {- extractOpenIDTokenInfo,- processOpenIDPlaceholders,- isOpenIDTokenValid,- createBearerAuthHeader,- isOpenIDAvailable,- type OpenIDTokenInfo,-} from '../packages/api/src/utils/oidc';-import { processMCPEnv, resolveHeaders } from '../packages/api/src/utils/env';-import type { TUser } from 'librechat-data-provider';-import type { IUser } from '@librechat/data-schemas';--// Mock logger to avoid console output during tests-jest.mock('@librechat/data-schemas', () => ({- logger: {- error: jest.fn(),- warn: jest.fn(),- info: jest.fn(),- },-}));--describe('OpenID Connect Federated Provider Token Integration', () => {- // Mock user with Cognito tokens- const mockCognitoUser: Partial<IUser> = {- id: 'user-123',- email: '[email protected]',- name: 'Test User',- provider: 'openid',- openidId: 'cognito-user-123',- federatedTokens: {- access_token: 'cognito-access-token-123',- id_token:- 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjb2duaXRvLXVzZXItMTIzIiwiZW1haWwiOiJ0ZXN0QGV4YW1wbGUuY29tIiwibmFtZSI6IlRlc3QgVXNlciIsImV4cCI6MTcwMDAwMDAwMH0.fake-signature',- expires_at: Math.floor(Date.now() / 1000) + 3600, // Expires in 1 hour- },- };-- const mockExpiredCognitoUser: Partial<IUser> = {- ...mockCognitoUser,- federatedTokens: {- access_token: 'expired-cognito-token',- id_token: 'expired-cognito-id-token',- expires_at: Math.floor(Date.now() / 1000) - 3600, // Expired 1 hour ago- },- };-- // Mock user with tokens in alternative location- const mockOpenIDTokensUser: Partial<IUser> = {- id: 'user-456',- email: '[email protected]',- name: 'Alt User',- provider: 'openid',- openidId: 'alt-user-456',- openidTokens: {- access_token: 'alt-access-token-456',- id_token: 'alt-id-token-789',- expires_at: Math.floor(Date.now() / 1000) + 3600,- },- };-- beforeEach(() => {- jest.clearAllMocks();- });-- describe('extractOpenIDTokenInfo', () => {- it('should extract federated provider token info from Cognito user', () => {- const tokenInfo = extractOpenIDTokenInfo(mockCognitoUser as IUser);-- expect(tokenInfo).toEqual({- accessToken: 'cognito-access-token-123',- idToken: expect.stringContaining('eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9'),- expiresAt: expect.any(Number),- userId: 'cognito-user-123',- userEmail: '[email protected]',- userName: 'Test User',- claims: expect.objectContaining({- sub: 'cognito-user-123',- email: '[email protected]',- name: 'Test User',- }),- });- });-- it('should extract tokens from alternative storage location', () => {- const tokenInfo = extractOpenIDTokenInfo(mockOpenIDTokensUser as IUser);-- expect(tokenInfo).toEqual({- accessToken: 'alt-access-token-456',- idToken: 'alt-id-token-789',- expiresAt: expect.any(Number),- userId: 'alt-user-456',- userEmail: '[email protected]',- userName: 'Alt User',- });- });-- it('should return null for non-OpenID user', () => {- const nonOpenIDUser: Partial<IUser> = {- id: 'user-123',- provider: 'google',- email: '[email protected]',- };-- const tokenInfo = extractOpenIDTokenInfo(nonOpenIDUser as IUser);- expect(tokenInfo).toBeNull();- });-- it('should return null for null/undefined user', () => {- expect(extractOpenIDTokenInfo(null)).toBeNull();- expect(extractOpenIDTokenInfo(undefined)).toBeNull();- });-- it('should handle JWT parsing errors gracefully', () => {- const userWithMalformedJWT: Partial<IUser> = {- ...mockCognitoUser,- federatedTokens: {- access_token: 'valid-access-token',- id_token: 'malformed.jwt.token',- expires_at: Math.floor(Date.now() / 1000) + 3600,- },- };-- const tokenInfo = extractOpenIDTokenInfo(userWithMalformedJWT as IUser);-- expect(tokenInfo).toBeDefined();- expect(tokenInfo?.accessToken).toBe('valid-access-token');- expect(tokenInfo?.claims).toBeUndefined();- });- });-- describe('isOpenIDTokenValid', () => {- it('should return true for valid Cognito token', () => {- const tokenInfo = extractOpenIDTokenInfo(mockCognitoUser as IUser);- expect(isOpenIDTokenValid(tokenInfo)).toBe(true);- });-- it('should return false for expired Cognito token', () => {- const tokenInfo = extractOpenIDTokenInfo(mockExpiredCognitoUser as IUser);- expect(isOpenIDTokenValid(tokenInfo)).toBe(false);- });-- it('should return false for null token info', () => {- expect(isOpenIDTokenValid(null)).toBe(false);- });-- it('should return false for token info without access token', () => {- const tokenInfo: OpenIDTokenInfo = {- userId: 'user-123',- userEmail: '[email protected]',- };- expect(isOpenIDTokenValid(tokenInfo)).toBe(false);- });- });-- describe('processOpenIDPlaceholders', () => {- const tokenInfo: OpenIDTokenInfo = {- accessToken: 'cognito-access-token-123',- idToken: 'cognito-id-token-456',- userId: 'cognito-user-789',- userEmail: '[email protected]',- userName: 'Cognito User',- expiresAt: 1700000000,- };-- it('should replace OpenID Connect token placeholders', () => {- const template = 'Bearer {{LIBRECHAT_OPENID_TOKEN}}';- const result = processOpenIDPlaceholders(template, tokenInfo);- expect(result).toBe('Bearer cognito-access-token-123');- });-- it('should replace specific OpenID Connect placeholders', () => {- const template = `- Access: {{LIBRECHAT_OPENID_ACCESS_TOKEN}}- ID: {{LIBRECHAT_OPENID_ID_TOKEN}}- User: {{LIBRECHAT_OPENID_USER_ID}}- Email: {{LIBRECHAT_OPENID_USER_EMAIL}}- Name: {{LIBRECHAT_OPENID_USER_NAME}}- Expires: {{LIBRECHAT_OPENID_EXPIRES_AT}}- `;-- const result = processOpenIDPlaceholders(template, tokenInfo);-- expect(result).toContain('Access: cognito-access-token-123');- expect(result).toContain('ID: cognito-id-token-456');- expect(result).toContain('User: cognito-user-789');- expect(result).toContain('Email: [email protected]');- expect(result).toContain('Name: Cognito User');- expect(result).toContain('Expires: 1700000000');- });-- it('should handle missing token fields gracefully', () => {- const partialTokenInfo: OpenIDTokenInfo = {- accessToken: 'partial-cognito-token',- userId: 'user-123',- };-- const template = 'Token: {{LIBRECHAT_OPENID_TOKEN}}, Email: {{LIBRECHAT_OPENID_USER_EMAIL}}';- const result = processOpenIDPlaceholders(template, partialTokenInfo);-- expect(result).toBe('Token: partial-cognito-token, Email: ');- });-- it('should return original value for null token info', () => {- const template = 'Bearer {{LIBRECHAT_OPENID_TOKEN}}';- const result = processOpenIDPlaceholders(template, null);- expect(result).toBe(template);- });- });-- describe('createBearerAuthHeader', () => {- it('should create proper Bearer header with Cognito token', () => {- const tokenInfo: OpenIDTokenInfo = {- accessToken: 'cognito-test-token-123',- };-- const header = createBearerAuthHeader(tokenInfo);- expect(header).toBe('Bearer cognito-test-token-123');- });-- it('should return empty string for null token info', () => {- const header = createBearerAuthHeader(null);- expect(header).toBe('');- });-- it('should return empty string for token info without access token', () => {- const tokenInfo: OpenIDTokenInfo = {- userId: 'user-123',- };-- const header = createBearerAuthHeader(tokenInfo);- expect(header).toBe('');- });- });-- describe('isOpenIDAvailable', () => {- const originalEnv = process.env;-- beforeEach(() => {- jest.resetModules();- process.env = { ...originalEnv };- });-- afterAll(() => {- process.env = originalEnv;- });-- it('should return true when OpenID Connect is properly configured for Cognito', () => {- process.env.OPENID_CLIENT_ID = 'cognito-client-id';- process.env.OPENID_CLIENT_SECRET = 'cognito-client-secret';- process.env.OPENID_ISSUER = 'https://cognito-idp.us-east-1.amazonaws.com/us-east-1_ABC123';-- expect(isOpenIDAvailable()).toBe(true);- });-- it('should return false when OpenID Connect is not configured', () => {- delete process.env.OPENID_CLIENT_ID;- delete process.env.OPENID_CLIENT_SECRET;- delete process.env.OPENID_ISSUER;-- expect(isOpenIDAvailable()).toBe(false);- });-- it('should return false when OpenID Connect is partially configured', () => {- process.env.OPENID_CLIENT_ID = 'cognito-client-id';- delete process.env.OPENID_CLIENT_SECRET;- delete process.env.OPENID_ISSUER;-- expect(isOpenIDAvailable()).toBe(false);- });- });-- describe('Integration with resolveHeaders', () => {- it('should resolve OpenID Connect placeholders in headers for Cognito', () => {- const headers = {- Authorization: '{{LIBRECHAT_OPENID_TOKEN}}',- 'X-User-ID': '{{LIBRECHAT_OPENID_USER_ID}}',- 'X-User-Email': '{{LIBRECHAT_OPENID_USER_EMAIL}}',- };-- const resolvedHeaders = resolveHeaders({- headers,- user: mockCognitoUser as TUser,- });-- expect(resolvedHeaders['Authorization']).toBe('cognito-access-token-123');- expect(resolvedHeaders['X-User-ID']).toBe('cognito-user-123');- expect(resolvedHeaders['X-User-Email']).toBe('[email protected]');- });-- it('should work with Bearer token format for Cognito', () => {- const headers = {- Authorization: 'Bearer {{LIBRECHAT_OPENID_TOKEN}}',- };-- const resolvedHeaders = resolveHeaders({- headers,- user: mockCognitoUser as TUser,- });-- expect(resolvedHeaders['Authorization']).toBe('Bearer cognito-access-token-123');- });-- it('should work with specific access token placeholder', () => {- const headers = {- Authorization: 'Bearer {{LIBRECHAT_OPENID_ACCESS_TOKEN}}',- 'X-Cognito-ID-Token': '{{LIBRECHAT_OPENID_ID_TOKEN}}',- };-- const resolvedHeaders = resolveHeaders({- headers,- user: mockCognitoUser as TUser,- });-- expect(resolvedHeaders['Authorization']).toBe('Bearer cognito-access-token-123');- expect(resolvedHeaders['X-Cognito-ID-Token']).toContain(- 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9',- );- });- });-- describe('Integration with processMCPEnv', () => {- it('should process OpenID Connect placeholders in MCP environment variables for Cognito', () => {- const mcpOptions = {- command: 'node',- args: ['server.js'],- env: {- COGNITO_ACCESS_TOKEN: '{{LIBRECHAT_OPENID_TOKEN}}',- USER_ID: '{{LIBRECHAT_OPENID_USER_ID}}',- USER_EMAIL: '{{LIBRECHAT_OPENID_USER_EMAIL}}',- },- };-- const processedOptions = processMCPEnv({- options: mcpOptions,- user: mockCognitoUser as TUser,- });-- expect(processedOptions.env?.['COGNITO_ACCESS_TOKEN']).toBe('cognito-access-token-123');- expect(processedOptions.env?.['USER_ID']).toBe('cognito-user-123');- expect(processedOptions.env?.['USER_EMAIL']).toBe('[email protected]');- });-- it('should process OpenID Connect placeholders in MCP headers for HTTP transport', () => {- const mcpOptions = {- type: 'sse' as const,- url: 'https://api.example.com/mcp',- headers: {- Authorization: 'Bearer {{LIBRECHAT_OPENID_ACCESS_TOKEN}}',- 'X-Cognito-User-Info': '{{LIBRECHAT_OPENID_USER_EMAIL}}',- 'X-Cognito-ID-Token': '{{LIBRECHAT_OPENID_ID_TOKEN}}',- },- };-- const processedOptions = processMCPEnv({- options: mcpOptions,- user: mockCognitoUser as TUser,- });-- expect(processedOptions.headers?.['Authorization']).toBe('Bearer cognito-access-token-123');- expect(processedOptions.headers?.['X-Cognito-User-Info']).toBe('[email protected]');- expect(processedOptions.headers?.['X-Cognito-ID-Token']).toContain(- 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9',- );- });-- it('should handle AWS-specific MCP server configuration', () => {- const awsMcpOptions = {- command: 'node',- args: ['aws-mcp-server.js'],- env: {- AWS_COGNITO_TOKEN: '{{LIBRECHAT_OPENID_ACCESS_TOKEN}}',- AWS_COGNITO_ID_TOKEN: '{{LIBRECHAT_OPENID_ID_TOKEN}}',- COGNITO_USER_SUB: '{{LIBRECHAT_OPENID_USER_ID}}',- },- };-- const processedOptions = processMCPEnv({- options: awsMcpOptions,- user: mockCognitoUser as TUser,- });-- expect(processedOptions.env?.['AWS_COGNITO_TOKEN']).toBe('cognito-access-token-123');- expect(processedOptions.env?.['AWS_COGNITO_ID_TOKEN']).toContain(- 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9',- );- expect(processedOptions.env?.['COGNITO_USER_SUB']).toBe('cognito-user-123');- });- });-- describe('Security and Edge Cases', () => {- it('should not process OpenID Connect placeholders for expired tokens', () => {- const headers = {- Authorization: 'Bearer {{LIBRECHAT_OPENID_TOKEN}}',- };-- const resolvedHeaders = resolveHeaders({- headers,- user: mockExpiredCognitoUser as TUser,- });-- // Should not replace placeholder if token is expired- expect(resolvedHeaders['Authorization']).toBe('Bearer {{LIBRECHAT_OPENID_TOKEN}}');- });-- it('should handle malformed federated token data gracefully', () => {- const malformedUser: Partial<IUser> = {- id: 'user-123',- provider: 'openid',- openidId: 'cognito-user',- federatedTokens: null, // Malformed tokens- };-- const headers = {- Authorization: 'Bearer {{LIBRECHAT_OPENID_TOKEN}}',- };-- const resolvedHeaders = resolveHeaders({- headers,- user: malformedUser as TUser,- });-- // Should not replace placeholder if token extraction fails- expect(resolvedHeaders['Authorization']).toBe('Bearer {{LIBRECHAT_OPENID_TOKEN}}');- });-- it('should handle multiple placeholder instances in same string', () => {- const template =- '{{LIBRECHAT_OPENID_TOKEN}}-{{LIBRECHAT_OPENID_TOKEN}}-{{LIBRECHAT_OPENID_USER_ID}}';-- const tokenInfo: OpenIDTokenInfo = {- accessToken: 'cognito-token123',- userId: 'cognito-user456',- };-- const result = processOpenIDPlaceholders(template, tokenInfo);- expect(result).toBe('cognito-token123-cognito-token123-cognito-user456');- });-- it('should handle users without federated tokens storage', () => {- const userWithoutTokens: Partial<IUser> = {- id: 'user-789',- provider: 'openid',- openidId: 'user-without-tokens',- email: '[email protected]',- // No federatedTokens or openidTokens- };-- const headers = {- Authorization: 'Bearer {{LIBRECHAT_OPENID_TOKEN}}',- };-- const resolvedHeaders = resolveHeaders({- headers,- user: userWithoutTokens as TUser,- });-- // Should not replace placeholder if no tokens available- expect(resolvedHeaders['Authorization']).toBe('Bearer {{LIBRECHAT_OPENID_TOKEN}}');- });-- it('should prioritize federatedTokens over openidTokens', () => {- const userWithBothTokens: Partial<IUser> = {- id: 'user-priority',- provider: 'openid',- openidId: 'priority-user',- federatedTokens: {- access_token: 'federated-priority-token',- expires_at: Math.floor(Date.now() / 1000) + 3600,- },- openidTokens: {- access_token: 'openid-fallback-token',- expires_at: Math.floor(Date.now() / 1000) + 3600,- },- };-- const tokenInfo = extractOpenIDTokenInfo(userWithBothTokens as IUser);- expect(tokenInfo?.accessToken).toBe('federated-priority-token');- });- });-});