@librechat/agents 1.6.2 → 1.6.3

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.
@@ -93,7 +93,11 @@ function createCodeExecutionTool(params = {}) {
93
93
 
94
94
  # Usage
95
95
  - Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
96
- - All desired output must be explicitly written to stdout.`,
96
+ - All desired output must be explicitly written to stdout; e.g.:
97
+ - For \`py\`, use the \`print()\` function.
98
+ - For \`js\` and \`ts\`, use the \`console\` or \`process\` methods.
99
+ - For other languages, use the appropriate output functions.
100
+ - Files generated by the code will be accessed by the user.`,
97
101
  schema: CodeExecutionToolSchema,
98
102
  responseFormat: 'content_and_artifact',
99
103
  });
@@ -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 getCodeBaseURL = (): string => getEnvironmentVariable(EnvVar.CODE_BASEURL) ?? Constants.OFFICIAL_CODE_BASEURL;\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 args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with.'),\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 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. To output values, write explicitly to stdout.\\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 formattedOutput += result.files[i].name;\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 `Calling tool with arguments:\\n\\n${JSON.stringify({\n lang,\n code,\n ...rest,\n })}\\n\\nraised the following error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: 'execute_code',\n description: `Executes code in various programming languages, returning stdout/stderr output.\n\n# Usage\n- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.\n- All desired output must be explicitly written to stdout.`,\n schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":["config","getEnvironmentVariable","EnvVar","Constants","z","tool"],"mappings":";;;;;;;;AAOAA,aAAM,EAAE,CAAC;AAEI,MAAA,cAAc,GAAG,MAAcC,0BAAsB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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;AACd,YAAA,OAAO,CAAmC,gCAAA,EAAA,IAAI,CAAC,SAAS,CAAC;gBACvD,IAAI;gBACJ,IAAI;AACJ,gBAAA,GAAG,IAAI;AACR,aAAA,CAAC,CAAuC,mCAAA,EAAA,KAA2B,EAAE,OAAO,EAAE,CAAC;SACjF;AACH,KAAC,EACD;AACE,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,CAAA;;;;AAIwC,0DAAA,CAAA;AACrD,QAAA,MAAM,EAAE,uBAAuB;AAC/B,QAAA,cAAc,EAAE,sBAAsB;AACvC,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 getCodeBaseURL = (): string => getEnvironmentVariable(EnvVar.CODE_BASEURL) ?? Constants.OFFICIAL_CODE_BASEURL;\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 args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with.'),\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 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. To output values, write explicitly to stdout.\\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 formattedOutput += result.files[i].name;\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 `Calling tool with arguments:\\n\\n${JSON.stringify({\n lang,\n code,\n ...rest,\n })}\\n\\nraised the following error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: 'execute_code',\n description: `Executes code in various programming languages, returning stdout/stderr output.\n\n# Usage\n- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.\n- All desired output must be explicitly written to stdout; e.g.:\n - For \\`py\\`, use the \\`print()\\` function.\n - For \\`js\\` and \\`ts\\`, use the \\`console\\` or \\`process\\` methods.\n - For other languages, use the appropriate output functions.\n- Files generated by the code will be accessed by the user.`,\n schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":["config","getEnvironmentVariable","EnvVar","Constants","z","tool"],"mappings":";;;;;;;;AAOAA,aAAM,EAAE,CAAC;AAEI,MAAA,cAAc,GAAG,MAAcC,0BAAsB,CAACC,YAAM,CAAC,YAAY,CAAC,IAAIC,eAAS,CAAC,sBAAsB;AAE3H,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;KACN,CAAC;SACC,QAAQ,CAAC,6DAA6D,CAAC;AAC1E,IAAA,IAAI,EAAEA,KAAC,CAAC,MAAM,EAAE;SACb,QAAQ,CAAC,uFAAuF,CAAC;AACpG,IAAA,IAAI,EAAEA,KAAC,CAAC,KAAK,CAACA,KAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;SACjC,QAAQ,CAAC,gDAAgD,CAAC;AAC9D,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,CAAC,MAAM,EAAE;AACX,QAAA,MAA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C,gBAAA,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;AACtC,gBAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE;oBAClC,eAAe,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAExC,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;AACd,YAAA,OAAO,CAAmC,gCAAA,EAAA,IAAI,CAAC,SAAS,CAAC;gBACvD,IAAI;gBACJ,IAAI;AACJ,gBAAA,GAAG,IAAI;AACR,aAAA,CAAC,CAAuC,mCAAA,EAAA,KAA2B,EAAE,OAAO,EAAE,CAAC;SACjF;AACH,KAAC,EACD;AACE,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,CAAA;;;;;;;;AAQyC,2DAAA,CAAA;AACtD,QAAA,MAAM,EAAE,uBAAuB;AAC/B,QAAA,cAAc,EAAE,sBAAsB;AACvC,KAAA,CACF,CAAC;AACJ;;;;;"}
@@ -91,7 +91,11 @@ function createCodeExecutionTool(params = {}) {
91
91
 
92
92
  # Usage
93
93
  - Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
94
- - All desired output must be explicitly written to stdout.`,
94
+ - All desired output must be explicitly written to stdout; e.g.:
95
+ - For \`py\`, use the \`print()\` function.
96
+ - For \`js\` and \`ts\`, use the \`console\` or \`process\` methods.
97
+ - For other languages, use the appropriate output functions.
98
+ - Files generated by the code will be accessed by the user.`,
95
99
  schema: CodeExecutionToolSchema,
96
100
  responseFormat: 'content_and_artifact',
97
101
  });
@@ -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 getCodeBaseURL = (): string => getEnvironmentVariable(EnvVar.CODE_BASEURL) ?? Constants.OFFICIAL_CODE_BASEURL;\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 args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with.'),\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 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. To output values, write explicitly to stdout.\\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 formattedOutput += result.files[i].name;\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 `Calling tool with arguments:\\n\\n${JSON.stringify({\n lang,\n code,\n ...rest,\n })}\\n\\nraised the following error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: 'execute_code',\n description: `Executes code in various programming languages, returning stdout/stderr output.\n\n# Usage\n- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.\n- All desired output must be explicitly written to stdout.`,\n schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":[],"mappings":";;;;;;AAOA,MAAM,EAAE,CAAC;AAEI,MAAA,cAAc,GAAG,MAAc,sBAAsB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC,sBAAsB;AAE3H,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;KACN,CAAC;SACC,QAAQ,CAAC,6DA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,OAAO,CAAmC,gCAAA,EAAA,IAAI,CAAC,SAAS,CAAC;gBACvD,IAAI;gBACJ,IAAI;AACJ,gBAAA,GAAG,IAAI;AACR,aAAA,CAAC,CAAuC,mCAAA,EAAA,KAA2B,EAAE,OAAO,EAAE,CAAC;SACjF;AACH,KAAC,EACD;AACE,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,CAAA;;;;AAIwC,0DAAA,CAAA;AACrD,QAAA,MAAM,EAAE,uBAAuB;AAC/B,QAAA,cAAc,EAAE,sBAAsB;AACvC,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 getCodeBaseURL = (): string => getEnvironmentVariable(EnvVar.CODE_BASEURL) ?? Constants.OFFICIAL_CODE_BASEURL;\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 args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with.'),\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 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. To output values, write explicitly to stdout.\\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 formattedOutput += result.files[i].name;\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 `Calling tool with arguments:\\n\\n${JSON.stringify({\n lang,\n code,\n ...rest,\n })}\\n\\nraised the following error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: 'execute_code',\n description: `Executes code in various programming languages, returning stdout/stderr output.\n\n# Usage\n- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.\n- All desired output must be explicitly written to stdout; e.g.:\n - For \\`py\\`, use the \\`print()\\` function.\n - For \\`js\\` and \\`ts\\`, use the \\`console\\` or \\`process\\` methods.\n - For other languages, use the appropriate output functions.\n- Files generated by the code will be accessed by the user.`,\n schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":[],"mappings":";;;;;;AAOA,MAAM,EAAE,CAAC;AAEI,MAAA,cAAc,GAAG,MAAc,sBAAsB,CAA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;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;AACd,YAAA,OAAO,CAAmC,gCAAA,EAAA,IAAI,CAAC,SAAS,CAAC;gBACvD,IAAI;gBACJ,IAAI;AACJ,gBAAA,GAAG,IAAI;AACR,aAAA,CAAC,CAAuC,mCAAA,EAAA,KAA2B,EAAE,OAAO,EAAE,CAAC;SACjF;AACH,KAAC,EACD;AACE,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,CAAA;;;;;;;;AAQyC,2DAAA,CAAA;AACtD,QAAA,MAAM,EAAE,uBAAuB;AAC/B,QAAA,cAAc,EAAE,sBAAsB;AACvC,KAAA,CACF,CAAC;AACJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "main": "./dist/cjs/main.cjs",
5
5
  "module": "./dist/esm/main.mjs",
6
6
  "types": "./dist/types/index.d.ts",
@@ -102,7 +102,11 @@ function createCodeExecutionTool(params: t.CodeExecutionToolParams = {}): Dynami
102
102
 
103
103
  # Usage
104
104
  - Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
105
- - All desired output must be explicitly written to stdout.`,
105
+ - All desired output must be explicitly written to stdout; e.g.:
106
+ - For \`py\`, use the \`print()\` function.
107
+ - For \`js\` and \`ts\`, use the \`console\` or \`process\` methods.
108
+ - For other languages, use the appropriate output functions.
109
+ - Files generated by the code will be accessed by the user.`,
106
110
  schema: CodeExecutionToolSchema,
107
111
  responseFormat: 'content_and_artifact',
108
112
  }