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

🎉 feat: Code Interpreter API and Agents Release (#4860)

Danny Avila1a815f5e19fd
diff --git a/.env.example b/.env.example
index e4aa8a46f0..017712027e 100644
--- a/.env.example
+++ b/.env.example
@@ -177,10 +177,10 @@ OPENAI_API_KEY=user_provided
DEBUG_OPENAI=false
# TITLE_CONVO=false
-# OPENAI_TITLE_MODEL=gpt-3.5-turbo
+# OPENAI_TITLE_MODEL=gpt-4o-mini
# OPENAI_SUMMARIZE=true
-# OPENAI_SUMMARY_MODEL=gpt-3.5-turbo
+# OPENAI_SUMMARY_MODEL=gpt-4o-mini
# OPENAI_FORCE_PROMPT=true
diff --git a/api/app/clients/BaseClient.js b/api/app/clients/BaseClient.js
index 33e3df3ac6..8b9e89860c 100644
--- a/api/app/clients/BaseClient.js
+++ b/api/app/clients/BaseClient.js
@@ -50,6 +50,8 @@ class BaseClient {
/** The key for the usage object's output tokens
* @type {string} */
this.outputTokensKey = 'completion_tokens';
+ /** @type {Set<string>} */
+ this.savedMessageIds = new Set();
}
setOptions() {
@@ -84,7 +86,7 @@ class BaseClient {
return this.options.agent.id;
}
- return this.modelOptions.model;
+ return this.modelOptions?.model ?? this.model;
}
/**
@@ -508,7 +510,7 @@ class BaseClient {
conversationId,
parentMessageId: userMessage.messageId,
isCreatedByUser: false,
- model: this.modelOptions.model,
+ model: this.modelOptions?.model ?? this.model,
sender: this.sender,
text: generation,
};
@@ -545,6 +547,7 @@ class BaseClient {
if (!isEdited && !this.skipSaveUserMessage) {
this.userMessagePromise = this.saveMessageToDatabase(userMessage, saveOptions, user);
+ this.savedMessageIds.add(userMessage.messageId);
if (typeof opts?.getReqData === 'function') {
opts.getReqData({
userMessagePromise: this.userMessagePromise,
@@ -563,8 +566,8 @@ class BaseClient {
user: this.user,
tokenType: 'prompt',
amount: promptTokens,
- model: this.modelOptions.model,
endpoint: this.options.endpoint,
+ model: this.modelOptions?.model ?? this.model,
endpointTokenConfig: this.options.endpointTokenConfig,
},
});
@@ -574,6 +577,7 @@ class BaseClient {
const completion = await this.sendCompletion(payload, opts);
this.abortController.requestCompleted = true;
+ /** @type {TMessage} */
const responseMessage = {
messageId: responseMessageId,
conversationId,
@@ -635,7 +639,16 @@ class BaseClient {
responseMessage.attachments = (await Promise.all(this.artifactPromises)).filter((a) => a);
}
+ if (this.options.attachments) {
+ try {
+ saveOptions.files = this.options.attachments.map((attachments) => attachments.file_id);
+ } catch (error) {
+ logger.error('[BaseClient] Error mapping attachments for conversation', error);
+ }
+ }
+
this.responsePromise = this.saveMessageToDatabase(responseMessage, saveOptions, user);
+ this.savedMessageIds.add(responseMessage.messageId);
const messageCache = getLogStores(CacheKeys.MESSAGES);
messageCache.set(
responseMessageId,
@@ -902,8 +915,9 @@ class BaseClient {
// Note: gpt-3.5-turbo and gpt-4 may update over time. Use default for these as well as for unknown models
let tokensPerMessage = 3;
let tokensPerName = 1;
+ const model = this.modelOptions?.model ?? this.model;
- if (this.modelOptions.model === 'gpt-3.5-turbo-0301') {
+ if (model === 'gpt-3.5-turbo-0301') {
tokensPerMessage = 4;
tokensPerName = -1;
}
@@ -961,6 +975,15 @@ class BaseClient {
return _messages;
}
+ const seen = new Set();
+ const attachmentsProcessed =
+ this.options.attachments && !(this.options.attachments instanceof Promise);
+ if (attachmentsProcessed) {
+ for (const attachment of this.options.attachments) {
+ seen.add(attachment.file_id);
+ }
+ }
+
/**
*
* @param {TMessage} message
@@ -971,7 +994,19 @@ class BaseClient {
this.message_file_map = {};
}
- const fileIds = message.files.map((file) => file.file_id);
+ const fileIds = [];
+ for (const file of message.files) {
+ if (seen.has(file.file_id)) {
+ continue;
+ }
+ fileIds.push(file.file_id);
+ seen.add(file.file_id);
+ }
+
+ if (fileIds.length === 0) {
+ return message;
+ }
+
const files = await getFiles({
file_id: { $in: fileIds },
});
diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js
index 6a8377be6f..d3bf5ddd12 100644
--- a/api/app/clients/OpenAIClient.js
+++ b/api/app/clients/OpenAIClient.js
@@ -688,7 +688,7 @@ class OpenAIClient extends BaseClient {
}
initializeLLM({
- model = 'gpt-3.5-turbo',
+ model = 'gpt-4o-mini',
modelName,
temperature = 0.2,
presence_penalty = 0,
@@ -793,7 +793,7 @@ class OpenAIClient extends BaseClient {
const { OPENAI_TITLE_MODEL } = process.env ?? {};
- let model = this.options.titleModel ?? OPENAI_TITLE_MODEL ?? 'gpt-3.5-turbo';
+ let model = this.options.titleModel ?? OPENAI_TITLE_MODEL ?? 'gpt-4o-mini';
if (model === Constants.CURRENT_MODEL) {
model = this.modelOptions.model;
}
@@ -982,7 +982,7 @@ ${convo}
let prompt;
// TODO: remove the gpt fallback and make it specific to endpoint
- const { OPENAI_SUMMARY_MODEL = 'gpt-3.5-turbo' } = process.env ?? {};
+ const { OPENAI_SUMMARY_MODEL = 'gpt-4o-mini' } = process.env ?? {};
let model = this.options.summaryModel ?? OPENAI_SUMMARY_MODEL;
if (model === Constants.CURRENT_MODEL) {
model = this.modelOptions.model;
diff --git a/api/app/clients/PluginsClient.js b/api/app/clients/PluginsClient.js
index b25412d676..09e3dc5adc 100644
--- a/api/app/clients/PluginsClient.js
+++ b/api/app/clients/PluginsClient.js
@@ -105,7 +105,7 @@ class PluginsClient extends OpenAIClient {
chatHistory: new ChatMessageHistory(pastMessages),
});
- this.tools = await loadTools({
+ const { loadedTools } = await loadTools({
user,
model,
tools: this.options.tools,
@@ -119,12 +119,15 @@ class PluginsClient extends OpenAIClient {
processFileURL,
message,
},
+ useSpecs: true,
});
- if (this.tools.length === 0) {
+ if (loadedTools.length === 0) {
return;
}
+ this.tools = loadedTools;
+
logger.debug('[PluginsClient] Requested Tools', this.options.tools);
logger.debug(
'[PluginsClient] Loaded Tools',
diff --git a/api/app/clients/llm/createLLM.js b/api/app/clients/llm/createLLM.js
index c227a2bf36..7dc0d40ceb 100644
--- a/api/app/clients/llm/createLLM.js
+++ b/api/app/clients/llm/createLLM.js
@@ -17,7 +17,7 @@ const { isEnabled } = require('~/server/utils');
*
* @example
* const llm = createLLM({
- * modelOptions: { modelName: 'gpt-3.5-turbo', temperature: 0.2 },
+ * modelOptions: { modelName: 'gpt-4o-mini', temperature: 0.2 },
* configOptions: { basePath: 'https://example.api/path' },
* callbacks: { onMessage: handleMessage },
* openAIApiKey: 'your-api-key'
diff --git a/api/app/clients/memory/summaryBuffer.demo.js b/api/app/clients/memory/summaryBuffer.demo.js
index 73f4182710..fc575c3032 100644
--- a/api/app/clients/memory/summaryBuffer.demo.js
+++ b/api/app/clients/memory/summaryBuffer.demo.js
@@ -3,7 +3,7 @@ const { ChatOpenAI } = require('@langchain/openai');
const { getBufferString, ConversationSummaryBufferMemory } = require('langchain/memory');
const chatPromptMemory = new ConversationSummaryBufferMemory({
- llm: new ChatOpenAI({ modelName: 'gpt-3.5-turbo', temperature: 0 }),
+ llm: new ChatOpenAI({ modelName: 'gpt-4o-mini', temperature: 0 }),
maxTokenLimit: 10,
returnMessages: true,
});
diff --git a/api/app/clients/prompts/formatMessages.js b/api/app/clients/prompts/formatMessages.js
index fff18fad32..d84e62cca8 100644
--- a/api/app/clients/prompts/formatMessages.js
+++ b/api/app/clients/prompts/formatMessages.js
@@ -204,7 +204,7 @@ const formatAgentMessages = (payload) => {
new ToolMessage({
tool_call_id: tool_call.id,
name: tool_call.name,
- content: output,
+ content: output || '',
}),
);
} else {
diff --git a/api/app/clients/specs/BaseClient.test.js b/api/app/clients/specs/BaseClient.test.js
index c62a5e2f18..4db1c9822a 100644
--- a/api/app/clients/specs/BaseClient.test.js
+++ b/api/app/clients/specs/BaseClient.test.js
@@ -61,7 +61,7 @@ describe('BaseClient', () => {
const options = {
// debug: true,
modelOptions: {
- model: 'gpt-3.5-turbo',
+ model: 'gpt-4o-mini',
temperature: 0,
},
};
diff --git a/api/app/clients/specs/OpenAIClient.test.js b/api/app/clients/specs/OpenAIClient.test.js
index 3021c1caf2..2fa37957d1 100644
--- a/api/app/clients/specs/OpenAIClient.test.js
+++ b/api/app/clients/specs/OpenAIClient.test.js
@@ -221,7 +221,7 @@ describe('OpenAIClient', () => {
it('should set isChatCompletion based on useOpenRouter, reverseProxyUrl, or model', () => {
client.setOptions({ reverseProxyUrl: null });
- // true by default since default model will be gpt-3.5-turbo
+ // true by default since default model will be gpt-4o-mini
expect(client.isChatCompletion).toBe(true);
client.isChatCompletion = undefined;
@@ -230,7 +230,7 @@ describe('OpenAIClient', () => {
expect(client.isChatCompletion).toBe(false);
client.isChatCompletion = undefined;
- client.setOptions({ modelOptions: { model: 'gpt-3.5-turbo' }, reverseProxyUrl: null });
+ client.setOptions({ modelOptions: { model: 'gpt-4o-mini' }, reverseProxyUrl: null });
expect(client.isChatCompletion).toBe(true);
});
diff --git a/api/app/clients/tools/structured/DALLE3.js b/api/app/clients/tools/structured/DALLE3.js
index 8cfeaf8416..b604ad4ea4 100644
--- a/api/app/clients/tools/structured/DALLE3.js
+++ b/api/app/clients/tools/structured/DALLE3.js
@@ -19,6 +19,8 @@ class DALLE3 extends Tool {
this.userId = fields.userId;
this.fileStrategy = fields.fileStrategy;
+ /** @type {boolean} */
+ this.isAgent = fields.isAgent;
if (fields.processFileURL) {
/** @type {processFileURL} Necessary for output to contain all image metadata. */
this.processFileURL = fields.processFileURL.bind(this);
@@ -108,6 +110,19 @@ class DALLE3 extends Tool {
return `![generated image](${imageUrl})`;
}
+ returnValue(value) {
+ if (this.isAgent === true && typeof value === 'string') {
+ return [value, {}];
+ } else if (this.isAgent === true && typeof value === 'object') {
+ return [
+ 'DALL-E displayed an image. All generated images are already plainly visible, so don\'t repeat the descriptions in detail. Do not list download links as they are available in the UI already. The user may download the images by clicking on them, but do not mention anything about downloading to the user.',
+ value,
+ ];
+ }
+
+ return value;
+ }
+
async _call(data) {
const { prompt, quality = 'standard', size = '1024x1024', style = 'vivid' } = data;
if (!prompt) {
@@ -126,18 +141,23 @@ class DALLE3 extends Tool {
});
} catch (error) {
logger.error('[DALL-E-3] Problem generating the image:', error);
- return `Something went wrong when trying to generate the image. The DALL-E API may be unavailable:
-Error Message: ${error.message}`;
+ return this
+ .returnValue(`Something went wrong when trying to generate the image. The DALL-E API may be unavailable:
+Error Message: ${error.message}`);
}
if (!resp) {
- return 'Something went wrong when trying to generate the image. The DALL-E API may be unavailable';
+ return this.returnValue(
+ 'Something went wrong when trying to generate the image. The DALL-E API may be unavailable',
+ );
}
const theImageUrl = resp.data[0].url;
if (!theImageUrl) {
- return 'No image URL returned from OpenAI API. There may be a problem with the API or your configuration.';
+ return this.returnValue(
+ 'No image URL returned from OpenAI API. There may be a problem with the API or your configuration.',
+ );
}
const imageBasename = getImageBasename(theImageUrl);
@@ -157,11 +177,11 @@ Error Message: ${error.message}`;
try {
const result = await this.processFileURL({
- fileStrategy: this.fileStrategy,
- userId: this.userId,
URL: theImageUrl,
- fileName: imageName,
basePath: 'images',
+ userId: this.userId,
+ fileName: imageName,
+ fileStrategy: this.fileStrategy,
context: FileContext.image_generation,
});
@@ -175,7 +195,7 @@ Error Message: ${error.message}`;
this.result = `Failed to save the image locally. ${error.message}`;
}
- return this.result;
+ return this.returnValue(this.result);
}
}
diff --git a/api/app/clients/tools/util/createFileSearchTool.js b/api/app/clients/tools/util/fileSearch.js
similarity index 61%
rename from api/app/clients/tools/util/createFileSearchTool.js
rename to api/app/clients/tools/util/fileSearch.js
index f00e4757f6..2d1010bd3b 100644
--- a/api/app/clients/tools/util/createFileSearchTool.js
+++ b/api/app/clients/tools/util/fileSearch.js
@@ -10,20 +10,50 @@ const { logger } = require('~/config');
* @param {Object} options
* @param {ServerRequest} options.req
* @param {Agent['tool_resources']} options.tool_resources
- * @returns
+ * @returns {Promise<{
+ * files: Array<{ file_id: string; filename: string }>,
+ * toolContext: string
+ * }>}
*/
-const createFileSearchTool = async (options) => {
- const { req, tool_resources } = options;
+const primeFiles = async (options) => {
+ const { tool_resources } = options;
const file_ids = tool_resources?.[EToolResources.file_search]?.file_ids ?? [];
- const files = (await getFiles({ file_id: { $in: file_ids } })).map((file) => ({
- file_id: file.file_id,
- filename: file.filename,
- }));
+ const agentResourceIds = new Set(file_ids);
+ const resourceFiles = tool_resources?.[EToolResources.file_search]?.files ?? [];
+ const dbFiles = ((await getFiles({ file_id: { $in: file_ids } })) ?? []).concat(resourceFiles);
+
+ let toolContext = `- Note: Semantic search is available through the ${Tools.file_search} tool but no files are currently loaded. Request the user to upload documents to search through.`;
+
+ const files = [];
+ for (let i = 0; i < dbFiles.length; i++) {
+ const file = dbFiles[i];
+ if (!file) {
+ continue;
+ }
+ if (i === 0) {
+ toolContext = `- Note: Use the ${Tools.file_search} tool to find relevant information within:`;
+ }
+ toolContext += `\n\t- ${file.filename}${
+ agentResourceIds.has(file.file_id) ? '' : ' (just attached by user)'
+ }`;
+ files.push({
+ file_id: file.file_id,
+ filename: file.filename,
+ });
+ }
- const fileList = files.map((file) => `- ${file.filename}`).join('\n');
- const toolDescription = `Performs a semantic search based on a natural language query across the following files:\n${fileList}`;
+ return { files, toolContext };
+};
- const FileSearch = tool(
+/**
+ *
+ * @param {Object} options
+ * @param {ServerRequest} options.req
+ * @param {Array<{ file_id: string; filename: string }>} options.files
+ * @returns
+ */
+const createFileSearchTool = async ({ req, files }) => {
+ return tool(
async ({ query }) => {
if (files.length === 0) {
return 'No files to search. Instruct the user to add files for the search.';
@@ -87,7 +117,7 @@ const createFileSearchTool = async (options) => {
},
{
name: Tools.file_search,
- description: toolDescription,
+ description: `Performs semantic search across attached "${Tools.file_search}" documents using natural language queries. This tool analyzes the content of uploaded files to find relevant information, quotes, and passages that best match your query. Use this to extract specific information or find relevant sections within the available documents.`,
schema: z.object({
query: z
.string()
@@ -97,8 +127,6 @@ const createFileSearchTool = async (options) => {
}),
},
);
-
- return FileSearch;
};
-module.exports = createFileSearchTool;
+module.exports = { createFileSearchTool, primeFiles };
diff --git a/api/app/clients/tools/util/handleTools.js b/api/app/clients/tools/util/handleTools.js
index bcfd4b3468..401bef4f52 100644
--- a/api/app/clients/tools/util/handleTools.js
+++ b/api/app/clients/tools/util/handleTools.js
@@ -15,8 +15,8 @@ const {
StructuredWolfram,
TavilySearchResults,
} = require('../');
-const { primeFiles } = require('~/server/services/Files/Code/process');
-const createFileSearchTool = require('./createFileSearchTool');
+const { primeFiles: primeCodeFiles } = require('~/server/services/Files/Code/process');
+const { createFileSearchTool, primeFiles: primeSearchFiles } = require('./fileSearch');
const { loadSpecs } = require('./loadSpecs');
const { logger } = require('~/config');
@@ -83,7 +83,7 @@ const validateTools = async (user, tools = []) => {
}
};
-const loadAuthValues = async ({ userId, authFields }) => {
+const loadAuthValues = async ({ userId, authFields, throwError = true }) => {
let authValues = {};
/**
@@ -98,7 +98,7 @@ const loadAuthValues = async ({ userId, authFields }) => {
return { authField: field, authValue: value };
}
try {
- value = await getUserPluginAuthValue(userId, field);
+ value = await getUserPluginAuthValue(userId, field, throwError);
} catch (err) {
if (field === fields[fields.length - 1] && !value) {
throw err;
@@ -122,15 +122,18 @@ const loadAuthValues = async ({ userId, authFields }) => {
return authValues;
};
+/** @typedef {typeof import('@langchain/core/tools').Tool} ToolConstructor */
+/** @typedef {import('@langchain/core/tools').Tool} Tool */
+
/**
* Initializes a tool with authentication values for the given user, supporting alternate authentication fields.
* Authentication fields can have alternates separated by "||", and the first defined variable will be used.
*
* @param {string} userId The user ID for which the tool is being loaded.
* @param {Array<string>} authFields Array of strings representing the authentication fields. Supports alternate fields delimited by "||".
- * @param {typeof import('langchain/tools').Tool} ToolConstructor The constructor function for the tool to be initialized.
+ * @param {ToolConstructor} ToolConstructor The constructor function for the tool to be initialized.
* @param {Object} options Optional parameters to be passed to the tool constructor alongside authentication values.
- * @returns {Function} An Async function that, when called, asynchronously initializes and returns an instance of the tool with authentication.
+ * @returns {() => Promise<Tool>} An Async function that, when called, asynchronously initializes and returns an instance of the tool with authentication.
*/
const loadToolWithAuth = (userId, authFields, ToolConstructor, options = {}) => {
return async function () {
@@ -142,11 +145,12 @@ const loadToolWithAuth = (userId, authFields, ToolConstructor, options = {}) =>
const loadTools = async ({
user,
model,
- functions = true,
- returnMap = false,
+ isAgent,
+ useSpecs,
tools = [],
options = {},
- skipSpecs = false,
+ functions = true,
+ returnMap = false,
}) => {
const toolConstructors = {
calculator: Calculator,
@@ -174,11 +178,12 @@ const loadTools = async ({
const requestedTools = {};
- if (functions) {
+ if (functions === true) {
toolConstructors.dalle = DALLE3;
}
const imageGenOptions = {
+ isAgent,
req: options.req,
fileStrategy: options.fileStrategy,
processFileURL: options.processFileURL,
@@ -189,7 +194,6 @@ const loadTools = async ({
const toolOptions = {
serpapi: { location: 'Austin,Texas,United States', hl: 'en', gl: 'us' },
dalle: imageGenOptions,
- 'dall-e': imageGenOptions,
'stable-diffusion': imageGenOptions,
};
@@ -203,24 +207,38 @@ const loadTools = async ({
toolAuthFields[tool.pluginKey] = tool.authConfig.map((auth) => auth.authField);
});
+ const toolContextMap = {};
const remainingTools = [];
for (const tool of tools) {
if (tool === Tools.execute_code) {
- const authValues = await loadAuthValues({
- userId: user,
- authFields: [EnvVar.CODE_API_KEY],
- });
- const files = await primeFiles(options, authValues[EnvVar.CODE_API_KEY]);
- requestedTools[tool] = () =>
- createCodeExecutionTool({
+ requestedTools[tool] = async () => {
+ const authValues = await loadAuthValues({
+ userId: user,
+ authFields: [EnvVar.CODE_API_KEY],
+ });
+ const codeApiKey = authValues[EnvVar.CODE_API_KEY];
+ const { files, toolContext } = await primeCodeFiles(options, codeApiKey);
+ if (toolContext) {
+ toolContextMap[tool] = toolContext;
+ }
+ const CodeExecutionTool = createCodeExecutionTool({
user_id: user,
files,
...authValues,
});
+ CodeExecutionTool.apiKey = codeApiKey;
+ return CodeExecutionTool;
+ };
continue;
} else if (tool === Tools.file_search) {
- requestedTools[tool] = () => createFileSearchTool(options);
+ requestedTools[tool] = async () => {
+ const { files, toolContext } = await primeSearchFiles(options);
+ if (toolContext) {
+ toolContextMap[tool] = toolContext;
+ }
+ return createFileSearchTool({ req: options.req, files });
+ };
continue;
}
@@ -241,13 +259,13 @@ const loadTools = async ({
continue;
}
- if (functions) {
+ if (functions === true) {
remainingTools.push(tool);
}
}
let specs = null;
- if (functions && remainingTools.length > 0 && skipSpecs !== true) {
+ if (useSpecs === true && functions === true && remainingTools.length > 0) {
specs = await loadSpecs({
llm: model,
user,
@@ -270,23 +288,21 @@ const loadTools = async ({
return requestedTools;
}
- // load tools
- let result = [];
+ const toolPromises = [];
for (const tool of tools) {
const validTool = requestedTools[tool];
- if (!validTool) {
- continue;
- }
- const plugin = await validTool();
-
- if (Array.isArray(plugin)) {
- result = [...result, ...plugin];
- } else if (plugin) {
- result.push(plugin);
+ if (validTool) {
+ toolPromises.push(
+ validTool().catch((error) => {
+ logger.error(`Error loading tool ${tool}:`, error);
+ return null;
+ }),
+ );
}
}
- return result;
+ const loadedTools = (await Promise.all(toolPromises)).flatMap((plugin) => plugin || []);
+ return { loadedTools, toolContextMap };
};
module.exports = {
diff --git a/api/app/clients/tools/util/handleTools.test.js b/api/app/clients/tools/util/handleTools.test.js
index 6d1c2a2e94..6538ce9aa4 100644
--- a/api/app/clients/tools/util/handleTools.test.js
+++ b/api/app/clients/tools/util/handleTools.test.js
@@ -128,12 +128,14 @@ describe('Tool Handlers', () => {
);
beforeAll(async () => {
- toolFunctions = await loadTools({
+ const toolMap = await loadTools({
user: fakeUser._id,
model: BaseLLM,
tools: sampleTools,
returnMap: true,
+ useSpecs: true,
});
+ toolFunctions = toolMap;
loadTool1 = toolFunctions[sampleTools[0]];
loadTool2 = toolFunctions[sampleTools[1]];
loadTool3 = toolFunctions[sampleTools[2]];
@@ -195,6 +197,7 @@ describe('Tool Handlers', () => {
expect(mockPluginService.getUserPluginAuthValue).toHaveBeenCalledWith(
'userId',
'DALLE3_API_KEY',
+ true,
);
});
@@ -224,6 +227,7 @@ describe('Tool Handlers', () => {
user: fakeUser._id,
model: BaseLLM,
returnMap: true,
+ useSpecs: true,
});
expect(toolFunctions).toEqual({});
});
@@ -235,6 +239,7 @@ describe('Tool Handlers', () => {
tools: ['stable-diffusion'],
functions: true,
returnMap: true,
+ useSpecs: true,
});
const structuredTool = await toolFunctions['stable-diffusion']();
expect(structuredTool).toBeInstanceOf(StructuredSD);
diff --git a/api/cache/getLogStores.js b/api/cache/getLogStores.js
index 1fdaee9006..273888f2f4 100644
--- a/api/cache/getLogStores.js
+++ b/api/cache/getLogStores.js
@@ -70,6 +70,7 @@ const namespaces = {
[ViolationTypes.TTS_LIMIT]: createViolationInstance(ViolationTypes.TTS_LIMIT),
[ViolationTypes.STT_LIMIT]: createViolationInstance(ViolationTypes.STT_LIMIT),
[ViolationTypes.CONVO_ACCESS]: createViolationInstance(ViolationTypes.CONVO_ACCESS),
+ [ViolationTypes.TOOL_CALL_LIMIT]: createViolationInstance(ViolationTypes.TOOL_CALL_LIMIT),
[ViolationTypes.FILE_UPLOAD_LIMIT]: createViolationInstance(ViolationTypes.FILE_UPLOAD_LIMIT),
[ViolationTypes.VERIFY_EMAIL_LIMIT]: createViolationInstance(ViolationTypes.VERIFY_EMAIL_LIMIT),
[ViolationTypes.RESET_PASSWORD_LIMIT]: createViolationInstance(
diff --git a/api/models/Agent.js b/api/models/Agent.js
index 7d599d3032..206c983f97 100644
--- a/api/models/Agent.js
+++ b/api/models/Agent.js
@@ -118,36 +118,43 @@ const addAgentResourceFile = async ({ agent_id, tool_resource, file_id }) => {
};
/**
- * Removes a resource file id from an agent.
+ * Removes multiple resource files from an agent in a single update.
* @param {object} params
- * @param {ServerRequest} params.req
* @param {string} params.agent_id
- * @param {string} params.tool_resource
- * @param {string} params.file_id
+ * @param {Array<{tool_resource: string, file_id: string}>} params.files
* @returns {Promise<Agent>} The updated agent.
*/
-const removeAgentResourceFile = async ({ agent_id, tool_resource, file_id }) => {
+const removeAgentResourceFiles = async ({ agent_id, files }) => {
const searchParameter = { id: agent_id };
const agent = await getAgent(searchParameter);
if (!agent) {
- throw new Error('Agent not found for removing resource file');
+ throw new Error('Agent not found for removing resource files');
}
- const tool_resources = agent.tool_resources || {};
-
- if (tool_resources[tool_resource] && tool_resources[tool_resource].file_ids) {
- tool_resources[tool_resource].file_ids = tool_resources[tool_resource].file_ids.filter(
- (id) => id !== file_id,
- );
+ const tool_resources = { ...agent.tool_resources } || {};
- if (tool_resources[tool_resource].file_ids.length === 0) {
- delete tool_resources[tool_resource];
+ const filesByResource = files.reduce((acc, { tool_resource, file_id }) => {
+ if (!acc[tool_resource]) {
+ acc[tool_resource] = new Set();
}
- }
+ acc[tool_resource].add(file_id);
+ return acc;
+ }, {});
+
+ Object.entries(filesByResource).forEach(([resource, fileIds]) => {
+ if (tool_resources[resource] && tool_resources[resource].file_ids) {
+ tool_resources[resource].file_ids = tool_resources[resource].file_ids.filter(
+ (id) => !fileIds.has(id),
+ );
+
+ if (tool_resources[resource].file_ids.length === 0) {
+ delete tool_resources[resource];
+ }
+ }
+ });
const updateData = { tool_resources };
-
return await updateAgent(searchParameter, updateData);
};
@@ -281,5 +288,5 @@ module.exports = {
getListAgents,
updateAgentProjects,
addAgentResourceFile,
- removeAgentResourceFile,
+ removeAgentResourceFiles,
};
diff --git a/api/models/Conversation.js b/api/models/Conversation.js
index 0850ed0a71..8231f4548f 100644
--- a/api/models/Conversation.js
+++ b/api/models/Conversation.js
@@ -15,6 +15,19 @@ const searchConversation = async (conversationId) => {
throw new Error('Error searching conversation');
}
};
+/**
+ * Searches for a conversation by conversationId and returns associated file ids.
+ * @param {string} conversationId - The conversation's ID.
+ * @returns {Promise<string[] | null>}
+ */
+const getConvoFiles = async (conversationId) => {
+ try {
+ return (await Conversation.findOne({ conversationId }, 'files').lean())?.files ?? [];
+ } catch (error) {
+ logger.error('[getConvoFiles] Error getting conversation files', error);
+ throw new Error('Error getting conversation files');
+ }
+};
/**
* Retrieves a single conversation for a given user and conversation ID.
@@ -62,6 +75,7 @@ const deleteNullOrEmptyConversations = async () => {
module.exports = {
Conversation,
+ getConvoFiles,
searchConversation,
deleteNullOrEmptyConversations,
/**
@@ -82,6 +96,7 @@ module.exports = {
update.conversationId = newConversationId;
}
+ /** Note: the resulting Model object is necessary for Meilisearch operations */
const conversation = await Conversation.findOneAndUpdate(
{ conversationId, user: req.user.id },
update,
diff --git a/api/models/Message.js b/api/models/Message.js
index 0d807f6bfd..f8f4fa7bc4 100644
--- a/api/models/Message.js
+++ b/api/models/Message.js
@@ -265,6 +265,26 @@ async function getMessages(filter, select) {
}
}
+/**
+ * Retrieves a single message from the database.
+ * @async
+ * @function getMessage
+ * @param {{ user: string, messageId: string }} params - The search parameters
+ * @returns {Promise<TMessage | null>} The message that matches the criteria or null if not found
+ * @throws {Error} If there is an error in retrieving the message
+ */
+async function getMessage({ user, messageId }) {
+ try {
+ return await Message.findOne({
+ user,
+ messageId,
+ }).lean();
+ } catch (err) {
+ logger.error('Error getting message:', err);
+ throw err;
+ }
+}
+
/**
* Deletes messages from the database.
*
@@ -292,5 +312,6 @@ module.exports = {
updateMessage,
deleteMessagesSince,
getMessages,
+ getMessage,
deleteMessages,
};
diff --git a/api/models/ToolCall.js b/api/models/ToolCall.js
new file mode 100644
index 0000000000..e1d7b0cc84
--- /dev/null
+++ b/api/models/ToolCall.js
@@ -0,0 +1,96 @@
+const ToolCall = require('./schema/toolCallSchema');
+
+/**
+ * Create a new tool call
+ * @param {ToolCallData} toolCallData - The tool call data
+ * @returns {Promise<ToolCallData>} The created tool call document
+ */
+async function createToolCall(toolCallData) {
+ try {
+ return await ToolCall.create(toolCallData);
+ } catch (error) {
+ throw new Error(`Error creating tool call: ${error.message}`);
+ }
+}
+
+/**
+ * Get a tool call by ID
+ * @param {string} id - The tool call document ID
+ * @returns {Promise<ToolCallData|null>} The tool call document or null if not found
+ */
+async function getToolCallById(id) {
+ try {
+ return await ToolCall.findById(id).lean();
+ } catch (error) {
+ throw new Error(`Error fetching tool call: ${error.message}`);
+ }
+}
+
+/**
+ * Get tool calls by message ID and user
+ * @param {string} messageId - The message ID
+ * @param {string} userId - The user's ObjectId
+ * @returns {Promise<Array>} Array of tool call documents
+ */
+async function getToolCallsByMessage(messageId, userId) {
+ try {
+ return await ToolCall.find({ messageId, user: userId }).lean();
+ } catch (error) {
+ throw new Error(`Error fetching tool calls: ${error.message}`);
+ }
+}
+
+/**
+ * Get tool calls by conversation ID and user
+ * @param {string} conversationId - The conversation ID
+ * @param {string} userId - The user's ObjectId
+ * @returns {Promise<ToolCallData[]>} Array of tool call documents
+ */
+async function getToolCallsByConvo(conversationId, userId) {
+ try {
+ return await ToolCall.find({ conversationId, user: userId }).lean();
+ } catch (error) {
+ throw new Error(`Error fetching tool calls: ${error.message}`);
+ }
+}
+
+/**
+ * Update a tool call
+ * @param {string} id - The tool call document ID
+ * @param {Partial<ToolCallData>} updateData - The data to update
+ * @returns {Promise<ToolCallData|null>} The updated tool call document or null if not found
+ */
+async function updateToolCall(id, updateData) {
+ try {
+ return await ToolCall.findByIdAndUpdate(id, updateData, { new: true }).lean();
+ } catch (error) {
+ throw new Error(`Error updating tool call: ${error.message}`);
+ }
+}
+
+/**
+ * Delete a tool call
+ * @param {string} userId - The related user's ObjectId
+ * @param {string} [conversationId] - The tool call conversation ID
+ * @returns {Promise<{ ok?: number; n?: number; deletedCount?: number }>} The result of the delete operation
+ */
+async function deleteToolCalls(userId, conversationId) {
+ try {
+ const query = { user: userId };
+ if (conversationId) {
+ query.conversationId = conversationId;
+ }
+ return await ToolCall.deleteMany(query);
+ } catch (error) {
+ throw new Error(`Error deleting tool call: ${error.message}`);
+ }
+}
+
+module.exports = {
+ createToolCall,
+ updateToolCall,
+ deleteToolCalls,
+ getToolCallById,
+ getToolCallsByConvo,
+ getToolCallsByMessage,
+};
diff --git a/api/models/index.js b/api/models/index.js
index 380c93cc42..73fc2f4ab9 100644
--- a/api/models/index.js
+++ b/api/models/index.js
@@ -18,6 +18,7 @@ const {
updateFileUsage,
} = require('./File');
const {
+ getMessage,
getMessages,
saveMessage,
recordMessage,
@@ -51,6 +52,7 @@ module.exports = {
getFiles,
updateFileUsage,
+ getMessage,
getMessages,
saveMessage,
recordMessage,
diff --git a/api/models/schema/agent.js b/api/models/schema/agent.js
index d7c5762b53..2006859ab6 100644
--- a/api/models/schema/agent.js
+++ b/api/models/schema/agent.js
@@ -58,6 +58,15 @@ const agentSchema = mongoose.Schema(
type: String,
default: undefined,
},
+ hide_sequential_outputs: {
+ type: Boolean,
+ },
+ end_after_tools: {
+ type: Boolean,
+ },
+ agent_ids: {
+ type: [String],
+ },
isCollaborative: {
type: Boolean,
default: undefined,
diff --git a/api/models/schema/convoSchema.js b/api/models/schema/convoSchema.js
index 7b020e3309..85232ed6a2 100644
--- a/api/models/schema/convoSchema.js
+++ b/api/models/schema/convoSchema.js
@@ -26,6 +26,9 @@ const convoSchema = mongoose.Schema(
type: mongoose.Schema.Types.Mixed,
},
...conversationPreset,
+ agent_id: {
+ type: String,
+ },
// for bingAI only
bingConversationId: {
type: String,
@@ -47,6 +50,9 @@ const convoSchema = mongoose.Schema(
default: [],
meiliIndex: true,
},
+ files: {
+ type: [String],
+ },
},
{ timestamps: true },
);
diff --git a/api/models/schema/defaults.js b/api/models/schema/defaults.js
index 6dced3af86..7898482359 100644
--- a/api/models/schema/defaults.js
+++ b/api/models/schema/defaults.js
@@ -93,6 +93,10 @@ const conversationPreset = {
imageDetail: {
type: String,
},
+ /* agents */
+ agent_id: {
+ type: String,
+ },
/* assistants */
assistant_id: {
type: String,
diff --git a/api/models/schema/toolCallSchema.js b/api/models/schema/toolCallSchema.js
new file mode 100644
index 0000000000..2af4c67c1b
--- /dev/null
+++ b/api/models/schema/toolCallSchema.js
@@ -0,0 +1,54 @@
+const mongoose = require('mongoose');
+
+/**
+ * @typedef {Object} ToolCallData
+ * @property {string} conversationId - The ID of the conversation
+ * @property {string} messageId - The ID of the message
+ * @property {string} toolId - The ID of the tool
+ * @property {string | ObjectId} user - The user's ObjectId
+ * @property {unknown} [result] - Optional result data
+ * @property {TAttachment[]} [attachments] - Optional attachments data
+ * @property {number} [blockIndex] - Optional code block index
+ * @property {number} [partIndex] - Optional part index
+ */
+
+/** @type {MongooseSchema<ToolCallData>} */
+const toolCallSchema = mongoose.Schema(
+ {
+ conversationId: {
+ type: String,
+ required: true,
+ },
+ messageId: {
+ type: String,
+ required: true,
+ },
+ toolId: {
+ type: String,
+ required: true,
+ },
+ user: {
+ type: mongoose.Schema.Types.ObjectId,
+ ref: 'User',
+ required: true,
+ },
+ result: {
+ type: mongoose.Schema.Types.Mixed,
+ },
+ attachments: {
+ type: mongoose.Schema.Types.Mixed,
+ },
+ blockIndex: {
+ type: Number,
+ },
+ partIndex: {
+ type: Number,
+ },
+ },
+ { timestamps: true },
+);
+
+toolCallSchema.index({ messageId: 1, user: 1 });
+toolCallSchema.index({ conversationId: 1, user: 1 });
+
+module.exports = mongoose.model('ToolCall', toolCallSchema);
diff --git a/api/package.json b/api/package.json
index d0377d6e0c..9184037fdf 100644
--- a/api/package.json
+++ b/api/package.json
@@ -39,12 +39,12 @@
"@google/generative-ai": "^0.21.0",
"@keyv/mongo": "^2.1.8",
"@keyv/redis": "^2.8.1",
- "@langchain/community": "^0.3.13",
- "@langchain/core": "^0.3.17",
+ "@langchain/community": "^0.3.14",
+ "@langchain/core": "^0.3.18",
"@langchain/google-genai": "^0.1.4",
"@langchain/google-vertexai": "^0.1.2",
"@langchain/textsplitters": "^0.1.0",
- "@librechat/agents": "^1.7.7",
+ "@librechat/agents": "^1.8.5",
"axios": "^1.7.7",
"bcryptjs": "^2.4.3",
"cheerio": "^1.0.0-rc.12",
diff --git a/api/server/controllers/AskController.js b/api/server/controllers/AskController.js
index d2d774b009..6534d6b3b3 100644
--- a/api/server/controllers/AskController.js
+++ b/api/server/controllers/AskController.js
@@ -127,6 +127,7 @@ const AskController = async (req, res, next, initializeClient, addTitle) => {
},
};
+ /** @type {TMessage} */
let response = await client.sendMessage(text, messageOptions);
response.endpoint = endpointOption.endpoint;
@@ -150,11 +151,13 @@ const AskController = async (req, res, next, initializeClient, addTitle) => {
});
res.end();
- await saveMessage(
- req,
- { ...response, user },
- { context: 'api/server/controllers/AskController.js - response end' },
- );
+ if (!client.savedMessageIds.has(response.messageId)) {
+ await saveMessage(
+ req,
+ { ...response, user },
+ { context: 'api/server/controllers/AskController.js - response end' },
+ );
+ }
}
if (!client.skipSaveUserMessage) {
diff --git a/api/server/controllers/UserController.js b/api/server/controllers/UserController.js
index f9ed887b15..9e01da38e5 100644
--- a/api/server/controllers/UserController.js
+++ b/api/server/controllers/UserController.js
@@ -14,6 +14,7 @@ const { updateUserPluginsService, deleteUserKey } = require('~/server/services/U
const { verifyEmail, resendVerificationEmail } = require('~/server/services/AuthService');
const { processDeleteRequest } = require('~/server/services/Files/process');
const { deleteAllSharedLinks } = require('~/models/Share');
+const { deleteToolCalls } = require('~/models/ToolCall');
const { Transaction } = require('~/models/Transaction');
const { logger } = require('~/config');
@@ -123,6 +124,7 @@ const deleteUserController = async (req, res) => {
await deleteAllSharedLinks(user.id); // delete user shared links
await deleteUserFiles(req); // delete user files
await deleteFiles(null, user.id); // delete database files in case of orphaned files from previous steps
+ await deleteToolCalls(user.id); // delete user tool calls
/* TODO: queue job for cleaning actions and assistants of non-existant users */
logger.info(`User deleted account. Email: ${user.email} ID: ${user.id}`);
res.status(200).send({ message: 'User deleted' });
diff --git a/api/server/controllers/agents/callbacks.js b/api/server/controllers/agents/callbacks.js
index 209de71714..08fceeb3c8 100644
--- a/api/server/controllers/agents/callbacks.js
+++ b/api/server/controllers/agents/callbacks.js
@@ -1,4 +1,4 @@
-const { Tools } = require('librechat-data-provider');
+const { Tools, StepTypes, imageGenTools } = require('librechat-data-provider');
const {
EnvVar,
GraphEvents,
@@ -57,6 +57,9 @@ class ModelEndHandler {
}
const usage = data?.output?.usage_metadata;
+ if (metadata?.model) {
+ usage.model = metadata.model;
+ }
if (usage) {
this.collectedUsage.push(usage);
@@ -89,9 +92,27 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
* Handle ON_RUN_STEP event.
* @param {string} event - The event name.
* @param {StreamEventData} data - The event data.
+ * @param {GraphRunnableConfig['configurable']} [metadata] The runnable metadata.
*/
- handle: (event, data) => {
- sendEvent(res, { event, data });
+ handle: (event, data, metadata) => {
+ if (data?.stepDetails.type === StepTypes.TOOL_CALLS) {
+ sendEvent(res, { event, data });
+ } else if (metadata?.last_agent_index === metadata?.agent_index) {
+ sendEvent(res, { event, data });
+ } else if (!metadata?.hide_sequential_outputs) {
+ sendEvent(res, { event, data });
+ } else {
+ const agentName = metadata?.name ?? 'Agent';
+ const isToolCall = data?.stepDetails.type === StepTypes.TOOL_CALLS;
+ const action = isToolCall ? 'performing a task...' : 'thinking...';
+ sendEvent(res, {
+ event: 'on_agent_update',
+ data: {
+ runId: metadata?.run_id,
+ message: `${agentName} is ${action}`,
+ },
+ });
+ }
aggregateContent({ event, data });
},
},
@@ -100,9 +121,16 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
* Handle ON_RUN_STEP_DELTA event.
* @param {string} event - The event name.
* @param {StreamEventData} data - The event data.
+ * @param {GraphRunnableConfig['configurable']} [metadata] The runnable metadata.
*/
- handle: (event, data) => {
- sendEvent(res, { event, data });
+ handle: (event, data, metadata) => {
+ if (data?.delta.type === StepTypes.TOOL_CALLS) {
+ sendEvent(res, { event, data });
+ } else if (metadata?.last_agent_index === metadata?.agent_index) {
+ sendEvent(res, { event, data });
+ } else if (!metadata?.hide_sequential_outputs) {
+ sendEvent(res, { event, data });
+ }
aggregateContent({ event, data });
},
},
@@ -111,9 +139,16 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
* Handle ON_RUN_STEP_COMPLETED event.
* @param {string} event - The event name.
* @param {StreamEventData & { result: ToolEndData }} data - The event data.
+ * @param {GraphRunnableConfig['configurable']} [metadata] The runnable metadata.
*/
- handle: (event, data) => {
- sendEvent(res, { event, data });
+ handle: (event, data, metadata) => {
+ if (data?.result != null) {
+ sendEvent(res, { event, data });
+ } else if (metadata?.last_agent_index === metadata?.agent_index) {
+ sendEvent(res, { event, data });
+ } else if (!metadata?.hide_sequential_outputs) {
+ sendEvent(res, { event, data });
+ }
aggregateContent({ event, data });
},
},
@@ -122,9 +157,14 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
* Handle ON_MESSAGE_DELTA event.
* @param {string} event - The event name.
* @param {StreamEventData} data - The event data.
+ * @param {GraphRunnableConfig['configurable']} [metadata] The runnable metadata.
*/
- handle: (event, data) => {
- sendEvent(res, { event, data });
+ handle: (event, data, metadata) => {
+ if (metadata?.last_agent_index === metadata?.agent_index) {
+ sendEvent(res, { event, data });
+ } else if (!metadata?.hide_sequential_outputs) {
+ sendEvent(res, { event, data });
+ }
aggregateContent({ event, data });
},
},
@@ -151,16 +191,41 @@ function createToolEndCallback({ req, res, artifactPromises }) {
return;
}
+ if (imageGenTools.has(output.name) && output.artifact) {
+ artifactPromises.push(
+ (async () => {
+ const fileMetadata = Object.assign(output.artifact, {
+ messageId: metadata.run_id,
+ toolCallId: output.tool_call_id,
+ conversationId: metadata.thread_id,
+ });
+ if (!res.headersSent) {
+ return fileMetadata;
+ }
+
+ if (!fileMetadata) {
+ return null;
+ }
+
+ res.write(`event: attachment\ndata: ${JSON.stringify(fileMetadata)}\n\n`);
+ return fileMetadata;
+ })().catch((error) => {
+ logger.error('Error processing code output:', error);
+ return null;
+ }),
+ );
+ return;
+ }
+
if (output.name !== Tools.execute_code) {
return;
}
- const { tool_call_id, artifact } = output;
- if (!artifact.files) {
+ if (!output.artifact.files) {
return;
}
- for (const file of artifact.files) {
+ for (const file of output.artifact.files) {
const { id, name } = file;
artifactPromises.push(
(async () => {
@@ -173,10 +238,10 @@ function createToolEndCallback({ req, res, artifactPromises }) {
id,
name,
apiKey: result[EnvVar.CODE_API_KEY],
- toolCallId: tool_call_id,
messageId: metadata.run_id,
- session_id: artifact.session_id,
+ toolCallId: output.tool_call_id,
conversationId: metadata.thread_id,
+ session_id: output.artifact.session_id,
});
if (!res.headersSent) {
return fileMetadata;
diff --git a/api/server/controllers/agents/client.js b/api/server/controllers/agents/client.js
index 277d545baa..450accb8ae 100644
--- a/api/server/controllers/agents/client.js
+++ b/api/server/controllers/agents/client.js
@@ -12,9 +12,11 @@ const {
Constants,
VisionModes,
openAISchema,
+ ContentTypes,
EModelEndpoint,
KnownEndpoints,
anthropicSchema,
+ isAgentsEndpoint,
bedrockOutputParser,
removeNullishValues,
} = require('librechat-data-provider');
@@ -30,10 +32,10 @@ const {
createContextHandlers,
} = require('~/app/clients/prompts');
const { encodeAndFormat } = require('~/server/services/Files/images/encode');
+const { getBufferString, HumanMessage } = require('@langchain/core/messages');
const Tokenizer = require('~/server/services/Tokenizer');
const { spendTokens } = require('~/models/spendTokens');
const BaseClient = require('~/app/clients/BaseClient');
-// const { sleep } = require('~/server/utils');
const { createRun } = require('./run');
const { logger } = require('~/config');
@@ -48,6 +50,12 @@ const providerParsers = {
const legacyContentEndpoints = new Set([KnownEndpoints.groq, KnownEndpoints.deepseek]);
+const noSystemModelRegex = [/\bo1\b/gi];
+
+// const { processMemory, memoryInstructions } = require('~/server/services/Endpoints/agents/memory');
+// const { getFormattedMemories } = require('~/models/Memory');
+// const { getCurrentDateTime } = require('~/utils');
+
class AgentClient extends BaseClient {
constructor(options = {}) {
super(null, options);
@@ -62,15 +70,15 @@ class AgentClient extends BaseClient {
this.run;
const {
+ agentConfigs,
contentParts,
collectedUsage,
artifactPromises,
maxContextTokens,
- modelOptions = {},
...clientOptions
} = options;
- this.modelOptions = modelOptions;
+ this.agentConfigs = agentConfigs;
this.maxContextTokens = maxContextTokens;
/** @type {MessageContentComplex[]} */
this.contentParts = contentParts;
@@ -80,6 +88,8 @@ class AgentClient extends BaseClient {
this.artifactPromises = artifactPromises;
/** @type {AgentClientOptions} */
this.options = Object.assign({ endpoint: options.endpoint }, clientOptions);
+ /** @type {string} */
+ this.model = this.options.agent.model_parameters.model;
}
/**
@@ -169,7 +179,7 @@ class AgentClient extends BaseClient {
: {};
if (parseOptions) {
- runOptions = parseOptions(this.modelOptions);
+ runOptions = parseOptions(this.options.agent.model_parameters);
}
return removeNullishValues(
@@ -224,7 +234,28 @@ class AgentClient extends BaseClient {
let promptTokens;
/** @type {string} */
- let systemContent = `${instructions ?? ''}${additional_instructions ?? ''}`;
+ let systemContent = [instructions ?? '', additional_instructions ?? '']
+ .filter(Boolean)
+ .join('\n')
+ .trim();
+ // this.systemMessage = getCurrentDateTime();
+ // const { withKeys, withoutKeys } = await getFormattedMemories({
+ // userId: this.options.req.user.id,
+ // });
+ // processMemory({
+ // userId: this.options.req.user.id,
+ // message: this.options.req.body.text,
+ // parentMessageId,
+ // memory: withKeys,
+ // thread_id: this.conversationId,
+ // }).catch((error) => {
+ // logger.error('Memory Agent failed to process memory', error);
+ // });
+
+ // this.systemMessage += '\n\n' + memoryInstructions;
+ // if (withoutKeys) {
+ // this.systemMessage += `\n\n# Existing memory about the user:\n${withoutKeys}`;
+ // }
if (this.options.attachments) {
const attachments = await this.options.attachments;
@@ -245,7 +276,8 @@ class AgentClient extends BaseClient {
this.options.attachments = files;
}
- if (this.message_file_map) {
+ /** Note: Bedrock uses legacy RAG API handling */
+ if (this.message_file_map && !isAgentsEndpoint(this.options.endpoint)) {
this.contextHandlers = createContextHandlers(
this.options.req,
orderedMessages[orderedMessages.length - 1].text,
@@ -319,7 +351,6 @@ class AgentClient extends BaseClient {
/** @type {sendCompletion} */
async sendCompletion(payload, opts = {}) {
- this.modelOptions.user = this.user;
await this.chatCompletion({
payload,
onProgress: opts.onProgress,
@@ -339,10 +370,10 @@ class AgentClient extends BaseClient {
await spendTokens(
{
context,
- model: model ?? this.modelOptions.model,
conversationId: this.conversationId,
user: this.user ?? this.options.req.user?.id,
endpointTokenConfig: this.options.endpointTokenConfig,
+ model: usage.model ?? model ?? this.model ?? this.options.agent.model_parameters.model,
},
{ promptTokens: usage.input_tokens, completionTokens: usage.output_tokens },
);
@@ -457,43 +488,190 @@ class AgentClient extends BaseClient {
// });
// }
- const run = await createRun({
- req: this.options.req,
- agent: this.options.agent,
- tools: this.options.tools,
- runId: this.responseMessageId,
- modelOptions: this.modelOptions,
- customHandlers: this.options.eventHandlers,
- });
-
const config = {
configurable: {
thread_id: this.conversationId,
+ last_agent_index: this.agentConfigs?.size ?? 0,
+ hide_sequential_outputs: this.options.agent.hide_sequential_outputs,
},
signal: abortController.signal,
streamMode: 'values',
version: 'v2',
};
- if (!run) {
- throw new Error('Failed to create run');
+ const initialMessages = formatAgentMessages(payload);
+ if (legacyContentEndpoints.has(this.options.agent.endpoint)) {
+ formatContentStrings(initialMessages);
}
- this.run = run;
+ /** @type {ReturnType<createRun>} */
+ let run;
+
+ /**
+ *
+ * @param {Agent} agent
+ * @param {BaseMessage[]} messages
+ * @param {number} [i]
+ * @param {TMessageContentParts[]} [contentData]
+ */
+ const runAgent = async (agent, messages, i = 0, contentData = []) => {
+ config.configurable.model = agent.model_parameters.model;
+ if (i > 0) {
+ this.model = agent.model_parameters.model;
+ }
+ config.configurable.agent_id = agent.id;
+ config.configurable.name = agent.name;
+ config.configurable.agent_index = i;
+ const noSystemMessages = noSystemModelRegex.some((regex) =>
+ agent.model_parameters.model.match(regex),
+ );
- const messages = formatAgentMessages(payload);
- if (legacyContentEndpoints.has(this.options.agent.endpoint)) {
- formatContentStrings(messages);
+ const systemMessage = Object.values(agent.toolContextMap ?? {})
+ .join('\n')
+ .trim();
+
+ let systemContent = [
+ systemMessage,
+ agent.instructions ?? '',
+ i !== 0 ? agent.additional_instructions ?? '' : '',
+ ]
+ .join('\n')
+ .trim();
+
+ if (noSystemMessages === true) {
+ agent.instructions = undefined;
+ agent.additional_instructions = undefined;
+ } else {
+ agent.instructions = systemContent;
+ agent.additional_instructions = undefined;
+ }
+
+ if (noSystemMessages === true && systemContent?.length) {
+ let latestMessage = messages.pop().content;
+ if (typeof latestMessage !== 'string') {
+ latestMessage = latestMessage[0].text;
+ }
+ latestMessage = [systemContent, latestMessage].join('\n');
+ messages.push(new HumanMessage(latestMessage));
+ }
+
+ run = await createRun({
+ agent,
+ req: this.options.req,
+ runId: this.responseMessageId,
+ signal: abortController.signal,
+ customHandlers: this.options.eventHandlers,
+ });
+
+ if (!run) {
+ throw new Error('Failed to create run');
+ }
+
+ if (i === 0) {
+ this.run = run;
+ }
+
+ if (contentData.length) {
+ run.Graph.contentData = contentData;
+ }
+
+ await run.processStream({ messages }, config, {
+ keepContent: i !== 0,
+ callbacks: {
+ [Callback.TOOL_ERROR]: (graph, error, toolId) => {
+ logger.error(
+ '[api/server/controllers/agents/client.js #chatCompletion] Tool Error',
+ error,
+ toolId,
+ );
+ },
+ },
+ });
+ };
+
+ await runAgent(this.options.agent, initialMessages);
+
+ let finalContentStart = 0;
+ if (this.agentConfigs && this.agentConfigs.size > 0) {
+ let latestMessage = initialMessages.pop().content;
+ if (typeof latestMessage !== 'string') {
+ latestMessage = latestMessage[0].text;
+ }
+ let i = 1;
+ let runMessages = [];
+
+ const lastFiveMessages = initialMessages.slice(-5);
+ for (const [agentId, agent] of this.agentConfigs) {
+ if (abortController.signal.aborted === true) {
+ break;
+ }
+ const currentRun = await run;
+
+ if (
+ i === this.agentConfigs.size &&
+ config.configurable.hide_sequential_outputs === true
+ ) {
+ const content = this.contentParts.filter(
+ (part) => part.type === ContentTypes.TOOL_CALL,
+ );
+
+ this.options.res.write(
+ `event: message\ndata: ${JSON.stringify({
+ event: 'on_content_update',
+ data: {
+ runId: this.responseMessageId,
+ content,
+ },
+ })}\n\n`,
+ );
+ }
+ const _runMessages = currentRun.Graph.getRunMessages();
+ finalContentStart = this.contentParts.length;
+ runMessages = runMessages.concat(_runMessages);
+ const contentData = currentRun.Graph.contentData.slice();
+ const bufferString = getBufferString([new HumanMessage(latestMessage), ...runMessages]);
+ if (i === this.agentConfigs.size) {
+ logger.debug(`SEQUENTIAL AGENTS: Last buffer string:\n${bufferString}`);
+ }
+ try {
+ const contextMessages = [];
+ for (const message of lastFiveMessages) {
+ const messageType = message._getType();
+ if (
+ (!agent.tools || agent.tools.length === 0) &&
+ (messageType === 'tool' || (message.tool_calls?.length ?? 0) > 0)
+ ) {
+ continue;
+ }
+
+ contextMessages.push(message);
+ }
+ const currentMessages = [...contextMessages, new HumanMessage(bufferString)];
+ await runAgent(agent, currentMessages, i, contentData);
+ } catch (err) {
+ logger.error(
+ `[api/server/controllers/agents/client.js #chatCompletion] Error running agent ${agentId} (${i})`,
+ err,
+ );
+ }
+ i++;
+ }
}
- await run.processStream({ messages }, config, {
- [Callback.TOOL_ERROR]: (graph, error, toolId) => {
- logger.error(
- '[api/server/controllers/agents/client.js #chatCompletion] Tool Error',
- error,
- toolId,
- );
- },
+
+ if (config.configurable.hide_sequential_outputs !== true) {
+ finalContentStart = 0;
+ }
+
+ this.contentParts = this.contentParts.filter((part, index) => {
+ // Include parts that are either:
+ // 1. At or after the finalContentStart index
+ // 2. Of type tool_call
+ // 3. Have tool_call_ids property
+ return (
+ index >= finalContentStart || part.type === ContentTypes.TOOL_CALL || part.tool_call_ids
+ );
});
+
this.recordCollectedUsage({ context: 'message' }).catch((err) => {
logger.error(
'[api/server/controllers/agents/client.js #chatCompletion] Error recording collected usage',
@@ -586,7 +764,7 @@ class AgentClient extends BaseClient {
}
getEncoding() {
- return this.modelOptions.model?.includes('gpt-4o') ? 'o200k_base' : 'cl100k_base';
+ return this.model?.includes('gpt-4o') ? 'o200k_base' : 'cl100k_base';
}
/**
diff --git a/api/server/controllers/agents/request.js b/api/server/controllers/agents/request.js
index 2006d4e6ea..8ceadd977d 100644
--- a/api/server/controllers/agents/request.js
+++ b/api/server/controllers/agents/request.js
@@ -94,8 +94,14 @@ const AgentController = async (req, res, next, initializeClient, addTitle) => {
conversation.title =
conversation && !conversation.title ? null : conversation?.title || 'New Chat';
- if (client.options.attachments) {
- userMessage.files = client.options.attachments;
+ if (req.body.files && client.options.attachments) {
+ userMessage.files = [];
+ const messageFiles = new Set(req.body.files.map((file) => file.file_id));
+ for (let attachment of client.options.attachments) {
+ if (messageFiles.has(attachment.file_id)) {
+ userMessage.files.push(attachment);
+ }
+ }
delete userMessage.image_urls;
}
@@ -109,11 +115,13 @@ const AgentController = async (req, res, next, initializeClient, addTitle) => {
});
res.end();
- await saveMessage(
- req,
- { ...response, user },
- { context: 'api/server/controllers/agents/request.js - response end' },
- );
+ if (!client.savedMessageIds.has(response.messageId)) {
+ await saveMessage(
+ req,
+ { ...response, user },
+ { context: 'api/server/controllers/agents/request.js - response end' },
+ );
+ }
}
if (!client.skipSaveUserMessage) {
diff --git a/api/server/controllers/agents/run.js b/api/server/controllers/agents/run.js
index 56cc46d5b3..db7f945ca2 100644
--- a/api/server/controllers/agents/run.js
+++ b/api/server/controllers/agents/run.js
@@ -3,8 +3,8 @@ const { providerEndpointMap } = require('librechat-data-provider');
/**
* @typedef {import('@librechat/agents').t} t
+ * @typedef {import('@librechat/agents').StandardGraphConfig} StandardGraphConfig
* @typedef {import('@librechat/agents').StreamEventData} StreamEventData
- * @typedef {import('@librechat/agents').ClientOptions} ClientOptions
* @typedef {import('@librechat/agents').EventHandler} EventHandler
* @typedef {import('@librechat/agents').GraphEvents} GraphEvents
* @typedef {import('@librechat/agents').IState} IState
@@ -17,18 +17,16 @@ const { providerEndpointMap } = require('librechat-data-provider');
* @param {ServerRequest} [options.req] - The server request.
* @param {string | undefined} [options.runId] - Optional run ID; otherwise, a new run ID will be generated.
* @param {Agent} options.agent - The agent for this run.
- * @param {StructuredTool[] | undefined} [options.tools] - The tools to use in the run.
+ * @param {AbortSignal} options.signal - The signal for this run.
* @param {Record<GraphEvents, EventHandler> | undefined} [options.customHandlers] - Custom event handlers.
- * @param {ClientOptions} [options.modelOptions] - Optional model to use; if not provided, it will use the default from modelMap.
* @param {boolean} [options.streaming=true] - Whether to use streaming.
* @param {boolean} [options.streamUsage=true] - Whether to stream usage information.
* @returns {Promise<Run<IState>>} A promise that resolves to a new Run instance.
*/
async function createRun({
runId,
- tools,
agent,
- modelOptions,
+ signal,
customHandlers,
streaming = true,
streamUsage = true,
@@ -40,14 +38,17 @@ async function createRun({
streaming,
streamUsage,
},
- modelOptions,
+ agent.model_parameters,
);
+ /** @type {StandardGraphConfig} */
const graphConfig = {
- tools,
+ signal,
llmConfig,
+ tools: agent.tools,
instructions: agent.instructions,
additional_instructions: agent.additional_instructions,
+ // toolEnd: agent.end_after_tools,
};
// TEMPORARY FOR TESTING
diff --git a/api/server/controllers/tools.js b/api/server/controllers/tools.js
index 9fd9cb2942..9460e66136 100644
--- a/api/server/controllers/tools.js
+++ b/api/server/controllers/tools.js
@@ -1,6 +1,12 @@
+const { nanoid } = require('nanoid');
const { EnvVar } = require('@librechat/agents');
-const { Tools, AuthType } = require('librechat-data-provider');
-const { loadAuthValues } = require('~/app/clients/tools/util');
+const { Tools, AuthType, ToolCallTypes } = require('librechat-data-provider');
+const { processFileURL, uploadImageBuffer } = require('~/server/services/Files/process');
+const { processCodeOutput } = require('~/server/services/Files/Code/process');
+const { loadAuthValues, loadTools } = require('~/app/clients/tools/util');
+const { createToolCall, getToolCallsByConvo } = require('~/models/ToolCall');
+const { getMessage } = require('~/models/Message');
+const { logger } = require('~/config');
const fieldsMap = {
[Tools.execute_code]: [EnvVar.CODE_API_KEY],
@@ -24,6 +30,7 @@ const verifyToolAuth = async (req, res) => {
result = await loadAuthValues({
userId: req.user.id,
authFields,
+ throwError: false,
});
} catch (error) {
res.status(200).json({ authenticated: false, message: AuthType.USER_PROVIDED });
@@ -48,6 +55,131 @@ const verifyToolAuth = async (req, res) => {
}
};
+/**
+ * @param {ServerRequest} req - The request object, containing information about the HTTP request.
+ * @param {ServerResponse} res - The response object, used to send back the desired HTTP response.
+ * @returns {Promise<void>} A promise that resolves when the function has completed.
+ */
+const callTool = async (req, res) => {
+ try {
+ const { toolId = '' } = req.params;
+ if (!fieldsMap[toolId]) {
+ logger.warn(`[${toolId}/call] User ${req.user.id} attempted call to invalid tool`);
+ res.status(404).json({ message: 'Tool not found' });
+ return;
+ }
+
+ const { partIndex, blockIndex, messageId, conversationId, ...args } = req.body;
+ if (!messageId) {
+ logger.warn(`[${toolId}/call] User ${req.user.id} attempted call without message ID`);
+ res.status(400).json({ message: 'Message ID required' });
+ return;
+ }
+
+ const message = await getMessage({ user: req.user.id, messageId });
+ if (!message) {
+ logger.debug(`[${toolId}/call] User ${req.user.id} attempted call with invalid message ID`);
+ res.status(404).json({ message: 'Message not found' });
+ return;
+ }
+ logger.debug(`[${toolId}/call] User: ${req.user.id}`);
+ const { loadedTools } = await loadTools({
+ user: req.user.id,
+ tools: [toolId],
+ functions: true,
+ options: {
+ req,
+ returnMetadata: true,
+ processFileURL,
+ uploadImageBuffer,
+ fileStrategy: req.app.locals.fileStrategy,
+ },
+ });
+
+ const tool = loadedTools[0];
+ const toolCallId = `${req.user.id}_${nanoid()}`;
+ const result = await tool.invoke({
+ args,
+ name: toolId,
+ id: toolCallId,
+ type: ToolCallTypes.TOOL_CALL,
+ });
+
+ const { content, artifact } = result;
+ const toolCallData = {
+ toolId,
+ messageId,
+ partIndex,
+ blockIndex,
+ conversationId,
+ result: content,
+ user: req.user.id,
+ };
+
+ if (!artifact || !artifact.files || toolId !== Tools.execute_code) {
+ createToolCall(toolCallData).catch((error) => {
+ logger.error(`Error creating tool call: ${error.message}`);
+ });
+ return res.status(200).json({
+ result: content,
+ });
+ }
+
+ const artifactPromises = [];
+ for (const file of artifact.files) {
+ const { id, name } = file;
+ artifactPromises.push(
+ (async () => {
+ const fileMetadata = await processCodeOutput({
+ req,
+ id,
+ name,
+ apiKey: tool.apiKey,
+ messageId,
+ toolCallId,
+ conversationId,
+ session_id: artifact.session_id,
+ });
+
+ if (!fileMetadata) {
+ return null;
+ }
+
+ return fileMetadata;
+ })().catch((error) => {
+ logger.error('Error processing code output:', error);
+ return null;
+ }),
+ );
+ }
+ const attachments = await Promise.all(artifactPromises);
+ toolCallData.attachments = attachments;
+ createToolCall(toolCallData).catch((error) => {
+ logger.error(`Error creating tool call: ${error.message}`);
+ });
+ res.status(200).json({
+ result: content,
+ attachments,
+ });
+ } catch (error) {
+ logger.error('Error calling tool', error);
+ res.status(500).json({ message: 'Error calling tool' });
+ }
+};
+
+const getToolCalls = async (req, res) => {
+ try {
+ const { conversationId } = req.query;
+ const toolCalls = await getToolCallsByConvo(conversationId, req.user.id);
+ res.status(200).json(toolCalls);
+ } catch (error) {
+ logger.error('Error getting tool calls', error);
+ res.status(500).json({ message: 'Error getting tool calls' });
+ }
+};
+
module.exports = {
+ callTool,
+ getToolCalls,
verifyToolAuth,
};
diff --git a/api/server/middleware/buildEndpointOption.js b/api/server/middleware/buildEndpointOption.js
index 25bb5a3c9c..139a0134d2 100644
--- a/api/server/middleware/buildEndpointOption.js
+++ b/api/server/middleware/buildEndpointOption.js
@@ -10,6 +10,7 @@ const openAI = require('~/server/services/Endpoints/openAI');
const agents = require('~/server/services/Endpoints/agents');
const custom = require('~/server/services/Endpoints/custom');
const google = require('~/server/services/Endpoints/google');
+const { getConvoFiles } = require('~/models/Conversation');
const { handleError } = require('~/server/utils');
const buildFunction = {
@@ -72,21 +73,32 @@ async function buildEndpointOption(req, res, next) {
}
}
- const endpointFn = buildFunction[endpointType ?? endpoint];
- const builder = isAgentsEndpoint(endpoint) ? (...args) => endpointFn(req, ...args) : endpointFn;
-
- // TODO: use object params
- req.body.endpointOption = builder(endpoint, parsedBody, endpointType);
+ try {
+ const isAgents = isAgentsEndpoint(endpoint);
+ const endpointFn = buildFunction[endpointType ?? endpoint];
+ const builder = isAgents ? (...args) => endpointFn(req, ...args) : endpointFn;
- // TODO: use `getModelsConfig` only when necessary
- const modelsConfig = await getModelsConfig(req);
- req.body.endpointOption.modelsConfig = modelsConfig;
+ // TODO: use object params
+ req.body.endpointOption = builder(endpoint, parsedBody, endpointType);
- if (req.body.files) {
- // hold the promise
- req.body.endpointOption.attachments = processFiles(req.body.files);
+ // TODO: use `getModelsConfig` only when necessary
+ const modelsConfig = await getModelsConfig(req);
+ const { resendFiles = true } = req.body.endpointOption;
+ req.body.endpointOption.modelsConfig = modelsConfig;
+ if (isAgents && resendFiles && req.body.conversationId) {
+ const fileIds = await getConvoFiles(req.body.conversationId);
+ const requestFiles = req.body.files ?? [];
+ if (requestFiles.length || fileIds.length) {
+ req.body.endpointOption.attachments = processFiles(requestFiles, fileIds);
+ }
+ } else if (req.body.files) {
+ // hold the promise
+ req.body.endpointOption.attachments = processFiles(req.body.files);
+ }
+ next();
+ } catch (error) {
+ return handleError(res, { text: 'Error building endpoint option' });
}
- next();
}
module.exports = buildEndpointOption;
diff --git a/api/server/middleware/limiters/index.js b/api/server/middleware/limiters/index.js
index 0ae6bb5c5e..d1c11e0a12 100644
--- a/api/server/middleware/limiters/index.js
+++ b/api/server/middleware/limiters/index.js
@@ -5,6 +5,7 @@ const loginLimiter = require('./loginLimiter');
const importLimiters = require('./importLimiters');
const uploadLimiters = require('./uploadLimiters');
const registerLimiter = require('./registerLimiter');
+const toolCallLimiter = require('./toolCallLimiter');
const messageLimiters = require('./messageLimiters');
const verifyEmailLimiter = require('./verifyEmailLimiter');
const resetPasswordLimiter = require('./resetPasswordLimiter');
@@ -15,6 +16,7 @@ module.exports = {
...messageLimiters,
loginLimiter,
registerLimiter,
+ toolCallLimiter,
createTTSLimiters,
createSTTLimiters,
verifyEmailLimiter,
diff --git a/api/server/middleware/limiters/toolCallLimiter.js b/api/server/middleware/limiters/toolCallLimiter.js
new file mode 100644
index 0000000000..47dcaeabb4
--- /dev/null
+++ b/api/server/middleware/limiters/toolCallLimiter.js
@@ -0,0 +1,25 @@
+const rateLimit = require('express-rate-limit');
+const { ViolationTypes } = require('librechat-data-provider');
+const logViolation = require('~/cache/logViolation');
+
+const toolCallLimiter = rateLimit({
+ windowMs: 1000,
+ max: 1,
+ handler: async (req, res) => {
+ const type = ViolationTypes.TOOL_CALL_LIMIT;
+ const errorMessage = {
+ type,
+ max: 1,
+ limiter: 'user',
+ windowInMinutes: 1,
+ };
+
+ await logViolation(req, res, type, errorMessage, 0);
+ res.status(429).json({ message: 'Too many tool call requests. Try again later' });
+ },
+ keyGenerator: function (req) {
+ return req.user?.id;
+ },
+});
+
+module.exports = toolCallLimiter;
diff --git a/api/server/routes/agents/chat.js b/api/server/routes/agents/chat.js
index 8302abcde0..fdb2db54d3 100644
--- a/api/server/routes/agents/chat.js
+++ b/api/server/routes/agents/chat.js
@@ -1,19 +1,23 @@
const express = require('express');
-
-const router = express.Router();
+const { PermissionTypes, Permissions } = require('librechat-data-provider');
const {
setHeaders,
handleAbort,
// validateModel,
- // validateEndpoint,
+ generateCheckAccess,
+ validateConvoAccess,
buildEndpointOption,
} = require('~/server/middleware');
const { initializeClient } = require('~/server/services/Endpoints/agents');
const AgentController = require('~/server/controllers/agents/request');
const addTitle = require('~/server/services/Endpoints/agents/title');
+const router = express.Router();
+
router.post('/abort', handleAbort());
+const checkAgentAccess = generateCheckAccess(PermissionTypes.AGENTS, [Permissions.USE]);
+
/**
* @route POST /
* @desc Chat with an assistant
@@ -25,7 +29,8 @@ router.post('/abort', handleAbort());
router.post(
'/',
// validateModel,
- // validateEndpoint,
+ checkAgentAccess,
+ validateConvoAccess,
buildEndpointOption,
setHeaders,
async (req, res, next) => {
diff --git a/api/server/routes/agents/tools.js b/api/server/routes/agents/tools.js
index b58fc21d4f..8e498b1db8 100644
--- a/api/server/routes/agents/tools.js
+++ b/api/server/routes/agents/tools.js
@@ -1,6 +1,7 @@
const express = require('express');
+const { callTool, verifyToolAuth, getToolCalls } = require('~/server/controllers/tools');
const { getAvailableTools } = require('~/server/controllers/PluginController');
-const { verifyToolAuth } = require('~/server/controllers/tools');
+const { toolCallLimiter } = require('~/server/middleware/limiters');
const router = express.Router();
@@ -11,6 +12,13 @@ const router = express.Router();
*/
router.get('/', getAvailableTools);
+/**
+ * Get a list of tool calls.
+ * @route GET /agents/tools/calls
+ * @returns {ToolCallData[]} 200 - application/json
+ */
+router.get('/calls', getToolCalls);
+
/**
* Verify authentication for a specific tool
* @route GET /agents/tools/:toolId/auth
@@ -19,4 +27,13 @@ router.get('/', getAvailableTools);
*/
router.get('/:toolId/auth', verifyToolAuth);
+/**
+ * Execute code for a specific tool
+ * @route POST /agents/tools/:toolId/call
+ * @param {string} toolId - The ID of the tool to execute
+ * @param {object} req.body - Request body
+ * @returns {object} Result of code execution
+ */
+router.post('/:toolId/call', toolCallLimiter, callTool);
+
module.exports = router;
diff --git a/api/server/routes/convos.js b/api/server/routes/convos.js
index d47e757fd8..0aec01b8ee 100644
--- a/api/server/routes/convos.js
+++ b/api/server/routes/convos.js
@@ -7,6 +7,7 @@ const requireJwtAuth = require('~/server/middleware/requireJwtAuth');
const { forkConversation } = require('~/server/utils/import/fork');
const { importConversations } = require('~/server/utils/import');
const { createImportLimiters } = require('~/server/middleware');
+const { deleteToolCalls } = require('~/models/ToolCall');
const getLogStores = require('~/cache/getLogStores');
const { sleep } = require('~/server/utils');
const { logger } = require('~/config');
@@ -105,6 +106,7 @@ router.post('/clear', async (req, res) => {
try {
const dbResponse = await deleteConvos(req.user.id, filter);
+ await deleteToolCalls(req.user.id, filter.conversationId);
res.status(201).json(dbResponse);
} catch (error) {
logger.error('Error clearing conversations', error);
diff --git a/api/server/routes/files/files.js b/api/server/routes/files/files.js
index e177142908..c320f7705b 100644
--- a/api/server/routes/files/files.js
+++ b/api/server/routes/files/files.js
@@ -107,6 +107,10 @@ router.delete('/', async (req, res) => {
}
});
+function isValidID(str) {
+ return /^[A-Za-z0-9_-]{21}$/.test(str);
+}
+
router.get('/code/download/:session_id/:fileId', async (req, res) => {
try {
const { session_id, fileId } = req.params;
@@ -117,6 +121,11 @@ router.get('/code/download/:session_id/:fileId', async (req, res) => {
return res.status(400).send('Bad request');
}
+ if (!isValidID(session_id) || !isValidID(fileId)) {
+ logger.debug(`${logPrefix} invalid session_id or fileId`);
+ return res.status(400).send('Bad request');
+ }
+
const { getDownloadStream } = getStrategyFunctions(FileSources.execute_code);
if (!getDownloadStream) {
logger.warn(
@@ -213,21 +222,20 @@ router.get('/download/:userId/:file_id', async (req, res) => {
});
router.post('/', async (req, res) => {
- const file = req.file;
const metadata = req.body;
let cleanup = true;
try {
- filterFile({ req, file });
+ filterFile({ req });
metadata.temp_file_id = metadata.file_id;
metadata.file_id = req.file_id;
if (isAgentsEndpoint(metadata.endpoint)) {
- return await processAgentFileUpload({ req, res, file, metadata });
+ return await processAgentFileUpload({ req, res, metadata });
}
- await processFileUpload({ req, res, file, metadata });
+ await processFileUpload({ req, res, metadata });
} catch (error) {
let message = 'Error processing file';
logger.error('[/files] Error processing file:', error);
@@ -238,7 +246,7 @@ router.post('/', async (req, res) => {
// TODO: delete remote file if it exists
try {
- await fs.unlink(file.path);
+ await fs.unlink(req.file.path);
cleanup = false;
} catch (error) {
logger.error('[/files] Error deleting file:', error);
@@ -248,7 +256,7 @@ router.post('/', async (req, res) => {
if (cleanup) {
try {
- await fs.unlink(file.path);
+ await fs.unlink(req.file.path);
} catch (error) {
logger.error('[/files] Error deleting file after file processing:', error);
}
diff --git a/api/server/routes/files/images.js b/api/server/routes/files/images.js
index 318ac91e22..d6d04446f8 100644
--- a/api/server/routes/files/images.js
+++ b/api/server/routes/files/images.js
@@ -1,7 +1,12 @@
const path = require('path');
const fs = require('fs').promises;
const express = require('express');
-const { filterFile, processImageFile } = require('~/server/services/Files/process');
+const { isAgentsEndpoint } = require('librechat-data-provider');
+const {
+ filterFile,
+ processImageFile,
+ processAgentFileUpload,
+} = require('~/server/services/Files/process');
const { logger } = require('~/config');
const router = express.Router();
@@ -10,12 +15,16 @@ router.post('/', async (req, res) => {
const metadata = req.body;
try {
- filterFile({ req, file: req.file, image: true });
+ filterFile({ req, image: true });
metadata.temp_file_id = metadata.file_id;
metadata.file_id = req.file_id;
- await processImageFile({ req, res, file: req.file, metadata });
+ if (isAgentsEndpoint(metadata.endpoint) && metadata.tool_resource != null) {
+ return await processAgentFileUpload({ req, res, metadata });
+ }
+
+ await processImageFile({ req, res, metadata });
} catch (error) {
// TODO: delete remote file if it exists
logger.error('[/files/images] Error processing file:', error);
diff --git a/api/server/routes/roles.js b/api/server/routes/roles.js
index 36152e2c7e..e58ebb6fe7 100644
--- a/api/server/routes/roles.js
+++ b/api/server/routes/roles.js
@@ -1,6 +1,7 @@
const express = require('express');
const {
promptPermissionsSchema,
+ agentPermissionsSchema,
PermissionTypes,
roleDefaults,
SystemRoles,
@@ -72,4 +73,37 @@ router.put('/:roleName/prompts', checkAdmin, async (req, res) => {
}
});
+/**
+ * PUT /api/roles/:roleName/agents
+ * Update agent permissions for a specific role
+ */
+router.put('/:roleName/agents', checkAdmin, async (req, res) => {
+ const { roleName: _r } = req.params;
+ // TODO: TEMP, use a better parsing for roleName
+ const roleName = _r.toUpperCase();
+ /** @type {TRole['AGENTS']} */
+ const updates = req.body;
+
+ try {
+ const parsedUpdates = agentPermissionsSchema.partial().parse(updates);
+
+ const role = await getRoleByName(roleName);
+ if (!role) {
+ return res.status(404).send({ message: 'Role not found' });
+ }
+
+ const mergedUpdates = {
+ [PermissionTypes.AGENTS]: {
+ ...role[PermissionTypes.AGENTS],
+ ...parsedUpdates,
+ },
+ };
+
+ const updatedRole = await updateRoleByName(roleName, mergedUpdates);
+ res.status(200).send(updatedRole);
+ } catch (error) {
+ return res.status(400).send({ message: 'Invalid prompt permissions.', error: error.errors });
+ }
+});
+
module.exports = router;
diff --git a/api/server/services/AppService.js b/api/server/services/AppService.js
index f99e962871..19a9fc91a9 100644
--- a/api/server/services/AppService.js
+++ b/api/server/services/AppService.js
@@ -8,7 +8,6 @@ const { loadDefaultInterface } = require('./start/interface');
const { azureConfigSetup } = require('./start/azureOpenAI');
const { loadAndFormatTools } = require('./ToolService');
const { initializeRoles } = require('~/models/Role');
-const { cleanup } = require('./cleanup');
const paths = require('~/config/paths');
/**
@@ -18,7 +17,6 @@ const paths = require('~/config/paths');
* @param {Express.Application} app - The Express application object.
*/
const AppService = async (app) => {
- cleanup();
await initializeRoles();
/** @type {TCustomConfig}*/
const config = (await loadCustomConfig()) ?? {};
diff --git a/api/server/services/Config/EndpointService.js b/api/server/services/Config/EndpointService.js
index 49f9d8f548..dc055e2872 100644
--- a/api/server/services/Config/EndpointService.js
+++ b/api/server/services/Config/EndpointService.js
@@ -49,10 +49,6 @@ module.exports = {
process.env.BEDROCK_AWS_SECRET_ACCESS_KEY ?? process.env.BEDROCK_AWS_DEFAULT_REGION,
),
/* key will be part of separate config */
- [EModelEndpoint.agents]: generateConfig(
- process.env.EXPERIMENTAL_AGENTS,
- undefined,
- EModelEndpoint.agents,
- ),
+ [EModelEndpoint.agents]: generateConfig('true', undefined, EModelEndpoint.agents),
},
};
diff --git a/api/server/services/Endpoints/agents/build.js b/api/server/services/Endpoints/agents/build.js
index 853c9ba266..90e251a4ea 100644
--- a/api/server/services/Endpoints/agents/build.js
+++ b/api/server/services/Endpoints/agents/build.js
@@ -2,8 +2,14 @@ const { loadAgent } = require('~/models/Agent');
const { logger } = require('~/config');
const buildOptions = (req, endpoint, parsedBody) => {
- const { agent_id, instructions, spec, ...model_parameters } = parsedBody;
-
+ const {
+ agent_id,
+ instructions,
+ spec,
+ maxContextTokens,
+ resendFiles = true,
+ ...model_parameters
+ } = parsedBody;
const agentPromise = loadAgent({
req,
agent_id,
@@ -13,12 +19,14 @@ const buildOptions = (req, endpoint, parsedBody) => {
});
const endpointOption = {
- agent: agentPromise,
+ spec,
endpoint,
agent_id,
+ resendFiles,
instructions,
- spec,
+ maxContextTokens,
model_parameters,
+ agent: agentPromise,
};
return endpointOption;
diff --git a/api/server/services/Endpoints/agents/initialize.js b/api/server/services/Endpoints/agents/initialize.js
index 796f69e4ac..507546a345 100644
--- a/api/server/services/Endpoints/agents/initialize.js
+++ b/api/server/services/Endpoints/agents/initialize.js
@@ -16,6 +16,8 @@ const { getCustomEndpointConfig } = require('~/server/services/Config');
const { loadAgentTools } = require('~/server/services/ToolService');
const AgentClient = require('~/server/controllers/agents/client');
const { getModelMaxTokens } = require('~/utils');
+const { getAgent } = require('~/models/Agent');
+const { logger } = require('~/config');
const providerConfigMap = {
[EModelEndpoint.openAI]: initOpenAI,
@@ -25,6 +27,113 @@ const providerConfigMap = {
[Providers.OLLAMA]: initCustom,
};
+/**
+ *
+ * @param {Promise<Array<MongoFile | null>> | undefined} _attachments
+ * @param {AgentToolResources | undefined} _tool_resources
+ * @returns {Promise<{ attachments: Array<MongoFile | undefined> | undefined, tool_resources: AgentToolResources | undefined }>}
+ */
+const primeResources = async (_attachments, _tool_resources) => {
+ try {
+ if (!_attachments) {
+ return { attachments: undefined, tool_resources: _tool_resources };
+ }
+ /** @type {Array<MongoFile | undefined> | undefined} */
+ const files = await _attachments;
+ const attachments = [];
+ const tool_resources = _tool_resources ?? {};
+
+ for (const file of files) {
+ if (!file) {
+ continue;
+ }
+ if (file.metadata?.fileIdentifier) {
+ const execute_code = tool_resources.execute_code ?? {};
+ if (!execute_code.files) {
+ tool_resources.execute_code = { ...execute_code, files: [] };
+ }
+ tool_resources.execute_code.files.push(file);
+ } else if (file.embedded === true) {
+ const file_search = tool_resources.file_search ?? {};
+ if (!file_search.files) {
+ tool_resources.file_search = { ...file_search, files: [] };
+ }
+ tool_resources.file_search.files.push(file);
+ }
+
+ attachments.push(file);
+ }
+ return { attachments, tool_resources };
+ } catch (error) {
+ logger.error('Error priming resources', error);
+ return { attachments: _attachments, tool_resources: _tool_resources };
+ }
+};
+
+const initializeAgentOptions = async ({
+ req,
+ res,
+ agent,
+ endpointOption,
+ tool_resources,
+ isInitialAgent = false,
+}) => {
+ const { tools, toolContextMap } = await loadAgentTools({
+ req,
+ tools: agent.tools,
+ agent_id: agent.id,
+ tool_resources,
+ });
+
+ const provider = agent.provider;
+ let getOptions = providerConfigMap[provider];
+
+ if (!getOptions) {
+ const customEndpointConfig = await getCustomEndpointConfig(provider);
+ if (!customEndpointConfig) {
+ throw new Error(`Provider ${provider} not supported`);
+ }
+ getOptions = initCustom;
+ agent.provider = Providers.OPENAI;
+ agent.endpoint = provider.toLowerCase();
+ }
+
+ const model_parameters = agent.model_parameters ?? { model: agent.model };
+ const _endpointOption = isInitialAgent
+ ? endpointOption
+ : {
+ model_parameters,
+ };
+
+ const options = await getOptions({
+ req,
+ res,
+ optionsOnly: true,
+ overrideEndpoint: provider,
+ overrideModel: agent.model,
+ endpointOption: _endpointOption,
+ });
+
+ agent.model_parameters = Object.assign(model_parameters, options.llmConfig);
+ if (options.configOptions) {
+ agent.model_parameters.configuration = options.configOptions;
+ }
+
+ if (!agent.model_parameters.model) {
+ agent.model_parameters.model = agent.model;
+ }
+
+ return {
+ ...agent,
+ tools,
+ toolContextMap,
+ maxContextTokens:
+ agent.max_context_tokens ??
+ getModelMaxTokens(agent.model_parameters.model, providerEndpointMap[provider]) ??
+ 4000,
+ };
+};
+
const initializeClient = async ({ req, res, endpointOption }) => {
if (!endpointOption) {
throw new Error('Endpoint option not provided');
@@ -48,70 +157,68 @@ const initializeClient = async ({ req, res, endpointOption }) => {
throw new Error('No agent promise provided');
}
- /** @type {Agent | null} */
- const agent = await endpointOption.agent;
- if (!agent) {
+ // Initialize primary agent
+ const primaryAgent = await endpointOption.agent;
+ if (!primaryAgent) {
throw new Error('Agent not found');
}
- const { tools } = await loadAgentTools({
- req,
- tools: agent.tools,
- agent_id: agent.id,
- tool_resources: agent.tool_resources,
- });
+ const { attachments, tool_resources } = await primeResources(
+ endpointOption.attachments,
+ primaryAgent.tool_resources,
+ );
- const provider = agent.provider;
- let modelOptions = { model: agent.model };
- let getOptions = providerConfigMap[provider];
- if (!getOptions) {
- const customEndpointConfig = await getCustomEndpointConfig(provider);
- if (!customEndpointConfig) {
- throw new Error(`Provider ${provider} not supported`);
- }
- getOptions = initCustom;
- agent.provider = Providers.OPENAI;
- agent.endpoint = provider.toLowerCase();
- }
+ const agentConfigs = new Map();
- // TODO: pass-in override settings that are specific to current run
- endpointOption.model_parameters.model = agent.model;
- const options = await getOptions({
+ // Handle primary agent
+ const primaryConfig = await initializeAgentOptions({
req,
res,
+ agent: primaryAgent,
endpointOption,
- optionsOnly: true,
- overrideEndpoint: provider,
- overrideModel: agent.model,
+ tool_resources,
+ isInitialAgent: true,
});
- modelOptions = Object.assign(modelOptions, options.llmConfig);
- if (options.configOptions) {
- modelOptions.configuration = options.configOptions;
+ const agent_ids = primaryConfig.agent_ids;
+ if (agent_ids?.length) {
+ for (const agentId of agent_ids) {
+ const agent = await getAgent({ id: agentId });
+ if (!agent) {
+ throw new Error(`Agent ${agentId} not found`);
+ }
+ const config = await initializeAgentOptions({
+ req,
+ res,
+ agent,
+ endpointOption,
+ });
+ agentConfigs.set(agentId, config);
+ }
}
- const sender = getResponseSender({
- ...endpointOption,
- model: endpointOption.model_parameters.model,
- });
+ const sender =
+ primaryAgent.name ??
+ getResponseSender({
+ ...endpointOption,
+ model: endpointOption.model_parameters.model,
+ });
const client = new AgentClient({
req,
- agent,
- tools,
+ agent: primaryConfig,
sender,
+ attachments,
contentParts,
- modelOptions,
eventHandlers,
collectedUsage,
artifactPromises,
+ spec: endpointOption.spec,
+ agentConfigs,
endpoint: EModelEndpoint.agents,
- attachments: endpointOption.attachments,
- maxContextTokens:
- agent.max_context_tokens ??
- getModelMaxTokens(modelOptions.model, providerEndpointMap[provider]) ??
- 4000,
+ maxContextTokens: primaryConfig.maxContextTokens,
});
+
return { client };
};
diff --git a/api/server/services/Endpoints/bedrock/initialize.js b/api/server/services/Endpoints/bedrock/initialize.js
index 00630c41e6..d2be7e235b 100644
--- a/api/server/services/Endpoints/bedrock/initialize.js
+++ b/api/server/services/Endpoints/bedrock/initialize.js
@@ -5,7 +5,6 @@ const {
getResponseSender,
} = require('librechat-data-provider');
const { getDefaultHandlers } = require('~/server/controllers/agents/callbacks');
-// const { loadAgentTools } = require('~/server/services/ToolService');
const getOptions = require('~/server/services/Endpoints/bedrock/options');
const AgentClient = require('~/server/controllers/agents/client');
const { getModelMaxTokens } = require('~/utils');
@@ -20,8 +19,6 @@ const initializeClient = async ({ req, res, endpointOption }) => {
const { contentParts, aggregateContent } = createContentAggregator();
const eventHandlers = getDefaultHandlers({ res, aggregateContent, collectedUsage });
- // const tools = [createTavilySearchTool()];
-
/** @type {Agent} */
const agent = {
id: EModelEndpoint.bedrock,
@@ -36,8 +33,6 @@ const initializeClient = async ({ req, res, endpointOption }) => {
agent.instructions = `${agent.instructions ?? ''}\n${endpointOption.artifactsPrompt}`.trim();
}
- let modelOptions = { model: agent.model };
-
// TODO: pass-in override settings that are specific to current run
const options = await getOptions({
req,
@@ -45,28 +40,34 @@ const initializeClient = async ({ req, res, endpointOption }) => {
endpointOption,
});
- modelOptions = Object.assign(modelOptions, options.llmConfig);
- const maxContextTokens =
- agent.max_context_tokens ??
- getModelMaxTokens(modelOptions.model, providerEndpointMap[agent.provider]);
+ agent.model_parameters = Object.assign(agent.model_parameters, options.llmConfig);
+ if (options.configOptions) {
+ agent.model_parameters.configuration = options.configOptions;
+ }
- const sender = getResponseSender({
- ...endpointOption,
- model: endpointOption.model_parameters.model,
- });
+ const sender =
+ agent.name ??
+ getResponseSender({
+ ...endpointOption,
+ model: endpointOption.model_parameters.model,
+ });
const client = new AgentClient({
req,
agent,
sender,
// tools,
- modelOptions,
contentParts,
eventHandlers,
collectedUsage,
- maxContextTokens,
+ spec: endpointOption.spec,
endpoint: EModelEndpoint.bedrock,
- configOptions: options.configOptions,
+ resendFiles: endpointOption.resendFiles,
+ maxContextTokens:
+ endpointOption.maxContextTokens ??
+ agent.max_context_tokens ??
+ getModelMaxTokens(agent.model_parameters.model, providerEndpointMap[agent.provider]) ??
+ 4000,
attachments: endpointOption.attachments,
});
return { client };
diff --git a/api/server/services/Endpoints/custom/initialize.js b/api/server/services/Endpoints/custom/initialize.js
index 2390ea368d..c88e6882f5 100644
--- a/api/server/services/Endpoints/custom/initialize.js
+++ b/api/server/services/Endpoints/custom/initialize.js
@@ -10,8 +10,8 @@ const { getUserKeyValues, checkUserKeyExpiry } = require('~/server/services/User
const { getLLMConfig } = require('~/server/services/Endpoints/openAI/llm');
const { getCustomEndpointConfig } = require('~/server/services/Config');
const { fetchModels } = require('~/server/services/ModelService');
+const { isUserProvided, sleep } = require('~/server/utils');
const getLogStores = require('~/cache/getLogStores');
-const { isUserProvided } = require('~/server/utils');
const { OpenAIClient } = require('~/app');
const { PROXY } = process.env;
@@ -141,7 +141,18 @@ const initializeClient = async ({ req, res, endpointOption, optionsOnly, overrid
},
clientOptions,
);
- return getLLMConfig(apiKey, requestOptions);
+ const options = getLLMConfig(apiKey, requestOptions);
+ if (!customOptions.streamRate) {
+ return options;
+ }
+ options.llmConfig.callbacks = [
+ {
+ handleLLMNewToken: async () => {
+ await sleep(customOptions.streamRate);
+ },
+ },
+ ];
+ return options;
}
if (clientOptions.reverseProxyUrl) {
diff --git a/api/server/services/Endpoints/openAI/initialize.js b/api/server/services/Endpoints/openAI/initialize.js
index a84be42b91..63abbfea9c 100644
--- a/api/server/services/Endpoints/openAI/initialize.js
+++ b/api/server/services/Endpoints/openAI/initialize.js
@@ -6,7 +6,7 @@ const {
} = require('librechat-data-provider');
const { getUserKeyValues, checkUserKeyExpiry } = require('~/server/services/UserService');
const { getLLMConfig } = require('~/server/services/Endpoints/openAI/llm');
-const { isEnabled, isUserProvided } = require('~/server/utils');
+const { isEnabled, isUserProvided, sleep } = require('~/server/utils');
const { getAzureCredentials } = require('~/utils');
const { OpenAIClient } = require('~/app');
@@ -140,7 +140,18 @@ const initializeClient = async ({
},
clientOptions,
);
- return getLLMConfig(apiKey, requestOptions);
+ const options = getLLMConfig(apiKey, requestOptions);
+ if (!clientOptions.streamRate) {
+ return options;
+ }
+ options.llmConfig.callbacks = [
+ {
+ handleLLMNewToken: async () => {
+ await sleep(clientOptions.streamRate);
+ },
+ },
+ ];
+ return options;
}
const client = new OpenAIClient(apiKey, Object.assign({ req, res }, clientOptions));
diff --git a/api/server/services/Files/Code/crud.js b/api/server/services/Files/Code/crud.js
index 82b999b9bb..07d09548ab 100644
--- a/api/server/services/Files/Code/crud.js
+++ b/api/server/services/Files/Code/crud.js
@@ -40,12 +40,16 @@ async function getCodeOutputDownloadStream(fileIdentifier, apiKey) {
* @param {import('fs').ReadStream | import('stream').Readable} params.stream - The read stream for the file.
* @param {string} params.filename - The name of the file.
* @param {string} params.apiKey - The API key for authentication.
+ * @param {string} [params.entity_id] - Optional entity ID for the file.
* @returns {Promise<string>}
* @throws {Error} If there's an error during the upload process.
*/
-async function uploadCodeEnvFile({ req, stream, filename, apiKey }) {
+async function uploadCodeEnvFile({ req, stream, filename, apiKey, entity_id = '' }) {
try {
const form = new FormData();
+ if (entity_id.length > 0) {
+ form.append('entity_id', entity_id);
+ }
form.append('file', stream, filename);
const baseURL = getCodeBaseURL();
@@ -67,7 +71,12 @@ async function uploadCodeEnvFile({ req, stream, filename, apiKey }) {
throw new Error(`Error uploading file: ${result.message}`);
}
- return `${result.session_id}/${result.files[0].fileId}`;
+ const fileIdentifier = `${result.session_id}/${result.files[0].fileId}`;
+ if (entity_id.length === 0) {
+ return fileIdentifier;
+ }
+
+ return `${fileIdentifier}?entity_id=${entity_id}`;
} catch (error) {
throw new Error(`Error uploading file: ${error.message}`);
}
diff --git a/api/server/services/Files/Code/process.js b/api/server/services/Files/Code/process.js
index 313b98f39b..2a941a4647 100644
--- a/api/server/services/Files/Code/process.js
+++ b/api/server/services/Files/Code/process.js
@@ -3,10 +3,11 @@ const { v4 } = require('uuid');
const axios = require('axios');
const { getCodeBaseURL } = require('@librechat/agents');
const {
- EToolResources,
+ Tools,
FileContext,
- imageExtRegex,
FileSources,
+ imageExtRegex,
+ EToolResources,
} = require('librechat-data-provider');
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
const { convertImage } = require('~/server/services/Files/images/convert');
@@ -110,12 +111,20 @@ function checkIfActive(dateString) {
async function getSessionInfo(fileIdentifier, apiKey) {
try {
const baseURL = getCodeBaseURL();
- const session_id = fileIdentifier.split('/')[0];
+ const [path, queryString] = fileIdentifier.split('?');
+ const session_id = path.split('/')[0];
+
+ let queryParams = {};
+ if (queryString) {
+ queryParams = Object.fromEntries(new URLSearchParams(queryString).entries());
+ }
+
const response = await axios({
method: 'get',
url: `${baseURL}/files/${session_id}`,
params: {
detail: 'summary',
+ ...queryParams,
},
headers: {
'User-Agent': 'LibreChat/1.0',
@@ -124,7 +133,7 @@ async function getSessionInfo(fileIdentifier, apiKey) {
timeout: 5000,
});
- return response.data.find((file) => file.name.startsWith(fileIdentifier))?.lastModified;
+ return response.data.find((file) => file.name.startsWith(path))?.lastModified;
} catch (error) {
logger.error(`Error fetching session info: ${error.message}`, error);
return null;
@@ -137,29 +146,56 @@ async function getSessionInfo(fileIdentifier, apiKey) {
* @param {ServerRequest} options.req
* @param {Agent['tool_resources']} options.tool_resources
* @param {string} apiKey
- * @returns {Promise<Array<{ id: string; session_id: string; name: string }>>}
+ * @returns {Promise<{
+ * files: Array<{ id: string; session_id: string; name: string }>,
+ * toolContext: string,
+ * }>}
*/
const primeFiles = async (options, apiKey) => {
const { tool_resources } = options;
const file_ids = tool_resources?.[EToolResources.execute_code]?.file_ids ?? [];
- const dbFiles = await getFiles({ file_id: { $in: file_ids } });
+ const agentResourceIds = new Set(file_ids);
+ const resourceFiles = tool_resources?.[EToolResources.execute_code]?.files ?? [];
+ const dbFiles = ((await getFiles({ file_id: { $in: file_ids } })) ?? []).concat(resourceFiles);
const files = [];
const sessions = new Map();
- for (const file of dbFiles) {
+ let toolContext = '';
+
+ for (let i = 0; i < dbFiles.length; i++) {
+ const file = dbFiles[i];
+ if (!file) {
+ continue;
+ }
+
if (file.metadata.fileIdentifier) {
- const [session_id, id] = file.metadata.fileIdentifier.split('/');
+ const [path, queryString] = file.metadata.fileIdentifier.split('?');
+ const [session_id, id] = path.split('/');
+
const pushFile = () => {
+ if (!toolContext) {
+ toolContext = `- Note: The following files are available in the "${Tools.execute_code}" tool environment:`;
+ }
+ toolContext += `\n\t- /mnt/data/${file.filename}${
+ agentResourceIds.has(file.file_id) ? '' : ' (just attached by user)'
+ }`;
files.push({
id,
session_id,
name: file.filename,
});
};
+
if (sessions.has(session_id)) {
pushFile();
continue;
}
+
+ let queryParams = {};
+ if (queryString) {
+ queryParams = Object.fromEntries(new URLSearchParams(queryString).entries());
+ }
+
const reuploadFile = async () => {
try {
const { getDownloadStream } = getStrategyFunctions(file.source);
@@ -171,6 +207,7 @@ const primeFiles = async (options, apiKey) => {
req: options.req,
stream,
filename: file.filename,
+ entity_id: queryParams.entity_id,
apiKey,
});
await updateFile({ file_id: file.file_id, metadata: { fileIdentifier } });
@@ -198,7 +235,7 @@ const primeFiles = async (options, apiKey) => {
}
}
- return files;
+ return { files, toolContext };
};
module.exports = {
diff --git a/api/server/services/Files/images/encode.js b/api/server/services/Files/images/encode.js
index f457927019..94153ffc64 100644
--- a/api/server/services/Files/images/encode.js
+++ b/api/server/services/Files/images/encode.js
@@ -97,6 +97,7 @@ async function encodeAndFormat(req, files, endpoint, mode) {
filepath: file.filepath,
filename: file.filename,
embedded: !!file.embedded,
+ metadata: file.metadata,
};
if (file.height && file.width) {
diff --git a/api/server/services/Files/process.js b/api/server/services/Files/process.js
index 5436b7037a..ab401420f1 100644
--- a/api/server/services/Files/process.js
+++ b/api/server/services/Files/process.js
@@ -20,7 +20,7 @@ const {
const { EnvVar } = require('@librechat/agents');
const { addResourceFileId, deleteResourceFileId } = require('~/server/controllers/assistants/v2');
const { convertImage, resizeAndConvert } = require('~/server/services/Files/images');
-const { addAgentResourceFile, removeAgentResourceFile } = require('~/models/Agent');
+const { addAgentResourceFile, removeAgentResourceFiles } = require('~/models/Agent');
const { getOpenAIClient } = require('~/server/controllers/assistants/helpers');
const { createFile, updateFileUsage, deleteFiles } = require('~/models/File');
const { loadAuthValues } = require('~/app/clients/tools/util');
@@ -29,10 +29,34 @@ const { getStrategyFunctions } = require('./strategies');
const { determineFileType } = require('~/server/utils');
const { logger } = require('~/config');
-const processFiles = async (files) => {
+/**
+ *
+ * @param {Array<MongoFile>} files
+ * @param {Array<string>} [fileIds]
+ * @returns
+ */
+const processFiles = async (files, fileIds) => {
const promises = [];
+ const seen = new Set();
+
for (let file of files) {
const { file_id } = file;
+ if (seen.has(file_id)) {
+ continue;
+ }
+ seen.add(file_id);
+ promises.push(updateFileUsage({ file_id }));
+ }
+
+ if (!fileIds) {
+ return await Promise.all(promises);
+ }
+
+ for (let file_id of fileIds) {
+ if (seen.has(file_id)) {
+ continue;
+ }
+ seen.add(file_id);
promises.push(updateFileUsage({ file_id }));
}
@@ -44,7 +68,7 @@ const processFiles = async (files) => {
* Enqueues the delete operation to the leaky bucket queue if necessary, or adds it directly to promises.
*
* @param {object} params - The passed parameters.
- * @param {Express.Request} params.req - The express request object.
+ * @param {ServerRequest} params.req - The express request object.
* @param {MongoFile} params.file - The file object to delete.
* @param {Function} params.deleteFile - The delete file function.
* @param {Promise[]} params.promises - The array of promises to await.
@@ -91,7 +115,7 @@ function enqueueDeleteOperation({ req, file, deleteFile, promises, resolvedFileI
*
* @param {Object} params - The params object.
* @param {MongoFile[]} params.files - The file objects to delete.
- * @param {Express.Request} params.req - The express request object.
+ * @param {ServerRequest} params.req - The express request object.
* @param {DeleteFilesBody} params.req.body - The request body.
* @param {string} [params.req.body.agent_id] - The agent ID if file uploaded is associated to an agent.
* @param {string} [params.req.body.assistant_id] - The assistant ID if file uploaded is associated to an assistant.
@@ -128,18 +152,16 @@ const processDeleteRequest = async ({ req, files }) => {
await initializeClients();
}
+ const agentFiles = [];
+
for (const file of files) {
const source = file.source ?? FileSources.local;
if (req.body.agent_id && req.body.tool_resource) {
- promises.push(
- removeAgentResourceFile({
- req,
- file_id: file.file_id,
- agent_id: req.body.agent_id,
- tool_resource: req.body.tool_resource,
- }),
- );
+ agentFiles.push({
+ tool_resource: req.body.tool_resource,
+ file_id: file.file_id,
+ });
}
if (checkOpenAIStorage(source) && !client[source]) {
@@ -183,6 +205,15 @@ const processDeleteRequest = async ({ req, files }) => {
enqueueDeleteOperation({ req, file, deleteFile, promises, resolvedFileIds, openai });
}
+ if (agentFiles.length > 0) {
+ promises.push(
+ removeAgentResourceFiles({
+ agent_id: req.body.agent_id,
+ files: agentFiles,
+ }),
+ );
+ }
+
await Promise.allSettled(promises);
await deleteFiles(resolvedFileIds);
};
@@ -242,14 +273,14 @@ const processFileURL = async ({ fileStrategy, userId, URL, fileName, basePath, c
* Saves file metadata to the database with an expiry TTL.
*
* @param {Object} params - The parameters object.
- * @param {Express.Request} params.req - The Express request object.
+ * @param {ServerRequest} params.req - The Express request object.
* @param {Express.Response} [params.res] - The Express response object.
- * @param {Express.Multer.File} params.file - The uploaded file.
* @param {ImageMetadata} params.metadata - Additional metadata for the file.
* @param {boolean} params.returnFile - Whether to return the file metadata or return response as normal.
* @returns {Promise<void>}
*/
-const processImageFile = async ({ req, res, file, metadata, returnFile = false }) => {
+const processImageFile = async ({ req, res, metadata, returnFile = false }) => {
+ const { file } = req;
const source = req.app.locals.fileStrategy;
const { handleImageUpload } = getStrategyFunctions(source);
const { file_id, temp_file_id, endpoint } = metadata;
@@ -289,7 +320,7 @@ const processImageFile = async ({ req, res, file, metadata, returnFile = false }
* returns minimal file metadata, without saving to the database.
*
* @param {Object} params - The parameters object.
- * @param {Express.Request} params.req - The Express request object.
+ * @param {ServerRequest} params.req - The Express request object.
* @param {FileContext} params.context - The context of the file (e.g., 'avatar', 'image_generation', etc.)
* @param {boolean} [params.resize=true] - Whether to resize and convert the image to target format. Default is `true`.
* @param {{ buffer: Buffer, width: number, height: number, bytes: number, filename: string, type: string, file_id: string }} [params.metadata] - Required metadata for the file if resize is false.
@@ -335,13 +366,12 @@ const uploadImageBuffer = async ({ req, context, metadata = {}, resize = true })
* Files must be deleted from the server filesystem manually.
*
* @param {Object} params - The parameters object.
- * @param {Express.Request} params.req - The Express request object.
+ * @param {ServerRequest} params.req - The Express request object.
* @param {Express.Response} params.res - The Express response object.
- * @param {Express.Multer.File} params.file - The uploaded file.
* @param {FileMetadata} params.metadata - Additional metadata for the file.
* @returns {Promise<void>}
*/
-const processFileUpload = async ({ req, res, file, metadata }) => {
+const processFileUpload = async ({ req, res, metadata }) => {
const isAssistantUpload = isAssistantsEndpoint(metadata.endpoint);
const assistantSource =
metadata.endpoint === EModelEndpoint.azureAssistants ? FileSources.azure : FileSources.openai;
@@ -355,6 +385,7 @@ const processFileUpload = async ({ req, res, file, metadata }) => {
({ openai } = await getOpenAIClient({ req }));
}
+ const { file } = req;
const {
id,
bytes,
@@ -422,13 +453,13 @@ const processFileUpload = async ({ req, res, file, metadata }) => {
* Files must be deleted from the server filesystem manually.
*
* @param {Object} params - The parameters object.
- * @param {Express.Request} params.req - The Express request object.
+ * @param {ServerRequest} params.req - The Express request object.
* @param {Express.Response} params.res - The Express response object.
- * @param {Express.Multer.File} params.file - The uploaded file.
* @param {FileMetadata} params.metadata - Additional metadata for the file.
* @returns {Promise<void>}
*/
-const processAgentFileUpload = async ({ req, res, file, metadata }) => {
+const processAgentFileUpload = async ({ req, res, metadata }) => {
+ const { file } = req;
const { agent_id, tool_resource } = metadata;
if (agent_id && !tool_resource) {
throw new Error('No tool resource provided for agent file upload');
@@ -453,6 +484,7 @@ const processAgentFileUpload = async ({ req, res, file, metadata }) => {
stream,
filename: file.originalname,
apiKey: result[EnvVar.CODE_API_KEY],
+ entity_id: messageAttachment === true ? undefined : agent_id,
});
fileInfoMetadata = { fileIdentifier };
}
@@ -576,7 +608,7 @@ const processOpenAIFile = async ({
/**
* Process OpenAI image files, convert to target format, save and return file metadata.
* @param {object} params - The params object.
- * @param {Express.Request} params.req - The Express request object.
+ * @param {ServerRequest} params.req - The Express request object.
* @param {Buffer} params.buffer - The image buffer.
* @param {string} params.file_id - The file ID.
* @param {string} params.filename - The filename.
@@ -708,20 +740,20 @@ async function retrieveAndProcessFile({
* Filters a file based on its size and the endpoint origin.
*
* @param {Object} params - The parameters for the function.
- * @param {object} params.req - The request object from Express.
+ * @param {ServerRequest} params.req - The request object from Express.
* @param {string} [params.req.endpoint]
* @param {string} [params.req.file_id]
* @param {number} [params.req.width]
* @param {number} [params.req.height]
* @param {number} [params.req.version]
- * @param {Express.Multer.File} params.file - The file uploaded to the server via multer.
* @param {boolean} [params.image] - Whether the file expected is an image.
* @param {boolean} [params.isAvatar] - Whether the file expected is a user or entity avatar.
* @returns {void}
*
* @throws {Error} If a file exception is caught (invalid file size or type, lack of metadata).
*/
-function filterFile({ req, file, image, isAvatar }) {
+function filterFile({ req, image, isAvatar }) {
+ const { file } = req;
const { endpoint, file_id, width, height } = req.body;
if (!file_id && !isAvatar) {
diff --git a/api/server/services/PluginService.js b/api/server/services/PluginService.js
index 2b09da96a7..e03f7f89e9 100644
--- a/api/server/services/PluginService.js
+++ b/api/server/services/PluginService.js
@@ -7,6 +7,7 @@ const { logger } = require('~/config');
*
* @param {string} userId - The unique identifier of the user for whom the plugin authentication value is to be retrieved.
* @param {string} authField - The specific authentication field (e.g., 'API_KEY', 'URL') whose value is to be retrieved and decrypted.
+ * @param {boolean} throwError - Whether to throw an error if the authentication value does not exist. Defaults to `true`.
* @returns {Promise<string|null>} A promise that resolves to the decrypted authentication value if found, or `null` if no such authentication value exists for the given user and field.
*
* The function throws an error if it encounters any issue during the retrieval or decryption process, or if the authentication value does not exist.
@@ -22,7 +23,7 @@ const { logger } = require('~/config');
* @throws {Error} Throws an error if there's an issue during the retrieval or decryption process, or if the authentication value does not exist.
* @async
*/
-const getUserPluginAuthValue = async (userId, authField) => {
+const getUserPluginAuthValue = async (userId, authField, throwError = true) => {
try {
const pluginAuth = await PluginAuth.findOne({ userId, authField }).lean();
if (!pluginAuth) {
@@ -32,6 +33,9 @@ const getUserPluginAuthValue = async (userId, authField) => {
const decryptedValue = await decrypt(pluginAuth.value);
return decryptedValue;
} catch (err) {
+ if (!throwError) {
+ return null;
+ }
logger.error('[getUserPluginAuthValue]', err);
throw err;
}
diff --git a/api/server/services/ToolService.js b/api/server/services/ToolService.js
index 4ffaf3d5ba..91a5e7a6cf 100644
--- a/api/server/services/ToolService.js
+++ b/api/server/services/ToolService.js
@@ -1,8 +1,8 @@
const fs = require('fs');
const path = require('path');
const { zodToJsonSchema } = require('zod-to-json-schema');
-const { Calculator } = require('@langchain/community/tools/calculator');
const { tool: toolFn, Tool } = require('@langchain/core/tools');
+const { Calculator } = require('@langchain/community/tools/calculator');
const {
Tools,
ContentTypes,
@@ -170,7 +170,7 @@ async function processRequiredActions(client, requiredActions) {
requiredActions,
);
const tools = requiredActions.map((action) => action.tool);
- const loadedTools = await loadTools({
+ const { loadedTools } = await loadTools({
user: client.req.user.id,
model: client.req.body.model ?? 'gpt-4o-mini',
tools,
@@ -183,7 +183,6 @@ async function processRequiredActions(client, requiredActions) {
fileStrategy: client.req.app.locals.fileStrategy,
returnMetadata: true,
},
- skipSpecs: true,
});
const ToolMap = loadedTools.reduce((map, tool) => {
@@ -378,21 +377,21 @@ async function loadAgentTools({ req, agent_id, tools, tool_resources, openAIApiK
if (!tools || tools.length === 0) {
return {};
}
- const loadedTools = await loadTools({
+ const { loadedTools, toolContextMap } = await loadTools({
user: req.user.id,
// model: req.body.model ?? 'gpt-4o-mini',
tools,
functions: true,
+ isAgent: agent_id != null,
options: {
req,
openAIApiKey,
tool_resources,
- returnMetadata: true,
processFileURL,
uploadImageBuffer,
+ returnMetadata: true,
fileStrategy: req.app.locals.fileStrategy,
},
- skipSpecs: true,
});
const agentTools = [];
@@ -403,16 +402,19 @@ async function loadAgentTools({ req, agent_id, tools, tool_resources, openAIApiK
continue;
}
- const toolInstance = toolFn(
- async (...args) => {
- return tool['_call'](...args);
- },
- {
- name: tool.name,
- description: tool.description,
- schema: tool.schema,
- },
- );
+ const toolDefinition = {
+ name: tool.name,
+ schema: tool.schema,
+ description: tool.description,
+ };
+
+ if (imageGenTools.has(tool.name)) {
+ toolDefinition.responseFormat = 'content_and_artifact';
+ }
+
+ const toolInstance = toolFn(async (...args) => {
+ return tool['_call'](...args);
+ }, toolDefinition);
agentTools.push(toolInstance);
}
@@ -476,6 +478,7 @@ async function loadAgentTools({ req, agent_id, tools, tool_resources, openAIApiK
return {
tools: agentTools,
+ toolContextMap,
};
}
diff --git a/api/server/services/start/interface.js b/api/server/services/start/interface.js
index bf31eb78b8..10db2fd3a8 100644
--- a/api/server/services/start/interface.js
+++ b/api/server/services/start/interface.js
@@ -32,17 +32,20 @@ async function loadDefaultInterface(config, configDefaults, roleName = SystemRol
bookmarks: interfaceConfig?.bookmarks ?? defaults.bookmarks,
prompts: interfaceConfig?.prompts ?? defaults.prompts,
multiConvo: interfaceConfig?.multiConvo ?? defaults.multiConvo,
+ agents: interfaceConfig?.agents ?? defaults.agents,
});
await updateAccessPermissions(roleName, {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: loadedInterface.prompts },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: loadedInterface.bookmarks },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: loadedInterface.multiConvo },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: loadedInterface.agents },
});
await updateAccessPermissions(SystemRoles.ADMIN, {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: loadedInterface.prompts },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: loadedInterface.bookmarks },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: loadedInterface.multiConvo },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: loadedInterface.agents },
});
let i = 0;
diff --git a/api/server/services/start/interface.spec.js b/api/server/services/start/interface.spec.js
index 62239a6a29..0041246433 100644
--- a/api/server/services/start/interface.spec.js
+++ b/api/server/services/start/interface.spec.js
@@ -7,8 +7,15 @@ jest.mock('~/models/Role', () => ({
}));
describe('loadDefaultInterface', () => {
- it('should call updateAccessPermissions with the correct parameters when prompts and bookmarks are true', async () => {
- const config = { interface: { prompts: true, bookmarks: true } };
+ it('should call updateAccessPermissions with the correct parameters when permission types are true', async () => {
+ const config = {
+ interface: {
+ prompts: true,
+ bookmarks: true,
+ multiConvo: true,
+ agents: true,
+ },
+ };
const configDefaults = { interface: {} };
await loadDefaultInterface(config, configDefaults);
@@ -16,12 +23,20 @@ describe('loadDefaultInterface', () => {
expect(updateAccessPermissions).toHaveBeenCalledWith(SystemRoles.USER, {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: true },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: true },
- [PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: undefined },
+ [PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: true },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: true },
});
});
- it('should call updateAccessPermissions with false when prompts and bookmarks are false', async () => {
- const config = { interface: { prompts: false, bookmarks: false } };
+ it('should call updateAccessPermissions with false when permission types are false', async () => {
+ const config = {
+ interface: {
+ prompts: false,
+ bookmarks: false,
+ multiConvo: false,
+ agents: false,
+ },
+ };
const configDefaults = { interface: {} };
await loadDefaultInterface(config, configDefaults);
@@ -29,11 +44,12 @@ describe('loadDefaultInterface', () => {
expect(updateAccessPermissions).toHaveBeenCalledWith(SystemRoles.USER, {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: false },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: false },
- [PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: undefined },
+ [PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: false },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: false },
});
});
- it('should call updateAccessPermissions with undefined when prompts and bookmarks are not specified in config', async () => {
+ it('should call updateAccessPermissions with undefined when permission types are not specified in config', async () => {
const config = {};
const configDefaults = { interface: {} };
@@ -43,11 +59,19 @@ describe('loadDefaultInterface', () => {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: undefined },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: undefined },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: undefined },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: undefined },
});
});
- it('should call updateAccessPermissions with undefined when prompts and bookmarks are explicitly undefined', async () => {
- const config = { interface: { prompts: undefined, bookmarks: undefined } };
+ it('should call updateAccessPermissions with undefined when permission types are explicitly undefined', async () => {
+ const config = {
+ interface: {
+ prompts: undefined,
+ bookmarks: undefined,
+ multiConvo: undefined,
+ agents: undefined,
+ },
+ };
const configDefaults = { interface: {} };
await loadDefaultInterface(config, configDefaults);
@@ -56,11 +80,19 @@ describe('loadDefaultInterface', () => {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: undefined },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: undefined },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: undefined },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: undefined },
});
});
- it('should call updateAccessPermissions with mixed values for prompts and bookmarks', async () => {
- const config = { interface: { prompts: true, bookmarks: false } };
+ it('should call updateAccessPermissions with mixed values for permission types', async () => {
+ const config = {
+ interface: {
+ prompts: true,
+ bookmarks: false,
+ multiConvo: undefined,
+ agents: true,
+ },
+ };
const configDefaults = { interface: {} };
await loadDefaultInterface(config, configDefaults);
@@ -69,19 +101,28 @@ describe('loadDefaultInterface', () => {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: true },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: false },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: undefined },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: true },
});
});
it('should call updateAccessPermissions with true when config is undefined', async () => {
const config = undefined;
- const configDefaults = { interface: { prompts: true, bookmarks: true } };
+ const configDefaults = {
+ interface: {
+ prompts: true,
+ bookmarks: true,
+ multiConvo: true,
+ agents: true,
+ },
+ };
await loadDefaultInterface(config, configDefaults);
expect(updateAccessPermissions).toHaveBeenCalledWith(SystemRoles.USER, {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: true },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: true },
- [PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: undefined },
+ [PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: true },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: true },
});
});
@@ -95,6 +136,7 @@ describe('loadDefaultInterface', () => {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: undefined },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: undefined },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: true },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: undefined },
});
});
@@ -108,6 +150,7 @@ describe('loadDefaultInterface', () => {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: undefined },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: undefined },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: false },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: undefined },
});
});
@@ -121,11 +164,19 @@ describe('loadDefaultInterface', () => {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: undefined },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: undefined },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: undefined },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: undefined },
});
});
it('should call updateAccessPermissions with all interface options including multiConvo', async () => {
- const config = { interface: { prompts: true, bookmarks: false, multiConvo: true } };
+ const config = {
+ interface: {
+ prompts: true,
+ bookmarks: false,
+ multiConvo: true,
+ agents: false,
+ },
+ };
const configDefaults = { interface: {} };
await loadDefaultInterface(config, configDefaults);
@@ -134,12 +185,20 @@ describe('loadDefaultInterface', () => {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: true },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: false },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: true },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: false },
});
});
it('should use default values for multiConvo when config is undefined', async () => {
const config = undefined;
- const configDefaults = { interface: { prompts: true, bookmarks: true, multiConvo: false } };
+ const configDefaults = {
+ interface: {
+ prompts: true,
+ bookmarks: true,
+ multiConvo: false,
+ agents: undefined,
+ },
+ };
await loadDefaultInterface(config, configDefaults);
@@ -147,6 +206,7 @@ describe('loadDefaultInterface', () => {
[PermissionTypes.PROMPTS]: { [Permissions.USE]: true },
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: true },
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: false },
+ [PermissionTypes.AGENTS]: { [Permissions.USE]: undefined },
});
});
});
diff --git a/api/server/utils/handleText.js b/api/server/utils/handleText.js
index 5a32394fcd..92f8253fc7 100644
--- a/api/server/utils/handleText.js
+++ b/api/server/utils/handleText.js
@@ -196,14 +196,11 @@ function generateConfig(key, baseURL, endpoint) {
if (agents) {
config.capabilities = [
+ AgentCapabilities.execute_code,
AgentCapabilities.file_search,
AgentCapabilities.actions,
AgentCapabilities.tools,
];
-
- if (key === 'EXPERIMENTAL_RUN_CODE') {
- config.capabilities.push(AgentCapabilities.execute_code);
- }
}
if (assistants && endpoint === EModelEndpoint.azureAssistants) {
diff --git a/api/typedefs.js b/api/typedefs.js
index 8c1af11a69..a80a25609d 100644
--- a/api/typedefs.js
+++ b/api/typedefs.js
@@ -56,12 +56,33 @@
* @memberof typedefs
*/
+/**
+ * @exports BaseMessage
+ * @typedef {import('@langchain/core/messages').BaseMessage} BaseMessage
+ * @memberof typedefs
+ */
+
/**
* @exports UsageMetadata
* @typedef {import('@langchain/core/messages').UsageMetadata} UsageMetadata
* @memberof typedefs
*/
+/**
+ * @exports GraphRunnableConfig
+ * @typedef {import('@langchain/core/runnables').RunnableConfig<{
+ * req: ServerRequest;
+ * thread_id: string;
+ * run_id: string;
+ * agent_id: string;
+ * name: string;
+ * agent_index: number;
+ * last_agent_index: number;
+ * hide_sequential_outputs: boolean;
+ * }>} GraphRunnableConfig
+ * @memberof typedefs
+ */
+
/**
* @exports Ollama
* @typedef {import('ollama').Ollama} Ollama
@@ -689,6 +710,12 @@
* @memberof typedefs
*/
+/**
+ * @exports ToolCallData
+ * @typedef {import('~/models/schema/toolCallSchema.js').ToolCallData} ToolCallData
+ * @memberof typedefs
+ */
+
/**
* @exports MongoUser
* @typedef {import('~/models/schema/userSchema.js').MongoUser} MongoUser
@@ -803,6 +830,12 @@
* @memberof typedefs
*/
+/**
+ * @exports AgentToolResources
+ * @typedef {import('librechat-data-provider').AgentToolResources} AgentToolResources
+ * @memberof typedefs
+ */
+
/**
* @exports AgentCreateParams
* @typedef {import('librechat-data-provider').AgentCreateParams} AgentCreateParams
diff --git a/client/public/assets/c.svg b/client/public/assets/c.svg
new file mode 100644
index 0000000000..fc75a6258b
--- /dev/null
+++ b/client/public/assets/c.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>C</title><path d="M16.5921 9.1962s-.354-3.298-3.627-3.39c-3.2741-.09-4.9552 2.474-4.9552 6.14 0 3.6651 1.858 6.5972 5.0451 6.5972 3.184 0 3.5381-3.665 3.5381-3.665l6.1041.365s.36 3.31-2.196 5.836c-2.552 2.5241-5.6901 2.9371-7.8762 2.9201-2.19-.017-5.2261.034-8.1602-2.97-2.938-3.0101-3.436-5.9302-3.436-8.8002 0-2.8701.556-6.6702 4.047-9.5502C7.444.72 9.849 0 12.254 0c10.0422 0 10.7172 9.2602 10.7172 9.2602z"/></svg>
\ No newline at end of file
diff --git a/client/public/assets/cplusplus.svg b/client/public/assets/cplusplus.svg
new file mode 100644
index 0000000000..fe2f58d6af
--- /dev/null
+++ b/client/public/assets/cplusplus.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>C++</title><path d="M22.394 6c-.167-.29-.398-.543-.652-.69L12.926.22c-.509-.294-1.34-.294-1.848 0L2.26 5.31c-.508.293-.923 1.013-.923 1.6v10.18c0 .294.104.62.271.91.167.29.398.543.652.69l8.816 5.09c.508.293 1.34.293 1.848 0l8.816-5.09c.254-.147.485-.4.652-.69.167-.29.27-.616.27-.91V6.91c.003-.294-.1-.62-.268-.91zM12 19.11c-3.92 0-7.109-3.19-7.109-7.11 0-3.92 3.19-7.11 7.11-7.11a7.133 7.133 0 016.156 3.553l-3.076 1.78a3.567 3.567 0 00-3.08-1.78A3.56 3.56 0 008.444 12 3.56 3.56 0 0012 15.555a3.57 3.57 0 003.08-1.778l3.078 1.78A7.135 7.135 0 0112 19.11zm7.11-6.715h-.79v.79h-.79v-.79h-.79v-.79h.79v-.79h.79v.79h.79zm2.962 0h-.79v.79h-.79v-.79h-.79v-.79h.79v-.79h.79v.79h.79z"/></svg>
\ No newline at end of file
diff --git a/client/public/assets/fortran.svg b/client/public/assets/fortran.svg
new file mode 100644
index 0000000000..44ae0a8e5f
--- /dev/null
+++ b/client/public/assets/fortran.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Fortran</title><path d="M19.536 0H4.464A4.463 4.463 0 0 0 0 4.464v15.073A4.463 4.463 0 0 0 4.464 24h15.073A4.463 4.463 0 0 0 24 19.536V4.464A4.463 4.463 0 0 0 19.536 0zm1.193 6.493v3.871l-.922-.005c-.507-.003-.981-.021-1.052-.041-.128-.036-.131-.05-.192-.839-.079-1.013-.143-1.462-.306-2.136-.352-1.457-1.096-2.25-2.309-2.463-.509-.089-2.731-.176-4.558-.177L10.13 4.7v5.82l.662-.033c.757-.038 1.353-.129 1.64-.252.306-.131.629-.462.781-.799.158-.352.262-.815.345-1.542.033-.286.07-.572.083-.636.024-.116.028-.117 1.036-.117h1.012v9.3h-2.062l-.035-.536c-.063-.971-.252-1.891-.479-2.331-.311-.601-.922-.871-2.151-.95a11.422 11.422 0 0 1-.666-.059l-.172-.027.02 2.926c.021 3.086.03 3.206.265 3.465.241.266.381.284 2.827.368.05.002.065.246.065 1.041v1.039H3.271v-1.039c0-.954.007-1.039.091-1.041.05-.001.543-.023 1.097-.049.891-.042 1.033-.061 1.244-.167a.712.712 0 0 0 .345-.328c.106-.206.107-.254.107-6.78 0-6.133-.006-6.584-.09-6.737a.938.938 0 0 0-.553-.436c-.104-.032-.65-.07-1.215-.086l-1.026-.027V2.622h17.458v3.871z"/></svg>
\ No newline at end of file
diff --git a/client/public/assets/go.svg b/client/public/assets/go.svg
new file mode 100644
index 0000000000..0cadd56b11
--- /dev/null
+++ b/client/public/assets/go.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Go</title><path d="M1.811 10.231c-.047 0-.058-.023-.035-.059l.246-.315c.023-.035.081-.058.128-.058h4.172c.046 0 .058.035.035.07l-.199.303c-.023.036-.082.07-.117.07zM.047 11.306c-.047 0-.059-.023-.035-.058l.245-.316c.023-.035.082-.058.129-.058h5.328c.047 0 .07.035.058.07l-.093.28c-.012.047-.058.07-.105.07zm2.828 1.075c-.047 0-.059-.035-.035-.07l.163-.292c.023-.035.07-.07.117-.07h2.337c.047 0 .07.035.07.082l-.023.28c0 .047-.047.082-.082.082zm12.129-2.36c-.736.187-1.239.327-1.963.514-.176.046-.187.058-.34-.117-.174-.199-.303-.327-.548-.444-.737-.362-1.45-.257-2.115.175-.795.514-1.204 1.274-1.192 2.22.011.935.654 1.706 1.577 1.835.795.105 1.46-.175 1.987-.77.105-.13.198-.27.315-.434H10.47c-.245 0-.304-.152-.222-.35.152-.362.432-.97.596-1.274a.315.315 0 01.292-.187h4.253c-.023.316-.023.631-.07.947a4.983 4.983 0 01-.958 2.29c-.841 1.11-1.94 1.8-3.33 1.986-1.145.152-2.209-.07-3.143-.77-.865-.655-1.356-1.52-1.484-2.595-.152-1.274.222-2.419.993-3.424.83-1.086 1.928-1.776 3.272-2.02 1.098-.2 2.15-.07 3.096.571.62.41 1.063.97 1.356 1.648.07.105.023.164-.117.2m3.868 6.461c-1.064-.024-2.034-.328-2.852-1.029a3.665 3.665 0 01-1.262-2.255c-.21-1.32.152-2.489.947-3.529.853-1.122 1.881-1.706 3.272-1.95 1.192-.21 2.314-.095 3.33.595.923.63 1.496 1.484 1.648 2.605.198 1.578-.257 2.863-1.344 3.962-.771.783-1.718 1.273-2.805 1.495-.315.06-.63.07-.934.106zm2.78-4.72c-.011-.153-.011-.27-.034-.387-.21-1.157-1.274-1.81-2.384-1.554-1.087.245-1.788.935-2.045 2.033-.21.912.234 1.835 1.075 2.21.643.28 1.285.244 1.905-.07.923-.48 1.425-1.228 1.484-2.233z"/></svg>
\ No newline at end of file
diff --git a/client/public/assets/nodedotjs.svg b/client/public/assets/nodedotjs.svg
new file mode 100644
index 0000000000..281c829627
--- /dev/null
+++ b/client/public/assets/nodedotjs.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Node.js</title><path d="M11.998,24c-0.321,0-0.641-0.084-0.922-0.247l-2.936-1.737c-0.438-0.245-0.224-0.332-0.08-0.383 c0.585-0.203,0.703-0.25,1.328-0.604c0.065-0.037,0.151-0.023,0.218,0.017l2.256,1.339c0.082,0.045,0.197,0.045,0.272,0l8.795-5.076 c0.082-0.047,0.134-0.141,0.134-0.238V6.921c0-0.099-0.053-0.192-0.137-0.242l-8.791-5.072c-0.081-0.047-0.189-0.047-0.271,0 L3.075,6.68C2.99,6.729,2.936,6.825,2.936,6.921v10.15c0,0.097,0.054,0.189,0.139,0.235l2.409,1.392 c1.307,0.654,2.108-0.116,2.108-0.89V7.787c0-0.142,0.114-0.253,0.256-0.253h1.115c0.139,0,0.255,0.112,0.255,0.253v10.021 c0,1.745-0.95,2.745-2.604,2.745c-0.508,0-0.909,0-2.026-0.551L2.28,18.675c-0.57-0.329-0.922-0.945-0.922-1.604V6.921 c0-0.659,0.353-1.275,0.922-1.603l8.795-5.082c0.557-0.315,1.296-0.315,1.848,0l8.794,5.082c0.57,0.329,0.924,0.944,0.924,1.603 v10.15c0,0.659-0.354,1.273-0.924,1.604l-8.794,5.078C12.643,23.916,12.324,24,11.998,24z M19.099,13.993 c0-1.9-1.284-2.406-3.987-2.763c-2.731-0.361-3.009-0.548-3.009-1.187c0-0.528,0.235-1.233,2.258-1.233 c1.807,0,2.473,0.389,2.747,1.607c0.024,0.115,0.129,0.199,0.247,0.199h1.141c0.071,0,0.138-0.031,0.186-0.081 c0.048-0.054,0.074-0.123,0.067-0.196c-0.177-2.098-1.571-3.076-4.388-3.076c-2.508,0-4.004,1.058-4.004,2.833 c0,1.925,1.488,2.457,3.895,2.695c2.88,0.282,3.103,0.703,3.103,1.269c0,0.983-0.789,1.402-2.642,1.402 c-2.327,0-2.839-0.584-3.011-1.742c-0.02-0.124-0.126-0.215-0.253-0.215h-1.137c-0.141,0-0.254,0.112-0.254,0.253 c0,1.482,0.806,3.248,4.655,3.248C17.501,17.007,19.099,15.91,19.099,13.993z"/></svg>
\ No newline at end of file
diff --git a/client/public/assets/php.svg b/client/public/assets/php.svg
new file mode 100644
index 0000000000..a08156aff7
--- /dev/null
+++ b/client/public/assets/php.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>PHP</title><path d="M7.01 10.207h-.944l-.515 2.648h.838c.556 0 .97-.105 1.242-.314.272-.21.455-.559.55-1.049.092-.47.05-.802-.124-.995-.175-.193-.523-.29-1.047-.29zM12 5.688C5.373 5.688 0 8.514 0 12s5.373 6.313 12 6.313S24 15.486 24 12c0-3.486-5.373-6.312-12-6.312zm-3.26 7.451c-.261.25-.575.438-.917.551-.336.108-.765.164-1.285.164H5.357l-.327 1.681H3.652l1.23-6.326h2.65c.797 0 1.378.209 1.744.628.366.418.476 1.002.33 1.752a2.836 2.836 0 0 1-.305.847c-.143.255-.33.49-.561.703zm4.024.715l.543-2.799c.063-.318.039-.536-.068-.651-.107-.116-.336-.174-.687-.174H11.46l-.704 3.625H9.388l1.23-6.327h1.367l-.327 1.682h1.218c.767 0 1.295.134 1.586.401s.378.7.263 1.299l-.572 2.944h-1.389zm7.597-2.265a2.782 2.782 0 0 1-.305.847c-.143.255-.33.49-.561.703a2.44 2.44 0 0 1-.917.551c-.336.108-.765.164-1.286.164h-1.18l-.327 1.682h-1.378l1.23-6.326h2.649c.797 0 1.378.209 1.744.628.366.417.477 1.001.331 1.751zM17.766 10.207h-.943l-.516 2.648h.838c.557 0 .971-.105 1.242-.314.272-.21.455-.559.551-1.049.092-.47.049-.802-.125-.995s-.524-.29-1.047-.29z"/></svg>
\ No newline at end of file
diff --git a/client/public/assets/python.svg b/client/public/assets/python.svg
new file mode 100644
index 0000000000..30587d8164
--- /dev/null
+++ b/client/public/assets/python.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Python</title><path d="M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.77l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.17l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05-.05-1.23.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.18l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09zm13.09 3.95l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08z"/></svg>
\ No newline at end of file
diff --git a/client/public/assets/rust.svg b/client/public/assets/rust.svg
new file mode 100644
index 0000000000..b95ce42ae7
--- /dev/null
+++ b/client/public/assets/rust.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Rust</title><path d="M23.8346 11.7033l-1.0073-.6236a13.7268 13.7268 0 00-.0283-.2936l.8656-.8069a.3483.3483 0 00-.1154-.578l-1.1066-.414a8.4958 8.4958 0 00-.087-.2856l.6904-.9587a.3462.3462 0 00-.2257-.5446l-1.1663-.1894a9.3574 9.3574 0 00-.1407-.2622l.49-1.0761a.3437.3437 0 00-.0274-.3361.3486.3486 0 00-.3006-.154l-1.1845.0416a6.7444 6.7444 0 00-.1873-.2268l.2723-1.153a.3472.3472 0 00-.417-.4172l-1.1532.2724a14.0183 14.0183 0 00-.2278-.1873l.0415-1.1845a.3442.3442 0 00-.49-.328l-1.076.491c-.0872-.0476-.1742-.0952-.2623-.1407l-.1903-1.1673A.3483.3483 0 0016.256.955l-.9597.6905a8.4867 8.4867 0 00-.2855-.086l-.414-1.1066a.3483.3483 0 00-.5781-.1154l-.8069.8666a9.2936 9.2936 0 00-.2936-.0284L12.2946.1683a.3462.3462 0 00-.5892 0l-.6236 1.0073a13.7383 13.7383 0 00-.2936.0284L9.9803.3374a.3462.3462 0 00-.578.1154l-.4141 1.1065c-.0962.0274-.1903.0567-.2855.086L7.744.955a.3483.3483 0 00-.5447.2258L7.009 2.348a9.3574 9.3574 0 00-.2622.1407l-1.0762-.491a.3462.3462 0 00-.49.328l.0416 1.1845a7.9826 7.9826 0 00-.2278.1873L3.8413 3.425a.3472.3472 0 00-.4171.4171l.2713 1.1531c-.0628.075-.1255.1509-.1863.2268l-1.1845-.0415a.3462.3462 0 00-.328.49l.491 1.0761a9.167 9.167 0 00-.1407.2622l-1.1662.1894a.3483.3483 0 00-.2258.5446l.6904.9587a13.303 13.303 0 00-.087.2855l-1.1065.414a.3483.3483 0 00-.1155.5781l.8656.807a9.2936 9.2936 0 00-.0283.2935l-1.0073.6236a.3442.3442 0 000 .5892l1.0073.6236c.008.0982.0182.1964.0283.2936l-.8656.8079a.3462.3462 0 00.1155.578l1.1065.4141c.0273.0962.0567.1914.087.2855l-.6904.9587a.3452.3452 0 00.2268.5447l1.1662.1893c.0456.088.0922.1751.1408.2622l-.491 1.0762a.3462.3462 0 00.328.49l1.1834-.0415c.0618.0769.1235.1528.1873.2277l-.2713 1.1541a.3462.3462 0 00.4171.4161l1.153-.2713c.075.0638.151.1255.2279.1863l-.0415 1.1845a.3442.3442 0 00.49.327l1.0761-.49c.087.0486.1741.0951.2622.1407l.1903 1.1662a.3483.3483 0 00.5447.2268l.9587-.6904a9.299 9.299 0 00.2855.087l.414 1.1066a.3452.3452 0 00.5781.1154l.8079-.8656c.0972.0111.1954.0203.2936.0294l.6236 1.0073a.3472.3472 0 00.5892 0l.6236-1.0073c.0982-.0091.1964-.0183.2936-.0294l.8069.8656a.3483.3483 0 00.578-.1154l.4141-1.1066a8.4626 8.4626 0 00.2855-.087l.9587.6904a.3452.3452 0 00.5447-.2268l.1903-1.1662c.088-.0456.1751-.0931.2622-.1407l1.0762.49a.3472.3472 0 00.49-.327l-.0415-1.1845a6.7267 6.7267 0 00.2267-.1863l1.1531.2713a.3472.3472 0 00.4171-.416l-.2713-1.1542c.0628-.0749.1255-.1508.1863-.2278l1.1845.0415a.3442.3442 0 00.328-.49l-.49-1.076c.0475-.0872.0951-.1742.1407-.2623l1.1662-.1893a.3483.3483 0 00.2258-.5447l-.6904-.9587.087-.2855 1.1066-.414a.3462.3462 0 00.1154-.5781l-.8656-.8079c.0101-.0972.0202-.1954.0283-.2936l1.0073-.6236a.3442.3442 0 000-.5892zm-6.7413 8.3551a.7138.7138 0 01.2986-1.396.714.714 0 11-.2997 1.396zm-.3422-2.3142a.649.649 0 00-.7715.5l-.3573 1.6685c-1.1035.501-2.3285.7795-3.6193.7795a8.7368 8.7368 0 01-3.6951-.814l-.3574-1.6684a.648.648 0 00-.7714-.499l-1.473.3158a8.7216 8.7216 0 01-.7613-.898h7.1676c.081 0 .1356-.0141.1356-.088v-2.536c0-.074-.0536-.0881-.1356-.0881h-2.0966v-1.6077h2.2677c.2065 0 1.1065.0587 1.394 1.2088.0901.3533.2875 1.5044.4232 1.8729.1346.413.6833 1.2381 1.2685 1.2381h3.5716a.7492.7492 0 00.1296-.0131 8.7874 8.7874 0 01-.8119.9526zM6.8369 20.024a.714.714 0 11-.2997-1.396.714.714 0 01.2997 1.396zM4.1177 8.9972a.7137.7137 0 11-1.304.5791.7137.7137 0 011.304-.579zm-.8352 1.9813l1.5347-.6824a.65.65 0 00.33-.8585l-.3158-.7147h1.2432v5.6025H3.5669a8.7753 8.7753 0 01-.2834-3.348zm6.7343-.5437V8.7836h2.9601c.153 0 1.0792.1772 1.0792.8697 0 .575-.7107.7815-1.2948.7815zm10.7574 1.4862c0 .2187-.008.4363-.0243.651h-.9c-.09 0-.1265.0586-.1265.1477v.413c0 .973-.5487 1.1846-1.0296 1.2382-.4576.0517-.9648-.1913-1.0275-.4717-.2704-1.5186-.7198-1.8436-1.4305-2.4034.8817-.5599 1.799-1.386 1.799-2.4915 0-1.1936-.819-1.9458-1.3769-2.3153-.7825-.5163-1.6491-.6195-1.883-.6195H5.4682a8.7651 8.7651 0 014.907-2.7699l1.0974 1.151a.648.648 0 00.9182.0213l1.227-1.1743a8.7753 8.7753 0 016.0044 4.2762l-.8403 1.8982a.652.652 0 00.33.8585l1.6178.7188c.0283.2875.0425.577.0425.8717zm-9.3006-9.5993a.7128.7128 0 11.984 1.0316.7137.7137 0 01-.984-1.0316zm8.3389 6.71a.7107.7107 0 01.9395-.3625.7137.7137 0 11-.9405.3635z"/></svg>
\ No newline at end of file
diff --git a/client/public/assets/tsnode.svg b/client/public/assets/tsnode.svg
new file mode 100644
index 0000000000..5cc1aadb0e
--- /dev/null
+++ b/client/public/assets/tsnode.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>ts-node</title><path d="M11.999 0c-.196 0-.392.05-.568.153L2.026 5.58a1.135 1.135 0 00-.568.983V17.43c0 .406.216.781.568.984l5.787 3.344v-7.344H4.748v-1.943h8.342v1.943h-3.065v8.622l1.406.812c.351.203.784.203 1.136 0l2.317-1.338a3.958 3.958 0 01-1.195-1.413l1.801-1.042c.361.59.806 1.06 1.48 1.25l2.174-1.256c-.127-.568-.698-.823-1.584-1.21l-.553-.238c-1.596-.68-2.655-1.532-2.655-3.334 0-1.658 1.265-2.922 3.24-2.922 1.406 0 2.417.49 3.144 1.77l-1.723 1.105c-.379-.68-.79-.948-1.421-.948-.648 0-1.06.41-1.06.948 0 .663.412.932 1.36 1.343l.553.237c1.336.573 2.255 1.155 2.676 2.107l.853-.493c.352-.203.568-.578.568-.984V6.565c0-.406-.216-.782-.568-.984L12.567.153A1.134 1.134 0 0011.999 0z"/></svg>
\ No newline at end of file
diff --git a/client/src/Providers/CodeBlockContext.tsx b/client/src/Providers/CodeBlockContext.tsx
new file mode 100644
index 0000000000..915e740840
--- /dev/null
+++ b/client/src/Providers/CodeBlockContext.tsx
@@ -0,0 +1,34 @@
+import { createContext, useContext, ReactNode, useCallback, useRef } from 'react';
+
+type TCodeBlockContext = {
+ getNextIndex: (skip: boolean) => number;
+ resetCounter: () => void;
+ // codeBlocks: Map<number, string>;
+};
+
+export const CodeBlockContext = createContext<TCodeBlockContext>({} as TCodeBlockContext);
+export const useCodeBlockContext = () => useContext(CodeBlockContext);
+
+export function CodeBlockProvider({ children }: { children: ReactNode }) {
+ const counterRef = useRef(0);
+ // const codeBlocks = useRef(new Map<number, string>()).current;
+
+ const getNextIndex = useCallback((skip: boolean) => {
+ if (skip) {
+ return counterRef.current;
+ }
+ const nextIndex = counterRef.current;
+ counterRef.current += 1;
+ return nextIndex;
+ }, []);
+
+ const resetCounter = useCallback(() => {
+ counterRef.current = 0;
+ }, []);
+
+ return (
+ <CodeBlockContext.Provider value={{ getNextIndex, resetCounter }}>
+ {children}
+ </CodeBlockContext.Provider>
+ );
+}
diff --git a/client/src/Providers/MessageContext.tsx b/client/src/Providers/MessageContext.tsx
new file mode 100644
index 0000000000..6673dd2eb3
--- /dev/null
+++ b/client/src/Providers/MessageContext.tsx
@@ -0,0 +1,9 @@
+import { createContext, useContext } from 'react';
+type MessageContext = {
+ messageId: string;
+ partIndex?: number;
+ conversationId?: string | null;
+};
+
+export const MessageContext = createContext<MessageContext>({} as MessageContext);
+export const useMessageContext = () => useContext(MessageContext);
diff --git a/client/src/Providers/ToolCallsMapContext.tsx b/client/src/Providers/ToolCallsMapContext.tsx
new file mode 100644
index 0000000000..516d3d77f0
--- /dev/null
+++ b/client/src/Providers/ToolCallsMapContext.tsx
@@ -0,0 +1,21 @@
+import { createContext, useContext } from 'react';
+import useToolCallsMap from '~/hooks/Plugins/useToolCallsMap';
+type ToolCallsMapContextType = ReturnType<typeof useToolCallsMap>;
+
+export const ToolCallsMapContext = createContext<ToolCallsMapContextType>(
+ {} as ToolCallsMapContextType,
+);
+export const useToolCallsMapContext = () => useContext(ToolCallsMapContext);
+
+interface ToolCallsMapProviderProps {
+ children: React.ReactNode;
+ conversationId: string;
+}
+
+export function ToolCallsMapProvider({ children, conversationId }: ToolCallsMapProviderProps) {
+ const toolCallsMap = useToolCallsMap({ conversationId });
+
+ return (
+ <ToolCallsMapContext.Provider value={toolCallsMap}>{children}</ToolCallsMapContext.Provider>
+ );
+}
diff --git a/client/src/Providers/index.ts b/client/src/Providers/index.ts
index be9036a51c..d777b5bb76 100644
--- a/client/src/Providers/index.ts
+++ b/client/src/Providers/index.ts
@@ -9,9 +9,12 @@ export * from './FileMapContext';
export * from './AddedChatContext';
export * from './ChatFormContext';
export * from './BookmarkContext';
+export * from './MessageContext';
export * from './DashboardContext';
export * from './AssistantsContext';
export * from './AgentsContext';
export * from './AssistantsMapContext';
export * from './AnnouncerContext';
export * from './AgentsMapContext';
+export * from './CodeBlockContext';
+export * from './ToolCallsMapContext';
diff --git a/client/src/common/agents-types.ts b/client/src/common/agents-types.ts
index fd268e8cb7..7f64f07882 100644
--- a/client/src/common/agents-types.ts
+++ b/client/src/common/agents-types.ts
@@ -11,6 +11,8 @@ export type TAgentOption = OptionWithIcon &
export type TAgentCapabilities = {
[AgentCapabilities.execute_code]: boolean;
[AgentCapabilities.file_search]: boolean;
+ [AgentCapabilities.end_after_tools]?: boolean;
+ [AgentCapabilities.hide_sequential_outputs]?: boolean;
};
export type AgentForm = {
@@ -23,4 +25,5 @@ export type AgentForm = {
model_parameters: AgentModelParameters;
tools?: string[];
provider?: AgentProvider | OptionWithIcon;
+ agent_ids?: string[];
} & TAgentCapabilities;
diff --git a/client/src/common/index.ts b/client/src/common/index.ts
index 85dda0700c..428f01017d 100644
--- a/client/src/common/index.ts
+++ b/client/src/common/index.ts
@@ -1,5 +1,6 @@
export * from './a11y';
export * from './artifacts';
export * from './types';
+export * from './tools';
export * from './assistants-types';
export * from './agents-types';
diff --git a/client/src/common/tools.ts b/client/src/common/tools.ts
new file mode 100644
index 0000000000..140f5678c1
--- /dev/null
+++ b/client/src/common/tools.ts
@@ -0,0 +1,6 @@
+import type { AuthType } from 'librechat-data-provider';
+
+export type ApiKeyFormData = {
+ apiKey: string;
+ authType?: string | AuthType;
+};
diff --git a/client/src/common/types.ts b/client/src/common/types.ts
index 3590b279b8..fe732ce0c0 100644
--- a/client/src/common/types.ts
+++ b/client/src/common/types.ts
@@ -1,36 +1,21 @@
-import React from 'react';
+import { RefObject } from 'react';
import { FileSources } from 'librechat-data-provider';
import type * as InputNumberPrimitive from 'rc-input-number';
import type { ColumnDef } from '@tanstack/react-table';
import type { SetterOrUpdater } from 'recoil';
-import type {
- TRole,
- TUser,
- Agent,
- Action,
- TPreset,
- TPlugin,
- TMessage,
- Assistant,
- TResPlugin,
- TLoginUser,
- AuthTypeEnum,
- TModelsConfig,
- TConversation,
- TStartupConfig,
- EModelEndpoint,
- TEndpointsConfig,
- ActionMetadata,
- AssistantDocument,
- AssistantsEndpoint,
- TMessageContentParts,
- AuthorizationTypeEnum,
- TSetOption as SetOption,
- TokenExchangeMethodEnum,
-} from 'librechat-data-provider';
+import type * as t from 'librechat-data-provider';
import type { UseMutationResult } from '@tanstack/react-query';
import type { LucideIcon } from 'lucide-react';
+export type CodeBarProps = {
+ lang: string;
+ error?: boolean;
+ plugin?: boolean;
+ blockIndex?: number;
+ allowExecution?: boolean;
+ codeRef: RefObject<HTMLElement>;
+};
+
export enum PromptsEditorMode {
SIMPLE = 'simple',
ADVANCED = 'advanced',
@@ -65,21 +50,21 @@ export type AudioChunk = {
export type AssistantListItem = {
id: string;
name: string;
- metadata: Assistant['metadata'];
+ metadata: t.Assistant['metadata'];
model: string;
};
export type AgentListItem = {
id: string;
name: string;
- avatar: Agent['avatar'];
+ avatar: t.Agent['avatar'];
};
-export type TPluginMap = Record<string, TPlugin>;
+export type TPluginMap = Record<string, t.TPlugin>;
export type GenericSetter<T> = (value: T | ((currentValue: T) => T)) => void;
-export type LastSelectedModels = Record<EModelEndpoint, string>;
+export type LastSelectedModels = Record<t.EModelEndpoint, string>;
export type LocalizeFunction = (phraseKey: string, ...values: string[]) => string;
@@ -145,11 +130,11 @@ export type FileSetter =
export type ActionAuthForm = {
/* General */
- type: AuthTypeEnum;
+ type: t.AuthTypeEnum;
saved_auth_fields: boolean;
/* API key */
api_key: string; // not nested
- authorization_type: AuthorizationTypeEnum;
+ authorization_type: t.AuthorizationTypeEnum;
custom_auth_header: string;
/* OAuth */
oauth_client_id: string; // not nested
@@ -157,23 +142,23 @@ export type ActionAuthForm = {
authorization_url: string;
client_url: string;
scope: string;
- token_exchange_method: TokenExchangeMethodEnum;
+ token_exchange_method: t.TokenExchangeMethodEnum;
};
-export type ActionWithNullableMetadata = Omit<Action, 'metadata'> & {
- metadata: ActionMetadata | null;
+export type ActionWithNullableMetadata = Omit<t.Action, 'metadata'> & {
+ metadata: t.ActionMetadata | null;
};
export type AssistantPanelProps = {
index?: number;
action?: ActionWithNullableMetadata;
- actions?: Action[];
+ actions?: t.Action[];
assistant_id?: string;
activePanel?: string;
- endpoint: AssistantsEndpoint;
+ endpoint: t.AssistantsEndpoint;
version: number | string;
- documentsMap: Map<string, AssistantDocument> | null;
- setAction: React.Dispatch<React.SetStateAction<Action | undefined>>;
+ documentsMap: Map<string, t.AssistantDocument> | null;
+ setAction: React.Dispatch<React.SetStateAction<t.Action | undefined>>;
setCurrentAssistantId: React.Dispatch<React.SetStateAction<string | undefined>>;
setActivePanel: React.Dispatch<React.SetStateAction<Panel>>;
};
@@ -182,11 +167,11 @@ export type AgentPanelProps = {
index?: number;
agent_id?: string;
activePanel?: string;
- action?: Action;
- actions?: Action[];
+ action?: t.Action;
+ actions?: t.Action[];
setActivePanel: React.Dispatch<React.SetStateAction<Panel>>;
- setAction: React.Dispatch<React.SetStateAction<Action | undefined>>;
- endpointsConfig?: TEndpointsConfig;
+ setAction: React.Dispatch<React.SetStateAction<t.Action | undefined>>;
+ endpointsConfig?: t.TEndpointsConfig;
setCurrentAgentId: React.Dispatch<React.SetStateAction<string | undefined>>;
};
@@ -199,7 +184,7 @@ export type AgentModelPanelProps = {
export type AugmentedColumnDef<TData, TValue> = ColumnDef<TData, TValue> & DataColumnMeta;
-export type TSetOption = SetOption;
+export type TSetOption = t.TSetOption;
export type TSetExample = (
i: number,
@@ -234,7 +219,7 @@ export type TShowToast = {
};
export type TBaseSettingsProps = {
- conversation: TConversation | TPreset | null;
+ conversation: t.TConversation | t.TPreset | null;
className?: string;
isPreset?: boolean;
readonly?: boolean;
@@ -255,7 +240,7 @@ export type TModelSelectProps = TSettingsProps & TModels;
export type TEditPresetProps = {
open: boolean;
onOpenChange: React.Dispatch<React.SetStateAction<boolean>>;
- preset: TPreset;
+ preset: t.TPreset;
title?: string;
};
@@ -266,18 +251,18 @@ export type TSetOptionsPayload = {
addExample: () => void;
removeExample: () => void;
setAgentOption: TSetOption;
- // getConversation: () => TConversation | TPreset | null;
+ // getConversation: () => t.TConversation | t.TPreset | null;
checkPluginSelection: (value: string) => boolean;
setTools: (newValue: string, remove?: boolean) => void;
setOptions?: TSetOptions;
};
export type TPresetItemProps = {
- preset: TPreset;
- value: TPreset;
- onSelect: (preset: TPreset) => void;
- onChangePreset: (preset: TPreset) => void;
- onDeletePreset: (preset: TPreset) => void;
+ preset: t.TPreset;
+ value: t.TPreset;
+ onSelect: (preset: t.TPreset) => void;
+ onChangePreset: (preset: t.TPreset) => void;
+ onDeletePreset: (preset: t.TPreset) => void;
};
export type TOnClick = (e: React.MouseEvent<HTMLButtonElement>) => void;
@@ -302,16 +287,16 @@ export type TOptions = {
isRegenerate?: boolean;
isContinued?: boolean;
isEdited?: boolean;
- overrideMessages?: TMessage[];
+ overrideMessages?: t.TMessage[];
};
export type TAskFunction = (props: TAskProps, options?: TOptions) => void;
export type TMessageProps = {
- conversation?: TConversation | null;
+ conversation?: t.TConversation | null;
messageId?: string | null;
- message?: TMessage;
- messagesTree?: TMessage[];
+ message?: t.TMessage;
+ messagesTree?: t.TMessage[];
currentEditId: string | number | null;
isSearchView?: boolean;
siblingIdx?: number;
@@ -330,7 +315,7 @@ export type TInitialProps = {
};
export type TAdditionalProps = {
ask: TAskFunction;
- message: TMessage;
+ message: t.TMessage;
isCreatedByUser: boolean;
siblingIdx: number;
enterEdit: (cancel: boolean) => void;
@@ -354,7 +339,7 @@ export type TDisplayProps = TText &
export type TConfigProps = {
userKey: string;
setUserKey: React.Dispatch<React.SetStateAction<string>>;
- endpoint: EModelEndpoint | string;
+ endpoint: t.EModelEndpoint | string;
};
export type TDangerButtonProps = {
@@ -389,18 +374,18 @@ export type TResError = {
};
export type TAuthContext = {
- user: TUser | undefined;
+ user: t.TUser | undefined;
token: string | undefined;
isAuthenticated: boolean;
error: string | undefined;
- login: (data: TLoginUser) => void;
+ login: (data: t.TLoginUser) => void;
logout: () => void;
setError: React.Dispatch<React.SetStateAction<string | undefined>>;
- roles?: Record<string, TRole | null | undefined>;
+ roles?: Record<string, t.TRole | null | undefined>;
};
export type TUserContext = {
- user?: TUser | undefined;
+ user?: t.TUser | undefined;
token: string | undefined;
isAuthenticated: boolean;
redirect?: string;
@@ -411,16 +396,16 @@ export type TAuthConfig = {
test?: boolean;
};
-export type IconProps = Pick<TMessage, 'isCreatedByUser' | 'model'> &
- Pick<TConversation, 'chatGptLabel' | 'modelLabel' | 'jailbreak'> & {
+export type IconProps = Pick<t.TMessage, 'isCreatedByUser' | 'model'> &
+ Pick<t.TConversation, 'chatGptLabel' | 'modelLabel' | 'jailbreak'> & {
size?: number;
button?: boolean;
iconURL?: string;
message?: boolean;
className?: string;
iconClassName?: string;
- endpoint?: EModelEndpoint | string | null;
- endpointType?: EModelEndpoint | null;
+ endpoint?: t.EModelEndpoint | string | null;
+ endpointType?: t.EModelEndpoint | null;
assistantName?: string;
agentName?: string;
error?: boolean;
@@ -440,7 +425,7 @@ export type VoiceOption = {
export type TMessageAudio = {
messageId?: string;
- content?: TMessageContentParts[] | string;
+ content?: t.TMessageContentParts[] | string;
className?: string;
isLast: boolean;
index: number;
@@ -482,12 +467,12 @@ export interface ExtendedFile {
export type ContextType = { navVisible: boolean; setNavVisible: (visible: boolean) => void };
export interface SwitcherProps {
- endpoint?: EModelEndpoint | null;
+ endpoint?: t.EModelEndpoint | null;
endpointKeyProvided: boolean;
isCollapsed: boolean;
}
export type TLoginLayoutContext = {
- startupConfig: TStartupConfig | null;
+ startupConfig: t.TStartupConfig | null;
startupConfigError: unknown;
isFetching: boolean;
error: string | null;
@@ -497,34 +482,34 @@ export type TLoginLayoutContext = {
};
export type NewConversationParams = {
- template?: Partial<TConversation>;
- preset?: Partial<TPreset>;
- modelsData?: TModelsConfig;
+ template?: Partial<t.TConversation>;
+ preset?: Partial<t.TPreset>;
+ modelsData?: t.TModelsConfig;
buildDefault?: boolean;
keepLatestMessage?: boolean;
keepAddedConvos?: boolean;
};
-export type ConvoGenerator = (params: NewConversationParams) => void | TConversation;
+export type ConvoGenerator = (params: NewConversationParams) => void | t.TConversation;
export type TBaseResData = {
- plugin?: TResPlugin;
+ plugin?: t.TResPlugin;
final?: boolean;
initial?: boolean;
- previousMessages?: TMessage[];
- conversation: TConversation;
+ previousMessages?: t.TMessage[];
+ conversation: t.TConversation;
conversationId?: string;
- runMessages?: TMessage[];
+ runMessages?: t.TMessage[];
};
export type TResData = TBaseResData & {
- requestMessage: TMessage;
- responseMessage: TMessage;
+ requestMessage: t.TMessage;
+ responseMessage: t.TMessage;
};
export type TFinalResData = TBaseResData & {
- requestMessage?: TMessage;
- responseMessage?: TMessage;
+ requestMessage?: t.TMessage;
+ responseMessage?: t.TMessage;
};
export type TVectorStore = {
diff --git a/client/src/components/Chat/AddMultiConvo.tsx b/client/src/components/Chat/AddMultiConvo.tsx
index 8ee85ebb3a..6cfeb04b9c 100644
--- a/client/src/components/Chat/AddMultiConvo.tsx
+++ b/client/src/components/Chat/AddMultiConvo.tsx
@@ -5,7 +5,6 @@ import { useChatContext, useAddedChatContext } from '~/Providers';
import { TooltipAnchor } from '~/components';
import { mainTextareaId } from '~/common';
import { useLocalize } from '~/hooks';
-import { cn } from '~/utils';
function AddMultiConvo() {
const { conversation } = useChatContext();
diff --git a/client/src/components/Chat/Input/Files/AttachFileMenu.tsx b/client/src/components/Chat/Input/Files/AttachFileMenu.tsx
new file mode 100644
index 0000000000..a6854d4a70
--- /dev/null
+++ b/client/src/components/Chat/Input/Files/AttachFileMenu.tsx
@@ -0,0 +1,100 @@
+import * as Ariakit from '@ariakit/react';
+import React, { useRef, useState } from 'react';
+import { FileSearch, ImageUpIcon, TerminalSquareIcon } from 'lucide-react';
+import { EToolResources } from 'librechat-data-provider';
+import { FileUpload, TooltipAnchor, DropdownPopup } from '~/components/ui';
+import { AttachmentIcon } from '~/components/svg';
+import { useLocalize } from '~/hooks';
+import { cn } from '~/utils';
+
+interface AttachFileProps {
+ isRTL: boolean;
+ disabled?: boolean | null;
+ handleFileChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
+ setToolResource?: React.Dispatch<React.SetStateAction<string | undefined>>;
+}
+
+const AttachFile = ({ isRTL, disabled, setToolResource, handleFileChange }: AttachFileProps) => {
+ const localize = useLocalize();
+ const isUploadDisabled = disabled ?? false;
+ const inputRef = useRef<HTMLInputElement>(null);
+ const [isPopoverActive, setIsPopoverActive] = useState(false);
+
+ const handleUploadClick = (isImage?: boolean) => {
+ if (!inputRef.current) {
+ return;
+ }
+ inputRef.current.value = '';
+ inputRef.current.accept = isImage === true ? 'image/*' : '';
+ inputRef.current.click();
+ inputRef.current.accept = '';
+ };
+
+ const dropdownItems = [
+ {
+ label: localize('com_ui_upload_image_input'),
+ onClick: () => {
+ setToolResource?.(undefined);
+ handleUploadClick(true);
+ },
+ icon: <ImageUpIcon className="icon-md" />,
+ },
+ {
+ label: localize('com_ui_upload_file_search'),
+ onClick: () => {
+ setToolResource?.(EToolResources.file_search);
+ handleUploadClick();
+ },
+ icon: <FileSearch className="icon-md" />,
+ },
+ {
+ label: localize('com_ui_upload_code_files'),
+ onClick: () => {
+ setToolResource?.(EToolResources.execute_code);
+ handleUploadClick();
+ },
+ icon: <TerminalSquareIcon className="icon-md" />,
+ },
+ ];
+
+ const menuTrigger = (
+ <TooltipAnchor
+ render={
+ <Ariakit.MenuButton
+ disabled={isUploadDisabled}
+ id="attach-file-menu-button"
+ aria-label="Attach File Options"
+ className={cn(
+ 'absolute flex size-[35px] items-center justify-center rounded-full p-1 transition-colors hover:bg-surface-hover focus:outline-none focus:ring-2 focus:ring-primary focus:ring-opacity-50',
+ isRTL ? 'bottom-2 right-2' : 'bottom-2 left-1 md:left-2',
+ )}
+ >
+ <div className="flex w-full items-center justify-center gap-2">
+ <AttachmentIcon />
+ </div>
+ </Ariakit.MenuButton>
+ }
+ id="attach-file-menu-button"
+ description={localize('com_sidepanel_attach_files')}
+ disabled={isUploadDisabled}
+ />
+ );
+
+ return (
+ <FileUpload ref={inputRef} handleFileChange={handleFileChange}>
+ <div className="relative">
+ <DropdownPopup
+ menuId="attach-file-menu"
+ isOpen={isPopoverActive}
+ setIsOpen={setIsPopoverActive}
+ modal={true}
+ trigger={menuTrigger}
+ items={dropdownItems}
+ iconClassName="mr-0"
+ />
+ </div>
+ </FileUpload>
+ );
+};
+
+export default React.memo(AttachFile);
diff --git a/client/src/components/Chat/Input/Files/FileFormWrapper.tsx b/client/src/components/Chat/Input/Files/FileFormWrapper.tsx
index 230b303615..a0310cf7f2 100644
--- a/client/src/components/Chat/Input/Files/FileFormWrapper.tsx
+++ b/client/src/components/Chat/Input/Files/FileFormWrapper.tsx
@@ -1,12 +1,14 @@
-import { memo } from 'react';
+import { memo, useMemo } from 'react';
import { useRecoilValue } from 'recoil';
import {
supportsFiles,
mergeFileConfig,
+ isAgentsEndpoint,
EndpointFileConfig,
fileConfig as defaultFileConfig,
} from 'librechat-data-provider';
import { useGetFileConfig } from '~/data-provider';
+import AttachFileMenu from './AttachFileMenu';
import { useChatContext } from '~/Providers';
import { useFileHandling } from '~/hooks';
import AttachFile from './AttachFile';
@@ -20,23 +22,46 @@ function FileFormWrapper({
disableInputs: boolean;
children?: React.ReactNode;
}) {
- const { handleFileChange, abortUpload } = useFileHandling();
const chatDirection = useRecoilValue(store.chatDirection).toLowerCase();
-
const { files, setFiles, conversation, setFilesLoading } = useChatContext();
+ const { endpoint: _endpoint, endpointType } = conversation ?? { endpoint: null };
+ const isAgents = useMemo(() => isAgentsEndpoint(_endpoint), [_endpoint]);
+
+ const { handleFileChange, abortUpload, setToolResource } = useFileHandling();
+
const { data: fileConfig = defaultFileConfig } = useGetFileConfig({
select: (data) => mergeFileConfig(data),
});
const isRTL = chatDirection === 'rtl';
- const { endpoint: _endpoint, endpointType } = conversation ?? { endpoint: null };
const endpointFileConfig = fileConfig.endpoints[_endpoint ?? ''] as
| EndpointFileConfig
| undefined;
+
const endpointSupportsFiles: boolean = supportsFiles[endpointType ?? _endpoint ?? ''] ?? false;
const isUploadDisabled = (disableInputs || endpointFileConfig?.disabled) ?? false;
+ const renderAttachFile = () => {
+ if (isAgents) {
+ return (
+ <AttachFileMenu
+ isRTL={isRTL}
+ disabled={disableInputs}
+ setToolResource={setToolResource}
+ handleFileChange={handleFileChange}
+ />
+ );
+ }
+ if (endpointSupportsFiles && !isUploadDisabled) {
+ return (
+ <AttachFile isRTL={isRTL} disabled={disableInputs} handleFileChange={handleFileChange} />
+ );
+ }
+
+ return null;
+ };
+
return (
<>
<FileRow
@@ -50,9 +75,7 @@ function FileFormWrapper({
)}
/>
{children}
- {endpointSupportsFiles && !isUploadDisabled && (
- <AttachFile isRTL={isRTL} disabled={disableInputs} handleFileChange={handleFileChange} />
- )}
+ {renderAttachFile()}
</>
);
}
diff --git a/client/src/components/Chat/Input/Mention.tsx b/client/src/components/Chat/Input/Mention.tsx
index 65dd07c792..e268bba00f 100644
--- a/client/src/components/Chat/Input/Mention.tsx
+++ b/client/src/components/Chat/Input/Mention.tsx
@@ -26,8 +26,15 @@ export default function Mention({
}) {
const localize = useLocalize();
const assistantMap = useAssistantsMapContext();
- const { options, presets, modelSpecs, modelsConfig, endpointsConfig, assistantListMap } =
- useMentions({ assistantMap: assistantMap || {}, includeAssistants });
+ const {
+ options,
+ presets,
+ modelSpecs,
+ agentsList,
+ modelsConfig,
+ endpointsConfig,
+ assistantListMap,
+ } = useMentions({ assistantMap: assistantMap || {}, includeAssistants });
const { onSelectMention } = useSelectMention({
presets,
modelSpecs,
@@ -62,18 +69,23 @@ export default function Mention({
}
};
- if (mention.type === 'endpoint' && mention.value === EModelEndpoint.assistants) {
+ if (mention.type === 'endpoint' && mention.value === EModelEndpoint.agents) {
+ setSearchValue('');
+ setInputOptions(agentsList ?? []);
+ setActiveIndex(0);
+ inputRef.current?.focus();
+ } else if (mention.type === 'endpoint' && mention.value === EModelEndpoint.assistants) {
setSearchValue('');
- setInputOptions(assistantListMap[EModelEndpoint.assistants]);
+ setInputOptions(assistantListMap[EModelEndpoint.assistants] ?? []);
setActiveIndex(0);
inputRef.current?.focus();
} else if (mention.type === 'endpoint' && mention.value === EModelEndpoint.azureAssistants) {
setSearchValue('');
- setInputOptions(assistantListMap[EModelEndpoint.azureAssistants]);
+ setInputOptions(assistantListMap[EModelEndpoint.azureAssistants] ?? []);
setActiveIndex(0);
inputRef.current?.focus();
} else if (mention.type === 'endpoint') {
- const models = (modelsConfig?.[mention.value ?? ''] ?? []).map((model) => ({
+ const models = (modelsConfig?.[mention.value || ''] ?? []).map((model) => ({
value: mention.value,
label: model,
type: 'model',
diff --git a/client/src/components/Chat/Menus/Endpoints/MenuItems.tsx b/client/src/components/Chat/Menus/Endpoints/MenuItems.tsx
index f5ff608285..aa50f274d3 100644
--- a/client/src/components/Chat/Menus/Endpoints/MenuItems.tsx
+++ b/client/src/components/Chat/Menus/Endpoints/MenuItems.tsx
@@ -1,47 +1,57 @@
import type { FC } from 'react';
import { Close } from '@radix-ui/react-popover';
-import { EModelEndpoint, alternateName } from 'librechat-data-provider';
+import {
+ EModelEndpoint,
+ alternateName,
+ PermissionTypes,
+ Permissions,
+} from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import MenuSeparator from '../UI/MenuSeparator';
import { getEndpointField } from '~/utils';
+import { useHasAccess } from '~/hooks';
import MenuItem from './MenuItem';
const EndpointItems: FC<{
- endpoints: EModelEndpoint[];
+ endpoints: Array<EModelEndpoint | undefined>;
selected: EModelEndpoint | '';
-}> = ({ endpoints, selected }) => {
+}> = ({ endpoints = [], selected }) => {
+ const hasAccessToAgents = useHasAccess({
+ permissionType: PermissionTypes.AGENTS,
+ permission: Permissions.USE,
+ });
const { data: endpointsConfig } = useGetEndpointsQuery();
return (
<>
- {endpoints &&
- endpoints.map((endpoint, i) => {
- if (!endpoint) {
- return null;
- } else if (!endpointsConfig?.[endpoint]) {
- return null;
- }
- const userProvidesKey: boolean | null | undefined = getEndpointField(
- endpointsConfig,
- endpoint,
- 'userProvide',
- );
- return (
- <Close asChild key={`endpoint-${endpoint}`}>
- <div key={`endpoint-${endpoint}`}>
- <MenuItem
- key={`endpoint-item-${endpoint}`}
- title={alternateName[endpoint] || endpoint}
- value={endpoint}
- selected={selected === endpoint}
- data-testid={`endpoint-item-${endpoint}`}
- userProvidesKey={!!userProvidesKey}
- // description="With DALL·E, browsing and analysis"
- />
- {i !== endpoints.length - 1 && <MenuSeparator />}
- </div>
- </Close>
- );
- })}
+ {endpoints.map((endpoint, i) => {
+ if (!endpoint) {
+ return null;
+ } else if (!endpointsConfig?.[endpoint]) {
+ return null;
+ }
+
+ if (endpoint === EModelEndpoint.agents && !hasAccessToAgents) {
+ return null;
+ }
+ const userProvidesKey: boolean | null | undefined =
+ getEndpointField(endpointsConfig, endpoint, 'userProvide') ?? false;
+ return (
+ <Close asChild key={`endpoint-${endpoint}`}>
+ <div key={`endpoint-${endpoint}`}>
+ <MenuItem
+ key={`endpoint-item-${endpoint}`}
+ title={alternateName[endpoint] || endpoint}
+ value={endpoint}
+ selected={selected === endpoint}
+ data-testid={`endpoint-item-${endpoint}`}
+ userProvidesKey={!!userProvidesKey}
+ // description="With DALL·E, browsing and analysis"
+ />
+ {i !== endpoints.length - 1 && <MenuSeparator />}
+ </div>
+ </Close>
+ );
+ })}
</>
);
};
diff --git a/client/src/components/Chat/Messages/Content/ContentParts.tsx b/client/src/components/Chat/Messages/Content/ContentParts.tsx
index c2018d1905..a59093e160 100644
--- a/client/src/components/Chat/Messages/Content/ContentParts.tsx
+++ b/client/src/components/Chat/Messages/Content/ContentParts.tsx
@@ -4,12 +4,14 @@ import { ContentTypes } from 'librechat-data-provider';
import type { TMessageContentParts, TAttachment, Agents } from 'librechat-data-provider';
import EditTextPart from './Parts/EditTextPart';
import { mapAttachments } from '~/utils/map';
+import { MessageContext } from '~/Providers';
import store from '~/store';
import Part from './Part';
type ContentPartsProps = {
content: Array<TMessageContentParts | undefined> | undefined;
messageId: string;
+ conversationId?: string | null;
attachments?: TAttachment[];
isCreatedByUser: boolean;
isLast: boolean;
@@ -27,6 +29,7 @@ const ContentParts = memo(
({
content,
messageId,
+ conversationId,
attachments,
isCreatedByUser,
isLast,
@@ -79,15 +82,23 @@ const ContentParts = memo(
const attachments = attachmentMap[toolCallId];
return (
- <Part
- part={part}
- isSubmitting={isSubmitting}
- attachments={attachments}
- key={`display-${messageId}-${idx}`}
- showCursor={idx === content.length - 1 && isLast}
- messageId={messageId}
- isCreatedByUser={isCreatedByUser}
- />
+ <MessageContext.Provider
+ key={`provider-${messageId}-${idx}`}
+ value={{
+ messageId,
+ conversationId,
+ partIndex: idx,
+ }}
+ >
+ <Part
+ part={part}
+ attachments={attachments}
+ isSubmitting={isSubmitting}
+ key={`part-${messageId}-${idx}`}
+ isCreatedByUser={isCreatedByUser}
+ showCursor={idx === content.length - 1 && isLast}
+ />
+ </MessageContext.Provider>
);
})}
</>
diff --git a/client/src/components/Chat/Messages/Content/Markdown.tsx b/client/src/components/Chat/Messages/Content/Markdown.tsx
index 5ef21c79d0..59cbc70481 100644
--- a/client/src/components/Chat/Messages/Content/Markdown.tsx
+++ b/client/src/components/Chat/Messages/Content/Markdown.tsx
@@ -1,4 +1,4 @@
-import React, { memo, useMemo } from 'react';
+import React, { memo, useMemo, useRef, useEffect } from 'react';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
import supersub from 'remark-supersub';
@@ -10,10 +10,10 @@ import remarkDirective from 'remark-directive';
import type { Pluggable } from 'unified';
import { Artifact, artifactPlugin } from '~/components/Artifacts/Artifact';
import { langSubset, preprocessLaTeX, handleDoubleClick } from '~/utils';
+import { useToastContext, CodeBlockProvider, useCodeBlockContext } from '~/Providers';
import CodeBlock from '~/components/Messages/Content/CodeBlock';
import { useFileDownload } from '~/data-provider';
import useLocalize from '~/hooks/useLocalize';
-import { useToastContext } from '~/Providers';
import store from '~/store';
type TCodeProps = {
@@ -25,6 +25,32 @@ type TCodeProps = {
export const code: React.ElementType = memo(({ className, children }: TCodeProps) => {
const match = /language-(\w+)/.exec(className ?? '');
const lang = match && match[1];
+ const isMath = lang === 'math';
+ const isSingleLine = typeof children === 'string' && children.split('\n').length === 1;
+
+ const { getNextIndex, resetCounter } = useCodeBlockContext();
+ const blockIndex = useRef(getNextIndex(isMath || isSingleLine)).current;
+
+ useEffect(() => {
+ resetCounter();
+ }, [children, resetCounter]);
+
+ if (isMath) {
+ return children;
+ } else if (isSingleLine) {
+ return (
+ <code onDoubleClick={handleDoubleClick} className={className}>
+ {children}
+ </code>
+ );
+ } else {
+ return <CodeBlock lang={lang ?? 'text'} codeChildren={children} blockIndex={blockIndex} />;
+ }
+});
+
+export const codeNoExecution: React.ElementType = memo(({ className, children }: TCodeProps) => {
+ const match = /language-(\w+)/.exec(className ?? '');
+ const lang = match && match[1];
if (lang === 'math') {
return children;
@@ -35,7 +61,7 @@ export const code: React.ElementType = memo(({ className, children }: TCodeProps
</code>
);
} else {
- return <CodeBlock lang={lang ?? 'text'} codeChildren={children} />;
+ return <CodeBlock lang={lang ?? 'text'} codeChildren={children} allowExecution={false} />;
}
});
@@ -45,7 +71,11 @@ export const a: React.ElementType = memo(
const { showToast } = useToastContext();
const localize = useLocalize();
- const { file_id, filename, filepath } = useMemo(() => {
+ const {
+ file_id = '',
+ filename = '',
+ filepath,
+ } = useMemo(() => {
const pattern = new RegExp(`(?:files|outputs)/${user?.id}/([^\\s]+)`);
const match = href.match(pattern);
if (match && match[0]) {
@@ -164,25 +194,27 @@ const Markdown = memo(({ content = '', showCursor, isLatestMessage }: TContentPr
: [supersub, remarkGfm, [remarkMath, { singleDollarTextMath: true }]];
return (
- <ReactMarkdown
- /** @ts-ignore */
- remarkPlugins={remarkPlugins}
- /* @ts-ignore */
- rehypePlugins={rehypePlugins}
- // linkTarget="_new"
- components={
- {
- code,
- a,
- p,
- artifact: Artifact,
- } as {
- [nodeType: string]: React.ElementType;
+ <CodeBlockProvider>
+ <ReactMarkdown
+ /** @ts-ignore */
+ remarkPlugins={remarkPlugins}
+ /* @ts-ignore */
+ rehypePlugins={rehypePlugins}
+ // linkTarget="_new"
+ components={
+ {
+ code,
+ a,
+ p,
+ artifact: Artifact,
+ } as {
+ [nodeType: string]: React.ElementType;
+ }
}
- }
- >
- {isLatestMessage && showCursor === true ? currentContent + cursor : currentContent}
- </ReactMarkdown>
+ >
+ {isLatestMessage && showCursor === true ? currentContent + cursor : currentContent}
+ </ReactMarkdown>
+ </CodeBlockProvider>
);
});
diff --git a/client/src/components/Chat/Messages/Content/MarkdownLite.tsx b/client/src/components/Chat/Messages/Content/MarkdownLite.tsx
index 0996f7f740..1571d23448 100644
--- a/client/src/components/Chat/Messages/Content/MarkdownLite.tsx
+++ b/client/src/components/Chat/Messages/Content/MarkdownLite.tsx
@@ -6,40 +6,51 @@ import supersub from 'remark-supersub';
import ReactMarkdown from 'react-markdown';
import rehypeHighlight from 'rehype-highlight';
import type { PluggableList } from 'unified';
+import { code, codeNoExecution, a, p } from './Markdown';
+import { CodeBlockProvider } from '~/Providers';
import { langSubset } from '~/utils';
-import { code, a, p } from './Markdown';
-const MarkdownLite = memo(({ content = '' }: { content?: string }) => {
- const rehypePlugins: PluggableList = [
- [rehypeKatex, { output: 'mathml' }],
- [
- rehypeHighlight,
- {
- detect: true,
- ignoreMissing: true,
- subset: langSubset,
- },
- ],
- ];
-
- return (
- <ReactMarkdown
- remarkPlugins={[supersub, remarkGfm, [remarkMath, { singleDollarTextMath: true }]]}
- rehypePlugins={rehypePlugins}
- // linkTarget="_new"
- components={
+const MarkdownLite = memo(
+ ({ content = '', codeExecution = true }: { content?: string; codeExecution?: boolean }) => {
+ const rehypePlugins: PluggableList = [
+ [rehypeKatex, { output: 'mathml' }],
+ [
+ rehypeHighlight,
{
- code,
- a,
- p,
- } as {
- [nodeType: string]: React.ElementType;
- }
- }
- >
- {content}
- </ReactMarkdown>
- );
-});
+ detect: true,
+ ignoreMissing: true,
+ subset: langSubset,
+ },
+ ],
+ ];
+
+ return (
+ <CodeBlockProvider>
+ <ReactMarkdown
+ remarkPlugins={[
+ /** @ts-ignore */
+ supersub,
+ remarkGfm,
+ [remarkMath, { singleDollarTextMath: true }],
+ ]}
+ /** @ts-ignore */
+ rehypePlugins={rehypePlugins}
+ // linkTarget="_new"
+ components={
+ {
+ code: codeExecution ? code : codeNoExecution,
+ a,
+ p,
+ } as {
+ [nodeType: string]: React.ElementType;
+ }
+ }
+ >
+ {content}
+ </ReactMarkdown>
+ </CodeBlockProvider>
+ );
+ },
+);
export default MarkdownLite;
diff --git a/client/src/components/Chat/Messages/Content/Part.tsx b/client/src/components/Chat/Messages/Content/Part.tsx
index 83241a4211..f64ab6f361 100644
--- a/client/src/components/Chat/Messages/Content/Part.tsx
+++ b/client/src/components/Chat/Messages/Content/Part.tsx
@@ -21,143 +21,130 @@ type PartProps = {
part?: TMessageContentParts;
isSubmitting: boolean;
showCursor: boolean;
- messageId: string;
isCreatedByUser: boolean;
attachments?: TAttachment[];
};
-const Part = memo(
- ({ part, isSubmitting, attachments, showCursor, messageId, isCreatedByUser }: PartProps) => {
- attachments && console.log(attachments);
- if (!part) {
+const Part = memo(({ part, isSubmitting, attachments, showCursor, isCreatedByUser }: PartProps) => {
+ if (!part) {
+ return null;
+ }
+
+ if (part.type === ContentTypes.ERROR) {
+ return <ErrorMessage text={part[ContentTypes.TEXT].value} className="my-2" />;
+ } else if (part.type === ContentTypes.TEXT) {
+ const text = typeof part.text === 'string' ? part.text : part.text.value;
+
+ if (typeof text !== 'string') {
+ return null;
+ }
+ if (part.tool_call_ids != null && !text) {
return null;
}
+ return (
+ <Container>
+ <Text text={text} isCreatedByUser={isCreatedByUser} showCursor={showCursor} />
+ </Container>
+ );
+ } else if (part.type === ContentTypes.TOOL_CALL) {
+ const toolCall = part[ContentTypes.TOOL_CALL];
- if (part.type === ContentTypes.ERROR) {
- return <ErrorMessage text={part[ContentTypes.TEXT].value} className="my-2" />;
- } else if (part.type === ContentTypes.TEXT) {
- const text = typeof part.text === 'string' ? part.text : part.text.value;
+ if (!toolCall) {
+ return null;
+ }
- if (typeof text !== 'string') {
- return null;
- }
- if (part.tool_call_ids != null && !text) {
- return null;
- }
+ const isToolCall =
+ 'args' in toolCall && (!toolCall.type || toolCall.type === ToolCallTypes.TOOL_CALL);
+ if (isToolCall && toolCall.name === Tools.execute_code) {
return (
- <Container>
- <Text
- text={text}
- isCreatedByUser={isCreatedByUser}
- messageId={messageId}
- showCursor={showCursor}
- />
- </Container>
+ <ExecuteCode
+ args={typeof toolCall.args === 'string' ? toolCall.args : ''}
+ output={toolCall.output ?? ''}
+ initialProgress={toolCall.progress ?? 0.1}
+ isSubmitting={isSubmitting}
+ attachments={attachments}
+ />
);
- } else if (part.type === ContentTypes.TOOL_CALL) {
- const toolCall = part[ContentTypes.TOOL_CALL];
-
- if (!toolCall) {
+ } else if (isToolCall) {
+ return (
+ <ToolCall
+ args={toolCall.args ?? ''}
+ name={toolCall.name || ''}
+ output={toolCall.output ?? ''}
+ initialProgress={toolCall.progress ?? 0.1}
+ isSubmitting={isSubmitting}
+ attachments={attachments}
+ />
+ );
+ } else if (toolCall.type === ToolCallTypes.CODE_INTERPRETER) {
+ const code_interpreter = toolCall[ToolCallTypes.CODE_INTERPRETER];
+ return (
+ <CodeAnalyze
+ initialProgress={toolCall.progress ?? 0.1}
+ code={code_interpreter.input}
+ outputs={code_interpreter.outputs ?? []}
+ isSubmitting={isSubmitting}
+ />
+ );
+ } else if (
+ toolCall.type === ToolCallTypes.RETRIEVAL ||
+ toolCall.type === ToolCallTypes.FILE_SEARCH
+ ) {
+ return (
+ <RetrievalCall initialProgress={toolCall.progress ?? 0.1} isSubmitting={isSubmitting} />
+ );
+ } else if (
+ toolCall.type === ToolCallTypes.FUNCTION &&
+ ToolCallTypes.FUNCTION in toolCall &&
+ imageGenTools.has(toolCall.function.name)
+ ) {
+ return (
+ <ImageGen
+ initialProgress={toolCall.progress ?? 0.1}
+ args={toolCall.function.arguments as string}
+ />
+ );
+ } else if (toolCall.type === ToolCallTypes.FUNCTION && ToolCallTypes.FUNCTION in toolCall) {
+ if (isImageVisionTool(toolCall)) {
+ if (isSubmitting && showCursor) {
+ return (
+ <Container>
+ <Text text={''} isCreatedByUser={isCreatedByUser} showCursor={showCursor} />
+ </Container>
+ );
+ }
return null;
}
- const isToolCall =
- 'args' in toolCall && (!toolCall.type || toolCall.type === ToolCallTypes.TOOL_CALL);
- if (isToolCall && toolCall.name === Tools.execute_code) {
- return (
- <ExecuteCode
- args={typeof toolCall.args === 'string' ? toolCall.args : ''}
- output={toolCall.output ?? ''}
- initialProgress={toolCall.progress ?? 0.1}
- isSubmitting={isSubmitting}
- attachments={attachments}
- />
- );
- } else if (isToolCall) {
- return (
- <ToolCall
- args={toolCall.args ?? ''}
- name={toolCall.name ?? ''}
- output={toolCall.output ?? ''}
- initialProgress={toolCall.progress ?? 0.1}
- isSubmitting={isSubmitting}
- />
- );
- } else if (toolCall.type === ToolCallTypes.CODE_INTERPRETER) {
- const code_interpreter = toolCall[ToolCallTypes.CODE_INTERPRETER];
- return (
- <CodeAnalyze
- initialProgress={toolCall.progress ?? 0.1}
- code={code_interpreter.input}
- outputs={code_interpreter.outputs ?? []}
- isSubmitting={isSubmitting}
- />
- );
- } else if (
- toolCall.type === ToolCallTypes.RETRIEVAL ||
- toolCall.type === ToolCallTypes.FILE_SEARCH
- ) {
- return (
- <RetrievalCall initialProgress={toolCall.progress ?? 0.1} isSubmitting={isSubmitting} />
- );
- } else if (
- toolCall.type === ToolCallTypes.FUNCTION &&
- ToolCallTypes.FUNCTION in toolCall &&
- imageGenTools.has(toolCall.function.name)
- ) {
- return (
- <ImageGen
- initialProgress={toolCall.progress ?? 0.1}
- args={toolCall.function.arguments as string}
- />
- );
- } else if (toolCall.type === ToolCallTypes.FUNCTION && ToolCallTypes.FUNCTION in toolCall) {
- if (isImageVisionTool(toolCall)) {
- if (isSubmitting && showCursor) {
- return (
- <Container>
- <Text
- text={''}
- isCreatedByUser={isCreatedByUser}
- messageId={messageId}
- showCursor={showCursor}
- />
- </Container>
- );
- }
- return null;
- }
-
- return (
- <ToolCall
- initialProgress={toolCall.progress ?? 0.1}
- isSubmitting={isSubmitting}
- args={toolCall.function.arguments as string}
- name={toolCall.function.name}
- output={toolCall.function.output}
- />
- );
- }
- } else if (part.type === ContentTypes.IMAGE_FILE) {
- const imageFile = part[ContentTypes.IMAGE_FILE];
- const height = imageFile.height ?? 1920;
- const width = imageFile.width ?? 1080;
return (
- <Image
- imagePath={imageFile.filepath}
- height={height}
- width={width}
- altText={imageFile.filename ?? 'Uploaded Image'}
- placeholderDimensions={{
- height: height + 'px',
- width: width + 'px',
- }}
+ <ToolCall
+ initialProgress={toolCall.progress ?? 0.1}
+ isSubmitting={isSubmitting}
+ args={toolCall.function.arguments as string}
+ name={toolCall.function.name}
+ output={toolCall.function.output}
/>
);
}
+ } else if (part.type === ContentTypes.IMAGE_FILE) {
+ const imageFile = part[ContentTypes.IMAGE_FILE];
+ const height = imageFile.height ?? 1920;
+ const width = imageFile.width ?? 1080;
+ return (
+ <Image
+ imagePath={imageFile.filepath}
+ height={height}
+ width={width}
+ altText={imageFile.filename ?? 'Uploaded Image'}
+ placeholderDimensions={{
+ height: height + 'px',
+ width: width + 'px',
+ }}
+ />
+ );
+ }
- return null;
- },
-);
+ return null;
+});
export default Part;
diff --git a/client/src/components/Chat/Messages/Content/Parts/Attachment.tsx b/client/src/components/Chat/Messages/Content/Parts/Attachment.tsx
new file mode 100644
index 0000000000..785a37a343
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/Attachment.tsx
@@ -0,0 +1,19 @@
+import { imageExtRegex } from 'librechat-data-provider';
+import type { TAttachment, TFile, TAttachmentMetadata } from 'librechat-data-provider';
+import Image from '~/components/Chat/Messages/Content/Image';
+
+export default function Attachment({ attachment }: { attachment?: TAttachment }) {
+ if (!attachment) {
+ return null;
+ }
+ const { width, height, filepath = null } = attachment as TFile & TAttachmentMetadata;
+ const isImage =
+ imageExtRegex.test(attachment.filename) && width != null && height != null && filepath != null;
+
+ if (isImage) {
+ return (
+ <Image altText={attachment.filename} imagePath={filepath} height={height} width={width} />
+ );
+ }
+ return null;
+}
diff --git a/client/src/components/Chat/Messages/Content/Parts/ExecuteCode.tsx b/client/src/components/Chat/Messages/Content/Parts/ExecuteCode.tsx
index 559fc3cd2c..49a15fc71c 100644
--- a/client/src/components/Chat/Messages/Content/Parts/ExecuteCode.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/ExecuteCode.tsx
@@ -1,12 +1,11 @@
import React, { useMemo, useState } from 'react';
import { useRecoilValue } from 'recoil';
-import { CodeInProgress } from './CodeProgress';
-import { imageExtRegex } from 'librechat-data-provider';
-import type { TFile, TAttachment, TAttachmentMetadata } from 'librechat-data-provider';
+import type { TAttachment } from 'librechat-data-provider';
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
import FinishedIcon from '~/components/Chat/Messages/Content/FinishedIcon';
import MarkdownLite from '~/components/Chat/Messages/Content/MarkdownLite';
-import Image from '~/components/Chat/Messages/Content/Image';
+import { CodeInProgress } from './CodeProgress';
+import Attachment from './Attachment';
import LogContent from './LogContent';
import { useProgress } from '~/hooks';
import store from '~/store';
@@ -86,7 +85,10 @@ export default function ExecuteCode({
</div>
{showCode && (
<div className="code-analyze-block mb-3 mt-0.5 overflow-hidden rounded-xl bg-black">
- <MarkdownLite content={code ? `\`\`\`${lang}\n${code}\n\`\`\`` : ''} />
+ <MarkdownLite
+ content={code ? `\`\`\`${lang}\n${code}\n\`\`\`` : ''}
+ codeExecution={false}
+ />
{output.length > 0 && (
<div className="bg-gray-700 p-4 text-xs">
<div
@@ -103,25 +105,9 @@ export default function ExecuteCode({
)}
</div>
)}
- {attachments?.map((attachment, index) => {
- const { width, height, filepath } = attachment as TFile & TAttachmentMetadata;
- const isImage =
- imageExtRegex.test(attachment.filename) &&
- width != null &&
- height != null &&
- filepath != null;
- if (isImage) {
- return (
- <Image
- key={index}
- altText={attachment.filename}
- imagePath={filepath}
- height={height}
- width={width}
- />
- );
- }
- })}
+ {attachments?.map((attachment, index) => (
+ <Attachment attachment={attachment} key={index} />
+ ))}
</>
);
}
diff --git a/client/src/components/Chat/Messages/Content/Parts/LogContent.tsx b/client/src/components/Chat/Messages/Content/Parts/LogContent.tsx
index 9f9eceaa4f..9a6e3fc99d 100644
--- a/client/src/components/Chat/Messages/Content/Parts/LogContent.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/LogContent.tsx
@@ -1,17 +1,26 @@
import { isAfter } from 'date-fns';
import React, { useMemo } from 'react';
import { imageExtRegex } from 'librechat-data-provider';
-import type { TAttachment } from 'librechat-data-provider';
+import type { TFile, TAttachment, TAttachmentMetadata } from 'librechat-data-provider';
+import Image from '~/components/Chat/Messages/Content/Image';
import { useLocalize } from '~/hooks';
import LogLink from './LogLink';
interface LogContentProps {
output?: string;
+ renderImages?: boolean;
attachments?: TAttachment[];
}
-const LogContent: React.FC<LogContentProps> = ({ output = '', attachments }) => {
+type ImageAttachment = TFile &
+ TAttachmentMetadata & {
+ height: number;
+ width: number;
+ };
+
+const LogContent: React.FC<LogContentProps> = ({ output = '', renderImages, attachments }) => {
const localize = useLocalize();
+
const processedContent = useMemo(() => {
if (!output) {
return '';
@@ -21,8 +30,29 @@ const LogContent: React.FC<LogContentProps> = ({ output = '', attachments }) =>
return parts[0].trim();
}, [output]);
- const nonImageAttachments =
- attachments?.filter((file) => !imageExtRegex.test(file.filename)) || [];
+ const { imageAttachments, nonImageAttachments } = useMemo(() => {
+ const imageAtts: ImageAttachment[] = [];
+ const nonImageAtts: TAttachment[] = [];
+
+ attachments?.forEach((attachment) => {
+ const { width, height, filepath = null } = attachment as TFile & TAttachmentMetadata;
+ const isImage =
+ imageExtRegex.test(attachment.filename) &&
+ width != null &&
+ height != null &&
+ filepath != null;
+ if (isImage) {
+ imageAtts.push(attachment as ImageAttachment);
+ } else {
+ nonImageAtts.push(attachment);
+ }
+ });
+
+ return {
+ imageAttachments: renderImages === true ? imageAtts : null,
+ nonImageAttachments: nonImageAtts,
+ };
+ }, [attachments, renderImages]);
const renderAttachment = (file: TAttachment) => {
const now = new Date();
@@ -59,6 +89,18 @@ const LogContent: React.FC<LogContentProps> = ({ output = '', attachments }) =>
))}
</div>
)}
+ {imageAttachments?.map((attachment, index) => {
+ const { width, height, filepath } = attachment;
+ return (
+ <Image
+ key={index}
+ altText={attachment.filename}
+ imagePath={filepath}
+ height={height}
+ width={width}
+ />
+ );
+ })}
</>
);
};
diff --git a/client/src/components/Chat/Messages/Content/Parts/Text.tsx b/client/src/components/Chat/Messages/Content/Parts/Text.tsx
index b52a0bfa52..5806f76aac 100644
--- a/client/src/components/Chat/Messages/Content/Parts/Text.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/Text.tsx
@@ -2,15 +2,14 @@ import { memo, useMemo, ReactElement } from 'react';
import { useRecoilValue } from 'recoil';
import MarkdownLite from '~/components/Chat/Messages/Content/MarkdownLite';
import Markdown from '~/components/Chat/Messages/Content/Markdown';
-import { useChatContext } from '~/Providers';
+import { useChatContext, useMessageContext } from '~/Providers';
import { cn } from '~/utils';
import store from '~/store';
type TextPartProps = {
text: string;
- isCreatedByUser: boolean;
- messageId: string;
showCursor: boolean;
+ isCreatedByUser: boolean;
};
type ContentType =
@@ -18,7 +17,8 @@ type ContentType =
| ReactElement<React.ComponentProps<typeof MarkdownLite>>
| ReactElement;
-const TextPart = memo(({ text, isCreatedByUser, messageId, showCursor }: TextPartProps) => {
+const TextPart = memo(({ text, isCreatedByUser, showCursor }: TextPartProps) => {
+ const { messageId } = useMessageContext();
const { isSubmitting, latestMessage } = useChatContext();
const enableUserMsgMarkdown = useRecoilValue(store.enableUserMsgMarkdown);
const showCursorState = useMemo(() => showCursor && isSubmitting, [showCursor, isSubmitting]);
diff --git a/client/src/components/Chat/Messages/Content/ToolCall.tsx b/client/src/components/Chat/Messages/Content/ToolCall.tsx
index 64b3210981..756fbd4878 100644
--- a/client/src/components/Chat/Messages/Content/ToolCall.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolCall.tsx
@@ -1,9 +1,11 @@
import { useMemo } from 'react';
-import { actionDelimiter, actionDomainSeparator, Constants } from 'librechat-data-provider';
import * as Popover from '@radix-ui/react-popover';
+import { actionDelimiter, actionDomainSeparator, Constants } from 'librechat-data-provider';
+import type { TAttachment } from 'librechat-data-provider';
import useLocalize from '~/hooks/useLocalize';
import ProgressCircle from './ProgressCircle';
import InProgressCall from './InProgressCall';
+import Attachment from './Parts/Attachment';
import CancelledIcon from './CancelledIcon';
import ProgressText from './ProgressText';
import FinishedIcon from './FinishedIcon';
@@ -18,12 +20,14 @@ export default function ToolCall({
name,
args: _args = '',
output,
+ attachments,
}: {
initialProgress: number;
isSubmitting: boolean;
name: string;
args: string | Record<string, unknown>;
output?: string | null;
+ attachments?: TAttachment[];
}) {
const localize = useLocalize();
const progress = useProgress(initialProgress);
@@ -106,6 +110,9 @@ export default function ToolCall({
/>
)}
</div>
+ {attachments?.map((attachment, index) => (
+ <Attachment attachment={attachment} key={index} />
+ ))}
</Popover.Root>
);
}
diff --git a/client/src/components/Chat/Messages/Content/ToolPopover.tsx b/client/src/components/Chat/Messages/Content/ToolPopover.tsx
index dbc203f7b6..97e5aefa41 100644
--- a/client/src/components/Chat/Messages/Content/ToolPopover.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolPopover.tsx
@@ -33,7 +33,7 @@ export default function ToolPopover({
<div tabIndex={-1}>
<div className="bg-token-surface-primary max-w-sm rounded-md p-2 shadow-[0_0_24px_0_rgba(0,0,0,0.05),inset_0_0.5px_0_0_rgba(0,0,0,0.05),0_2px_8px_0_rgba(0,0,0,0.05)]">
<div className="mb-2 text-sm font-medium dark:text-gray-100">
- {domain
+ {domain != null && domain
? localize('com_assistants_domain_info', domain)
: localize('com_assistants_function_use', function_name)}
</div>
@@ -42,7 +42,7 @@ export default function ToolPopover({
<code className="!whitespace-pre-wrap ">{formatText(input)}</code>
</div>
</div>
- {output && (
+ {output != null && output && (
<>
<div className="mb-2 mt-2 text-sm font-medium dark:text-gray-100">
{localize('com_ui_result')}
diff --git a/client/src/components/Chat/Messages/MessageParts.tsx b/client/src/components/Chat/Messages/MessageParts.tsx
index 52a2dbe2dd..0e9d7cc40a 100644
--- a/client/src/components/Chat/Messages/MessageParts.tsx
+++ b/client/src/components/Chat/Messages/MessageParts.tsx
@@ -82,11 +82,12 @@ export default function Message(props: TMessageProps) {
<div className="flex-col gap-1 md:gap-3">
<div className="flex max-w-full flex-grow flex-col gap-0">
<ContentParts
- content={message.content as Array<TMessageContentParts | undefined>}
- messageId={message.messageId}
- isCreatedByUser={message.isCreatedByUser}
isLast={isLast}
isSubmitting={isSubmitting}
+ messageId={message.messageId}
+ isCreatedByUser={message.isCreatedByUser}
+ conversationId={conversation?.conversationId}
+ content={message.content as Array<TMessageContentParts | undefined>}
/>
</div>
</div>
diff --git a/client/src/components/Chat/Messages/ui/MessageRender.tsx b/client/src/components/Chat/Messages/ui/MessageRender.tsx
index bf237dea44..f77d9acafe 100644
--- a/client/src/components/Chat/Messages/ui/MessageRender.tsx
+++ b/client/src/components/Chat/Messages/ui/MessageRender.tsx
@@ -9,6 +9,7 @@ import HoverButtons from '~/components/Chat/Messages/HoverButtons';
import Icon from '~/components/Chat/Messages/MessageIcon';
import { Plugin } from '~/components/Messages/Content';
import SubRow from '~/components/Chat/Messages/SubRow';
+import { MessageContext } from '~/Providers';
import { useMessageActions } from '~/hooks';
import { cn, logger } from '~/utils';
import store from '~/store';
@@ -59,9 +60,10 @@ const MessageRender = memo(
const fontSize = useRecoilValue(store.fontSize);
const handleRegenerateMessage = useCallback(() => regenerateMessage(), [regenerateMessage]);
const { isCreatedByUser, error, unfinished } = msg ?? {};
+ const hasNoChildren = !(msg?.children?.length ?? 0);
const isLast = useMemo(
- () => !msg?.children?.length && (msg?.depth === latestMessage?.depth || msg?.depth === -1),
- [msg?.children, msg?.depth, latestMessage?.depth],
+ () => hasNoChildren && (msg?.depth === latestMessage?.depth || msg?.depth === -1),
+ [hasNoChildren, msg?.depth, latestMessage?.depth],
);
if (!msg) {
@@ -122,24 +124,31 @@ const MessageRender = memo(
<h2 className={cn('select-none font-semibold', fontSize)}>{messageLabel}</h2>
<div className="flex-col gap-1 md:gap-3">
<div className="flex max-w-full flex-grow flex-col gap-0">
- {msg.plugin && <Plugin plugin={msg.plugin} />}
- <MessageContent
- ask={ask}
- edit={edit}
- isLast={isLast}
- text={msg.text || ''}
- message={msg}
- enterEdit={enterEdit}
- error={!!(error ?? false)}
- isSubmitting={isSubmitting}
- unfinished={unfinished ?? false}
- isCreatedByUser={isCreatedByUser ?? true}
- siblingIdx={siblingIdx ?? 0}
- setSiblingIdx={setSiblingIdx ?? (() => ({}))}
- />
+ <MessageContext.Provider
+ value={{
+ messageId: msg.messageId,
+ conversationId: conversation?.conversationId,
+ }}
+ >
+ {msg.plugin && <Plugin plugin={msg.plugin} />}
+ <MessageContent
+ ask={ask}
+ edit={edit}
+ isLast={isLast}
+ text={msg.text || ''}
+ message={msg}
+ enterEdit={enterEdit}
+ error={!!(error ?? false)}
+ isSubmitting={isSubmitting}
+ unfinished={unfinished ?? false}
+ isCreatedByUser={isCreatedByUser ?? true}
+ siblingIdx={siblingIdx ?? 0}
+ setSiblingIdx={setSiblingIdx ?? (() => ({}))}
+ />
+ </MessageContext.Provider>
</div>
</div>
- {!msg.children?.length && (isSubmittingFamily === true || isSubmitting) ? (
+ {hasNoChildren && (isSubmittingFamily === true || isSubmitting) ? (
<PlaceholderRow isCard={isCard} />
) : (
<SubRow classes="text-xs">
diff --git a/client/src/components/Endpoints/SaveAsPresetDialog.tsx b/client/src/components/Endpoints/SaveAsPresetDialog.tsx
index 338c2b8729..b827a2d8c2 100644
--- a/client/src/components/Endpoints/SaveAsPresetDialog.tsx
+++ b/client/src/components/Endpoints/SaveAsPresetDialog.tsx
@@ -28,7 +28,7 @@ const SaveAsPresetDialog = ({ open, onOpenChange, preset }: TEditPresetProps) =>
createPresetMutation.mutate(_preset, {
onSuccess: () => {
showToast({
- message: `${toastTitle} ${localize('com_endpoint_preset_saved')}`,
+ message: `${toastTitle} ${localize('com_ui_saved')}`,
});
onOpenChange(false); // Close the dialog on success
},
diff --git a/client/src/components/Messages/Content/CodeBlock.tsx b/client/src/components/Messages/Content/CodeBlock.tsx
index 7f1b4e1b39..df80c90ecb 100644
--- a/client/src/components/Messages/Content/CodeBlock.tsx
+++ b/client/src/components/Messages/Content/CodeBlock.tsx
@@ -1,81 +1,133 @@
import copy from 'copy-to-clipboard';
import { InfoIcon } from 'lucide-react';
-import React, { useRef, useState, RefObject } from 'react';
+import { Tools } from 'librechat-data-provider';
+import React, { useRef, useState, useMemo, useEffect } from 'react';
+import type { CodeBarProps } from '~/common';
+import LogContent from '~/components/Chat/Messages/Content/Parts/LogContent';
+import ResultSwitcher from '~/components/Messages/Content/ResultSwitcher';
+import { useToolCallsMapContext, useMessageContext } from '~/Providers';
+import RunCode from '~/components/Messages/Content/RunCode';
import Clipboard from '~/components/svg/Clipboard';
import CheckMark from '~/components/svg/CheckMark';
import useLocalize from '~/hooks/useLocalize';
import cn from '~/utils/cn';
-type CodeBarProps = {
- lang: string;
- codeRef: RefObject<HTMLElement>;
- plugin?: boolean;
- error?: boolean;
-};
-
-type CodeBlockProps = Pick<CodeBarProps, 'lang' | 'plugin' | 'error'> & {
+type CodeBlockProps = Pick<
+ CodeBarProps,
+ 'lang' | 'plugin' | 'error' | 'allowExecution' | 'blockIndex'
+> & {
codeChildren: React.ReactNode;
classProp?: string;
};
-const CodeBar: React.FC<CodeBarProps> = React.memo(({ lang, codeRef, error, plugin = null }) => {
- const localize = useLocalize();
- const [isCopied, setIsCopied] = useState(false);
- return (
- <div className="relative flex items-center rounded-tl-md rounded-tr-md bg-gray-700 px-4 py-2 font-sans text-xs text-gray-200 dark:bg-gray-700">
- <span className="">{lang}</span>
- {plugin === true ? (
- <InfoIcon className="ml-auto flex h-4 w-4 gap-2 text-white/50" />
- ) : (
- <button
- type="button"
- className={cn(
- 'ml-auto flex gap-2',
- error === true ? 'h-4 w-4 items-start text-white/50' : '',
- )}
- onClick={async () => {
- const codeString = codeRef.current?.textContent;
- if (codeString != null) {
- setIsCopied(true);
- copy(codeString.trim(), { format: 'text/plain' });
+const CodeBar: React.FC<CodeBarProps> = React.memo(
+ ({ lang, error, codeRef, blockIndex, plugin = null, allowExecution = true }) => {
+ const localize = useLocalize();
+ const [isCopied, setIsCopied] = useState(false);
+ return (
+ <div className="relative flex items-center justify-between rounded-tl-md rounded-tr-md bg-gray-700 px-4 py-2 font-sans text-xs text-gray-200 dark:bg-gray-700">
+ <span className="">{lang}</span>
+ {plugin === true ? (
+ <InfoIcon className="ml-auto flex h-4 w-4 gap-2 text-white/50" />
+ ) : (
+ <div className="flex items-center justify-center gap-4">
+ {allowExecution === true && (
+ <RunCode lang={lang} codeRef={codeRef} blockIndex={blockIndex} />
+ )}
+ <button
+ type="button"
+ className={cn(
+ 'ml-auto flex gap-2',
+ error === true ? 'h-4 w-4 items-start text-white/50' : '',
+ )}
+ onClick={async () => {
+ const codeString = codeRef.current?.textContent;
+ if (codeString != null) {
+ setIsCopied(true);
+ copy(codeString.trim(), { format: 'text/plain' });
- setTimeout(() => {
- setIsCopied(false);
- }, 3000);
- }
- }}
- >
- {isCopied ? (
- <>
- <CheckMark className="h-[18px] w-[18px]" />
- {error === true ? '' : localize('com_ui_copied')}
- </>
- ) : (
- <>
- <Clipboard />
- {error === true ? '' : localize('com_ui_copy_code')}
- </>
- )}
- </button>
- )}
- </div>
- );
-});
+ setTimeout(() => {
+ setIsCopied(false);
+ }, 3000);
+ }
+ }}
+ >
+ {isCopied ? (
+ <>
+ <CheckMark className="h-[18px] w-[18px]" />
+ {error === true ? '' : localize('com_ui_copied')}
+ </>
+ ) : (
+ <>
+ <Clipboard />
+ {error === true ? '' : localize('com_ui_copy_code')}
+ </>
+ )}
+ </button>
+ </div>
+ )}
+ </div>
+ );
+ },
+);
const CodeBlock: React.FC<CodeBlockProps> = ({
lang,
+ blockIndex,
codeChildren,
classProp = '',
+ allowExecution = true,
plugin = null,
error,
}) => {
const codeRef = useRef<HTMLElement>(null);
+ const toolCallsMap = useToolCallsMapContext();
+ const { messageId, partIndex } = useMessageContext();
+ const key = allowExecution
+ ? `${messageId}_${partIndex ?? 0}_${blockIndex ?? 0}_${Tools.execute_code}`
+ : '';
+ const [currentIndex, setCurrentIndex] = useState(0);
+
+ const fetchedToolCalls = toolCallsMap?.[key];
+ const [toolCalls, setToolCalls] = useState(toolCallsMap?.[key] ?? null);
+
+ useEffect(() => {
+ if (fetchedToolCalls) {
+ setToolCalls(fetchedToolCalls);
+ setCurrentIndex(fetchedToolCalls.length - 1);
+ }
+ }, [fetchedToolCalls]);
+
+ const currentToolCall = useMemo(() => toolCalls?.[currentIndex], [toolCalls, currentIndex]);
+
+ const next = () => {
+ if (!toolCalls) {
+ return;
+ }
+ if (currentIndex < toolCalls.length - 1) {
+ setCurrentIndex(currentIndex + 1);
+ }
+ };
+
+ const previous = () => {
+ if (currentIndex > 0) {
+ setCurrentIndex(currentIndex - 1);
+ }
+ };
+
const isNonCode = !!(plugin === true || error === true);
const language = isNonCode ? 'json' : lang;
return (
<div className="w-full rounded-md bg-gray-900 text-xs text-white/80">
- <CodeBar lang={lang} codeRef={codeRef} plugin={plugin === true} error={error} />
+ <CodeBar
+ lang={lang}
+ error={error}
+ codeRef={codeRef}
+ blockIndex={blockIndex}
+ plugin={plugin === true}
+ allowExecution={allowExecution}
+ />
<div className={cn(classProp, 'overflow-y-auto p-4')}>
<code
ref={codeRef}
@@ -86,6 +138,34 @@ const CodeBlock: React.FC<CodeBlockProps> = ({
{codeChildren}
</code>
</div>
+ {allowExecution === true && toolCalls && toolCalls.length > 0 && (
+ <>
+ <div className="bg-gray-700 p-4 text-xs">
+ <div
+ className="prose flex flex-col-reverse text-white"
+ style={{
+ color: 'white',
+ }}
+ >
+ <pre className="shrink-0">
+ <LogContent
+ output={(currentToolCall?.result as string | undefined) ?? ''}
+ attachments={currentToolCall?.attachments ?? []}
+ renderImages={true}
+ />
+ </pre>
+ </div>
+ </div>
+ {toolCalls.length > 1 && (
+ <ResultSwitcher
+ currentIndex={currentIndex}
+ totalCount={toolCalls.length}
+ onPrevious={previous}
+ onNext={next}
+ />
+ )}
+ </>
+ )}
</div>
);
};
diff --git a/client/src/components/Messages/Content/ResultSwitcher.tsx b/client/src/components/Messages/Content/ResultSwitcher.tsx
new file mode 100644
index 0000000000..eb8c59b568
--- /dev/null
+++ b/client/src/components/Messages/Content/ResultSwitcher.tsx
@@ -0,0 +1,69 @@
+interface ResultSwitcherProps {
+ currentIndex: number;
+ totalCount: number;
+ onPrevious: () => void;
+ onNext: () => void;
+}
+
+const ResultSwitcher: React.FC<ResultSwitcherProps> = ({
+ currentIndex,
+ totalCount,
+ onPrevious,
+ onNext,
+}) => {
+ if (totalCount <= 1) {
+ return null;
+ }
+
+ return (
+ <div className="flex items-center justify-start gap-1 self-center bg-gray-700 pb-2 text-xs">
+ <button
+ className="hover-button rounded-md p-1 text-gray-400 hover:bg-gray-700 hover:text-gray-200 disabled:hover:text-gray-400"
+ type="button"
+ onClick={onPrevious}
+ disabled={currentIndex === 0}
+ >
+ <svg
+ stroke="currentColor"
+ fill="none"
+ strokeWidth="1.5"
+ viewBox="0 0 24 24"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className="h-4 w-4"
+ height="1em"
+ width="1em"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <polyline points="15 18 9 12 15 6" />
+ </svg>
+ </button>
+ <span className="flex-shrink-0 tabular-nums">
+ {currentIndex + 1} / {totalCount}
+ </span>
+ <button
+ className="hover-button rounded-md p-1 text-gray-400 hover:bg-gray-700 hover:text-gray-200 disabled:hover:text-gray-400"
+ type="button"
+ onClick={onNext}
+ disabled={currentIndex === totalCount - 1}
+ >
+ <svg
+ stroke="currentColor"
+ fill="none"
+ strokeWidth="1.5"
+ viewBox="0 0 24 24"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className="h-4 w-4"
+ height="1em"
+ width="1em"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <polyline points="9 18 15 12 9 6" />
+ </svg>
+ </button>
+ </div>
+ );
+};
+
+export default ResultSwitcher;
diff --git a/client/src/components/Messages/Content/RunCode.tsx b/client/src/components/Messages/Content/RunCode.tsx
new file mode 100644
index 0000000000..b219083468
--- /dev/null
+++ b/client/src/components/Messages/Content/RunCode.tsx
@@ -0,0 +1,109 @@
+import debounce from 'lodash/debounce';
+import { Tools, AuthType } from 'librechat-data-provider';
+import { TerminalSquareIcon, Loader } from 'lucide-react';
+import React, { useMemo, useCallback, useEffect } from 'react';
+import type { CodeBarProps } from '~/common';
+import { useVerifyAgentToolAuth, useToolCallMutation } from '~/data-provider';
+import ApiKeyDialog from '~/components/SidePanel/Agents/Code/ApiKeyDialog';
+import { useLocalize, useCodeApiKeyForm } from '~/hooks';
+import { useMessageContext } from '~/Providers';
+import { cn, normalizeLanguage } from '~/utils';
+import { useToastContext } from '~/Providers';
+
+const RunCode: React.FC<CodeBarProps> = React.memo(({ lang, codeRef, blockIndex }) => {
+ const localize = useLocalize();
+ const { showToast } = useToastContext();
+ const execute = useToolCallMutation(Tools.execute_code, {
+ onError: () => {
+ showToast({ message: localize('com_ui_run_code_error'), status: 'error' });
+ },
+ });
+
+ const { messageId, conversationId, partIndex } = useMessageContext();
+ const normalizedLang = useMemo(() => normalizeLanguage(lang), [lang]);
+ const { data } = useVerifyAgentToolAuth({ toolId: Tools.execute_code });
+ const authType = useMemo(() => data?.message ?? false, [data?.message]);
+ const isAuthenticated = useMemo(() => data?.authenticated ?? false, [data?.authenticated]);
+ const { methods, onSubmit, isDialogOpen, setIsDialogOpen, handleRevokeApiKey } =
+ useCodeApiKeyForm({});
+
+ const handleExecute = useCallback(async () => {
+ if (!isAuthenticated) {
+ setIsDialogOpen(true);
+ return;
+ }
+ const codeString: string = codeRef.current?.textContent ?? '';
+ if (
+ typeof codeString !== 'string' ||
+ codeString.length === 0 ||
+ typeof normalizedLang !== 'string' ||
+ normalizedLang.length === 0
+ ) {
+ return;
+ }
+
+ execute.mutate({
+ partIndex,
+ messageId,
+ blockIndex,
+ conversationId: conversationId ?? '',
+ lang: normalizedLang,
+ code: codeString,
+ });
+ }, [
+ codeRef,
+ execute,
+ partIndex,
+ messageId,
+ blockIndex,
+ conversationId,
+ normalizedLang,
+ setIsDialogOpen,
+ isAuthenticated,
+ ]);
+
+ const debouncedExecute = useMemo(
+ () => debounce(handleExecute, 1000, { leading: true }),
+ [handleExecute],
+ );
+
+ useEffect(() => {
+ return () => {
+ debouncedExecute.cancel();
+ };
+ }, [debouncedExecute]);
+
+ if (typeof normalizedLang !== 'string' || normalizedLang.length === 0) {
+ return null;
+ }
+
+ return (
+ <>
+ <button
+ type="button"
+ className={cn('ml-auto flex gap-2')}
+ onClick={debouncedExecute}
+ disabled={execute.isLoading}
+ >
+ {execute.isLoading ? (
+ <Loader className="animate-spin" size={18} />
+ ) : (
+ <TerminalSquareIcon size={18} />
+ )}
+ {localize('com_ui_run_code')}
+ </button>
+ <ApiKeyDialog
+ onSubmit={onSubmit}
+ isOpen={isDialogOpen}
+ register={methods.register}
+ onRevoke={handleRevokeApiKey}
+ onOpenChange={setIsDialogOpen}
+ handleSubmit={methods.handleSubmit}
+ isToolAuthenticated={isAuthenticated}
+ isUserProvided={authType === AuthType.USER_PROVIDED}
+ />
+ </>
+ );
+});
+
+export default RunCode;
diff --git a/client/src/components/Messages/ContentRender.tsx b/client/src/components/Messages/ContentRender.tsx
index 1d33ae5b63..5033b9a291 100644
--- a/client/src/components/Messages/ContentRender.tsx
+++ b/client/src/components/Messages/ContentRender.tsx
@@ -129,16 +129,17 @@ const ContentRender = memo(
<div className="flex-col gap-1 md:gap-3">
<div className="flex max-w-full flex-grow flex-col gap-0">
<ContentParts
- content={msg.content as Array<TMessageContentParts | undefined>}
- messageId={msg.messageId}
- isCreatedByUser={msg.isCreatedByUser}
- isLast={isLast}
- isSubmitting={isSubmitting}
edit={edit}
+ isLast={isLast}
enterEdit={enterEdit}
siblingIdx={siblingIdx}
+ messageId={msg.messageId}
+ isSubmitting={isSubmitting}
setSiblingIdx={setSiblingIdx}
attachments={msg.attachments}
+ isCreatedByUser={msg.isCreatedByUser}
+ conversationId={conversation?.conversationId}
+ content={msg.content as Array<TMessageContentParts | undefined>}
/>
</div>
</div>
diff --git a/client/src/components/Prompts/AdminSettings.tsx b/client/src/components/Prompts/AdminSettings.tsx
index 7c1f00daed..4ae85a1940 100644
--- a/client/src/components/Prompts/AdminSettings.tsx
+++ b/client/src/components/Prompts/AdminSettings.tsx
@@ -29,17 +29,19 @@ const LabelController: React.FC<LabelControllerProps> = ({
setValue,
}) => (
<div className="mb-4 flex items-center justify-between gap-2">
- <label
+ <button
className="cursor-pointer select-none"
- htmlFor={promptPerm}
+ type="button"
+ // htmlFor={promptPerm}
onClick={() =>
setValue(promptPerm, !getValues(promptPerm), {
shouldDirty: true,
})
}
+ tabIndex={0}
>
{label}
- </label>
+ </button>
<Controller
name={promptPerm}
control={control}
@@ -48,7 +50,7 @@ const LabelController: React.FC<LabelControllerProps> = ({
{...field}
checked={field.value}
onCheckedChange={field.onChange}
- value={field?.value?.toString()}
+ value={field.value.toString()}
/>
)}
/>
@@ -61,7 +63,7 @@ const AdminSettings = () => {
const { showToast } = useToastContext();
const { mutate, isLoading } = useUpdatePromptPermissionsMutation({
onSuccess: () => {
- showToast({ status: 'success', message: localize('com_endpoint_preset_saved') });
+ showToast({ status: 'success', message: localize('com_ui_saved') });
},
onError: () => {
showToast({ status: 'error', message: localize('com_ui_error_save_admin_settings') });
diff --git a/client/src/components/Prompts/Groups/VariableForm.tsx b/client/src/components/Prompts/Groups/VariableForm.tsx
index 74103d7c46..eb8b6683ac 100644
--- a/client/src/components/Prompts/Groups/VariableForm.tsx
+++ b/client/src/components/Prompts/Groups/VariableForm.tsx
@@ -14,9 +14,9 @@ import {
replaceSpecialVars,
extractVariableInfo,
} from '~/utils';
+import { codeNoExecution } from '~/components/Chat/Messages/Content/Markdown';
import { useAuthContext, useLocalize, useSubmitMessage } from '~/hooks';
import { TextareaAutosize, InputCombobox } from '~/components/ui';
-import { code } from '~/components/Chat/Messages/Content/Markdown';
type FieldType = 'text' | 'select';
@@ -143,12 +143,16 @@ export default function VariableForm({
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div className="mb-6 max-h-screen max-w-[90vw] overflow-auto rounded-md bg-gray-100 p-4 text-text-secondary dark:bg-gray-700/50 sm:max-w-full md:max-h-80">
<ReactMarkdown
+ /** @ts-ignore */
remarkPlugins={[supersub, remarkGfm, [remarkMath, { singleDollarTextMath: true }]]}
rehypePlugins={[
+ /** @ts-ignore */
[rehypeKatex, { output: 'mathml' }],
+ /** @ts-ignore */
[rehypeHighlight, { ignoreMissing: true }],
]}
- components={{ code }}
+ /** @ts-ignore */
+ components={{ code: codeNoExecution }}
className="prose dark:prose-invert light dark:text-gray-70 my-1 max-h-[50vh] break-words"
>
{generateHighlightedMarkdown()}
diff --git a/client/src/components/Prompts/PromptDetails.tsx b/client/src/components/Prompts/PromptDetails.tsx
index 0f2a64a71c..4dec2dd4fe 100644
--- a/client/src/components/Prompts/PromptDetails.tsx
+++ b/client/src/components/Prompts/PromptDetails.tsx
@@ -6,7 +6,7 @@ import remarkMath from 'remark-math';
import supersub from 'remark-supersub';
import rehypeHighlight from 'rehype-highlight';
import type { TPromptGroup } from 'librechat-data-provider';
-import { code } from '~/components/Chat/Messages/Content/Markdown';
+import { codeNoExecution } from '~/components/Chat/Messages/Content/Markdown';
import { useLocalize, useAuthContext } from '~/hooks';
import CategoryIcon from './Groups/CategoryIcon';
import PromptVariables from './PromptVariables';
@@ -50,12 +50,20 @@ const PromptDetails = ({ group }: { group?: TPromptGroup }) => {
</h2>
<div className="group relative min-h-32 rounded-b-lg border border-gray-300 p-4 transition-all duration-150 dark:border-gray-600 sm:max-w-full">
<ReactMarkdown
- remarkPlugins={[supersub, remarkGfm, [remarkMath, { singleDollarTextMath: true }]]}
+ remarkPlugins={[
+ /** @ts-ignore */
+ supersub,
+ remarkGfm,
+ [remarkMath, { singleDollarTextMath: true }],
+ ]}
rehypePlugins={[
+ /** @ts-ignore */
[rehypeKatex, { output: 'mathml' }],
+ /** @ts-ignore */
[rehypeHighlight, { ignoreMissing: true }],
]}
- components={{ p: PromptVariableGfm, code }}
+ /** @ts-ignore */
+ components={{ p: PromptVariableGfm, code: codeNoExecution }}
className="prose dark:prose-invert light dark:text-gray-70 my-1"
>
{mainText}
diff --git a/client/src/components/Prompts/PromptEditor.tsx b/client/src/components/Prompts/PromptEditor.tsx
index e47cbc0b11..d01edad32c 100644
--- a/client/src/components/Prompts/PromptEditor.tsx
+++ b/client/src/components/Prompts/PromptEditor.tsx
@@ -9,8 +9,8 @@ import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';
import supersub from 'remark-supersub';
import ReactMarkdown from 'react-markdown';
+import { codeNoExecution } from '~/components/Chat/Messages/Content/Markdown';
import AlwaysMakeProd from '~/components/Prompts/Groups/AlwaysMakeProd';
-import { code } from '~/components/Chat/Messages/Content/Markdown';
import { SaveIcon, CrossIcon } from '~/components/svg';
import { TextareaAutosize } from '~/components/ui';
import { PromptVariableGfm } from './Markdown';
@@ -75,7 +75,7 @@ const PromptEditor: React.FC<Props> = ({ name, isEditing, setIsEditing }) => {
role="button"
className={cn(
'min-h-[8rem] w-full rounded-b-lg border border-border-medium p-4 transition-all duration-150',
- { 'bg-surface-secondary-alt cursor-pointer hover:bg-surface-tertiary': !isEditing },
+ { 'cursor-pointer bg-surface-secondary-alt hover:bg-surface-tertiary': !isEditing },
)}
onClick={() => !isEditing && setIsEditing(true)}
onKeyDown={(e) => {
@@ -107,9 +107,12 @@ const PromptEditor: React.FC<Props> = ({ name, isEditing, setIsEditing }) => {
/>
) : (
<ReactMarkdown
+ /** @ts-ignore */
remarkPlugins={[supersub, remarkGfm, [remarkMath, { singleDollarTextMath: true }]]}
+ /** @ts-ignore */
rehypePlugins={rehypePlugins}
- components={{ p: PromptVariableGfm, code }}
+ /** @ts-ignore */
+ components={{ p: PromptVariableGfm, code: codeNoExecution }}
className="markdown prose dark:prose-invert light my-1 w-full break-words text-text-primary"
>
{field.value}
diff --git a/client/src/components/Prompts/PromptVariables.tsx b/client/src/components/Prompts/PromptVariables.tsx
index 23e9540cb2..8fd25d3095 100644
--- a/client/src/components/Prompts/PromptVariables.tsx
+++ b/client/src/components/Prompts/PromptVariables.tsx
@@ -53,6 +53,7 @@ const PromptVariables = ({
) : (
<div className="flex h-7 items-center">
<span className="text-xs text-text-secondary md:text-sm">
+ {/** @ts-ignore */}
<ReactMarkdown components={{ code: CodeVariableGfm }}>
{localize('com_ui_variables_info')}
</ReactMarkdown>
@@ -68,6 +69,7 @@ const PromptVariables = ({
</span>
{'\u00A0'}
<span className="text-xs text-text-secondary md:text-sm">
+ {/** @ts-ignore */}
<ReactMarkdown components={{ code: CodeVariableGfm }}>
{localize('com_ui_special_variables_info')}
</ReactMarkdown>
@@ -79,6 +81,7 @@ const PromptVariables = ({
</span>
{'\u00A0'}
<span className="text-xs text-text-secondary md:text-sm">
+ {/** @ts-ignore */}
<ReactMarkdown components={{ code: CodeVariableGfm }}>
{localize('com_ui_dropdown_variables_info')}
</ReactMarkdown>
diff --git a/client/src/components/Share/Message.tsx b/client/src/components/Share/Message.tsx
index 7bc112ba8c..9b72ede5aa 100644
--- a/client/src/components/Share/Message.tsx
+++ b/client/src/components/Share/Message.tsx
@@ -6,6 +6,7 @@ import SearchContent from '~/components/Chat/Messages/Content/SearchContent';
import SiblingSwitch from '~/components/Chat/Messages/SiblingSwitch';
import { Plugin } from '~/components/Messages/Content';
import SubRow from '~/components/Chat/Messages/SubRow';
+import { MessageContext } from '~/Providers';
// eslint-disable-next-line import/no-cycle
import MultiMessage from './MultiMessage';
import { cn } from '~/utils';
@@ -31,10 +32,10 @@ export default function Message(props: TMessageProps) {
const {
text = '',
children,
- messageId = null,
- isCreatedByUser = true,
error = false,
+ messageId = '',
unfinished = false,
+ isCreatedByUser = true,
} = message;
let messageLabel = '';
@@ -64,26 +65,33 @@ export default function Message(props: TMessageProps) {
<div className={cn('select-none font-semibold', fontSize)}>{messageLabel}</div>
<div className="flex-col gap-1 md:gap-3">
<div className="flex max-w-full flex-grow flex-col gap-0">
- {/* Legacy Plugins */}
- {message.plugin && <Plugin plugin={message.plugin} />}
- {message.content ? (
- <SearchContent message={message} />
- ) : (
- <MessageContent
- edit={false}
- error={error}
- isLast={false}
- ask={() => ({})}
- text={text}
- message={message}
- isSubmitting={false}
- enterEdit={() => ({})}
- unfinished={!!unfinished}
- isCreatedByUser={isCreatedByUser}
- siblingIdx={siblingIdx ?? 0}
- setSiblingIdx={setSiblingIdx ?? (() => ({}))}
- />
- )}
+ <MessageContext.Provider
+ value={{
+ messageId,
+ conversationId: conversation?.conversationId,
+ }}
+ >
+ {/* Legacy Plugins */}
+ {message.plugin && <Plugin plugin={message.plugin} />}
+ {message.content ? (
+ <SearchContent message={message} />
+ ) : (
+ <MessageContent
+ edit={false}
+ error={error}
+ isLast={false}
+ ask={() => ({})}
+ text={text || ''}
+ message={message}
+ isSubmitting={false}
+ enterEdit={() => ({})}
+ unfinished={unfinished}
+ siblingIdx={siblingIdx ?? 0}
+ isCreatedByUser={isCreatedByUser}
+ setSiblingIdx={setSiblingIdx ?? (() => ({}))}
+ />
+ )}
+ </MessageContext.Provider>
</div>
</div>
<SubRow classes="text-xs">
diff --git a/client/src/components/SidePanel/Agents/AdminSettings.tsx b/client/src/components/SidePanel/Agents/AdminSettings.tsx
new file mode 100644
index 0000000000..dcc48212df
--- /dev/null
+++ b/client/src/components/SidePanel/Agents/AdminSettings.tsx
@@ -0,0 +1,163 @@
+import { useMemo, useEffect } from 'react';
+import { ShieldEllipsis } from 'lucide-react';
+import { useForm, Controller } from 'react-hook-form';
+import { Permissions, SystemRoles, roleDefaults, PermissionTypes } from 'librechat-data-provider';
+import type { Control, UseFormSetValue, UseFormGetValues } from 'react-hook-form';
+import { OGDialog, OGDialogTitle, OGDialogContent, OGDialogTrigger } from '~/components/ui';
+import { useUpdateAgentPermissionsMutation } from '~/data-provider';
+import { useLocalize, useAuthContext } from '~/hooks';
+import { Button, Switch } from '~/components/ui';
+import { useToastContext } from '~/Providers';
+
+type FormValues = Record<Permissions, boolean>;
+
+type LabelControllerProps = {
+ label: string;
+ agentPerm: Permissions;
+ control: Control<FormValues, unknown, FormValues>;
+ setValue: UseFormSetValue<FormValues>;
+ getValues: UseFormGetValues<FormValues>;
+};
+
+const defaultValues = roleDefaults[SystemRoles.USER];
+
+const LabelController: React.FC<LabelControllerProps> = ({
+ control,
+ agentPerm,
+ label,
+ getValues,
+ setValue,
+}) => (
+ <div className="mb-4 flex items-center justify-between gap-2">
+ <button
+ className="cursor-pointer select-none"
+ type="button"
+ onClick={() =>
+ setValue(agentPerm, !getValues(agentPerm), {
+ shouldDirty: true,
+ })
+ }
+ tabIndex={0}
+ >
+ {label}
+ </button>
+ <Controller
+ name={agentPerm}
+ control={control}
+ render={({ field }) => (
+ <Switch
+ {...field}
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ value={field.value.toString()}
+ />
+ )}
+ />
+ </div>
+);
+
+const AdminSettings = () => {
+ const localize = useLocalize();
+ const { user, roles } = useAuthContext();
+ const { showToast } = useToastContext();
+ const { mutate, isLoading } = useUpdateAgentPermissionsMutation({
+ onSuccess: () => {
+ showToast({ status: 'success', message: localize('com_ui_saved') });
+ },
+ onError: () => {
+ showToast({ status: 'error', message: localize('com_ui_error_save_admin_settings') });
+ },
+ });
+
+ const {
+ reset,
+ control,
+ setValue,
+ getValues,
+ handleSubmit,
+ formState: { isSubmitting },
+ } = useForm<FormValues>({
+ mode: 'onChange',
+ defaultValues: useMemo(() => {
+ if (roles?.[SystemRoles.USER]) {
+ return roles[SystemRoles.USER][PermissionTypes.AGENTS];
+ }
+
+ return defaultValues[PermissionTypes.AGENTS];
+ }, [roles]),
+ });
+
+ useEffect(() => {
+ if (roles?.[SystemRoles.USER]?.[PermissionTypes.AGENTS]) {
+ reset(roles[SystemRoles.USER][PermissionTypes.AGENTS]);
+ }
+ }, [roles, reset]);
+
+ if (user?.role !== SystemRoles.ADMIN) {
+ return null;
+ }
+
+ const labelControllerData = [
+ {
+ agentPerm: Permissions.SHARED_GLOBAL,
+ label: localize('com_ui_agents_allow_share_global'),
+ },
+ {
+ agentPerm: Permissions.USE,
+ label: localize('com_ui_agents_allow_use'),
+ },
+ {
+ agentPerm: Permissions.CREATE,
+ label: localize('com_ui_agents_allow_create'),
+ },
+ ];
+
+ const onSubmit = (data: FormValues) => {
+ mutate({ roleName: SystemRoles.USER, updates: data });
+ };
+
+ return (
+ <OGDialog>
+ <OGDialogTrigger asChild>
+ <Button
+ size={'sm'}
+ variant={'outline'}
+ className="btn btn-neutral border-token-border-light relative my-1 h-9 w-full rounded-lg font-medium"
+ >
+ <ShieldEllipsis className="cursor-pointer" />
+ {localize('com_ui_admin_settings')}
+ </Button>
+ </OGDialogTrigger>
+ <OGDialogContent className="w-1/4 bg-white dark:border-gray-700 dark:bg-gray-850 dark:text-gray-300">
+ <OGDialogTitle>{`${localize('com_ui_admin_settings')} - ${localize(
+ 'com_ui_agents',
+ )}`}</OGDialogTitle>
+ <form className="p-2" onSubmit={handleSubmit(onSubmit)}>
+ <div className="py-5">
+ {labelControllerData.map(({ agentPerm, label }) => (
+ <LabelController
+ key={agentPerm}
+ control={control}
+ agentPerm={agentPerm}
+ label={label}
+ getValues={getValues}
+ setValue={setValue}
+ />
+ ))}
+ </div>
+ <div className="flex justify-end">
+ <button
+ type="submit"
+ disabled={isSubmitting || isLoading}
+ className="btn rounded bg-green-500 font-bold text-white transition-all hover:bg-green-600"
+ >
+ {localize('com_ui_save')}
+ </button>
+ </div>
+ </form>
+ </OGDialogContent>
+ </OGDialog>
+ );
+};
+
+export default AdminSettings;
diff --git a/client/src/components/SidePanel/Agents/AgentConfig.tsx b/client/src/components/SidePanel/Agents/AgentConfig.tsx
index fb14d7e5f3..798e75c1bd 100644
--- a/client/src/components/SidePanel/Agents/AgentConfig.tsx
+++ b/client/src/components/SidePanel/Agents/AgentConfig.tsx
@@ -1,24 +1,32 @@
import React, { useState, useMemo, useCallback } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { Controller, useWatch, useFormContext } from 'react-hook-form';
-import { QueryKeys, AgentCapabilities, EModelEndpoint, SystemRoles } from 'librechat-data-provider';
+import {
+ QueryKeys,
+ SystemRoles,
+ Permissions,
+ EModelEndpoint,
+ PermissionTypes,
+ AgentCapabilities,
+} from 'librechat-data-provider';
import type { TConfig, TPlugin } from 'librechat-data-provider';
import type { AgentForm, AgentPanelProps } from '~/common';
import { cn, defaultTextProps, removeFocusOutlines, getEndpointField, getIconKey } from '~/utils';
import { useCreateAgentMutation, useUpdateAgentMutation } from '~/data-provider';
+import { useLocalize, useAuthContext, useHasAccess } from '~/hooks';
import { useToastContext, useFileMapContext } from '~/Providers';
import { icons } from '~/components/Chat/Menus/Endpoints/Icons';
import Action from '~/components/SidePanel/Builder/Action';
import { ToolSelectDialog } from '~/components/Tools';
-import { useLocalize, useAuthContext } from '~/hooks';
import { processAgentOption } from '~/utils';
+import AdminSettings from './AdminSettings';
import { Spinner } from '~/components/svg';
import DeleteButton from './DeleteButton';
import AgentAvatar from './AgentAvatar';
import FileSearch from './FileSearch';
import ShareAgent from './ShareAgent';
import AgentTool from './AgentTool';
-// import CodeForm from './Code/Form';
+import CodeForm from './Code/Form';
import { Panel } from '~/common';
const labelClass = 'mb-2 text-token-text-primary block font-medium';
@@ -55,6 +63,11 @@ export default function AgentConfig({
const tools = useWatch({ control, name: 'tools' });
const agent_id = useWatch({ control, name: 'id' });
+ const hasAccessToShareAgents = useHasAccess({
+ permissionType: PermissionTypes.AGENTS,
+ permission: Permissions.SHARED_GLOBAL,
+ });
+
const toolsEnabled = useMemo(
() => agentsConfig?.capabilities?.includes(AgentCapabilities.tools),
[agentsConfig],
@@ -263,7 +276,7 @@ export default function AgentConfig({
/>
</div>
{/* Instructions */}
- <div className="mb-6">
+ <div className="mb-4">
<label className={labelClass} htmlFor="instructions">
{localize('com_ui_instructions')}
</label>
@@ -275,7 +288,7 @@ export default function AgentConfig({
<textarea
{...field}
value={field.value ?? ''}
- maxLength={32768}
+ // maxLength={32768}
className={cn(inputClass, 'min-h-[100px] resize-y')}
id="instructions"
placeholder={localize('com_agents_instructions_placeholder')}
@@ -297,7 +310,7 @@ export default function AgentConfig({
/>
</div>
{/* Model and Provider */}
- <div className="mb-6">
+ <div className="mb-4">
<label className={labelClass} htmlFor="provider">
{localize('com_ui_model')} <span className="text-red-500">*</span>
</label>
@@ -319,16 +332,23 @@ export default function AgentConfig({
/>
</div>
)}
- <span>{model != null ? model : localize('com_ui_select_model')}</span>
+ <span>{model != null && model ? model : localize('com_ui_select_model')}</span>
</div>
</button>
</div>
- {/* Code Execution */}
- {/* {codeEnabled && <CodeForm agent_id={agent_id} files={code_files} />} */}
- {/* File Search */}
- {fileSearchEnabled && <FileSearch agent_id={agent_id} files={knowledge_files} />}
+ {(codeEnabled || fileSearchEnabled) && (
+ <div className="mb-4 flex w-full flex-col items-start gap-3">
+ <label className="text-token-text-primary block font-medium">
+ {localize('com_assistants_capabilities')}
+ </label>
+ {/* Code Execution */}
+ {codeEnabled && <CodeForm agent_id={agent_id} files={code_files} />}
+ {/* File Search */}
+ {fileSearchEnabled && <FileSearch agent_id={agent_id} files={knowledge_files} />}
+ </div>
+ )}
{/* Agent Tools & Actions */}
- <div className="mb-6">
+ <div className="mb-4">
<label className={labelClass}>
{`${toolsEnabled === true ? localize('com_ui_tools') : ''}
${toolsEnabled === true && actionsEnabled === true ? ' + ' : ''}
@@ -360,7 +380,7 @@ export default function AgentConfig({
<button
type="button"
onClick={() => setShowToolDialog(true)}
- className="btn btn-neutral border-token-border-light relative h-8 w-full rounded-lg font-medium"
+ className="btn btn-neutral border-token-border-light relative h-9 w-full rounded-lg font-medium"
aria-haspopup="dialog"
>
<div className="flex w-full items-center justify-center gap-2">
@@ -373,7 +393,7 @@ export default function AgentConfig({
type="button"
disabled={!agent_id}
onClick={handleAddActions}
- className="btn btn-neutral border-token-border-light relative h-8 w-full rounded-lg font-medium"
+ className="btn btn-neutral border-token-border-light relative h-9 w-full rounded-lg font-medium"
aria-haspopup="dialog"
>
<div className="flex w-full items-center justify-center gap-2">
@@ -384,6 +404,7 @@ export default function AgentConfig({
</div>
</div>
</div>
+ {user?.role === SystemRoles.ADMIN && <AdminSettings />}
{/* Context Button */}
<div className="flex items-center justify-end gap-2">
<DeleteButton
@@ -391,7 +412,8 @@ export default function AgentConfig({
setCurrentAgentId={setCurrentAgentId}
createMutation={create}
/>
- {(agent?.author === user?.id || user?.role === SystemRoles.ADMIN) && (
+ {(agent?.author === user?.id || user?.role === SystemRoles.ADMIN) &&
+ hasAccessToShareAgents && (
<ShareAgent
agent_id={agent_id}
agentName={agent?.name ?? ''}
@@ -401,7 +423,7 @@ export default function AgentConfig({
)}
{/* Submit Button */}
<button
- className="btn btn-primary focus:shadow-outline flex w-full items-center justify-center px-4 py-2 font-semibold text-white hover:bg-green-600 focus:border-green-500"
+ className="btn btn-primary focus:shadow-outline flex h-9 w-full items-center justify-center px-4 py-2 font-semibold text-white hover:bg-green-600 focus:border-green-500"
type="submit"
disabled={create.isLoading || update.isLoading}
aria-busy={create.isLoading || update.isLoading}
diff --git a/client/src/components/SidePanel/Agents/AgentPanel.tsx b/client/src/components/SidePanel/Agents/AgentPanel.tsx
index b7356f3c3b..dec5e333d4 100644
--- a/client/src/components/SidePanel/Agents/AgentPanel.tsx
+++ b/client/src/components/SidePanel/Agents/AgentPanel.tsx
@@ -126,6 +126,9 @@ export default function AgentPanel({
model: _model,
model_parameters,
provider: _provider,
+ agent_ids,
+ end_after_tools,
+ hide_sequential_outputs,
} = data;
const model = _model ?? '';
@@ -143,6 +146,9 @@ export default function AgentPanel({
tools,
provider,
model_parameters,
+ agent_ids,
+ end_after_tools,
+ hide_sequential_outputs,
},
});
return;
@@ -163,6 +169,9 @@ export default function AgentPanel({
tools,
provider,
model_parameters,
+ agent_ids,
+ end_after_tools,
+ hide_sequential_outputs,
});
},
[agent_id, create, update, showToast, localize],
diff --git a/client/src/components/SidePanel/Agents/AgentSelect.tsx b/client/src/components/SidePanel/Agents/AgentSelect.tsx
index bd03b4a3a2..e8aabc2c6d 100644
--- a/client/src/components/SidePanel/Agents/AgentSelect.tsx
+++ b/client/src/components/SidePanel/Agents/AgentSelect.tsx
@@ -58,6 +58,8 @@ export default function AgentSelect({
const capabilities: TAgentCapabilities = {
[AgentCapabilities.execute_code]: false,
[AgentCapabilities.file_search]: false,
+ [AgentCapabilities.end_after_tools]: false,
+ [AgentCapabilities.hide_sequential_outputs]: false,
};
const agentTools: string[] = [];
diff --git a/client/src/components/SidePanel/Agents/Code/Action.tsx b/client/src/components/SidePanel/Agents/Code/Action.tsx
index 4a1af816d5..a2a16d4419 100644
--- a/client/src/components/SidePanel/Agents/Code/Action.tsx
+++ b/client/src/components/SidePanel/Agents/Code/Action.tsx
@@ -1,38 +1,39 @@
-import { useState } from 'react';
import { KeyRoundIcon } from 'lucide-react';
import { AuthType, AgentCapabilities } from 'librechat-data-provider';
-import { useFormContext, Controller, useForm, useWatch } from 'react-hook-form';
+import { useFormContext, Controller, useWatch } from 'react-hook-form';
import type { AgentForm } from '~/common';
import {
- Input,
- OGDialog,
Checkbox,
HoverCard,
HoverCardContent,
HoverCardPortal,
HoverCardTrigger,
- Button,
} from '~/components/ui';
-import OGDialogTemplate from '~/components/ui/OGDialogTemplate';
-import { useLocalize, useAuthCodeTool } from '~/hooks';
+import { useLocalize, useCodeApiKeyForm } from '~/hooks';
import { CircleHelpIcon } from '~/components/svg';
+import ApiKeyDialog from './ApiKeyDialog';
import { ESide } from '~/common';
-type ApiKeyFormData = {
- apiKey: string;
- authType?: string | AuthType;
-};
-
export default function Action({ authType = '', isToolAuthenticated = false }) {
const localize = useLocalize();
const methods = useFormContext<AgentForm>();
const { control, setValue, getValues } = methods;
- const [isDialogOpen, setIsDialogOpen] = useState(false);
- const runCodeIsEnabled = useWatch({ control, name: AgentCapabilities.execute_code });
-
- const { installTool, removeTool } = useAuthCodeTool({ isEntityTool: true });
+ const {
+ onSubmit,
+ isDialogOpen,
+ setIsDialogOpen,
+ handleRevokeApiKey,
+ methods: keyFormMethods,
+ } = useCodeApiKeyForm({
+ onSubmit: () => {
+ setValue(AgentCapabilities.execute_code, true, { shouldDirty: true });
+ },
+ onRevoke: () => {
+ setValue(AgentCapabilities.execute_code, false, { shouldDirty: true });
+ },
+ });
- const { reset, register, handleSubmit } = useForm<ApiKeyFormData>();
+ const runCodeIsEnabled = useWatch({ control, name: AgentCapabilities.execute_code });
const isUserProvided = authType === AuthType.USER_PROVIDED;
const handleCheckboxChange = (checked: boolean) => {
@@ -45,18 +46,6 @@ export default function Action({ authType = '', isToolAuthenticated = false }) {
}
};
- const onSubmit = (data: { apiKey: string }) => {
- reset();
- installTool(data.apiKey);
- setIsDialogOpen(false);
- };
-
- const handleRevokeApiKey = () => {
- reset();
- removeTool();
- setIsDialogOpen(false);
- };
-
return (
<>
<HoverCard openDelay={50}>
@@ -87,7 +76,7 @@ export default function Action({ authType = '', isToolAuthenticated = false }) {
className="form-check-label text-token-text-primary w-full cursor-pointer"
htmlFor={AgentCapabilities.execute_code}
>
- {localize('com_agents_execute_code')}
+ {localize('com_ui_run_code')}
</label>
</button>
<div className="ml-2 flex gap-2">
@@ -104,48 +93,23 @@ export default function Action({ authType = '', isToolAuthenticated = false }) {
<HoverCardContent side={ESide.Top} className="w-80">
<div className="space-y-2">
<p className="text-sm text-text-secondary">
- {/* // TODO: add a Code Interpreter description */}
+ {localize('com_agents_code_interpreter')}
</p>
</div>
</HoverCardContent>
</HoverCardPortal>
</div>
</HoverCard>
- <OGDialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
- <OGDialogTemplate
- className="w-11/12 sm:w-1/4"
- title={localize('com_agents_tool_not_authenticated')}
- main={
- <form onSubmit={handleSubmit(onSubmit)}>
- <Input
- type="password"
- placeholder="Enter API Key"
- autoComplete="one-time-code"
- readOnly={true}
- onFocus={(e) => (e.target.readOnly = false)}
- {...register('apiKey', { required: true })}
- />
- </form>
- }
- selection={{
- selectHandler: handleSubmit(onSubmit),
- selectClasses: 'bg-green-500 hover:bg-green-600 text-white',
- selectText: localize('com_ui_save'),
- }}
- buttons={
- isUserProvided &&
- isToolAuthenticated && (
- <Button
- onClick={handleRevokeApiKey}
- className="bg-destructive text-white transition-all duration-200 hover:bg-destructive/80"
- >
- {localize('com_ui_revoke')}
- </Button>
- )
- }
- showCancelButton={true}
- />
- </OGDialog>
+ <ApiKeyDialog
+ isOpen={isDialogOpen}
+ onSubmit={onSubmit}
+ onRevoke={handleRevokeApiKey}
+ onOpenChange={setIsDialogOpen}
+ register={keyFormMethods.register}
+ isToolAuthenticated={isToolAuthenticated}
+ handleSubmit={keyFormMethods.handleSubmit}
+ isUserProvided={authType === AuthType.USER_PROVIDED}
+ />
</>
);
}
diff --git a/client/src/components/SidePanel/Agents/Code/ApiKeyDialog.tsx b/client/src/components/SidePanel/Agents/Code/ApiKeyDialog.tsx
new file mode 100644
index 0000000000..ae0e76c324
--- /dev/null
+++ b/client/src/components/SidePanel/Agents/Code/ApiKeyDialog.tsx
@@ -0,0 +1,106 @@
+import type { UseFormRegister, UseFormHandleSubmit } from 'react-hook-form';
+import type { ApiKeyFormData } from '~/common';
+import OGDialogTemplate from '~/components/ui/OGDialogTemplate';
+import { Input, Button, OGDialog } from '~/components/ui';
+import { useLocalize } from '~/hooks';
+
+export default function ApiKeyDialog({
+ isOpen,
+ onSubmit,
+ onRevoke,
+ onOpenChange,
+ isUserProvided,
+ isToolAuthenticated,
+ register,
+ handleSubmit,
+}: {
+ isOpen: boolean;
+ onOpenChange: (open: boolean) => void;
+ onSubmit: (data: { apiKey: string }) => void;
+ onRevoke: () => void;
+ isUserProvided: boolean;
+ isToolAuthenticated: boolean;
+ register: UseFormRegister<ApiKeyFormData>;
+ handleSubmit: UseFormHandleSubmit<ApiKeyFormData>;
+}) {
+ const localize = useLocalize();
+ const languageIcons = [
+ 'python.svg',
+ 'nodedotjs.svg',
+ 'tsnode.svg',
+ 'rust.svg',
+ 'go.svg',
+ 'c.svg',
+ 'cplusplus.svg',
+ 'php.svg',
+ 'fortran.svg',
+ ];
+
+ return (
+ <OGDialog open={isOpen} onOpenChange={onOpenChange}>
+ <OGDialogTemplate
+ className="w-11/12 sm:w-[450px]"
+ title=""
+ main={
+ <>
+ <div className="mb-4 text-center font-medium">
+ {localize('com_ui_librechat_code_api_title')}
+ </div>
+ <div className="mb-4 text-center text-sm">
+ {localize('com_ui_librechat_code_api_subtitle')}
+ </div>
+ {/* Language Icons Stack */}
+ <div className="mb-6">
+ <div className="mx-auto mb-4 flex max-w-[400px] flex-wrap justify-center gap-3">
+ {languageIcons.map((icon) => (
+ <div key={icon} className="h-6 w-6">
+ <img
+ src={`/assets/${icon}`}
+ alt=""
+ className="h-full w-full object-contain opacity-[0.85] dark:invert"
+ />
+ </div>
+ ))}
+ </div>
+ <a
+ href="https://code.librechat.ai/pricing"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="block text-center text-[15px] font-medium text-blue-500 underline decoration-1 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300"
+ >
+ {localize('com_ui_librechat_code_api_key')}
+ </a>
+ </div>
+ <form onSubmit={handleSubmit(onSubmit)}>
+ <Input
+ type="password"
+ placeholder={localize('com_ui_enter_api_key')}
+ autoComplete="one-time-code"
+ readOnly={true}
+ onFocus={(e) => (e.target.readOnly = false)}
+ {...register('apiKey', { required: true })}
+ />
+ </form>
+ </>
+ }
+ selection={{
+ selectHandler: handleSubmit(onSubmit),
+ selectClasses: 'bg-green-500 hover:bg-green-600 text-white',
+ selectText: localize('com_ui_save'),
+ }}
+ buttons={
+ isUserProvided &&
+ isToolAuthenticated && (
+ <Button
+ onClick={onRevoke}
+ className="bg-destructive text-white transition-all duration-200 hover:bg-destructive/80"
+ >
+ {localize('com_ui_revoke')}
+ </Button>
+ )
+ }
+ showCancelButton={true}
+ />
+ </OGDialog>
+ );
+}
diff --git a/client/src/components/SidePanel/Agents/Code/Files.tsx b/client/src/components/SidePanel/Agents/Code/Files.tsx
index 2e92671571..1775ee88a9 100644
--- a/client/src/components/SidePanel/Agents/Code/Files.tsx
+++ b/client/src/components/SidePanel/Agents/Code/Files.tsx
@@ -12,6 +12,7 @@ import type { ExtendedFile, AgentForm } from '~/common';
import { useFileHandling, useLocalize, useLazyEffect } from '~/hooks';
import FileRow from '~/components/Chat/Input/Files/FileRow';
import { useGetFileConfig } from '~/data-provider';
+import { AttachmentIcon } from '~/components/svg';
import { useChatContext } from '~/Providers';
const tool_resource = EToolResources.execute_code;
@@ -68,8 +69,8 @@ export default function Files({
return (
<div className="mb-2 w-full">
- <div className="flex flex-col gap-4">
- <div className="text-token-text-tertiary rounded-lg text-xs">
+ <div className="flex flex-col gap-3">
+ <div className="rounded-lg text-xs text-text-secondary">
{localize('com_assistants_code_interpreter_files')}
</div>
<FileRow
@@ -85,10 +86,10 @@ export default function Files({
<button
type="button"
disabled={!agent_id || codeChecked === false}
- className="btn btn-neutral border-token-border-light relative h-8 w-full rounded-lg font-medium"
+ className="btn btn-neutral border-token-border-light relative h-9 w-full rounded-lg font-medium"
onClick={handleButtonClick}
>
- <div className="flex w-full items-center justify-center gap-2">
+ <div className="flex w-full items-center justify-center gap-1">
<input
multiple={true}
type="file"
@@ -98,7 +99,8 @@ export default function Files({
disabled={!agent_id || codeChecked === false}
onChange={handleFileChange}
/>
- {localize('com_ui_upload_files')}
+ <AttachmentIcon className="text-token-text-primary h-4 w-4" />
+ {localize('com_ui_upload_code_files')}
</div>
</button>
</div>
diff --git a/client/src/components/SidePanel/Agents/Code/Form.tsx b/client/src/components/SidePanel/Agents/Code/Form.tsx
index 6985c2b389..8375983056 100644
--- a/client/src/components/SidePanel/Agents/Code/Form.tsx
+++ b/client/src/components/SidePanel/Agents/Code/Form.tsx
@@ -16,13 +16,18 @@ export default function CodeForm({
const { data } = useVerifyAgentToolAuth({ toolId: Tools.execute_code });
return (
- <div className="mb-4">
- <div className="mb-1.5 flex items-center">
- <span>
- <label className="text-token-text-primary block font-medium">
- {localize('com_assistants_capabilities')}
- </label>
- </span>
+ <div className="w-full">
+ <div className="mb-1.5 flex items-center gap-2">
+ <div className="flex flex-row items-center gap-1">
+ <div className="flex items-center gap-1">
+ <span className="text-token-text-primary block font-medium">
+ {localize('com_agents_code_interpreter_title')}
+ </span>
+ <span className="text-xs text-text-secondary">
+ {localize('com_agents_by_librechat')}
+ </span>
+ </div>
+ </div>
</div>
<div className="flex flex-col items-start gap-2">
<Action authType={data?.message} isToolAuthenticated={data?.authenticated} />
diff --git a/client/src/components/SidePanel/Agents/FileSearch.tsx b/client/src/components/SidePanel/Agents/FileSearch.tsx
index bd377fd072..8ce49b91d4 100644
--- a/client/src/components/SidePanel/Agents/FileSearch.tsx
+++ b/client/src/components/SidePanel/Agents/FileSearch.tsx
@@ -67,7 +67,7 @@ export default function FileSearch({
};
return (
- <div className="mb-6">
+ <div className="w-full">
<div className="mb-1.5 flex items-center gap-2">
<span>
<label className="text-token-text-primary block font-medium">
@@ -76,12 +76,12 @@ export default function FileSearch({
</span>
</div>
<FileSearchCheckbox />
- <div className="flex flex-col gap-2">
+ <div className="flex flex-col gap-3">
<div>
<button
type="button"
disabled={!agent_id || fileSearchChecked === false}
- className="btn btn-neutral border-token-border-light relative h-8 w-full rounded-lg font-medium"
+ className="btn btn-neutral border-token-border-light relative h-9 w-full rounded-lg font-medium"
onClick={handleButtonClick}
>
<div className="flex w-full items-center justify-center gap-1">
@@ -95,13 +95,13 @@ export default function FileSearch({
disabled={!agent_id || fileSearchChecked === false}
onChange={handleFileChange}
/>
- {localize('com_ui_upload_files')}
+ {localize('com_ui_upload_file_search')}
</div>
</button>
</div>
{/* Disabled Message */}
{agent_id ? null : (
- <div className="text-sm text-text-secondary">
+ <div className="text-xs text-text-secondary">
{localize('com_agents_file_search_disabled')}
</div>
)}
diff --git a/client/src/components/SidePanel/Agents/ModelPanel.tsx b/client/src/components/SidePanel/Agents/ModelPanel.tsx
index 0f61fe74a6..745428122c 100644
--- a/client/src/components/SidePanel/Agents/ModelPanel.tsx
+++ b/client/src/components/SidePanel/Agents/ModelPanel.tsx
@@ -31,14 +31,17 @@ export default function Parameters({
: (providerOption as StringOption | undefined)?.value;
return value ?? '';
}, [providerOption]);
- const models = useMemo(() => (provider ? modelsData[provider] : []), [modelsData, provider]);
+ const models = useMemo(
+ () => (provider ? modelsData[provider] ?? [] : []),
+ [modelsData, provider],
+ );
useEffect(() => {
const _model = model ?? '';
if (provider && _model) {
const modelExists = models.includes(_model);
if (!modelExists) {
- const newModels = modelsData[provider];
+ const newModels = modelsData[provider] ?? [];
setValue('model', newModels[0] ?? '');
}
}
@@ -105,14 +108,16 @@ export default function Parameters({
<SelectDropDown
emptyTitle={true}
value={field.value ?? ''}
+ title={localize('com_ui_provider')}
placeholder={localize('com_ui_select_provider')}
+ searchPlaceholder={localize('com_ui_select_search_provider')}
setValue={field.onChange}
availableValues={providers}
showAbove={false}
showLabel={false}
className={cn(
cardStyle,
- 'flex h-[40px] w-full flex-none items-center justify-center border-none px-4 hover:cursor-pointer',
+ 'flex h-9 w-full flex-none items-center justify-center border-none px-4 hover:cursor-pointer',
(field.value === undefined || field.value === '') &&
'border-2 border-yellow-400',
)}
diff --git a/client/src/components/SidePanel/Agents/Sequential/HideSequential.tsx b/client/src/components/SidePanel/Agents/Sequential/HideSequential.tsx
new file mode 100644
index 0000000000..f52207eabc
--- /dev/null
+++ b/client/src/components/SidePanel/Agents/Sequential/HideSequential.tsx
@@ -0,0 +1,74 @@
+import { AgentCapabilities } from 'librechat-data-provider';
+import { useFormContext, Controller } from 'react-hook-form';
+import type { AgentForm } from '~/common';
+import {
+ Checkbox,
+ HoverCard,
+ // HoverCardContent,
+ // HoverCardPortal,
+ // HoverCardTrigger,
+} from '~/components/ui';
+// import { CircleHelpIcon } from '~/components/svg';
+// import { useLocalize } from '~/hooks';
+// import { ESide } from '~/common';
+
+export default function HideSequential() {
+ // const localize = useLocalize();
+ const methods = useFormContext<AgentForm>();
+ const { control, setValue, getValues } = methods;
+
+ return (
+ <>
+ <HoverCard openDelay={50}>
+ <div className="my-2 flex items-center">
+ <Controller
+ name={AgentCapabilities.hide_sequential_outputs}
+ control={control}
+ render={({ field }) => (
+ <Checkbox
+ {...field}
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ className="relative float-left mr-2 inline-flex h-4 w-4 cursor-pointer"
+ value={field.value?.toString()}
+ />
+ )}
+ />
+ <button
+ type="button"
+ className="flex items-center space-x-2"
+ onClick={() =>
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
+ setValue(
+ AgentCapabilities.hide_sequential_outputs,
+ !getValues(AgentCapabilities.hide_sequential_outputs),
+ {
+ shouldDirty: true,
+ },
+ )
+ }
+ >
+ <label
+ className="form-check-label text-token-text-primary w-full cursor-pointer"
+ htmlFor={AgentCapabilities.hide_sequential_outputs}
+ >
+ Hide Sequential Agent Outputs except the last agent&apos;s
+ </label>
+ {/* <HoverCardTrigger>
+ <CircleHelpIcon className="h-5 w-5 text-gray-500" />
+ </HoverCardTrigger> */}
+ </button>
+ {/* <HoverCardPortal>
+ <HoverCardContent side={ESide.Top} className="w-80">
+ <div className="space-y-2">
+ <p className="text-sm text-text-secondary">
+ {localize('com_agents_ttg_info')}
+ </p>
+ </div>
+ </HoverCardContent>
+ </HoverCardPortal> */}
+ </div>
+ </HoverCard>
+ </>
+ );
+}
diff --git a/client/src/components/SidePanel/Agents/Sequential/SequentialAgents.tsx b/client/src/components/SidePanel/Agents/Sequential/SequentialAgents.tsx
new file mode 100644
index 0000000000..14b1c07251
--- /dev/null
+++ b/client/src/components/SidePanel/Agents/Sequential/SequentialAgents.tsx
@@ -0,0 +1,153 @@
+import { Plus, X } from 'lucide-react';
+import React, { useRef, useState } from 'react';
+import { Transition } from 'react-transition-group';
+import { Constants } from 'librechat-data-provider';
+import { cn, defaultTextProps, removeFocusOutlines } from '~/utils';
+import { TooltipAnchor } from '~/components/ui';
+import HideSequential from './HideSequential';
+
+interface SequentialAgentsProps {
+ field: {
+ value: string[];
+ onChange: (value: string[]) => void;
+ };
+}
+
+const labelClass = 'mb-2 text-token-text-primary block font-medium';
+const inputClass = cn(
+ defaultTextProps,
+ 'flex w-full px-3 py-2 dark:border-gray-800 dark:bg-gray-800 rounded-xl mb-2',
+ removeFocusOutlines,
+);
+
+const maxAgents = 5;
+
+const SequentialAgents: React.FC<SequentialAgentsProps> = ({ field }) => {
+ const inputRefs = useRef<(HTMLInputElement | null)[]>([]);
+ const nodeRef = useRef(null);
+ const [newAgentId, setNewAgentId] = useState('');
+
+ const handleAddAgentId = () => {
+ if (newAgentId.trim() && field.value.length < maxAgents) {
+ const newValues = [...field.value, newAgentId];
+ field.onChange(newValues);
+ setNewAgentId('');
+ }
+ };
+
+ const handleDeleteAgentId = (index: number) => {
+ const newValues = field.value.filter((_, i) => i !== index);
+ field.onChange(newValues);
+ };
+
+ const defaultStyle = {
+ transition: 'opacity 200ms ease-in-out',
+ opacity: 0,
+ };
+
+ const triggerShake = (element: HTMLElement) => {
+ element.classList.remove('shake');
+ void element.offsetWidth;
+ element.classList.add('shake');
+ setTimeout(() => {
+ element.classList.remove('shake');
+ }, 200);
+ };
+
+ const transitionStyles = {
+ entering: { opacity: 1 },
+ entered: { opacity: 1 },
+ exiting: { opacity: 0 },
+ exited: { opacity: 0 },
+ };
+
+ const hasReachedMax = field.value.length >= Constants.MAX_CONVO_STARTERS;
+
+ return (
+ <div className="relative">
+ <label className={labelClass} htmlFor="agent_ids">
+ Sequential Agents
+ </label>
+ <div className="mt-4 space-y-2">
+ <HideSequential />
+ {/* Display existing agents first */}
+ {field.value.map((agentId, index) => (
+ <div key={index} className="relative">
+ <input
+ ref={(el) => (inputRefs.current[index] = el)}
+ value={agentId}
+ onChange={(e) => {
+ const newValue = [...field.value];
+ newValue[index] = e.target.value;
+ field.onChange(newValue);
+ }}
+ className={`${inputClass} pr-10`}
+ type="text"
+ maxLength={64}
+ />
+ <TooltipAnchor
+ side="top"
+ description={'Remove agent ID'}
+ className="absolute right-1 top-1 flex size-7 items-center justify-center rounded-lg transition-colors duration-200 hover:bg-surface-hover"
+ onClick={() => handleDeleteAgentId(index)}
+ >
+ <X className="size-4" />
+ </TooltipAnchor>
+ </div>
+ ))}
+ {/* Input for new agent at the bottom */}
+ <div className="relative">
+ <input
+ ref={(el) => (inputRefs.current[field.value.length] = el)}
+ value={newAgentId}
+ maxLength={64}
+ className={`${inputClass} pr-10`}
+ type="text"
+ placeholder={hasReachedMax ? 'Max agents reached' : 'Enter agent ID (e.g. agent_1234)'}
+ onChange={(e) => setNewAgentId(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ if (hasReachedMax) {
+ triggerShake(e.currentTarget);
+ } else {
+ handleAddAgentId();
+ }
+ }
+ }}
+ />
+ <Transition
+ nodeRef={nodeRef}
+ in={field.value.length < Constants.MAX_CONVO_STARTERS}
+ timeout={200}
+ unmountOnExit
+ >
+ {(state: string) => (
+ <div
+ ref={nodeRef}
+ style={{
+ ...defaultStyle,
+ ...transitionStyles[state as keyof typeof transitionStyles],
+ transition: state === 'entering' ? 'none' : defaultStyle.transition,
+ }}
+ className="absolute right-1 top-1"
+ >
+ <TooltipAnchor
+ side="top"
+ description={hasReachedMax ? 'Max agents reached' : 'Add agent ID'}
+ className="flex size-7 items-center justify-center rounded-lg transition-colors duration-200 hover:bg-surface-hover"
+ onClick={handleAddAgentId}
+ disabled={hasReachedMax}
+ >
+ <Plus className="size-4" />
+ </TooltipAnchor>
+ </div>
+ )}
+ </Transition>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default SequentialAgents;
diff --git a/client/src/components/SidePanel/Builder/CodeFiles.tsx b/client/src/components/SidePanel/Builder/CodeFiles.tsx
index 94b9efe914..22be0a5dcd 100644
--- a/client/src/components/SidePanel/Builder/CodeFiles.tsx
+++ b/client/src/components/SidePanel/Builder/CodeFiles.tsx
@@ -76,7 +76,7 @@ export default function CodeFiles({
<button
type="button"
disabled={!assistant_id}
- className="btn btn-neutral border-token-border-light relative h-8 w-full rounded-lg font-medium"
+ className="btn btn-neutral border-token-border-light relative h-9 w-full rounded-lg font-medium"
onClick={handleButtonClick}
>
<div className="flex w-full items-center justify-center gap-2">
diff --git a/client/src/components/SidePanel/Nav.tsx b/client/src/components/SidePanel/Nav.tsx
index d5b35b5faf..56964c9a34 100644
--- a/client/src/components/SidePanel/Nav.tsx
+++ b/client/src/components/SidePanel/Nav.tsx
@@ -32,6 +32,7 @@ export default function Nav({ links, isCollapsed, resize, defaultActive }: NavPr
<TooltipAnchor
description={localize(link.title)}
side="left"
+ key={`nav-link-${index}`}
render={
<Button
variant="ghost"
diff --git a/client/src/components/SidePanel/SidePanel.tsx b/client/src/components/SidePanel/SidePanel.tsx
index b150e2c2dc..dacd0beb16 100644
--- a/client/src/components/SidePanel/SidePanel.tsx
+++ b/client/src/components/SidePanel/SidePanel.tsx
@@ -6,8 +6,8 @@ import {
useGetStartupConfig,
useUserKeyQuery,
} from 'librechat-data-provider/react-query';
+import type { TEndpointsConfig, TInterfaceConfig } from 'librechat-data-provider';
import type { ImperativePanelHandle } from 'react-resizable-panels';
-import type { TEndpointsConfig } from 'librechat-data-provider';
import { ResizableHandleAlt, ResizablePanel, ResizablePanelGroup } from '~/components/ui/Resizable';
import { useMediaQuery, useLocalStorage, useLocalize } from '~/hooks';
import useSideNavLinks from '~/hooks/Nav/useSideNavLinks';
@@ -65,7 +65,7 @@ const SidePanel = ({
const { data: endpointsConfig = {} as TEndpointsConfig } = useGetEndpointsQuery();
const { data: startupConfig } = useGetStartupConfig();
const interfaceConfig = useMemo(
- () => startupConfig?.interface ?? defaultInterface,
+ () => (startupConfig?.interface ?? defaultInterface) as Partial<TInterfaceConfig>,
[startupConfig],
);
@@ -117,17 +117,17 @@ const SidePanel = ({
});
const calculateLayout = useCallback(() => {
- if (!artifacts) {
+ if (artifacts == null) {
const navSize = defaultLayout.length === 2 ? defaultLayout[1] : defaultLayout[2];
return [100 - navSize, navSize];
} else {
- const navSize = Math.max(minSize, navCollapsedSize);
+ const navSize = 0;
const remainingSpace = 100 - navSize;
const newMainSize = Math.floor(remainingSpace / 2);
const artifactsSize = remainingSpace - newMainSize;
return [newMainSize, artifactsSize, navSize];
}
- }, [artifacts, defaultLayout, minSize, navCollapsedSize]);
+ }, [artifacts, defaultLayout]);
const currentLayout = useMemo(() => normalizeLayout(calculateLayout()), [calculateLayout]);
@@ -261,7 +261,7 @@ const SidePanel = ({
: 'opacity-100',
)}
>
- {interfaceConfig.modelSelect && (
+ {interfaceConfig.modelSelect === true && (
<div
className={cn(
'sticky left-0 right-0 top-0 z-[100] flex h-[52px] flex-wrap items-center justify-center bg-background',
diff --git a/client/src/components/ui/DropdownPopup.tsx b/client/src/components/ui/DropdownPopup.tsx
index b85de89403..ad161db838 100644
--- a/client/src/components/ui/DropdownPopup.tsx
+++ b/client/src/components/ui/DropdownPopup.tsx
@@ -1,5 +1,6 @@
import React from 'react';
import * as Ariakit from '@ariakit/react';
+import { cn } from '~/utils';
interface DropdownProps {
trigger: React.ReactNode;
@@ -15,11 +16,21 @@ interface DropdownProps {
isOpen: boolean;
setIsOpen: (isOpen: boolean) => void;
className?: string;
+ iconClassName?: string;
anchor?: { x: string; y: string };
+ modal?: boolean;
menuId: string;
}
-const DropdownPopup: React.FC<DropdownProps> = ({ trigger, items, isOpen, setIsOpen, menuId }) => {
+const DropdownPopup: React.FC<DropdownProps> = ({
+ trigger,
+ items,
+ isOpen,
+ setIsOpen,
+ menuId,
+ modal,
+ iconClassName,
+}) => {
const menu = Ariakit.useMenuStore({ open: isOpen, setOpen: setIsOpen });
return (
@@ -27,8 +38,9 @@ const DropdownPopup: React.FC<DropdownProps> = ({ trigger, items, isOpen, setIsO
{trigger}
<Ariakit.Menu
id={menuId}
- className="z-50 mt-2 overflow-hidden rounded-lg bg-header-primary p-1.5 shadow-lg outline-none focus-visible:ring-2 focus-visible:ring-ring-primary"
+ className="absolute z-50 mt-2 overflow-hidden rounded-lg bg-header-primary p-1.5 shadow-lg outline-none focus-visible:ring-2 focus-visible:ring-ring-primary"
gutter={8}
+ modal={modal}
>
{items
.filter((item) => item.show !== false)
@@ -49,7 +61,7 @@ const DropdownPopup: React.FC<DropdownProps> = ({ trigger, items, isOpen, setIsO
}}
>
{item.icon != null && (
- <span className="mr-2 h-5 w-5" aria-hidden="true">
+ <span className={cn('mr-2 h-5 w-5', iconClassName)} aria-hidden="true">
{item.icon}
</span>
)}
diff --git a/client/src/components/ui/MultiSearch.tsx b/client/src/components/ui/MultiSearch.tsx
index 1856449340..8dda8cc8c9 100644
--- a/client/src/components/ui/MultiSearch.tsx
+++ b/client/src/components/ui/MultiSearch.tsx
@@ -81,13 +81,13 @@ function defaultGetStringKey(node: unknown): string {
* @returns
*/
export function useMultiSearch<OptionsType extends unknown[]>({
- availableOptions,
+ availableOptions = [] as unknown as OptionsType,
placeholder,
getTextKeyOverride,
className,
disabled = false,
}: {
- availableOptions: OptionsType;
+ availableOptions?: OptionsType;
placeholder?: string;
getTextKeyOverride?: (node: OptionsType[0]) => string;
className?: string;
diff --git a/client/src/components/ui/SelectDropDown.tsx b/client/src/components/ui/SelectDropDown.tsx
index 26ed808b28..b36e915973 100644
--- a/client/src/components/ui/SelectDropDown.tsx
+++ b/client/src/components/ui/SelectDropDown.tsx
@@ -20,7 +20,7 @@ type SelectDropDownProps = {
value: string | null | Option | OptionWithIcon;
setValue: DropdownValueSetter | ((value: string) => void);
tabIndex?: number;
- availableValues: string[] | Option[] | OptionWithIcon[];
+ availableValues?: string[] | Option[] | OptionWithIcon[];
emptyTitle?: boolean;
showAbove?: boolean;
showLabel?: boolean;
@@ -89,18 +89,20 @@ function SelectDropDown({
title = localize('com_ui_model');
}
+ const values = availableValues ?? [];
+
// Detemine if we should to convert this component into a searchable select. If we have enough elements, a search
// input will appear near the top of the menu, allowing correct filtering of different model menu items. This will
// reset once the component is unmounted (as per a normal search)
const [filteredValues, searchRender] = useMultiSearch<string[] | Option[]>({
- availableOptions: availableValues,
+ availableOptions: values,
placeholder: searchPlaceholder,
getTextKeyOverride: (option) => getOptionText(option).toUpperCase(),
className: searchClassName,
disabled,
});
const hasSearchRender = searchRender != null;
- const options = hasSearchRender ? filteredValues : availableValues;
+ const options = hasSearchRender ? filteredValues : values;
const renderIcon = showOptionIcon && value != null && (value as OptionWithIcon).icon != null;
diff --git a/client/src/components/ui/Tooltip.tsx b/client/src/components/ui/Tooltip.tsx
index ec969095ec..2bf89e24d0 100644
--- a/client/src/components/ui/Tooltip.tsx
+++ b/client/src/components/ui/Tooltip.tsx
@@ -7,6 +7,7 @@ interface TooltipAnchorProps extends Ariakit.TooltipAnchorProps {
description: string;
side?: 'top' | 'bottom' | 'left' | 'right';
className?: string;
+ focusable?: boolean;
role?: string;
}
diff --git a/client/src/data-provider/Agents/index.ts b/client/src/data-provider/Agents/index.ts
new file mode 100644
index 0000000000..3cf1ef310b
--- /dev/null
+++ b/client/src/data-provider/Agents/index.ts
@@ -0,0 +1 @@
+export * from './queries';
diff --git a/client/src/data-provider/Agents/queries.ts b/client/src/data-provider/Agents/queries.ts
new file mode 100644
index 0000000000..838984ff10
--- /dev/null
+++ b/client/src/data-provider/Agents/queries.ts
@@ -0,0 +1,76 @@
+import { QueryKeys, dataService, EModelEndpoint, defaultOrderQuery } from 'librechat-data-provider';
+import { useQuery, useQueryClient } from '@tanstack/react-query';
+import type { QueryObserverResult, UseQueryOptions } from '@tanstack/react-query';
+import type t from 'librechat-data-provider';
+
+/**
+ * AGENTS
+ */
+
+/**
+ * Hook for getting all available tools for A
+ */
+export const useAvailableAgentToolsQuery = (): QueryObserverResult<t.TPlugin[]> => {
+ const queryClient = useQueryClient();
+ const endpointsConfig = queryClient.getQueryData<t.TEndpointsConfig>([QueryKeys.endpoints]);
+
+ const enabled = !!endpointsConfig?.[EModelEndpoint.agents];
+ return useQuery<t.TPlugin[]>([QueryKeys.tools], () => dataService.getAvailableAgentTools(), {
+ refetchOnWindowFocus: false,
+ refetchOnReconnect: false,
+ refetchOnMount: false,
+ enabled,
+ });
+};
+
+/**
+ * Hook for listing all Agents, with optional parameters provided for pagination and sorting
+ */
+export const useListAgentsQuery = <TData = t.AgentListResponse>(
+ params: t.AgentListParams = defaultOrderQuery,
+ config?: UseQueryOptions<t.AgentListResponse, unknown, TData>,
+): QueryObserverResult<TData> => {
+ const queryClient = useQueryClient();
+ const endpointsConfig = queryClient.getQueryData<t.TEndpointsConfig>([QueryKeys.endpoints]);
+
+ const enabled = !!endpointsConfig?.[EModelEndpoint.agents];
+ return useQuery<t.AgentListResponse, unknown, TData>(
+ [QueryKeys.agents, params],
+ () => dataService.listAgents(params),
+ {
+ // Example selector to sort them by created_at
+ // select: (res) => {
+ // return res.data.sort((a, b) => a.created_at - b.created_at);
+ // },
+ refetchOnWindowFocus: false,
+ refetchOnReconnect: false,
+ refetchOnMount: false,
+ retry: false,
+ ...config,
+ enabled: config?.enabled !== undefined ? config.enabled && enabled : enabled,
+ },
+ );
+};
+
+/**
+ * Hook for retrieving details about a single agent
+ */
+export const useGetAgentByIdQuery = (
+ agent_id: string,
+ config?: UseQueryOptions<t.Agent>,
+): QueryObserverResult<t.Agent> => {
+ return useQuery<t.Agent>(
+ [QueryKeys.agent, agent_id],
+ () =>
+ dataService.getAgentById({
+ agent_id,
+ }),
+ {
+ refetchOnWindowFocus: false,
+ refetchOnReconnect: false,
+ refetchOnMount: false,
+ retry: false,
+ ...config,
+ },
+ );
+};
diff --git a/client/src/data-provider/Tools/index.ts b/client/src/data-provider/Tools/index.ts
index c8699b2430..d0720956a0 100644
--- a/client/src/data-provider/Tools/index.ts
+++ b/client/src/data-provider/Tools/index.ts
@@ -1,2 +1,2 @@
export * from './queries';
-// export * from './mutations';
+export * from './mutations';
diff --git a/client/src/data-provider/Tools/mutations.ts b/client/src/data-provider/Tools/mutations.ts
new file mode 100644
index 0000000000..0c87c6e5eb
--- /dev/null
+++ b/client/src/data-provider/Tools/mutations.ts
@@ -0,0 +1,42 @@
+import { dataService, QueryKeys, Tools } from 'librechat-data-provider';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
+import type { UseMutationResult } from '@tanstack/react-query';
+import type * as t from 'librechat-data-provider';
+
+export const useToolCallMutation = <T extends t.ToolId>(
+ toolId: T,
+ options?: t.ToolCallMutationOptions<T>,
+): UseMutationResult<t.ToolCallResponse, Error, t.ToolParams<T>> => {
+ const queryClient = useQueryClient();
+ return useMutation(
+ (toolParams: t.ToolParams<T>) => {
+ return dataService.callTool({
+ toolId,
+ toolParams,
+ });
+ },
+ {
+ onMutate: (variables) => options?.onMutate?.(variables),
+ onError: (error, variables, context) => options?.onError?.(error, variables, context),
+ onSuccess: (response, variables, context) => {
+ queryClient.setQueryData<t.ToolCallResults>(
+ [QueryKeys.toolCalls, variables.conversationId],
+ (prev) => [
+ ...(prev ?? []),
+ {
+ user: '',
+ toolId: Tools.execute_code,
+ partIndex: variables.partIndex,
+ messageId: variables.messageId,
+ blockIndex: variables.blockIndex,
+ conversationId: variables.conversationId,
+ result: response.result,
+ attachments: response.attachments,
+ },
+ ],
+ );
+ return options?.onSuccess?.(response, variables, context);
+ },
+ },
+ );
+};
diff --git a/client/src/data-provider/Tools/queries.ts b/client/src/data-provider/Tools/queries.ts
index 7ca8e2f0ef..e438e3d53e 100644
--- a/client/src/data-provider/Tools/queries.ts
+++ b/client/src/data-provider/Tools/queries.ts
@@ -1,5 +1,5 @@
-import { QueryKeys, dataService } from 'librechat-data-provider';
import { useQuery } from '@tanstack/react-query';
+import { Constants, QueryKeys, dataService } from 'librechat-data-provider';
import type { QueryObserverResult, UseQueryOptions } from '@tanstack/react-query';
import type t from 'librechat-data-provider';
@@ -18,3 +18,24 @@ export const useVerifyAgentToolAuth = (
},
);
};
+
+export const useGetToolCalls = <TData = t.ToolCallResults>(
+ params: t.GetToolCallParams,
+ config?: UseQueryOptions<t.ToolCallResults, unknown, TData>,
+): QueryObserverResult<TData, unknown> => {
+ const { conversationId = '' } = params;
+ return useQuery<t.ToolCallResults, unknown, TData>(
+ [QueryKeys.toolCalls, conversationId],
+ () => dataService.getToolCalls(params),
+ {
+ refetchOnWindowFocus: false,
+ refetchOnReconnect: false,
+ refetchOnMount: false,
+ enabled:
+ conversationId.length > 0 &&
+ conversationId !== Constants.NEW_CONVO &&
+ conversationId !== Constants.SEARCH,
+ ...config,
+ },
+ );
+};
diff --git a/client/src/data-provider/index.ts b/client/src/data-provider/index.ts
index 2a9dc740f2..3d5039f1d4 100644
--- a/client/src/data-provider/index.ts
+++ b/client/src/data-provider/index.ts
@@ -1,3 +1,4 @@
+export * from './Agents';
export * from './Files';
export * from './Tools';
export * from './connection';
diff --git a/client/src/data-provider/queries.ts b/client/src/data-provider/queries.ts
index 79b34dd74e..3ed41b762e 100644
--- a/client/src/data-provider/queries.ts
+++ b/client/src/data-provider/queries.ts
@@ -22,9 +22,6 @@ import type {
AssistantListParams,
AssistantListResponse,
AssistantDocument,
- Agent,
- AgentListParams,
- AgentListResponse,
TEndpointsConfig,
TCheckUserKeyResponse,
SharedLinkListParams,
@@ -370,78 +367,6 @@ export const useGetAssistantDocsQuery = <TData = AssistantDocument[]>(
);
};
-/**
- * AGENTS
- */
-
-/**
- * Hook for getting all available tools for A
- */
-export const useAvailableAgentToolsQuery = (): QueryObserverResult<TPlugin[]> => {
- const queryClient = useQueryClient();
- const endpointsConfig = queryClient.getQueryData<TEndpointsConfig>([QueryKeys.endpoints]);
-
- const enabled = !!endpointsConfig?.[EModelEndpoint.agents];
- return useQuery<TPlugin[]>([QueryKeys.tools], () => dataService.getAvailableAgentTools(), {
- refetchOnWindowFocus: false,
- refetchOnReconnect: false,
- refetchOnMount: false,
- enabled,
- });
-};
-
-/**
- * Hook for listing all Agents, with optional parameters provided for pagination and sorting
- */
-export const useListAgentsQuery = <TData = AgentListResponse>(
- params: AgentListParams = defaultOrderQuery,
- config?: UseQueryOptions<AgentListResponse, unknown, TData>,
-): QueryObserverResult<TData> => {
- const queryClient = useQueryClient();
- const endpointsConfig = queryClient.getQueryData<TEndpointsConfig>([QueryKeys.endpoints]);
-
- const enabled = !!endpointsConfig?.[EModelEndpoint.agents];
- return useQuery<AgentListResponse, unknown, TData>(
- [QueryKeys.agents, params],
- () => dataService.listAgents(params),
- {
- // Example selector to sort them by created_at
- // select: (res) => {
- // return res.data.sort((a, b) => a.created_at - b.created_at);
- // },
- refetchOnWindowFocus: false,
- refetchOnReconnect: false,
- refetchOnMount: false,
- retry: false,
- ...config,
- enabled: config?.enabled !== undefined ? config.enabled && enabled : enabled,
- },
- );
-};
-
-/**
- * Hook for retrieving details about a single agent
- */
-export const useGetAgentByIdQuery = (
- agent_id: string,
- config?: UseQueryOptions<Agent>,
-): QueryObserverResult<Agent> => {
- return useQuery<Agent>(
- [QueryKeys.agent, agent_id],
- () =>
- dataService.getAgentById({
- agent_id,
- }),
- {
- refetchOnWindowFocus: false,
- refetchOnReconnect: false,
- refetchOnMount: false,
- retry: false,
- ...config,
- },
- );
-};
-
/** STT/TTS */
/* Text to speech voices */
diff --git a/client/src/data-provider/roles.ts b/client/src/data-provider/roles.ts
index bebeaecf24..d038440d43 100644
--- a/client/src/data-provider/roles.ts
+++ b/client/src/data-provider/roles.ts
@@ -22,7 +22,12 @@ export const useGetRole = (
export const useUpdatePromptPermissionsMutation = (
options?: t.UpdatePromptPermOptions,
-): UseMutationResult<t.UpdatePromptPermResponse, t.TError, t.UpdatePromptPermVars, unknown> => {
+): UseMutationResult<
+ t.UpdatePermResponse,
+ t.TError | undefined,
+ t.UpdatePromptPermVars,
+ unknown
+> => {
const queryClient = useQueryClient();
const { onMutate, onSuccess, onError } = options ?? {};
return useMutation(
@@ -38,7 +43,10 @@ export const useUpdatePromptPermissionsMutation = (
}
},
onError: (...args) => {
- args[0] && console.error('Failed to update prompt permissions:', args[0]);
+ const error = args[0];
+ if (error != null) {
+ console.error('Failed to update prompt permissions:', error);
+ }
if (onError) {
onError(...args);
}
@@ -47,3 +55,39 @@ export const useUpdatePromptPermissionsMutation = (
},
);
};
+
+export const useUpdateAgentPermissionsMutation = (
+ options?: t.UpdateAgentPermOptions,
+): UseMutationResult<
+ t.UpdatePermResponse,
+ t.TError | undefined,
+ t.UpdateAgentPermVars,
+ unknown
+> => {
+ const queryClient = useQueryClient();
+ const { onMutate, onSuccess, onError } = options ?? {};
+ return useMutation(
+ (variables) => {
+ promptPermissionsSchema.partial().parse(variables.updates);
+ return dataService.updateAgentPermissions(variables);
+ },
+ {
+ onSuccess: (data, variables, context) => {
+ queryClient.invalidateQueries([QueryKeys.roles, variables.roleName]);
+ if (onSuccess != null) {
+ onSuccess(data, variables, context);
+ }
+ },
+ onError: (...args) => {
+ const error = args[0];
+ if (error != null) {
+ console.error('Failed to update prompt permissions:', error);
+ }
+ if (onError != null) {
+ onError(...args);
+ }
+ },
+ onMutate,
+ },
+ );
+};
diff --git a/client/src/hooks/Assistants/useAssistantListMap.ts b/client/src/hooks/Assistants/useAssistantListMap.ts
index 5b1b975a47..bd6c84b736 100644
--- a/client/src/hooks/Assistants/useAssistantListMap.ts
+++ b/client/src/hooks/Assistants/useAssistantListMap.ts
@@ -16,7 +16,7 @@ export default function useAssistantListMap<T = AssistantListItem[] | null>(
selector: (res: AssistantListResponse) => T = selectAssistantsResponse as (
res: AssistantListResponse,
) => T,
-): Record<AssistantsEndpoint, T> {
+): Record<AssistantsEndpoint, T | null> {
const { data: assistantsList = null } = useListAssistantsQuery(
EModelEndpoint.assistants,
undefined,
diff --git a/client/src/hooks/Conversations/usePresets.ts b/client/src/hooks/Conversations/usePresets.ts
index 76b98dbb67..8e8e5436d8 100644
--- a/client/src/hooks/Conversations/usePresets.ts
+++ b/client/src/hooks/Conversations/usePresets.ts
@@ -46,7 +46,7 @@ export default function usePresets() {
return;
}
- if (presets && presets.length > 0 && user && presets[0].user !== user?.id) {
+ if (presets && presets.length > 0 && user && presets[0].user !== user.id) {
presetsQuery.refetch();
return;
}
@@ -80,7 +80,7 @@ export default function usePresets() {
}
const previousPresets = presetsQuery.data ?? [];
if (previousPresets) {
- setPresets(previousPresets.filter((p) => p.presetId !== preset?.presetId));
+ setPresets(previousPresets.filter((p) => p.presetId !== preset.presetId));
}
},
onSuccess: () => {
@@ -99,12 +99,12 @@ export default function usePresets() {
const updatePreset = useUpdatePresetMutation({
onSuccess: (data, preset) => {
const toastTitle = data.title ? `"${data.title}"` : localize('com_endpoint_preset_title');
- let message = `${toastTitle} ${localize('com_endpoint_preset_saved')}`;
+ let message = `${toastTitle} ${localize('com_ui_saved')}`;
if (data.defaultPreset && data.presetId !== _defaultPreset?.presetId) {
message = `${toastTitle} ${localize('com_endpoint_preset_default')}`;
setDefaultPreset(data);
newConversation({ preset: data });
- } else if (preset?.defaultPreset === false) {
+ } else if (preset.defaultPreset === false) {
setDefaultPreset(null);
message = `${toastTitle} ${localize('com_endpoint_preset_default_removed')}`;
}
@@ -233,7 +233,7 @@ export default function usePresets() {
if (!preset) {
return;
}
- const fileName = filenamify(preset?.title || 'preset');
+ const fileName = filenamify(preset.title || 'preset');
exportFromJSON({
data: cleanupPreset({ preset }),
fileName,
diff --git a/client/src/hooks/Files/useDelayedUploadToast.ts b/client/src/hooks/Files/useDelayedUploadToast.ts
index 6e3472a7f5..03f0b29995 100644
--- a/client/src/hooks/Files/useDelayedUploadToast.ts
+++ b/client/src/hooks/Files/useDelayedUploadToast.ts
@@ -25,7 +25,7 @@ export const useDelayedUploadToast = () => {
showToast({
message,
status: 'warning',
- duration: 7000,
+ duration: 10000,
});
}, delay);
diff --git a/client/src/hooks/Files/useFileHandling.ts b/client/src/hooks/Files/useFileHandling.ts
index 251e043901..fd73c4f89f 100644
--- a/client/src/hooks/Files/useFileHandling.ts
+++ b/client/src/hooks/Files/useFileHandling.ts
@@ -8,6 +8,7 @@ import {
EModelEndpoint,
codeTypeMapping,
mergeFileConfig,
+ isAgentsEndpoint,
isAssistantsEndpoint,
defaultAssistantsVersion,
fileConfig as defaultFileConfig,
@@ -38,6 +39,7 @@ const useFileHandling = (params?: UseFileHandling) => {
const [errors, setErrors] = useState<string[]>([]);
const abortControllerRef = useRef<AbortController | null>(null);
const { startUploadTimer, clearUploadTimer } = useDelayedUploadToast();
+ const [toolResource, setToolResource] = useState<string | undefined>();
const { files, setFiles, setFilesLoading, conversation } = useChatContext();
const setError = (error: string) => setErrors((prevErrors) => [...prevErrors, error]);
const { addFile, replaceFile, updateFileById, deleteFileById } = useUpdateFiles(
@@ -147,6 +149,9 @@ const useFileHandling = (params?: UseFileHandling) => {
: error?.response?.data?.message ?? 'com_error_files_upload';
setError(errorMessage);
},
+ onMutate: () => {
+ setToolResource(undefined);
+ },
},
abortControllerRef.current?.signal,
);
@@ -178,6 +183,18 @@ const useFileHandling = (params?: UseFileHandling) => {
}
}
+ if (isAgentsEndpoint(endpoint)) {
+ if (!agent_id) {
+ formData.append('message_file', 'true');
+ }
+ if (toolResource != null) {
+ formData.append('tool_resource', toolResource);
+ }
+ if (conversation?.agent_id != null && formData.get('agent_id') == null) {
+ formData.append('agent_id', conversation.agent_id);
+ }
+ }
+
if (!isAssistantsEndpoint(endpoint)) {
uploadFile.mutate(formData);
return;
@@ -377,6 +394,7 @@ const useFileHandling = (params?: UseFileHandling) => {
return {
handleFileChange,
+ setToolResource,
handleFiles,
abortUpload,
setFiles,
diff --git a/client/src/hooks/Input/useMentions.ts b/client/src/hooks/Input/useMentions.ts
index 8e81f2dae1..4d5205a72d 100644
--- a/client/src/hooks/Input/useMentions.ts
+++ b/client/src/hooks/Input/useMentions.ts
@@ -5,17 +5,17 @@ import {
useGetEndpointsQuery,
} from 'librechat-data-provider/react-query';
import {
- getConfigDefaults,
- EModelEndpoint,
alternateName,
+ EModelEndpoint,
+ getConfigDefaults,
isAssistantsEndpoint,
} from 'librechat-data-provider';
-import type { AssistantsEndpoint, TAssistantsMap, TEndpointsConfig } from 'librechat-data-provider';
+import type { TAssistantsMap, TEndpointsConfig } from 'librechat-data-provider';
import type { MentionOption } from '~/common';
import useAssistantListMap from '~/hooks/Assistants/useAssistantListMap';
+import { useGetPresetsQuery, useListAgentsQuery } from '~/data-provider';
import { mapEndpoints, getPresetTitle } from '~/utils';
import { EndpointIcon } from '~/components/Endpoints';
-import { useGetPresetsQuery } from '~/data-provider';
const defaultInterface = getConfigDefaults().interface;
@@ -25,7 +25,7 @@ const assistantMapFn =
assistantMap,
endpointsConfig,
}: {
- endpoint: AssistantsEndpoint;
+ endpoint: EModelEndpoint | string;
assistantMap: TAssistantsMap;
endpointsConfig: TEndpointsConfig;
}) =>
@@ -65,6 +65,27 @@ export default function useMentions({
description,
})),
);
+ const { data: agentsList = null } = useListAgentsQuery(undefined, {
+ select: (res) => {
+ const { data } = res;
+ return data.map(({ id, name, avatar }) => ({
+ value: id,
+ label: name ?? '',
+ type: EModelEndpoint.agents,
+ icon: EndpointIcon({
+ conversation: {
+ agent_id: id,
+ endpoint: EModelEndpoint.agents,
+ iconURL: avatar?.filepath,
+ },
+ containerClassName: 'shadow-stroke overflow-hidden rounded-full',
+ endpointsConfig: endpointsConfig,
+ context: 'menu-item',
+ size: 20,
+ }),
+ }));
+ },
+ });
const assistantListMap = useMemo(
() => ({
[EModelEndpoint.assistants]: listMap[EModelEndpoint.assistants]
@@ -101,7 +122,7 @@ export default function useMentions({
validEndpoints = endpoints.filter((endpoint) => !isAssistantsEndpoint(endpoint));
}
const mentions = [
- ...(modelSpecs?.length > 0 ? modelSpecs : []).map((modelSpec) => ({
+ ...(modelSpecs.length > 0 ? modelSpecs : []).map((modelSpec) => ({
value: modelSpec.name,
label: modelSpec.label,
description: modelSpec.description,
@@ -116,9 +137,9 @@ export default function useMentions({
}),
type: 'modelSpec' as const,
})),
- ...(interfaceConfig.endpointsMenu ? validEndpoints : []).map((endpoint) => ({
+ ...(interfaceConfig.endpointsMenu === true ? validEndpoints : []).map((endpoint) => ({
value: endpoint,
- label: alternateName[endpoint] ?? endpoint ?? '',
+ label: alternateName[endpoint as string] ?? endpoint ?? '',
type: 'endpoint' as const,
icon: EndpointIcon({
conversation: { endpoint },
@@ -127,13 +148,14 @@ export default function useMentions({
size: 20,
}),
})),
+ ...(agentsList ?? []),
...(endpointsConfig?.[EModelEndpoint.assistants] && includeAssistants
? assistantListMap[EModelEndpoint.assistants] || []
: []),
...(endpointsConfig?.[EModelEndpoint.azureAssistants] && includeAssistants
? assistantListMap[EModelEndpoint.azureAssistants] || []
: []),
- ...((interfaceConfig.presets ? presets : [])?.map((preset, index) => ({
+ ...((interfaceConfig.presets === true ? presets : [])?.map((preset, index) => ({
value: preset.presetId ?? `preset-${index}`,
label: preset.title ?? preset.modelLabel ?? preset.chatGptLabel ?? '',
description: getPresetTitle(preset, true),
@@ -154,6 +176,7 @@ export default function useMentions({
presets,
endpoints,
modelSpecs,
+ agentsList,
assistantMap,
endpointsConfig,
assistantListMap,
@@ -166,6 +189,7 @@ export default function useMentions({
options,
presets,
modelSpecs,
+ agentsList,
modelsConfig,
endpointsConfig,
assistantListMap,
diff --git a/client/src/hooks/Input/useSelectMention.ts b/client/src/hooks/Input/useSelectMention.ts
index a85d4ff14f..df11ec0440 100644
--- a/client/src/hooks/Input/useSelectMention.ts
+++ b/client/src/hooks/Input/useSelectMention.ts
@@ -1,6 +1,6 @@
import { useCallback } from 'react';
import { useRecoilValue } from 'recoil';
-import { EModelEndpoint, isAssistantsEndpoint } from 'librechat-data-provider';
+import { EModelEndpoint, isAgentsEndpoint, isAssistantsEndpoint } from 'librechat-data-provider';
import type {
TPreset,
TModelSpec,
@@ -64,7 +64,11 @@ export default function useSelectMention({
preset.endpointType = newEndpointType;
}
- if (isAssistantsEndpoint(newEndpoint) && preset.assistant_id != null && !(preset.model ?? '')) {
+ if (
+ isAssistantsEndpoint(newEndpoint) &&
+ preset.assistant_id != null &&
+ !(preset.model ?? '')
+ ) {
preset.model = assistantMap?.[newEndpoint]?.[preset.assistant_id]?.model;
}
@@ -94,11 +98,19 @@ export default function useSelectMention({
keepAddedConvos: isModular,
});
},
- [conversation, getDefaultConversation, modularChat, newConversation, endpointsConfig, assistantMap],
+ [
+ conversation,
+ getDefaultConversation,
+ modularChat,
+ newConversation,
+ endpointsConfig,
+ assistantMap,
+ ],
);
type Kwargs = {
model?: string;
+ agent_id?: string;
assistant_id?: string;
};
@@ -228,6 +240,10 @@ export default function useSelectMention({
assistant_id: key,
model: assistantMap?.[option.type]?.[key]?.model ?? '',
});
+ } else if (isAgentsEndpoint(option.type)) {
+ onSelectEndpoint(option.type, {
+ agent_id: key,
+ });
}
},
[modelSpecs, onSelectEndpoint, onSelectPreset, onSelectSpec, presets, assistantMap],
diff --git a/client/src/hooks/Input/useTextarea.ts b/client/src/hooks/Input/useTextarea.ts
index f77d03a783..d30dc199d9 100644
--- a/client/src/hooks/Input/useTextarea.ts
+++ b/client/src/hooks/Input/useTextarea.ts
@@ -1,11 +1,12 @@
import debounce from 'lodash/debounce';
import { useEffect, useRef, useCallback } from 'react';
import { useRecoilValue, useRecoilState } from 'recoil';
-import { isAssistantsEndpoint } from 'librechat-data-provider';
+import { Constants } from 'librechat-data-provider';
import type { TEndpointOption } from 'librechat-data-provider';
import type { KeyboardEvent } from 'react';
-import { forceResize, insertTextAtCursor, getAssistantName } from '~/utils';
+import { forceResize, insertTextAtCursor, getEntityName, getEntity } from '~/utils';
import { useAssistantsMapContext } from '~/Providers/AssistantsMapContext';
+import { useAgentsMapContext } from '~/Providers/AgentsMapContext';
import useGetSender from '~/hooks/Conversations/useGetSender';
import useFileHandling from '~/hooks/Files/useFileHandling';
import { useInteractionHealthCheck } from '~/data-provider';
@@ -28,6 +29,7 @@ export default function useTextarea({
const localize = useLocalize();
const getSender = useGetSender();
const isComposing = useRef(false);
+ const agentsMap = useAgentsMapContext();
const { handleFiles } = useFileHandling();
const assistantMap = useAssistantsMapContext();
const checkHealth = useInteractionHealthCheck();
@@ -44,19 +46,25 @@ export default function useTextarea({
} = useChatContext();
const [activePrompt, setActivePrompt] = useRecoilState(store.activePromptByIndex(index));
- const { conversationId, jailbreak, endpoint = '', assistant_id } = conversation || {};
+ const { conversationId, jailbreak = false, endpoint = '' } = conversation || {};
+ const { entity, isAgent, isAssistant } = getEntity({
+ endpoint,
+ agentsMap,
+ assistantMap,
+ agent_id: conversation?.agent_id,
+ assistant_id: conversation?.assistant_id,
+ });
+ const entityName = entity?.name ?? '';
+
const isNotAppendable =
- ((latestMessage?.unfinished && !isSubmitting) || latestMessage?.error) &&
- !isAssistantsEndpoint(endpoint);
+ (((latestMessage?.unfinished ?? false) && !isSubmitting) || (latestMessage?.error ?? false)) &&
+ !isAssistant;
// && (conversationId?.length ?? 0) > 6; // also ensures that we don't show the wrong placeholder
- const assistant =
- isAssistantsEndpoint(endpoint) && assistantMap?.[endpoint ?? '']?.[assistant_id ?? ''];
- const assistantName = (assistant && assistant.name) || '';
-
useEffect(() => {
- if (activePrompt && textAreaRef.current) {
- insertTextAtCursor(textAreaRef.current, activePrompt);
+ const prompt = activePrompt ?? '';
+ if (prompt && textAreaRef.current) {
+ insertTextAtCursor(textAreaRef.current, prompt);
forceResize(textAreaRef.current);
setActivePrompt(undefined);
}
@@ -64,16 +72,17 @@ export default function useTextarea({
// auto focus to input, when enter a conversation.
useEffect(() => {
- if (!conversationId) {
+ const convoId = conversationId ?? '';
+ if (!convoId) {
return;
}
// Prevents Settings from not showing on new conversation, also prevents showing toneStyle change without jailbreak
- if (conversationId === 'new' || !jailbreak) {
+ if (convoId === Constants.NEW_CONVO || !jailbreak) {
setShowBingToneSetting(false);
}
- if (conversationId !== 'search') {
+ if (convoId !== Constants.SEARCH) {
textAreaRef.current?.focus();
}
// setShowBingToneSetting is a recoil setter, so it doesn't need to be in the dependency array
@@ -89,7 +98,8 @@ export default function useTextarea({
}, [isSubmitting, textAreaRef]);
useEffect(() => {
- if (textAreaRef.current?.value) {
+ const currentValue = textAreaRef.current?.value ?? '';
+ if (currentValue) {
return;
}
@@ -98,10 +108,13 @@ export default function useTextarea({
return localize('com_endpoint_config_placeholder');
}
const currentEndpoint = conversation?.endpoint ?? '';
+ const currentAgentId = conversation?.agent_id ?? '';
const currentAssistantId = conversation?.assistant_id ?? '';
- if (
- isAssistantsEndpoint(currentEndpoint) &&
- (!currentAssistantId || !assistantMap?.[currentEndpoint]?.[currentAssistantId ?? ''])
+ if (isAgent && (!currentAgentId || !agentsMap?.[currentAgentId])) {
+ return localize('com_endpoint_agent_placeholder');
+ } else if (
+ isAssistant &&
+ (!currentAssistantId || !assistantMap?.[currentEndpoint]?.[currentAssistantId])
) {
return localize('com_endpoint_assistant_placeholder');
}
@@ -110,9 +123,10 @@ export default function useTextarea({
return localize('com_endpoint_message_not_appendable');
}
- const sender = isAssistantsEndpoint(currentEndpoint)
- ? getAssistantName({ name: assistantName, localize })
- : getSender(conversation as TEndpointOption);
+ const sender =
+ isAssistant || isAgent
+ ? getEntityName({ name: entityName, isAgent, localize })
+ : getSender(conversation as TEndpointOption);
return `${localize('com_endpoint_message')} ${sender ? sender : 'AI'}`;
};
@@ -137,15 +151,18 @@ export default function useTextarea({
return () => debouncedSetPlaceholder.cancel();
}, [
- conversation,
- disabled,
- latestMessage,
- isNotAppendable,
+ isAgent,
localize,
+ disabled,
getSender,
- assistantName,
+ agentsMap,
+ entityName,
textAreaRef,
+ isAssistant,
assistantMap,
+ conversation,
+ latestMessage,
+ isNotAppendable,
]);
const handleKeyDown = useCallback(
@@ -181,7 +198,7 @@ export default function useTextarea({
}
if ((isNonShiftEnter || isCtrlEnter) && !isComposing.current) {
- const globalAudio = document.getElementById(globalAudioId) as HTMLAudioElement;
+ const globalAudio = document.getElementById(globalAudioId) as HTMLAudioElement | undefined;
if (globalAudio) {
console.log('Unmuting global audio');
globalAudio.muted = false;
@@ -207,14 +224,15 @@ export default function useTextarea({
return;
}
- if (!e.clipboardData) {
+ const clipboardData = e.clipboardData as DataTransfer | undefined;
+ if (!clipboardData) {
return;
}
- if (e.clipboardData.files.length > 0) {
+ if (clipboardData.files.length > 0) {
setFilesLoading(true);
const timestampedFiles: File[] = [];
- for (const file of e.clipboardData.files) {
+ for (const file of clipboardData.files) {
const newFile = new File([file], `clipboard_${+new Date()}_${file.name}`, {
type: file.type,
});
diff --git a/client/src/hooks/Messages/useMessageActions.tsx b/client/src/hooks/Messages/useMessageActions.tsx
index 3a7e1d59d3..be80b404be 100644
--- a/client/src/hooks/Messages/useMessageActions.tsx
+++ b/client/src/hooks/Messages/useMessageActions.tsx
@@ -41,7 +41,7 @@ export default function useMessageActions(props: TMessageActions) {
[isMultiMessage, addedConvo, rootConvo],
);
- const agentMap = useAgentsMapContext();
+ const agentsMap = useAgentsMapContext();
const assistantMap = useAssistantsMapContext();
const { text, content, messageId = null, isCreatedByUser } = message ?? {};
@@ -68,20 +68,20 @@ export default function useMessageActions(props: TMessageActions) {
return undefined;
}
- if (!agentMap) {
+ if (!agentsMap) {
return undefined;
}
const modelKey = message?.model ?? '';
if (modelKey) {
- return agentMap[modelKey];
+ return agentsMap[modelKey];
}
const agentId = conversation?.agent_id ?? '';
if (agentId) {
- return agentMap[agentId];
+ return agentsMap[agentId];
}
- }, [agentMap, conversation?.agent_id, conversation?.endpoint, message?.model]);
+ }, [agentsMap, conversation?.agent_id, conversation?.endpoint, message?.model]);
const isSubmitting = useMemo(
() => (isMultiMessage === true ? isSubmittingAdditional : isSubmittingRoot),
diff --git a/client/src/hooks/Messages/useMessageHelpers.tsx b/client/src/hooks/Messages/useMessageHelpers.tsx
index 2db72031e4..6ffc01e30e 100644
--- a/client/src/hooks/Messages/useMessageHelpers.tsx
+++ b/client/src/hooks/Messages/useMessageHelpers.tsx
@@ -22,7 +22,7 @@ export default function useMessageHelpers(props: TMessageProps) {
setLatestMessage,
} = useChatContext();
const assistantMap = useAssistantsMapContext();
- const agentMap = useAgentsMapContext();
+ const agentsMap = useAgentsMapContext();
const { text, content, children, messageId = null, isCreatedByUser } = message ?? {};
const edit = messageId === currentEditId;
@@ -102,8 +102,8 @@ export default function useMessageHelpers(props: TMessageProps) {
const modelKey = message?.model ?? '';
- return agentMap ? agentMap[modelKey] : undefined;
- }, [agentMap, conversation?.endpoint, message?.model]);
+ return agentsMap ? agentsMap[modelKey] : undefined;
+ }, [agentsMap, conversation?.endpoint, message?.model]);
const regenerateMessage = () => {
if ((isSubmitting && isCreatedByUser === true) || !message) {
diff --git a/client/src/hooks/Nav/useSideNavLinks.ts b/client/src/hooks/Nav/useSideNavLinks.ts
index a59d933a93..9cddf8720c 100644
--- a/client/src/hooks/Nav/useSideNavLinks.ts
+++ b/client/src/hooks/Nav/useSideNavLinks.ts
@@ -10,9 +10,9 @@ import {
} from 'librechat-data-provider';
import type { TConfig, TInterfaceConfig } from 'librechat-data-provider';
import type { NavLink } from '~/common';
+import AgentPanelSwitch from '~/components/SidePanel/Agents/AgentPanelSwitch';
import BookmarkPanel from '~/components/SidePanel/Bookmarks/BookmarkPanel';
import PanelSwitch from '~/components/SidePanel/Builder/PanelSwitch';
-import AgentPanelSwitch from '~/components/SidePanel/Agents/AgentPanelSwitch';
import PromptsAccordion from '~/components/Prompts/PromptsAccordion';
import Parameters from '~/components/SidePanel/Parameters/Panel';
import FilesPanel from '~/components/SidePanel/Files/Panel';
@@ -44,6 +44,14 @@ export default function useSideNavLinks({
permissionType: PermissionTypes.BOOKMARKS,
permission: Permissions.USE,
});
+ const hasAccessToAgents = useHasAccess({
+ permissionType: PermissionTypes.AGENTS,
+ permission: Permissions.USE,
+ });
+ const hasAccessToCreateAgents = useHasAccess({
+ permissionType: PermissionTypes.AGENTS,
+ permission: Permissions.CREATE,
+ });
const Links = useMemo(() => {
const links: NavLink[] = [];
@@ -64,6 +72,8 @@ export default function useSideNavLinks({
}
if (
+ hasAccessToAgents &&
+ hasAccessToCreateAgents &&
isAgentsEndpoint(endpoint) &&
agents &&
// agents.disableBuilder !== true &&
@@ -137,8 +147,10 @@ export default function useSideNavLinks({
endpointType,
endpoint,
agents,
+ hasAccessToAgents,
hasAccessToPrompts,
hasAccessToBookmarks,
+ hasAccessToCreateAgents,
hidePanel,
]);
diff --git a/client/src/hooks/Plugins/index.ts b/client/src/hooks/Plugins/index.ts
index 0668e757d6..6fe68c4567 100644
--- a/client/src/hooks/Plugins/index.ts
+++ b/client/src/hooks/Plugins/index.ts
@@ -1,3 +1,4 @@
export { default as useAuthCodeTool } from './useAuthCodeTool';
export { default as usePluginInstall } from './usePluginInstall';
+export { default as useCodeApiKeyForm } from './useCodeApiKeyForm';
export { default as usePluginDialogHelpers } from './usePluginDialogHelpers';
diff --git a/client/src/hooks/Plugins/useCodeApiKeyForm.ts b/client/src/hooks/Plugins/useCodeApiKeyForm.ts
new file mode 100644
index 0000000000..4b1f9814a3
--- /dev/null
+++ b/client/src/hooks/Plugins/useCodeApiKeyForm.ts
@@ -0,0 +1,43 @@
+// client/src/hooks/Plugins/useCodeApiKeyForm.ts
+import { useState, useCallback } from 'react';
+import { useForm } from 'react-hook-form';
+import type { ApiKeyFormData } from '~/common';
+import useAuthCodeTool from '~/hooks/Plugins/useAuthCodeTool';
+
+export default function useCodeApiKeyForm({
+ onSubmit,
+ onRevoke,
+}: {
+ onSubmit?: () => void;
+ onRevoke?: () => void;
+}) {
+ const methods = useForm<ApiKeyFormData>();
+ const [isDialogOpen, setIsDialogOpen] = useState(false);
+ const { installTool, removeTool } = useAuthCodeTool({ isEntityTool: true });
+ const { reset } = methods;
+
+ const onSubmitHandler = useCallback(
+ (data: { apiKey: string }) => {
+ reset();
+ installTool(data.apiKey);
+ setIsDialogOpen(false);
+ onSubmit?.();
+ },
+ [onSubmit, reset, installTool],
+ );
+
+ const handleRevokeApiKey = useCallback(() => {
+ reset();
+ removeTool();
+ setIsDialogOpen(false);
+ onRevoke?.();
+ }, [reset, onRevoke, removeTool]);
+
+ return {
+ methods,
+ isDialogOpen,
+ setIsDialogOpen,
+ handleRevokeApiKey,
+ onSubmit: onSubmitHandler,
+ };
+}
diff --git a/client/src/hooks/Plugins/useToolCallsMap.ts b/client/src/hooks/Plugins/useToolCallsMap.ts
new file mode 100644
index 0000000000..4690f6fab5
--- /dev/null
+++ b/client/src/hooks/Plugins/useToolCallsMap.ts
@@ -0,0 +1,28 @@
+import { ToolCallResult } from 'librechat-data-provider';
+import { useMemo } from 'react';
+import { useGetToolCalls } from '~/data-provider';
+import { mapToolCalls, logger } from '~/utils';
+
+type ToolCallsMap = {
+ [x: string]: ToolCallResult[] | undefined;
+};
+
+export default function useToolCallsMap({
+ conversationId,
+}: {
+ conversationId: string;
+}): ToolCallsMap | undefined {
+ const { data: toolCallsMap = null } = useGetToolCalls(
+ { conversationId },
+ {
+ select: (res) => mapToolCalls(res),
+ },
+ );
+
+ const result = useMemo<ToolCallsMap | undefined>(() => {
+ return toolCallsMap !== null ? toolCallsMap : undefined;
+ }, [toolCallsMap]);
+
+ logger.log('tools', 'tool calls map:', result);
+ return result;
+}
diff --git a/client/src/hooks/SSE/useStepHandler.ts b/client/src/hooks/SSE/useStepHandler.ts
index ae57e8daf6..d9d64d2a4d 100644
--- a/client/src/hooks/SSE/useStepHandler.ts
+++ b/client/src/hooks/SSE/useStepHandler.ts
@@ -21,7 +21,14 @@ type TUseStepHandler = {
type TStepEvent = {
event: string;
- data: Agents.MessageDeltaEvent | Agents.RunStep | Agents.ToolEndEvent;
+ data:
+ | Agents.MessageDeltaEvent
+ | Agents.RunStep
+ | Agents.ToolEndEvent
+ | {
+ runId?: string;
+ message: string;
+ };
};
type MessageDeltaUpdate = { type: ContentTypes.TEXT; text: string; tool_call_ids?: string[] };
@@ -166,6 +173,30 @@ export default function useStepHandler({
}
});
}
+ } else if (event === 'on_agent_update') {
+ const { runId, message } = data as { runId?: string; message: string };
+ const responseMessageId = runId ?? '';
+ if (!responseMessageId) {
+ console.warn('No message id found in agent update event');
+ return;
+ }
+
+ const responseMessage = messages[messages.length - 1] as TMessage;
+
+ const response = {
+ ...responseMessage,
+ parentMessageId: userMessage.messageId,
+ conversationId: userMessage.conversationId,
+ messageId: responseMessageId,
+ content: [
+ {
+ type: ContentTypes.TEXT,
+ text: message,
+ },
+ ],
+ } as TMessage;
+
+ setMessages([...messages.slice(0, -1), response]);
} else if (event === 'on_message_delta') {
const messageDelta = data as Agents.MessageDeltaEvent;
const runStep = stepMap.current.get(messageDelta.id);
diff --git a/client/src/localization/languages/Ar.ts b/client/src/localization/languages/Ar.ts
index 34ef82e80a..6cf40bd6bc 100644
--- a/client/src/localization/languages/Ar.ts
+++ b/client/src/localization/languages/Ar.ts
@@ -528,7 +528,7 @@ export default {
com_endpoint_preset_default_item: 'الافتراضي:',
com_endpoint_preset_default_none: 'لا يوجد إعداد مسبق افتراضي نشط.',
com_endpoint_preset_title: 'إعداد مسبق',
- com_endpoint_preset_saved: 'تم الحفظ!',
+ com_ui_saved: 'تم الحفظ!',
com_endpoint_preset_default: 'أصبح الإعداد المسبق الافتراضي الآن.',
com_endpoint_preset_selected: 'الإعداد المسبق نشط!',
com_endpoint_preset_selected_title: 'مُحدَّد!',
@@ -644,7 +644,7 @@ export default {
com_agents_file_search_info:
'عند التمكين، سيتم إعلام الوكيل بأسماء الملفات المدرجة أدناه بالضبط، مما يتيح له استرجاع السياق ذي الصلة من هذه الملفات.',
com_ui_agent_already_shared_to_all: 'هذا المساعد مشارك بالفعل مع جميع المستخدمين',
- com_agents_execute_code: 'تنفيذ الشفرة',
+ com_ui_run_code: 'تنفيذ الشفرة',
com_ui_no_changes: 'لا توجد تغييرات للتحديث',
com_ui_agent_editing_allowed: 'يمكن للمستخدمين الآخرين تعديل هذا الوكيل بالفعل',
com_ui_error_connection: 'خطأ في الاتصال بالخادم، حاول تحديث الصفحة.',
diff --git a/client/src/localization/languages/Br.ts b/client/src/localization/languages/Br.ts
index c1fd491662..566540d78d 100644
--- a/client/src/localization/languages/Br.ts
+++ b/client/src/localization/languages/Br.ts
@@ -548,7 +548,7 @@ export default {
com_endpoint_preset_default_item: 'Padrão:',
com_endpoint_preset_default_none: 'Nenhum preset padrão ativo.',
com_endpoint_preset_title: 'Preset',
- com_endpoint_preset_saved: 'Salvo!',
+ com_ui_saved: 'Salvo!',
com_endpoint_preset_default: 'é agora o preset padrão.',
com_endpoint_preset: 'preset',
com_endpoint_presets: 'presets',
diff --git a/client/src/localization/languages/De.ts b/client/src/localization/languages/De.ts
index f1ae7f4635..dfe46d83c1 100644
--- a/client/src/localization/languages/De.ts
+++ b/client/src/localization/languages/De.ts
@@ -509,7 +509,7 @@ export default {
com_endpoint_preset_default_item: 'Standard:',
com_endpoint_preset_default_none: 'Keine Standardvoreinstellung aktiv.',
com_endpoint_preset_title: 'Voreinstellung',
- com_endpoint_preset_saved: 'Gespeichert!',
+ com_ui_saved: 'Gespeichert!',
com_endpoint_preset_default: 'ist jetzt die Standardvoreinstellung.',
com_endpoint_preset: 'Voreinstellung',
com_endpoint_presets: 'Voreinstellungen',
@@ -801,7 +801,7 @@ export default {
com_ui_endpoint: 'Endpunkt',
com_ui_region: 'Region',
com_ui_model_parameters: 'Modell-Parameter',
- com_agents_execute_code: 'Code ausführen',
+ com_ui_run_code: 'Code ausführen',
com_ui_provider: 'Anbieter',
com_ui_model_save_success: 'Modellparameter erfolgreich gespeichert',
com_ui_select_region: 'Wähle eine Region',
diff --git a/client/src/localization/languages/Eng.ts b/client/src/localization/languages/Eng.ts
index 6dd32362b4..e8fe794c14 100644
--- a/client/src/localization/languages/Eng.ts
+++ b/client/src/localization/languages/Eng.ts
@@ -3,6 +3,10 @@
// file deepcode ignore HardcodedNonCryptoSecret: No hardcoded secrets present in this file
export default {
+ com_ui_enter_api_key: 'Enter API Key',
+ com_ui_librechat_code_api_title: 'Run AI Code',
+ com_ui_librechat_code_api_subtitle: 'Secure. Multi-language. Input/Output Files.',
+ com_ui_librechat_code_api_key: 'Get your LibreChat Code Interpreter API key',
com_nav_convo_menu_options: 'Conversation Menu Options',
com_ui_artifacts: 'Artifacts',
com_ui_artifacts_toggle: 'Toggle Artifacts UI',
@@ -102,6 +106,7 @@ export default {
com_agents_description_placeholder: 'Optional: Describe your Agent here',
com_agents_instructions_placeholder: 'The system instructions that the agent uses',
com_agents_search_name: 'Search agents by name',
+ com_sidepanel_select_agent: 'Select an Agent',
com_agents_update_error: 'There was an error updating your agent.',
com_agents_create_error: 'There was an error creating your agent.',
com_agents_missing_provider_model: 'Please select a provider and model before creating an agent.',
@@ -111,8 +116,11 @@ export default {
com_agents_enable_file_search: 'Enable File Search',
com_agents_file_search_info:
'When enabled, the agent will be informed of the exact filenames listed below, allowing it to retrieve relevant context from these files.',
+ com_agents_code_interpreter_title: 'Code Interpreter',
+ com_agents_by_librechat: 'by LibreChat',
+ com_agents_code_interpreter:
+ 'When enabled, allows your agent to leverage the LibreChat Code Interpreter API to run generated code, including file processing, securely. Requires a valid API key.',
com_agents_file_search_disabled: 'Agent must be created before uploading files for File Search.',
- com_agents_execute_code: 'Run Code',
com_ui_agent_already_shared_to_all: 'This agent is already shared to all users',
com_ui_agent_editing_allowed: 'Other users can already edit this agent',
com_ui_no_changes: 'No changes to update',
@@ -177,6 +185,7 @@ export default {
com_ui_select_provider: 'Select a provider',
com_ui_select_provider_first: 'Select a provider first',
com_ui_select_search_model: 'Search model by name',
+ com_ui_select_search_provider: 'Search provider by name',
com_ui_select_search_region: 'Search region by name',
com_ui_select_search_plugin: 'Search plugin by name',
com_ui_use_prompt: 'Use prompt',
@@ -184,6 +193,9 @@ export default {
com_ui_next: 'Next',
com_ui_stop: 'Stop',
com_ui_upload_files: 'Upload files',
+ com_ui_upload_image_input: 'Upload Image',
+ com_ui_upload_file_search: 'Upload for File Search',
+ com_ui_upload_code_files: 'Upload for Code Interpreter',
com_ui_prompt: 'Prompt',
com_ui_prompts: 'Prompts',
com_ui_prompt_name: 'Prompt Name',
@@ -236,6 +248,8 @@ export default {
com_ui_read_aloud: 'Read aloud',
com_ui_copied: 'Copied!',
com_ui_copy_code: 'Copy code',
+ com_ui_run_code: 'Run Code',
+ com_ui_run_code_error: 'There was an error running the code',
com_ui_copy_to_clipboard: 'Copy to clipboard',
com_ui_copied_to_clipboard: 'Copied to clipboard',
com_ui_fork: 'Fork',
@@ -331,6 +345,9 @@ export default {
com_ui_prompts_allow_share_global: 'Allow sharing Prompts to all users',
com_ui_prompt_shared_to_all: 'This prompt is shared to all users',
com_ui_prompt_update_error: 'There was an error updating the prompt',
+ com_ui_agents_allow_share_global: 'Allow sharing Agents to all users',
+ com_ui_agents_allow_use: 'Allow using Agents',
+ com_ui_agents_allow_create: 'Allow creating Agents',
com_ui_prompt_already_shared_to_all: 'This prompt is already shared to all users',
com_ui_description_placeholder: 'Optional: Enter a description to display for the prompt',
com_ui_command_placeholder: 'Optional: Enter a command for the prompt or name will be used.',
@@ -574,7 +591,7 @@ export default {
com_endpoint_preset_default_item: 'Default:',
com_endpoint_preset_default_none: 'No default preset active.',
com_endpoint_preset_title: 'Preset',
- com_endpoint_preset_saved: 'Saved!',
+ com_ui_saved: 'Saved!',
com_endpoint_preset_default: 'is now the default preset.',
com_endpoint_preset: 'preset',
com_endpoint_presets: 'presets',
@@ -610,6 +627,7 @@ export default {
com_endpoint_skip_hover:
'Enable skipping the completion step, which reviews the final answer and generated steps',
com_endpoint_config_key: 'Set API Key',
+ com_endpoint_agent_placeholder: 'Please select an Agent',
com_endpoint_assistant_placeholder: 'Please select an Assistant from the right-hand Side Panel',
com_endpoint_config_placeholder: 'Set your Key in the Header menu to chat.',
com_endpoint_config_key_for: 'Set API Key for',
@@ -651,6 +669,7 @@ export default {
com_nav_font_size_lg: 'Large',
com_nav_font_size_xl: 'Extra Large',
com_nav_welcome_assistant: 'Please Select an Assistant',
+ com_nav_welcome_agent: 'Please Select an Agent',
com_nav_welcome_message: 'How can I help you today?',
com_nav_auto_scroll: 'Auto-Scroll to latest message on chat open',
com_nav_user_msg_markdown: 'Render user messages as markdown',
diff --git a/client/src/localization/languages/Es.ts b/client/src/localization/languages/Es.ts
index a23ff0d653..a451b8b8d7 100644
--- a/client/src/localization/languages/Es.ts
+++ b/client/src/localization/languages/Es.ts
@@ -350,7 +350,7 @@ export default {
com_endpoint_preset_default_item: 'Predeterminado:',
com_endpoint_preset_default_none: 'No hay configuración preestablecida predeterminada activa.',
com_endpoint_preset_title: 'Configuración preestablecida',
- com_endpoint_preset_saved: '¡Guardado!',
+ com_ui_saved: '¡Guardado!',
com_endpoint_preset_default: 'es ahora la configuración preestablecida predeterminada.',
com_endpoint_preset: 'configuración preestablecida',
com_endpoint_presets: 'configuraciones preestablecidas',
@@ -716,7 +716,7 @@ export default {
com_agents_file_search_disabled:
'Es necesario crear el Agente antes de subir archivos para la Búsqueda de Archivos.',
- com_agents_execute_code: 'Ejecutar código',
+ com_ui_run_code: 'Ejecutar código',
com_ui_agent_already_shared_to_all: 'Este asistente ya está compartido con todos los usuarios',
diff --git a/client/src/localization/languages/Fi.ts b/client/src/localization/languages/Fi.ts
index 8f8e3bb909..a546c14265 100644
--- a/client/src/localization/languages/Fi.ts
+++ b/client/src/localization/languages/Fi.ts
@@ -489,7 +489,7 @@ export default {
com_endpoint_preset_default_item: 'Oletus:',
com_endpoint_preset_default_none: 'Oletus-esiasetusta ei ole käytössä',
com_endpoint_preset_title: 'Esiasetus',
- com_endpoint_preset_saved: 'Tallennettu!',
+ com_ui_saved: 'Tallennettu!',
com_endpoint_preset_default: 'on nyt oletus-esiasetus.',
com_endpoint_preset: 'esiasetus',
com_endpoint_presets: 'esiasetukset',
diff --git a/client/src/localization/languages/Fr.ts b/client/src/localization/languages/Fr.ts
index e35a12b146..4d0a18b84b 100644
--- a/client/src/localization/languages/Fr.ts
+++ b/client/src/localization/languages/Fr.ts
@@ -257,7 +257,7 @@ export default {
com_endpoint_preset_default_item: 'Par défaut :',
com_endpoint_preset_default_none: 'Aucun préréglage par défaut actif.',
com_endpoint_preset_title: 'Préréglage',
- com_endpoint_preset_saved: 'Enregistré!',
+ com_ui_saved: 'Enregistré!',
com_endpoint_preset_default: 'est maintenant le préréglage par défaut.',
com_endpoint_preset: 'préréglage',
com_endpoint_presets: 'préréglages',
@@ -794,7 +794,7 @@ export default {
com_agents_enable_file_search: 'Activer la recherche de fichiers',
com_agents_file_search_info:
'Lorsque cette option est activée, l\'agent sera informé des noms exacts des fichiers listés ci-dessous, lui permettant d\'extraire le contexte pertinent de ces fichiers.',
- com_agents_execute_code: 'Exécuter le code',
+ com_ui_run_code: 'Exécuter le code',
com_agents_file_search_disabled:
'L\'agent doit être créé avant de pouvoir télécharger des fichiers pour la Recherche de Fichiers.',
com_ui_agent_already_shared_to_all: 'Cet agent est déjà partagé avec tous les utilisateurs',
diff --git a/client/src/localization/languages/He.ts b/client/src/localization/languages/He.ts
index 59c96ca24a..dd8e61f5dc 100644
--- a/client/src/localization/languages/He.ts
+++ b/client/src/localization/languages/He.ts
@@ -283,7 +283,7 @@ export default {
com_endpoint_preset_default_item: 'ברירת מחדל:',
com_endpoint_preset_default_none: 'אין ברירת מחדל פעילה.',
com_endpoint_preset_title: 'הגדרה מראש',
- com_endpoint_preset_saved: 'שמור!',
+ com_ui_saved: 'שמור!',
com_endpoint_preset_default: 'הוא כעת ברירת המחדל המוגדרת מראש.',
com_endpoint_preset: 'preset',
com_endpoint_presets: 'presets',
diff --git a/client/src/localization/languages/Id.ts b/client/src/localization/languages/Id.ts
index d3177cba25..baecfc5aba 100644
--- a/client/src/localization/languages/Id.ts
+++ b/client/src/localization/languages/Id.ts
@@ -248,7 +248,7 @@ export default {
com_endpoint_preset_default_item: 'Default:',
com_endpoint_preset_default_none: 'Tidak ada preset default yang aktif.',
com_endpoint_preset_title: 'Preset',
- com_endpoint_preset_saved: 'Tersimpan!',
+ com_ui_saved: 'Tersimpan!',
com_endpoint_preset_default: 'sekarang menjadi preset default.',
com_endpoint_preset: 'preset',
com_endpoint_presets: 'presets',
diff --git a/client/src/localization/languages/It.ts b/client/src/localization/languages/It.ts
index 98c950149f..d92bcdd200 100644
--- a/client/src/localization/languages/It.ts
+++ b/client/src/localization/languages/It.ts
@@ -402,7 +402,7 @@ export default {
com_endpoint_preset_default_item: 'Predefinita:',
com_endpoint_preset_default_none: 'Nessuna preimpostazione predefinita attiva.',
com_endpoint_preset_title: 'Preimpostazione',
- com_endpoint_preset_saved: 'Salvata!',
+ com_ui_saved: 'Salvata!',
com_endpoint_preset_default: 'è ora la preimpostazione predefinita.',
com_endpoint_preset: 'preimpostazione',
com_endpoint_presets: 'preimpostazioni',
@@ -676,7 +676,7 @@ export default {
com_agents_enable_file_search: 'Abilita Ricerca File',
com_agents_file_search_info:
'Quando abilitato, l\'agente verrà informato dei nomi esatti dei file elencati di seguito, permettendogli di recuperare il contesto pertinente da questi file.',
- com_agents_execute_code: 'Esegui Codice',
+ com_ui_run_code: 'Esegui Codice',
com_agents_file_search_disabled:
'L\'Agente deve essere creato prima di caricare file per la Ricerca File.',
com_ui_agent_already_shared_to_all: 'Questo assistente è già condiviso con tutti gli utenti',
diff --git a/client/src/localization/languages/Jp.ts b/client/src/localization/languages/Jp.ts
index fcd472b601..65899f4075 100644
--- a/client/src/localization/languages/Jp.ts
+++ b/client/src/localization/languages/Jp.ts
@@ -541,7 +541,7 @@ export default {
com_endpoint_preset_default_item: 'デフォルト:',
com_endpoint_preset_default_none: '現在有効なプリセットはありません。',
com_endpoint_preset_title: 'プリセット',
- com_endpoint_preset_saved: '保存しました!',
+ com_ui_saved: '保存しました!',
com_endpoint_preset_default: 'が有効化されました。',
com_endpoint_preset: 'プリセット',
com_endpoint_presets: 'プリセット',
@@ -834,7 +834,7 @@ export default {
'ファイル検索用のファイルをアップロードする前に、エージェントを作成する必要があります。',
com_agents_file_search_info:
'有効にすると、エージェントは以下に表示されているファイル名を正確に認識し、それらのファイルから関連する情報を取得することができます。',
- com_agents_execute_code: 'コードを実行',
+ com_ui_run_code: 'コードを実行',
com_ui_agent_editing_allowed: 'このエージェントは他のユーザーが既に編集可能です',
com_ui_agent_already_shared_to_all: 'このアシスタントは既に全ユーザーに共有されています',
com_ui_no_changes: '更新する変更はありません',
diff --git a/client/src/localization/languages/Ko.ts b/client/src/localization/languages/Ko.ts
index b5fa1d9750..3519d1f0fa 100644
--- a/client/src/localization/languages/Ko.ts
+++ b/client/src/localization/languages/Ko.ts
@@ -859,7 +859,7 @@ export default {
com_endpoint_preset_default_item: '기본값:',
com_endpoint_preset_default_none: '기본 프리셋이 설정되지 않았습니다.',
com_endpoint_preset_title: '프리셋',
- com_endpoint_preset_saved: '저장되었습니다!',
+ com_ui_saved: '저장되었습니다!',
com_endpoint_preset_default: '이제 기본 프리셋입니다.',
com_endpoint_preset_selected: '프리셋 활성화됨',
com_endpoint_preset_selected_title: '활성화됨',
@@ -1020,7 +1020,7 @@ export default {
com_agents_file_search_disabled:
'파일 검색을 위해 파일을 업로드하기 전에 에이전트를 먼저 생성해야 합니다',
- com_agents_execute_code: '코드 실행',
+ com_ui_run_code: '코드 실행',
com_ui_agent_already_shared_to_all: '이 에이전트는 이미 모든 사용자와 공유되어 있습니다',
diff --git a/client/src/localization/languages/Ru.ts b/client/src/localization/languages/Ru.ts
index e2b9a701c2..5c4578b635 100644
--- a/client/src/localization/languages/Ru.ts
+++ b/client/src/localization/languages/Ru.ts
@@ -251,7 +251,7 @@ export default {
com_endpoint_preset_default_item: 'По умолчанию:',
com_endpoint_preset_default_none: 'Активных пресетов по умолчанию нет.',
com_endpoint_preset_title: 'Пресет',
- com_endpoint_preset_saved: 'Сохранено!',
+ com_ui_saved: 'Сохранено!',
com_endpoint_preset_default: 'теперь пресет "По умолчаанию".',
com_endpoint_preset: 'пресет',
com_endpoint_presets: 'пресеты',
@@ -699,7 +699,7 @@ export default {
com_agents_file_search_disabled: 'Для загрузки файлов в Поиск необходимо сначала создать агента',
- com_agents_execute_code: 'Выполнить код',
+ com_ui_run_code: 'Выполнить код',
com_ui_agent_editing_allowed: 'Другие пользователи уже могут редактировать этого ассистента',
diff --git a/client/src/localization/languages/Tr.ts b/client/src/localization/languages/Tr.ts
index f69ea540e4..8bf9ef239e 100644
--- a/client/src/localization/languages/Tr.ts
+++ b/client/src/localization/languages/Tr.ts
@@ -450,7 +450,7 @@ export default {
com_endpoint_preset_default_item: 'Varsayılan:',
com_endpoint_preset_default_none: 'Aktif varsayılan hazır ayar yok.',
com_endpoint_preset_title: 'Hazır Ayar',
- com_endpoint_preset_saved: 'Kaydedildi!',
+ com_ui_saved: 'Kaydedildi!',
com_endpoint_preset_default: 'şu anda varsayılan hazır ayar.',
com_endpoint_preset: 'hazır ayar',
com_endpoint_presets: 'hazır ayarlar',
diff --git a/client/src/localization/languages/Zh.ts b/client/src/localization/languages/Zh.ts
index 178b1c22ea..d66e8d08ba 100644
--- a/client/src/localization/languages/Zh.ts
+++ b/client/src/localization/languages/Zh.ts
@@ -514,7 +514,7 @@ export default {
com_endpoint_preset_default_item: '默认:',
com_endpoint_preset_default_none: '无默认预设可用。',
com_endpoint_preset_title: '预设',
- com_endpoint_preset_saved: '保存成功!',
+ com_ui_saved: '保存成功!',
com_endpoint_preset_default: '现在是默认预设。',
com_endpoint_preset: '预设',
com_endpoint_presets: '预设',
@@ -806,7 +806,7 @@ export default {
com_agents_file_search_info:
'启用后,系统会告知Agent以下列出的具体文件名,使其能够从这些文件中检索相关内容。',
- com_agents_execute_code: '运行代码',
+ com_ui_run_code: '运行代码',
com_agents_file_search_disabled: '必须先创建Agent,才能上传文件用于文件搜索。',
diff --git a/client/src/localization/languages/ZhTraditional.ts b/client/src/localization/languages/ZhTraditional.ts
index ef2f03241c..2c5f8ba902 100644
--- a/client/src/localization/languages/ZhTraditional.ts
+++ b/client/src/localization/languages/ZhTraditional.ts
@@ -502,7 +502,7 @@ export default {
com_endpoint_preset_default_item: '預設值',
com_endpoint_preset_default_none: '無啟用的預設設定。',
com_endpoint_preset_title: '預設項目',
- com_endpoint_preset_saved: '已儲存!',
+ com_ui_saved: '已儲存!',
com_endpoint_preset_default: '現在是預設的預設設定。',
com_endpoint_preset_selected: '已選擇預設設定!',
com_endpoint_preset_selected_title: '已選取!',
@@ -612,7 +612,7 @@ export default {
com_agents_missing_provider_model: '請在建立代理前選擇供應商和模型。',
com_agents_enable_file_search: '啟用檔案搜尋',
com_agents_file_search_disabled: '必須先建立代理才能上傳檔案進行檔案搜尋。',
- com_agents_execute_code: '執行程式碼',
+ com_ui_run_code: '執行程式碼',
com_agents_no_access: '您沒有權限編輯此助理',
com_ui_no_changes: '沒有需要更新的變更',
com_ui_agent_already_shared_to_all: '此助理已與所有使用者共享',
diff --git a/client/src/localization/prompts/instructions/Br.md b/client/src/localization/prompts/instructions/Br.md
index 5cb628a784..2b87cb514e 100644
--- a/client/src/localization/prompts/instructions/Br.md
+++ b/client/src/localization/prompts/instructions/Br.md
@@ -1063,7 +1063,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: Predefinição
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: Salvo!
diff --git a/client/src/localization/prompts/instructions/De.md b/client/src/localization/prompts/instructions/De.md
index ae21098b7a..818c9d9f3e 100644
--- a/client/src/localization/prompts/instructions/De.md
+++ b/client/src/localization/prompts/instructions/De.md
@@ -1091,7 +1091,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: Voreinstellung
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: Gespeichert!
diff --git a/client/src/localization/prompts/instructions/Es.md b/client/src/localization/prompts/instructions/Es.md
index 747f8662c2..f1291e8993 100644
--- a/client/src/localization/prompts/instructions/Es.md
+++ b/client/src/localization/prompts/instructions/Es.md
@@ -1063,7 +1063,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: Configuración preestablecida
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: ¡Guardado!
diff --git a/client/src/localization/prompts/instructions/Fr.md b/client/src/localization/prompts/instructions/Fr.md
index f678b3a91d..7500c739b7 100644
--- a/client/src/localization/prompts/instructions/Fr.md
+++ b/client/src/localization/prompts/instructions/Fr.md
@@ -731,7 +731,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: Préréglage
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: Enregistré!
diff --git a/client/src/localization/prompts/instructions/He.md b/client/src/localization/prompts/instructions/He.md
index f0be581e43..3be0fb9aa5 100644
--- a/client/src/localization/prompts/instructions/He.md
+++ b/client/src/localization/prompts/instructions/He.md
@@ -875,7 +875,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: הגדרה מראש
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: שמור!
diff --git a/client/src/localization/prompts/instructions/Id.md b/client/src/localization/prompts/instructions/Id.md
index 857e65e13a..344e6916f0 100644
--- a/client/src/localization/prompts/instructions/Id.md
+++ b/client/src/localization/prompts/instructions/Id.md
@@ -739,7 +739,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: Preset
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: Tersimpan!
diff --git a/client/src/localization/prompts/instructions/It.md b/client/src/localization/prompts/instructions/It.md
index 2ce33f1c43..3db429d172 100644
--- a/client/src/localization/prompts/instructions/It.md
+++ b/client/src/localization/prompts/instructions/It.md
@@ -1219,7 +1219,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: Preimpostazione
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: Salvata!
diff --git a/client/src/localization/prompts/instructions/Jp.md b/client/src/localization/prompts/instructions/Jp.md
index 6e725f0b89..971a1c1a0b 100644
--- a/client/src/localization/prompts/instructions/Jp.md
+++ b/client/src/localization/prompts/instructions/Jp.md
@@ -1107,7 +1107,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: プリセット
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: 保存しました!
diff --git a/client/src/localization/prompts/instructions/Ru.md b/client/src/localization/prompts/instructions/Ru.md
index ede307b2ca..5b36e97216 100644
--- a/client/src/localization/prompts/instructions/Ru.md
+++ b/client/src/localization/prompts/instructions/Ru.md
@@ -743,7 +743,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: Пресет
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: Сохранено!
diff --git a/client/src/localization/prompts/instructions/Tr.md b/client/src/localization/prompts/instructions/Tr.md
index dd93d0afd1..3a650467bf 100644
--- a/client/src/localization/prompts/instructions/Tr.md
+++ b/client/src/localization/prompts/instructions/Tr.md
@@ -695,7 +695,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: Ön Ayar
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: Kaydedildi
diff --git a/client/src/localization/prompts/instructions/Zh.md b/client/src/localization/prompts/instructions/Zh.md
index 739a600e72..bdb8aa38be 100644
--- a/client/src/localization/prompts/instructions/Zh.md
+++ b/client/src/localization/prompts/instructions/Zh.md
@@ -1071,7 +1071,7 @@ Write a prompt that is mindful of the nuances in the language with respect to it
- **english**: Preset
- **translated**: 预设
-- **com_endpoint_preset_saved**:
+- **com_ui_saved**:
- **english**: Saved!
- **translated**: 保存成功!
diff --git a/client/src/routes/ChatRoute.tsx b/client/src/routes/ChatRoute.tsx
index 7474ac0275..e266af23b1 100644
--- a/client/src/routes/ChatRoute.tsx
+++ b/client/src/routes/ChatRoute.tsx
@@ -10,6 +10,7 @@ import type { TPreset } from 'librechat-data-provider';
import { useNewConvo, useAppStartup, useAssistantListMap } from '~/hooks';
import { useGetConvoIdQuery, useHealthCheck } from '~/data-provider';
import { getDefaultModelSpec, getModelSpecIconURL } from '~/utils';
+import { ToolCallsMapProvider } from '~/Providers';
import ChatView from '~/components/Chat/ChatView';
import useAuthRedirect from './useAuthRedirect';
import { Spinner } from '~/components/svg';
@@ -22,7 +23,7 @@ export default function ChatRoute() {
useAppStartup({ startupConfig, user });
const index = 0;
- const { conversationId } = useParams();
+ const { conversationId = '' } = useParams();
const { conversation } = store.useCreateConversationAtom(index);
const { newConversation } = useNewConvo();
@@ -32,7 +33,7 @@ export default function ChatRoute() {
enabled: isAuthenticated,
refetchOnMount: 'always',
});
- const initialConvoQuery = useGetConvoIdQuery(conversationId ?? '', {
+ const initialConvoQuery = useGetConvoIdQuery(conversationId, {
enabled: isAuthenticated && conversationId !== Constants.NEW_CONVO,
});
const endpointsQuery = useGetEndpointsQuery({ enabled: isAuthenticated });
@@ -40,14 +41,14 @@ export default function ChatRoute() {
useEffect(() => {
const shouldSetConvo =
- startupConfig && !hasSetConversation.current && !modelsQuery.data?.initial;
+ (startupConfig && !hasSetConversation.current && !modelsQuery.data?.initial) ?? false;
/* Early exit if startupConfig is not loaded and conversation is already set and only initial models have loaded */
if (!shouldSetConvo) {
return;
}
if (conversationId === Constants.NEW_CONVO && endpointsQuery.data && modelsQuery.data) {
- const spec = getDefaultModelSpec(startupConfig.modelSpecs?.list);
+ const spec = getDefaultModelSpec(startupConfig?.modelSpecs?.list);
newConversation({
modelsData: modelsQuery.data,
@@ -78,7 +79,7 @@ export default function ChatRoute() {
assistantListMap[EModelEndpoint.assistants] &&
assistantListMap[EModelEndpoint.azureAssistants]
) {
- const spec = getDefaultModelSpec(startupConfig.modelSpecs?.list);
+ const spec = getDefaultModelSpec(startupConfig?.modelSpecs?.list);
newConversation({
modelsData: modelsQuery.data,
template: conversation ? conversation : undefined,
@@ -128,7 +129,7 @@ export default function ChatRoute() {
}
// if not a conversation
- if (conversation?.conversationId === 'search') {
+ if (conversation?.conversationId === Constants.SEARCH) {
return null;
}
// if conversationId not match
@@ -140,5 +141,9 @@ export default function ChatRoute() {
return null;
}
- return <ChatView index={index} />;
+ return (
+ <ToolCallsMapProvider conversationId={conversation.conversationId ?? ''}>
+ <ChatView index={index} />
+ </ToolCallsMapProvider>
+ );
}
diff --git a/client/src/utils/endpoints.ts b/client/src/utils/endpoints.ts
index 3b8f882608..717d92ed5b 100644
--- a/client/src/utils/endpoints.ts
+++ b/client/src/utils/endpoints.ts
@@ -9,17 +9,19 @@ import {
import type * as t from 'librechat-data-provider';
import type { LocalizeFunction } from '~/common';
-export const getAssistantName = ({
+export const getEntityName = ({
name = '',
localize,
+ isAgent,
}: {
name?: string;
+ isAgent?: boolean;
localize: LocalizeFunction;
}) => {
if (name && name.length > 0) {
return name;
} else {
- return localize('com_ui_assistant');
+ return isAgent === true ? localize('com_ui_agent') : localize('com_ui_assistant');
}
};
@@ -96,14 +98,18 @@ export function updateLastSelectedModel({
return;
}
/* Note: an empty string value is possible */
- const lastConversationSetup = JSON.parse((localStorage.getItem(firstLocalConvoKey) ?? '{}') || '{}');
+ const lastConversationSetup = JSON.parse(
+ (localStorage.getItem(firstLocalConvoKey) ?? '{}') || '{}',
+ );
if (lastConversationSetup.endpoint === endpoint) {
lastConversationSetup.model = model;
localStorage.setItem(firstLocalConvoKey, JSON.stringify(lastConversationSetup));
}
- const lastSelectedModels = JSON.parse((localStorage.getItem(LocalStorageKeys.LAST_MODEL) ?? '{}') || '{}');
+ const lastSelectedModels = JSON.parse(
+ (localStorage.getItem(LocalStorageKeys.LAST_MODEL) ?? '{}') || '{}',
+ );
lastSelectedModels[endpoint] = model;
localStorage.setItem(LocalStorageKeys.LAST_MODEL, JSON.stringify(lastSelectedModels));
}
diff --git a/client/src/utils/languages.ts b/client/src/utils/languages.ts
index f32ae9da9a..2a7d83e897 100644
--- a/client/src/utils/languages.ts
+++ b/client/src/utils/languages.ts
@@ -1,4 +1,4 @@
-const languages = new Set([
+export const languages = new Set([
'adoc',
'apacheconf',
'arm',
@@ -315,7 +315,7 @@ const languages = new Set([
'zephir',
]);
-const langSubset = [
+export const langSubset = [
'python',
'javascript',
'java',
@@ -353,4 +353,75 @@ const langSubset = [
'yaml',
];
-export { languages, langSubset };
+enum Languages {
+ c = 'c',
+ cpp = 'cpp',
+ d = 'd',
+ f90 = 'f90',
+ go = 'go',
+ java = 'java',
+ js = 'js',
+ php = 'php',
+ py = 'py',
+ rs = 'rs',
+ ts = 'ts',
+}
+
+// Create a mapping of common variations to the enum values
+const languageAliases: Record<string, Languages | undefined> = {
+ // C
+ c: Languages.c,
+
+ // C++
+ cpp: Languages.cpp,
+ 'c++': Languages.cpp,
+ cplusplus: Languages.cpp,
+
+ // D
+ d: Languages.d,
+
+ // Fortran
+ f90: Languages.f90,
+ fortran: Languages.f90,
+ fortran90: Languages.f90,
+
+ // Go
+ go: Languages.go,
+ golang: Languages.go,
+
+ // Java
+ java: Languages.java,
+
+ // JavaScript
+ js: Languages.js,
+ javascript: Languages.js,
+ node: Languages.js,
+ nodejs: Languages.js,
+
+ // PHP
+ php: Languages.php,
+
+ // Python
+ py: Languages.py,
+ python: Languages.py,
+ python3: Languages.py,
+
+ // Rust
+ rs: Languages.rs,
+ rust: Languages.rs,
+
+ // TypeScript
+ ts: Languages.ts,
+ typescript: Languages.ts,
+};
+
+export function normalizeLanguage(lang: string): Languages | string {
+ const normalizedLang = lang.toLowerCase().trim();
+ const validLang = languageAliases[normalizedLang];
+
+ if (!validLang) {
+ return '';
+ }
+
+ return validLang;
+}
diff --git a/client/src/utils/map.ts b/client/src/utils/map.ts
index 45fc5f0645..14cf3d71a5 100644
--- a/client/src/utils/map.ts
+++ b/client/src/utils/map.ts
@@ -1,15 +1,15 @@
-import type { TFile, TAttachment, Assistant, Agent, TPlugin } from 'librechat-data-provider';
+import type * as t from 'librechat-data-provider';
import type { TPluginMap } from '~/common';
/** Maps Attachments by `toolCallId` for quick lookup */
-export function mapAttachments(attachments: Array<TAttachment | null | undefined>) {
- const attachmentMap: Record<string, TAttachment[] | undefined> = {};
+export function mapAttachments(attachments: Array<t.TAttachment | null | undefined>) {
+ const attachmentMap: Record<string, t.TAttachment[] | undefined> = {};
for (const attachment of attachments) {
if (attachment === null || attachment === undefined) {
continue;
}
- const key = attachment.toolCallId ?? '';
+ const key = attachment.toolCallId || '';
if (key.length === 0) {
continue;
}
@@ -25,8 +25,8 @@ export function mapAttachments(attachments: Array<TAttachment | null | undefined
}
/** Maps Files by `file_id` for quick lookup */
-export function mapFiles(files: TFile[]) {
- const fileMap = {} as Record<string, TFile>;
+export function mapFiles(files: t.TFile[]) {
+ const fileMap = {} as Record<string, t.TFile>;
for (const file of files) {
fileMap[file.file_id] = file;
@@ -36,8 +36,8 @@ export function mapFiles(files: TFile[]) {
}
/** Maps Assistants by `id` for quick lookup */
-export function mapAssistants(assistants: Assistant[]) {
- const assistantMap = {} as Record<string, Assistant>;
+export function mapAssistants(assistants: t.Assistant[]) {
+ const assistantMap = {} as Record<string, t.Assistant>;
for (const assistant of assistants) {
assistantMap[assistant.id] = assistant;
@@ -47,18 +47,18 @@ export function mapAssistants(assistants: Assistant[]) {
}
/** Maps Agents by `id` for quick lookup */
-export function mapAgents(agents: Agent[]) {
- const agentMap = {} as Record<string, Agent>;
+export function mapAgents(agents: t.Agent[]) {
+ const agentsMap = {} as Record<string, t.Agent>;
for (const agent of agents) {
- agentMap[agent.id] = agent;
+ agentsMap[agent.id] = agent;
}
- return agentMap;
+ return agentsMap;
}
/** Maps Plugins by `pluginKey` for quick lookup */
-export function mapPlugins(plugins: TPlugin[]): TPluginMap {
+export function mapPlugins(plugins: t.TPlugin[]): TPluginMap {
return plugins.reduce((acc, plugin) => {
acc[plugin.pluginKey] = plugin;
return acc;
@@ -67,9 +67,9 @@ export function mapPlugins(plugins: TPlugin[]): TPluginMap {
/** Transform query data to object with list and map fields */
export const selectPlugins = (
- data: TPlugin[] | undefined,
+ data: t.TPlugin[] | undefined,
): {
- list: TPlugin[];
+ list: t.TPlugin[];
map: TPluginMap;
} => {
if (!data) {
@@ -86,13 +86,29 @@ export const selectPlugins = (
};
/** Transform array to TPlugin values */
-export function processPlugins(tools: (string | TPlugin)[], allPlugins?: TPluginMap): TPlugin[] {
+export function processPlugins(
+ tools: (string | t.TPlugin)[],
+ allPlugins?: TPluginMap,
+): t.TPlugin[] {
return tools
- .map((tool: string | TPlugin) => {
+ .map((tool: string | t.TPlugin) => {
if (typeof tool === 'string') {
return allPlugins?.[tool];
}
return tool;
})
- .filter((tool: TPlugin | undefined): tool is TPlugin => tool !== undefined);
+ .filter((tool: t.TPlugin | undefined): tool is t.TPlugin => tool !== undefined);
+}
+
+export function mapToolCalls(toolCalls: t.ToolCallResults = []): {
+ [key: string]: t.ToolCallResult[] | undefined;
+} {
+ return toolCalls.reduce((acc, call) => {
+ const key = `${call.messageId}_${call.partIndex ?? 0}_${call.blockIndex ?? 0}_${call.toolId}`;
+ const array = acc[key] ?? [];
+ array.push(call);
+ acc[key] = array;
+
+ return acc;
+ }, {} as { [key: string]: t.ToolCallResult[] | undefined });
}
diff --git a/client/src/utils/messages.ts b/client/src/utils/messages.ts
index 507618a2c7..7a52ff4106 100644
--- a/client/src/utils/messages.ts
+++ b/client/src/utils/messages.ts
@@ -1,5 +1,5 @@
import { ContentTypes, Constants } from 'librechat-data-provider';
-import type { TMessage } from 'librechat-data-provider';
+import type { TMessage, TMessageContentParts } from 'librechat-data-provider';
export const getLengthAndLastTenChars = (str?: string): string => {
if (typeof str !== 'string' || str.length === 0) {
@@ -20,12 +20,12 @@ export const getLatestText = (message?: TMessage | null, includeIndex?: boolean)
}
if (message.content && message.content.length > 0) {
for (let i = message.content.length - 1; i >= 0; i--) {
- const part = message.content[i];
- if (part.type !== ContentTypes.TEXT) {
+ const part = message.content[i] as TMessageContentParts | undefined;
+ if (part && part.type !== ContentTypes.TEXT) {
continue;
}
- const text = (typeof part.text === 'string' ? part.text : part.text.value) || '';
+ const text = (typeof part?.text === 'string' ? part.text : part?.text.value) ?? '';
if (text.length > 0) {
if (includeIndex === true) {
return `${text}-${i}`;
@@ -52,7 +52,7 @@ export const getAllContentText = (message?: TMessage | null): string => {
if (message.content && message.content.length > 0) {
return message.content
.filter((part) => part.type === ContentTypes.TEXT)
- .map((part) => (typeof part.text === 'string' ? part.text : part.text.value) ?? '')
+ .map((part) => (typeof part.text === 'string' ? part.text : part.text.value) || '')
.filter((text) => text.length > 0)
.join('\n');
}
diff --git a/package-lock.json b/package-lock.json
index c80f6537e1..58ca8f621d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -48,12 +48,12 @@
"@google/generative-ai": "^0.21.0",
"@keyv/mongo": "^2.1.8",
"@keyv/redis": "^2.8.1",
- "@langchain/community": "^0.3.13",
- "@langchain/core": "^0.3.17",
+ "@langchain/community": "^0.3.14",
+ "@langchain/core": "^0.3.18",
"@langchain/google-genai": "^0.1.4",
"@langchain/google-vertexai": "^0.1.2",
"@langchain/textsplitters": "^0.1.0",
- "@librechat/agents": "^1.7.7",
+ "@librechat/agents": "^1.8.5",
"axios": "^1.7.7",
"bcryptjs": "^2.4.3",
"cheerio": "^1.0.0-rc.12",
@@ -142,93 +142,511 @@
"node": ">=18.0.0"
}
},
- "api/node_modules/@langchain/anthropic": {
- "version": "0.3.7",
- "resolved": "https://registry.npmjs.org/@langchain/anthropic/-/anthropic-0.3.7.tgz",
- "integrity": "sha512-MjV7BNPalnG3S6PqXYHRtv3nEML1fFHl9OsqjT5KCPcULxJImnIZrJX5qMTnezM5A+Q6KOZt3e07x7aYCmU3Sg==",
- "license": "MIT",
- "dependencies": {
- "@anthropic-ai/sdk": "^0.27.3",
- "fast-xml-parser": "^4.4.1",
- "zod": "^3.22.4",
- "zod-to-json-schema": "^3.22.4"
- },
- "engines": {
- "node": ">=18"
- },
- "peerDependencies": {
- "@langchain/core": ">=0.2.21 <0.4.0"
- }
- },
- "api/node_modules/@langchain/anthropic/node_modules/@anthropic-ai/sdk": {
- "version": "0.27.3",
- "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.27.3.tgz",
- "integrity": "sha512-IjLt0gd3L4jlOfilxVXTifn42FnVffMgDC04RJK1KDZpmkBWLv0XC92MVVmkxrFZNS/7l3xWgP/I3nqtX1sQHw==",
- "license": "MIT",
- "dependencies": {
- "@types/node": "^18.11.18",
- "@types/node-fetch": "^2.6.4",
- "abort-controller": "^3.0.0",
- "agentkeepalive": "^4.2.1",
- "form-data-encoder": "1.7.2",
- "formdata-node": "^4.3.2",
- "node-fetch": "^2.6.7"
- }
- },
- "api/node_modules/@langchain/aws": {
- "version": "0.1.2",
- "resolved": "https://registry.npmjs.org/@langchain/aws/-/aws-0.1.2.tgz",
- "integrity": "sha512-1cQvv8XSbaZXceAbYexSm/8WLqfEJ4VF6qbf/XLwkpUKMFGqpSBA00+Bn5p8K/Ms+PyMguZrxVNqd6daqxhDBQ==",
- "license": "MIT",
+ "api/node_modules/@langchain/community": {
+ "version": "0.3.14",
+ "resolved": "https://registry.npmjs.org/@langchain/community/-/community-0.3.14.tgz",
+ "integrity": "sha512-zadvK0pu15Jp028VEV4wV+lYB1ViojSolSdSNMdE82KuaK97kH/F1aynQ2W+ebHzjr0lG3dUF3OfOqHU37VgwA==",
"dependencies": {
- "@aws-sdk/client-bedrock-agent-runtime": "^3.616.0",
- "@aws-sdk/client-bedrock-runtime": "^3.602.0",
- "@aws-sdk/client-kendra": "^3.352.0",
- "@aws-sdk/credential-provider-node": "^3.600.0",
- "zod": "^3.23.8",
+ "@langchain/openai": ">=0.2.0 <0.4.0",
+ "binary-extensions": "^2.2.0",
+ "expr-eval": "^2.0.2",
+ "flat": "^5.0.2",
+ "js-yaml": "^4.1.0",
+ "langchain": ">=0.2.3 <0.3.0 || >=0.3.4 <0.4.0",
+ "langsmith": "^0.2.0",
+ "uuid": "^10.0.0",
+ "zod": "^3.22.3",
"zod-to-json-schema": "^3.22.5"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
- "@langchain/core": ">=0.2.21 <0.4.0"
- }
- },
- "api/node_modules/@langchain/core": {
- "version": "0.2.34",
- "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.2.34.tgz",
- "integrity": "sha512-Hkveq1UcOjUj1DVn5erbqElyRj1t04NORSuSIZAJCtPO7EDkIqomjAarJ5+I5NUpQeIONgbOdnY9TkJ6cKUSVA==",
- "dependencies": {
- "ansi-styles": "^5.0.0",
- "camelcase": "6",
- "decamelize": "1.2.0",
- "js-tiktoken": "^1.0.12",
- "langsmith": "^0.1.56-rc.1",
- "mustache": "^4.2.0",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "uuid": "^10.0.0",
- "zod": "^3.22.4",
- "zod-to-json-schema": "^3.22.3"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "api/node_modules/@langchain/google-common": {
- "version": "0.1.2",
- "resolved": "https://registry.npmjs.org/@langchain/google-common/-/google-common-0.1.2.tgz",
- "integrity": "sha512-3A7vUr2WObCFUusM/Wl0yZN7QGGXboXyparORkZdv0RnGngPm6tBmqbAyWYmT8R9aQNHqzBKDEQBiSRvTxao1w==",
- "dependencies": {
- "uuid": "^10.0.0",
- "zod-to-json-schema": "^3.22.4"
- },
- "engines": {
- "node": ">=18"
+ "@arcjet/redact": "^v1.0.0-alpha.23",
+ "@aws-crypto/sha256-js": "^5.0.0",
+ "@aws-sdk/client-bedrock-agent-runtime": "^3.583.0",
+ "@aws-sdk/client-bedrock-runtime": "^3.422.0",
+ "@aws-sdk/client-dynamodb": "^3.310.0",
+ "@aws-sdk/client-kendra": "^3.352.0",
+ "@aws-sdk/client-lambda": "^3.310.0",
+ "@aws-sdk/client-s3": "^3.310.0",
+ "@aws-sdk/client-sagemaker-runtime": "^3.310.0",
+ "@aws-sdk/client-sfn": "^3.310.0",
+ "@aws-sdk/credential-provider-node": "^3.388.0",
+ "@azure/search-documents": "^12.0.0",
+ "@azure/storage-blob": "^12.15.0",
+ "@browserbasehq/sdk": "*",
+ "@clickhouse/client": "^0.2.5",
+ "@cloudflare/ai": "*",
+ "@datastax/astra-db-ts": "^1.0.0",
+ "@elastic/elasticsearch": "^8.4.0",
+ "@getmetal/metal-sdk": "*",
+ "@getzep/zep-cloud": "^1.0.6",
+ "@getzep/zep-js": "^0.9.0",
+ "@gomomento/sdk": "^1.51.1",
+ "@gomomento/sdk-core": "^1.51.1",
+ "@google-ai/generativelanguage": "*",
+ "@google-cloud/storage": "^6.10.1 || ^7.7.0",
+ "@gradientai/nodejs-sdk": "^1.2.0",
+ "@huggingface/inference": "^2.6.4",
+ "@ibm-cloud/watsonx-ai": "*",
+ "@langchain/core": ">=0.2.21 <0.4.0",
+ "@layerup/layerup-security": "^1.5.12",
+ "@libsql/client": "^0.14.0",
+ "@mendable/firecrawl-js": "^1.4.3",
+ "@mlc-ai/web-llm": "*",
+ "@mozilla/readability": "*",
+ "@neondatabase/serverless": "*",
+ "@notionhq/client": "^2.2.10",
+ "@opensearch-project/opensearch": "*",
+ "@pinecone-database/pinecone": "*",
+ "@planetscale/database": "^1.8.0",
+ "@premai/prem-sdk": "^0.3.25",
+ "@qdrant/js-client-rest": "^1.8.2",
+ "@raycast/api": "^1.55.2",
+ "@rockset/client": "^0.9.1",
+ "@smithy/eventstream-codec": "^2.0.5",
+ "@smithy/protocol-http": "^3.0.6",
+ "@smithy/signature-v4": "^2.0.10",
+ "@smithy/util-utf8": "^2.0.0",
+ "@spider-cloud/spider-client": "^0.0.21",
+ "@supabase/supabase-js": "^2.45.0",
+ "@tensorflow-models/universal-sentence-encoder": "*",
+ "@tensorflow/tfjs-converter": "*",
+ "@tensorflow/tfjs-core": "*",
+ "@upstash/ratelimit": "^1.1.3 || ^2.0.3",
+ "@upstash/redis": "^1.20.6",
+ "@upstash/vector": "^1.1.1",
+ "@vercel/kv": "^0.2.3",
+ "@vercel/postgres": "^0.5.0",
+ "@writerai/writer-sdk": "^0.40.2",
+ "@xata.io/client": "^0.28.0",
+ "@xenova/transformers": "^2.17.2",
+ "@zilliz/milvus2-sdk-node": ">=2.3.5",
+ "apify-client": "^2.7.1",
+ "assemblyai": "^4.6.0",
+ "better-sqlite3": ">=9.4.0 <12.0.0",
+ "cassandra-driver": "^4.7.2",
+ "cborg": "^4.1.1",
+ "cheerio": "^1.0.0-rc.12",
+ "chromadb": "*",
+ "closevector-common": "0.1.3",
+ "closevector-node": "0.1.6",
+ "closevector-web": "0.1.6",
+ "cohere-ai": "*",
+ "convex": "^1.3.1",
+ "crypto-js": "^4.2.0",
+ "d3-dsv": "^2.0.0",
+ "discord.js": "^14.14.1",
+ "dria": "^0.0.3",
+ "duck-duck-scrape": "^2.2.5",
+ "epub2": "^3.0.1",
+ "faiss-node": "^0.5.1",
+ "firebase-admin": "^11.9.0 || ^12.0.0",
+ "google-auth-library": "*",
+ "googleapis": "*",
+ "hnswlib-node": "^3.0.0",
+ "html-to-text": "^9.0.5",
+ "ibm-cloud-sdk-core": "*",
+ "ignore": "^5.2.0",
+ "interface-datastore": "^8.2.11",
+ "ioredis": "^5.3.2",
+ "it-all": "^3.0.4",
+ "jsdom": "*",
+ "jsonwebtoken": "^9.0.2",
+ "llmonitor": "^0.5.9",
+ "lodash": "^4.17.21",
+ "lunary": "^0.7.10",
+ "mammoth": "^1.6.0",
+ "mongodb": ">=5.2.0",
+ "mysql2": "^3.9.8",
+ "neo4j-driver": "*",
+ "notion-to-md": "^3.1.0",
+ "officeparser": "^4.0.4",
+ "pdf-parse": "1.1.1",
+ "pg": "^8.11.0",
+ "pg-copy-streams": "^6.0.5",
+ "pickleparser": "^0.2.1",
+ "playwright": "^1.32.1",
+ "portkey-ai": "^0.1.11",
+ "puppeteer": "*",
+ "pyodide": ">=0.24.1 <0.27.0",
+ "redis": "*",
+ "replicate": "^0.29.4",
+ "sonix-speech-recognition": "^2.1.1",
+ "srt-parser-2": "^1.2.3",
+ "typeorm": "^0.3.20",
+ "typesense": "^1.5.3",
+ "usearch": "^1.1.1",
+ "vectordb": "^0.1.4",
+ "voy-search": "0.6.2",
+ "weaviate-ts-client": "*",
+ "web-auth-library": "^1.0.3",
+ "ws": "^8.14.2",
+ "youtube-transcript": "^1.0.6",
+ "youtubei.js": "^9.1.0"
},
- "peerDependencies": {
- "@langchain/core": ">=0.2.21 <0.4.0"
+ "peerDependenciesMeta": {
+ "@arcjet/redact": {
+ "optional": true
+ },
+ "@aws-crypto/sha256-js": {
+ "optional": true
+ },
+ "@aws-sdk/client-bedrock-agent-runtime": {
+ "optional": true
+ },
+ "@aws-sdk/client-bedrock-runtime": {
+ "optional": true
+ },
+ "@aws-sdk/client-dynamodb": {
+ "optional": true
+ },
+ "@aws-sdk/client-kendra": {
+ "optional": true
+ },
+ "@aws-sdk/client-lambda": {
+ "optional": true
+ },
+ "@aws-sdk/client-s3": {
+ "optional": true
+ },
+ "@aws-sdk/client-sagemaker-runtime": {
+ "optional": true
+ },
+ "@aws-sdk/client-sfn": {
+ "optional": true
+ },
+ "@aws-sdk/credential-provider-node": {
+ "optional": true
+ },
+ "@azure/search-documents": {
+ "optional": true
+ },
+ "@azure/storage-blob": {
+ "optional": true
+ },
+ "@browserbasehq/sdk": {
+ "optional": true
+ },
+ "@clickhouse/client": {
+ "optional": true
+ },
+ "@cloudflare/ai": {
+ "optional": true
+ },
+ "@datastax/astra-db-ts": {
+ "optional": true
+ },
+ "@elastic/elasticsearch": {
+ "optional": true
+ },
+ "@getmetal/metal-sdk": {
+ "optional": true
+ },
+ "@getzep/zep-cloud": {
+ "optional": true
+ },
+ "@getzep/zep-js": {
+ "optional": true
+ },
+ "@gomomento/sdk": {
+ "optional": true
+ },
+ "@gomomento/sdk-core": {
+ "optional": true
+ },
+ "@google-ai/generativelanguage": {
+ "optional": true
+ },
+ "@google-cloud/storage": {
+ "optional": true
+ },
+ "@gradientai/nodejs-sdk": {
+ "optional": true
+ },
+ "@huggingface/inference": {
+ "optional": true
+ },
+ "@layerup/layerup-security": {
+ "optional": true
+ },
+ "@libsql/client": {
+ "optional": true
+ },
+ "@mendable/firecrawl-js": {
+ "optional": true
+ },
+ "@mlc-ai/web-llm": {
+ "optional": true
+ },
+ "@mozilla/readability": {
+ "optional": true
+ },
+ "@neondatabase/serverless": {
+ "optional": true
+ },
+ "@notionhq/client": {
+ "optional": true
+ },
+ "@opensearch-project/opensearch": {
+ "optional": true
+ },
+ "@pinecone-database/pinecone": {
+ "optional": true
+ },
+ "@planetscale/database": {
+ "optional": true
+ },
+ "@premai/prem-sdk": {
+ "optional": true
+ },
+ "@qdrant/js-client-rest": {
+ "optional": true
+ },
+ "@raycast/api": {
+ "optional": true
+ },
+ "@rockset/client": {
+ "optional": true
+ },
+ "@smithy/eventstream-codec": {
+ "optional": true
+ },
+ "@smithy/protocol-http": {
+ "optional": true
+ },
+ "@smithy/signature-v4": {
+ "optional": true
+ },
+ "@smithy/util-utf8": {
+ "optional": true
+ },
+ "@spider-cloud/spider-client": {
+ "optional": true
+ },
+ "@supabase/supabase-js": {
+ "optional": true
+ },
+ "@tensorflow-models/universal-sentence-encoder": {
+ "optional": true
+ },
+ "@tensorflow/tfjs-converter": {
+ "optional": true
+ },
+ "@tensorflow/tfjs-core": {
+ "optional": true
+ },
+ "@upstash/ratelimit": {
+ "optional": true
+ },
+ "@upstash/redis": {
+ "optional": true
+ },
+ "@upstash/vector": {
+ "optional": true
+ },
+ "@vercel/kv": {
+ "optional": true
+ },
+ "@vercel/postgres": {
+ "optional": true
+ },
+ "@writerai/writer-sdk": {
+ "optional": true
+ },
+ "@xata.io/client": {
+ "optional": true
+ },
+ "@xenova/transformers": {
+ "optional": true
+ },
+ "@zilliz/milvus2-sdk-node": {
+ "optional": true
+ },
+ "apify-client": {
+ "optional": true
+ },
+ "assemblyai": {
+ "optional": true
+ },
+ "better-sqlite3": {
+ "optional": true
+ },
+ "cassandra-driver": {
+ "optional": true
+ },
+ "cborg": {
+ "optional": true
+ },
+ "cheerio": {
+ "optional": true
+ },
+ "chromadb": {
+ "optional": true
+ },
+ "closevector-common": {
+ "optional": true
+ },
+ "closevector-node": {
+ "optional": true
+ },
+ "closevector-web": {
+ "optional": true
+ },
+ "cohere-ai": {
+ "optional": true
+ },
+ "convex": {
+ "optional": true
+ },
+ "crypto-js": {
+ "optional": true
+ },
+ "d3-dsv": {
+ "optional": true
+ },
+ "discord.js": {
+ "optional": true
+ },
+ "dria": {
+ "optional": true
+ },
+ "duck-duck-scrape": {
+ "optional": true
+ },
+ "epub2": {
+ "optional": true
+ },
+ "faiss-node": {
+ "optional": true
+ },
+ "firebase-admin": {
+ "optional": true
+ },
+ "google-auth-library": {
+ "optional": true
+ },
+ "googleapis": {
+ "optional": true
+ },
+ "hnswlib-node": {
+ "optional": true
+ },
+ "html-to-text": {
+ "optional": true
+ },
+ "ignore": {
+ "optional": true
+ },
+ "interface-datastore": {
+ "optional": true
+ },
+ "ioredis": {
+ "optional": true
+ },
+ "it-all": {
+ "optional": true
+ },
+ "jsdom": {
+ "optional": true
+ },
+ "jsonwebtoken": {
+ "optional": true
+ },
+ "llmonitor": {
+ "optional": true
+ },
+ "lodash": {
+ "optional": true
+ },
+ "lunary": {
+ "optional": true
+ },
+ "mammoth": {
+ "optional": true
+ },
+ "mongodb": {
+ "optional": true
+ },
+ "mysql2": {
+ "optional": true
+ },
+ "neo4j-driver": {
+ "optional": true
+ },
+ "notion-to-md": {
+ "optional": true
+ },
+ "officeparser": {
+ "optional": true
+ },
+ "pdf-parse": {
+ "optional": true
+ },
+ "pg": {
+ "optional": true
+ },
+ "pg-copy-streams": {
+ "optional": true
+ },
+ "pickleparser": {
+ "optional": true
+ },
+ "playwright": {
+ "optional": true
+ },
+ "portkey-ai": {
+ "optional": true
+ },
+ "puppeteer": {
+ "optional": true
+ },
+ "pyodide": {
+ "optional": true
+ },
+ "redis": {
+ "optional": true
+ },
+ "replicate": {
+ "optional": true
+ },
+ "sonix-speech-recognition": {
+ "optional": true
+ },
+ "srt-parser-2": {
+ "optional": true
+ },
+ "typeorm": {
+ "optional": true
+ },
+ "typesense": {
+ "optional": true
+ },
+ "usearch": {
+ "optional": true
+ },
+ "vectordb": {
+ "optional": true
+ },
+ "voy-search": {
+ "optional": true
+ },
+ "weaviate-ts-client": {
+ "optional": true
+ },
+ "web-auth-library": {
+ "optional": true
+ },
+ "ws": {
+ "optional": true
+ },
+ "youtube-transcript": {
+ "optional": true
+ },
+ "youtubei.js": {
+ "optional": true
+ }
}
},
"api/node_modules/@langchain/google-genai": {
@@ -246,35 +664,6 @@
"@langchain/core": ">=0.3.17 <0.4.0"
}
},
- "api/node_modules/@langchain/google-vertexai": {
- "version": "0.1.2",
- "resolved": "https://registry.npmjs.org/@langchain/google-vertexai/-/google-vertexai-0.1.2.tgz",
- "integrity": "sha512-b8Di2AgSwlyyKl4A5qii+19Wj82I1KvtUXSDvJpDzhucuyrJjmnNb/0ClkaIQv6RyISajtxszxxSGHukPn3PJA==",
- "dependencies": {
- "@langchain/google-gauth": "~0.1.2"
- },
- "engines": {
- "node": ">=18"
- },
- "peerDependencies": {
- "@langchain/core": ">=0.2.21 <0.4.0"
- }
- },
- "api/node_modules/@langchain/google-vertexai/node_modules/@langchain/google-gauth": {
- "version": "0.1.2",
- "resolved": "https://registry.npmjs.org/@langchain/google-gauth/-/google-gauth-0.1.2.tgz",
- "integrity": "sha512-5fPPaVcv4l2o/WdPuFLkIKFsfAeY8JD7zP/lFlTTeDvCbGbnsywwX08ZCqe9jgDIVBGcIoUqhiyBvwrpJMzMEw==",
- "dependencies": {
- "@langchain/google-common": "~0.1.2",
- "google-auth-library": "^8.9.0"
- },
- "engines": {
- "node": ">=18"
- },
- "peerDependencies": {
- "@langchain/core": ">=0.2.21 <0.4.0"
- }
- },
"api/node_modules/@langchain/openai": {
"version": "0.3.12",
"resolved": "https://registry.npmjs.org/@langchain/openai/-/openai-0.3.12.tgz",
@@ -308,23 +697,22 @@
}
},
"api/node_modules/@librechat/agents": {
- "version": "1.7.7",
- "resolved": "https://registry.npmjs.org/@librechat/agents/-/agents-1.7.7.tgz",
- "integrity": "sha512-0VOvPtPzbAUF5BXt+qeIlQqYzPV4RC4+iz3g9HooBPDIuPlaEHAH7RC2fiRKO6XJ/1E5/8YSj6YugV3MJGyyoQ==",
- "license": "MIT",
+ "version": "1.8.5",
+ "resolved": "https://registry.npmjs.org/@librechat/agents/-/agents-1.8.5.tgz",
+ "integrity": "sha512-c7aVohA6RRISq67gqRz+iSAIVZag1ggfhfCpFw9cTCtZsJ2zUhvBwDw8+sN9yx5SLQ3LM/3Ns147529i7SfwvA==",
"dependencies": {
"@aws-crypto/sha256-js": "^5.2.0",
"@aws-sdk/credential-provider-node": "^3.613.0",
"@aws-sdk/types": "^3.609.0",
- "@langchain/anthropic": "^0.3.7",
- "@langchain/aws": "^0.1.1",
- "@langchain/community": "^0.3.11",
- "@langchain/core": "^0.3.16",
- "@langchain/google-vertexai": "^0.0.20",
+ "@langchain/anthropic": "^0.3.8",
+ "@langchain/aws": "^0.1.2",
+ "@langchain/community": "^0.3.14",
+ "@langchain/core": "^0.3.18",
+ "@langchain/google-vertexai": "^0.1.2",
"@langchain/langgraph": "^0.2.19",
"@langchain/mistralai": "^0.0.26",
"@langchain/ollama": "^0.1.1",
- "@langchain/openai": "^0.3.11",
+ "@langchain/openai": "^0.3.14",
"@smithy/eventstream-codec": "^2.2.0",
"@smithy/protocol-http": "^3.0.6",
"@smithy/signature-v4": "^2.0.10",
@@ -336,125 +724,6 @@
"node": ">=14.0.0"
}
},
- "api/node_modules/@librechat/agents/node_modules/@langchain/core": {
- "version": "0.3.17",
- "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.3.17.tgz",
- "integrity": "sha512-o4lgmRcEqAyioP4Snxat1DGIT0oasOYsfo9uvAxVjwGq+XRicXm+bO3smCBSiiPQnd6jJ9ULWJlI0RFUV1oNqQ==",
- "license": "MIT",
- "dependencies": {
- "ansi-styles": "^5.0.0",
- "camelcase": "6",
- "decamelize": "1.2.0",
- "js-tiktoken": "^1.0.12",
- "langsmith": "^0.2.0",
- "mustache": "^4.2.0",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "uuid": "^10.0.0",
- "zod": "^3.22.4",
- "zod-to-json-schema": "^3.22.3"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "api/node_modules/@librechat/agents/node_modules/@langchain/google-vertexai": {
- "version": "0.0.20",
- "resolved": "https://registry.npmjs.org/@langchain/google-vertexai/-/google-vertexai-0.0.20.tgz",
- "integrity": "sha512-78rGODbPVo6aITkQjbYVL7Ard5lf7xZWwHE83mpEg2hER/vLPcstHK795q6d9jcNf+9Da2y5tqWjzR/dx+OFDw==",
- "license": "MIT",
- "dependencies": {
- "@langchain/core": ">0.1.56 <0.3.0",
- "@langchain/google-gauth": "~0.0.20"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "api/node_modules/@librechat/agents/node_modules/@langchain/google-vertexai/node_modules/@langchain/core": {
- "version": "0.2.36",
- "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.2.36.tgz",
- "integrity": "sha512-qHLvScqERDeH7y2cLuJaSAlMwg3f/3Oc9nayRSXRU2UuaK/SOhI42cxiPLj1FnuHJSmN0rBQFkrLx02gI4mcVg==",
- "license": "MIT",
- "dependencies": {
- "ansi-styles": "^5.0.0",
- "camelcase": "6",
- "decamelize": "1.2.0",
- "js-tiktoken": "^1.0.12",
- "langsmith": "^0.1.56-rc.1",
- "mustache": "^4.2.0",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "uuid": "^10.0.0",
- "zod": "^3.22.4",
- "zod-to-json-schema": "^3.22.3"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "api/node_modules/@librechat/agents/node_modules/@langchain/google-vertexai/node_modules/langsmith": {
- "version": "0.1.68",
- "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.1.68.tgz",
- "integrity": "sha512-otmiysWtVAqzMx3CJ4PrtUBhWRG5Co8Z4o7hSZENPjlit9/j3/vm3TSvbaxpDYakZxtMjhkcJTqrdYFipISEiQ==",
- "license": "MIT",
- "dependencies": {
- "@types/uuid": "^10.0.0",
- "commander": "^10.0.1",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "semver": "^7.6.3",
- "uuid": "^10.0.0"
- },
- "peerDependencies": {
- "openai": "*"
- },
- "peerDependenciesMeta": {
- "openai": {
- "optional": true
- }
- }
- },
- "api/node_modules/@librechat/agents/node_modules/@langchain/langgraph": {
- "version": "0.2.20",
- "resolved": "https://registry.npmjs.org/@langchain/langgraph/-/langgraph-0.2.20.tgz",
- "integrity": "sha512-MMD4G++gHs+5OO5Uu75gduskTboJ8Q7ZAwzd1s64a1Y/38pdgDqJdYRHRCGpx8eeCuKhsRzV2Sssnl5lujfj8w==",
- "license": "MIT",
- "dependencies": {
- "@langchain/langgraph-checkpoint": "~0.0.10",
- "@langchain/langgraph-sdk": "~0.0.20",
- "uuid": "^10.0.0",
- "zod": "^3.23.8"
- },
- "engines": {
- "node": ">=18"
- },
- "peerDependencies": {
- "@langchain/core": ">=0.2.36 <0.3.0 || >=0.3.9 < 0.4.0"
- }
- },
- "api/node_modules/@librechat/agents/node_modules/langsmith": {
- "version": "0.2.4",
- "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.2.4.tgz",
- "integrity": "sha512-0st1OWbH/jiGAksoJrUBOq4Gc9iMX6yy8FYmF/0aGcZEd2hpiara+Y03mpe2BuhteRR2U3YjL7Lj/TNA1Jj5/g==",
- "license": "MIT",
- "dependencies": {
- "@types/uuid": "^10.0.0",
- "commander": "^10.0.1",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "semver": "^7.6.3",
- "uuid": "^10.0.0"
- },
- "peerDependencies": {
- "openai": "*"
- },
- "peerDependenciesMeta": {
- "openai": {
- "optional": true
- }
- }
- },
"api/node_modules/@types/node": {
"version": "18.19.14",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.14.tgz",
@@ -471,17 +740,6 @@
"@types/webidl-conversions": "*"
}
},
- "api/node_modules/ansi-styles": {
- "version": "5.2.0",
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
- "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/chalk/ansi-styles?sponsor=1"
- }
- },
"api/node_modules/bson": {
"version": "6.10.1",
"resolved": "https://registry.npmjs.org/bson/-/bson-6.10.1.tgz",
@@ -581,27 +839,6 @@
"node": ">=12.0.0"
}
},
- "api/node_modules/langsmith": {
- "version": "0.1.59",
- "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.1.59.tgz",
- "integrity": "sha512-dW+z6s538zBswFFP2w/xzvVef7y2+yNt6GkmRCeLtwfpbMaM4di7JboK3vmnZ+0/LjNb2ukiMmgsTNKu/Y43cg==",
- "dependencies": {
- "@types/uuid": "^10.0.0",
- "commander": "^10.0.1",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "semver": "^7.6.3",
- "uuid": "^10.0.0"
- },
- "peerDependencies": {
- "openai": "*"
- },
- "peerDependenciesMeta": {
- "openai": {
- "optional": true
- }
- }
- },
"api/node_modules/mongodb": {
"version": "6.10.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.10.0.tgz",
@@ -773,19 +1010,6 @@
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
- "api/node_modules/uuid": {
- "version": "10.0.0",
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
- "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
- "funding": [
- "https://github.com/sponsors/broofa",
- "https://github.com/sponsors/ctavan"
- ],
- "license": "MIT",
- "bin": {
- "uuid": "dist/bin/uuid"
- }
- },
"api/node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
@@ -9011,28 +9235,26 @@
}
},
"node_modules/@langchain/anthropic": {
- "version": "0.2.18",
- "resolved": "https://registry.npmjs.org/@langchain/anthropic/-/anthropic-0.2.18.tgz",
- "integrity": "sha512-4ZDTxMwGKTPRAi2Supu/faBSmwPIm/ga5QlazyO78Mf/8QbDR2DcvM5394FAy+X/nRAfnMbyXteO5IRJm653gw==",
- "optional": true,
- "peer": true,
+ "version": "0.3.8",
+ "resolved": "https://registry.npmjs.org/@langchain/anthropic/-/anthropic-0.3.8.tgz",
+ "integrity": "sha512-7qeRDhNnCf1peAbjY825R2HNszobJeGvqi2cfPl+YsduDIYEGUzfoGRRarPI5joIGX5YshCsch6NFtap2bLfmw==",
"dependencies": {
- "@anthropic-ai/sdk": "^0.25.2",
- "@langchain/core": ">=0.2.21 <0.3.0",
+ "@anthropic-ai/sdk": "^0.27.3",
"fast-xml-parser": "^4.4.1",
"zod": "^3.22.4",
"zod-to-json-schema": "^3.22.4"
},
"engines": {
"node": ">=18"
+ },
+ "peerDependencies": {
+ "@langchain/core": ">=0.2.21 <0.4.0"
}
},
"node_modules/@langchain/anthropic/node_modules/@anthropic-ai/sdk": {
- "version": "0.25.2",
- "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.25.2.tgz",
- "integrity": "sha512-F1Hck/asswwidFLtGdMg3XYgRxEUfygNbpkq5KEaEGsHNaSfxeX18/uZGQCL0oQNcj/tYNx8BaFXVwRhFDi45g==",
- "optional": true,
- "peer": true,
+ "version": "0.27.3",
+ "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.27.3.tgz",
+ "integrity": "sha512-IjLt0gd3L4jlOfilxVXTifn42FnVffMgDC04RJK1KDZpmkBWLv0XC92MVVmkxrFZNS/7l3xWgP/I3nqtX1sQHw==",
"dependencies": {
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.4",
@@ -9043,185 +9265,39 @@
"node-fetch": "^2.6.7"
}
},
- "node_modules/@langchain/anthropic/node_modules/@langchain/core": {
- "version": "0.2.34",
- "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.2.34.tgz",
- "integrity": "sha512-Hkveq1UcOjUj1DVn5erbqElyRj1t04NORSuSIZAJCtPO7EDkIqomjAarJ5+I5NUpQeIONgbOdnY9TkJ6cKUSVA==",
- "optional": true,
- "peer": true,
- "dependencies": {
- "ansi-styles": "^5.0.0",
- "camelcase": "6",
- "decamelize": "1.2.0",
- "js-tiktoken": "^1.0.12",
- "langsmith": "^0.1.56-rc.1",
- "mustache": "^4.2.0",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "uuid": "^10.0.0",
- "zod": "^3.22.4",
- "zod-to-json-schema": "^3.22.3"
- },
- "engines": {
- "node": ">=18"
- }
- },
"node_modules/@langchain/anthropic/node_modules/@types/node": {
- "version": "18.19.53",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.53.tgz",
- "integrity": "sha512-GLxgUgHhDKO1Edw9Q0lvMbiO/IQXJwJlMaqxSGBXMpPy8uhkCs2iiPFaB2Q/gmobnFkckD3rqTBMVjXdwq+nKg==",
- "optional": true,
- "peer": true,
+ "version": "18.19.64",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.64.tgz",
+ "integrity": "sha512-955mDqvO2vFf/oL7V3WiUtiz+BugyX8uVbaT2H8oj3+8dRyH2FLiNdowe7eNqRM7IOIZvzDH76EoAT+gwm6aIQ==",
"dependencies": {
"undici-types": "~5.26.4"
}
},
- "node_modules/@langchain/anthropic/node_modules/ansi-styles": {
- "version": "5.2.0",
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
- "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
- "optional": true,
- "peer": true,
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/chalk/ansi-styles?sponsor=1"
- }
- },
- "node_modules/@langchain/anthropic/node_modules/langsmith": {
- "version": "0.1.61",
- "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.1.61.tgz",
- "integrity": "sha512-XQE4KPScwPmdaT0mWDzhNxj9gvqXUR+C7urLA0QFi27XeoQdm17eYpudenn4wxC0gIyUJutQCyuYJpfwlT5JnQ==",
- "optional": true,
- "peer": true,
- "dependencies": {
- "@types/uuid": "^10.0.0",
- "commander": "^10.0.1",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "semver": "^7.6.3",
- "uuid": "^10.0.0"
- },
- "peerDependencies": {
- "openai": "*"
- },
- "peerDependenciesMeta": {
- "openai": {
- "optional": true
- }
- }
- },
- "node_modules/@langchain/anthropic/node_modules/uuid": {
- "version": "10.0.0",
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
- "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
- "funding": [
- "https://github.com/sponsors/broofa",
- "https://github.com/sponsors/ctavan"
- ],
- "optional": true,
- "peer": true,
- "bin": {
- "uuid": "dist/bin/uuid"
- }
- },
"node_modules/@langchain/aws": {
- "version": "0.0.10",
- "resolved": "https://registry.npmjs.org/@langchain/aws/-/aws-0.0.10.tgz",
- "integrity": "sha512-q9sL34lq2UpSVDBTNixy2+DJbjd5RSlCGBoatVeWpfMDv2J47sJZlfVGfXLidFZhQox6uL1GyQJoKrIb+Cu97Q==",
- "optional": true,
- "peer": true,
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/@langchain/aws/-/aws-0.1.2.tgz",
+ "integrity": "sha512-1cQvv8XSbaZXceAbYexSm/8WLqfEJ4VF6qbf/XLwkpUKMFGqpSBA00+Bn5p8K/Ms+PyMguZrxVNqd6daqxhDBQ==",
"dependencies": {
"@aws-sdk/client-bedrock-agent-runtime": "^3.616.0",
"@aws-sdk/client-bedrock-runtime": "^3.602.0",
"@aws-sdk/client-kendra": "^3.352.0",
"@aws-sdk/credential-provider-node": "^3.600.0",
- "@langchain/core": ">=0.2.21 <0.3.0",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.22.5"
},
"engines": {
"node": ">=18"
- }
- },
- "node_modules/@langchain/aws/node_modules/@langchain/core": {
- "version": "0.2.34",
- "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.2.34.tgz",
- "integrity": "sha512-Hkveq1UcOjUj1DVn5erbqElyRj1t04NORSuSIZAJCtPO7EDkIqomjAarJ5+I5NUpQeIONgbOdnY9TkJ6cKUSVA==",
- "optional": true,
- "peer": true,
- "dependencies": {
- "ansi-styles": "^5.0.0",
- "camelcase": "6",
- "decamelize": "1.2.0",
- "js-tiktoken": "^1.0.12",
- "langsmith": "^0.1.56-rc.1",
- "mustache": "^4.2.0",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "uuid": "^10.0.0",
- "zod": "^3.22.4",
- "zod-to-json-schema": "^3.22.3"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "node_modules/@langchain/aws/node_modules/ansi-styles": {
- "version": "5.2.0",
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
- "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
- "optional": true,
- "peer": true,
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/chalk/ansi-styles?sponsor=1"
- }
- },
- "node_modules/@langchain/aws/node_modules/langsmith": {
- "version": "0.1.61",
- "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.1.61.tgz",
- "integrity": "sha512-XQE4KPScwPmdaT0mWDzhNxj9gvqXUR+C7urLA0QFi27XeoQdm17eYpudenn4wxC0gIyUJutQCyuYJpfwlT5JnQ==",
- "optional": true,
- "peer": true,
- "dependencies": {
- "@types/uuid": "^10.0.0",
- "commander": "^10.0.1",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "semver": "^7.6.3",
- "uuid": "^10.0.0"
},
"peerDependencies": {
- "openai": "*"
- },
- "peerDependenciesMeta": {
- "openai": {
- "optional": true
- }
+ "@langchain/core": ">=0.2.21 <0.4.0"
}
},
- "node_modules/@langchain/aws/node_modules/uuid": {
- "version": "10.0.0",
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
- "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
- "funding": [
- "https://github.com/sponsors/broofa",
- "https://github.com/sponsors/ctavan"
- ],
+ "node_modules/@langchain/community": {
+ "version": "0.3.15",
+ "resolved": "https://registry.npmjs.org/@langchain/community/-/community-0.3.15.tgz",
+ "integrity": "sha512-yG4cv33u7zYar14yqZCI7o2KjwRb+9S7upVzEmVVETimpicm9UjpkMfX4qa4A4IslM1TtC4uy2Ymu9EcINZSpQ==",
"optional": true,
"peer": true,
- "bin": {
- "uuid": "dist/bin/uuid"
- }
- },
- "node_modules/@langchain/community": {
- "version": "0.3.13",
- "resolved": "https://registry.npmjs.org/@langchain/community/-/community-0.3.13.tgz",
- "integrity": "sha512-D48SZXJgjqlDmoX7ZU6rik/1ynL3zKhhSypmIQln+dfwXECKKPNKkJLnCxNQkTHNc5NgpXwwXKeruWyySHSMHw==",
"dependencies": {
"@langchain/openai": ">=0.2.0 <0.4.0",
"binary-extensions": "^2.2.0",
@@ -9266,6 +9342,7 @@
"@gradientai/nodejs-sdk": "^1.2.0",
"@huggingface/inference": "^2.6.4",
"@ibm-cloud/watsonx-ai": "*",
+ "@lancedb/lancedb": "^0.12.0",
"@langchain/core": ">=0.2.21 <0.4.0",
"@layerup/layerup-security": "^1.5.12",
"@libsql/client": "^0.14.0",
@@ -9354,7 +9431,6 @@
"typeorm": "^0.3.20",
"typesense": "^1.5.3",
"usearch": "^1.1.1",
- "vectordb": "^0.1.4",
"voy-search": "0.6.2",
"weaviate-ts-client": "*",
"web-auth-library": "^1.0.3",
@@ -9444,6 +9520,9 @@
"@huggingface/inference": {
"optional": true
},
+ "@lancedb/lancedb": {
+ "optional": true
+ },
"@layerup/layerup-security": {
"optional": true
},
@@ -9702,9 +9781,6 @@
"usearch": {
"optional": true
},
- "vectordb": {
- "optional": true
- },
"voy-search": {
"optional": true
},
@@ -9733,16 +9809,16 @@
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
+ "optional": true,
+ "peer": true,
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/@langchain/core": {
- "version": "0.3.17",
- "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.3.17.tgz",
- "integrity": "sha512-o4lgmRcEqAyioP4Snxat1DGIT0oasOYsfo9uvAxVjwGq+XRicXm+bO3smCBSiiPQnd6jJ9ULWJlI0RFUV1oNqQ==",
- "license": "MIT",
- "peer": true,
+ "version": "0.3.18",
+ "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.3.18.tgz",
+ "integrity": "sha512-IEZCrFs1Xd0J2FTH1D3Lnm3/Yk2r8LSpwDeLYwcCom3rNAK5k4mKQ2rwIpNq3YuqBdrTNMKRO+PopjkP1SB17A==",
"dependencies": {
"ansi-styles": "^5.0.0",
"camelcase": "6",
@@ -9764,7 +9840,6 @@
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
- "peer": true,
"engines": {
"node": ">=10"
},
@@ -9781,179 +9856,6 @@
"https://github.com/sponsors/ctavan"
],
"license": "MIT",
- "peer": true,
- "bin": {
- "uuid": "dist/bin/uuid"
- }
- },
- "node_modules/@langchain/google-common": {
- "version": "0.0.27",
- "resolved": "https://registry.npmjs.org/@langchain/google-common/-/google-common-0.0.27.tgz",
- "integrity": "sha512-CGuSQYncI5BYx+RJ2lFBT/yyH/FMeqNj8HXnkEWQFlySI7FsZNqhnr64yfuSdeOiSWuqpDBECLSLJ/YVp2iJJQ==",
- "dependencies": {
- "@langchain/core": ">=0.2.21 <0.3.0",
- "uuid": "^10.0.0",
- "zod-to-json-schema": "^3.22.4"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "node_modules/@langchain/google-common/node_modules/@langchain/core": {
- "version": "0.2.31",
- "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.2.31.tgz",
- "integrity": "sha512-qGfeaACST7dvovgHItzuag9fEBGK7IjCE9vRuTu/y8/WYGJi28WPD/AwWxnu7YdW1vZSuIXO6ZA76t2G9B/oKg==",
- "dependencies": {
- "ansi-styles": "^5.0.0",
- "camelcase": "6",
- "decamelize": "1.2.0",
- "js-tiktoken": "^1.0.12",
- "langsmith": "^0.1.43",
- "mustache": "^4.2.0",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "uuid": "^10.0.0",
- "zod": "^3.22.4",
- "zod-to-json-schema": "^3.22.3"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "node_modules/@langchain/google-common/node_modules/ansi-styles": {
- "version": "5.2.0",
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
- "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/chalk/ansi-styles?sponsor=1"
- }
- },
- "node_modules/@langchain/google-common/node_modules/langsmith": {
- "version": "0.1.49",
- "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.1.49.tgz",
- "integrity": "sha512-PI9qzBalZYpN2gu1kf1IX/+unRRXTiZRhtTKYfWcPyQVPZ5exZVJfZy515+FUp1iXdgacr2tS2ZtNGUB2Vdejg==",
- "dependencies": {
- "@types/uuid": "^10.0.0",
- "commander": "^10.0.1",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "semver": "^7.6.3",
- "uuid": "^10.0.0"
- },
- "peerDependencies": {
- "@langchain/core": "*",
- "langchain": "*",
- "openai": "*"
- },
- "peerDependenciesMeta": {
- "@langchain/core": {
- "optional": true
- },
- "langchain": {
- "optional": true
- },
- "openai": {
- "optional": true
- }
- }
- },
- "node_modules/@langchain/google-common/node_modules/uuid": {
- "version": "10.0.0",
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
- "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
- "funding": [
- "https://github.com/sponsors/broofa",
- "https://github.com/sponsors/ctavan"
- ],
- "bin": {
- "uuid": "dist/bin/uuid"
- }
- },
- "node_modules/@langchain/google-gauth": {
- "version": "0.0.27",
- "resolved": "https://registry.npmjs.org/@langchain/google-gauth/-/google-gauth-0.0.27.tgz",
- "integrity": "sha512-iBRKWE0IqKCB8Y5lBDBSGr5HqYvnZTX8mbbuoFnXFe+bdtXzktl/zS/zD5uLCj61hwWKFTDmJyKrKp2Hsst79w==",
- "dependencies": {
- "@langchain/core": ">=0.2.21 <0.3.0",
- "@langchain/google-common": "~0.0.27",
- "google-auth-library": "^8.9.0"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "node_modules/@langchain/google-gauth/node_modules/@langchain/core": {
- "version": "0.2.31",
- "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.2.31.tgz",
- "integrity": "sha512-qGfeaACST7dvovgHItzuag9fEBGK7IjCE9vRuTu/y8/WYGJi28WPD/AwWxnu7YdW1vZSuIXO6ZA76t2G9B/oKg==",
- "dependencies": {
- "ansi-styles": "^5.0.0",
- "camelcase": "6",
- "decamelize": "1.2.0",
- "js-tiktoken": "^1.0.12",
- "langsmith": "^0.1.43",
- "mustache": "^4.2.0",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "uuid": "^10.0.0",
- "zod": "^3.22.4",
- "zod-to-json-schema": "^3.22.3"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "node_modules/@langchain/google-gauth/node_modules/@langchain/core/node_modules/langsmith": {
- "version": "0.1.49",
- "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.1.49.tgz",
- "integrity": "sha512-PI9qzBalZYpN2gu1kf1IX/+unRRXTiZRhtTKYfWcPyQVPZ5exZVJfZy515+FUp1iXdgacr2tS2ZtNGUB2Vdejg==",
- "dependencies": {
- "@types/uuid": "^10.0.0",
- "commander": "^10.0.1",
- "p-queue": "^6.6.2",
- "p-retry": "4",
- "semver": "^7.6.3",
- "uuid": "^10.0.0"
- },
- "peerDependencies": {
- "@langchain/core": "*",
- "langchain": "*",
- "openai": "*"
- },
- "peerDependenciesMeta": {
- "@langchain/core": {
- "optional": true
- },
- "langchain": {
- "optional": true
- },
- "openai": {
- "optional": true
- }
- }
- },
- "node_modules/@langchain/google-gauth/node_modules/ansi-styles": {
- "version": "5.2.0",
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
- "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/chalk/ansi-styles?sponsor=1"
- }
- },
- "node_modules/@langchain/google-gauth/node_modules/uuid": {
- "version": "10.0.0",
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
- "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
- "funding": [
- "https://github.com/sponsors/broofa",
- "https://github.com/sponsors/ctavan"
- ],
"bin": {
"uuid": "dist/bin/uuid"
}
@@ -10051,14 +9953,11 @@
}
},
"node_modules/@langchain/google-vertexai": {
- "version": "0.1.0",
- "resolved": "https://registry.npmjs.org/@langchain/google-vertexai/-/google-vertexai-0.1.0.tgz",
- "integrity": "sha512-xTi5NvNGSLQl/7OTsj4QTT0DkNbZ7cYDrEB0HqpZOwo6I5dulh/h2payGVQ6hdXj7Yyv78dRc5FdQSbyHui/WQ==",
- "license": "MIT",
- "optional": true,
- "peer": true,
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/@langchain/google-vertexai/-/google-vertexai-0.1.2.tgz",
+ "integrity": "sha512-b8Di2AgSwlyyKl4A5qii+19Wj82I1KvtUXSDvJpDzhucuyrJjmnNb/0ClkaIQv6RyISajtxszxxSGHukPn3PJA==",
"dependencies": {
- "@langchain/google-gauth": "~0.1.0"
+ "@langchain/google-gauth": "~0.1.2"
},
"engines": {
"node": ">=18"
@@ -10068,12 +9967,9 @@
}
},
"node_modules/@langchain/google-vertexai/node_modules/@langchain/google-common": {
- "version": "0.1.1",
- "resolved": "https://registry.npmjs.org/@langchain/google-common/-/google-common-0.1.1.tgz",
- "integrity": "sha512-oT/6lBev/Ufkp1dJbOTJ2S7xD9c+w9CqnqKqFOSxuZJbM4G8hzJtt7PDBOGfamIwtQP8dR7ORKXs1sCl+f5Tig==",
- "license": "MIT",
- "optional": true,
- "peer": true,
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/@langchain/google-common/-/google-common-0.1.2.tgz",
+ "integrity": "sha512-3A7vUr2WObCFUusM/Wl0yZN7QGGXboXyparORkZdv0RnGngPm6tBmqbAyWYmT8R9aQNHqzBKDEQBiSRvTxao1w==",
"dependencies": {
"uuid": "^10.0.0",
"zod-to-json-schema": "^3.22.4"
@@ -10086,14 +9982,11 @@
}
},
"node_modules/@langchain/google-vertexai/node_modules/@langchain/google-gauth": {
- "version": "0.1.0",
- "resolved": "https://registry.npmjs.org/@langchain/google-gauth/-/google-gauth-0.1.0.tgz",
- "integrity": "sha512-0kps1NmaNiSl4n3lRw+7xsyhrEfIxNqBjih0kNYWPjLg55f9I9+QAlz7F1Sz/628HF1WQLFLQcBQA4geGzvenQ==",
- "license": "MIT",
- "optional": true,
- "peer": true,
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/@langchain/google-gauth/-/google-gauth-0.1.2.tgz",
+ "integrity": "sha512-5fPPaVcv4l2o/WdPuFLkIKFsfAeY8JD7zP/lFlTTeDvCbGbnsywwX08ZCqe9jgDIVBGcIoUqhiyBvwrpJMzMEw==",
"dependencies": {
- "@langchain/google-common": "~0.1.0",
+ "@langchain/google-common": "~0.1.2",
"google-auth-library": "^8.9.0"
},
"engines": {
@@ -10111,18 +10004,31 @@
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
- "license": "MIT",
- "optional": true,
- "peer": true,
"bin": {
"uuid": "dist/bin/uuid"
}
},
+ "node_modules/@langchain/langgraph": {
+ "version": "0.2.20",
+ "resolved": "https://registry.npmjs.org/@langchain/langgraph/-/langgraph-0.2.20.tgz",
+ "integrity": "sha512-MMD4G++gHs+5OO5Uu75gduskTboJ8Q7ZAwzd1s64a1Y/38pdgDqJdYRHRCGpx8eeCuKhsRzV2Sssnl5lujfj8w==",
+ "dependencies": {
+ "@langchain/langgraph-checkpoint": "~0.0.10",
+ "@langchain/langgraph-sdk": "~0.0.20",
+ "uuid": "^10.0.0",
+ "zod": "^3.23.8"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "peerDependencies": {
+ "@langchain/core": ">=0.2.36 <0.3.0 || >=0.3.9 < 0.4.0"
+ }
+ },
"node_modules/@langchain/langgraph-checkpoint": {
"version": "0.0.11",
"resolved": "https://registry.npmjs.org/@langchain/langgraph-checkpoint/-/langgraph-checkpoint-0.0.11.tgz",
"integrity": "sha512-nroHHkAi/UPn9LqqZcgOydfB8qZw5TXuXDFc43MIydnW4lb8m9hVHnQ3lgb2WGSgtbZJnsIx0TzL19oemJBRKg==",
- "license": "MIT",
"dependencies": {
"uuid": "^10.0.0"
},
@@ -10141,16 +10047,14 @@
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
- "license": "MIT",
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/@langchain/langgraph-sdk": {
- "version": "0.0.22",
- "resolved": "https://registry.npmjs.org/@langchain/langgraph-sdk/-/langgraph-sdk-0.0.22.tgz",
- "integrity": "sha512-+VWA4l6cgUEpxCZwW2aJLGpTYXTO1LYUjrv53Ru9i3ahEHrC7fu9BJL198WdDL6Pk+Qt2pyNkq/30HoKUKFTfQ==",
- "license": "MIT",
+ "version": "0.0.23",
+ "resolved": "https://registry.npmjs.org/@langchain/langgraph-sdk/-/langgraph-sdk-0.0.23.tgz",
+ "integrity": "sha512-4LfwMN1PdawJ9I3dXxQHUb1NoJaZo5SklQbAamrS6fLrUU9fSoYkPu1mYQp3uJjKtXRYOnuoP0egYyQPoKuiXQ==",
"dependencies": {
"@types/json-schema": "^7.0.15",
"p-queue": "^6.6.2",
@@ -10158,6 +10062,18 @@
"uuid": "^9.0.0"
}
},
+ "node_modules/@langchain/langgraph/node_modules/uuid": {
+ "version": "10.0.0",
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
+ "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
+ "funding": [
+ "https://github.com/sponsors/broofa",
+ "https://github.com/sponsors/ctavan"
+ ],
+ "bin": {
+ "uuid": "dist/bin/uuid"
+ }
+ },
"node_modules/@langchain/mistralai": {
"version": "0.0.26",
"resolved": "https://registry.npmjs.org/@langchain/mistralai/-/mistralai-0.0.26.tgz",
@@ -10268,9 +10184,11 @@
}
},
"node_modules/@langchain/openai": {
- "version": "0.3.13",
- "resolved": "https://registry.npmjs.org/@langchain/openai/-/openai-0.3.13.tgz",
- "integrity": "sha512-lfiauYttb1Vv1GVGDNZlse8475RUsKm9JJ7X9kMVtYoOQnK8xxzMVSrpW7HYLmJokrtVgF6STwRzNJI2gZ3uBw==",
+ "version": "0.3.14",
+ "resolved": "https://registry.npmjs.org/@langchain/openai/-/openai-0.3.14.tgz",
+ "integrity": "sha512-lNWjUo1tbvsss45IF7UQtMu1NJ6oUKvhgPYWXnX9f/d6OmuLu7D99HQ3Y88vLcUo9XjjOy417olYHignMduMjA==",
+ "optional": true,
+ "peer": true,
"dependencies": {
"js-tiktoken": "^1.0.12",
"openai": "^4.71.0",
@@ -10288,6 +10206,8 @@
"version": "18.19.64",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.64.tgz",
"integrity": "sha512-955mDqvO2vFf/oL7V3WiUtiz+BugyX8uVbaT2H8oj3+8dRyH2FLiNdowe7eNqRM7IOIZvzDH76EoAT+gwm6aIQ==",
+ "optional": true,
+ "peer": true,
"dependencies": {
"undici-types": "~5.26.4"
}
@@ -10296,6 +10216,8 @@
"version": "4.72.0",
"resolved": "https://registry.npmjs.org/openai/-/openai-4.72.0.tgz",
"integrity": "sha512-hFqG9BWCs7L7ifrhJXw7mJXmUBr7d9N6If3J9563o0jfwVA4wFANFDDaOIWFdgDdwgCXg5emf0Q+LoLCGszQYA==",
+ "optional": true,
+ "peer": true,
"dependencies": {
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.4",
@@ -36251,7 +36173,7 @@
},
"packages/data-provider": {
"name": "librechat-data-provider",
- "version": "0.7.56",
+ "version": "0.7.57",
"license": "ISC",
"dependencies": {
"@types/js-yaml": "^4.0.9",
diff --git a/packages/data-provider/package.json b/packages/data-provider/package.json
index 95fde7c0b0..6217a39b5c 100644
--- a/packages/data-provider/package.json
+++ b/packages/data-provider/package.json
@@ -1,6 +1,6 @@
{
"name": "librechat-data-provider",
- "version": "0.7.56",
+ "version": "0.7.57",
"description": "data services for librechat apps",
"main": "dist/index.js",
"module": "dist/index.es.js",
diff --git a/packages/data-provider/src/api-endpoints.ts b/packages/data-provider/src/api-endpoints.ts
index 0868d218e8..46b67f2d40 100644
--- a/packages/data-provider/src/api-endpoints.ts
+++ b/packages/data-provider/src/api-endpoints.ts
@@ -207,8 +207,8 @@ export const getAllPromptGroups = () => `${prompts()}/all`;
/* Roles */
export const roles = () => '/api/roles';
export const getRole = (roleName: string) => `${roles()}/${roleName.toLowerCase()}`;
-export const updatePromptPermissions = (roleName: string) =>
- `${roles()}/${roleName.toLowerCase()}/prompts`;
+export const updatePromptPermissions = (roleName: string) => `${getRole(roleName)}/prompts`;
+export const updateAgentPermissions = (roleName: string) => `${getRole(roleName)}/agents`;
/* Conversation Tags */
export const conversationTags = (tag?: string) =>
diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts
index 85dd7a3d72..ad809d49f5 100644
--- a/packages/data-provider/src/config.ts
+++ b/packages/data-provider/src/config.ts
@@ -140,6 +140,8 @@ export enum Capabilities {
}
export enum AgentCapabilities {
+ hide_sequential_outputs = 'hide_sequential_outputs',
+ end_after_tools = 'end_after_tools',
execute_code = 'execute_code',
file_search = 'file_search',
actions = 'actions',
@@ -475,6 +477,7 @@ export const configSchema = z.object({
bookmarks: z.boolean().optional(),
presets: z.boolean().optional(),
prompts: z.boolean().optional(),
+ agents: z.boolean().optional(),
})
.default({
endpointsMenu: true,
@@ -485,6 +488,7 @@ export const configSchema = z.object({
multiConvo: true,
bookmarks: true,
prompts: true,
+ agents: true,
}),
fileStrategy: fileSourceSchema.default(FileSources.local),
registration: z
@@ -932,6 +936,10 @@ export enum ViolationTypes {
* Verify Conversation Access violation.
*/
CONVO_ACCESS = 'convo_access',
+ /**
+ * Tool Call Limit Violation.
+ */
+ TOOL_CALL_LIMIT = 'tool_call_limit',
}
/**
@@ -1086,6 +1094,8 @@ export enum Constants {
NO_PARENT = '00000000-0000-0000-0000-000000000000',
/** Standard value for the initial conversationId before a request is sent */
NEW_CONVO = 'new',
+ /** Standard value for the conversationId used for search queries */
+ SEARCH = 'search',
/** Fixed, encoded domain length for Azure OpenAI Assistants Function name parsing. */
ENCODED_DOMAIN_LENGTH = 10,
/** Identifier for using current_model in multi-model requests. */
diff --git a/packages/data-provider/src/data-service.ts b/packages/data-provider/src/data-service.ts
index 1a6cdae199..d0c6a80818 100644
--- a/packages/data-provider/src/data-service.ts
+++ b/packages/data-provider/src/data-service.ts
@@ -314,6 +314,30 @@ export const getVerifyAgentToolAuth = (
);
};
+export const callTool = <T extends m.ToolId>({
+ toolId,
+ toolParams,
+}: {
+ toolId: T;
+ toolParams: m.ToolParams<T>;
+}): Promise<m.ToolCallResponse> => {
+ return request.post(
+ endpoints.agents({
+ path: `tools/${toolId}/call`,
+ }),
+ toolParams,
+ );
+};
+
+export const getToolCalls = (params: q.GetToolCallParams): Promise<q.ToolCallResults> => {
+ return request.get(
+ endpoints.agents({
+ path: 'tools/calls',
+ options: params,
+ }),
+ );
+};
+
/* Files */
export const getFiles = (): Promise<f.TFile[]> => {
@@ -669,10 +693,16 @@ export function getRole(roleName: string): Promise<r.TRole> {
export function updatePromptPermissions(
variables: m.UpdatePromptPermVars,
-): Promise<m.UpdatePromptPermResponse> {
+): Promise<m.UpdatePermResponse> {
return request.put(endpoints.updatePromptPermissions(variables.roleName), variables.updates);
}
+export function updateAgentPermissions(
+ variables: m.UpdateAgentPermVars,
+): Promise<m.UpdatePermResponse> {
+ return request.put(endpoints.updateAgentPermissions(variables.roleName), variables.updates);
+}
+
/* Tags */
export function getConversationTags(): Promise<t.TConversationTagsResponse> {
return request.get(endpoints.conversationTags());
diff --git a/packages/data-provider/src/index.ts b/packages/data-provider/src/index.ts
index 59e0d60b71..c42857bd93 100644
--- a/packages/data-provider/src/index.ts
+++ b/packages/data-provider/src/index.ts
@@ -7,6 +7,7 @@ export * from './file-config';
export * from './artifacts';
/* schema helpers */
export * from './parsers';
+export * from './zod';
/* custom/dynamic configurations */
export * from './generate';
export * from './models';
diff --git a/packages/data-provider/src/keys.ts b/packages/data-provider/src/keys.ts
index b977853974..12ee8b3681 100644
--- a/packages/data-provider/src/keys.ts
+++ b/packages/data-provider/src/keys.ts
@@ -26,6 +26,7 @@ export enum QueryKeys {
fileConfig = 'fileConfig',
tools = 'tools',
toolAuth = 'toolAuth',
+ toolCalls = 'toolCalls',
agentTools = 'agentTools',
actions = 'actions',
assistantDocs = 'assistantDocs',
diff --git a/packages/data-provider/src/schemas.ts b/packages/data-provider/src/schemas.ts
index dd23b9aa77..3aaf37d81c 100644
--- a/packages/data-provider/src/schemas.ts
+++ b/packages/data-provider/src/schemas.ts
@@ -1096,13 +1096,14 @@ export type TBanner = z.infer<typeof tBannerSchema>;
export const compactAgentsSchema = tConversationSchema
.pick({
- model: true,
+ spec: true,
+ // model: true,
+ iconURL: true,
+ greeting: true,
agent_id: true,
+ resendFiles: true,
instructions: true,
additional_instructions: true,
- iconURL: true,
- greeting: true,
- spec: true,
})
.transform(removeNullishValues)
.catch(() => ({}));
diff --git a/packages/data-provider/src/types/agents.ts b/packages/data-provider/src/types/agents.ts
index d66fa63b9e..9ab57607d4 100644
--- a/packages/data-provider/src/types/agents.ts
+++ b/packages/data-provider/src/types/agents.ts
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-namespace */
import { StepTypes, ContentTypes, ToolCallTypes } from './runs';
import type { FunctionToolCall } from './assistants';
+import type { TAttachment } from 'src/schemas';
export namespace Agents {
export type MessageType = 'human' | 'ai' | 'generic' | 'system' | 'function' | 'tool' | 'remove';
@@ -218,3 +219,14 @@ export namespace Agents {
}
export type ContentType = ContentTypes.TEXT | ContentTypes.IMAGE_URL | string;
}
+
+export type ToolCallResult = {
+ user: string;
+ toolId: string;
+ result?: unknown;
+ messageId: string;
+ partIndex?: number;
+ blockIndex?: number;
+ conversationId: string;
+ attachments?: TAttachment[];
+};
diff --git a/packages/data-provider/src/types/assistants.ts b/packages/data-provider/src/types/assistants.ts
index 6e21c0b5b2..6a59fc7c7f 100644
--- a/packages/data-provider/src/types/assistants.ts
+++ b/packages/data-provider/src/types/assistants.ts
@@ -147,6 +147,7 @@ export type File = {
export type AgentParameterValue = number | null;
export type AgentModelParameters = {
+ model?: string;
temperature: AgentParameterValue;
max_context_tokens: AgentParameterValue;
max_output_tokens: AgentParameterValue;
@@ -165,6 +166,10 @@ export interface ExecuteCodeResource {
* There can be a maximum of 20 files associated with the tool.
*/
file_ids?: Array<string>;
+ /**
+ * A list of files already fetched.
+ */
+ files?: Array<TFile>;
}
export interface AgentFileSearchResource {
@@ -178,6 +183,10 @@ export interface AgentFileSearchResource {
* To be used before vector stores are implemented.
*/
file_ids?: Array<string>;
+ /**
+ * A list of files already fetched.
+ */
+ files?: Array<TFile>;
}
export type Agent = {
@@ -201,6 +210,9 @@ export type Agent = {
conversation_starters?: string[];
isCollaborative?: boolean;
tool_resources?: AgentToolResources;
+ agent_ids?: string[];
+ end_after_tools?: boolean;
+ hide_sequential_outputs?: boolean;
};
export type TAgentsMap = Record<string, Agent | undefined>;
@@ -215,7 +227,7 @@ export type AgentCreateParams = {
provider: AgentProvider;
model: string | null;
model_parameters: AgentModelParameters;
-};
+} & Pick<Agent, 'agent_ids' | 'end_after_tools' | 'hide_sequential_outputs'>;
export type AgentUpdateParams = {
name?: string | null;
@@ -231,7 +243,7 @@ export type AgentUpdateParams = {
projectIds?: string[];
removeProjectIds?: string[];
isCollaborative?: boolean;
-};
+} & Pick<Agent, 'agent_ids' | 'end_after_tools' | 'hide_sequential_outputs'>;
export type AgentListParams = {
limit?: number;
diff --git a/packages/data-provider/src/types/mutations.ts b/packages/data-provider/src/types/mutations.ts
index 8d4aed2501..f5d867d725 100644
--- a/packages/data-provider/src/types/mutations.ts
+++ b/packages/data-provider/src/types/mutations.ts
@@ -1,6 +1,7 @@
import * as types from '../types';
import * as r from '../roles';
import {
+ Tools,
Assistant,
AssistantCreateParams,
AssistantUpdateParams,
@@ -222,18 +223,29 @@ export type RegistrationOptions = MutationOptions<
types.TError
>;
-export type UpdatePromptPermVars = {
+export type UpdatePermVars<T> = {
roleName: string;
- updates: Partial<r.TPromptPermissions>;
+ updates: Partial<T>;
};
-export type UpdatePromptPermResponse = r.TRole;
+export type UpdatePromptPermVars = UpdatePermVars<r.TPromptPermissions>;
+
+export type UpdateAgentPermVars = UpdatePermVars<r.TAgentPermissions>;
+
+export type UpdatePermResponse = r.TRole;
export type UpdatePromptPermOptions = MutationOptions<
- UpdatePromptPermResponse,
+ UpdatePermResponse,
UpdatePromptPermVars,
unknown,
- types.TError
+ types.TError | null | undefined
+>;
+
+export type UpdateAgentPermOptions = MutationOptions<
+ UpdatePermResponse,
+ UpdateAgentPermVars,
+ unknown,
+ types.TError | null | undefined
>;
export type UpdateConversationTagOptions = MutationOptions<
@@ -251,3 +263,24 @@ export type AcceptTermsMutationOptions = MutationOptions<
/* Tools */
export type UpdatePluginAuthOptions = MutationOptions<types.TUser, types.TUpdateUserPlugins>;
+
+export type ToolParamsMap = {
+ [Tools.execute_code]: {
+ lang: string;
+ code: string;
+ };
+};
+
+export type ToolId = keyof ToolParamsMap;
+
+export type ToolParams<T extends ToolId> = ToolParamsMap[T] & {
+ messageId: string;
+ partIndex?: number;
+ blockIndex?: number;
+ conversationId: string;
+};
+export type ToolCallResponse = { result: unknown; attachments?: types.TAttachment[] };
+export type ToolCallMutationOptions<T extends ToolId> = MutationOptions<
+ ToolCallResponse,
+ ToolParams<T>
+>;
diff --git a/packages/data-provider/src/types/queries.ts b/packages/data-provider/src/types/queries.ts
index 7aeaa6eb20..74d6e71835 100644
--- a/packages/data-provider/src/types/queries.ts
+++ b/packages/data-provider/src/types/queries.ts
@@ -1,4 +1,5 @@
import type { InfiniteData } from '@tanstack/react-query';
+import type * as a from '../types/agents';
import type * as s from '../schemas';
import type * as t from '../types';
@@ -75,3 +76,6 @@ export type ConversationTagsResponse = s.TConversationTag[];
export type VerifyToolAuthParams = { toolId: string };
export type VerifyToolAuthResponse = { authenticated: boolean; message?: string | s.AuthType };
+
+export type GetToolCallParams = { conversationId: string };
+export type ToolCallResults = a.ToolCallResult[];
diff --git a/packages/data-provider/src/zod.spec.ts b/packages/data-provider/src/zod.spec.ts
new file mode 100644
index 0000000000..37915649bc
--- /dev/null
+++ b/packages/data-provider/src/zod.spec.ts
@@ -0,0 +1,467 @@
+/* eslint-disable jest/no-conditional-expect */
+/* eslint-disable @typescript-eslint/no-explicit-any */
+// zod.spec.ts
+import { z } from 'zod';
+import { convertJsonSchemaToZod } from './zod';
+import type { JsonSchemaType } from './zod';
+
+describe('convertJsonSchemaToZod', () => {
+ describe('primitive types', () => {
+ it('should convert string schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'string',
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse('test')).toBe('test');
+ expect(() => zodSchema.parse(123)).toThrow();
+ });
+
+ it('should convert string enum schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'string',
+ enum: ['foo', 'bar', 'baz'],
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse('foo')).toBe('foo');
+ expect(() => zodSchema.parse('invalid')).toThrow();
+ });
+
+ it('should convert number schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'number',
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse(123)).toBe(123);
+ expect(() => zodSchema.parse('123')).toThrow();
+ });
+
+ it('should convert boolean schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'boolean',
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse(true)).toBe(true);
+ expect(() => zodSchema.parse('true')).toThrow();
+ });
+ });
+
+ describe('array types', () => {
+ it('should convert array of strings schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'array',
+ items: { type: 'string' },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse(['a', 'b', 'c'])).toEqual(['a', 'b', 'c']);
+ expect(() => zodSchema.parse(['a', 123, 'c'])).toThrow();
+ });
+
+ it('should convert array of numbers schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'array',
+ items: { type: 'number' },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse([1, 2, 3])).toEqual([1, 2, 3]);
+ expect(() => zodSchema.parse([1, '2', 3])).toThrow();
+ });
+ });
+
+ describe('object types', () => {
+ it('should convert simple object schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {
+ name: { type: 'string' },
+ age: { type: 'number' },
+ },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse({ name: 'John', age: 30 })).toEqual({ name: 'John', age: 30 });
+ expect(() => zodSchema.parse({ name: 123, age: 30 })).toThrow();
+ });
+
+ it('should handle required fields', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {
+ name: { type: 'string' },
+ age: { type: 'number' },
+ },
+ required: ['name'],
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });
+ expect(() => zodSchema.parse({})).toThrow();
+ });
+
+ it('should handle nested objects', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {
+ user: {
+ type: 'object',
+ properties: {
+ name: { type: 'string' },
+ age: { type: 'number' },
+ },
+ required: ['name'],
+ },
+ },
+ required: ['user'],
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse({ user: { name: 'John', age: 30 } })).toEqual({
+ user: { name: 'John', age: 30 },
+ });
+ expect(() => zodSchema.parse({ user: { age: 30 } })).toThrow();
+ });
+
+ it('should handle objects with arrays', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {
+ names: {
+ type: 'array',
+ items: { type: 'string' },
+ },
+ },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse({ names: ['John', 'Jane'] })).toEqual({ names: ['John', 'Jane'] });
+ expect(() => zodSchema.parse({ names: ['John', 123] })).toThrow();
+ });
+ });
+
+ describe('edge cases', () => {
+ it('should handle empty object schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {},
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse({})).toEqual({});
+ });
+
+ it('should handle unknown types as unknown', () => {
+ const schema = {
+ type: 'invalid',
+ } as unknown as JsonSchemaType;
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse('anything')).toBe('anything');
+ expect(zodSchema.parse(123)).toBe(123);
+ });
+
+ it('should handle empty enum arrays as regular strings', () => {
+ const schema: JsonSchemaType = {
+ type: 'string',
+ enum: [],
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ expect(zodSchema.parse('test')).toBe('test');
+ });
+ });
+
+ describe('complex schemas', () => {
+ it('should handle complex nested schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {
+ id: { type: 'number' },
+ user: {
+ type: 'object',
+ properties: {
+ name: { type: 'string' },
+ roles: {
+ type: 'array',
+ items: {
+ type: 'object',
+ properties: {
+ name: { type: 'string' },
+ permissions: {
+ type: 'array',
+ items: {
+ type: 'string',
+ enum: ['read', 'write', 'admin'],
+ },
+ },
+ },
+ required: ['name', 'permissions'],
+ },
+ },
+ },
+ required: ['name', 'roles'],
+ },
+ },
+ required: ['id', 'user'],
+ };
+
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ const validData = {
+ id: 1,
+ user: {
+ name: 'John',
+ roles: [
+ {
+ name: 'moderator',
+ permissions: ['read', 'write'],
+ },
+ ],
+ },
+ };
+
+ expect(zodSchema.parse(validData)).toEqual(validData);
+ expect(() =>
+ zodSchema.parse({
+ id: 1,
+ user: {
+ name: 'John',
+ roles: [
+ {
+ name: 'moderator',
+ permissions: ['invalid'],
+ },
+ ],
+ },
+ }),
+ ).toThrow();
+ });
+ });
+
+ // zod.spec.ts
+ describe('schema descriptions', () => {
+ it('should preserve top-level description', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ description: 'A test schema description',
+ properties: {
+ name: { type: 'string' },
+ },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+ expect(zodSchema.description).toBe('A test schema description');
+ });
+
+ it('should preserve field descriptions', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {
+ name: {
+ type: 'string',
+ description: 'The user\'s name',
+ },
+ age: {
+ type: 'number',
+ description: 'The user\'s age',
+ },
+ },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ const shape = (zodSchema as z.ZodObject<any>).shape;
+ expect(shape.name.description).toBe('The user\'s name');
+ expect(shape.age.description).toBe('The user\'s age');
+ });
+
+ it('should preserve descriptions in nested objects', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ description: 'User record',
+ properties: {
+ user: {
+ type: 'object',
+ description: 'User details',
+ properties: {
+ name: {
+ type: 'string',
+ description: 'The user\'s name',
+ },
+ settings: {
+ type: 'object',
+ description: 'User preferences',
+ properties: {
+ theme: {
+ type: 'string',
+ description: 'UI theme preference',
+ enum: ['light', 'dark'],
+ },
+ },
+ },
+ },
+ },
+ },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ // Type assertions for better type safety
+ const shape = zodSchema instanceof z.ZodObject ? zodSchema.shape : {};
+ expect(zodSchema.description).toBe('User record');
+
+ if ('user' in shape) {
+ expect(shape.user.description).toBe('User details');
+
+ const userShape = shape.user instanceof z.ZodObject ? shape.user.shape : {};
+ if ('name' in userShape && 'settings' in userShape) {
+ expect(userShape.name.description).toBe('The user\'s name');
+ expect(userShape.settings.description).toBe('User preferences');
+
+ const settingsShape =
+ userShape.settings instanceof z.ZodObject ? userShape.settings.shape : {};
+ if ('theme' in settingsShape) {
+ expect(settingsShape.theme.description).toBe('UI theme preference');
+ }
+ }
+ }
+ });
+
+ it('should preserve descriptions in arrays', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {
+ tags: {
+ type: 'array',
+ description: 'User tags',
+ items: {
+ type: 'string',
+ description: 'Individual tag',
+ },
+ },
+ scores: {
+ type: 'array',
+ description: 'Test scores',
+ items: {
+ type: 'number',
+ description: 'Individual score',
+ },
+ },
+ },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ const shape = (zodSchema as z.ZodObject<any>).shape;
+ expect(shape.tags.description).toBe('User tags');
+ expect(shape.scores.description).toBe('Test scores');
+ });
+
+ it('should preserve descriptions in enums', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ properties: {
+ role: {
+ type: 'string',
+ description: 'User role in the system',
+ enum: ['admin', 'user', 'guest'],
+ },
+ status: {
+ type: 'string',
+ description: 'Account status',
+ enum: ['active', 'suspended', 'deleted'],
+ },
+ },
+ };
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ const shape = (zodSchema as z.ZodObject<any>).shape;
+ expect(shape.role.description).toBe('User role in the system');
+ expect(shape.status.description).toBe('Account status');
+ });
+
+ it('should preserve descriptions in a complex schema', () => {
+ const schema: JsonSchemaType = {
+ type: 'object',
+ description: 'User profile configuration',
+ properties: {
+ basicInfo: {
+ type: 'object',
+ description: 'Basic user information',
+ properties: {
+ name: {
+ type: 'string',
+ description: 'Full name of the user',
+ },
+ age: {
+ type: 'number',
+ description: 'User age in years',
+ },
+ },
+ required: ['name'],
+ },
+ preferences: {
+ type: 'object',
+ description: 'User preferences',
+ properties: {
+ notifications: {
+ type: 'array',
+ description: 'Notification settings',
+ items: {
+ type: 'object',
+ description: 'Individual notification preference',
+ properties: {
+ type: {
+ type: 'string',
+ description: 'Type of notification',
+ enum: ['email', 'sms', 'push'],
+ },
+ enabled: {
+ type: 'boolean',
+ description: 'Whether this notification is enabled',
+ },
+ },
+ },
+ },
+ theme: {
+ type: 'string',
+ description: 'UI theme preference',
+ enum: ['light', 'dark', 'system'],
+ },
+ },
+ },
+ },
+ };
+
+ const zodSchema = convertJsonSchemaToZod(schema);
+
+ // Test top-level description
+ expect(zodSchema.description).toBe('User profile configuration');
+
+ const shape = zodSchema instanceof z.ZodObject ? zodSchema.shape : {};
+
+ // Test basic info descriptions
+ if ('basicInfo' in shape) {
+ expect(shape.basicInfo.description).toBe('Basic user information');
+ const basicInfoShape = shape.basicInfo instanceof z.ZodObject ? shape.basicInfo.shape : {};
+
+ if ('name' in basicInfoShape && 'age' in basicInfoShape) {
+ expect(basicInfoShape.name.description).toBe('Full name of the user');
+ expect(basicInfoShape.age.description).toBe('User age in years');
+ }
+ }
+
+ // Test preferences descriptions
+ if ('preferences' in shape) {
+ expect(shape.preferences.description).toBe('User preferences');
+ const preferencesShape =
+ shape.preferences instanceof z.ZodObject ? shape.preferences.shape : {};
+
+ if ('notifications' in preferencesShape && 'theme' in preferencesShape) {
+ expect(preferencesShape.notifications.description).toBe('Notification settings');
+ expect(preferencesShape.theme.description).toBe('UI theme preference');
+ }
+ }
+ });
+ });
+});
diff --git a/packages/data-provider/src/zod.ts b/packages/data-provider/src/zod.ts
new file mode 100644
index 0000000000..455bc579d5
--- /dev/null
+++ b/packages/data-provider/src/zod.ts
@@ -0,0 +1,66 @@
+import { z } from 'zod';
+
+export type JsonSchemaType = {
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object';
+ enum?: string[];
+ items?: JsonSchemaType;
+ properties?: Record<string, JsonSchemaType>;
+ required?: string[];
+ description?: string;
+};
+
+export function convertJsonSchemaToZod(schema: JsonSchemaType): z.ZodType {
+ let zodSchema: z.ZodType;
+
+ // Handle primitive types
+ if (schema.type === 'string') {
+ if (Array.isArray(schema.enum) && schema.enum.length > 0) {
+ const [first, ...rest] = schema.enum;
+ zodSchema = z.enum([first, ...rest] as [string, ...string[]]);
+ } else {
+ zodSchema = z.string();
+ }
+ } else if (schema.type === 'number') {
+ zodSchema = z.number();
+ } else if (schema.type === 'boolean') {
+ zodSchema = z.boolean();
+ } else if (schema.type === 'array' && schema.items !== undefined) {
+ const itemSchema = convertJsonSchemaToZod(schema.items);
+ zodSchema = z.array(itemSchema);
+ } else if (schema.type === 'object') {
+ const shape: Record<string, z.ZodType> = {};
+ const properties = schema.properties ?? {};
+
+ for (const [key, value] of Object.entries(properties)) {
+ let fieldSchema = convertJsonSchemaToZod(value);
+ if (value.description != null && value.description !== '') {
+ fieldSchema = fieldSchema.describe(value.description);
+ }
+ shape[key] = fieldSchema;
+ }
+
+ let objectSchema = z.object(shape);
+
+ if (Array.isArray(schema.required) && schema.required.length > 0) {
+ const partial = Object.fromEntries(
+ Object.entries(shape).map(([key, value]) => [
+ key,
+ schema.required?.includes(key) === true ? value : value.optional(),
+ ]),
+ );
+ objectSchema = z.object(partial);
+ } else {
+ objectSchema = objectSchema.partial();
+ }
+ zodSchema = objectSchema;
+ } else {
+ zodSchema = z.unknown();
+ }
+
+ // Add description if present
+ if (schema.description != null && schema.description !== '') {
+ zodSchema = zodSchema.describe(schema.description);
+ }
+
+ return zodSchema;
+}