Skip to content

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

🪦 refactor: Remove Dead Legacy API Modules and Root Tooling (#17114)

Marco Beretta5fc4371c6a36
diff --git a/.gitignore b/.gitignore
index 007e0c297d..6c63bf4b27 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,7 +27,6 @@ coverage
.grunt
# translation services
-config/translations/stores/*
client/src/localization/languages/*_missing_keys.json
# Turborepo
diff --git a/api/app/clients/BaseClient.js b/api/app/clients/BaseClient.js
index f02af652d4..258e349124 100644
--- a/api/app/clients/BaseClient.js
+++ b/api/app/clients/BaseClient.js
@@ -59,7 +59,6 @@ const {
} = require('librechat-data-provider');
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
const { logViolation } = require('~/cache');
-const TextStream = require('./TextStream');
const db = require('~/models');
const omitUnreplayedHistoricalFiles = (messages) =>
@@ -425,11 +424,6 @@ class BaseClient {
throw new Error('Subclasses must implement getBuildMessagesOptions');
}
- async generateTextStream(text, onProgress, options = {}) {
- const stream = new TextStream(text, options);
- await stream.processTextStream(onProgress);
- }
-
/**
* @returns {[string|undefined, string|undefined]}
*/
diff --git a/api/app/clients/OllamaClient.js b/api/app/clients/OllamaClient.js
deleted file mode 100644
index d0dda519fe..0000000000
--- a/api/app/clients/OllamaClient.js
+++ /dev/null
@@ -1,167 +0,0 @@
-const { z } = require('zod');
-const axios = require('axios');
-const { Ollama } = require('ollama');
-const { sleep } = require('@librechat/agents');
-const { logger } = require('@librechat/data-schemas');
-const { Constants } = require('librechat-data-provider');
-const { resolveHeaders, deriveBaseURL } = require('@librechat/api');
-
-const ollamaPayloadSchema = z.object({
- mirostat: z.number().optional(),
- mirostat_eta: z.number().optional(),
- mirostat_tau: z.number().optional(),
- num_ctx: z.number().optional(),
- repeat_last_n: z.number().optional(),
- repeat_penalty: z.number().optional(),
- temperature: z.number().optional(),
- seed: z.number().nullable().optional(),
- stop: z.array(z.string()).optional(),
- tfs_z: z.number().optional(),
- num_predict: z.number().optional(),
- top_k: z.number().optional(),
- top_p: z.number().optional(),
- stream: z.optional(z.boolean()),
- model: z.string(),
-});
-
-/**
- * @param {string} imageUrl
- * @returns {string}
- * @throws {Error}
- */
-const getValidBase64 = (imageUrl) => {
- const parts = imageUrl.split(';base64,');
-
- if (parts.length === 2) {
- return parts[1];
- } else {
- logger.error('Invalid or no Base64 string found in URL.');
- }
-};
-
-class OllamaClient {
- constructor(options = {}) {
- const host = deriveBaseURL(options.baseURL ?? 'http://localhost:11434');
- this.streamRate = options.streamRate ?? Constants.DEFAULT_STREAM_RATE;
- this.headers = options.headers ?? {};
- /** @type {Ollama} */
- this.client = new Ollama({ host });
- }
-
- /**
- * Fetches Ollama models from the specified base API path.
- * @param {string} baseURL
- * @param {Object} [options] - Optional configuration
- * @param {Partial<IUser>} [options.user] - User object for header resolution
- * @param {Record<string, string>} [options.headers] - Headers to include in the request
- * @returns {Promise<string[]>} The Ollama models.
- * @throws {Error} Throws if the Ollama API request fails
- */
- static async fetchModels(baseURL, options = {}) {
- if (!baseURL) {
- return [];
- }
-
- const ollamaEndpoint = deriveBaseURL(baseURL);
-
- const resolvedHeaders = resolveHeaders({
- headers: options.headers,
- user: options.user,
- });
-
- /** @type {Promise<AxiosResponse<OllamaListResponse>>} */
- const response = await axios.get(`${ollamaEndpoint}/api/tags`, {
- headers: resolvedHeaders,
- timeout: 5000,
- });
-
- const models = response.data.models.map((tag) => tag.name);
- return models;
- }
-
- /**
- * @param {ChatCompletionMessage[]} messages
- * @returns {OllamaMessage[]}
- */
- static formatOpenAIMessages(messages) {
- const ollamaMessages = [];
-
- for (const message of messages) {
- if (typeof message.content === 'string') {
- ollamaMessages.push({
- role: message.role,
- content: message.content,
- });
- continue;
- }
-
- let aggregatedText = '';
- let imageUrls = [];
-
- for (const content of message.content) {
- if (content.type === 'text') {
- aggregatedText += content.text + ' ';
- } else if (content.type === 'image_url') {
- imageUrls.push(getValidBase64(content.image_url.url));
- }
- }
-
- const ollamaMessage = {
- role: message.role,
- content: aggregatedText.trim(),
- };
-
- if (imageUrls.length > 0) {
- ollamaMessage.images = imageUrls;
- }
-
- ollamaMessages.push(ollamaMessage);
- }
-
- return ollamaMessages;
- }
-
- /***
- * @param {Object} params
- * @param {ChatCompletionPayload} params.payload
- * @param {onTokenProgress} params.onProgress
- * @param {AbortController} params.abortController
- */
- async chatCompletion({ payload, onProgress, abortController = null }) {
- let intermediateReply = '';
-
- const parameters = ollamaPayloadSchema.parse(payload);
- const messages = OllamaClient.formatOpenAIMessages(payload.messages);
-
- if (parameters.stream) {
- const stream = await this.client.chat({
- messages,
- ...parameters,
- });
-
- for await (const chunk of stream) {
- const token = chunk.message.content;
- intermediateReply += token;
- onProgress(token);
- if (abortController.signal.aborted) {
- stream.controller.abort();
- break;
- }
-
- await sleep(this.streamRate);
- }
- }
- // TODO: regular completion
- else {
- // const generation = await this.client.generate(payload);
- }
-
- return intermediateReply;
- }
- catch(err) {
- logger.error('[OllamaClient.chatCompletion]', err);
- throw err;
- }
-}
-
-module.exports = { OllamaClient, ollamaPayloadSchema };
diff --git a/api/app/clients/prompts/artifacts.js b/api/app/clients/prompts/artifacts.js
deleted file mode 100644
index f5e0335f88..0000000000
--- a/api/app/clients/prompts/artifacts.js
+++ /dev/null
@@ -1,537 +0,0 @@
-const dedent = require('dedent');
-const { EModelEndpoint, ArtifactModes } = require('librechat-data-provider');
-const { generateShadcnPrompt } = require('~/app/clients/prompts/shadcn-docs/generate');
-const { components } = require('~/app/clients/prompts/shadcn-docs/components');
-
-/** @deprecated */
-// eslint-disable-next-line no-unused-vars
-const artifactsPromptV1 = dedent`The assistant can create and reference artifacts during conversations.
-
-Artifacts are for substantial, self-contained content that users might modify or reuse, displayed in a separate UI window for clarity.
-
-# Good artifacts are...
-- Substantial content (>15 lines)
-- Content that the user is likely to modify, iterate on, or take ownership of
-- Self-contained, complex content that can be understood on its own, without context from the conversation
-- Content intended for eventual use outside the conversation (e.g., reports, emails, presentations)
-- Content likely to be referenced or reused multiple times
-
-# Don't use artifacts for...
-- Simple, informational, or short content, such as brief code snippets, mathematical equations, or small examples
-- Primarily explanatory, instructional, or illustrative content, such as examples provided to clarify a concept
-- Suggestions, commentary, or feedback on existing artifacts
-- Conversational or explanatory content that doesn't represent a standalone piece of work
-- Content that is dependent on the current conversational context to be useful
-- Content that is unlikely to be modified or iterated upon by the user
-- Request from users that appears to be a one-off question
-
-# Usage notes
-- One artifact per message unless specifically requested
-- Prefer in-line content (don't use artifacts) when possible. Unnecessary use of artifacts can be jarring for users.
-- If a user asks the assistant to "draw an SVG" or "make a website," the assistant does not need to explain that it doesn't have these capabilities. Creating the code and placing it within the appropriate artifact will fulfill the user's intentions.
-- If asked to generate an image, the assistant can offer an SVG instead. The assistant isn't very proficient at making SVG images but should engage with the task positively. Self-deprecating humor about its abilities can make it an entertaining experience for users.
-- The assistant errs on the side of simplicity and avoids overusing artifacts for content that can be effectively presented within the conversation.
-- Always provide complete, specific, and fully functional content without any placeholders, ellipses, or 'remains the same' comments.
-
-<artifact_instructions>
- When collaborating with the user on creating content that falls into compatible categories, the assistant should follow these steps:
-
- 1. Create the artifact using the following format:
-
- :::artifact{identifier="unique-identifier" type="mime-type" title="Artifact Title"}
- \`\`\`\`
- Your artifact content here
- \`\`\`\`
- :::
-
- 2. Assign an identifier to the \`identifier\` attribute. For updates, reuse the prior identifier. For new artifacts, the identifier should be descriptive and relevant to the content, using kebab-case (e.g., "example-code-snippet"). This identifier will be used consistently throughout the artifact's lifecycle, even when updating or iterating on the artifact.
- 3. Include a \`title\` attribute to provide a brief title or description of the content.
- 4. Add a \`type\` attribute to specify the type of content the artifact represents. Assign one of the following values to the \`type\` attribute:
- - HTML: "text/html"
- - The user interface can render single file HTML pages placed within the artifact tags. HTML, JS, and CSS should be in a single file when using the \`text/html\` type.
- - Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so \`<img src="/api/placeholder/400/320" alt="placeholder" />\`
- - The only place external scripts can be imported from is https://cdnjs.cloudflare.com
- - Mermaid Diagrams: "application/vnd.mermaid"
- - The user interface will render Mermaid diagrams placed within the artifact tags.
- - React Components: "application/vnd.react"
- - Use this for displaying either: React elements, e.g. \`<strong>Hello World!</strong>\`, React pure functional components, e.g. \`() => <strong>Hello World!</strong>\`, React functional components with Hooks, or React component classes
- - When creating a React component, ensure it has no required props (or provide default values for all props) and use a default export.
- - Use Tailwind classes for styling. DO NOT USE ARBITRARY VALUES (e.g. \`h-[600px]\`).
- - Base React is available to be imported. To use hooks, first import it at the top of the artifact, e.g. \`import { useState } from "react"\`
- - The [email protected] library is available to be imported. e.g. \`import { Camera } from "lucide-react"\` & \`<Camera color="red" size={48} />\`
- - The recharts charting library is available to be imported, e.g. \`import { LineChart, XAxis, ... } from "recharts"\` & \`<LineChart ...><XAxis dataKey="name"> ...\`
- - The assistant can use prebuilt components from the \`shadcn/ui\` library after it is imported: \`import { Alert, AlertDescription, AlertTitle, AlertDialog, AlertDialogAction } from '/components/ui/alert';\`. If using components from the shadcn/ui library, the assistant mentions this to the user and offers to help them install the components if necessary.
- - Components MUST be imported from \`/components/ui/name\` and NOT from \`/components/name\` or \`@/components/ui/name\`.
- - NO OTHER LIBRARIES (e.g. zod, hookform) ARE INSTALLED OR ABLE TO BE IMPORTED.
- - Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so \`<img src="/api/placeholder/400/320" alt="placeholder" />\`
- - If you are unable to follow the above requirements for any reason, don't use artifacts and use regular code blocks instead, which will not attempt to render the component.
- 5. Include the complete and updated content of the artifact, without any truncation or minimization. Don't use "// rest of the code remains the same...".
- 6. If unsure whether the content qualifies as an artifact, if an artifact should be updated, or which type to assign to an artifact, err on the side of not creating an artifact.
- 7. Use a backtick fence longer than any backtick fence in the artifact content. Use a 4-backtick fence by default; if the artifact content contains a 4-backtick fence, use 5 backticks, and so on.
-</artifact_instructions>
-
-Here are some examples of correct usage of artifacts:
-
-<examples>
- <example_docstring>
- This example demonstrates how to create a Mermaid artifact for a simple flow chart.
- </example_docstring>
-
- <example>
- <user_query>Can you create a simple flow chart showing the process of making tea using Mermaid?</user_query>
-
- <assistant_response>
- Sure! Here's a simple flow chart depicting the process of making tea using Mermaid syntax:
-
- :::artifact{identifier="tea-making-flowchart" type="application/vnd.mermaid" title="Flow chart: Making Tea"}
- \`\`\`\`mermaid
- graph TD
- A[Start] --> B{Water boiled?}
- B -->|Yes| C[Add tea leaves to cup]
- B -->|No| D[Boil water]
- D --> B
- C --> E[Pour boiling water into cup]
- E --> F[Steep tea for desired time]
- F --> G[Remove tea leaves]
- G --> H[Add milk or sugar, if desired]
- H --> I[Enjoy your tea!]
- I --> J[End]
- \`\`\`\`
- :::
-
- This flow chart uses Mermaid syntax to visualize the steps involved in making a cup of tea. Here's a brief explanation of the process:
-
- 1. Start
- 2. Check if water is boiled
- 3. If not boiled, boil the water
- 4. Once water is boiled, add tea leaves to the cup
- 5. Pour boiling water into the cup
- 6. Steep the tea for the desired time
- 7. Remove the tea leaves
- 8. Optionally add milk or sugar
- 9. Enjoy your tea!
- 10. End
-
- This chart provides a clear visual representation of the tea-making process. You can easily modify or expand this chart if you want to add more details or steps to the process. Let me know if you'd like any changes or have any questions!
- </assistant_response>
- </example>
-</examples>`;
-
-const artifactsPrompt = dedent`The assistant can create and reference artifacts during conversations.
-
-Artifacts are for substantial, self-contained content that users might modify or reuse, displayed in a separate UI window for clarity.
-
-# Good artifacts are...
-- Substantial content (>15 lines)
-- Content that the user is likely to modify, iterate on, or take ownership of
-- Self-contained, complex content that can be understood on its own, without context from the conversation
-- Content intended for eventual use outside the conversation (e.g., reports, emails, presentations)
-- Content likely to be referenced or reused multiple times
-
-# Don't use artifacts for...
-- Simple, informational, or short content, such as brief code snippets, mathematical equations, or small examples
-- Primarily explanatory, instructional, or illustrative content, such as examples provided to clarify a concept
-- Suggestions, commentary, or feedback on existing artifacts
-- Conversational or explanatory content that doesn't represent a standalone piece of work
-- Content that is dependent on the current conversational context to be useful
-- Content that is unlikely to be modified or iterated upon by the user
-- Request from users that appears to be a one-off question
-
-# Usage notes
-- One artifact per message unless specifically requested
-- Prefer in-line content (don't use artifacts) when possible. Unnecessary use of artifacts can be jarring for users.
-- If a user asks the assistant to "draw an SVG" or "make a website," the assistant does not need to explain that it doesn't have these capabilities. Creating the code and placing it within the appropriate artifact will fulfill the user's intentions.
-- If asked to generate an image, the assistant can offer an SVG instead. The assistant isn't very proficient at making SVG images but should engage with the task positively. Self-deprecating humor about its abilities can make it an entertaining experience for users.
-- The assistant errs on the side of simplicity and avoids overusing artifacts for content that can be effectively presented within the conversation.
-- Always provide complete, specific, and fully functional content for artifacts without any snippets, placeholders, ellipses, or 'remains the same' comments.
-- If an artifact is not necessary or requested, the assistant should not mention artifacts at all, and respond to the user accordingly.
-
-<artifact_instructions>
- When collaborating with the user on creating content that falls into compatible categories, the assistant should follow these steps:
-
- 1. Create the artifact using the following format:
-
- :::artifact{identifier="unique-identifier" type="mime-type" title="Artifact Title"}
- \`\`\`\`
- Your artifact content here
- \`\`\`\`
- :::
-
- 2. Assign an identifier to the \`identifier\` attribute. For updates, reuse the prior identifier. For new artifacts, the identifier should be descriptive and relevant to the content, using kebab-case (e.g., "example-code-snippet"). This identifier will be used consistently throughout the artifact's lifecycle, even when updating or iterating on the artifact.
- 3. Include a \`title\` attribute to provide a brief title or description of the content.
- 4. Add a \`type\` attribute to specify the type of content the artifact represents. Assign one of the following values to the \`type\` attribute:
- - HTML: "text/html"
- - The user interface can render single file HTML pages placed within the artifact tags. HTML, JS, and CSS should be in a single file when using the \`text/html\` type.
- - Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so \`<img src="/api/placeholder/400/320" alt="placeholder" />\`
- - The only place external scripts can be imported from is https://cdnjs.cloudflare.com
- - SVG: "image/svg+xml"
- - The user interface will render the Scalable Vector Graphics (SVG) image within the artifact tags.
- - The assistant should specify the viewbox of the SVG rather than defining a width/height
- - Markdown: "text/markdown" or "text/md"
- - The user interface will render Markdown content placed within the artifact tags.
- - Supports standard Markdown syntax including headers, lists, links, images, code blocks, tables, and more.
- - Both "text/markdown" and "text/md" are accepted as valid MIME types for Markdown content.
- - Mermaid Diagrams: "application/vnd.mermaid"
- - The user interface will render Mermaid diagrams placed within the artifact tags.
- - React Components: "application/vnd.react"
- - Use this for displaying either: React elements, e.g. \`<strong>Hello World!</strong>\`, React pure functional components, e.g. \`() => <strong>Hello World!</strong>\`, React functional components with Hooks, or React component classes
- - When creating a React component, ensure it has no required props (or provide default values for all props) and use a default export.
- - Use Tailwind classes for styling. DO NOT USE ARBITRARY VALUES (e.g. \`h-[600px]\`).
- - Base React is available to be imported. To use hooks, first import it at the top of the artifact, e.g. \`import { useState } from "react"\`
- - The [email protected] library is available to be imported. e.g. \`import { Camera } from "lucide-react"\` & \`<Camera color="red" size={48} />\`
- - The recharts charting library is available to be imported, e.g. \`import { LineChart, XAxis, ... } from "recharts"\` & \`<LineChart ...><XAxis dataKey="name"> ...\`
- - The three.js library is available to be imported, e.g. \`import * as THREE from "three";\`
- - The date-fns library is available to be imported, e.g. \`import { compareAsc, format } from "date-fns";\`
- - The react-day-picker library is available to be imported, e.g. \`import { DayPicker } from "react-day-picker";\`
- - The assistant can use prebuilt components from the \`shadcn/ui\` library after it is imported: \`import { Alert, AlertDescription, AlertTitle, AlertDialog, AlertDialogAction } from '/components/ui/alert';\`. If using components from the shadcn/ui library, the assistant mentions this to the user and offers to help them install the components if necessary.
- - Components MUST be imported from \`/components/ui/name\` and NOT from \`/components/name\` or \`@/components/ui/name\`.
- - NO OTHER LIBRARIES (e.g. zod, hookform) ARE INSTALLED OR ABLE TO BE IMPORTED.
- - Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so \`<img src="/api/placeholder/400/320" alt="placeholder" />\`
- - When iterating on code, ensure that the code is complete and functional without any snippets, placeholders, or ellipses.
- - If you are unable to follow the above requirements for any reason, don't use artifacts and use regular code blocks instead, which will not attempt to render the component.
- 5. Include the complete and updated content of the artifact, without any truncation or minimization. Don't use "// rest of the code remains the same...".
- 6. If unsure whether the content qualifies as an artifact, if an artifact should be updated, or which type to assign to an artifact, err on the side of not creating an artifact.
- 7. Use a backtick fence longer than any backtick fence in the artifact content. Use a 4-backtick fence by default; if the artifact content contains a 4-backtick fence, use 5 backticks, and so on.
-</artifact_instructions>
-
-Here are some examples of correct usage of artifacts:
-
-<examples>
- <example_docstring>
- This example demonstrates how to create a Mermaid artifact for a simple flow chart.
- </example_docstring>
-
- <example>
- <user_query>Can you create a simple flow chart showing the process of making tea using Mermaid?</user_query>
-
- <assistant_response>
- Sure! Here's a simple flow chart depicting the process of making tea using Mermaid syntax:
-
- :::artifact{identifier="tea-making-flowchart" type="application/vnd.mermaid" title="Flow chart: Making Tea"}
- \`\`\`\`mermaid
- graph TD
- A[Start] --> B{Water boiled?}
- B -->|Yes| C[Add tea leaves to cup]
- B -->|No| D[Boil water]
- D --> B
- C --> E[Pour boiling water into cup]
- E --> F[Steep tea for desired time]
- F --> G[Remove tea leaves]
- G --> H[Add milk or sugar, if desired]
- H --> I[Enjoy your tea!]
- I --> J[End]
- \`\`\`\`
- :::
-
- This flow chart uses Mermaid syntax to visualize the steps involved in making a cup of tea. Here's a brief explanation of the process:
-
- 1. Start
- 2. Check if water is boiled
- 3. If not boiled, boil the water
- 4. Once water is boiled, add tea leaves to the cup
- 5. Pour boiling water into the cup
- 6. Steep the tea for the desired time
- 7. Remove the tea leaves
- 8. Optionally add milk or sugar
- 9. Enjoy your tea!
- 10. End
-
- This chart provides a clear visual representation of the tea-making process. You can easily modify or expand this chart if you want to add more details or steps to the process. Let me know if you'd like any changes or have any questions!
- </assistant_response>
- </example>
-
- <example>
- <user_query>Create a simple React counter component</user_query>
- <assistant_response>
- Here's a simple React counter component:
-
- :::artifact{identifier="react-counter" type="application/vnd.react" title="React Counter"}
- \`\`\`\`
- import { useState } from 'react';
-
- export default function Counter() {
- const [count, setCount] = useState(0);
- return (
- <div className="p-4">
- <p className="mb-2">Count: {count}</p>
- <button className="bg-blue-500 text-white px-4 py-2 rounded" onClick={() => setCount(count + 1)}>
- Increment
- </button>
- </div>
- );
- }
- \`\`\`\`
- :::
-
- This component creates a simple counter with an increment button.
- </assistant_response>
- </example>
-
- <example>
- <user_query>Create a basic HTML structure for a blog post</user_query>
- <assistant_response>
- Here's a basic HTML structure for a blog post:
-
- :::artifact{identifier="blog-post-html" type="text/html" title="Blog Post HTML"}
- \`\`\`\`
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>My Blog Post</title>
- <style>
- body { font-family: Arial, sans-serif; line-height: 1.6; max-width: 800px; margin: 0 auto; padding: 20px; }
- h1 { color: #333; }
- p { margin-bottom: 15px; }
- </style>
- </head>
- <body>
- <header>
- <h1>My First Blog Post</h1>
- </header>
- <main>
- <article>
- <p>This is the content of my blog post. It's short and sweet!</p>
- </article>
- </main>
- <footer>
- <p>&copy; 2023 My Blog</p>
- </footer>
- </body>
- </html>
- \`\`\`\`
- :::
-
- This HTML structure provides a simple layout for a blog post.
- </assistant_response>
- </example>
-</examples>`;
-
-const artifactsOpenAIPrompt = dedent`The assistant can create and reference artifacts during conversations.
-
-Artifacts are for substantial, self-contained content that users might modify or reuse, displayed in a separate UI window for clarity.
-
-# Good artifacts are...
-- Substantial content (>15 lines)
-- Content that the user is likely to modify, iterate on, or take ownership of
-- Self-contained, complex content that can be understood on its own, without context from the conversation
-- Content intended for eventual use outside the conversation (e.g., reports, emails, presentations)
-- Content likely to be referenced or reused multiple times
-
-# Don't use artifacts for...
-- Simple, informational, or short content, such as brief code snippets, mathematical equations, or small examples
-- Primarily explanatory, instructional, or illustrative content, such as examples provided to clarify a concept
-- Suggestions, commentary, or feedback on existing artifacts
-- Conversational or explanatory content that doesn't represent a standalone piece of work
-- Content that is dependent on the current conversational context to be useful
-- Content that is unlikely to be modified or iterated upon by the user
-- Request from users that appears to be a one-off question
-
-# Usage notes
-- One artifact per message unless specifically requested
-- Prefer in-line content (don't use artifacts) when possible. Unnecessary use of artifacts can be jarring for users.
-- If a user asks the assistant to "draw an SVG" or "make a website," the assistant does not need to explain that it doesn't have these capabilities. Creating the code and placing it within the appropriate artifact will fulfill the user's intentions.
-- If asked to generate an image, the assistant can offer an SVG instead. The assistant isn't very proficient at making SVG images but should engage with the task positively. Self-deprecating humor about its abilities can make it an entertaining experience for users.
-- The assistant errs on the side of simplicity and avoids overusing artifacts for content that can be effectively presented within the conversation.
-- Always provide complete, specific, and fully functional content for artifacts without any snippets, placeholders, ellipses, or 'remains the same' comments.
-- If an artifact is not necessary or requested, the assistant should not mention artifacts at all, and respond to the user accordingly.
-
-## Artifact Instructions
- When collaborating with the user on creating content that falls into compatible categories, the assistant should follow these steps:
-
- 1. Create the artifact using the following remark-directive markdown format:
-
- :::artifact{identifier="unique-identifier" type="mime-type" title="Artifact Title"}
- \`\`\`\`
- Your artifact content here
- \`\`\`\`
- :::
-
- a. Example of correct format:
-
- :::artifact{identifier="example-artifact" type="text/plain" title="Example Artifact"}
- \`\`\`\`
- This is the content of the artifact.
- It can span multiple lines.
- \`\`\`\`
- :::
-
- b. Common mistakes to avoid:
- - Don't split the opening ::: line
- - Don't add extra backticks outside the artifact structure
- - Don't omit the closing :::
-
- 2. Assign an identifier to the \`identifier\` attribute. For updates, reuse the prior identifier. For new artifacts, the identifier should be descriptive and relevant to the content, using kebab-case (e.g., "example-code-snippet"). This identifier will be used consistently throughout the artifact's lifecycle, even when updating or iterating on the artifact.
- 3. Include a \`title\` attribute to provide a brief title or description of the content.
- 4. Add a \`type\` attribute to specify the type of content the artifact represents. Assign one of the following values to the \`type\` attribute:
- - HTML: "text/html"
- - The user interface can render single file HTML pages placed within the artifact tags. HTML, JS, and CSS should be in a single file when using the \`text/html\` type.
- - Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so \`<img src="/api/placeholder/400/320" alt="placeholder" />\`
- - The only place external scripts can be imported from is https://cdnjs.cloudflare.com
- - SVG: "image/svg+xml"
- - The user interface will render the Scalable Vector Graphics (SVG) image within the artifact tags.
- - The assistant should specify the viewbox of the SVG rather than defining a width/height
- - Markdown: "text/markdown" or "text/md"
- - The user interface will render Markdown content placed within the artifact tags.
- - Supports standard Markdown syntax including headers, lists, links, images, code blocks, tables, and more.
- - Both "text/markdown" and "text/md" are accepted as valid MIME types for Markdown content.
- - Mermaid Diagrams: "application/vnd.mermaid"
- - The user interface will render Mermaid diagrams placed within the artifact tags.
- - React Components: "application/vnd.react"
- - Use this for displaying either: React elements, e.g. \`<strong>Hello World!</strong>\`, React pure functional components, e.g. \`() => <strong>Hello World!</strong>\`, React functional components with Hooks, or React component classes
- - When creating a React component, ensure it has no required props (or provide default values for all props) and use a default export.
- - Use Tailwind classes for styling. DO NOT USE ARBITRARY VALUES (e.g. \`h-[600px]\`).
- - Base React is available to be imported. To use hooks, first import it at the top of the artifact, e.g. \`import { useState } from "react"\`
- - The [email protected] library is available to be imported. e.g. \`import { Camera } from "lucide-react"\` & \`<Camera color="red" size={48} />\`
- - The recharts charting library is available to be imported, e.g. \`import { LineChart, XAxis, ... } from "recharts"\` & \`<LineChart ...><XAxis dataKey="name"> ...\`
- - The three.js library is available to be imported, e.g. \`import * as THREE from "three";\`
- - The date-fns library is available to be imported, e.g. \`import { compareAsc, format } from "date-fns";\`
- - The react-day-picker library is available to be imported, e.g. \`import { DayPicker } from "react-day-picker";\`
- - The assistant can use prebuilt components from the \`shadcn/ui\` library after it is imported: \`import { Alert, AlertDescription, AlertTitle, AlertDialog, AlertDialogAction } from '/components/ui/alert';\`. If using components from the shadcn/ui library, the assistant mentions this to the user and offers to help them install the components if necessary.
- - Components MUST be imported from \`/components/ui/name\` and NOT from \`/components/name\` or \`@/components/ui/name\`.
- - NO OTHER LIBRARIES (e.g. zod, hookform) ARE INSTALLED OR ABLE TO BE IMPORTED.
- - Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so \`<img src="/api/placeholder/400/320" alt="placeholder" />\`
- - When iterating on code, ensure that the code is complete and functional without any snippets, placeholders, or ellipses.
- - If you are unable to follow the above requirements for any reason, don't use artifacts and use regular code blocks instead, which will not attempt to render the component.
- 5. Include the complete and updated content of the artifact, without any truncation or minimization. Don't use "// rest of the code remains the same...".
- 6. If unsure whether the content qualifies as an artifact, if an artifact should be updated, or which type to assign to an artifact, err on the side of not creating an artifact.
- 7. Use a backtick fence longer than any backtick fence in the artifact content. Use a 4-backtick fence by default; if the artifact content contains a 4-backtick fence, use 5 backticks, and so on.
-
-Here are some examples of correct usage of artifacts:
-
-## Examples
-
-### Example 1
-
- This example demonstrates how to create a Mermaid artifact for a simple flow chart.
-
- User: Can you create a simple flow chart showing the process of making tea using Mermaid?
-
- Assistant: Sure! Here's a simple flow chart depicting the process of making tea using Mermaid syntax:
-
- :::artifact{identifier="tea-making-flowchart" type="application/vnd.mermaid" title="Flow chart: Making Tea"}
- \`\`\`\`mermaid
- graph TD
- A[Start] --> B{Water boiled?}
- B -->|Yes| C[Add tea leaves to cup]
- B -->|No| D[Boil water]
- D --> B
- C --> E[Pour boiling water into cup]
- E --> F[Steep tea for desired time]
- F --> G[Remove tea leaves]
- G --> H[Add milk or sugar, if desired]
- H --> I[Enjoy your tea!]
- I --> J[End]
- \`\`\`\`
- :::
-
- This flow chart uses Mermaid syntax to visualize the steps involved in making a cup of tea. Here's a brief explanation of the process:
-
- 1. Start
- 2. Check if water is boiled
- 3. If not boiled, boil the water
- 4. Once water is boiled, add tea leaves to the cup
- 5. Pour boiling water into the cup
- 6. Steep the tea for the desired time
- 7. Remove the tea leaves
- 8. Optionally add milk or sugar
- 9. Enjoy your tea!
- 10. End
-
- This chart provides a clear visual representation of the tea-making process. You can easily modify or expand this chart if you want to add more details or steps to the process. Let me know if you'd like any changes or have any questions!
-
----
-
-### Example 2
-
- User: Create a simple React counter component
-
- Assistant: Here's a simple React counter component:
-
- :::artifact{identifier="react-counter" type="application/vnd.react" title="React Counter"}
- \`\`\`\`
- import { useState } from 'react';
-
- export default function Counter() {
- const [count, setCount] = useState(0);
- return (
- <div className="p-4">
- <p className="mb-2">Count: {count}</p>
- <button className="bg-blue-500 text-white px-4 py-2 rounded" onClick={() => setCount(count + 1)}>
- Increment
- </button>
- </div>
- );
- }
- \`\`\`\`
- :::
-
- This component creates a simple counter with an increment button.
-
----
-
-### Example 3
- User: Create a basic HTML structure for a blog post
- Assistant: Here's a basic HTML structure for a blog post:
-
- :::artifact{identifier="blog-post-html" type="text/html" title="Blog Post HTML"}
- \`\`\`\`
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>My Blog Post</title>
- <style>
- body { font-family: Arial, sans-serif; line-height: 1.6; max-width: 800px; margin: 0 auto; padding: 20px; }
- h1 { color: #333; }
- p { margin-bottom: 15px; }
- </style>
- </head>
- <body>
- <header>
- <h1>My First Blog Post</h1>
- </header>
- <main>
- <article>
- <p>This is the content of my blog post. It's short and sweet!</p>
- </article>
- </main>
- <footer>
- <p>&copy; 2023 My Blog</p>
- </footer>
- </body>
- </html>
- \`\`\`\`
- :::
-
- This HTML structure provides a simple layout for a blog post.
-
----`;
-
-/**
- *
- * @param {Object} params
- * @param {EModelEndpoint | string} params.endpoint - The current endpoint
- * @param {ArtifactModes} params.artifacts - The current artifact mode
- * @returns
- */
-const generateArtifactsPrompt = ({ endpoint, artifacts }) => {
- if (artifacts === ArtifactModes.CUSTOM) {
- return null;
- }
-
- let prompt = artifactsPrompt;
- if (endpoint !== EModelEndpoint.anthropic) {
- prompt = artifactsOpenAIPrompt;
- }
-
- if (artifacts === ArtifactModes.SHADCNUI) {
- prompt += generateShadcnPrompt({ components, useXML: endpoint === EModelEndpoint.anthropic });
- }
-
- return prompt;
-};
-
-module.exports = generateArtifactsPrompt;
diff --git a/api/app/clients/prompts/formatAgentMessages.spec.js b/api/app/clients/prompts/formatAgentMessages.spec.js
deleted file mode 100644
index 86ec5c2e03..0000000000
--- a/api/app/clients/prompts/formatAgentMessages.spec.js
+++ /dev/null
@@ -1,680 +0,0 @@
-const { ContentTypes } = require('librechat-data-provider');
-const {
- AIMessage,
- ToolMessage,
- HumanMessage,
- SystemMessage,
-} = require('@librechat/agents/langchain/messages');
-const { formatAgentMessages } = require('./formatMessages');
-
-describe('formatAgentMessages', () => {
- it('should format simple user and AI messages', () => {
- const payload = [
- { role: 'user', content: 'Hello' },
- { role: 'assistant', content: 'Hi there!' },
- ];
- const result = formatAgentMessages(payload);
- expect(result).toHaveLength(2);
- expect(result[0]).toBeInstanceOf(HumanMessage);
- expect(result[1]).toBeInstanceOf(AIMessage);
- });
-
- it('should handle system messages', () => {
- const payload = [{ role: 'system', content: 'You are a helpful assistant.' }];
- const result = formatAgentMessages(payload);
- expect(result).toHaveLength(1);
- expect(result[0]).toBeInstanceOf(SystemMessage);
- });
-
- it('should format messages with content arrays', () => {
- const payload = [
- {
- role: 'user',
- content: [{ type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Hello' }],
- },
- ];
- const result = formatAgentMessages(payload);
- expect(result).toHaveLength(1);
- expect(result[0]).toBeInstanceOf(HumanMessage);
- });
-
- it('should handle tool calls and create ToolMessages', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- {
- type: ContentTypes.TEXT,
- [ContentTypes.TEXT]: 'Let me check that for you.',
- tool_call_ids: ['123'],
- },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: {
- id: '123',
- name: 'search',
- args: '{"query":"weather"}',
- output: 'The weather is sunny.',
- inputValidationError: true,
- },
- },
- ],
- },
- ];
- const result = formatAgentMessages(payload);
- expect(result).toHaveLength(2);
- expect(result[0]).toBeInstanceOf(AIMessage);
- expect(result[1]).toBeInstanceOf(ToolMessage);
- expect(result[0].tool_calls).toHaveLength(1);
- expect(result[0].tool_calls[0]).not.toHaveProperty('inputValidationError');
- expect(result[1].tool_call_id).toBe('123');
- });
-
- it('should handle multiple content parts in assistant messages', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Part 1' },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Part 2' },
- ],
- },
- ];
- const result = formatAgentMessages(payload);
- expect(result).toHaveLength(1);
- expect(result[0]).toBeInstanceOf(AIMessage);
- expect(result[0].content).toHaveLength(2);
- });
-
- it('should throw an error for invalid tool call structure', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: {
- id: '123',
- name: 'search',
- args: '{"query":"weather"}',
- output: 'The weather is sunny.',
- },
- },
- ],
- },
- ];
- expect(() => formatAgentMessages(payload)).toThrow('Invalid tool call structure');
- });
-
- it('should handle tool calls with non-JSON args', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Checking...', tool_call_ids: ['123'] },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: {
- id: '123',
- name: 'search',
- args: 'non-json-string',
- output: 'Result',
- },
- },
- ],
- },
- ];
- const result = formatAgentMessages(payload);
- expect(result).toHaveLength(2);
- expect(result[0].tool_calls[0].args).toStrictEqual({ input: 'non-json-string' });
- });
-
- it('should handle complex tool calls with multiple steps', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- {
- type: ContentTypes.TEXT,
- [ContentTypes.TEXT]: "I'll search for that information.",
- tool_call_ids: ['search_1'],
- },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: {
- id: 'search_1',
- name: 'search',
- args: '{"query":"weather in New York"}',
- output: 'The weather in New York is currently sunny with a temperature of 75°F.',
- },
- },
- {
- type: ContentTypes.TEXT,
- [ContentTypes.TEXT]: "Now, I'll convert the temperature.",
- tool_call_ids: ['convert_1'],
- },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: {
- id: 'convert_1',
- name: 'convert_temperature',
- args: '{"temperature": 75, "from": "F", "to": "C"}',
- output: '23.89°C',
- },
- },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: "Here's your answer." },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
-
- expect(result).toHaveLength(5);
- expect(result[0]).toBeInstanceOf(AIMessage);
- expect(result[1]).toBeInstanceOf(ToolMessage);
- expect(result[2]).toBeInstanceOf(AIMessage);
- expect(result[3]).toBeInstanceOf(ToolMessage);
- expect(result[4]).toBeInstanceOf(AIMessage);
-
- // Check first AIMessage
- expect(result[0].content).toBe("I'll search for that information.");
- expect(result[0].tool_calls).toHaveLength(1);
- expect(result[0].tool_calls[0]).toEqual({
- id: 'search_1',
- name: 'search',
- args: { query: 'weather in New York' },
- });
-
- // Check first ToolMessage
- expect(result[1].tool_call_id).toBe('search_1');
- expect(result[1].name).toBe('search');
- expect(result[1].content).toBe(
- 'The weather in New York is currently sunny with a temperature of 75°F.',
- );
-
- // Check second AIMessage
- expect(result[2].content).toBe("Now, I'll convert the temperature.");
- expect(result[2].tool_calls).toHaveLength(1);
- expect(result[2].tool_calls[0]).toEqual({
- id: 'convert_1',
- name: 'convert_temperature',
- args: { temperature: 75, from: 'F', to: 'C' },
- });
-
- // Check second ToolMessage
- expect(result[3].tool_call_id).toBe('convert_1');
- expect(result[3].name).toBe('convert_temperature');
- expect(result[3].content).toBe('23.89°C');
-
- // Check final AIMessage
- expect(result[4].content).toStrictEqual([
- { [ContentTypes.TEXT]: "Here's your answer.", type: ContentTypes.TEXT },
- ]);
- });
-
- it.skip('should not produce two consecutive assistant messages and format content correctly', () => {
- const payload = [
- { role: 'user', content: 'Hello' },
- {
- role: 'assistant',
- content: [{ type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Hi there!' }],
- },
- {
- role: 'assistant',
- content: [{ type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'How can I help you?' }],
- },
- { role: 'user', content: "What's the weather?" },
- {
- role: 'assistant',
- content: [
- {
- type: ContentTypes.TEXT,
- [ContentTypes.TEXT]: 'Let me check that for you.',
- tool_call_ids: ['weather_1'],
- },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: {
- id: 'weather_1',
- name: 'check_weather',
- args: '{"location":"New York"}',
- output: 'Sunny, 75°F',
- },
- },
- ],
- },
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: "Here's the weather information." },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
-
- // Check correct message count and types
- expect(result).toHaveLength(6);
- expect(result[0]).toBeInstanceOf(HumanMessage);
- expect(result[1]).toBeInstanceOf(AIMessage);
- expect(result[2]).toBeInstanceOf(HumanMessage);
- expect(result[3]).toBeInstanceOf(AIMessage);
- expect(result[4]).toBeInstanceOf(ToolMessage);
- expect(result[5]).toBeInstanceOf(AIMessage);
-
- // Check content of messages
- expect(result[0].content).toStrictEqual([
- { [ContentTypes.TEXT]: 'Hello', type: ContentTypes.TEXT },
- ]);
- expect(result[1].content).toStrictEqual([
- { [ContentTypes.TEXT]: 'Hi there!', type: ContentTypes.TEXT },
- { [ContentTypes.TEXT]: 'How can I help you?', type: ContentTypes.TEXT },
- ]);
- expect(result[2].content).toStrictEqual([
- { [ContentTypes.TEXT]: "What's the weather?", type: ContentTypes.TEXT },
- ]);
- expect(result[3].content).toBe('Let me check that for you.');
- expect(result[4].content).toBe('Sunny, 75°F');
- expect(result[5].content).toStrictEqual([
- { [ContentTypes.TEXT]: "Here's the weather information.", type: ContentTypes.TEXT },
- ]);
-
- // Check that there are no consecutive AIMessages
- const messageTypes = result.map((message) => message.constructor);
- for (let i = 0; i < messageTypes.length - 1; i++) {
- expect(messageTypes[i] === AIMessage && messageTypes[i + 1] === AIMessage).toBe(false);
- }
-
- // Additional check to ensure the consecutive assistant messages were combined
- expect(result[1].content).toHaveLength(2);
- });
-
- it('should skip THINK type content parts', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Initial response' },
- { type: ContentTypes.THINK, [ContentTypes.THINK]: 'Reasoning about the problem...' },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Final answer' },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
-
- expect(result).toHaveLength(1);
- expect(result[0]).toBeInstanceOf(AIMessage);
- expect(result[0].content).toEqual('Initial response\nFinal answer');
- });
-
- it('should join TEXT content as string when THINK content type is present', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.THINK, [ContentTypes.THINK]: 'Analyzing the problem...' },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'First part of response' },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Second part of response' },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Final part of response' },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
-
- expect(result).toHaveLength(1);
- expect(result[0]).toBeInstanceOf(AIMessage);
- expect(typeof result[0].content).toBe('string');
- expect(result[0].content).toBe(
- 'First part of response\nSecond part of response\nFinal part of response',
- );
- expect(result[0].content).not.toContain('Analyzing the problem...');
- });
-
- it('should exclude ERROR type content parts', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Hello there' },
- {
- type: ContentTypes.ERROR,
- [ContentTypes.ERROR]:
- 'An error occurred while processing the request: Something went wrong',
- },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Final answer' },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
-
- expect(result).toHaveLength(1);
- expect(result[0]).toBeInstanceOf(AIMessage);
- expect(result[0].content).toEqual([
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Hello there' },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Final answer' },
- ]);
-
- // Make sure no error content exists in the result
- const hasErrorContent = result[0].content.some(
- (item) =>
- item.type === ContentTypes.ERROR || JSON.stringify(item).includes('An error occurred'),
- );
- expect(hasErrorContent).toBe(false);
- });
-
- describe('Vertex Gemini thoughtSignatures persistence (issue #13006 follow-up)', () => {
- const SIG_A = 'AY89a1/sigA==';
- const SIG_B = 'AY89a1/sigB==';
-
- it('restores additional_kwargs.signatures onto the AIMessage that owns the tool_call', () => {
- const payload = [
- { role: 'user', content: 'list files' },
- {
- role: 'assistant',
- metadata: { thoughtSignatures: { t1: SIG_A } },
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: '', tool_call_ids: ['t1'] },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't1', name: 'bash', args: '{}', output: 'ok' },
- },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
-
- const assistant = result.find((m) => m instanceof AIMessage);
- expect(assistant.tool_calls).toHaveLength(1);
- expect(assistant.additional_kwargs?.signatures).toEqual([SIG_A]);
- });
-
- it('attaches signatures per-step in multi-step tool turns (codex review fix)', () => {
- // Reproduces the Codex P1 concern: an assistant turn where the agent
- // loop made two LLM cycles, each emitting its own tool_call. Each step
- // must carry its OWN signature on resume — Vertex validates per-step,
- // not per-turn.
- const payload = [
- { role: 'user', content: 'do two things' },
- {
- role: 'assistant',
- metadata: { thoughtSignatures: { t1: SIG_A, t2: SIG_B } },
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'first', tool_call_ids: ['t1'] },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't1', name: 'a', args: '{}', output: 'okA' },
- },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'second', tool_call_ids: ['t2'] },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't2', name: 'b', args: '{}', output: 'okB' },
- },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
- const aiMessages = result.filter((m) => m instanceof AIMessage);
- expect(aiMessages).toHaveLength(2);
- expect(aiMessages[0].tool_calls).toHaveLength(1);
- expect(aiMessages[0].additional_kwargs?.signatures).toEqual([SIG_A]);
- expect(aiMessages[1].tool_calls).toHaveLength(1);
- expect(aiMessages[1].additional_kwargs?.signatures).toEqual([SIG_B]);
- });
-
- it('preserves tool_call ordering when signatures are partial', () => {
- // Mixed case: only some tool_calls have stored signatures. Position-
- // aligned array (with empty placeholders) lets the agents-side
- // dispatcher attach the correct signature to the correct functionCall.
- const payload = [
- { role: 'user', content: 'two parallel tools' },
- {
- role: 'assistant',
- metadata: { thoughtSignatures: { t2: SIG_B } },
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: '', tool_call_ids: ['t1', 't2'] },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't1', name: 'a', args: '{}', output: 'okA' },
- },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't2', name: 'b', args: '{}', output: 'okB' },
- },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
- const assistant = result.find((m) => m instanceof AIMessage);
- expect(assistant.additional_kwargs?.signatures).toEqual(['', SIG_B]);
- });
-
- it('no-op when metadata.thoughtSignatures is absent', () => {
- const payload = [
- { role: 'user', content: 'hi' },
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: '', tool_call_ids: ['t1'] },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't1', name: 'bash', args: '{}', output: 'ok' },
- },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
- const assistant = result.find((m) => m instanceof AIMessage);
- expect(assistant.additional_kwargs?.signatures).toBeUndefined();
- });
-
- it('no-op when assistant message has no tool_calls', () => {
- const payload = [
- { role: 'user', content: 'hi' },
- {
- role: 'assistant',
- metadata: { thoughtSignatures: { t1: SIG_A } },
- content: 'plain text reply',
- },
- ];
-
- const result = formatAgentMessages(payload);
- const assistant = result.find((m) => m instanceof AIMessage);
- expect(assistant.additional_kwargs?.signatures).toBeUndefined();
- });
-
- it('no-op when no tool_call has a corresponding stored signature', () => {
- // The persisted map exists but addresses different tool_call_ids
- // (e.g., the previous turn's signatures, somehow leaked). Don't
- // fabricate empty arrays onto the AIMessage.
- const payload = [
- { role: 'user', content: 'hi' },
- {
- role: 'assistant',
- metadata: { thoughtSignatures: { unrelated_id: SIG_A } },
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: '', tool_call_ids: ['t1'] },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't1', name: 'bash', args: '{}', output: 'ok' },
- },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
- const assistant = result.find((m) => m instanceof AIMessage);
- expect(assistant.additional_kwargs?.signatures).toBeUndefined();
- });
- });
-
- describe('steer content parts', () => {
- it('replays a steer between tool steps as a standalone HumanMessage', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- {
- type: ContentTypes.TEXT,
- [ContentTypes.TEXT]: 'Checking the weather.',
- tool_call_ids: ['t1'],
- },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't1', name: 'search', args: '{}', output: 'sunny' },
- },
- {
- type: ContentTypes.STEER,
- [ContentTypes.STEER]: 'also check tomorrow',
- steerId: 's1',
- },
- {
- type: ContentTypes.TEXT,
- [ContentTypes.TEXT]: 'Checking tomorrow too.',
- tool_call_ids: ['t2'],
- },
- {
- type: ContentTypes.TOOL_CALL,
- tool_call: { id: 't2', name: 'search', args: '{}', output: 'rain' },
- },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
- expect(result.map((m) => m.constructor)).toEqual([
- AIMessage,
- ToolMessage,
- HumanMessage,
- AIMessage,
- ToolMessage,
- ]);
- expect(result[2].content).toBe('also check tomorrow');
- expect(result[2].additional_kwargs).toEqual({ source: 'steer' });
- expect(result[3].tool_calls).toHaveLength(1);
- });
-
- it('flushes accumulated assistant text before the steer', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Some prose so far.' },
- { type: ContentTypes.STEER, [ContentTypes.STEER]: 'change direction' },
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'New direction prose.' },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
- expect(result.map((m) => m.constructor)).toEqual([AIMessage, HumanMessage, AIMessage]);
- expect(result[0].content).toBe('Some prose so far.');
- expect(result[1].content).toBe('change direction');
- expect(result[2].content).toEqual([
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'New direction prose.' },
- ]);
- });
-
- it('handles a steer as the final content part', () => {
- const payload = [
- {
- role: 'assistant',
- content: [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Answer text.' },
- { type: ContentTypes.STEER, [ContentTypes.STEER]: 'trailing steer' },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
- expect(result.map((m) => m.constructor)).toEqual([AIMessage, HumanMessage]);
- expect(result[1].content).toBe('trailing steer');
- });
-
- it('prefers stamped media content for multimodal steers', () => {
- const media = [
- { type: 'text', text: 'see the chart' },
- { type: 'image_url', image_url: { url: 'data:image/png;base64,abc', detail: 'auto' } },
- ];
- const payload = [
- {
- role: 'assistant',
- content: [
- {
- type: ContentTypes.STEER,
- [ContentTypes.STEER]: 'see the chart',
- files: [{ file_id: 'f1' }],
- media,
- },
- ],
- },
- ];
-
- const result = formatAgentMessages(payload);
- expect(result).toHaveLength(1);
- expect(result[0]).toBeInstanceOf(HumanMessage);
- expect(result[0].content).toEqual(media);
- });
- });
-
- describe('promptless sends', () => {
- const PLACEHOLDER = [{ type: 'text', text: '(no text)' }];
-
- it('should stand in for a replayed promptless turn instead of a blank block', () => {
- const result = formatAgentMessages([
- { role: 'user', content: '' },
- { role: 'assistant', content: 'Hi' },
- ]);
-
- expect(result).toHaveLength(2);
- expect(result[0]).toBeInstanceOf(HumanMessage);
- expect(result[0].content).toEqual(PLACEHOLDER);
- expect(result[0].content).not.toContainEqual(
- expect.objectContaining({ type: 'text', text: '' }),
- );
- });
-
- it('should keep the turn so assistant messages never become adjacent', () => {
- const result = formatAgentMessages([
- { role: 'assistant', content: 'first' },
- { role: 'user', content: '' },
- { role: 'assistant', content: 'second' },
- ]);
-
- expect(result).toHaveLength(3);
- expect(result[1]).toBeInstanceOf(HumanMessage);
- });
-
- it('should not emit a blank text block for a whitespace-only user message', () => {
- const result = formatAgentMessages([{ role: 'user', content: ' ' }]);
-
- expect(result).toHaveLength(1);
- expect(result[0].content).toEqual(PLACEHOLDER);
- });
-
- it('should keep a promptless user message that still carries its images', () => {
- const image_urls = [{ type: 'image_url', image_url: { url: 'data:image/png;base64,AAA' } }];
- const result = formatAgentMessages([{ role: 'user', content: '', image_urls }]);
-
- expect(result).toHaveLength(1);
- expect(result[0].content).toEqual(image_urls);
- expect(result[0].content).not.toContainEqual(
- expect.objectContaining({ type: 'text', text: '' }),
- );
- });
-
- it('should still format a user message that has text', () => {
- const result = formatAgentMessages([{ role: 'user', content: 'hello' }]);
-
- expect(result).toHaveLength(1);
- expect(result[0]).toBeInstanceOf(HumanMessage);
- expect(result[0].content).toEqual([{ type: 'text', text: 'hello' }]);
- });
- });
-});
diff --git a/api/app/clients/prompts/formatGoogleInputs.js b/api/app/clients/prompts/formatGoogleInputs.js
deleted file mode 100644
index c929df8b51..0000000000
--- a/api/app/clients/prompts/formatGoogleInputs.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Formats an object to match the struct_val, list_val, string_val, float_val, and int_val format.
- *
- * @param {Object} obj - The object to be formatted.
- * @returns {Object} The formatted object.
- *
- * Handles different types:
- * - Arrays are wrapped in list_val and each element is processed.
- * - Objects are recursively processed.
- * - Strings are wrapped in string_val.
- * - Numbers are wrapped in float_val or int_val depending on whether they are floating-point or integers.
- */
-function formatGoogleInputs(obj) {
- const formattedObj = {};
-
- for (const key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- const value = obj[key];
-
- // Handle arrays
- if (Array.isArray(value)) {
- formattedObj[key] = { list_val: value.map((item) => formatGoogleInputs(item)) };
- }
- // Handle objects
- else if (typeof value === 'object' && value !== null) {
- formattedObj[key] = formatGoogleInputs(value);
- }
- // Handle numbers
- else if (typeof value === 'number') {
- formattedObj[key] = Number.isInteger(value) ? { int_val: value } : { float_val: value };
- }
- // Handle other types (e.g., strings)
- else {
- formattedObj[key] = { string_val: [value] };
- }
- }
- }
-
- return { struct_val: formattedObj };
-}
-
-module.exports = formatGoogleInputs;
diff --git a/api/app/clients/prompts/formatGoogleInputs.spec.js b/api/app/clients/prompts/formatGoogleInputs.spec.js
deleted file mode 100644
index 8fef9dfb5f..0000000000
--- a/api/app/clients/prompts/formatGoogleInputs.spec.js
+++ /dev/null
@@ -1,274 +0,0 @@
-const formatGoogleInputs = require('./formatGoogleInputs');
-
-describe('formatGoogleInputs', () => {
- it('formats message correctly', () => {
- const input = {
- messages: [
- {
- content: 'hi',
- author: 'user',
- },
- ],
- context: 'context',
- examples: [
- {
- input: {
- author: 'user',
- content: 'user input',
- },
- output: {
- author: 'bot',
- content: 'bot output',
- },
- },
- ],
- parameters: {
- temperature: 0.2,
- topP: 0.8,
- topK: 40,
- maxOutputTokens: 1024,
- },
- };
-
- const expectedOutput = {
- struct_val: {
- messages: {
- list_val: [
- {
- struct_val: {
- content: {
- string_val: ['hi'],
- },
- author: {
- string_val: ['user'],
- },
- },
- },
- ],
- },
- context: {
- string_val: ['context'],
- },
- examples: {
- list_val: [
- {
- struct_val: {
- input: {
- struct_val: {
- author: {
- string_val: ['user'],
- },
- content: {
- string_val: ['user input'],
- },
- },
- },
- output: {
- struct_val: {
- author: {
- string_val: ['bot'],
- },
- content: {
- string_val: ['bot output'],
- },
- },
- },
- },
- },
- ],
- },
- parameters: {
- struct_val: {
- temperature: {
- float_val: 0.2,
- },
- topP: {
- float_val: 0.8,
- },
- topK: {
- int_val: 40,
- },
- maxOutputTokens: {
- int_val: 1024,
- },
- },
- },
- },
- };
-
- const result = formatGoogleInputs(input);
- expect(JSON.stringify(result)).toEqual(JSON.stringify(expectedOutput));
- });
-
- it('formats real payload parts', () => {
- const input = {
- instances: [
- {
- context: 'context',
- examples: [
- {
- input: {
- author: 'user',
- content: 'user input',
- },
- output: {
- author: 'bot',
- content: 'user output',
- },
- },
- ],
- messages: [
- {
- author: 'user',
- content: 'hi',
- },
- ],
- },
- ],
- parameters: {
- candidateCount: 1,
- maxOutputTokens: 1024,
- temperature: 0.2,
- topP: 0.8,
- topK: 40,
- },
- };
- const expectedOutput = {
- struct_val: {
- instances: {
- list_val: [
- {
- struct_val: {
- context: { string_val: ['context'] },
- examples: {
- list_val: [
- {
- struct_val: {
- input: {
- struct_val: {
- author: { string_val: ['user'] },
- content: { string_val: ['user input'] },
- },
- },
- output: {
- struct_val: {
- author: { string_val: ['bot'] },
- content: { string_val: ['user output'] },
- },
- },
- },
- },
- ],
- },
- messages: {
- list_val: [
- {
- struct_val: {
- author: { string_val: ['user'] },
- content: { string_val: ['hi'] },
- },
- },
- ],
- },
- },
- },
- ],
- },
- parameters: {
- struct_val: {
- candidateCount: { int_val: 1 },
- maxOutputTokens: { int_val: 1024 },
- temperature: { float_val: 0.2 },
- topP: { float_val: 0.8 },
- topK: { int_val: 40 },
- },
- },
- },
- };
-
- const result = formatGoogleInputs(input);
- expect(JSON.stringify(result)).toEqual(JSON.stringify(expectedOutput));
- });
-
- it('helps create valid payload parts', () => {
- const instances = {
- context: 'context',
- examples: [
- {
- input: {
- author: 'user',
- content: 'user input',
- },
- output: {
- author: 'bot',
- content: 'user output',
- },
- },
- ],
- messages: [
- {
- author: 'user',
- content: 'hi',
- },
- ],
- };
-
- const expectedInstances = {
- struct_val: {
- context: { string_val: ['context'] },
- examples: {
- list_val: [
- {
- struct_val: {
- input: {
- struct_val: {
- author: { string_val: ['user'] },
- content: { string_val: ['user input'] },
- },
- },
- output: {
- struct_val: {
- author: { string_val: ['bot'] },
- content: { string_val: ['user output'] },
- },
- },
- },
- },
- ],
- },
- messages: {
- list_val: [
- {
- struct_val: {
- author: { string_val: ['user'] },
- content: { string_val: ['hi'] },
- },
- },
- ],
- },
- },
- };
-
- const parameters = {
- candidateCount: 1,
- maxOutputTokens: 1024,
- temperature: 0.2,
- topP: 0.8,
- topK: 40,
- };
- const expectedParameters = {
- struct_val: {
- candidateCount: { int_val: 1 },
- maxOutputTokens: { int_val: 1024 },
- temperature: { float_val: 0.2 },
- topP: { float_val: 0.8 },
- topK: { int_val: 40 },
- },
- };
-
- const instancesResult = formatGoogleInputs(instances);
- const parametersResult = formatGoogleInputs(parameters);
- expect(JSON.stringify(instancesResult)).toEqual(JSON.stringify(expectedInstances));
- expect(JSON.stringify(parametersResult)).toEqual(JSON.stringify(expectedParameters));
- });
-});
diff --git a/api/app/clients/prompts/formatMessages.js b/api/app/clients/prompts/formatMessages.js
index 06662e08e7..d50fcb1024 100644
--- a/api/app/clients/prompts/formatMessages.js
+++ b/api/app/clients/prompts/formatMessages.js
@@ -1,17 +1,6 @@
const { ATTACHMENT_ONLY_TEXT } = require('@librechat/api');
const { EModelEndpoint, ContentTypes } = require('librechat-data-provider');
-const {
- AIMessage,
- ToolMessage,
- HumanMessage,
- SystemMessage,
-} = require('@librechat/agents/langchain/messages');
-
-/**
- * Stands in for a user turn that carries no text and whose attachments are no longer
- * being resent, so the turn stays valid without inventing content it never had.
- */
-const EMPTY_MESSAGE_PLACEHOLDER = '(no text)';
+const { AIMessage, HumanMessage, SystemMessage } = require('@librechat/agents/langchain/messages');
/**
* Formats a message to OpenAI Vision API payload format.
@@ -128,247 +117,6 @@ const formatMessage = ({ message, userName, assistantName, endpoint, langChain =
}
};
-/**
- * Formats an array of messages for LangChain.
- *
- * @param {Array<Object>} messages - The array of messages to format.
- * @param {Object} formatOptions - The options for formatting each message.
- * @param {string} [formatOptions.userName] - The name of the user.
- * @param {string} [formatOptions.assistantName] - The name of the assistant.
- * @returns {Array<(HumanMessage|AIMessage|SystemMessage)>} - The array of formatted LangChain messages.
- */
-const formatLangChainMessages = (messages, formatOptions) =>
- messages.map((msg) => formatMessage({ ...formatOptions, message: msg, langChain: true }));
-
-/**
- * Formats a LangChain message object by merging properties from `lc_kwargs` or `kwargs` and `additional_kwargs`.
- *
- * @param {Object} message - The message object to format.
- * @param {Object} [message.lc_kwargs] - Contains properties to be merged. Either this or `message.kwargs` should be provided.
- * @param {Object} [message.kwargs] - Contains properties to be merged. Either this or `message.lc_kwargs` should be provided.
- * @param {Object} [message.kwargs.additional_kwargs] - Additional properties to be merged.
- *
- * @returns {Object} The formatted LangChain message.
- */
-const formatFromLangChain = (message) => {
- const { additional_kwargs, ...message_kwargs } = message.lc_kwargs ?? message.kwargs;
- return {
- ...message_kwargs,
- ...additional_kwargs,
- };
-};
-
-/**
- * Formats an array of messages for LangChain, handling tool calls and creating ToolMessage instances.
- *
- * @param {Array<Partial<TMessage>>} payload - The array of messages to format.
- * @returns {Array<(HumanMessage|AIMessage|SystemMessage|ToolMessage)>} - The array of formatted LangChain messages, including ToolMessages for tool calls.
- */
-const formatAgentMessages = (payload) => {
- const messages = [];
-
- for (const message of payload) {
- if (typeof message.content === 'string') {
- /** An empty string yields a blank text block, which strict providers (Bedrock,
- * Anthropic) reject outright for the whole request. `formatVisionMessage`
- * already guards this for image-bearing sends; history replay of a
- * promptless send reaches here with no `image_urls`, so guard it too. */
- message.content = message.content.trim()
- ? [{ type: ContentTypes.TEXT, [ContentTypes.TEXT]: message.content }]
- : [];
- }
- if (message.role !== 'assistant') {
- const formatted = formatMessage({ message, langChain: true });
- /** A promptless send replayed from history can reduce to nothing once its
- * attachments are no longer resent. Providers reject a blank text block and
- * an empty content array alike, but dropping the turn is not safe either:
- * nothing merges the assistant turns it would leave adjacent, and the same
- * providers reject consecutive assistant messages. Keep the turn, and give
- * it the smallest honest stand-in for the content that is no longer there. */
- const { content: formattedContent } = formatted;
- const isEmpty = Array.isArray(formattedContent)
- ? formattedContent.length === 0
- : typeof formattedContent === 'string' && formattedContent.trim() === '';
- if (isEmpty) {
- formatted.content = [
- { type: ContentTypes.TEXT, [ContentTypes.TEXT]: EMPTY_MESSAGE_PLACEHOLDER },
- ];
- }
- messages.push(formatted);
- continue;
- }
-
- let currentContent = [];
- let lastAIMessage = null;
- /**
- * Every AIMessage produced from this TMessage that received `tool_calls`,
- * in order. Multi-step tool turns (where the agent loop cycles the LLM
- * multiple times with intervening tool results) produce one AIMessage per
- * cycle, each owning a different `tool_call_id`. We attach persisted
- * Vertex Gemini 3 thought signatures (`metadata.thoughtSignatures`,
- * keyed by `tool_call_id`) onto each one so every step has its right
- * signature on resume — Vertex validates per-step, not per-turn
- * (issue #13006 follow-up).
- */
- const toolBearingAIMessages = [];
-
- let hasReasoning = false;
- for (const part of message.content) {
- if (part.type === ContentTypes.TEXT && part.tool_call_ids) {
- /*
- If there's pending content, it needs to be aggregated as a single string to prepare for tool calls.
- For Anthropic models, the "tool_calls" field on a message is only respected if content is a string.
- */
- if (currentContent.length > 0) {
- let content = currentContent.reduce((acc, curr) => {
- if (curr.type === ContentTypes.TEXT) {
- return `${acc}${curr[ContentTypes.TEXT]}\n`;
- }
- return acc;
- }, '');
- content = `${content}\n${part[ContentTypes.TEXT] ?? ''}`.trim();
- lastAIMessage = new AIMessage({ content });
- messages.push(lastAIMessage);
- currentContent = [];
- continue;
- }
-
- // Create a new AIMessage with this text and prepare for tool calls
- lastAIMessage = new AIMessage({
- content: part.text || '',
- });
-
- messages.push(lastAIMessage);
- } else if (part.type === ContentTypes.TOOL_CALL) {
- if (!lastAIMessage) {
- throw new Error('Invalid tool call structure: No preceding AIMessage with tool_call_ids');
- }
-
- // Note: `tool_calls` list is defined when constructed by `AIMessage` class, and outputs should be excluded from it
- const {
- output,
- args: _args,
- inputValidationError: _inputValidationError,
- ...tool_call
- } = part.tool_call;
- // TODO: investigate; args as dictionary may need to be provider-or-tool-specific
- let args = _args;
- try {
- args = JSON.parse(_args);
- } catch (_e) {
- if (typeof _args === 'string') {
- args = { input: _args };
- }
- }
-
- tool_call.args = args;
- lastAIMessage.tool_calls.push(tool_call);
- if (toolBearingAIMessages[toolBearingAIMessages.length - 1] !== lastAIMessage) {
- toolBearingAIMessages.push(lastAIMessage);
- }
-
- // Add the corresponding ToolMessage
- messages.push(
- new ToolMessage({
- tool_call_id: tool_call.id,
- name: tool_call.name,
- content: output || '',
- }),
- );
- } else if (part.type === ContentTypes.THINK) {
- hasReasoning = true;
- continue;
- } else if (part.type === ContentTypes.STEER) {
- /*
- A mid-run steer: user speech persisted inline in the assistant message.
- Flush any accumulated assistant text first so ordering is preserved, then
- replay the steer as a standalone user message. `lastAIMessage` is NOT
- reset — the aggregator emits a fresh text-with-tool_call_ids part for any
- post-steer tool step, and preceding tool_call parts already pushed their
- ToolMessages, so the HumanMessage lands after them (valid provider order).
- */
- if (currentContent.length > 0) {
- if (currentContent.some((curr) => curr.type !== ContentTypes.TEXT)) {
- /** Non-text parts (images, files) must survive the flush intact —
- * folding to text here would drop them from replayed history. */
- messages.push(new AIMessage({ content: currentContent }));
- } else {
- const content = currentContent
- .reduce((acc, curr) => `${acc}${curr[ContentTypes.TEXT] ?? ''}\n`, '')
- .trim();
- if (content.length > 0) {
- messages.push(new AIMessage({ content }));
- }
- }
- currentContent = [];
- }
- messages.push(
- new HumanMessage({
- content:
- Array.isArray(part.media) && part.media.length > 0
- ? part.media
- : (part[ContentTypes.STEER] ?? ''),
- additional_kwargs: { source: 'steer' },
- }),
- );
- /** A post-steer tool_call must mint a FRESH assistant anchor —
- * attaching to the pre-steer one would emit its ToolMessage after
- * the HumanMessage while the call sat before it (invalid order). */
- lastAIMessage = null;
- } else if (
- part.type === ContentTypes.ERROR ||
- part.type === ContentTypes.AGENT_UPDATE ||
- part.type === ContentTypes.ACTIVITY_LABEL
- ) {
- // ACTIVITY_LABEL parts are UI-only progress notes — never model input.
- continue;
- } else {
- currentContent.push(part);
- }
- }
-
- if (hasReasoning) {
- currentContent = currentContent
- .reduce((acc, curr) => {
- if (curr.type === ContentTypes.TEXT) {
- return `${acc}${curr[ContentTypes.TEXT]}\n`;
- }
- return acc;
- }, '')
- .trim();
- }
-
- if (currentContent.length > 0) {
- messages.push(new AIMessage({ content: currentContent }));
- }
-
- /**
- * Restore signatures per-step. The persisted shape is
- * `{ [tool_call_id]: signature }`; for each tool-bearing AIMessage we
- * build a position-aligned `additional_kwargs.signatures` array (empty
- * placeholders for tool_calls without a stored signature). Agents'
- * `fixThoughtSignatures` then dispatches the non-empty entries to
- * functionCall parts in order — order matches because non-empty
- * signatures and tool_calls share their original parts ordering.
- */
- const sigsByCallId = message.metadata?.thoughtSignatures;
- if (sigsByCallId && typeof sigsByCallId === 'object' && toolBearingAIMessages.length > 0) {
- for (const aiMsg of toolBearingAIMessages) {
- const sigs = aiMsg.tool_calls.map((tc) => sigsByCallId[tc.id] ?? '');
- if (sigs.some((s) => typeof s === 'string' && s.length > 0)) {
- aiMsg.additional_kwargs ??= {};
- aiMsg.additional_kwargs.signatures = sigs;
- }
- }
- }
- }
-
- return messages;
-};
-
module.exports = {
formatMessage,
- formatFromLangChain,
- formatAgentMessages,
- formatLangChainMessages,
};
diff --git a/api/app/clients/prompts/formatMessages.spec.js b/api/app/clients/prompts/formatMessages.spec.js
index 45b397febe..962b94323c 100644
--- a/api/app/clients/prompts/formatMessages.spec.js
+++ b/api/app/clients/prompts/formatMessages.spec.js
@@ -1,7 +1,7 @@
const { ATTACHMENT_ONLY_TEXT } = require('@librechat/api');
const { Constants } = require('librechat-data-provider');
const { HumanMessage, AIMessage, SystemMessage } = require('@librechat/agents/langchain/messages');
-const { formatMessage, formatLangChainMessages, formatFromLangChain } = require('./formatMessages');
+const { formatMessage } = require('./formatMessages');
describe('formatMessage', () => {
it('formats user message', () => {
@@ -243,92 +243,3 @@ describe('formatMessage', () => {
expect(result.content).toBe('');
});
});
-
-describe('formatLangChainMessages', () => {
- it('formats an array of messages for LangChain', () => {
- const messages = [
- {
- role: 'system',
- content: 'This is a system message',
- },
- {
- sender: 'user',
- text: 'Hello',
- },
- {
- sender: 'assistant',
- text: 'Hi there',
- },
- ];
- const formatOptions = {
- userName: 'John',
- assistantName: 'Assistant',
- };
- const result = formatLangChainMessages(messages, formatOptions);
- expect(result).toHaveLength(3);
- expect(result[0]).toBeInstanceOf(SystemMessage);
- expect(result[1]).toBeInstanceOf(HumanMessage);
- expect(result[2]).toBeInstanceOf(AIMessage);
-
- expect(result[0].lc_kwargs.content).toEqual(messages[0].content);
- expect(result[1].lc_kwargs.content).toEqual(messages[1].text);
- expect(result[2].lc_kwargs.content).toEqual(messages[2].text);
-
- expect(result[1].lc_kwargs.name).toEqual(formatOptions.userName);
- expect(result[2].lc_kwargs.name).toEqual(formatOptions.assistantName);
- });
-
- describe('formatFromLangChain', () => {
- it('should merge kwargs and additional_kwargs', () => {
- const message = {
- kwargs: {
- content: 'some content',
- name: 'dan',
- additional_kwargs: {
- function_call: {
- name: 'dall-e',
- arguments: '{\n "input": "Subject: hedgehog, Style: cute"\n}',
- },
- },
- },
- };
-
- const expected = {
- content: 'some content',
- name: 'dan',
- function_call: {
- name: 'dall-e',
- arguments: '{\n "input": "Subject: hedgehog, Style: cute"\n}',
- },
- };
-
- expect(formatFromLangChain(message)).toEqual(expected);
- });
-
- it('should handle messages without additional_kwargs', () => {
- const message = {
- kwargs: {
- content: 'some content',
- name: 'dan',
- },
- };
-
- const expected = {
- content: 'some content',
- name: 'dan',
- };
-
- expect(formatFromLangChain(message)).toEqual(expected);
- });
-
- it('should handle empty messages', () => {
- const message = {
- kwargs: {},
- };
-
- const expected = {};
-
- expect(formatFromLangChain(message)).toEqual(expected);
- });
- });
-});
diff --git a/api/app/clients/prompts/index.js b/api/app/clients/prompts/index.js
index ba4859efe3..a0c6ff98db 100644
--- a/api/app/clients/prompts/index.js
+++ b/api/app/clients/prompts/index.js
@@ -1,12 +1,10 @@
const formatMessages = require('./formatMessages');
-const summaryPrompts = require('./summaryPrompts');
const truncate = require('./truncate');
const createVisionPrompt = require('./createVisionPrompt');
const createContextHandlers = require('./createContextHandlers');
module.exports = {
...formatMessages,
- ...summaryPrompts,
...truncate,
createVisionPrompt,
createContextHandlers,
diff --git a/api/app/clients/prompts/shadcn-docs/components.js b/api/app/clients/prompts/shadcn-docs/components.js
deleted file mode 100644
index b67c47d50f..0000000000
--- a/api/app/clients/prompts/shadcn-docs/components.js
+++ /dev/null
@@ -1,495 +0,0 @@
-// Essential Components
-const essentialComponents = {
- avatar: {
- componentName: 'Avatar',
- importDocs: 'import { Avatar, AvatarFallback, AvatarImage } from "/components/ui/avatar"',
- usageDocs: `
-<Avatar>
- <AvatarImage src="https://github.com/shadcn.png" />
- <AvatarFallback>CN</AvatarFallback>
-</Avatar>`,
- },
- button: {
- componentName: 'Button',
- importDocs: 'import { Button } from "/components/ui/button"',
- usageDocs: `
-<Button variant="outline">Button</Button>`,
- },
- card: {
- componentName: 'Card',
- importDocs: `
-import {
- Card,
- CardContent,
- CardDescription,
- CardFooter,
- CardHeader,
- CardTitle,
-} from "/components/ui/card"`,
- usageDocs: `
-<Card>
- <CardHeader>
- <CardTitle>Card Title</CardTitle>
- <CardDescription>Card Description</CardDescription>
- </CardHeader>
- <CardContent>
- <p>Card Content</p>
- </CardContent>
- <CardFooter>
- <p>Card Footer</p>
- </CardFooter>
-</Card>`,
- },
- checkbox: {
- componentName: 'Checkbox',
- importDocs: 'import { Checkbox } from "/components/ui/checkbox"',
- usageDocs: '<Checkbox />',
- },
- input: {
- componentName: 'Input',
- importDocs: 'import { Input } from "/components/ui/input"',
- usageDocs: '<Input />',
- },
- label: {
- componentName: 'Label',
- importDocs: 'import { Label } from "/components/ui/label"',
- usageDocs: '<Label htmlFor="email">Your email address</Label>',
- },
- radioGroup: {
- componentName: 'RadioGroup',
- importDocs: `
-import { Label } from "/components/ui/label"
-import { RadioGroup, RadioGroupItem } from "/components/ui/radio-group"`,
- usageDocs: `
-<RadioGroup defaultValue="option-one">
- <div className="flex items-center space-x-2">
- <RadioGroupItem value="option-one" id="option-one" />
- <Label htmlFor="option-one">Option One</Label>
- </div>
- <div className="flex items-center space-x-2">
- <RadioGroupItem value="option-two" id="option-two" />
- <Label htmlFor="option-two">Option Two</Label>
- </div>
-</RadioGroup>`,
- },
- select: {
- componentName: 'Select',
- importDocs: `
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "/components/ui/select"`,
- usageDocs: `
-<Select>
- <SelectTrigger className="w-[180px]">
- <SelectValue placeholder="Theme" />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="light">Light</SelectItem>
- <SelectItem value="dark">Dark</SelectItem>
- <SelectItem value="system">System</SelectItem>
- </SelectContent>
-</Select>`,
- },
- textarea: {
- componentName: 'Textarea',
- importDocs: 'import { Textarea } from "/components/ui/textarea"',
- usageDocs: '<Textarea />',
- },
-};
-
-// Extra Components
-const extraComponents = {
- accordion: {
- componentName: 'Accordion',
- importDocs: `
-import {
- Accordion,
- AccordionContent,
- AccordionItem,
- AccordionTrigger,
-} from "/components/ui/accordion"`,
- usageDocs: `
-<Accordion type="single" collapsible>
- <AccordionItem value="item-1">
- <AccordionTrigger>Is it accessible?</AccordionTrigger>
- <AccordionContent>
- Yes. It adheres to the WAI-ARIA design pattern.
- </AccordionContent>
- </AccordionItem>
-</Accordion>`,
- },
- alertDialog: {
- componentName: 'AlertDialog',
- importDocs: `
-import {
- AlertDialog,
- AlertDialogAction,
- AlertDialogCancel,
- AlertDialogContent,
- AlertDialogDescription,
- AlertDialogFooter,
- AlertDialogHeader,
- AlertDialogTitle,
- AlertDialogTrigger,
-} from "/components/ui/alert-dialog"`,
- usageDocs: `
-<AlertDialog>
- <AlertDialogTrigger>Open</AlertDialogTrigger>
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
- <AlertDialogDescription>
- This action cannot be undone.
- </AlertDialogDescription>
- </AlertDialogHeader>
- <AlertDialogFooter>
- <AlertDialogCancel>Cancel</AlertDialogCancel>
- <AlertDialogAction>Continue</AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
-</AlertDialog>`,
- },
- alert: {
- componentName: 'Alert',
- importDocs: `
-import {
- Alert,
- AlertDescription,
- AlertTitle,
-} from "/components/ui/alert"`,
- usageDocs: `
-<Alert>
- <AlertTitle>Heads up!</AlertTitle>
- <AlertDescription>
- You can add components to your app using the cli.
- </AlertDescription>
-</Alert>`,
- },
- aspectRatio: {
- componentName: 'AspectRatio',
- importDocs: 'import { AspectRatio } from "/components/ui/aspect-ratio"',
- usageDocs: `
-<AspectRatio ratio={16 / 9}>
- <Image src="..." alt="Image" className="rounded-md object-cover" />
-</AspectRatio>`,
- },
- badge: {
- componentName: 'Badge',
- importDocs: 'import { Badge } from "/components/ui/badge"',
- usageDocs: '<Badge>Badge</Badge>',
- },
- calendar: {
- componentName: 'Calendar',
- importDocs: 'import { Calendar } from "/components/ui/calendar"',
- usageDocs: '<Calendar />',
- },
- carousel: {
- componentName: 'Carousel',
- importDocs: `
-import {
- Carousel,
- CarouselContent,
- CarouselItem,
- CarouselNext,
- CarouselPrevious,
-} from "/components/ui/carousel"`,
- usageDocs: `
-<Carousel>
- <CarouselContent>
- <CarouselItem>...</CarouselItem>
- <CarouselItem>...</CarouselItem>
- <CarouselItem>...</CarouselItem>
- </CarouselContent>
- <CarouselPrevious />
- <CarouselNext />
-</Carousel>`,
- },
- collapsible: {
- componentName: 'Collapsible',
- importDocs: `
-import {
- Collapsible,
- CollapsibleContent,
- CollapsibleTrigger,
-} from "/components/ui/collapsible"`,
- usageDocs: `
-<Collapsible>
- <CollapsibleTrigger>Can I use this in my project?</CollapsibleTrigger>
- <CollapsibleContent>
- Yes. Free to use for personal and commercial projects. No attribution required.
- </CollapsibleContent>
-</Collapsible>`,
- },
- dialog: {
- componentName: 'Dialog',
- importDocs: `
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "/components/ui/dialog"`,
- usageDocs: `
-<Dialog>
- <DialogTrigger>Open</DialogTrigger>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Are you sure absolutely sure?</DialogTitle>
- <DialogDescription>
- This action cannot be undone.
- </DialogDescription>
- </DialogHeader>
- </DialogContent>
-</Dialog>`,
- },
- dropdownMenu: {
- componentName: 'DropdownMenu',
- importDocs: `
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
-} from "/components/ui/dropdown-menu"`,
- usageDocs: `
-<DropdownMenu>
- <DropdownMenuTrigger>Open</DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuLabel>My Account</DropdownMenuLabel>
- <DropdownMenuSeparator />
- <DropdownMenuItem>Profile</DropdownMenuItem>
- <DropdownMenuItem>Billing</DropdownMenuItem>
- <DropdownMenuItem>Team</DropdownMenuItem>
- <DropdownMenuItem>Subscription</DropdownMenuItem>
- </DropdownMenuContent>
-</DropdownMenu>`,
- },
- menubar: {
- componentName: 'Menubar',
- importDocs: `
-import {
- Menubar,
- MenubarContent,
- MenubarItem,
- MenubarMenu,
- MenubarSeparator,
- MenubarShortcut,
- MenubarTrigger,
-} from "/components/ui/menubar"`,
- usageDocs: `
-<Menubar>
- <MenubarMenu>
- <MenubarTrigger>File</MenubarTrigger>
- <MenubarContent>
- <MenubarItem>
- New Tab <MenubarShortcut>⌘T</MenubarShortcut>
- </MenubarItem>
- <MenubarItem>New Window</MenubarItem>
- <MenubarSeparator />
- <MenubarItem>Share</MenubarItem>
- <MenubarSeparator />
- <MenubarItem>Print</MenubarItem>
- </MenubarContent>
- </MenubarMenu>
-</Menubar>`,
- },
- navigationMenu: {
- componentName: 'NavigationMenu',
- importDocs: `
-import {
- NavigationMenu,
- NavigationMenuContent,
- NavigationMenuItem,
- NavigationMenuLink,
- NavigationMenuList,
- NavigationMenuTrigger,
- navigationMenuTriggerStyle,
-} from "/components/ui/navigation-menu"`,
- usageDocs: `
-<NavigationMenu>
- <NavigationMenuList>
- <NavigationMenuItem>
- <NavigationMenuTrigger>Item One</NavigationMenuTrigger>
- <NavigationMenuContent>
- <NavigationMenuLink>Link</NavigationMenuLink>
- </NavigationMenuContent>
- </NavigationMenuItem>
- </NavigationMenuList>
-</NavigationMenu>`,
- },
- popover: {
- componentName: 'Popover',
- importDocs: `
-import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "/components/ui/popover"`,
- usageDocs: `
-<Popover>
- <PopoverTrigger>Open</PopoverTrigger>
- <PopoverContent>Place content for the popover here.</PopoverContent>
-</Popover>`,
- },
- progress: {
- componentName: 'Progress',
- importDocs: 'import { Progress } from "/components/ui/progress"',
- usageDocs: '<Progress value={33} />',
- },
- separator: {
- componentName: 'Separator',
- importDocs: 'import { Separator } from "/components/ui/separator"',
- usageDocs: '<Separator />',
- },
- sheet: {
- componentName: 'Sheet',
- importDocs: `
-import {
- Sheet,
- SheetContent,
- SheetDescription,
- SheetHeader,
- SheetTitle,
- SheetTrigger,
-} from "/components/ui/sheet"`,
- usageDocs: `
-<Sheet>
- <SheetTrigger>Open</SheetTrigger>
- <SheetContent>
- <SheetHeader>
- <SheetTitle>Are you sure absolutely sure?</SheetTitle>
- <SheetDescription>
- This action cannot be undone.
- </SheetDescription>
- </SheetHeader>
- </SheetContent>
-</Sheet>`,
- },
- skeleton: {
- componentName: 'Skeleton',
- importDocs: 'import { Skeleton } from "/components/ui/skeleton"',
- usageDocs: '<Skeleton className="w-[100px] h-[20px] rounded-full" />',
- },
- slider: {
- componentName: 'Slider',
- importDocs: 'import { Slider } from "/components/ui/slider"',
- usageDocs: '<Slider defaultValue={[33]} max={100} step={1} />',
- },
- switch: {
- componentName: 'Switch',
- importDocs: 'import { Switch } from "/components/ui/switch"',
- usageDocs: '<Switch />',
- },
- table: {
- componentName: 'Table',
- importDocs: `
-import {
- Table,
- TableBody,
- TableCaption,
- TableCell,
- TableHead,
- TableHeader,
- TableRow,
-} from "/components/ui/table"`,
- usageDocs: `
-<Table>
- <TableCaption>A list of your recent invoices.</TableCaption>
- <TableHeader>
- <TableRow>
- <TableHead className="w-[100px]">Invoice</TableHead>
- <TableHead>Status</TableHead>
- <TableHead>Method</TableHead>
- <TableHead className="text-right">Amount</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- <TableRow>
- <TableCell className="font-medium">INV001</TableCell>
- <TableCell>Paid</TableCell>
- <TableCell>Credit Card</TableCell>
- <TableCell className="text-right">$250.00</TableCell>
- </TableRow>
- </TableBody>
-</Table>`,
- },
- tabs: {
- componentName: 'Tabs',
- importDocs: `
-import {
- Tabs,
- TabsContent,
- TabsList,
- TabsTrigger,
-} from "/components/ui/tabs"`,
- usageDocs: `
-<Tabs defaultValue="account" className="w-[400px]">
- <TabsList>
- <TabsTrigger value="account">Account</TabsTrigger>
- <TabsTrigger value="password">Password</TabsTrigger>
- </TabsList>
- <TabsContent value="account">Make changes to your account here.</TabsContent>
- <TabsContent value="password">Change your password here.</TabsContent>
-</Tabs>`,
- },
- toast: {
- componentName: 'Toast',
- importDocs: `
-import { useToast } from "/components/ui/use-toast"
-import { Button } from "/components/ui/button"`,
- usageDocs: `
-export function ToastDemo() {
- const { toast } = useToast()
- return (
- <Button
- onClick={() => {
- toast({
- title: "Scheduled: Catch up",
- description: "Friday, February 10, 2023 at 5:57 PM",
- })
- }}
- >
- Show Toast
- </Button>
- )
-}`,
- },
- toggle: {
- componentName: 'Toggle',
- importDocs: 'import { Toggle } from "/components/ui/toggle"',
- usageDocs: '<Toggle>Toggle</Toggle>',
- },
- tooltip: {
- componentName: 'Tooltip',
- importDocs: `
-import {
- Tooltip,
- TooltipContent,
- TooltipProvider,
- TooltipTrigger,
-} from "/components/ui/tooltip"`,
- usageDocs: `
-<TooltipProvider>
- <Tooltip>
- <TooltipTrigger>Hover</TooltipTrigger>
- <TooltipContent>
- <p>Add to library</p>
- </TooltipContent>
- </Tooltip>
-</TooltipProvider>`,
- },
-};
-
-const components = Object.assign({}, essentialComponents, extraComponents);
-
-module.exports = {
- components,
-};
diff --git a/api/app/clients/prompts/shadcn-docs/generate.js b/api/app/clients/prompts/shadcn-docs/generate.js
deleted file mode 100644
index 6a4cf8c7e3..0000000000
--- a/api/app/clients/prompts/shadcn-docs/generate.js
+++ /dev/null
@@ -1,50 +0,0 @@
-const dedent = require('dedent');
-
-/**
- * Generate system prompt for AI-assisted React component creation
- * @param {Object} options - Configuration options
- * @param {Object} options.components - Documentation for shadcn components
- * @param {boolean} [options.useXML=false] - Whether to use XML-style formatting for component instructions
- * @returns {string} The generated system prompt
- */
-function generateShadcnPrompt(options) {
- const { components, useXML = false } = options;
-
- let systemPrompt = dedent`
- ## Additional Artifact Instructions for React Components: "application/vnd.react"
-
- There are some prestyled components (primitives) available for use. Please use your best judgement to use any of these components if the app calls for one.
-
- Here are the components that are available, along with how to import them, and how to use them:
-
- ${Object.values(components)
- .map((component) => {
- if (useXML) {
- return dedent`
- <component>
- <name>${component.componentName}</name>
- <import-instructions>${component.importDocs}</import-instructions>
- <usage-instructions>${component.usageDocs}</usage-instructions>
- </component>
- `;
- } else {
- return dedent`
- # ${component.componentName}
-
- ## Import Instructions
- ${component.importDocs}
-
- ## Usage Instructions
- ${component.usageDocs}
- `;
- }
- })
- .join('\n\n')}
- `;
-
- return systemPrompt;
-}
-
-module.exports = {
- generateShadcnPrompt,
-};
diff --git a/api/app/clients/prompts/summaryPrompts.js b/api/app/clients/prompts/summaryPrompts.js
deleted file mode 100644
index 1897b19961..0000000000
--- a/api/app/clients/prompts/summaryPrompts.js
+++ /dev/null
@@ -1,53 +0,0 @@
-const { PromptTemplate } = require('@librechat/agents/langchain/prompts');
-/*
- * Without `{summary}` and `{new_lines}`, token count is 98
- * We are counting this towards the max context tokens for summaries, +3 for the assistant label (101)
- * If this prompt changes, use https://tiktokenizer.vercel.app/ to count the tokens
- */
-const _DEFAULT_SUMMARIZER_TEMPLATE = `Summarize the conversation by integrating new lines into the current summary.
-
-EXAMPLE:
-Current summary:
-The human inquires about the AI's view on artificial intelligence. The AI believes it's beneficial.
-
-New lines:
-Human: Why is it beneficial?
-AI: It helps humans achieve their potential.
-
-New summary:
-The human inquires about the AI's view on artificial intelligence. The AI believes it's beneficial because it helps humans achieve their potential.
-
-Current summary:
-{summary}
-
-New lines:
-{new_lines}
-
-New summary:`;
-
-const SUMMARY_PROMPT = new PromptTemplate({
- inputVariables: ['summary', 'new_lines'],
- template: _DEFAULT_SUMMARIZER_TEMPLATE,
-});
-
-/*
- * Without `{new_lines}`, token count is 27
- * We are counting this towards the max context tokens for summaries, rounded up to 30
- * If this prompt changes, use https://tiktokenizer.vercel.app/ to count the tokens
- */
-const _CUT_OFF_SUMMARIZER = `The following text is cut-off:
-{new_lines}
-
-Summarize the content as best as you can, noting that it was cut-off.
-
-Summary:`;
-
-const CUT_OFF_PROMPT = new PromptTemplate({
- inputVariables: ['new_lines'],
- template: _CUT_OFF_SUMMARIZER,
-});
-
-module.exports = {
- SUMMARY_PROMPT,
- CUT_OFF_PROMPT,
-};
diff --git a/api/app/clients/tools/structured/TavilySearch.js b/api/app/clients/tools/structured/TavilySearch.js
deleted file mode 100644
index a90b75b9f8..0000000000
--- a/api/app/clients/tools/structured/TavilySearch.js
+++ /dev/null
@@ -1,79 +0,0 @@
-const { z } = require('zod');
-const { fetch } = require('undici');
-const { tool } = require('@librechat/agents/langchain/tools');
-const { getEnvProxyDispatcher } = require('@librechat/api');
-const { getApiKey } = require('./credentials');
-
-function createTavilySearchTool(fields = {}) {
- const envVar = 'TAVILY_API_KEY';
- const override = fields.override ?? false;
- const apiKey = fields.apiKey ?? getApiKey(envVar, override);
- const kwargs = fields?.kwargs ?? {};
-
- return tool(
- async (input) => {
- const { query, ...rest } = input;
-
- const requestBody = {
- api_key: apiKey,
- query,
- ...rest,
- ...kwargs,
- };
-
- const fetchOptions = {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(requestBody),
- };
-
- const dispatcher = getEnvProxyDispatcher();
- if (dispatcher) {
- fetchOptions.dispatcher = dispatcher;
- }
-
- const response = await fetch('https://api.tavily.com/search', fetchOptions);
-
- const json = await response.json();
- if (!response.ok) {
- throw new Error(`Request failed with status ${response.status}: ${json.error}`);
- }
-
- return JSON.stringify(json);
- },
- {
- name: 'tavily_search_results_json',
- description:
- 'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events.',
- schema: z.object({
- query: z.string().min(1).describe('The search query string.'),
- max_results: z
- .number()
- .min(1)
- .max(10)
- .optional()
- .describe('The maximum number of search results to return. Defaults to 5.'),
- search_depth: z
- .enum(['basic', 'advanced'])
- .optional()
- .describe(
- 'The depth of the search, affecting result quality and response time (`basic` or `advanced`). Default is basic for quick results and advanced for indepth high quality results but longer response time. Advanced calls equals 2 requests.',
- ),
- include_images: z
- .boolean()
- .optional()
- .describe(
- 'Whether to include a list of query-related images in the response. Default is False.',
- ),
- include_answer: z
- .boolean()
- .optional()
- .describe('Whether to include answers in the search results. Default is False.'),
- }),
- },
- );
-}
-
-module.exports = createTavilySearchTool;
diff --git a/api/app/clients/tools/structured/credentials.js b/api/app/clients/tools/structured/credentials.js
deleted file mode 100644
index f9c4eae925..0000000000
--- a/api/app/clients/tools/structured/credentials.js
+++ /dev/null
@@ -1,13 +0,0 @@
-const { getEnvironmentVariable } = require('@librechat/agents/langchain/utils/env');
-
-function getApiKey(envVar, override) {
- const key = getEnvironmentVariable(envVar);
- if (!key && !override) {
- throw new Error(`Missing ${envVar} environment variable.`);
- }
- return key;
-}
-
-module.exports = {
- getApiKey,
-};
diff --git a/api/app/clients/tools/structured/specs/GeminiImageGen-proxy.spec.js b/api/app/clients/tools/structured/specs/GeminiImageGen-proxy.spec.js
deleted file mode 100644
index dbdda6e454..0000000000
--- a/api/app/clients/tools/structured/specs/GeminiImageGen-proxy.spec.js
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * These tests verify the proxy wrapper behavior for GeminiImageGen.
- * Instead of loading the full module (which has many dependencies),
- * we directly test the wrapper logic that would be applied.
- */
-describe('GeminiImageGen Proxy Configuration', () => {
- let originalEnv;
- let originalFetch;
-
- beforeAll(() => {
- originalEnv = { ...process.env };
- originalFetch = globalThis.fetch;
- });
-
- beforeEach(() => {
- process.env = { ...originalEnv };
- globalThis.fetch = originalFetch;
- });
-
- afterEach(() => {
- process.env = originalEnv;
- globalThis.fetch = originalFetch;
- });
-
- /**
- * Simulates the proxy wrapper that GeminiImageGen applies at module load.
- * This is the same logic from GeminiImageGen.js lines 30-42.
- */
- function applyProxyWrapper() {
- const proxyDispatcher = process.env.PROXY ? { type: 'proxy-dispatcher' } : undefined;
- if (proxyDispatcher) {
- const _originalFetch = globalThis.fetch;
-
- globalThis.fetch = function (url, options = {}) {
- const urlString = url.toString();
- if (urlString.includes('googleapis.com')) {
- options = { ...options, dispatcher: proxyDispatcher };
- }
- return _originalFetch.call(this, url, options);
- };
- }
- }
-
- it('should wrap globalThis.fetch when PROXY env is set', () => {
- process.env.PROXY = 'http://proxy.example.com:8080';
-
- const fetchBeforeWrap = globalThis.fetch;
-
- applyProxyWrapper();
-
- expect(globalThis.fetch).not.toBe(fetchBeforeWrap);
- });
-
- it('should not wrap globalThis.fetch when PROXY env is not set', () => {
- delete process.env.PROXY;
-
- const fetchBeforeWrap = globalThis.fetch;
-
- applyProxyWrapper();
-
- expect(globalThis.fetch).toBe(fetchBeforeWrap);
- });
-
- it('should add dispatcher to googleapis.com URLs', async () => {
- process.env.PROXY = 'http://proxy.example.com:8080';
-
- let capturedOptions = null;
- const mockFetch = jest.fn((url, options) => {
- capturedOptions = options;
- return Promise.resolve({ ok: true });
- });
- globalThis.fetch = mockFetch;
-
- applyProxyWrapper();
-
- await globalThis.fetch('https://generativelanguage.googleapis.com/v1/models', {});
-
- expect(capturedOptions).toBeDefined();
- expect(capturedOptions.dispatcher).toEqual({ type: 'proxy-dispatcher' });
- });
-
- it('should not add dispatcher to non-googleapis.com URLs', async () => {
- process.env.PROXY = 'http://proxy.example.com:8080';
-
- let capturedOptions = null;
- const mockFetch = jest.fn((url, options) => {
- capturedOptions = options;
- return Promise.resolve({ ok: true });
- });
- globalThis.fetch = mockFetch;
-
- applyProxyWrapper();
-
- await globalThis.fetch('https://api.openai.com/v1/images', {});
-
- expect(capturedOptions).toBeDefined();
- expect(capturedOptions.dispatcher).toBeUndefined();
- });
-
- it('should preserve existing options when adding dispatcher', async () => {
- process.env.PROXY = 'http://proxy.example.com:8080';
-
- let capturedOptions = null;
- const mockFetch = jest.fn((url, options) => {
- capturedOptions = options;
- return Promise.resolve({ ok: true });
- });
- globalThis.fetch = mockFetch;
-
- applyProxyWrapper();
-
- const customHeaders = { 'X-Custom-Header': 'test' };
- await globalThis.fetch('https://aiplatform.googleapis.com/v1/models', {
- headers: customHeaders,
- method: 'POST',
- });
-
- expect(capturedOptions).toBeDefined();
- expect(capturedOptions.dispatcher).toEqual({ type: 'proxy-dispatcher' });
- expect(capturedOptions.headers).toEqual(customHeaders);
- expect(capturedOptions.method).toBe('POST');
- });
-});
diff --git a/api/app/clients/tools/util/handleTools.js b/api/app/clients/tools/util/handleTools.js
index 91e87bb10d..b02270f001 100644
--- a/api/app/clients/tools/util/handleTools.js
+++ b/api/app/clients/tools/util/handleTools.js
@@ -44,7 +44,6 @@ const {
resolveMCPAppsPolicy,
} = require('librechat-data-provider');
const {
- availableTools,
manifestToolMap,
// Basic Tools
GoogleSearchAPI,
@@ -71,75 +70,11 @@ const { getMCPRequestContext } = require('~/server/services/MCPRequestContext');
const { createOpenIDSessionTokenProvider } = require('~/server/services/OpenIDSessionRefresh');
const { createFileSearchTool, primeFiles: primeSearchFiles } = require('./fileSearch');
const { primeFiles: primeCodeFiles } = require('~/server/services/Files/Code/process');
-const { getUserPluginAuthValue } = require('~/server/services/PluginService');
const { loadAuthValues } = require('~/server/services/Tools/credentials');
const { getMCPServerTools, checkCapability } = require('~/server/services/Config');
const { getMCPServersRegistry } = require('~/config');
const { getRoleByName, setMemory, deleteMemory, getFormattedMemories } = require('~/models');
-/**
- * Validates the availability and authentication of tools for a user based on environment variables or user-specific plugin authentication values.
- * Tools without required authentication or with valid authentication are considered valid.
- *
- * @param {Object} user The user object for whom to validate tool access.
- * @param {Array<string>} tools An array of tool identifiers to validate. Defaults to an empty array.
- * @returns {Promise<Array<string>>} A promise that resolves to an array of valid tool identifiers.
- */
-const validateTools = async (user, tools = []) => {
- try {
- const validToolsSet = new Set(tools);
- const availableToolsToValidate = availableTools.filter((tool) =>
- validToolsSet.has(tool.pluginKey),
- );
-
- /**
- * Validates the credentials for a given auth field or set of alternate auth fields for a tool.
- * If valid admin or user authentication is found, the function returns early. Otherwise, it removes the tool from the set of valid tools.
- *
- * @param {string} authField The authentication field or fields (separated by "||" for alternates) to validate.
- * @param {string} toolName The identifier of the tool being validated.
- */
- const validateCredentials = async (authField, toolName) => {
- const fields = authField.split('||');
- for (const field of fields) {
- const adminAuth = process.env[field];
- if (adminAuth && adminAuth.length > 0) {
- return;
- }
-
- let userAuth = null;
- try {
- userAuth = await getUserPluginAuthValue(user, field);
- } catch (err) {
- if (field === fields[fields.length - 1] && !userAuth) {
- throw err;
- }
- }
- if (userAuth && userAuth.length > 0) {
- return;
- }
- }
-
- validToolsSet.delete(toolName);
- };
-
- for (const tool of availableToolsToValidate) {
- if (!tool.authConfig || tool.authConfig.length === 0) {
- continue;
- }
-
- for (const auth of tool.authConfig) {
- await validateCredentials(auth.authField, tool.pluginKey);
- }
- }
-
- return Array.from(validToolsSet.values());
- } catch (err) {
- logger.error('[validateTools] There was a problem validating tools', err);
- throw new Error(err);
- }
-};
-
/** @typedef {typeof import('@librechat/agents/langchain/tools').Tool} ToolConstructor */
/** @typedef {import('@librechat/agents/langchain/tools').Tool} Tool */
@@ -710,6 +645,5 @@ const loadTools = async ({
module.exports = {
loadToolWithAuth,
- validateTools,
loadTools,
};
diff --git a/api/app/clients/tools/util/handleTools.test.js b/api/app/clients/tools/util/handleTools.test.js
index 75433afdff..d386288345 100644
--- a/api/app/clients/tools/util/handleTools.test.js
+++ b/api/app/clients/tools/util/handleTools.test.js
@@ -98,7 +98,7 @@ const { ASK_USER_QUESTION_TOOL_NAME, STANDARD_MCP_CAPABILITY_PROFILE } = require
const { User } = require('~/db/models');
const PluginService = require('~/server/services/PluginService');
-const { validateTools, loadTools, loadToolWithAuth } = require('./handleTools');
+const { loadTools, loadToolWithAuth } = require('./handleTools');
const { StructuredSD, availableTools, DALLE3 } = require('../');
describe('Tool Handlers', () => {
@@ -189,38 +189,6 @@ describe('Tool Handlers', () => {
}
});
- describe('validateTools', () => {
- it('returns valid tools given input tools and user authentication', async () => {
- const validTools = await validateTools(fakeUser._id, initialTools);
- expect(validTools).toBeDefined();
- expect(validTools.some((tool) => tool === pluginKey)).toBeTruthy();
- expect(validTools.length).toBeGreaterThan(0);
- });
-
- it('removes tools without valid credentials from the validTools array', async () => {
- const validTools = await validateTools(fakeUser._id, initialTools);
- expect(validTools.some((tool) => tool.pluginKey === pluginKey2)).toBeFalsy();
- });
-
- it('returns an empty array when no authenticated tools are provided', async () => {
- const validTools = await validateTools(fakeUser._id, []);
- expect(validTools).toEqual([]);
- });
-
- it('should validate a tool from an Environment Variable', async () => {
- const plugin = availableTools.find((tool) => tool.pluginKey === pluginKey2);
- const authConfigs = plugin.authConfig;
- for (const authConfig of authConfigs) {
- process.env[authConfig.authField] = mockCredential;
- }
- const validTools = await validateTools(fakeUser._id, [pluginKey2]);
- expect(validTools.length).toEqual(1);
- for (const authConfig of authConfigs) {
- delete process.env[authConfig.authField];
- }
- });
- });
-
describe('loadTools', () => {
let toolFunctions;
let loadTool1;
diff --git a/api/app/clients/tools/util/index.js b/api/app/clients/tools/util/index.js
index 9c96fb50f3..7fc31e3998 100644
--- a/api/app/clients/tools/util/index.js
+++ b/api/app/clients/tools/util/index.js
@@ -1,6 +1,5 @@
-const { validateTools, loadTools } = require('./handleTools');
+const { loadTools } = require('./handleTools');
module.exports = {
- validateTools,
loadTools,
};
diff --git a/api/app/index.js b/api/app/index.js
deleted file mode 100644
index bb11fb0877..0000000000
--- a/api/app/index.js
+++ /dev/null
@@ -1,5 +0,0 @@
-const clients = require('./clients');
-
-module.exports = {
- ...clients,
-};
diff --git a/api/config/meiliLogger.js b/api/config/meiliLogger.js
deleted file mode 100644
index 7eb6e3b986..0000000000
--- a/api/config/meiliLogger.js
+++ /dev/null
@@ -1,110 +0,0 @@
-const path = require('path');
-const fs = require('fs');
-const winston = require('winston');
-require('winston-daily-rotate-file');
-
-/**
- * Determine the log directory.
- * Priority:
- * 1. LIBRECHAT_LOG_DIR environment variable (allows user override)
- * 2. /app/logs if running in Docker (bind-mounted with correct permissions)
- * 3. api/logs relative to this file (local development)
- */
-const getLogDir = () => {
- if (process.env.LIBRECHAT_LOG_DIR) {
- return process.env.LIBRECHAT_LOG_DIR;
- }
-
- // Check if running in Docker container (cwd is /app)
- if (process.cwd() === '/app') {
- const dockerLogDir = '/app/logs';
- // Ensure the directory exists
- if (!fs.existsSync(dockerLogDir)) {
- fs.mkdirSync(dockerLogDir, { recursive: true });
- }
- return dockerLogDir;
- }
-
- // Local development: use api/logs relative to this file
- return path.join(__dirname, '..', 'logs');
-};
-
-const { NODE_ENV, DEBUG_LOGGING = false, LOG_TO_FILE = true } = process.env;
-
-const useDebugLogging =
- (typeof DEBUG_LOGGING === 'string' && DEBUG_LOGGING?.toLowerCase() === 'true') ||
- DEBUG_LOGGING === true;
-
-const useFileLogging =
- (typeof LOG_TO_FILE === 'string' && LOG_TO_FILE?.toLowerCase() !== 'false') ||
- LOG_TO_FILE === true;
-
-const levels = {
- error: 0,
- warn: 1,
- info: 2,
- http: 3,
- verbose: 4,
- debug: 5,
- activity: 6,
- silly: 7,
-};
-
-winston.addColors({
- info: 'green', // fontStyle color
- warn: 'italic yellow',
- error: 'red',
- debug: 'blue',
-});
-
-const level = () => {
- const env = NODE_ENV || 'development';
- const isDevelopment = env === 'development';
- return isDevelopment ? 'debug' : 'warn';
-};
-
-const fileFormat = winston.format.combine(
- winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
- winston.format.errors({ stack: true }),
- winston.format.splat(),
-);
-
-const logLevel = useDebugLogging ? 'debug' : 'error';
-const transports = [];
-
-if (useFileLogging) {
- const logDir = getLogDir();
-
- transports.push(
- new winston.transports.DailyRotateFile({
- level: logLevel,
- filename: `${logDir}/meiliSync-%DATE%.log`,
- datePattern: 'YYYY-MM-DD',
- zippedArchive: true,
- maxSize: '20m',
- maxFiles: '14d',
- format: fileFormat,
- }),
- );
-}
-
-const consoleFormat = winston.format.combine(
- winston.format.colorize({ all: true }),
- winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
- winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`),
-);
-
-transports.push(
- new winston.transports.Console({
- level: 'info',
- format: consoleFormat,
- }),
-);
-
-const logger = winston.createLogger({
- level: level(),
- levels,
- transports,
-});
-
-module.exports = logger;
diff --git a/api/package.json b/api/package.json
index c63c38ea1d..28e968fb75 100644
--- a/api/package.json
+++ b/api/package.json
@@ -7,14 +7,7 @@
"server-dev": "echo 'please run this from the root directory'",
"test": "cross-env NODE_ENV=test jest",
"b:test": "NODE_ENV=test bun jest",
- "test:ci": "jest --ci --logHeapUsage",
- "add-balance": "node ./add-balance.js",
- "list-balances": "node ./list-balances.js",
- "user-stats": "node ./user-stats.js",
- "create-user": "node ./create-user.js",
- "invite-user": "node ./invite-user.js",
- "ban-user": "node ./ban-user.js",
- "delete-user": "node ./delete-user.js"
+ "test:ci": "jest --ci --logHeapUsage"
},
"repository": {
"type": "git",
@@ -111,7 +104,6 @@
"nanoid": "^3.3.18",
"node-fetch": "^2.7.0",
"nodemailer": "^10.0.2",
- "ollama": "^0.5.0",
"openai": "5.8.2",
"openid-client": "^6.5.0",
"passport": "^0.6.0",
diff --git a/api/server/cleanup.js b/api/server/cleanup.js
index c27814292d..28f428edef 100644
--- a/api/server/cleanup.js
+++ b/api/server/cleanup.js
@@ -1,34 +1,5 @@
const { logger } = require('@librechat/data-schemas');
-/** WeakMap to hold temporary data associated with requests */
-const requestDataMap = new WeakMap();
-
-const FinalizationRegistry = global.FinalizationRegistry || null;
-
-/**
- * FinalizationRegistry to clean up client objects when they are garbage collected.
- * This is used to prevent memory leaks and ensure that client objects are
- * properly disposed of when they are no longer needed.
- * The registry holds a weak reference to the client object and a cleanup
- * callback that is called when the client object is garbage collected.
- * The callback can be used to perform any necessary cleanup operations,
- * such as removing event listeners or freeing up resources.
- */
-const clientRegistry = FinalizationRegistry
- ? new FinalizationRegistry((heldValue) => {
- try {
- // This will run when the client is garbage collected
- if (heldValue && heldValue.userId) {
- logger.debug(`[FinalizationRegistry] Cleaning up client for user ${heldValue.userId}`);
- } else {
- logger.debug('[FinalizationRegistry] Cleaning up client');
- }
- } catch {
- // Ignore errors
- }
- })
- : null;
-
const graphPropsToClean = [
'handlerRegistry',
'runId',
@@ -153,9 +124,6 @@ function disposeClient(client) {
if (client.isVisionModel) {
client.isVisionModel = null;
}
- if (client.isChatCompletion !== undefined) {
- client.isChatCompletion = null;
- }
if (client.contextHandlers) {
client.contextHandlers = null;
}
@@ -386,46 +354,6 @@ function disposeClient(client) {
}
}
-function processReqData(data = {}, context) {
- let {
- abortKey,
- userMessage,
- userMessagePromise,
- responseMessageId,
- promptTokens,
- conversationId,
- userMessageId,
- } = context;
- for (const key in data) {
- if (key === 'userMessage') {
- userMessage = data[key];
- userMessageId = data[key].messageId;
- } else if (key === 'userMessagePromise') {
- userMessagePromise = data[key];
- } else if (key === 'responseMessageId') {
- responseMessageId = data[key];
- } else if (key === 'promptTokens') {
- promptTokens = data[key];
- } else if (key === 'abortKey') {
- abortKey = data[key];
- } else if (!conversationId && key === 'conversationId') {
- conversationId = data[key];
- }
- }
- return {
- abortKey,
- userMessage,
- userMessagePromise,
- responseMessageId,
- promptTokens,
- conversationId,
- userMessageId,
- };
-}
-
module.exports = {
disposeClient,
- requestDataMap,
- clientRegistry,
- processReqData,
};
diff --git a/api/server/controllers/PluginController.js b/api/server/controllers/PluginController.js
index b5fb6f0b56..b59fe26e65 100644
--- a/api/server/controllers/PluginController.js
+++ b/api/server/controllers/PluginController.js
@@ -9,47 +9,6 @@ const { getCachedTools, setCachedTools } = require('~/server/services/Config');
const { availableTools, toolkits } = require('~/app/clients/tools');
const { getAppConfig } = require('~/server/services/Config');
-const getAvailablePluginsController = async (req, res) => {
- try {
- const appConfig =
- req.config ??
- (await getAppConfig({
- role: req.user?.role,
- userId: req.user?.id,
- tenantId: req.user?.tenantId,
- }));
- const { filteredTools = [], includedTools = [] } = appConfig;
-
- const uniquePlugins = filterUniquePlugins(
- filterGitHubComparePlugins(availableTools, appConfig?.githubCompare),
- );
- const includeSet = new Set(includedTools);
- const filterSet = new Set(filteredTools);
-
- /** includedTools takes precedence — filteredTools ignored when both are set. */
- const plugins = [];
- for (const plugin of uniquePlugins) {
- /** Agents-runtime-only tools (e.g. ask_user_question) never work on the
- * legacy plugins endpoint — no run to pause, no resume surface. */
- if (plugin.agentsOnly === true) {
- continue;
- }
- if (includeSet.size > 0) {
- if (!includeSet.has(plugin.pluginKey)) {
- continue;
- }
- } else if (filterSet.has(plugin.pluginKey)) {
- continue;
- }
- plugins.push(checkPluginAuth(plugin) ? { ...plugin, authenticated: true } : plugin);
- }
-
- res.status(200).json(plugins);
- } catch (error) {
- res.status(500).json({ message: error.message });
- }
-};
-
const getAvailableTools = async (req, res) => {
try {
const userId = req.user?.id;
@@ -119,5 +78,4 @@ const getAvailableTools = async (req, res) => {
module.exports = {
getAvailableTools,
- getAvailablePluginsController,
};
diff --git a/api/server/controllers/PluginController.spec.js b/api/server/controllers/PluginController.spec.js
index e9198fb6d1..b49eacec1d 100644
--- a/api/server/controllers/PluginController.spec.js
+++ b/api/server/controllers/PluginController.spec.js
@@ -22,7 +22,7 @@ jest.mock('~/app/clients/tools', () => ({
toolkits: [],
}));
-const { getAvailableTools, getAvailablePluginsController } = require('./PluginController');
+const { getAvailableTools } = require('./PluginController');
describe('PluginController', () => {
let mockReq, mockRes;
@@ -50,120 +50,6 @@ describe('PluginController', () => {
});
});
- describe('getAvailablePluginsController', () => {
- it('should use filterUniquePlugins to remove duplicate plugins', async () => {
- const mockPlugins = [
- { name: 'Plugin1', pluginKey: 'key1', description: 'First' },
- { name: 'Plugin1', pluginKey: 'key1', description: 'First duplicate' },
- { name: 'Plugin2', pluginKey: 'key2', description: 'Second' },
- ];
-
- require('~/app/clients/tools').availableTools.push(...mockPlugins);
-
- getAppConfig.mockResolvedValueOnce({
- filteredTools: [],
- includedTools: [],
- });
-
- await getAvailablePluginsController(mockReq, mockRes);
-
- expect(mockRes.status).toHaveBeenCalledWith(200);
- const responseData = mockRes.json.mock.calls[0][0];
- expect(responseData).toHaveLength(2);
- expect(responseData[0].pluginKey).toBe('key1');
- expect(responseData[1].pluginKey).toBe('key2');
- });
-
- it('should use checkPluginAuth to verify plugin authentication', async () => {
- const mockPlugin = { name: 'Plugin1', pluginKey: 'key1', description: 'First' };
-
- require('~/app/clients/tools').availableTools.push(mockPlugin);
-
- getAppConfig.mockResolvedValueOnce({
- filteredTools: [],
- includedTools: [],
- });
-
- await getAvailablePluginsController(mockReq, mockRes);
-
- const responseData = mockRes.json.mock.calls[0][0];
- expect(responseData[0].authenticated).toBeUndefined();
- });
-
- it('excludes agentsOnly plugins from the legacy plugins endpoint (no run to pause)', async () => {
- require('~/app/clients/tools').availableTools.push(
- { name: 'Ask User', pluginKey: 'ask_user_question', description: 'q', agentsOnly: true },
- { name: 'Plugin2', pluginKey: 'key2', description: 'Second' },
- );
-
- await getAvailablePluginsController(mockReq, mockRes);
-
- const responseData = mockRes.json.mock.calls[0][0];
- expect(responseData.map((p) => p.pluginKey)).toEqual(['key2']);
- });
-
- it('should filter plugins based on includedTools', async () => {
- const mockPlugins = [
- { name: 'Plugin1', pluginKey: 'key1', description: 'First' },
- { name: 'Plugin2', pluginKey: 'key2', description: 'Second' },
- ];
-
- require('~/app/clients/tools').availableTools.push(...mockPlugins);
-
- mockReq.config = {
- filteredTools: [],
- includedTools: ['key1'],
- };
-
- await getAvailablePluginsController(mockReq, mockRes);
-
- const responseData = mockRes.json.mock.calls[0][0];
- expect(responseData).toHaveLength(1);
- expect(responseData[0].pluginKey).toBe('key1');
- });
-
- it('should exclude plugins in filteredTools', async () => {
- const mockPlugins = [
- { name: 'Plugin1', pluginKey: 'key1', description: 'First' },
- { name: 'Plugin2', pluginKey: 'key2', description: 'Second' },
- ];
-
- require('~/app/clients/tools').availableTools.push(...mockPlugins);
-
- mockReq.config = {
- filteredTools: ['key2'],
- includedTools: [],
- };
-
- await getAvailablePluginsController(mockReq, mockRes);
-
- const responseData = mockRes.json.mock.calls[0][0];
- expect(responseData).toHaveLength(1);
- expect(responseData[0].pluginKey).toBe('key1');
- });
-
- it('should ignore filteredTools when includedTools is set', async () => {
- const mockPlugins = [
- { name: 'Plugin1', pluginKey: 'key1', description: 'First' },
- { name: 'Plugin2', pluginKey: 'key2', description: 'Second' },
- { name: 'Plugin3', pluginKey: 'key3', description: 'Third' },
- ];
-
- require('~/app/clients/tools').availableTools.push(...mockPlugins);
-
- mockReq.config = {
- includedTools: ['key1', 'key2'],
- filteredTools: ['key2'],
- };
-
- await getAvailablePluginsController(mockReq, mockRes);
-
- const responseData = mockRes.json.mock.calls[0][0];
- expect(responseData).toHaveLength(2);
- expect(responseData.map((p) => p.pluginKey)).toEqual(['key1', 'key2']);
- });
- });
-
describe('getAvailableTools', () => {
it.each([undefined, false, true])(
'gates the comparison entry on request policy (%p)',
@@ -390,17 +276,6 @@ describe('PluginController', () => {
expect(mockRes.json).toHaveBeenCalledWith([]);
});
- it('should handle undefined filteredTools and includedTools', async () => {
- mockReq.config = {};
-
- getAppConfig.mockResolvedValueOnce({});
-
- await getAvailablePluginsController(mockReq, mockRes);
-
- expect(mockRes.status).toHaveBeenCalledWith(200);
- expect(mockRes.json).toHaveBeenCalledWith([]);
- });
-
it('should handle toolkit with undefined toolDefinitions keys', async () => {
const mockToolkit = {
name: 'Toolkit1',
diff --git a/api/server/controllers/agents/__tests__/openai.spec.js b/api/server/controllers/agents/__tests__/openai.spec.js
index d7511dba92..daac481e4e 100644
--- a/api/server/controllers/agents/__tests__/openai.spec.js
+++ b/api/server/controllers/agents/__tests__/openai.spec.js
@@ -405,8 +405,6 @@ jest.mock('~/server/services/Endpoints/agents/skillDeps', () => ({
getSkillDbMethods: jest.fn(() => ({})),
canAuthorSkillFiles: mockCanAuthorSkillFiles,
withDeploymentSkillIds: jest.fn((ids = []) => ids),
- enrichWithSkillConfigurable: mockEnrichWithSkillConfigurable,
- buildSkillPrimedIdsByName: mockBuildSkillPrimedIdsByName,
buildAgentToolContext: mockBuildAgentToolContext,
resolveMemoryAvailability: mockResolveMemoryAvailability,
enrichLoadedToolsWithAgentContext: mockEnrichLoadedToolsWithAgentContext,
diff --git a/api/server/controllers/agents/__tests__/request.partialDisconnect.spec.js b/api/server/controllers/agents/__tests__/request.partialDisconnect.spec.js
index 8f7662158c..69492ce29a 100644
--- a/api/server/controllers/agents/__tests__/request.partialDisconnect.spec.js
+++ b/api/server/controllers/agents/__tests__/request.partialDisconnect.spec.js
@@ -124,10 +124,6 @@ jest.mock('@librechat/api', () => ({
jest.mock('~/server/cleanup', () => ({
disposeClient: jest.fn(),
- clientRegistry: null,
- requestDataMap: {
- set: jest.fn(),
- },
}));
jest.mock('~/server/middleware', () => ({
diff --git a/api/server/controllers/agents/__tests__/request.resumeMetadata.spec.js b/api/server/controllers/agents/__tests__/request.resumeMetadata.spec.js
index 8b9e2196e1..f2754ce74f 100644
--- a/api/server/controllers/agents/__tests__/request.resumeMetadata.spec.js
+++ b/api/server/controllers/agents/__tests__/request.resumeMetadata.spec.js
@@ -391,10 +391,6 @@ jest.mock('@librechat/api', () => ({
jest.mock('~/server/cleanup', () => ({
disposeClient: jest.fn(),
- clientRegistry: null,
- requestDataMap: {
- set: jest.fn(),
- },
}));
jest.mock('~/server/middleware', () => ({
diff --git a/api/server/controllers/agents/__tests__/responses.unit.spec.js b/api/server/controllers/agents/__tests__/responses.unit.spec.js
index 6be7ee74d5..36823a6406 100644
--- a/api/server/controllers/agents/__tests__/responses.unit.spec.js
+++ b/api/server/controllers/agents/__tests__/responses.unit.spec.js
@@ -518,8 +518,6 @@ jest.mock('~/server/services/Endpoints/agents/skillDeps', () => ({
getSkillDbMethods: jest.fn(() => ({})),
canAuthorSkillFiles: mockCanAuthorSkillFiles,
withDeploymentSkillIds: jest.fn((ids = []) => ids),
- enrichWithSkillConfigurable: mockEnrichWithSkillConfigurable,
- buildSkillPrimedIdsByName: mockBuildSkillPrimedIdsByName,
buildAgentToolContext: mockBuildAgentToolContext,
resolveMemoryAvailability: mockResolveMemoryAvailability,
enrichLoadedToolsWithAgentContext: mockEnrichLoadedToolsWithAgentContext,
diff --git a/api/server/controllers/agents/client.js b/api/server/controllers/agents/client.js
index aab16bed67..d74f4bba6c 100644
--- a/api/server/controllers/agents/client.js
+++ b/api/server/controllers/agents/client.js
@@ -603,8 +603,6 @@ class AgentClient extends BaseClient {
* @type {string} */
this.clientName = EModelEndpoint.agents;
- /** @deprecated @type {true} - Is a Chat Completion Request */
- this.isChatCompletion = true;
/** @type {number | undefined} */
this.jobCreatedAt = options.jobCreatedAt;
/** Generation-scoped LangGraph checkpoint namespace. Legacy paused jobs
@@ -4951,33 +4949,6 @@ class AgentClient extends BaseClient {
);
config = withPrivateTextAdmissionConfig(config, initialModelBoundAdmission);
- // TODO: needs to be added as part of AgentContext initialization
- // const noSystemModelRegex = [/\b(o1-preview|o1-mini|amazon\.titan-text)\b/gi];
- // const noSystemMessages = noSystemModelRegex.some((regex) =>
- // agent.model_parameters.model.match(regex),
- // );
- // if (noSystemMessages === true && systemContent?.length) {
- // const latestMessageContent = _messages.pop().content;
- // if (typeof latestMessageContent !== 'string') {
- // latestMessageContent[0].text = [systemContent, latestMessageContent[0].text].join('\n');
- // _messages.push(new HumanMessage({ content: latestMessageContent }));
- // } else {
- // const text = [systemContent, latestMessageContent].join('\n');
- // _messages.push(new HumanMessage(text));
- // }
- // }
- // let messages = _messages;
- // if (agent.useLegacyContent === true) {
- // messages = formatContentStrings(messages);
- // }
- // if (
- // agent.model_parameters?.clientOptions?.defaultHeaders?.['anthropic-beta']?.includes(
- // 'prompt-caching',
- // )
- // ) {
- // messages = addCacheControl(messages);
- // }
-
if (this.processMemory && !isCompactionTurn) {
memoryPromise = this.runMemory(memoryMessages);
}
diff --git a/api/server/controllers/agents/errors.js b/api/server/controllers/agents/errors.js
deleted file mode 100644
index 308e10cfc4..0000000000
--- a/api/server/controllers/agents/errors.js
+++ /dev/null
@@ -1,143 +0,0 @@
-// errorHandler.js
-const { logger } = require('@librechat/data-schemas');
-const { getTransactionsConfig } = require('@librechat/api');
-const { CacheKeys, ViolationTypes } = require('librechat-data-provider');
-const { sendResponse } = require('~/server/middleware/error');
-const { recordUsage } = require('~/server/services/Threads');
-const getLogStores = require('~/cache/getLogStores');
-const { getConvo } = require('~/models');
-
-/**
- * @typedef {Object} ErrorHandlerContext
- * @property {OpenAIClient} openai - The OpenAI client
- * @property {string} run_id - The run ID
- * @property {boolean} completedRun - Whether the run has completed
- * @property {string} assistant_id - The assistant ID
- * @property {string} conversationId - The conversation ID
- * @property {string} parentMessageId - The parent message ID
- * @property {string} responseMessageId - The response message ID
- * @property {string} endpoint - The endpoint being used
- * @property {string} cacheKey - The cache key for the current request
- */
-
-/**
- * @typedef {Object} ErrorHandlerDependencies
- * @property {ServerRequest} req - The Express request object
- * @property {Express.Response} res - The Express response object
- * @property {() => ErrorHandlerContext} getContext - Function to get the current context
- * @property {string} [originPath] - The origin path for the error handler
- */
-
-/**
- * Creates an error handler function with the given dependencies
- * @param {ErrorHandlerDependencies} dependencies - The dependencies for the error handler
- * @returns {(error: Error) => Promise<void>} The error handler function
- */
-const createErrorHandler = ({ req, res, getContext, originPath = '/assistants/chat/' }) => {
- const cache = getLogStores(CacheKeys.ABORT_KEYS);
-
- /**
- * Handles errors that occur during the chat process
- * @param {Error} error - The error that occurred
- * @returns {Promise<void>}
- */
- return async (error) => {
- const {
- openai,
- run_id,
- endpoint,
- cacheKey,
- completedRun,
- assistant_id,
- conversationId,
- parentMessageId,
- responseMessageId,
- } = getContext();
-
- const defaultErrorMessage =
- 'The Assistant run failed to initialize. Try sending a message in a new conversation.';
- const messageData = {
- assistant_id,
- conversationId,
- parentMessageId,
- sender: 'System',
- user: req.user.id,
- shouldSaveMessage: false,
- messageId: responseMessageId,
- endpoint,
- };
-
- if (error.message === 'Run cancelled') {
- return res.end();
- } else if (error.message === 'Request closed' && completedRun) {
- return;
- } else if (error.message === 'Request closed') {
- logger.debug(`[${originPath}] Request aborted on close`);
- } else if (/Files.*are invalid/.test(error.message)) {
- const errorMessage = `Files are invalid, or may not have uploaded yet.${
- endpoint === 'azureAssistants'
- ? " If using Azure OpenAI, files are only available in the region of the assistant's model at the time of upload."
- : ''
- }`;
- return sendResponse(req, res, messageData, errorMessage);
- } else if (error?.message?.includes('string too long')) {
- return sendResponse(
- req,
- res,
- messageData,
- 'Message too long. The Assistants API has a limit of 32,768 characters per message. Please shorten it and try again.',
- );
- } else if (error?.message?.includes(ViolationTypes.TOKEN_BALANCE)) {
- return sendResponse(req, res, messageData, error.message);
- } else {
- logger.error(`[${originPath}]`, error);
- }
-
- if (!openai || !run_id) {
- return sendResponse(req, res, messageData, defaultErrorMessage);
- }
-
- await new Promise((resolve) => setTimeout(resolve, 2000));
-
- try {
- const status = await cache.get(cacheKey);
- if (status === 'cancelled') {
- logger.debug(`[${originPath}] Run already cancelled`);
- return res.end();
- }
- await cache.delete(cacheKey);
- } catch (error) {
- logger.error(`[${originPath}] Error cancelling run`, error);
- }
-
- await new Promise((resolve) => setTimeout(resolve, 2000));
-
- let run;
- try {
- await recordUsage({
- ...run.usage,
- model: run.model,
- user: req.user.id,
- conversationId,
- transactions: getTransactionsConfig(req.config),
- });
- } catch (error) {
- logger.error(`[${originPath}] Error fetching or processing run`, error);
- }
-
- let finalEvent;
- try {
- finalEvent = {
- final: true,
- conversation: await getConvo(req.user.id, conversationId),
- };
- } catch (error) {
- logger.error(`[${originPath}] Error finalizing error process`, error);
- return sendResponse(req, res, messageData, 'The Assistant run failed');
- }
-
- return sendResponse(req, res, finalEvent);
- };
-};
-
-module.exports = { createErrorHandler };
diff --git a/api/server/controllers/assistants/helpers.js b/api/server/controllers/assistants/helpers.js
index 4630bfe7ef..b772ebd995 100644
--- a/api/server/controllers/assistants/helpers.js
+++ b/api/server/controllers/assistants/helpers.js
@@ -32,26 +32,6 @@ const getCurrentVersion = async (req, endpoint) => {
return version;
};
-/**
- * Asynchronously lists assistants based on provided query parameters.
- *
- * Initializes the client with the current request and response objects and lists assistants
- * according to the query parameters. This function abstracts the logic for non-Azure paths.
- *
- * @deprecated
- * @async
- * @param {object} params - The parameters object.
- * @param {object} params.req - The request object, used for initializing the client.
- * @param {object} params.res - The response object, used for initializing the client.
- * @param {string} params.version - The API version to use.
- * @param {object} params.query - The query parameters to list assistants (e.g., limit, order).
- * @returns {Promise<object>} A promise that resolves to the response from the `openai.beta.assistants.list` method call.
- */
-const _listAssistants = async ({ req, res, version, query }) => {
- const { openai } = await getOpenAIClient({ req, res, version });
- return openai.beta.assistants.list(query);
-};
-
/**
* Fetches all assistants based on provided query params, until `has_more` is `false`.
*
@@ -285,5 +265,4 @@ function filterAssistants({ assistants, userId, assistantsConfig }) {
module.exports = {
getOpenAIClient,
fetchAssistants,
- getCurrentVersion,
};
diff --git a/api/server/middleware/assistants/validateAuthor.js b/api/server/middleware/assistants/validateAuthor.js
index 6ffc8382b4..07cda1c9e3 100644
--- a/api/server/middleware/assistants/validateAuthor.js
+++ b/api/server/middleware/assistants/validateAuthor.js
@@ -7,15 +7,12 @@ const { getAssistant } = require('~/models');
* @param {object} params
* @param {object} params.req - Express Request
* @param {object} params.req.body - The request payload.
- * @param {string} params.overrideEndpoint - The override endpoint
- * @param {string} params.overrideAssistantId - The override assistant ID
* @param {OpenAIClient} params.openai - OpenAI API Client
* @returns {Promise<void>}
*/
-const validateAuthor = async ({ req, openai, overrideEndpoint, overrideAssistantId }) => {
- const endpoint = overrideEndpoint ?? req.body.endpoint ?? req.query.endpoint;
- const assistant_id =
- overrideAssistantId ?? req.params.id ?? req.body.assistant_id ?? req.query.assistant_id;
+const validateAuthor = async ({ req, openai }) => {
+ const endpoint = req.body.endpoint ?? req.query.endpoint;
+ const assistant_id = req.params.id ?? req.body.assistant_id ?? req.query.assistant_id;
const appConfig = req.config;
/** @type {Partial<TAssistantEndpoint>} */
diff --git a/api/server/middleware/index.js b/api/server/middleware/index.js
index 71b724786d..1c3ca45fa1 100644
--- a/api/server/middleware/index.js
+++ b/api/server/middleware/index.js
@@ -35,13 +35,11 @@ const limiters = require('./limiters');
const uaParser = require('./uaParser');
const checkBan = require('./checkBan');
const noIndex = require('./noIndex');
-const roles = require('./roles');
module.exports = {
...abortMiddleware,
...validate,
...limiters,
- ...roles,
...accessResources,
noIndex,
checkBan,
diff --git a/api/server/middleware/roles/admin.js b/api/server/middleware/roles/admin.js
deleted file mode 100644
index 3cb93fab53..0000000000
--- a/api/server/middleware/roles/admin.js
+++ /dev/null
@@ -1,14 +0,0 @@
-const { SystemRoles } = require('librechat-data-provider');
-
-function checkAdmin(req, res, next) {
- try {
- if (req.user.role !== SystemRoles.ADMIN) {
- return res.status(403).json({ message: 'Forbidden' });
- }
- next();
- } catch (error) {
- res.status(500).json({ message: 'Internal Server Error' });
- }
-}
-
-module.exports = checkAdmin;
diff --git a/api/server/middleware/roles/index.js b/api/server/middleware/roles/index.js
deleted file mode 100644
index f97d4b72b4..0000000000
--- a/api/server/middleware/roles/index.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * NOTE: hasCapability, requireCapability, hasConfigCapability, and
- * capabilityContextMiddleware are intentionally NOT re-exported here.
- *
- * capabilities.js depends on ~/models, and the middleware barrel
- * (middleware/index.js) is frequently required by modules that are
- * themselves loaded while the barrel is still initialising — creating
- * a circular-require that silently returns an empty exports object.
- *
- * Always import capability helpers directly:
- * require('~/server/middleware/roles/capabilities')
- */
-const checkAdmin = require('./admin');
-
-module.exports = {
- checkAdmin,
-};
diff --git a/api/server/middleware/spec/validateImages.spec.js b/api/server/middleware/spec/validateImages.spec.js
index 7eab98fa69..f0b7e16e3f 100644
--- a/api/server/middleware/spec/validateImages.spec.js
+++ b/api/server/middleware/spec/validateImages.spec.js
@@ -70,7 +70,7 @@ describe('validateImageRequest middleware', () => {
describe('Factory function', () => {
test('should return a pass-through middleware if secureImageLinks is false', async () => {
- const middleware = createValidateImageRequest(false);
+ const middleware = createValidateImageRequest({ secureImageLinks: false });
await middleware(req, res, next);
expect(next).toHaveBeenCalled();
expect(res.status).not.toHaveBeenCalled();
@@ -142,7 +142,7 @@ describe('validateImageRequest middleware', () => {
describe('Standard LibreChat token flow', () => {
beforeEach(() => {
- validateImageRequest = createValidateImageRequest(true);
+ validateImageRequest = createValidateImageRequest({ secureImageLinks: true });
});
test('should return 401 if refresh token is not provided', async () => {
@@ -361,7 +361,7 @@ describe('validateImageRequest middleware', () => {
describe('OpenID token flow', () => {
beforeEach(() => {
- validateImageRequest = createValidateImageRequest(true);
+ validateImageRequest = createValidateImageRequest({ secureImageLinks: true });
// Enable OpenID token reuse
isEnabled.mockReturnValue(true);
process.env.OPENID_REUSE_TOKENS = 'true';
@@ -459,7 +459,7 @@ describe('validateImageRequest middleware', () => {
let validToken;
beforeEach(() => {
- validateImageRequest = createValidateImageRequest(true);
+ validateImageRequest = createValidateImageRequest({ secureImageLinks: true });
validToken = jwt.sign(
{ id: validObjectId, exp: Math.floor(Date.now() / 1000) + 3600 },
process.env.JWT_REFRESH_SECRET,
diff --git a/api/server/middleware/validateImageRequest.js b/api/server/middleware/validateImageRequest.js
index ac8b9f00d4..b63fc132cc 100644
--- a/api/server/middleware/validateImageRequest.js
+++ b/api/server/middleware/validateImageRequest.js
@@ -30,17 +30,13 @@ const getAssistantEndpointConfigs = (appConfig) =>
/**
* Thin Express adapter for the typed image-authorization service in `@librechat/api`.
- * @param {boolean | {secureImageLinks?: boolean, assistantEndpoints?: object[]}} [config]
+ * @param {{secureImageLinks?: boolean, assistantEndpoints?: object[]}} [config]
*/
function createValidateImageRequest(config = {}) {
- const resolveDynamicConfig = typeof config !== 'boolean';
- const options =
- typeof config === 'boolean'
- ? { secureImageLinks: config }
- : {
- secureImageLinks: config.secureImageLinks,
- assistantEndpoints: config.assistantEndpoints,
- };
+ const options = {
+ secureImageLinks: config.secureImageLinks,
+ assistantEndpoints: config.assistantEndpoints,
+ };
const deps = {
parseCookies: cookie.parse,
@@ -53,9 +49,7 @@ function createValidateImageRequest(config = {}) {
getUserPrincipals,
hasCapabilityForPrincipals,
hasPermission,
- };
- if (resolveDynamicConfig) {
- deps.getImageConfig = async ({ userId, user }) => {
+ getImageConfig: async ({ userId, user }) => {
const appConfig = await getAppConfig(
getAppConfigOptionsFromUser({ ...user, id: userId }, user.tenantId),
);
@@ -63,8 +57,8 @@ function createValidateImageRequest(config = {}) {
secureImageLinks: appConfig.secureImageLinks,
assistantEndpoints: getAssistantEndpointConfigs(appConfig),
};
- };
- }
+ },
+ };
return createImageAuthorizationMiddleware(options, deps);
}
diff --git a/api/server/routes/files/list.spec.js b/api/server/routes/files/list.spec.js
index ce6302ce2a..37bf91cd9a 100644
--- a/api/server/routes/files/list.spec.js
+++ b/api/server/routes/files/list.spec.js
@@ -49,10 +49,6 @@ jest.mock('~/server/services/PermissionService', () => ({
getEffectivePermissions: jest.fn().mockResolvedValue(0),
}));
-jest.mock('~/server/services/Files', () => ({
- hasAccessToFilesViaAgent: jest.fn(),
-}));
-
const mockGetLogStores = jest.fn();
jest.mock('~/cache', () => ({
getLogStores: (...args) => mockGetLogStores(...args),
diff --git a/api/server/routes/files/preview.spec.js b/api/server/routes/files/preview.spec.js
index 3363c1b08a..20ed436837 100644
--- a/api/server/routes/files/preview.spec.js
+++ b/api/server/routes/files/preview.spec.js
@@ -57,10 +57,6 @@ jest.mock('~/server/services/PermissionService', () => ({
getEffectivePermissions: jest.fn().mockResolvedValue(0),
}));
-jest.mock('~/server/services/Files', () => ({
- hasAccessToFilesViaAgent: jest.fn(),
-}));
-
jest.mock('~/server/utils/files', () => ({
cleanFileName: (name) => name,
getContentDisposition: (name) => `attachment; filename="${name}"`,
diff --git a/api/server/routes/types/assistants.js b/api/server/routes/types/assistants.js
deleted file mode 100644
index 974bf587a8..0000000000
--- a/api/server/routes/types/assistants.js
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Enum for the possible tools that can be enabled on an assistant.
- * @readonly
- * @enum {string}
- */
-// eslint-disable-next-line no-unused-vars
-const Tools = {
- code_interpreter: 'code_interpreter',
- retrieval: 'retrieval',
- function: 'function',
-};
-
-/**
- * Represents a tool with its type.
- * @typedef {Object} Tool
- * @property {Tools} toolName - The name of the tool and its corresponding type from the Tools enum.
- */
-
-/**
- * @typedef {Object} Assistant
- * @property {string} id - The identifier, which can be referenced in API endpoints.
- * @property {number} created_at - The Unix timestamp (in seconds) for when the assistant was created.
- * @property {string|null} description - The maximum length is 512 characters.
- * @property {Array<string>} file_ids - A list of file IDs attached to this assistant.
- * @property {string|null} instructions - The system instructions that the assistant uses. The maximum length is 32768 characters.
- * @property {Object|null} metadata - Set of 16 key-value pairs that can be attached to an object.
- * @property {string} model - ID of the model to use.
- * @property {string|null} name - The name of the assistant. The maximum length is 256 characters.
- * @property {string} object - The object type, which is always 'assistant'.
- * @property {Tool[]} tools - A list of tools enabled on the assistant.
- */
-
-/**
- * @typedef {Object} AssistantCreateParams
- * @property {string} model - ID of the model to use.
- * @property {string|null} [description] - The description of the assistant.
- * @property {Array<string>} [file_ids] - A list of file IDs attached to this assistant.
- * @property {string|null} [instructions] - The system instructions that the assistant uses.
- * @property {Object|null} [metadata] - Set of 16 key-value pairs that can be attached to an object.
- * @property {string|null} [name] - The name of the assistant.
- * @property {Tool[]} tools - A list of tools enabled on the assistant.
- */
-
-/**
- * @typedef {Object} AssistantUpdateParams
- * // Similar properties to AssistantCreateParams, but all optional
- */
-
-/**
- * @typedef {Object} AssistantListParams
- * @property {string|null} [before] - A cursor for use in pagination.
- * @property {'asc'|'desc'} [order] - Sort order by the created_at timestamp of the objects.
- */
diff --git a/api/server/services/AssistantService.js b/api/server/services/AssistantService.js
index 2da8fe3d6d..26016c5de6 100644
--- a/api/server/services/AssistantService.js
+++ b/api/server/services/AssistantService.js
@@ -4,13 +4,11 @@ const { sendEvent } = require('@librechat/api');
const { logger } = require('@librechat/data-schemas');
const {
StepTypes,
- RunStatus,
StepStatus,
ContentTypes,
ToolCallTypes,
imageGenTools,
EModelEndpoint,
- defaultOrderQuery,
} = require('librechat-data-provider');
const { retrieveAndProcessFile } = require('~/server/services/Files/process');
const { processRequiredActions } = require('~/server/services/ToolService');
@@ -77,44 +75,6 @@ async function createOnTextProgress({
};
}
-/**
- * Retrieves the response from an OpenAI run.
- *
- * @param {Object} params - The parameters for getting the response.
- * @param {OpenAI} params.openai - The OpenAI SDK client instance.
- * @param {string} params.run_id - The ID of the run to get the response for.
- * @param {string} params.thread_id - The ID of the thread associated with the run.
- * @return {Promise<OpenAIAssistantFinish | OpenAIAssistantAction[] | ThreadMessage[] | RequiredActionFunctionToolCall[]>}
- */
-async function getResponse({ openai, run_id, thread_id }) {
- const run = await waitForRun({ openai, run_id, thread_id, pollIntervalMs: 2000 });
-
- if (run.status === RunStatus.COMPLETED) {
- const messages = await openai.beta.threads.messages.list(thread_id, defaultOrderQuery);
- const newMessages = messages.data.filter((msg) => msg.run_id === run_id);
-
- return newMessages;
- } else if (run.status === RunStatus.REQUIRES_ACTION) {
- const actions = [];
- run.required_action?.submit_tool_outputs.tool_calls.forEach((item) => {
- const functionCall = item.function;
- const args = JSON.parse(functionCall.arguments);
- actions.push({
- tool: functionCall.name,
- toolInput: args,
- toolCallId: item.id,
- run_id,
- thread_id,
- });
- });
-
- return actions;
- }
-
- const runInfo = JSON.stringify(run, null, 2);
- throw new Error(`Unexpected run status ${run.status}.\nFull run info:\n\n${runInfo}`);
-}
-
/**
* Filters the steps to keep only the most recent instance of each unique step.
* @param {RunStep[]} steps - The array of RunSteps to filter.
@@ -369,14 +329,6 @@ async function runAssistant({
logger.debug(`[runAssistant] Final step for ${run_id} with status ${runStatus}`, step);
const promises = [];
- // promises.push(
- // openai.beta.threads.messages.list(thread_id, defaultOrderQuery),
- // );
-
- // const finalSteps = stepsByStatus[runStatus];
- // for (const stepPromise of finalSteps) {
- // promises.push(stepPromise);
- // }
// loop across all statuses
for (const [_status, stepsPromises] of Object.entries(stepsByStatus)) {
@@ -395,8 +347,6 @@ async function runAssistant({
}
}
await in_progress({ step });
- // const res = resolved.shift();
- // messages = messages.concat(res.data.filter((msg) => msg && msg.run_id === run_id));
resolved.push(step);
/* Note: no issues without deep cloning, but it's safer to do so */
steps = klona(finalSteps);
@@ -418,8 +368,6 @@ async function runAssistant({
});
if (!run.required_action) {
- // const { messages: sortedMessages, text } = await processMessages(openai, messages);
- // return { run, steps, messages: sortedMessages, text };
const sortedMessages = messages.sort((a, b) => a.created_at - b.created_at);
return {
run,
@@ -461,7 +409,6 @@ async function runAssistant({
}
module.exports = {
- getResponse,
runAssistant,
createOnTextProgress,
};
diff --git a/api/server/services/Config/EndpointService.js b/api/server/services/Config/EndpointService.js
index 56fa84f2a2..add7c5f809 100644
--- a/api/server/services/Config/EndpointService.js
+++ b/api/server/services/Config/EndpointService.js
@@ -15,7 +15,6 @@ const {
AZURE_ASSISTANTS_BASE_URL,
} = process.env ?? {};
-const userProvidedOpenAI = isUserProvided(openAIApiKey);
const anthropicUsesVertex = isEnabled(process.env.ANTHROPIC_USE_VERTEX);
const firstNonEmpty = (...values) => values.find((value) => value != null && value !== '');
const bedrockUserProvidedCredential = [
@@ -28,9 +27,6 @@ const bedrockUserProvidedCredential = [
module.exports = {
config: {
googleKey,
- openAIApiKey,
- azureOpenAIApiKey,
- userProvidedOpenAI,
[EModelEndpoint.anthropic]: generateConfig(anthropicUsesVertex ? 'true' : anthropicApiKey),
[EModelEndpoint.openAI]: generateConfig(openAIApiKey, OPENAI_REVERSE_PROXY),
[EModelEndpoint.azureOpenAI]: generateConfig(azureOpenAIApiKey, AZURE_OPENAI_BASEURL),
diff --git a/api/server/services/Config/app.js b/api/server/services/Config/app.js
index c078e480e1..c0859093ca 100644
--- a/api/server/services/Config/app.js
+++ b/api/server/services/Config/app.js
@@ -99,8 +99,6 @@ async function invalidateConfigCaches(tenantId) {
module.exports = {
getAppConfig,
- clearAppConfigCache,
- clearOverrideCache,
invalidateConfigCaches,
getCodeEnvironmentRegistry,
invalidateCodeEnvironmentConfigCache,
diff --git a/api/server/services/Endpoints/agents/skillDeps.js b/api/server/services/Endpoints/agents/skillDeps.js
index 52d251a57d..f4155b98b5 100644
--- a/api/server/services/Endpoints/agents/skillDeps.js
+++ b/api/server/services/Endpoints/agents/skillDeps.js
@@ -373,12 +373,9 @@ module.exports = {
getSkillToolDeps,
getSkillManagementFileSaver,
canAuthorSkillFiles,
- isAgentSkillAuthoringEnabledForRun,
getSkillDbMethods,
withDeploymentSkillIds,
getSkillStrategyFunctions,
- enrichWithSkillConfigurable,
- buildSkillPrimedIdsByName,
buildAgentToolContext,
resolveMemoryAvailability,
enrichLoadedToolsWithAgentContext,
diff --git a/api/server/services/Endpoints/assistants/build.js b/api/server/services/Endpoints/assistants/build.js
index c05fa9f249..557c2f089e 100644
--- a/api/server/services/Endpoints/assistants/build.js
+++ b/api/server/services/Endpoints/assistants/build.js
@@ -1,5 +1,5 @@
+const { generateArtifactsPrompt } = require('@librechat/api');
const { removeNullishValues } = require('librechat-data-provider');
-const generateArtifactsPrompt = require('~/app/clients/prompts/artifacts');
const { getAssistant } = require('~/models');
const buildOptions = async (endpoint, parsedBody) => {
diff --git a/api/server/services/Endpoints/azureAssistants/build.js b/api/server/services/Endpoints/azureAssistants/build.js
index bc04ae73d2..3540f14982 100644
--- a/api/server/services/Endpoints/azureAssistants/build.js
+++ b/api/server/services/Endpoints/azureAssistants/build.js
@@ -1,5 +1,5 @@
+const { generateArtifactsPrompt } = require('@librechat/api');
const { removeNullishValues } = require('librechat-data-provider');
-const generateArtifactsPrompt = require('~/app/clients/prompts/artifacts');
const { getAssistant } = require('~/models');
const buildOptions = async (endpoint, parsedBody) => {
diff --git a/api/server/services/Files/Audio/streamAudio.js b/api/server/services/Files/Audio/streamAudio.js
index ab7c7d9c3c..8f674261f8 100644
--- a/api/server/services/Files/Audio/streamAudio.js
+++ b/api/server/services/Files/Audio/streamAudio.js
@@ -1,5 +1,5 @@
const { createSpeechChunkProcessor } = require('@librechat/api');
-const { CacheKeys, SEPARATORS, findLastSeparatorIndex } = require('librechat-data-provider');
+const { CacheKeys, SEPARATORS } = require('librechat-data-provider');
const { getLogStores } = require('~/cache');
const { getMessage } = require('~/models');
@@ -117,23 +117,8 @@ function splitTextIntoChunks(text, chunkSize = 4000) {
return chunks;
}
-/**
- *
- * @param {AsyncIterable<string>} llmStream
- */
-async function* llmMessageSource(llmStream) {
- for await (const chunk of llmStream) {
- const message = chunk.choices[0].delta.content;
- if (message) {
- yield message;
- }
- }
-}
-
module.exports = {
- findLastSeparatorIndex,
createChunkProcessor,
splitTextIntoChunks,
- llmMessageSource,
getRandomVoiceId,
};
diff --git a/api/server/services/Files/Local/crud.js b/api/server/services/Files/Local/crud.js
index 93d3efbb9f..12a28ba889 100644
--- a/api/server/services/Files/Local/crud.js
+++ b/api/server/services/Files/Local/crud.js
@@ -3,7 +3,6 @@ const path = require('path');
const axios = require('axios');
const {
deleteRagFile,
- moveLocalFile,
stripCacheBust,
writeLocalFile,
assertRemoteFileURL,
@@ -18,41 +17,6 @@ const { resizeImageBuffer } = require('~/server/services/Files/images/resize');
const { getBufferMetadata } = require('~/server/utils');
const paths = require('~/config/paths');
-/**
- * Saves a file to a specified output path with a new filename.
- *
- * @param {Express.Multer.File} file - The file object to be saved. Should contain properties like 'originalname' and 'path'.
- * @param {string} outputPath - The path where the file should be saved.
- * @param {string} outputFilename - The new filename for the saved file (without extension).
- * @returns {Promise<string>} The full path of the saved file.
- * @throws Will throw an error if the file saving process fails.
- */
-async function saveLocalFile(file, outputPath, outputFilename) {
- try {
- const fileExtension = path.extname(file.originalname);
- return await moveLocalFile(file.path, outputPath, outputFilename + fileExtension);
- } catch (error) {
- logger.error('[saveFile] Error while saving the file:', error);
- throw error;
- }
-}
-
-/**
- * Saves an uploaded image file to a specified directory based on the user's ID and a filename.
- *
- * @param {ServerRequest} req - The Express request object, containing the user's information and app configuration.
- * @param {Express.Multer.File} file - The uploaded file object.
- * @param {string} filename - The new filename to assign to the saved image (without extension).
- * @returns {Promise<void>}
- * @throws Will throw an error if the image saving process fails.
- */
-const saveLocalImage = async (req, file, filename) => {
- const appConfig = req.config;
- const imagePath = appConfig.paths.imageOutput;
- const outputPath = path.join(imagePath, req.user.id ?? '');
- await saveLocalFile(file, outputPath, filename);
-};
-
/**
* Saves a buffer to a specified directory on the local file system.
*
@@ -343,8 +307,6 @@ async function getLocalFileStream(req, requestedFilepath) {
}
module.exports = {
- saveLocalFile,
- saveLocalImage,
saveLocalBuffer,
saveFileFromURL,
getLocalFileURL,
diff --git a/api/server/services/Files/images/index.js b/api/server/services/Files/images/index.js
index d72a80690b..12ef884d51 100644
--- a/api/server/services/Files/images/index.js
+++ b/api/server/services/Files/images/index.js
@@ -1,4 +1,3 @@
-const avatar = require('./avatar');
const convert = require('./convert');
const encode = require('./encode');
const resize = require('./resize');
@@ -7,5 +6,4 @@ module.exports = {
...convert,
...encode,
...resize,
- avatar,
};
diff --git a/api/server/services/Files/index.js b/api/server/services/Files/index.js
deleted file mode 100644
index 872e8a0e81..0000000000
--- a/api/server/services/Files/index.js
+++ /dev/null
@@ -1,12 +0,0 @@
-const { processCodeFile } = require('./Code/process');
-const { processFileUpload } = require('./process');
-const { uploadImageBuffer } = require('./images');
-const { hasAccessToFilesViaAgent, filterFilesByAgentAccess } = require('./permissions');
-
-module.exports = {
- processCodeFile,
- processFileUpload,
- uploadImageBuffer,
- hasAccessToFilesViaAgent,
- filterFilesByAgentAccess,
-};
diff --git a/api/server/services/GraphApiService.js b/api/server/services/GraphApiService.js
index d9a6fa99fc..4f7363000c 100644
--- a/api/server/services/GraphApiService.js
+++ b/api/server/services/GraphApiService.js
@@ -497,96 +497,6 @@ const searchGroups = async (graphClient, query, limit = 10) => {
}
};
-/**
- * Test Graph API connectivity and permissions
- * @param {string} accessToken - OpenID Connect access token
- * @param {string} sub - Subject identifier
- * @returns {Promise<Object>} Test results with available permissions
- */
-const testGraphApiAccess = async (accessToken, sub) => {
- try {
- const graphClient = await createGraphClient(accessToken, sub);
- const results = {
- userAccess: false,
- peopleAccess: false,
- groupsAccess: false,
- usersEndpointAccess: false,
- groupsEndpointAccess: false,
- errors: [],
- };
-
- // Test User.Read permission
- try {
- await graphClient.api('/me').select('id,displayName').get();
- results.userAccess = true;
- } catch (error) {
- results.errors.push(`User.Read: ${error.message}`);
- }
-
- // Test People.Read permission with OrganizationUser filter
- try {
- await graphClient
- .api('/me/people')
- .filter("personType/subclass eq 'OrganizationUser'")
- .top(1)
- .get();
- results.peopleAccess = true;
- } catch (error) {
- results.errors.push(`People.Read (OrganizationUser): ${error.message}`);
- }
-
- // Test People.Read permission with UnifiedGroup filter
- try {
- await graphClient
- .api('/me/people')
- .filter("personType/subclass eq 'UnifiedGroup'")
- .top(1)
- .get();
- results.groupsAccess = true;
- } catch (error) {
- results.errors.push(`People.Read (UnifiedGroup): ${error.message}`);
- }
-
- // Test /users endpoint access (requires User.Read.All or similar)
- try {
- await graphClient
- .api('/users')
- .search('"displayName:test"')
- .select('id,displayName,userPrincipalName')
- .top(1)
- .get();
- results.usersEndpointAccess = true;
- } catch (error) {
- results.errors.push(`Users endpoint: ${error.message}`);
- }
-
- // Test /groups endpoint access (requires Group.Read.All or similar)
- try {
- await graphClient
- .api('/groups')
- .search('"displayName:test"')
- .select('id,displayName,mail')
- .top(1)
- .get();
- results.groupsEndpointAccess = true;
- } catch (error) {
- results.errors.push(`Groups endpoint: ${error.message}`);
- }
-
- return results;
- } catch (error) {
- logger.error('[testGraphApiAccess] Error testing Graph API access:', error);
- return {
- userAccess: false,
- peopleAccess: false,
- groupsAccess: false,
- usersEndpointAccess: false,
- groupsEndpointAccess: false,
- errors: [error.message],
- };
- }
-};
-
/**
* Map Graph API user object to TPrincipalSearchResult format
* @param {TGraphUser} user - Raw user object from Graph API
@@ -649,7 +559,6 @@ module.exports = {
getUserEntraGroups,
getUserOwnedEntraGroups,
getEntraGroupDetailsBatch,
- testGraphApiAccess,
searchEntraIdPrincipals,
exchangeTokenForGraphAccess,
entraIdPrincipalFeatureEnabled,
diff --git a/api/server/services/GraphApiService.spec.js b/api/server/services/GraphApiService.spec.js
index 3f085dabb7..87cee1a3e3 100644
--- a/api/server/services/GraphApiService.spec.js
+++ b/api/server/services/GraphApiService.spec.js
@@ -650,156 +650,4 @@ describe('GraphApiService', () => {
expect(result).toEqual([]);
});
});
-
- describe('testGraphApiAccess', () => {
- beforeEach(() => {
- jest.clearAllMocks();
- });
-
- it('should test all permissions and return success results', async () => {
- // Mock successful responses for all tests
- mockGraphClient.get
- .mockResolvedValueOnce({ id: 'user-123', displayName: 'Test User' }) // /me test
- .mockResolvedValueOnce({ value: [] }) // people OrganizationUser test
- .mockResolvedValueOnce({ value: [] }) // people UnifiedGroup test
- .mockResolvedValueOnce({ value: [] }) // /users endpoint test
- .mockResolvedValueOnce({ value: [] }); // /groups endpoint test
-
- const result = await GraphApiService.testGraphApiAccess('token', 'user');
-
- expect(result).toEqual({
- userAccess: true,
- peopleAccess: true,
- groupsAccess: true,
- usersEndpointAccess: true,
- groupsEndpointAccess: true,
- errors: [],
- });
-
- // Verify all endpoints were tested
- expect(mockGraphClient.api).toHaveBeenCalledWith('/me');
- expect(mockGraphClient.api).toHaveBeenCalledWith('/me/people');
- expect(mockGraphClient.api).toHaveBeenCalledWith('/users');
- expect(mockGraphClient.api).toHaveBeenCalledWith('/groups');
- expect(mockGraphClient.filter).toHaveBeenCalledWith(
- "personType/subclass eq 'OrganizationUser'",
- );
- expect(mockGraphClient.filter).toHaveBeenCalledWith("personType/subclass eq 'UnifiedGroup'");
- expect(mockGraphClient.search).toHaveBeenCalledWith('"displayName:test"');
- });
-
- it('should handle partial failures and record errors', async () => {
- // Mock mixed success/failure responses
- mockGraphClient.get
- .mockResolvedValueOnce({ id: 'user-123', displayName: 'Test User' }) // /me success
- .mockRejectedValueOnce(new Error('People access denied')) // people OrganizationUser fail
- .mockResolvedValueOnce({ value: [] }) // people UnifiedGroup success
- .mockRejectedValueOnce(new Error('Users endpoint access denied')) // /users fail
- .mockResolvedValueOnce({ value: [] }); // /groups success
-
- const result = await GraphApiService.testGraphApiAccess('token', 'user');
-
- expect(result).toEqual({
- userAccess: true,
- peopleAccess: false,
- groupsAccess: true,
- usersEndpointAccess: false,
- groupsEndpointAccess: true,
- errors: [
- 'People.Read (OrganizationUser): People access denied',
- 'Users endpoint: Users endpoint access denied',
- ],
- });
- });
-
- it('should handle complete Graph client creation failure', async () => {
- // Mock token exchange failure to test error handling
- if (client.genericGrantRequest) {
- client.genericGrantRequest.mockRejectedValue(new Error('Token exchange failed'));
- }
-
- const result = await GraphApiService.testGraphApiAccess('invalid-token', 'user');
-
- expect(result).toEqual({
- userAccess: false,
- peopleAccess: false,
- groupsAccess: false,
- usersEndpointAccess: false,
- groupsEndpointAccess: false,
- errors: ['Token exchange failed'],
- });
- });
-
- it('should record all permission errors', async () => {
- // Mock all requests to fail
- mockGraphClient.get
- .mockRejectedValueOnce(new Error('User.Read denied'))
- .mockRejectedValueOnce(new Error('People.Read OrganizationUser denied'))
- .mockRejectedValueOnce(new Error('People.Read UnifiedGroup denied'))
- .mockRejectedValueOnce(new Error('Users directory access denied'))
- .mockRejectedValueOnce(new Error('Groups directory access denied'));
-
- const result = await GraphApiService.testGraphApiAccess('token', 'user');
-
- expect(result).toEqual({
- userAccess: false,
- peopleAccess: false,
- groupsAccess: false,
- usersEndpointAccess: false,
- groupsEndpointAccess: false,
- errors: [
- 'User.Read: User.Read denied',
- 'People.Read (OrganizationUser): People.Read OrganizationUser denied',
- 'People.Read (UnifiedGroup): People.Read UnifiedGroup denied',
- 'Users endpoint: Users directory access denied',
- 'Groups endpoint: Groups directory access denied',
- ],
- });
- });
-
- it('should test new endpoints with correct search patterns', async () => {
- // Mock successful responses for endpoint testing
- mockGraphClient.get
- .mockResolvedValueOnce({ id: 'user-123', displayName: 'Test User' }) // /me
- .mockResolvedValueOnce({ value: [] }) // people OrganizationUser
- .mockResolvedValueOnce({ value: [] }) // people UnifiedGroup
- .mockResolvedValueOnce({ value: [] }) // /users
- .mockResolvedValueOnce({ value: [] }); // /groups
-
- await GraphApiService.testGraphApiAccess('token', 'user');
-
- // Verify /users endpoint test
- expect(mockGraphClient.api).toHaveBeenCalledWith('/users');
- expect(mockGraphClient.search).toHaveBeenCalledWith('"displayName:test"');
- expect(mockGraphClient.select).toHaveBeenCalledWith('id,displayName,userPrincipalName');
-
- // Verify /groups endpoint test
- expect(mockGraphClient.api).toHaveBeenCalledWith('/groups');
- expect(mockGraphClient.select).toHaveBeenCalledWith('id,displayName,mail');
- });
-
- it('should handle endpoint-specific permission failures', async () => {
- // Mock specific endpoint failures
- mockGraphClient.get
- .mockResolvedValueOnce({ id: 'user-123', displayName: 'Test User' }) // /me success
- .mockResolvedValueOnce({ value: [] }) // people OrganizationUser success
- .mockResolvedValueOnce({ value: [] }) // people UnifiedGroup success
- .mockRejectedValueOnce(new Error('Insufficient privileges')) // /users fail (User.Read.All needed)
- .mockRejectedValueOnce(new Error('Access denied to groups')); // /groups fail (Group.Read.All needed)
-
- const result = await GraphApiService.testGraphApiAccess('token', 'user');
-
- expect(result).toEqual({
- userAccess: true,
- peopleAccess: true,
- groupsAccess: true,
- usersEndpointAccess: false,
- groupsEndpointAccess: false,
- errors: [
- 'Users endpoint: Insufficient privileges',
- 'Groups endpoint: Access denied to groups',
- ],
- });
- });
- });
});
diff --git a/api/server/services/PluginService.js b/api/server/services/PluginService.js
index 4c52aa1acf..ce0d5a10a0 100644
--- a/api/server/services/PluginService.js
+++ b/api/server/services/PluginService.js
@@ -60,31 +60,6 @@ const getUserPluginAuthValue = async (userId, authField, throwError = true, plug
}
};
-// const updateUserPluginAuth = async (userId, authField, pluginKey, value) => {
-// try {
-// const encryptedValue = encrypt(value);
-
-// const pluginAuth = await PluginAuth.findOneAndUpdate(
-// { userId, authField },
-// {
-// $set: {
-// value: encryptedValue,
-// pluginKey
-// }
-// },
-// {
-// new: true,
-// upsert: true
-// }
-// );
-
-// return pluginAuth;
-// } catch (err) {
-// logger.error('[getUserPluginAuthValue]', err);
-// return err;
-// }
-// };
-
/**
*
* @async
diff --git a/api/server/services/Runs/handle.js b/api/server/services/Runs/handle.js
index c515fabfe4..75b4adea9c 100644
--- a/api/server/services/Runs/handle.js
+++ b/api/server/services/Runs/handle.js
@@ -1,9 +1,8 @@
const { sleep } = require('@librechat/agents');
const { logger } = require('@librechat/data-schemas');
-const { RunStatus, defaultOrderQuery, CacheKeys } = require('librechat-data-provider');
+const { RunStatus, CacheKeys } = require('librechat-data-provider');
const getLogStores = require('~/cache/getLogStores');
const { retrieveRun } = require('./methods');
-const RunManager = require('./RunManager');
async function withTimeout(promise, timeoutMs, timeoutMessage) {
let timeoutHandle;
@@ -168,97 +167,7 @@ async function waitForRun({
return run;
}
-/**
- * Retrieves all steps of a run.
- *
- * @deprecated: Steps are handled with runAssistant now.
- * @param {Object} params - The parameters for the retrieveRunSteps function.
- * @param {OpenAIClient} params.openai - The OpenAI client instance.
- * @param {string} params.thread_id - The ID of the thread associated with the run.
- * @param {string} params.run_id - The ID of the run to retrieve steps for.
- * @return {Promise<RunStep[]>} A promise that resolves to an array of RunStep objects.
- */
-async function _retrieveRunSteps({ openai, thread_id, run_id }) {
- const runSteps = await openai.beta.threads.runs.steps.list(run_id, { thread_id });
- return runSteps;
-}
-
-/**
- * Initializes a RunManager with handlers, then invokes waitForRun to monitor and manage an OpenAI run.
- *
- * @deprecated Use runAssistant instead.
- * @param {Object} params - The parameters for managing and monitoring the run.
- * @param {OpenAIClient} params.openai - The OpenAI client instance.
- * @param {string} params.run_id - The ID of the run to manage and monitor.
- * @param {string} params.thread_id - The ID of the thread associated with the run.
- * @return {Promise<Object>} A promise that resolves to an object containing the run and managed steps.
- */
-async function _handleRun({ openai, run_id, thread_id }) {
- let steps = [];
- let messages = [];
- const runManager = new RunManager({
- // 'in_progress': async ({ step, final, isLast }) => {
- // // Define logic for handling steps with 'in_progress' status
- // },
- // 'queued': async ({ step, final, isLast }) => {
- // // Define logic for handling steps with 'queued' status
- // },
- final: async ({ step, runStatus, stepsByStatus }) => {
- console.log(`Final step for ${run_id} with status ${runStatus}`);
- console.dir(step, { depth: null });
-
- const promises = [];
- promises.push(openai.beta.threads.messages.list(thread_id, defaultOrderQuery));
-
- // const finalSteps = stepsByStatus[runStatus];
- // for (const stepPromise of finalSteps) {
- // promises.push(stepPromise);
- // }
-
- // loop across all statuses
- for (const [_status, stepsPromises] of Object.entries(stepsByStatus)) {
- promises.push(...stepsPromises);
- }
-
- const resolved = await Promise.all(promises);
- const res = resolved.shift();
- messages = res.data.filter((msg) => msg.run_id === run_id);
- resolved.push(step);
- steps = resolved;
- },
- });
-
- const run = await waitForRun({
- openai,
- run_id,
- thread_id,
- runManager,
- pollIntervalMs: 2000,
- timeout: 60000,
- });
- const actions = [];
- if (run.required_action) {
- const { submit_tool_outputs } = run.required_action;
- submit_tool_outputs.tool_calls.forEach((item) => {
- const functionCall = item.function;
- const args = JSON.parse(functionCall.arguments);
- actions.push({
- tool: functionCall.name,
- toolInput: args,
- toolCallId: item.id,
- run_id,
- thread_id,
- });
- });
- }
-
- return { run, steps, messages, actions };
-}
-
module.exports = {
- sleep,
createRun,
waitForRun,
- // _handleRun,
- // retrieveRunSteps,
};
diff --git a/api/server/services/Schedules/index.js b/api/server/services/Schedules/index.js
index cd96bc2561..d81891bb82 100644
--- a/api/server/services/Schedules/index.js
+++ b/api/server/services/Schedules/index.js
@@ -109,7 +109,4 @@ module.exports = {
const methods = require('~/models');
return !(await methods.isAgentTriggerPrincipalActive(userId));
},
- // Identity-fenced delete for a retained job whose run has since been settled
- // inline; reconciliation only reaches jobs whose run is still active.
- clearScheduledJob: (...args) => getService().engineDeps.clearReconciledJob(...args),
};
diff --git a/api/server/services/ToolService.js b/api/server/services/ToolService.js
index 3cee887ce3..65db50b28e 100644
--- a/api/server/services/ToolService.js
+++ b/api/server/services/ToolService.js
@@ -785,8 +785,6 @@ const isExpectedMCPTool = (toolName) =>
toolName?.includes(Constants.mcp_delimiter) &&
!toolName.startsWith(mcpServerPinPrefix) &&
!isActionTool(toolName);
-const isExpectedMCPToolsUnavailableError = (error) =>
- error?.code === AGENT_EXPECTED_MCP_TOOLS_UNAVAILABLE;
const createExpectedMCPToolsUnavailableError = (agentName, cause) => {
const subject = agentName ? `Agent "${agentName}"` : 'The agent';
const error = new Error(
@@ -2704,7 +2702,6 @@ module.exports = {
processRequiredActions,
resolveAgentCapabilities,
isFatalAgentInitializationError,
- isExpectedMCPToolsUnavailableError,
/** Re-exported for controllers that already depend on (and mock) this
* module, avoiding a fresh heavy `services/MCP` require chain there. */
getAccessibleMcpServerNames,
diff --git a/api/server/services/cleanup.js b/api/server/services/cleanup.js
deleted file mode 100644
index dc4f62c2ac..0000000000
--- a/api/server/services/cleanup.js
+++ /dev/null
@@ -1,14 +0,0 @@
-const { logger } = require('@librechat/data-schemas');
-const { deleteNullOrEmptyConversations } = require('~/models');
-
-const cleanup = async () => {
- try {
- await deleteNullOrEmptyConversations();
- } catch (error) {
- logger.error('[cleanup] Error during app cleanup', error);
- } finally {
- logger.debug('Startup cleanup complete');
- }
-};
-
-module.exports = { cleanup };
diff --git a/api/server/utils/handleText.js b/api/server/utils/handleText.js
index cce96feff4..761882a6e9 100644
--- a/api/server/utils/handleText.js
+++ b/api/server/utils/handleText.js
@@ -59,64 +59,6 @@ const createOnProgress = (
return { onProgress, getPartialText, sendIntermediateMessage };
};
-const handleText = async (response) => {
- let { text } = response;
- response.text = text;
- return text;
-};
-
-const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
-const getString = (input) => (isObject(input) ? JSON.stringify(input) : input);
-
-function formatSteps(steps) {
- let output = '';
-
- for (let i = 0; i < steps.length; i++) {
- const step = steps[i];
- const actionInput = getString(step.action.toolInput);
- const observation = step.observation;
-
- if (actionInput === 'N/A' || observation?.trim()?.length === 0) {
- continue;
- }
-
- output += `Input: ${actionInput}\nOutput: ${getString(observation)}`;
-
- if (steps.length > 1 && i !== steps.length - 1) {
- output += '\n---\n';
- }
- }
-
- return output;
-}
-
-function formatAction(action) {
- const formattedAction = {
- plugin: action.tool,
- input: getString(action.toolInput),
- thought: action.log.includes('Thought: ')
- ? action.log.split('\n')[0].replace('Thought: ', '')
- : action.log.split('\n')[0],
- };
-
- formattedAction.thought = getString(formattedAction.thought);
-
- if (action.tool.toLowerCase() === 'self-reflection' || formattedAction.plugin === 'N/A') {
- formattedAction.inputStr = `{\n\tthought: ${formattedAction.input}${
- !formattedAction.thought.includes(formattedAction.input)
- ? ' - ' + formattedAction.thought
- : ''
- }\n}`;
- formattedAction.inputStr = formattedAction.inputStr.replace('N/A - ', '');
- } else {
- const hasThought = formattedAction.thought.length > 0;
- const thought = hasThought ? `\n\tthought: ${formattedAction.thought}` : '';
- formattedAction.inputStr = `{\n\tplugin: ${formattedAction.plugin}\n\tinput: ${formattedAction.input}\n${thought}}`;
- }
-
- return formattedAction;
-}
-
/**
* Generate the configuration for a given key and base URL.
* @param {string} key
@@ -163,10 +105,6 @@ function generateConfig(key, baseURL, endpoint) {
}
module.exports = {
- handleText,
- formatSteps,
- formatAction,
generateConfig,
- addSpaceIfNeeded,
createOnProgress,
};
diff --git a/api/typedefs.js b/api/typedefs.js
index 81bc2b2ea9..a13b751c88 100644
--- a/api/typedefs.js
+++ b/api/typedefs.js
@@ -197,12 +197,6 @@
* @memberof typedefs
*/
-/**
- * @exports Ollama
- * @typedef {import('ollama').Ollama} Ollama
- * @memberof typedefs
- */
-
/**
* @exports AxiosResponse
* @typedef {import('axios').AxiosResponse} AxiosResponse
@@ -287,12 +281,6 @@
* @memberof typedefs
*/
-/**
- * @exports OllamaMessage
- * @typedef {import('ollama').Message} OllamaMessage
- * @memberof typedefs
- */
-
/**
* @exports ChatCompletionMessage
* @typedef {import('openai').OpenAI.ChatCompletionMessageParam} ChatCompletionMessage
@@ -1504,9 +1492,6 @@
/**
* @exports EndpointServiceConfig
* @typedef {Object} EndpointServiceConfig
- * @property {string} openAIApiKey - The API key for OpenAI.
- * @property {string} azureOpenAIApiKey - The API key for Azure OpenAI.
- * @property {boolean} userProvidedOpenAI - Flag to indicate if OpenAI API key is user provided.
* @property {string} googleKey - The Palm key.
* @property {boolean|{userProvide: boolean}} [openAI] - Flag to indicate if OpenAI endpoint is user provided, or its configuration.
* @property {boolean|{userProvide: boolean}} [assistant] - Flag to indicate if Assistant endpoint is user provided, or its configuration.
diff --git a/api/utils/LoggingSystem.js b/api/utils/LoggingSystem.js
deleted file mode 100644
index 390079e508..0000000000
--- a/api/utils/LoggingSystem.js
+++ /dev/null
@@ -1,129 +0,0 @@
-const logger = require('./logger');
-
-// Sanitize outside the logger paths. This is useful for sanitizing variables directly with Regex and patterns.
-const redactPatterns = [
- // Array of regular expressions for redacting patterns
- /api[-_]?key/i,
- /password/i,
- /token/i,
- /secret/i,
- /key/i,
- /certificate/i,
- /client[-_]?id/i,
- /authorization[-_]?code/i,
- /authorization[-_]?login[-_]?hint/i,
- /authorization[-_]?acr[-_]?values/i,
- /authorization[-_]?response[-_]?mode/i,
- /authorization[-_]?nonce/i,
-];
-
-/*
- // Example of redacting sensitive data from object class instances
- function redactSensitiveData(obj) {
- if (obj instanceof User) {
- return {
- ...obj.toObject(),
- password: '***', // Redact the password field
- };
- }
- return obj;
- }
-
- // Example of redacting sensitive data from object class instances
- logger.info({ newUser: redactSensitiveData(newUser) }, 'newUser');
-*/
-
-const levels = {
- TRACE: 10,
- DEBUG: 20,
- INFO: 30,
- WARN: 40,
- ERROR: 50,
- FATAL: 60,
-};
-
-let level = levels.INFO;
-
-module.exports = {
- levels,
- setLevel: (l) => (level = l),
- log: {
- trace: (msg) => {
- if (level <= levels.TRACE) {
- return;
- }
- logger.trace(msg);
- },
- debug: (msg) => {
- if (level <= levels.DEBUG) {
- return;
- }
- logger.debug(msg);
- },
- info: (msg) => {
- if (level <= levels.INFO) {
- return;
- }
- logger.info(msg);
- },
- warn: (msg) => {
- if (level <= levels.WARN) {
- return;
- }
- logger.warn(msg);
- },
- error: (msg) => {
- if (level <= levels.ERROR) {
- return;
- }
- logger.error(msg);
- },
- fatal: (msg) => {
- if (level <= levels.FATAL) {
- return;
- }
- logger.fatal(msg);
- },
-
- // Custom loggers
- parameters: (parameters) => {
- if (level <= levels.TRACE) {
- return;
- }
- logger.debug({ parameters }, 'Function Parameters');
- },
- functionName: (name) => {
- if (level <= levels.TRACE) {
- return;
- }
- logger.debug(`EXECUTING: ${name}`);
- },
- flow: (flow) => {
- if (level <= levels.INFO) {
- return;
- }
- logger.debug(`BEGIN FLOW: ${flow}`);
- },
- variable: ({ name, value }) => {
- if (level <= levels.DEBUG) {
- return;
- }
- // Check if the variable name matches any of the redact patterns and redact the value
- let sanitizedValue = value;
- for (const pattern of redactPatterns) {
- if (pattern.test(name)) {
- sanitizedValue = '***';
- break;
- }
- }
- logger.debug({ variable: { name, value: sanitizedValue } }, `VARIABLE ${name}`);
- },
- request: () => (req, res, next) => {
- if (level < levels.DEBUG) {
- return next();
- }
- logger.debug({ query: req.query, body: req.body }, `Hit URL ${req.url} with following`);
- return next();
- },
- },
-};
diff --git a/bun.lock b/bun.lock
index 3214d6c35d..ec43f44d27 100644
--- a/bun.lock
+++ b/bun.lock
@@ -114,7 +114,6 @@
"nanoid": "^3.3.18",
"node-fetch": "^2.7.0",
"nodemailer": "^9.0.1",
- "ollama": "^0.5.0",
"openai": "5.8.2",
"openid-client": "^6.5.0",
"passport": "^0.6.0",
@@ -4122,7 +4121,6 @@
"okapibm25": ["[email protected]", "", {}, "sha512-UHmeH4MAtZXGFVncwbY7pfFvDVNxpsyM3W66aGPU0SHj1+ld59ty+9lJ0ifcrcnPUl1XdYoDgb06ObyCnpTs3g=="],
- "ollama": ["[email protected]", "", { "dependencies": { "whatwg-fetch": "^3.6.20" } }, "sha512-lTFqTf9bo7Cd3hpF6CviBe/DEhewjoZYd9N/uCe7O20qYTvGqrNOFOBDj3lbZgFWHUgDv5EeyusYxsZSLS8nvg=="],
"on-finished": ["[email protected]", "", { "dependencies": { "ee-first": "1.1.1" } }, "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg=="],
@@ -5008,7 +5006,6 @@
"whatwg-encoding": ["[email protected]", "", { "dependencies": { "iconv-lite": "0.6.3" } }, "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ=="],
- "whatwg-fetch": ["[email protected]", "", {}, "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg=="],
"whatwg-mimetype": ["[email protected]", "", {}, "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg=="],
diff --git a/config/translations/README.md b/config/translations/README.md
deleted file mode 100644
index 248e4e4c31..0000000000
--- a/config/translations/README.md
+++ /dev/null
@@ -1,30 +0,0 @@
-## Translations
-
-### Requirements:
-- All dependencies installed, run `npm ci` in the root directory.
-- bun: https://bun.sh/
-- `ANTHROPIC_API_KEY` in project root directory `.env` file.
-
-### ⚠️ Warning:
-
-This script can be expensive, several dollars worth, even with prompt caching. It can also be slow if it has not been run in a while, with translations contributed.
-
-### Instructions:
-
-*All commands are run from the root directory.*
-
-**Supported languages are localizations with general translation prompts**
-- These prompts are directly found in `client/src/localization/prompts`.
-- If your language is missing, you can contribute by adding a new file in `client/src/localization/prompts` with the language code as the file name.
-
-0. Make sure git history is clean with `git status`.
-1. Install `hnswlib-node` package temporarily (we don't need to include it in the project):
-```bash
-npm install --save-dev hnswlib-node
-```
-2. Run `bun install`.
-3. Main script: Run `bun config/translations/scan.ts`.
-4. Observe translations being generated in all supported languages and saved in `client/src/localization/languages`.
- - e.g.: `client/src/localization/languages/Es_missing_keys.json`
-5. Discard all git changes with `git checkout .`.
-6. Copy the generated translations to their respective files, e.g.: `client/src/localization/languages/Es.ts`.
\ No newline at end of file
diff --git a/config/translations/anthropic.ts b/config/translations/anthropic.ts
deleted file mode 100644
index 968474a45a..0000000000
--- a/config/translations/anthropic.ts
+++ /dev/null
@@ -1,82 +0,0 @@
-import Anthropic from '@anthropic-ai/sdk';
-import type * as a from '@anthropic-ai/sdk';
-import { parseParamFromPrompt, genTranslationPrompt } from '~/app/clients/prompts/titlePrompts';
-
-/**
- * Get the initialized Anthropic client.
- * @returns {Anthropic} The Anthropic client instance.
- */
-export function getClient() {
- /** @type {Anthropic.default.RequestOptions} */
- const options = {
- apiKey: process.env.ANTHROPIC_API_KEY,
- };
-
- return new Anthropic(options);
-}
-
-/**
- * This function capitlizes on [Anthropic's function calling training](https://docs.anthropic.com/claude/docs/functions-external-tools).
- *
- * @param {Object} params - The parameters for the generation.
- * @param {string} params.key
- * @param {string} params.baselineTranslation
- * @param {string} params.translationPrompt
- * @param {Array<{ pageContent: string }>} params.context
- *
- * @returns {Promise<string | 'New Chat'>} A promise that resolves to the generated conversation title.
- * In case of failure, it will return the default title, "New Chat".
- */
-export async function translateKeyPhrase({ key, baselineTranslation, translationPrompt, context }) {
- let translation: string | undefined;
- const model = 'claude-3-5-sonnet-20241022';
- const prompt = genTranslationPrompt(translationPrompt);
- const system = prompt;
-
- const translateCompletion = async () => {
- const text = `Current key: \`${key}\`
-
- Baseline translation: ${baselineTranslation}
-
- Please generate a translation for the key in the target language as described by the function.
-
- Similar key and phrases: ${context.map((c) => c.pageContent).join(', ')}
-
- Remember to invoke the tool with proper tool invocation; e.g.:
-
- <invoke>\n<tool_name>submit_translation</tool_name>\n<parameters>\n<translation>Your Translation Here</translation>\n</parameters>\n</invoke>`;
-
- const message: a.Anthropic.MessageParam = {
- role: 'user',
- content: [
- {
- type: 'text',
- text,
- /* @ts-ignore */
- cache_control: { type: 'ephemeral' },
- },
- ],
- };
- const requestOptions: a.Anthropic.MessageCreateParamsNonStreaming = {
- model,
- temperature: 0.3,
- max_tokens: 1024,
- system,
- stop_sequences: ['\n\nHuman:', '\n\nAssistant', '</function_calls>'],
- messages: [message],
- stream: false,
- };
-
- try {
- const client = getClient();
- const response = await client.messages.create(requestOptions);
- const text = response.content[0].text;
- translation = parseParamFromPrompt(text, 'translation');
- } catch (e) {
- console.error('[AnthropicClient] There was an issue generating the translation', e);
- }
- };
-
- await translateCompletion();
- return translation;
-}
diff --git a/config/translations/comparisons.ts b/config/translations/comparisons.ts
deleted file mode 100644
index a3a0193dc6..0000000000
--- a/config/translations/comparisons.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import fs from 'fs';
-import path from 'path';
-import { exec } from 'child_process';
-
-async function main(languagesDir: string) {
- const files = fs.readdirSync(languagesDir);
-
- for (const file of files) {
- const ext = path.extname(file);
- if (ext !== '.ts' && ext !== '.tsx') {
- continue;
- }
-
- const filePath = path.resolve(languagesDir, file);
-
- let fileContent = fs.readFileSync(filePath, 'utf8');
- const comparisonsObjRegex = /export const comparisons = {[\s\S]*?};/gm;
-
- if (comparisonsObjRegex.test(fileContent)) {
- // Remove the comparisons object
- fileContent = fileContent.replace(comparisonsObjRegex, '');
-
- // Remove any empty lines at the end of the file
- fileContent = fileContent.trim() + '\n';
-
- fs.writeFileSync(filePath, fileContent);
- console.log(`Removed comparisons from ${file}`);
- } else {
- console.log(`No comparisons found in ${file}`);
- }
- }
-
- // Execute ESLint with the --fix option on the entire directory
- exec(`bunx eslint "${languagesDir}" --fix`, (error, stdout, stderr) => {
- if (error) {
- console.error('Error executing ESLint:', error);
- return;
- }
- if (stderr) {
- console.error('ESLint stderr:', stderr);
- return;
- }
- console.log('ESLint stdout:', stdout);
- });
-}
-
-const languagesDir = './client/src/localization/languages';
-
-main(languagesDir).catch(console.error);
diff --git a/config/translations/embeddings.ts b/config/translations/embeddings.ts
deleted file mode 100644
index c556460b54..0000000000
--- a/config/translations/embeddings.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import dotenv from 'dotenv';
-dotenv.config({
- path: './',
-});
-import { OpenAIEmbeddings } from '@langchain/openai';
-import { HNSWLib } from '@langchain/community/vectorstores/hnswlib';
-import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters';
-import * as fs from 'fs';
-import * as path from 'path';
-
-export const storeEmbeddings = async (modulePath: string) => {
- try {
- const text = fs.readFileSync(modulePath, 'utf8');
- const textSplitter = new RecursiveCharacterTextSplitter({ chunkSize: 600 });
- const docs = await textSplitter.createDocuments([text]);
- const vectorStore = await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings());
- const directory = `./config/translations/stores/${path.basename(modulePath)}`;
-
- if (!fs.existsSync(directory)) {
- fs.mkdirSync(directory, { recursive: true });
- console.log(`Directory created: ${directory}`);
- } else {
- console.log(`Directory already exists: ${directory}`);
- return;
- }
-
- await vectorStore.save(directory);
- } catch (error) {
- console.error('Error storing embeddings');
- console.error(error);
- }
-};
-
-export const loadEmbeddings = async (modulePath: string) => {
- try {
- const directory = `./config/translations/stores/${path.basename(modulePath)}`;
- const loadedVectorStore = await HNSWLib.load(directory, new OpenAIEmbeddings());
- return loadedVectorStore;
- } catch (error) {
- console.error('Error loading embeddings');
- console.error(error);
- }
-};
diff --git a/config/translations/file.ts b/config/translations/file.ts
deleted file mode 100644
index 966dcc9587..0000000000
--- a/config/translations/file.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import path from 'path';
-import main from './main';
-
-async function processFile(baseFilePath: string, compareFilename: string) {
- await main(baseFilePath, compareFilename);
-}
-
-const args = process.argv.slice(-1);
-
-if (args.length !== 1) {
- console.log(process.argv, args);
- console.error('Usage: bun file.ts <compareFilename>');
- process.exit(1);
-}
-
-const languagesDir = './client/src/localization/languages';
-const baseFilePath = path.resolve(languagesDir, 'Eng.ts');
-
-const compareFilename = path.resolve(languagesDir, `${args[0]}.ts`);
-
-processFile(baseFilePath, compareFilename).catch(console.error);
diff --git a/config/translations/instructions.ts b/config/translations/instructions.ts
deleted file mode 100644
index 205d9da630..0000000000
--- a/config/translations/instructions.ts
+++ /dev/null
@@ -1,78 +0,0 @@
-import fs from 'fs';
-import path from 'path';
-
-const baseDirPath = './client/src/localization/languages';
-const promptsDirPath = './client/src/localization/prompts/instructions';
-
-async function ensureDirectoryExists(directory: string) {
- return fs.promises
- .access(directory)
- .catch(() => fs.promises.mkdir(directory, { recursive: true }));
-}
-
-// Helper function to generate Markdown from an object, recursively if needed
-function generateMarkdownFromObject(obj: object, depth = 0): string {
- if (typeof obj !== 'object' || obj === null) {
- return String(obj);
- }
-
- const indent = ' '.repeat(depth * 2);
- return Object.entries(obj)
- .map(([key, value]) => {
- if (typeof value === 'object') {
- return `\n${indent}- **${key}**:${generateMarkdownFromObject(value, depth + 1)}`;
- }
- return `${key === 'english' ? '\n' : ''}${indent}- **${key}**: ${value}`;
- })
- .join('\n');
-}
-
-async function generatePromptForFile(filePath: string, fileName: string) {
- const modulePath = path.resolve(filePath); // Ensuring path is correctly resolved
- const fileModule = await import(modulePath); // Dynamically importing the file as a module
- let comparisonsMarkdown = '';
-
- if (fileModule.comparisons) {
- comparisonsMarkdown = generateMarkdownFromObject(fileModule.comparisons);
- } else {
- comparisonsMarkdown = 'No comparisons object found.';
- }
-
- // Creating markdown content
- const promptContent = `# Instructions for Translation
-
-Write a prompt that is mindful of the nuances in the language with respect to its English counterpart, which serves as the baseline for translations. Here are the comparisons between the language translations and their English counterparts:
-
-${comparisonsMarkdown}
-
-Please consider the above comparisons to enhance understanding and guide improvements in translations.
-
-Provide insights or suggestions that could help refine the translation process, focusing on cultural and contextual relevance.
-
-Please craft a prompt that can be used to better inform future translations to this language.
-
-Write this prompt in the translated language, with all its nuances detected, not in the English.
-`;
-
- return promptContent;
-}
-
-async function createPromptsForTranslations() {
- await ensureDirectoryExists(promptsDirPath);
-
- const files = await fs.promises.readdir(baseDirPath);
-
- for (const file of files) {
- if (!file.includes('Eng.ts')) {
- // Ensure English or base file is excluded
- const filePath = path.join(baseDirPath, file);
- const promptContent = await generatePromptForFile(filePath, file);
- const outputFilePath = path.join(promptsDirPath, `${path.basename(file, '.ts')}.md`);
-
- await fs.promises.writeFile(outputFilePath, promptContent);
- console.log(`Prompt created for: ${file}`);
- }
- }
-}
-
-createPromptsForTranslations().then(() => console.log('Prompts generation completed.'));
diff --git a/config/translations/keys.ts b/config/translations/keys.ts
deleted file mode 100644
index 362c7b137b..0000000000
--- a/config/translations/keys.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import fs from 'fs';
-import path from 'path';
-
-async function readKeysFromFile(filePath: string): Promise<string[]> {
- const languageModule = await import(filePath);
- const keys = Object.keys(languageModule.default);
- return keys;
-}
-
-async function compareKeys(baseKeys: string[], keysFromOtherFile: string[]): Promise<string[]> {
- const missingKeys = baseKeys.filter((key) => !keysFromOtherFile.includes(key));
- return missingKeys;
-}
-
-async function main(baseFilePath: string, languagesDir: string) {
- const baseKeys = await readKeysFromFile(baseFilePath);
-
- const files = fs.readdirSync(languagesDir);
- for (const file of files) {
- const ext = path.extname(file);
- if (ext !== '.ts' && ext !== '.tsx') {
- continue;
- } // Ensure it's a TypeScript file
-
- const compareFilePath = path.resolve(languagesDir, file);
- if (compareFilePath === baseFilePath) {
- continue;
- } // Skip the base file
-
- try {
- const keysFromOtherFile = await readKeysFromFile(compareFilePath);
- const missingKeys = await compareKeys(baseKeys, keysFromOtherFile);
- if (missingKeys.length > 0) {
- console.log(`Missing Keys in ${file}:`, missingKeys);
- }
- } catch (error) {
- console.error(`Error processing file ${file}:`, error);
- }
- }
-}
-
-// Set the directory containing language files and specify the path to the base (English) language file.
-const languagesDir = './client/src/localization/languages';
-const baseFilePath = path.resolve(languagesDir, 'Eng.ts');
-
-main(baseFilePath, languagesDir).catch(console.error);
diff --git a/config/translations/main.ts b/config/translations/main.ts
deleted file mode 100644
index 3242318f32..0000000000
--- a/config/translations/main.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import fs from 'fs';
-import path from 'path';
-import { processLanguageModule, processMissingKey } from './process';
-const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
-
-export default async function main(baseFilePath: string, compareFilePath: string) {
- const prompt = await processLanguageModule(path.basename(compareFilePath), compareFilePath);
-
- if (prompt === undefined) {
- console.error(`Prompt not found for module: ${path.basename(compareFilePath)}`);
- return;
- }
-
- const baseModule = await import(baseFilePath);
- const baseKeys = Object.keys(baseModule.default);
-
- const compareModule = await import(compareFilePath);
- const compareKeys = Object.keys(compareModule.default);
-
- const missingKeys = baseKeys.filter((key) => !compareKeys.includes(key));
- const promises: Array<Promise<void>> = [];
- if (missingKeys.length > 0) {
- const keyTranslations = {};
- for (const key of missingKeys) {
- const baselineTranslation = baseModule.default[key] || 'No baseline translation available';
- const handleMissingKey = async () => {
- try {
- const result = await processMissingKey({
- key,
- baselineTranslation,
- translationPrompt: prompt,
- moduleName: path.basename(compareFilePath),
- });
- keyTranslations[key] = result;
- } catch (e) {
- console.error(`Error processing key: ${key}`, e);
- }
- };
-
- promises.push(handleMissingKey());
- await sleep(700);
- }
-
- await Promise.all(promises);
- const outputDir = path.dirname(compareFilePath);
- const outputFileName = `${path.basename(
- compareFilePath,
- path.extname(compareFilePath),
- )}_missing_keys.json`;
- const outputFilePath = path.join(outputDir, outputFileName);
- fs.writeFileSync(outputFilePath, JSON.stringify(keyTranslations, null, 2));
- }
-}
diff --git a/config/translations/process.ts b/config/translations/process.ts
deleted file mode 100644
index 7494dbbf60..0000000000
--- a/config/translations/process.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-import fs from 'fs';
-import path from 'path';
-import { storeEmbeddings, loadEmbeddings } from './embeddings';
-import { translateKeyPhrase } from './anthropic';
-
-const missingKeyMap = {};
-const vectorStoreMap = {};
-
-export async function processLanguageModule(moduleName: string, modulePath: string) {
- const filename = path.basename(moduleName, path.extname(moduleName));
- const promptFilePath = path.join(path.dirname(modulePath), '../prompts', `${filename}.md`);
- console.log(promptFilePath);
-
- if (!fs.existsSync(promptFilePath)) {
- console.error(`Prompt file not found for module: ${moduleName}`);
- return undefined;
- }
-
- const prompt = fs.readFileSync(promptFilePath, 'utf-8');
- await storeEmbeddings(modulePath);
- vectorStoreMap[moduleName] = await loadEmbeddings(modulePath);
- const baseKeys = Object.keys((await import(modulePath)).default);
- console.log(`Keys in module: ${moduleName}:`, baseKeys.length);
- missingKeyMap[moduleName] = 0;
- return prompt;
-}
-
-export async function processMissingKey({
- key,
- baselineTranslation,
- moduleName,
- translationPrompt,
-}: {
- key: string;
- baselineTranslation: string;
- moduleName: string;
- translationPrompt: string;
-}) {
- missingKeyMap[moduleName]++;
- const vectorStore = vectorStoreMap[moduleName];
- const context = await vectorStore.similaritySearch(key, 5);
- const translation = await translateKeyPhrase({
- key,
- baselineTranslation,
- translationPrompt,
- context,
- });
- console.log(`"${key}": "${translation}",\n`);
- return translation;
-}
diff --git a/config/translations/scan.ts b/config/translations/scan.ts
deleted file mode 100644
index 04a4e9b13e..0000000000
--- a/config/translations/scan.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import fs from 'fs';
-import path from 'path';
-import main from './main';
-
-async function scanDirectory(baseFilePath: string, languagesDir: string) {
- const files = fs.readdirSync(languagesDir);
- for (const file of files) {
- const ext = path.extname(file);
- if (ext !== '.ts' && ext !== '.tsx') {
- continue;
- }
-
- const compareFilePath = path.resolve(languagesDir, file);
- if (compareFilePath === baseFilePath) {
- continue;
- }
-
- await main(baseFilePath, compareFilePath);
- }
-}
-
-const languagesDir = './client/src/localization/languages';
-const baseFilePath = path.resolve(languagesDir, 'Eng.ts');
-
-scanDirectory(baseFilePath, languagesDir).catch(console.error);
diff --git a/config/translations/tsconfig.json b/config/translations/tsconfig.json
deleted file mode 100644
index e56fadd965..0000000000
--- a/config/translations/tsconfig.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "compilerOptions": {
- "noImplicitAny": false,
- "outDir": "./dist",
- "strict": true,
- "moduleResolution": "bundler",
- "esModuleInterop": true,
- "target": "es6",
- "module": "esnext",
- "lib": ["dom", "es6"],
- "paths": {
- "~/*": ["../../api/*"]
- }
- },
- "include": ["*.ts"]
-}
diff --git a/e2e/specs/settings.spec.ts b/e2e/specs/settings.spec.ts
deleted file mode 100644
index 0c49f78b18..0000000000
--- a/e2e/specs/settings.spec.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-import { expect, test } from '@playwright/test';
-
-test.describe('Settings suite', () => {
- test('Last OpenAI settings', async ({ page }) => {
- await page.goto('http://localhost:3080/', { timeout: 5000 });
- await page.evaluate(() =>
- window.localStorage.setItem(
- 'lastConversationSetup',
- JSON.stringify({
- conversationId: 'new',
- title: 'New Chat',
- endpoint: 'openAI',
- createdAt: '',
- updatedAt: '',
- }),
- ),
- );
- await page.goto('http://localhost:3080/', { timeout: 5000 });
-
- const initialLocalStorage = await page.evaluate(() => window.localStorage);
- const lastConvoSetup = JSON.parse(initialLocalStorage.lastConversationSetup);
- expect(lastConvoSetup.endpoint).toEqual('openAI');
-
- const newTopicButton = page.getByTestId('new-conversation-menu');
- await newTopicButton.click();
-
- // includes the icon + endpoint names in obj property
- const endpointItem = page.getByTestId('endpoint-item-openAI');
- await endpointItem.click();
-
- await page.getByTestId('text-input').click();
- const button1 = page.getByRole('button', { name: 'Mode: BingAI' });
- const button2 = page.getByRole('button', { name: 'Mode: Sydney' });
-
- try {
- await button1.click({ timeout: 100 });
- } catch (e) {
- // console.log('Bing button', e);
- }
-
- try {
- await button2.click({ timeout: 100 });
- } catch (e) {
- // console.log('Sydney button', e);
- }
- await page.getByRole('option', { name: 'Sydney' }).click();
- await page.getByRole('tab', { name: 'Balanced' }).click();
-
- // Change Endpoint to see if settings will persist
- await newTopicButton.click();
- await page.getByRole('menuitemradio', { name: 'ChatGPT OpenAI' }).click();
-
- // Close endpoint menu & re-select BingAI
- await page.getByTestId('text-input').click();
- await newTopicButton.click();
- await endpointItem.click();
-
- // Check if the settings persisted
- const localStorage = await page.evaluate(() => window.localStorage);
- const button = page.getByRole('button', { name: 'Mode: Sydney' });
- expect(button.count()).toBeTruthy();
- });
-});
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 8f6a3fbe0d..d857a6cafb 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -548,14 +548,6 @@ export default [
],
},
},
- {
- files: ['./config/translations/**/*.ts'],
- languageOptions: {
- parser: tsParser,
- ecmaVersion: 5,
- sourceType: 'script',
- },
- },
{
files: ['./packages/data-provider/specs/**/*.ts'],
languageOptions: {
diff --git a/helm/librechat-rag-api/templates/_helpers.tpl b/helm/librechat-rag-api/templates/_helpers.tpl
index c8485cf7a9..a4493211c8 100755
--- a/helm/librechat-rag-api/templates/_helpers.tpl
+++ b/helm/librechat-rag-api/templates/_helpers.tpl
@@ -45,21 +45,3 @@ RAG Selector labels
app.kubernetes.io/name: {{ include "rag.fullname" . }}-rag
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
-
-{{/*
-Create the name of the service account to use
-*/}}
-{{- define "rag.serviceAccountName" -}}
-{{- if .Values.serviceAccount.create }}
-{{- default (include "rag.fullname" .) .Values.serviceAccount.name }}
-{{- else }}
-{{- default "default" .Values.serviceAccount.name }}
-{{- end }}
-{{- end }}
-
-
-{{- define "rag.dbsecretValue" -}}
-{{- $secret := .Values.postgresql.auth.existingSecret -}}
-{{- $key := "password" -}}
-{{- printf "%s" (include "exec" (dict "command" "kubectl" "args" (list "get" "secret" $secret "-o=jsonpath={.data." $key "}"))) | b64enc -}}
-{{- end -}}
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 79c659ff32..cbd99b0d50 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -130,7 +130,6 @@
"nanoid": "^3.3.18",
"node-fetch": "^2.7.0",
"nodemailer": "^10.0.2",
- "ollama": "^0.5.0",
"openai": "5.8.2",
"openid-client": "^6.5.0",
"passport": "^0.6.0",
@@ -32828,15 +32827,6 @@
"integrity": "sha512-UHmeH4MAtZXGFVncwbY7pfFvDVNxpsyM3W66aGPU0SHj1+ld59ty+9lJ0ifcrcnPUl1XdYoDgb06ObyCnpTs3g==",
"license": "MIT"
},
- "node_modules/ollama": {
- "version": "0.5.18",
- "resolved": "https://registry.npmjs.org/ollama/-/ollama-0.5.18.tgz",
- "integrity": "sha512-lTFqTf9bo7Cd3hpF6CviBe/DEhewjoZYd9N/uCe7O20qYTvGqrNOFOBDj3lbZgFWHUgDv5EeyusYxsZSLS8nvg==",
- "license": "MIT",
- "dependencies": {
- "whatwg-fetch": "^3.6.20"
- }
- },
"node_modules/on-finished": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
@@ -39606,11 +39596,6 @@
"node": ">=0.10.0"
}
},
- "node_modules/whatwg-fetch": {
- "version": "3.6.20",
- "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz",
- "integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg=="
- },
"node_modules/whatwg-mimetype": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz",
diff --git a/package.json b/package.json
index 4927ac8a5c..9bdb2dbd40 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,6 @@
"rebase:deployed": "node config/deployed-update.js --rebase",
"start:deployed": "docker compose -f ./deploy-compose.yml up -d || docker-compose -f ./deploy-compose.yml up -d",
"stop:deployed": "docker compose -f ./deploy-compose.yml down || docker-compose -f ./deploy-compose.yml down",
- "upgrade": "node config/upgrade.js",
"create-user": "node config/create-user.js",
"invite-user": "node config/invite-user.js",
"list-users": "node config/list-users.js",
diff --git a/packages/data-schemas/src/methods/conversation.spec.ts b/packages/data-schemas/src/methods/conversation.spec.ts
index c971f1b408..ecea2ae359 100644
--- a/packages/data-schemas/src/methods/conversation.spec.ts
+++ b/packages/data-schemas/src/methods/conversation.spec.ts
@@ -105,9 +105,6 @@ const getConvosByCursor = (...args: Parameters<ConversationMethods['getConvosByC
methods.getConvosByCursor(...args);
const getConvosQueried = (...args: Parameters<ConversationMethods['getConvosQueried']>) =>
methods.getConvosQueried(...args);
-const deleteNullOrEmptyConversations = (
- ...args: Parameters<ConversationMethods['deleteNullOrEmptyConversations']>
-) => methods.deleteNullOrEmptyConversations(...args);
const searchConversation = (...args: Parameters<ConversationMethods['searchConversation']>) =>
methods.searchConversation(...args);
@@ -5014,32 +5011,6 @@ describe('Conversation Operations', () => {
});
});
- describe('deleteNullOrEmptyConversations', () => {
- it('should delete conversations with null, empty, or missing conversationIds', async () => {
- // Since conversationId is required by the schema, we can't create documents with null/missing IDs
- // This test should verify the function works when such documents exist (e.g., from data corruption)
-
- // For this test, let's create a valid conversation and verify the function doesn't delete it
- await Conversation.create({
- conversationId: mockConversationData.conversationId,
- user: 'user4',
- endpoint: EModelEndpoint.openAI,
- });
-
- deleteMessages.mockResolvedValue({ deletedCount: 0 });
-
- const result = await deleteNullOrEmptyConversations();
-
- expect(result?.conversations.deletedCount).toBe(0); // No invalid conversations to delete
- expect(result?.messages.deletedCount).toBe(0);
-
- // Verify valid conversation remains
- const remainingConvos = await Conversation.find({});
- expect(remainingConvos).toHaveLength(1);
- expect(remainingConvos[0].conversationId).toBe(mockConversationData.conversationId);
- });
- });
-
describe('Error Handling', () => {
it('should handle database errors in saveConvo', async () => {
// Force a database error by disconnecting
diff --git a/packages/data-schemas/src/methods/conversation.ts b/packages/data-schemas/src/methods/conversation.ts
index 65d8a07c3c..350178cafe 100644
--- a/packages/data-schemas/src/methods/conversation.ts
+++ b/packages/data-schemas/src/methods/conversation.ts
@@ -290,10 +290,6 @@ export interface ConversationMethods {
conversationId: string,
fieldsToSelect?: string | null,
): Promise<IConversation | null>;
- deleteNullOrEmptyConversations(): Promise<{
- conversations: { deletedCount?: number };
- messages: { deletedCount?: number };
- }>;
saveConvo(
ctx: {
userId: string;
@@ -2314,38 +2310,6 @@ export function createConversationMethods(
}
}
- /**
- * Deletes conversations and messages with null or empty IDs.
- */
- async function deleteNullOrEmptyConversations() {
- try {
- const Conversation = mongoose.models.Conversation as Model<IConversation>;
- const { deleteMessages } = getMessageMethods();
- const filter = {
- $or: [
- { conversationId: null },
- { conversationId: '' },
- { conversationId: { $exists: false } },
- ],
- };
-
- const result = await Conversation.deleteMany(filter);
- const messageDeleteResult = await deleteMessages(filter);
-
- logger.info(
- `[deleteNullOrEmptyConversations] Deleted ${result.deletedCount} conversations and ${messageDeleteResult.deletedCount} messages`,
- );
-
- return {
- conversations: result,
- messages: messageDeleteResult,
- };
- } catch (error) {
- logger.error('[deleteNullOrEmptyConversations] Error deleting conversations', error);
- throw new Error('Error deleting conversations with null or empty conversationId');
- }
- }
-
/**
* Searches for a conversation by conversationId and returns associated file ids.
*/
@@ -4574,7 +4538,6 @@ export function createConversationMethods(
return {
getConvoFiles,
searchConversation,
- deleteNullOrEmptyConversations,
stampForcedRetention,
saveConvo,
setConvoPinned,