@librechat/agents 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/enum.cjs +2 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +33 -22
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/esm/common/enum.mjs +2 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +33 -22
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/types/common/enum.d.ts +3 -1
- package/package.json +3 -3
- package/src/common/enum.ts +2 -0
- package/src/tools/CodeExecutor.ts +36 -22
package/dist/cjs/common/enum.cjs
CHANGED
|
@@ -125,6 +125,8 @@ exports.Callback = void 0;
|
|
|
125
125
|
exports.Constants = void 0;
|
|
126
126
|
(function (Constants) {
|
|
127
127
|
Constants["OFFICIAL_CODE_BASEURL"] = "https://api.librechat.ai/v1";
|
|
128
|
+
Constants["EXECUTE_CODE"] = "execute_code";
|
|
129
|
+
Constants["CONTENT_AND_ARTIFACT"] = "content_and_artifact";
|
|
128
130
|
})(exports.Constants || (exports.Constants = {}));
|
|
129
131
|
exports.EnvVar = void 0;
|
|
130
132
|
(function (EnvVar) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.cjs","sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end'\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n BEDROCK_LEGACY = 'bedrock_legacy',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools',\n AGENT = 'agent',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation'\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n TOOL_CALL = 'tool_call',\n IMAGE_FILE = 'image_file',\n IMAGE_URL = 'image_url',\n ERROR = 'error',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n CUSTOM_EVENT = 'handleCustomEvent'\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.librechat.ai/v1',\n}\n\nexport enum EnvVar {\n CODE_API_KEY = 'LIBRECHAT_CODE_API_KEY',\n CODE_BASEURL = 'LIBRECHAT_CODE_BASEURL'\n}\n"],"names":["GraphEvents","Providers","GraphNodeKeys","GraphNodeActions","CommonEvents","StepTypes","ContentTypes","ToolCallTypes","Callback","Constants","EnvVar"],"mappings":";;AAAA;;;;;AAKG;AACSA,6BA4DX;AA5DD,CAAA,UAAY,WAAW,EAAA;;;AAIrB,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;;AA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;;;AAgBE;AACJ,CAAC,EArBWA,gBAAQ,KAARA,gBAAQ,GAqBnB,EAAA,CAAA,CAAA,CAAA;AAEWC,
|
|
1
|
+
{"version":3,"file":"enum.cjs","sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end'\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n BEDROCK_LEGACY = 'bedrock_legacy',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools',\n AGENT = 'agent',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation'\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n TOOL_CALL = 'tool_call',\n IMAGE_FILE = 'image_file',\n IMAGE_URL = 'image_url',\n ERROR = 'error',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n CUSTOM_EVENT = 'handleCustomEvent'\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.librechat.ai/v1',\n EXECUTE_CODE = 'execute_code',\n CONTENT_AND_ARTIFACT = 'content_and_artifact',\n}\n\nexport enum EnvVar {\n CODE_API_KEY = 'LIBRECHAT_CODE_API_KEY',\n CODE_BASEURL = 'LIBRECHAT_CODE_BASEURL'\n}\n"],"names":["GraphEvents","Providers","GraphNodeKeys","GraphNodeActions","CommonEvents","StepTypes","ContentTypes","ToolCallTypes","Callback","Constants","EnvVar"],"mappings":";;AAAA;;;;;AAKG;AACSA,6BA4DX;AA5DD,CAAA,UAAY,WAAW,EAAA;;;AAIrB,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;;AAE3B,IAAA,WAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC,CAAA;;AAEvC,IAAA,WAAA,CAAA,uBAAA,CAAA,GAAA,uBAA+C,CAAA;;AAE/C,IAAA,WAAA,CAAA,kBAAA,CAAA,GAAA,kBAAqC,CAAA;;;AAKrC,IAAA,WAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;;AAEnC,IAAA,WAAA,CAAA,kBAAA,CAAA,GAAA,qBAAwC,CAAA;;AAGxC,IAAA,WAAA,CAAA,mBAAA,CAAA,GAAA,sBAA0C,CAAA;;AAG1C,IAAA,WAAA,CAAA,gBAAA,CAAA,GAAA,mBAAoC,CAAA;;AAGpC,IAAA,WAAA,CAAA,WAAA,CAAA,GAAA,cAA0B,CAAA;;AAG1B,IAAA,WAAA,CAAA,YAAA,CAAA,GAAA,eAA4B,CAAA;;AAG5B,IAAA,WAAA,CAAA,SAAA,CAAA,GAAA,YAAsB,CAAA;;AAGtB,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,gBAA8B,CAAA;;AAG9B,IAAA,WAAA,CAAA,cAAA,CAAA,GAAA,i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the code in.'),
|
|
29
29
|
code: zod.z.string()
|
|
30
|
-
.describe(
|
|
30
|
+
.describe(`The complete, self-contained code to execute, without any truncation or minimization.
|
|
31
|
+
- The environment is stateless; variables and imports don't persist between executions.
|
|
32
|
+
- Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.
|
|
33
|
+
- Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.
|
|
34
|
+
- py: This is not a Jupyter notebook environment. Use \`print()\` for all outputs.
|
|
35
|
+
- py: Matplotlib: Use \`plt.savefig()\` to save plots as files.
|
|
36
|
+
- js: use the \`console\` or \`process\` methods for all outputs.
|
|
37
|
+
- Other languages: use appropriate output functions.`),
|
|
31
38
|
args: zod.z.array(zod.z.string()).optional()
|
|
32
|
-
.describe('Additional arguments to execute the code with.'),
|
|
39
|
+
.describe('Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.'),
|
|
33
40
|
});
|
|
34
41
|
const EXEC_ENDPOINT = `${getCodeBaseURL()}/exec`;
|
|
35
42
|
function createCodeExecutionTool(params = {}) {
|
|
@@ -37,6 +44,25 @@ function createCodeExecutionTool(params = {}) {
|
|
|
37
44
|
if (!apiKey) {
|
|
38
45
|
throw new Error('No API key provided for code execution tool.');
|
|
39
46
|
}
|
|
47
|
+
let fileInstructions = '';
|
|
48
|
+
if (params.files && params.files.length > 0) {
|
|
49
|
+
fileInstructions = 'Available files:\n';
|
|
50
|
+
params.files.forEach((file) => {
|
|
51
|
+
const filePath = `/mnt/data/${file.name}`;
|
|
52
|
+
fileInstructions += `- ${filePath}\n`;
|
|
53
|
+
});
|
|
54
|
+
fileInstructions += '\nUse these files in your code as needed.\n';
|
|
55
|
+
}
|
|
56
|
+
const description = `
|
|
57
|
+
Runs code and returns stdout/stderr output from a stateless execution environment, similar to running scripts in a command-line interface. Each execution is isolated and independent.
|
|
58
|
+
|
|
59
|
+
Usage:
|
|
60
|
+
- No network access available.
|
|
61
|
+
- Generated files are automatically delivered; **DO NOT** provide download links.
|
|
62
|
+
- NEVER use this tool to execute malicious code.
|
|
63
|
+
|
|
64
|
+
${fileInstructions}
|
|
65
|
+
`.trim();
|
|
40
66
|
return tools.tool(async ({ lang, code, ...rest }) => {
|
|
41
67
|
const postData = {
|
|
42
68
|
lang,
|
|
@@ -63,7 +89,7 @@ function createCodeExecutionTool(params = {}) {
|
|
|
63
89
|
formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
64
90
|
}
|
|
65
91
|
else {
|
|
66
|
-
formattedOutput += 'stdout: Empty.
|
|
92
|
+
formattedOutput += 'stdout: Empty. Ensure you\'re writing output explicitly.\n';
|
|
67
93
|
}
|
|
68
94
|
if (result.stderr)
|
|
69
95
|
formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
@@ -86,28 +112,13 @@ function createCodeExecutionTool(params = {}) {
|
|
|
86
112
|
return [formattedOutput.trim(), { session_id: result.session_id }];
|
|
87
113
|
}
|
|
88
114
|
catch (error) {
|
|
89
|
-
return `
|
|
90
|
-
lang,
|
|
91
|
-
code,
|
|
92
|
-
...rest,
|
|
93
|
-
})}\n\nraised the following error:\n\n${error?.message}`;
|
|
115
|
+
return `Execution error:\n\n${error?.message}`;
|
|
94
116
|
}
|
|
95
117
|
}, {
|
|
96
|
-
name:
|
|
97
|
-
description
|
|
98
|
-
|
|
99
|
-
# Usage
|
|
100
|
-
- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
|
|
101
|
-
- All desired output must be explicitly written to stdout; e.g.:
|
|
102
|
-
- For \`py\`, use the \`print()\` function.
|
|
103
|
-
- For \`js\` and \`ts\`, use the \`console\` or \`process\` methods.
|
|
104
|
-
- For other languages, use the appropriate output functions.
|
|
105
|
-
- There is no network access.
|
|
106
|
-
- NEVER provide a link to download any generated files.
|
|
107
|
-
- Files are automatically delivered to the user.
|
|
108
|
-
- NEVER use this tool to execute malicious code.`,
|
|
118
|
+
name: _enum.Constants.EXECUTE_CODE,
|
|
119
|
+
description,
|
|
109
120
|
schema: CodeExecutionToolSchema,
|
|
110
|
-
responseFormat:
|
|
121
|
+
responseFormat: _enum.Constants.CONTENT_AND_ARTIFACT,
|
|
111
122
|
});
|
|
112
123
|
}
|
|
113
124
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.cjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { z } from 'zod';\nimport { config } from 'dotenv';\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\nimport { getEnvironmentVariable } from '@langchain/core/utils/env';\nimport type * as t from '@/types';\nimport { EnvVar, Constants } from '@/common';\n\nconfig();\n\nexport const imageExtRegex = /\\.(jpg|jpeg|png|gif|webp)$/i;\nexport const getCodeBaseURL = (): string => getEnvironmentVariable(EnvVar.CODE_BASEURL) ?? Constants.OFFICIAL_CODE_BASEURL;\n\nconst imageMessage = ' - the image is already displayed to the user';\nconst otherMessage = ' - the file is already downloaded by the user';\n\nconst CodeExecutionToolSchema = z.object({\n lang: z.enum([\n 'py',\n 'js',\n 'ts',\n 'c',\n 'cpp',\n 'java',\n 'php',\n 'rs',\n 'go',\n 'd',\n 'f90',\n ])\n .describe('The programming language or runtime to execute the code in.'),\n code: z.string()\n .describe(
|
|
1
|
+
{"version":3,"file":"CodeExecutor.cjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { z } from 'zod';\nimport { config } from 'dotenv';\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\nimport { getEnvironmentVariable } from '@langchain/core/utils/env';\nimport type * as t from '@/types';\nimport { EnvVar, Constants } from '@/common';\n\nconfig();\n\nexport const imageExtRegex = /\\.(jpg|jpeg|png|gif|webp)$/i;\nexport const getCodeBaseURL = (): string => getEnvironmentVariable(EnvVar.CODE_BASEURL) ?? Constants.OFFICIAL_CODE_BASEURL;\n\nconst imageMessage = ' - the image is already displayed to the user';\nconst otherMessage = ' - the file is already downloaded by the user';\n\nconst CodeExecutionToolSchema = z.object({\n lang: z.enum([\n 'py',\n 'js',\n 'ts',\n 'c',\n 'cpp',\n 'java',\n 'php',\n 'rs',\n 'go',\n 'd',\n 'f90',\n ])\n .describe('The programming language or runtime to execute the code in.'),\n code: z.string()\n .describe(`The complete, self-contained code to execute, without any truncation or minimization.\n- The environment is stateless; variables and imports don't persist between executions.\n- Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.\n- Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.\n- py: This is not a Jupyter notebook environment. Use \\`print()\\` for all outputs.\n- py: Matplotlib: Use \\`plt.savefig()\\` to save plots as files.\n- js: use the \\`console\\` or \\`process\\` methods for all outputs.\n- Other languages: use appropriate output functions.`),\n args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.'),\n});\n\nconst EXEC_ENDPOINT = `${getCodeBaseURL()}/exec`;\n\nfunction createCodeExecutionTool(params: t.CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\n const apiKey = params[EnvVar.CODE_API_KEY] ?? params.apiKey ?? getEnvironmentVariable(EnvVar.CODE_API_KEY) ?? '';\n if (!apiKey) {\n throw new Error('No API key provided for code execution tool.');\n }\n\n let fileInstructions = '';\n if (params.files && params.files.length > 0) {\n fileInstructions = 'Available files:\\n';\n params.files.forEach((file) => {\n const filePath = `/mnt/data/${file.name}`;\n fileInstructions += `- ${filePath}\\n`;\n });\n fileInstructions += '\\nUse these files in your code as needed.\\n';\n }\n\n const description = `\nRuns code and returns stdout/stderr output from a stateless execution environment, similar to running scripts in a command-line interface. Each execution is isolated and independent.\n\nUsage:\n- No network access available.\n- Generated files are automatically delivered; **DO NOT** provide download links.\n- NEVER use this tool to execute malicious code.\n\n${fileInstructions}\n`.trim();\n\n return tool<typeof CodeExecutionToolSchema>(\n async ({ lang, code, ...rest }) => {\n const postData = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n try {\n const response = await fetch(EXEC_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n body: JSON.stringify(postData),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const result: t.ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) {\n formattedOutput += `stdout:\\n${result.stdout}\\n`;\n } else {\n formattedOutput += 'stdout: Empty. Ensure you\\'re writing output explicitly.\\n';\n }\n if (result.stderr) formattedOutput += `stderr:\\n${result.stderr}\\n`;\n if (result.files && result.files.length > 0) {\n formattedOutput += 'Generated files:\\n';\n\n const fileCount = result.files.length;\n for (let i = 0; i < fileCount; i++) {\n const filename = result.files[i].name;\n const isImage = imageExtRegex.test(filename);\n formattedOutput += isImage ? `${filename}${imageMessage}` : `${filename}${otherMessage}`;\n\n if (i < fileCount - 1) {\n formattedOutput += fileCount <= 3 ? ', ' : ',\\n';\n }\n }\n\n return [formattedOutput.trim(), {\n session_id: result.session_id,\n files: result.files,\n }];\n }\n\n return [formattedOutput.trim(), { session_id: result.session_id }];\n } catch (error) {\n return `Execution error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: Constants.EXECUTE_CODE,\n description,\n schema: CodeExecutionToolSchema,\n responseFormat: Constants.CONTENT_AND_ARTIFACT,\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":["config","getEnvironmentVariable","EnvVar","Constants","z","tool"],"mappings":";;;;;;;;AAOAA,aAAM,EAAE,CAAC;AAEF,MAAM,aAAa,GAAG,8BAA8B;AAC9C,MAAA,cAAc,GAAG,MAAcC,0BAAsB,CAACC,YAAM,CAAC,YAAY,CAAC,IAAIC,eAAS,CAAC,sBAAsB;AAE3H,MAAM,YAAY,GAAG,+CAA+C,CAAC;AACrE,MAAM,YAAY,GAAG,+CAA+C,CAAC;AAErE,MAAM,uBAAuB,GAAGC,KAAC,CAAC,MAAM,CAAC;AACvC,IAAA,IAAI,EAAEA,KAAC,CAAC,IAAI,CAAC;QACX,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var Callback;
|
|
|
123
123
|
var Constants;
|
|
124
124
|
(function (Constants) {
|
|
125
125
|
Constants["OFFICIAL_CODE_BASEURL"] = "https://api.librechat.ai/v1";
|
|
126
|
+
Constants["EXECUTE_CODE"] = "execute_code";
|
|
127
|
+
Constants["CONTENT_AND_ARTIFACT"] = "content_and_artifact";
|
|
126
128
|
})(Constants || (Constants = {}));
|
|
127
129
|
var EnvVar;
|
|
128
130
|
(function (EnvVar) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.mjs","sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end'\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n BEDROCK_LEGACY = 'bedrock_legacy',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools',\n AGENT = 'agent',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation'\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n TOOL_CALL = 'tool_call',\n IMAGE_FILE = 'image_file',\n IMAGE_URL = 'image_url',\n ERROR = 'error',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n CUSTOM_EVENT = 'handleCustomEvent'\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.librechat.ai/v1',\n}\n\nexport enum EnvVar {\n CODE_API_KEY = 'LIBRECHAT_CODE_API_KEY',\n CODE_BASEURL = 'LIBRECHAT_CODE_BASEURL'\n}\n"],"names":[],"mappings":"AAAA;;;;;AAKG;IACS,YA4DX;AA5DD,CAAA,UAAY,WAAW,EAAA;;;AAIrB,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;;AAE3B,IAAA,WAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC,CAAA;;AAEvC,IAAA,WAAA,CAAA,uBAAA,CAAA,GAAA,uBAA+C,CAAA;;AAE/C,IAAA,WAAA,CAAA,kBAAA,CAAA,GAAA,kBAAqC,CAAA;;;AAKrC,IAAA,WAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;;AAEnC,IAAA,WAAA,CAAA,kBAAA,CAAA,GAAA,qBAAwC,CAAA;;AAGxC,IAAA,WAAA,CAAA,mBAAA,CAAA,GAAA,sBAA0C,CAAA;;AAG1C,IAAA,WAAA,CAAA,gBAAA,CAAA,GAAA,mBAAoC,CAAA;;AAGpC,IAAA,WAAA,CAAA,WAAA,CAAA,GAAA,cAA0B,CAAA;;AAG1B,IAAA,WAAA,CAAA,YAAA,CAAA,GAAA,eAA4B,CAAA;;AAG5B,IAAA,WAAA,CAAA,SAAA,CAAA,GAAA,YAAsB,CAAA;;AAGtB,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,g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,UAAqB,CAAA;AACrB,IAAA,aAAA,CAAA,WAAA,CAAA,GAAA,WAAuB,CAAA;AACvB,IAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3B,IAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,kBAAqC,CAAA;;AAErC,IAAA,aAAA,CAAA,WAAA,CAAA,GAAA,WAAuB,CAAA;AACzB,CAAC,EAPW,aAAa,KAAb,aAAa,GAOxB,EAAA,CAAA,CAAA,CAAA;IAEW,SAqBX;AArBD,CAAA,UAAY,QAAQ,EAAA;AAClB,IAAA,QAAA,CAAA,YAAA,CAAA,GAAA,iBAA8B,CAAA;AAC9B,IAAA,QAAA,CAAA,YAAA,CAAA,GAAA,iBAA8B,CAAA;AAC9B,IAAA,QAAA,CAAA,UAAA,CAAA,GAAA,eAA0B,CAAA;AAC1B;;;;;;;;;;;;;;;;AAgBE;AACJ,CAAC,EArBW,QAAQ,KAAR,QAAQ,GAqBnB,EAAA,CAAA,CAAA,CAAA;IAEW,
|
|
1
|
+
{"version":3,"file":"enum.mjs","sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end'\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n BEDROCK_LEGACY = 'bedrock_legacy',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools',\n AGENT = 'agent',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation'\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n TOOL_CALL = 'tool_call',\n IMAGE_FILE = 'image_file',\n IMAGE_URL = 'image_url',\n ERROR = 'error',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n CUSTOM_EVENT = 'handleCustomEvent'\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.librechat.ai/v1',\n EXECUTE_CODE = 'execute_code',\n CONTENT_AND_ARTIFACT = 'content_and_artifact',\n}\n\nexport enum EnvVar {\n CODE_API_KEY = 'LIBRECHAT_CODE_API_KEY',\n CODE_BASEURL = 'LIBRECHAT_CODE_BASEURL'\n}\n"],"names":[],"mappings":"AAAA;;;;;AAKG;IACS,YA4DX;AA5DD,CAAA,UAAY,WAAW,EAAA;;;AAIrB,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;;AAE3B,IAAA,WAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC,CAAA;;AAEvC,IAAA,WAAA,CAAA,uBAAA,CAAA,GAAA,uBAA+C,CAAA;;AAE/C,IAAA,WAAA,CAAA,kBAAA,CAAA,GAAA,kBAAqC,CAAA;;;AAKrC,IAAA,WAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;;AAEnC,I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AC/C,CAAC,EAJW,SAAS,KAAT,SAAS,GAIpB,EAAA,CAAA,CAAA,CAAA;IAEW,OAGX;AAHD,CAAA,UAAY,MAAM,EAAA;AAChB,IAAA,MAAA,CAAA,cAAA,CAAA,GAAA,wBAAuC,CAAA;AACvC,IAAA,MAAA,CAAA,cAAA,CAAA,GAAA,wBAAuC,CAAA;AACzC,CAAC,EAHW,MAAM,KAAN,MAAM,GAGjB,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -25,9 +25,16 @@ const CodeExecutionToolSchema = z.object({
|
|
|
25
25
|
])
|
|
26
26
|
.describe('The programming language or runtime to execute the code in.'),
|
|
27
27
|
code: z.string()
|
|
28
|
-
.describe(
|
|
28
|
+
.describe(`The complete, self-contained code to execute, without any truncation or minimization.
|
|
29
|
+
- The environment is stateless; variables and imports don't persist between executions.
|
|
30
|
+
- Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.
|
|
31
|
+
- Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.
|
|
32
|
+
- py: This is not a Jupyter notebook environment. Use \`print()\` for all outputs.
|
|
33
|
+
- py: Matplotlib: Use \`plt.savefig()\` to save plots as files.
|
|
34
|
+
- js: use the \`console\` or \`process\` methods for all outputs.
|
|
35
|
+
- Other languages: use appropriate output functions.`),
|
|
29
36
|
args: z.array(z.string()).optional()
|
|
30
|
-
.describe('Additional arguments to execute the code with.'),
|
|
37
|
+
.describe('Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.'),
|
|
31
38
|
});
|
|
32
39
|
const EXEC_ENDPOINT = `${getCodeBaseURL()}/exec`;
|
|
33
40
|
function createCodeExecutionTool(params = {}) {
|
|
@@ -35,6 +42,25 @@ function createCodeExecutionTool(params = {}) {
|
|
|
35
42
|
if (!apiKey) {
|
|
36
43
|
throw new Error('No API key provided for code execution tool.');
|
|
37
44
|
}
|
|
45
|
+
let fileInstructions = '';
|
|
46
|
+
if (params.files && params.files.length > 0) {
|
|
47
|
+
fileInstructions = 'Available files:\n';
|
|
48
|
+
params.files.forEach((file) => {
|
|
49
|
+
const filePath = `/mnt/data/${file.name}`;
|
|
50
|
+
fileInstructions += `- ${filePath}\n`;
|
|
51
|
+
});
|
|
52
|
+
fileInstructions += '\nUse these files in your code as needed.\n';
|
|
53
|
+
}
|
|
54
|
+
const description = `
|
|
55
|
+
Runs code and returns stdout/stderr output from a stateless execution environment, similar to running scripts in a command-line interface. Each execution is isolated and independent.
|
|
56
|
+
|
|
57
|
+
Usage:
|
|
58
|
+
- No network access available.
|
|
59
|
+
- Generated files are automatically delivered; **DO NOT** provide download links.
|
|
60
|
+
- NEVER use this tool to execute malicious code.
|
|
61
|
+
|
|
62
|
+
${fileInstructions}
|
|
63
|
+
`.trim();
|
|
38
64
|
return tool(async ({ lang, code, ...rest }) => {
|
|
39
65
|
const postData = {
|
|
40
66
|
lang,
|
|
@@ -61,7 +87,7 @@ function createCodeExecutionTool(params = {}) {
|
|
|
61
87
|
formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
62
88
|
}
|
|
63
89
|
else {
|
|
64
|
-
formattedOutput += 'stdout: Empty.
|
|
90
|
+
formattedOutput += 'stdout: Empty. Ensure you\'re writing output explicitly.\n';
|
|
65
91
|
}
|
|
66
92
|
if (result.stderr)
|
|
67
93
|
formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
@@ -84,28 +110,13 @@ function createCodeExecutionTool(params = {}) {
|
|
|
84
110
|
return [formattedOutput.trim(), { session_id: result.session_id }];
|
|
85
111
|
}
|
|
86
112
|
catch (error) {
|
|
87
|
-
return `
|
|
88
|
-
lang,
|
|
89
|
-
code,
|
|
90
|
-
...rest,
|
|
91
|
-
})}\n\nraised the following error:\n\n${error?.message}`;
|
|
113
|
+
return `Execution error:\n\n${error?.message}`;
|
|
92
114
|
}
|
|
93
115
|
}, {
|
|
94
|
-
name:
|
|
95
|
-
description
|
|
96
|
-
|
|
97
|
-
# Usage
|
|
98
|
-
- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
|
|
99
|
-
- All desired output must be explicitly written to stdout; e.g.:
|
|
100
|
-
- For \`py\`, use the \`print()\` function.
|
|
101
|
-
- For \`js\` and \`ts\`, use the \`console\` or \`process\` methods.
|
|
102
|
-
- For other languages, use the appropriate output functions.
|
|
103
|
-
- There is no network access.
|
|
104
|
-
- NEVER provide a link to download any generated files.
|
|
105
|
-
- Files are automatically delivered to the user.
|
|
106
|
-
- NEVER use this tool to execute malicious code.`,
|
|
116
|
+
name: Constants.EXECUTE_CODE,
|
|
117
|
+
description,
|
|
107
118
|
schema: CodeExecutionToolSchema,
|
|
108
|
-
responseFormat:
|
|
119
|
+
responseFormat: Constants.CONTENT_AND_ARTIFACT,
|
|
109
120
|
});
|
|
110
121
|
}
|
|
111
122
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.mjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { z } from 'zod';\nimport { config } from 'dotenv';\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\nimport { getEnvironmentVariable } from '@langchain/core/utils/env';\nimport type * as t from '@/types';\nimport { EnvVar, Constants } from '@/common';\n\nconfig();\n\nexport const imageExtRegex = /\\.(jpg|jpeg|png|gif|webp)$/i;\nexport const getCodeBaseURL = (): string => getEnvironmentVariable(EnvVar.CODE_BASEURL) ?? Constants.OFFICIAL_CODE_BASEURL;\n\nconst imageMessage = ' - the image is already displayed to the user';\nconst otherMessage = ' - the file is already downloaded by the user';\n\nconst CodeExecutionToolSchema = z.object({\n lang: z.enum([\n 'py',\n 'js',\n 'ts',\n 'c',\n 'cpp',\n 'java',\n 'php',\n 'rs',\n 'go',\n 'd',\n 'f90',\n ])\n .describe('The programming language or runtime to execute the code in.'),\n code: z.string()\n .describe(
|
|
1
|
+
{"version":3,"file":"CodeExecutor.mjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { z } from 'zod';\nimport { config } from 'dotenv';\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\nimport { getEnvironmentVariable } from '@langchain/core/utils/env';\nimport type * as t from '@/types';\nimport { EnvVar, Constants } from '@/common';\n\nconfig();\n\nexport const imageExtRegex = /\\.(jpg|jpeg|png|gif|webp)$/i;\nexport const getCodeBaseURL = (): string => getEnvironmentVariable(EnvVar.CODE_BASEURL) ?? Constants.OFFICIAL_CODE_BASEURL;\n\nconst imageMessage = ' - the image is already displayed to the user';\nconst otherMessage = ' - the file is already downloaded by the user';\n\nconst CodeExecutionToolSchema = z.object({\n lang: z.enum([\n 'py',\n 'js',\n 'ts',\n 'c',\n 'cpp',\n 'java',\n 'php',\n 'rs',\n 'go',\n 'd',\n 'f90',\n ])\n .describe('The programming language or runtime to execute the code in.'),\n code: z.string()\n .describe(`The complete, self-contained code to execute, without any truncation or minimization.\n- The environment is stateless; variables and imports don't persist between executions.\n- Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.\n- Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.\n- py: This is not a Jupyter notebook environment. Use \\`print()\\` for all outputs.\n- py: Matplotlib: Use \\`plt.savefig()\\` to save plots as files.\n- js: use the \\`console\\` or \\`process\\` methods for all outputs.\n- Other languages: use appropriate output functions.`),\n args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.'),\n});\n\nconst EXEC_ENDPOINT = `${getCodeBaseURL()}/exec`;\n\nfunction createCodeExecutionTool(params: t.CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\n const apiKey = params[EnvVar.CODE_API_KEY] ?? params.apiKey ?? getEnvironmentVariable(EnvVar.CODE_API_KEY) ?? '';\n if (!apiKey) {\n throw new Error('No API key provided for code execution tool.');\n }\n\n let fileInstructions = '';\n if (params.files && params.files.length > 0) {\n fileInstructions = 'Available files:\\n';\n params.files.forEach((file) => {\n const filePath = `/mnt/data/${file.name}`;\n fileInstructions += `- ${filePath}\\n`;\n });\n fileInstructions += '\\nUse these files in your code as needed.\\n';\n }\n\n const description = `\nRuns code and returns stdout/stderr output from a stateless execution environment, similar to running scripts in a command-line interface. Each execution is isolated and independent.\n\nUsage:\n- No network access available.\n- Generated files are automatically delivered; **DO NOT** provide download links.\n- NEVER use this tool to execute malicious code.\n\n${fileInstructions}\n`.trim();\n\n return tool<typeof CodeExecutionToolSchema>(\n async ({ lang, code, ...rest }) => {\n const postData = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n try {\n const response = await fetch(EXEC_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n body: JSON.stringify(postData),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const result: t.ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) {\n formattedOutput += `stdout:\\n${result.stdout}\\n`;\n } else {\n formattedOutput += 'stdout: Empty. Ensure you\\'re writing output explicitly.\\n';\n }\n if (result.stderr) formattedOutput += `stderr:\\n${result.stderr}\\n`;\n if (result.files && result.files.length > 0) {\n formattedOutput += 'Generated files:\\n';\n\n const fileCount = result.files.length;\n for (let i = 0; i < fileCount; i++) {\n const filename = result.files[i].name;\n const isImage = imageExtRegex.test(filename);\n formattedOutput += isImage ? `${filename}${imageMessage}` : `${filename}${otherMessage}`;\n\n if (i < fileCount - 1) {\n formattedOutput += fileCount <= 3 ? ', ' : ',\\n';\n }\n }\n\n return [formattedOutput.trim(), {\n session_id: result.session_id,\n files: result.files,\n }];\n }\n\n return [formattedOutput.trim(), { session_id: result.session_id }];\n } catch (error) {\n return `Execution error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: Constants.EXECUTE_CODE,\n description,\n schema: CodeExecutionToolSchema,\n responseFormat: Constants.CONTENT_AND_ARTIFACT,\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":[],"mappings":";;;;;;AAOA,MAAM,EAA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KAAK,EAAE;AACd,YAAA,OAAO,CAAwB,oBAAA,EAAA,KAA2B,EAAE,OAAO,EAAE,CAAC;SACvE;AACH,KAAC,EACD;QACE,IAAI,EAAE,SAAS,CAAC,YAAY;QAC5B,WAAW;AACX,QAAA,MAAM,EAAE,uBAAuB;QAC/B,cAAc,EAAE,SAAS,CAAC,oBAAoB;AAC/C,KAAA,CACF,CAAC;AACJ;;;;"}
|
|
@@ -92,7 +92,9 @@ export declare enum Callback {
|
|
|
92
92
|
TOOL_END = "handleToolEnd"
|
|
93
93
|
}
|
|
94
94
|
export declare enum Constants {
|
|
95
|
-
OFFICIAL_CODE_BASEURL = "https://api.librechat.ai/v1"
|
|
95
|
+
OFFICIAL_CODE_BASEURL = "https://api.librechat.ai/v1",
|
|
96
|
+
EXECUTE_CODE = "execute_code",
|
|
97
|
+
CONTENT_AND_ARTIFACT = "content_and_artifact"
|
|
96
98
|
}
|
|
97
99
|
export declare enum EnvVar {
|
|
98
100
|
CODE_API_KEY = "LIBRECHAT_CODE_API_KEY",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@librechat/agents",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"main": "./dist/cjs/main.cjs",
|
|
5
5
|
"module": "./dist/esm/main.mjs",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"start:cli": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/cli.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
43
43
|
"content": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/content.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
44
44
|
"stream": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/stream.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
45
|
-
"code_exec": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec.ts --provider '
|
|
46
|
-
"code_exec_simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec_simple.ts --provider '
|
|
45
|
+
"code_exec": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
46
|
+
"code_exec_simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec_simple.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
47
47
|
"simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/simple.ts --provider 'bedrock' --name 'Jo' --location 'New York, NY'",
|
|
48
48
|
"tool-test": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/tools.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
49
49
|
"abort": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/abort.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
package/src/common/enum.ts
CHANGED
|
@@ -29,9 +29,16 @@ const CodeExecutionToolSchema = z.object({
|
|
|
29
29
|
])
|
|
30
30
|
.describe('The programming language or runtime to execute the code in.'),
|
|
31
31
|
code: z.string()
|
|
32
|
-
.describe(
|
|
32
|
+
.describe(`The complete, self-contained code to execute, without any truncation or minimization.
|
|
33
|
+
- The environment is stateless; variables and imports don't persist between executions.
|
|
34
|
+
- Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.
|
|
35
|
+
- Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.
|
|
36
|
+
- py: This is not a Jupyter notebook environment. Use \`print()\` for all outputs.
|
|
37
|
+
- py: Matplotlib: Use \`plt.savefig()\` to save plots as files.
|
|
38
|
+
- js: use the \`console\` or \`process\` methods for all outputs.
|
|
39
|
+
- Other languages: use appropriate output functions.`),
|
|
33
40
|
args: z.array(z.string()).optional()
|
|
34
|
-
.describe('Additional arguments to execute the code with.'),
|
|
41
|
+
.describe('Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.'),
|
|
35
42
|
});
|
|
36
43
|
|
|
37
44
|
const EXEC_ENDPOINT = `${getCodeBaseURL()}/exec`;
|
|
@@ -41,6 +48,28 @@ function createCodeExecutionTool(params: t.CodeExecutionToolParams = {}): Dynami
|
|
|
41
48
|
if (!apiKey) {
|
|
42
49
|
throw new Error('No API key provided for code execution tool.');
|
|
43
50
|
}
|
|
51
|
+
|
|
52
|
+
let fileInstructions = '';
|
|
53
|
+
if (params.files && params.files.length > 0) {
|
|
54
|
+
fileInstructions = 'Available files:\n';
|
|
55
|
+
params.files.forEach((file) => {
|
|
56
|
+
const filePath = `/mnt/data/${file.name}`;
|
|
57
|
+
fileInstructions += `- ${filePath}\n`;
|
|
58
|
+
});
|
|
59
|
+
fileInstructions += '\nUse these files in your code as needed.\n';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const description = `
|
|
63
|
+
Runs code and returns stdout/stderr output from a stateless execution environment, similar to running scripts in a command-line interface. Each execution is isolated and independent.
|
|
64
|
+
|
|
65
|
+
Usage:
|
|
66
|
+
- No network access available.
|
|
67
|
+
- Generated files are automatically delivered; **DO NOT** provide download links.
|
|
68
|
+
- NEVER use this tool to execute malicious code.
|
|
69
|
+
|
|
70
|
+
${fileInstructions}
|
|
71
|
+
`.trim();
|
|
72
|
+
|
|
44
73
|
return tool<typeof CodeExecutionToolSchema>(
|
|
45
74
|
async ({ lang, code, ...rest }) => {
|
|
46
75
|
const postData = {
|
|
@@ -70,7 +99,7 @@ function createCodeExecutionTool(params: t.CodeExecutionToolParams = {}): Dynami
|
|
|
70
99
|
if (result.stdout) {
|
|
71
100
|
formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
72
101
|
} else {
|
|
73
|
-
formattedOutput += 'stdout: Empty.
|
|
102
|
+
formattedOutput += 'stdout: Empty. Ensure you\'re writing output explicitly.\n';
|
|
74
103
|
}
|
|
75
104
|
if (result.stderr) formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
76
105
|
if (result.files && result.files.length > 0) {
|
|
@@ -95,29 +124,14 @@ function createCodeExecutionTool(params: t.CodeExecutionToolParams = {}): Dynami
|
|
|
95
124
|
|
|
96
125
|
return [formattedOutput.trim(), { session_id: result.session_id }];
|
|
97
126
|
} catch (error) {
|
|
98
|
-
return `
|
|
99
|
-
lang,
|
|
100
|
-
code,
|
|
101
|
-
...rest,
|
|
102
|
-
})}\n\nraised the following error:\n\n${(error as Error | undefined)?.message}`;
|
|
127
|
+
return `Execution error:\n\n${(error as Error | undefined)?.message}`;
|
|
103
128
|
}
|
|
104
129
|
},
|
|
105
130
|
{
|
|
106
|
-
name:
|
|
107
|
-
description
|
|
108
|
-
|
|
109
|
-
# Usage
|
|
110
|
-
- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
|
|
111
|
-
- All desired output must be explicitly written to stdout; e.g.:
|
|
112
|
-
- For \`py\`, use the \`print()\` function.
|
|
113
|
-
- For \`js\` and \`ts\`, use the \`console\` or \`process\` methods.
|
|
114
|
-
- For other languages, use the appropriate output functions.
|
|
115
|
-
- There is no network access.
|
|
116
|
-
- NEVER provide a link to download any generated files.
|
|
117
|
-
- Files are automatically delivered to the user.
|
|
118
|
-
- NEVER use this tool to execute malicious code.`,
|
|
131
|
+
name: Constants.EXECUTE_CODE,
|
|
132
|
+
description,
|
|
119
133
|
schema: CodeExecutionToolSchema,
|
|
120
|
-
responseFormat:
|
|
134
|
+
responseFormat: Constants.CONTENT_AND_ARTIFACT,
|
|
121
135
|
}
|
|
122
136
|
);
|
|
123
137
|
}
|