@librechat/agents 1.5.4 → 1.5.5
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/tools/CodeExecutor.cjs +6 -0
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +6 -0
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/types/tools/CodeExecutor.d.ts +2 -1
- package/package.json +1 -1
- package/src/tools/CodeExecutor.ts +8 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
var dotenv = require('dotenv');
|
|
5
5
|
var tools = require('@langchain/core/tools');
|
|
6
|
+
var env = require('@langchain/core/utils/env');
|
|
6
7
|
|
|
7
8
|
dotenv.config();
|
|
8
9
|
const EXEC_ENDPOINT = 'https://api.librechat.ai/exec';
|
|
@@ -28,6 +29,10 @@ const CodeExecutionToolSchema = zod.z.object({
|
|
|
28
29
|
.describe('Additional arguments to execute the code with.'),
|
|
29
30
|
});
|
|
30
31
|
function createCodeExecutionTool(params = {}) {
|
|
32
|
+
const apiKey = params.apiKey ?? env.getEnvironmentVariable('LIBRECHAT_CODE_API_KEY') ?? '';
|
|
33
|
+
if (!apiKey) {
|
|
34
|
+
throw new Error('No API key provided for code execution tool.');
|
|
35
|
+
}
|
|
31
36
|
return tools.tool(async ({ lang, code, ...rest }) => {
|
|
32
37
|
const postData = {
|
|
33
38
|
lang,
|
|
@@ -41,6 +46,7 @@ function createCodeExecutionTool(params = {}) {
|
|
|
41
46
|
headers: {
|
|
42
47
|
'Content-Type': 'application/json',
|
|
43
48
|
'User-Agent': 'LibreChat/1.0',
|
|
49
|
+
'X-API-Key': apiKey,
|
|
44
50
|
},
|
|
45
51
|
body: JSON.stringify(postData),
|
|
46
52
|
});
|
|
@@ -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';\n\nconfig();\n\nconst EXEC_ENDPOINT = 'https://api.librechat.ai/exec';\n\nexport type CodeExecutionToolParams = {\n session_id?: string;\n user_id?: string;\n}\n\nexport type FileRef = {\n id: string;\n name: string;\n path?: string;\n};\n\nexport type FileRefs = FileRef[];\n\nexport type ExecuteResult = {\n session_id: string;\n stdout: string;\n stderr: string;\n files?: FileRefs;\n};\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 'bash',\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\nfunction createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\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 },\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: ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) formattedOutput += `stdout:\\n${result.stdout}\\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 result.files.forEach((file: FileRef) => {\n formattedOutput += `${file.name}`;\n });\n return [formattedOutput.trim(), result.files];\n }\n\n return [formattedOutput.trim(), undefined];\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 schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":["config","z","tool"],"mappings":"
|
|
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';\n\nconfig();\n\nconst EXEC_ENDPOINT = 'https://api.librechat.ai/exec';\n\nexport type CodeExecutionToolParams = undefined | {\n session_id?: string;\n user_id?: string;\n apiKey?: string;\n}\n\nexport type FileRef = {\n id: string;\n name: string;\n path?: string;\n};\n\nexport type FileRefs = FileRef[];\n\nexport type ExecuteResult = {\n session_id: string;\n stdout: string;\n stderr: string;\n files?: FileRefs;\n};\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 'bash',\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\nfunction createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\n const apiKey = params.apiKey ?? getEnvironmentVariable('LIBRECHAT_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: ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) formattedOutput += `stdout:\\n${result.stdout}\\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 result.files.forEach((file: FileRef) => {\n formattedOutput += `${file.name}`;\n });\n return [formattedOutput.trim(), result.files];\n }\n\n return [formattedOutput.trim(), undefined];\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 schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":["config","z","getEnvironmentVariable","tool"],"mappings":";;;;;;;AAKAA,aAAM,EAAE,CAAC;AAET,MAAM,aAAa,GAAG,+BAA+B,CAAC;AAuBtD,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,MAAM;QACN,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,E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AE,gBAAA,eAAe,IAAI,CAAY,SAAA,EAAA,MAAM,CAAC,MAAM,IAAI,CAAC;AACpE,YAAA,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC3C,eAAe,IAAI,oBAAoB,CAAC;gBACxC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAa,KAAI;AACrC,oBAAA,eAAe,IAAI,CAAG,EAAA,IAAI,CAAC,IAAI,EAAE,CAAC;AACpC,iBAAC,CAAC,CAAC;gBACH,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;aAC/C;YAED,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC;SAC5C;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,iFAAiF;AAC9F,QAAA,MAAM,EAAE,uBAAuB;AAC/B,QAAA,cAAc,EAAE,sBAAsB;AACvC,KAAA,CACF,CAAC;AACJ;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { config } from 'dotenv';
|
|
3
3
|
import { tool } from '@langchain/core/tools';
|
|
4
|
+
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
4
5
|
|
|
5
6
|
config();
|
|
6
7
|
const EXEC_ENDPOINT = 'https://api.librechat.ai/exec';
|
|
@@ -26,6 +27,10 @@ const CodeExecutionToolSchema = z.object({
|
|
|
26
27
|
.describe('Additional arguments to execute the code with.'),
|
|
27
28
|
});
|
|
28
29
|
function createCodeExecutionTool(params = {}) {
|
|
30
|
+
const apiKey = params.apiKey ?? getEnvironmentVariable('LIBRECHAT_CODE_API_KEY') ?? '';
|
|
31
|
+
if (!apiKey) {
|
|
32
|
+
throw new Error('No API key provided for code execution tool.');
|
|
33
|
+
}
|
|
29
34
|
return tool(async ({ lang, code, ...rest }) => {
|
|
30
35
|
const postData = {
|
|
31
36
|
lang,
|
|
@@ -39,6 +44,7 @@ function createCodeExecutionTool(params = {}) {
|
|
|
39
44
|
headers: {
|
|
40
45
|
'Content-Type': 'application/json',
|
|
41
46
|
'User-Agent': 'LibreChat/1.0',
|
|
47
|
+
'X-API-Key': apiKey,
|
|
42
48
|
},
|
|
43
49
|
body: JSON.stringify(postData),
|
|
44
50
|
});
|
|
@@ -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';\n\nconfig();\n\nconst EXEC_ENDPOINT = 'https://api.librechat.ai/exec';\n\nexport type CodeExecutionToolParams = {\n session_id?: string;\n user_id?: string;\n}\n\nexport type FileRef = {\n id: string;\n name: string;\n path?: string;\n};\n\nexport type FileRefs = FileRef[];\n\nexport type ExecuteResult = {\n session_id: string;\n stdout: string;\n stderr: string;\n files?: FileRefs;\n};\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 'bash',\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\nfunction createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\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 },\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: ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) formattedOutput += `stdout:\\n${result.stdout}\\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 result.files.forEach((file: FileRef) => {\n formattedOutput += `${file.name}`;\n });\n return [formattedOutput.trim(), result.files];\n }\n\n return [formattedOutput.trim(), undefined];\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 schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":[],"mappings":"
|
|
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';\n\nconfig();\n\nconst EXEC_ENDPOINT = 'https://api.librechat.ai/exec';\n\nexport type CodeExecutionToolParams = undefined | {\n session_id?: string;\n user_id?: string;\n apiKey?: string;\n}\n\nexport type FileRef = {\n id: string;\n name: string;\n path?: string;\n};\n\nexport type FileRefs = FileRef[];\n\nexport type ExecuteResult = {\n session_id: string;\n stdout: string;\n stderr: string;\n files?: FileRefs;\n};\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 'bash',\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\nfunction createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\n const apiKey = params.apiKey ?? getEnvironmentVariable('LIBRECHAT_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: ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) formattedOutput += `stdout:\\n${result.stdout}\\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 result.files.forEach((file: FileRef) => {\n formattedOutput += `${file.name}`;\n });\n return [formattedOutput.trim(), result.files];\n }\n\n return [formattedOutput.trim(), undefined];\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 schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":[],"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CAAC;SACjF;AACH,KAAC,EACD;AACE,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,iFAAiF;AAC9F,QAAA,MAAM,EAAE,uBAAuB;AAC/B,QAAA,cAAc,EAAE,sBAAsB;AACvC,KAAA,CACF,CAAC;AACJ;;;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
-
export type CodeExecutionToolParams = {
|
|
3
|
+
export type CodeExecutionToolParams = undefined | {
|
|
4
4
|
session_id?: string;
|
|
5
5
|
user_id?: string;
|
|
6
|
+
apiKey?: string;
|
|
6
7
|
};
|
|
7
8
|
export type FileRef = {
|
|
8
9
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { config } from 'dotenv';
|
|
3
3
|
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
4
|
+
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
4
5
|
|
|
5
6
|
config();
|
|
6
7
|
|
|
7
8
|
const EXEC_ENDPOINT = 'https://api.librechat.ai/exec';
|
|
8
9
|
|
|
9
|
-
export type CodeExecutionToolParams = {
|
|
10
|
+
export type CodeExecutionToolParams = undefined | {
|
|
10
11
|
session_id?: string;
|
|
11
12
|
user_id?: string;
|
|
13
|
+
apiKey?: string;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export type FileRef = {
|
|
@@ -49,6 +51,10 @@ const CodeExecutionToolSchema = z.object({
|
|
|
49
51
|
});
|
|
50
52
|
|
|
51
53
|
function createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {
|
|
54
|
+
const apiKey = params.apiKey ?? getEnvironmentVariable('LIBRECHAT_CODE_API_KEY') ?? '';
|
|
55
|
+
if (!apiKey) {
|
|
56
|
+
throw new Error('No API key provided for code execution tool.');
|
|
57
|
+
}
|
|
52
58
|
return tool<typeof CodeExecutionToolSchema>(
|
|
53
59
|
async ({ lang, code, ...rest }) => {
|
|
54
60
|
const postData = {
|
|
@@ -64,6 +70,7 @@ function createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicS
|
|
|
64
70
|
headers: {
|
|
65
71
|
'Content-Type': 'application/json',
|
|
66
72
|
'User-Agent': 'LibreChat/1.0',
|
|
73
|
+
'X-API-Key': apiKey,
|
|
67
74
|
},
|
|
68
75
|
body: JSON.stringify(postData),
|
|
69
76
|
});
|