@librechat/agents 1.9.91 → 1.9.92

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.
@@ -32,10 +32,11 @@ const CodeExecutionToolSchema = zod.z.object({
32
32
  - The environment is stateless; variables and imports don't persist between executions.
33
33
  - Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.
34
34
  - Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.
35
+ - IMPORTANT: You MUST explicitly print/output ALL results you want the user to see.
35
36
  - py: This is not a Jupyter notebook environment. Use \`print()\` for all outputs.
36
37
  - py: Matplotlib: Use \`plt.savefig()\` to save plots as files.
37
38
  - js: use the \`console\` or \`process\` methods for all outputs.
38
- - r: For graphics, use Cairo (X11 unavailable).
39
+ - r: IMPORTANT: No X11 display available. ALL graphics MUST use Cairo library (library(Cairo)).
39
40
  - Other languages: use appropriate output functions.`),
40
41
  args: zod.z.array(zod.z.string()).optional()
41
42
  .describe('Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.'),
@@ -46,15 +47,6 @@ function createCodeExecutionTool(params = {}) {
46
47
  if (!apiKey) {
47
48
  throw new Error('No API key provided for code execution tool.');
48
49
  }
49
- let fileInstructions = '';
50
- if (params.files && params.files.length > 0) {
51
- fileInstructions = 'Available files:\n';
52
- params.files.forEach((file) => {
53
- const filePath = `/mnt/data/${file.name}`;
54
- fileInstructions += `- ${filePath}\n`;
55
- });
56
- fileInstructions += '\nUse these files in your code as needed.\n';
57
- }
58
50
  const description = `
59
51
  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.
60
52
 
@@ -62,8 +54,6 @@ Usage:
62
54
  - No network access available.
63
55
  - Generated files are automatically delivered; **DO NOT** provide download links.
64
56
  - NEVER use this tool to execute malicious code.
65
-
66
- ${fileInstructions}
67
57
  `.trim();
68
58
  return tools.tool(async ({ lang, code, ...rest }) => {
69
59
  const postData = {
@@ -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 'r',\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- r: For graphics, use Cairo (X11 unavailable).\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,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,MAAM;QACN,KAAK;QACL,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,GAAG;KACJ,CAAC;SACC,QAAQ,CAAC,6DAA6D,CAAC;AAC1E,IAAA,IAAI,EAAEA,KAAC,CAAC,MAAM,EAAE;AACb,SAAA,QAAQ,CAAC,CAAA;;;;;;;;qDAQuC,CAAC;AACpD,IAAA,IAAI,EAAEA,KAAC,CAAC,KAAK,CAACA,KAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;SACjC,QAAQ,CAAC,iIAAiI,CAAC;AAC/I,CAAA,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,CAAA,EAAG,cAAc,EAAE,OAAO,CAAC;AAEjD,SAAS,uBAAuB,CAAC,MAAA,GAAoC,EAAE,EAAA;IACrE,MAAM,MAAM,GAAG,MAAM,CAACF,YAAM,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,MAAM,IAAID,0BAAsB,CAACC,YAAM,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IACjH,IAAI,CA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EAAE,MAAM,CAAC,UAAU;wBAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;AACpB,qBAAA,CAAC,CAAC;aACJ;AAED,YAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;SACpE;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,uBAAwB,KAA2B,EAAE,OAAO,CAAE,CAAA,EAAE,EAAE,CAAC,CAAC;SAC7E;AACH,KAAC,EACD;QACE,IAAI,EAAEF,eAAS,CAAC,YAAY;QAC5B,WAAW;AACX,QAAA,MAAM,EAAE,uBAAuB;QAC/B,cAAc,EAAEA,eAAS,CAAC,oBAAoB;AAC/C,KAAA,CACF,CAAC;AACJ;;;;;;"}
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 'r',\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- IMPORTANT: You MUST explicitly print/output ALL results you want the user to see.\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- r: IMPORTANT: No X11 display available. ALL graphics MUST use Cairo library (library(Cairo)).\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 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`.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,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,MAAM;QACN,KAAK;QACL,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,GAAG;KACJ,CAAC;SACC,QAAQ,CAAC,6DAA6D,CAAC;AAC1E,IAAA,IAAI,EAAEA,KAAC,CAAC,MAAM,EAAE;AACb,SAAA,QAAQ,CAAC,CAAA;;;;;;;;;qDASuC,CAAC;AACpD,IAAA,IAAI,EAAEA,KAAC,CAAC,KAAK,CAACA,KAAC,CAAC,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,YAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;SACpE;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,uBAAwB,KAA2B,EAAE,OAAO,CAAE,CAAA,EAAE,EAAE,CAAC,CAAC;SAC7E;AACH,KAAC,EACD;QACE,IAAI,EAAEF,eAAS,CAAC,YAAY;QAC5B,WAAW;AACX,QAAA,MAAM,EAAE,uBAAuB;QAC/B,cAAc,EAAEA,eAAS,CAAC,oBAAoB;AAC/C,KAAA,CACF,CAAC;AACJ;;;;;;"}
@@ -30,10 +30,11 @@ const CodeExecutionToolSchema = z.object({
30
30
  - The environment is stateless; variables and imports don't persist between executions.
31
31
  - Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.
32
32
  - Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.
33
+ - IMPORTANT: You MUST explicitly print/output ALL results you want the user to see.
33
34
  - py: This is not a Jupyter notebook environment. Use \`print()\` for all outputs.
34
35
  - py: Matplotlib: Use \`plt.savefig()\` to save plots as files.
35
36
  - js: use the \`console\` or \`process\` methods for all outputs.
36
- - r: For graphics, use Cairo (X11 unavailable).
37
+ - r: IMPORTANT: No X11 display available. ALL graphics MUST use Cairo library (library(Cairo)).
37
38
  - Other languages: use appropriate output functions.`),
38
39
  args: z.array(z.string()).optional()
39
40
  .describe('Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.'),
@@ -44,15 +45,6 @@ function createCodeExecutionTool(params = {}) {
44
45
  if (!apiKey) {
45
46
  throw new Error('No API key provided for code execution tool.');
46
47
  }
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
48
  const description = `
57
49
  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
50
 
@@ -60,8 +52,6 @@ Usage:
60
52
  - No network access available.
61
53
  - Generated files are automatically delivered; **DO NOT** provide download links.
62
54
  - NEVER use this tool to execute malicious code.
63
-
64
- ${fileInstructions}
65
55
  `.trim();
66
56
  return tool(async ({ lang, code, ...rest }) => {
67
57
  const postData = {
@@ -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 'r',\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- r: For graphics, use Cairo (X11 unavailable).\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,EAAE,CAAC;AAEF,MAAM,aAAa,GAAG,8BAA8B;AAC9C,MAAA,cAAc,GAAG,MAAc,sBAAsB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC,sBAAsB;AAE3H,MAAM,YAAY,GAAG,+CAA+C,CAAC;AACrE,MAAM,YAAY,GAAG,+CAA+C,CAAC;AAErE,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;AACvC,IAAA,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;QACX,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,MAAM;QACN,KAAK;QACL,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,GAAG;KACJ,CAAC;SACC,QAAQ,CAAC,6DAA6D,CAAC;AAC1E,IAAA,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;AACb,SAAA,QAAQ,CAAC,CAAA;;;;;;;;qDAQuC,CAAC;AACpD,IAAA,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;SACjC,QAAQ,CAAC,iIAAiI,CAAC;AAC/I,CAAA,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,CAAA,EAAG,cAAc,EA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AAY,EAAE,CAAC;AAEzF,oBAAA,IAAI,CAAC,GAAG,SAAS,GAAG,CAAC,EAAE;AACrB,wBAAA,eAAe,IAAI,SAAS,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;qBAClD;iBACF;AAED,gBAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE;wBAC9B,UAAU,EAAE,MAAM,CAAC,UAAU;wBAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;AACpB,qBAAA,CAAC,CAAC;aACJ;AAED,YAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;SACpE;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,uBAAwB,KAA2B,EAAE,OAAO,CAAE,CAAA,EAAE,EAAE,CAAC,CAAC;SAC7E;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;;;;"}
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 'r',\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- IMPORTANT: You MUST explicitly print/output ALL results you want the user to see.\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- r: IMPORTANT: No X11 display available. ALL graphics MUST use Cairo library (library(Cairo)).\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 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`.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,EAAE,CAAC;AAEF,MAAM,aAAa,GAAG,8BAA8B;AAC9C,MAAA,cAAc,GAAG,MAAc,sBAAsB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC,sBAAsB;AAE3H,MAAM,YAAY,GAAG,+CAA+C,CAAC;AACrE,MAAM,YAAY,GAAG,+CAA+C,CAAC;AAErE,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;AACvC,IAAA,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;QACX,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,MAAM;QACN,KAAK;QACL,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,GAAG;KACJ,CAAC;SACC,QAAQ,CAA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BAClD;iBACF;AAED,gBAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE;wBAC9B,UAAU,EAAE,MAAM,CAAC,UAAU;wBAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;AACpB,qBAAA,CAAC,CAAC;aACJ;AAED,YAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;SACpE;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,uBAAwB,KAA2B,EAAE,OAAO,CAAE,CAAA,EAAE,EAAE,CAAC,CAAC;SAC7E;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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents",
3
- "version": "1.9.91",
3
+ "version": "1.9.92",
4
4
  "main": "./dist/cjs/main.cjs",
5
5
  "module": "./dist/esm/main.mjs",
6
6
  "types": "./dist/types/index.d.ts",
@@ -84,6 +84,7 @@ async function testCodeExecution(): Promise<void> {
84
84
  console.log('Test 1: Simple Code Execution');
85
85
 
86
86
  const userMessage1 = `how much memory is this (its in bytes) in MB? 31192000`;
87
+ // const userMessage1 = `can you show me a good use case for rscript by running some code`;
87
88
 
88
89
  conversationHistory.push(new HumanMessage(userMessage1));
89
90
 
@@ -34,10 +34,11 @@ const CodeExecutionToolSchema = z.object({
34
34
  - The environment is stateless; variables and imports don't persist between executions.
35
35
  - Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.
36
36
  - Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.
37
+ - IMPORTANT: You MUST explicitly print/output ALL results you want the user to see.
37
38
  - py: This is not a Jupyter notebook environment. Use \`print()\` for all outputs.
38
39
  - py: Matplotlib: Use \`plt.savefig()\` to save plots as files.
39
40
  - js: use the \`console\` or \`process\` methods for all outputs.
40
- - r: For graphics, use Cairo (X11 unavailable).
41
+ - r: IMPORTANT: No X11 display available. ALL graphics MUST use Cairo library (library(Cairo)).
41
42
  - Other languages: use appropriate output functions.`),
42
43
  args: z.array(z.string()).optional()
43
44
  .describe('Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.'),
@@ -51,16 +52,6 @@ function createCodeExecutionTool(params: t.CodeExecutionToolParams = {}): Dynami
51
52
  throw new Error('No API key provided for code execution tool.');
52
53
  }
53
54
 
54
- let fileInstructions = '';
55
- if (params.files && params.files.length > 0) {
56
- fileInstructions = 'Available files:\n';
57
- params.files.forEach((file) => {
58
- const filePath = `/mnt/data/${file.name}`;
59
- fileInstructions += `- ${filePath}\n`;
60
- });
61
- fileInstructions += '\nUse these files in your code as needed.\n';
62
- }
63
-
64
55
  const description = `
65
56
  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.
66
57
 
@@ -68,8 +59,6 @@ Usage:
68
59
  - No network access available.
69
60
  - Generated files are automatically delivered; **DO NOT** provide download links.
70
61
  - NEVER use this tool to execute malicious code.
71
-
72
- ${fileInstructions}
73
62
  `.trim();
74
63
 
75
64
  return tool<typeof CodeExecutionToolSchema>(