@librechat/agents 3.1.23 → 3.1.24
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/main.cjs +19 -3
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs +12 -0
- package/dist/cjs/tools/Calculator.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +1 -0
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +14 -0
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/esm/main.mjs +3 -2
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs +12 -1
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +1 -1
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +14 -1
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/types/tools/Calculator.d.ts +11 -0
- package/dist/types/tools/CodeExecutor.d.ts +22 -0
- package/dist/types/tools/search/index.d.ts +1 -0
- package/dist/types/tools/search/schema.d.ts +32 -0
- package/package.json +1 -1
- package/src/tools/Calculator.ts +12 -0
- package/src/tools/CodeExecutor.ts +1 -1
- package/src/tools/search/index.ts +1 -0
- package/src/tools/search/schema.ts +14 -0
package/dist/cjs/main.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var ToolNode = require('./tools/ToolNode.cjs');
|
|
|
21
21
|
var schema = require('./tools/schema.cjs');
|
|
22
22
|
var handlers = require('./tools/handlers.cjs');
|
|
23
23
|
var tool = require('./tools/search/tool.cjs');
|
|
24
|
+
var schema$1 = require('./tools/search/schema.cjs');
|
|
24
25
|
var _enum = require('./common/enum.cjs');
|
|
25
26
|
var graph = require('./utils/graph.cjs');
|
|
26
27
|
var llm = require('./utils/llm.cjs');
|
|
@@ -28,7 +29,7 @@ var misc = require('./utils/misc.cjs');
|
|
|
28
29
|
var handlers$1 = require('./utils/handlers.cjs');
|
|
29
30
|
var run$1 = require('./utils/run.cjs');
|
|
30
31
|
var tokens = require('./utils/tokens.cjs');
|
|
31
|
-
var schema$
|
|
32
|
+
var schema$2 = require('./utils/schema.cjs');
|
|
32
33
|
var index = require('./llm/openai/index.cjs');
|
|
33
34
|
|
|
34
35
|
|
|
@@ -78,6 +79,8 @@ exports.Graph = Graph.Graph;
|
|
|
78
79
|
exports.StandardGraph = Graph.StandardGraph;
|
|
79
80
|
exports.MultiAgentGraph = MultiAgentGraph.MultiAgentGraph;
|
|
80
81
|
exports.Calculator = Calculator.Calculator;
|
|
82
|
+
exports.CalculatorSchema = Calculator.CalculatorSchema;
|
|
83
|
+
exports.CodeExecutionToolSchema = CodeExecutor.CodeExecutionToolSchema;
|
|
81
84
|
exports.createCodeExecutionTool = CodeExecutor.createCodeExecutionTool;
|
|
82
85
|
exports.getCodeBaseURL = CodeExecutor.getCodeBaseURL;
|
|
83
86
|
exports.imageExtRegex = CodeExecutor.imageExtRegex;
|
|
@@ -114,6 +117,19 @@ exports.handleToolCallChunks = handlers.handleToolCallChunks;
|
|
|
114
117
|
exports.handleToolCalls = handlers.handleToolCalls;
|
|
115
118
|
exports.toolResultTypes = handlers.toolResultTypes;
|
|
116
119
|
exports.createSearchTool = tool.createSearchTool;
|
|
120
|
+
Object.defineProperty(exports, "DATE_RANGE", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () { return schema$1.DATE_RANGE; }
|
|
123
|
+
});
|
|
124
|
+
exports.DEFAULT_COUNTRY_DESCRIPTION = schema$1.DEFAULT_COUNTRY_DESCRIPTION;
|
|
125
|
+
exports.DEFAULT_QUERY_DESCRIPTION = schema$1.DEFAULT_QUERY_DESCRIPTION;
|
|
126
|
+
exports.WebSearchToolSchema = schema$1.WebSearchToolSchema;
|
|
127
|
+
exports.countrySchema = schema$1.countrySchema;
|
|
128
|
+
exports.dateSchema = schema$1.dateSchema;
|
|
129
|
+
exports.imagesSchema = schema$1.imagesSchema;
|
|
130
|
+
exports.newsSchema = schema$1.newsSchema;
|
|
131
|
+
exports.querySchema = schema$1.querySchema;
|
|
132
|
+
exports.videosSchema = schema$1.videosSchema;
|
|
117
133
|
Object.defineProperty(exports, "Callback", {
|
|
118
134
|
enumerable: true,
|
|
119
135
|
get: function () { return _enum.Callback; }
|
|
@@ -174,7 +190,7 @@ exports.sleep = run$1.sleep;
|
|
|
174
190
|
exports.TokenEncoderManager = tokens.TokenEncoderManager;
|
|
175
191
|
exports.createTokenCounter = tokens.createTokenCounter;
|
|
176
192
|
exports.getTokenCountForMessage = tokens.getTokenCountForMessage;
|
|
177
|
-
exports.isZodSchema = schema$
|
|
178
|
-
exports.toJsonSchema = schema$
|
|
193
|
+
exports.isZodSchema = schema$2.isZodSchema;
|
|
194
|
+
exports.toJsonSchema = schema$2.toJsonSchema;
|
|
179
195
|
exports.CustomOpenAIClient = index.CustomOpenAIClient;
|
|
180
196
|
//# sourceMappingURL=main.cjs.map
|
package/dist/cjs/main.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -22,6 +22,17 @@ function _interopNamespaceDefault(e) {
|
|
|
22
22
|
|
|
23
23
|
var math__namespace = /*#__PURE__*/_interopNamespaceDefault(math);
|
|
24
24
|
|
|
25
|
+
/** Calculator tool schema for structured input */
|
|
26
|
+
const CalculatorSchema = {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
input: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: 'A valid mathematical expression to evaluate',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
required: ['input'],
|
|
35
|
+
};
|
|
25
36
|
class Calculator extends tools.Tool {
|
|
26
37
|
static lc_name() {
|
|
27
38
|
return 'Calculator';
|
|
@@ -42,4 +53,5 @@ class Calculator extends tools.Tool {
|
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
exports.Calculator = Calculator;
|
|
56
|
+
exports.CalculatorSchema = CalculatorSchema;
|
|
45
57
|
//# sourceMappingURL=Calculator.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calculator.cjs","sources":["../../../src/tools/Calculator.ts"],"sourcesContent":["import { Tool } from '@langchain/core/tools';\nimport * as math from 'mathjs';\n\nexport class Calculator extends Tool {\n static lc_name(): string {\n return 'Calculator';\n }\n\n get lc_namespace(): string[] {\n return [...super.lc_namespace, 'calculator'];\n }\n\n name = 'calculator';\n\n async _call(input: string): Promise<string> {\n try {\n return math.evaluate(input).toString();\n } catch {\n return 'I don\\'t know how to do that.';\n }\n }\n\n description =\n 'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.';\n}\n"],"names":["Tool","math"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Calculator.cjs","sources":["../../../src/tools/Calculator.ts"],"sourcesContent":["import { Tool } from '@langchain/core/tools';\nimport * as math from 'mathjs';\n\n/** Calculator tool schema for structured input */\nexport const CalculatorSchema = {\n type: 'object',\n properties: {\n input: {\n type: 'string',\n description: 'A valid mathematical expression to evaluate',\n },\n },\n required: ['input'],\n} as const;\n\nexport class Calculator extends Tool {\n static lc_name(): string {\n return 'Calculator';\n }\n\n get lc_namespace(): string[] {\n return [...super.lc_namespace, 'calculator'];\n }\n\n name = 'calculator';\n\n async _call(input: string): Promise<string> {\n try {\n return math.evaluate(input).toString();\n } catch {\n return 'I don\\'t know how to do that.';\n }\n }\n\n description =\n 'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.';\n}\n"],"names":["Tool","math"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA;AACa,MAAA,gBAAgB,GAAG;AAC9B,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,UAAU,EAAE;AACV,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,WAAW,EAAE,6CAA6C;AAC3D,SAAA;AACF,KAAA;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;;AAGf,MAAO,UAAW,SAAQA,UAAI,CAAA;AAClC,IAAA,OAAO,OAAO,GAAA;AACZ,QAAA,OAAO,YAAY;;AAGrB,IAAA,IAAI,YAAY,GAAA;QACd,OAAO,CAAC,GAAG,KAAK,CAAC,YAAY,EAAE,YAAY,CAAC;;IAG9C,IAAI,GAAG,YAAY;IAEnB,MAAM,KAAK,CAAC,KAAa,EAAA;AACvB,QAAA,IAAI;YACF,OAAOC,eAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;;AACtC,QAAA,MAAM;AACN,YAAA,OAAO,+BAA+B;;;IAI1C,WAAW,GACT,qKAAqK;AACxK;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.cjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { config } from 'dotenv';\nimport fetch, { RequestInit } from 'node-fetch';\nimport { HttpsProxyAgent } from 'https-proxy-agent';\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 =>\n getEnvironmentVariable(EnvVar.CODE_BASEURL) ??\n Constants.OFFICIAL_CODE_BASEURL;\n\nconst imageMessage = 'Image is already displayed to the user';\nconst otherMessage = 'File is already downloaded by the user';\nconst accessMessage =\n 'Note: Files from previous executions are automatically available and can be modified.';\nconst emptyOutputMessage =\n 'stdout: Empty. Ensure you\\'re writing output explicitly.\\n';\n\nconst SUPPORTED_LANGUAGES = [\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] as const;\n\nconst CodeExecutionToolSchema = {\n type: 'object',\n properties: {\n lang: {\n type: 'string',\n enum: SUPPORTED_LANGUAGES,\n description:\n 'The programming language or runtime to execute the code in.',\n },\n code: {\n type: 'string',\n description: `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- Generated files from previous executions are automatically available in \"/mnt/data/\".\n- Files from previous executions are automatically available and can be modified in place.\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 },\n args: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.',\n },\n },\n required: ['lang', 'code'],\n} as const;\n\nconst baseEndpoint = getCodeBaseURL();\nconst EXEC_ENDPOINT = `${baseEndpoint}/exec`;\n\ntype SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];\n\nfunction createCodeExecutionTool(\n params: t.CodeExecutionToolParams = {}\n): DynamicStructuredTool {\n const apiKey =\n params[EnvVar.CODE_API_KEY] ??\n params.apiKey ??\n getEnvironmentVariable(EnvVar.CODE_API_KEY) ??\n '';\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(\n async (rawInput, config) => {\n const { lang, code, ...rest } = rawInput as {\n lang: SupportedLanguage;\n code: string;\n args?: string[];\n };\n /**\n * Extract session context from config.toolCall (injected by ToolNode).\n * - session_id: For API to associate with previous session\n * - _injected_files: File refs to pass directly (avoids /files endpoint race condition)\n */\n const { session_id, _injected_files } = (config.toolCall ?? {}) as {\n session_id?: string;\n _injected_files?: t.CodeEnvFile[];\n };\n\n const postData: Record<string, unknown> = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n /**\n * File injection priority:\n * 1. Use _injected_files from ToolNode (avoids /files endpoint race condition)\n * 2. Fall back to fetching from /files endpoint if session_id provided but no injected files\n */\n if (_injected_files && _injected_files.length > 0) {\n postData.files = _injected_files;\n } else if (session_id != null && session_id.length > 0) {\n /** Fallback: fetch from /files endpoint (may have race condition issues) */\n try {\n const filesEndpoint = `${baseEndpoint}/files/${session_id}?detail=full`;\n const fetchOptions: RequestInit = {\n method: 'GET',\n headers: {\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n };\n\n if (process.env.PROXY != null && process.env.PROXY !== '') {\n fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);\n }\n\n const response = await fetch(filesEndpoint, fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch files for session: ${response.status}`\n );\n }\n\n const files = await response.json();\n if (Array.isArray(files) && files.length > 0) {\n const fileReferences: t.CodeEnvFile[] = files.map((file) => {\n const nameParts = file.name.split('/');\n const id = nameParts.length > 1 ? nameParts[1].split('.')[0] : '';\n\n return {\n session_id,\n id,\n name: file.metadata['original-filename'],\n };\n });\n\n postData.files = fileReferences;\n }\n } catch {\n // eslint-disable-next-line no-console\n console.warn(`Failed to fetch files for session: ${session_id}`);\n }\n }\n\n try {\n const fetchOptions: RequestInit = {\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 (process.env.PROXY != null && process.env.PROXY !== '') {\n fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);\n }\n const response = await fetch(EXEC_ENDPOINT, fetchOptions);\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 += emptyOutputMessage;\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 file = result.files[i];\n const isImage = imageExtRegex.test(file.name);\n formattedOutput += `- /mnt/data/${file.name} | ${isImage ? imageMessage : otherMessage}`;\n\n if (i < fileCount - 1) {\n formattedOutput += fileCount <= 3 ? ', ' : ',\\n';\n }\n }\n\n formattedOutput += `\\n\\n${accessMessage}`;\n return [\n formattedOutput.trim(),\n {\n session_id: result.session_id,\n files: result.files,\n },\n ];\n }\n\n return [formattedOutput.trim(), { session_id: result.session_id }];\n } catch (error) {\n throw new Error(\n `Execution error:\\n\\n${(error as Error | undefined)?.message}`\n );\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 };\n"],"names":["config","getEnvironmentVariable","EnvVar","Constants","tool","HttpsProxyAgent"],"mappings":";;;;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AG,YAAY,EAAE;AAExF,oBAAA,IAAI,CAAC,GAAG,SAAS,GAAG,CAAC,EAAE;AACrB,wBAAA,eAAe,IAAI,SAAS,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK;;;AAIpD,gBAAA,eAAe,IAAI,CAAA,IAAA,EAAO,aAAa,CAAA,CAAE;gBACzC,OAAO;oBACL,eAAe,CAAC,IAAI,EAAE;AACtB,oBAAA;wBACE,UAAU,EAAE,MAAM,CAAC,UAAU;wBAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;AACpB,qBAAA;iBACF;;AAGH,YAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;;QAClE,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,CAAA,oBAAA,EAAwB,KAA2B,EAAE,OAAO,CAAE,CAAA,CAC/D;;AAEL,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;AACH;;;;;;"}
|
|
1
|
+
{"version":3,"file":"CodeExecutor.cjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { config } from 'dotenv';\nimport fetch, { RequestInit } from 'node-fetch';\nimport { HttpsProxyAgent } from 'https-proxy-agent';\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 =>\n getEnvironmentVariable(EnvVar.CODE_BASEURL) ??\n Constants.OFFICIAL_CODE_BASEURL;\n\nconst imageMessage = 'Image is already displayed to the user';\nconst otherMessage = 'File is already downloaded by the user';\nconst accessMessage =\n 'Note: Files from previous executions are automatically available and can be modified.';\nconst emptyOutputMessage =\n 'stdout: Empty. Ensure you\\'re writing output explicitly.\\n';\n\nconst SUPPORTED_LANGUAGES = [\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] as const;\n\nexport const CodeExecutionToolSchema = {\n type: 'object',\n properties: {\n lang: {\n type: 'string',\n enum: SUPPORTED_LANGUAGES,\n description:\n 'The programming language or runtime to execute the code in.',\n },\n code: {\n type: 'string',\n description: `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- Generated files from previous executions are automatically available in \"/mnt/data/\".\n- Files from previous executions are automatically available and can be modified in place.\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 },\n args: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.',\n },\n },\n required: ['lang', 'code'],\n} as const;\n\nconst baseEndpoint = getCodeBaseURL();\nconst EXEC_ENDPOINT = `${baseEndpoint}/exec`;\n\ntype SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];\n\nfunction createCodeExecutionTool(\n params: t.CodeExecutionToolParams = {}\n): DynamicStructuredTool {\n const apiKey =\n params[EnvVar.CODE_API_KEY] ??\n params.apiKey ??\n getEnvironmentVariable(EnvVar.CODE_API_KEY) ??\n '';\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(\n async (rawInput, config) => {\n const { lang, code, ...rest } = rawInput as {\n lang: SupportedLanguage;\n code: string;\n args?: string[];\n };\n /**\n * Extract session context from config.toolCall (injected by ToolNode).\n * - session_id: For API to associate with previous session\n * - _injected_files: File refs to pass directly (avoids /files endpoint race condition)\n */\n const { session_id, _injected_files } = (config.toolCall ?? {}) as {\n session_id?: string;\n _injected_files?: t.CodeEnvFile[];\n };\n\n const postData: Record<string, unknown> = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n /**\n * File injection priority:\n * 1. Use _injected_files from ToolNode (avoids /files endpoint race condition)\n * 2. Fall back to fetching from /files endpoint if session_id provided but no injected files\n */\n if (_injected_files && _injected_files.length > 0) {\n postData.files = _injected_files;\n } else if (session_id != null && session_id.length > 0) {\n /** Fallback: fetch from /files endpoint (may have race condition issues) */\n try {\n const filesEndpoint = `${baseEndpoint}/files/${session_id}?detail=full`;\n const fetchOptions: RequestInit = {\n method: 'GET',\n headers: {\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n };\n\n if (process.env.PROXY != null && process.env.PROXY !== '') {\n fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);\n }\n\n const response = await fetch(filesEndpoint, fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch files for session: ${response.status}`\n );\n }\n\n const files = await response.json();\n if (Array.isArray(files) && files.length > 0) {\n const fileReferences: t.CodeEnvFile[] = files.map((file) => {\n const nameParts = file.name.split('/');\n const id = nameParts.length > 1 ? nameParts[1].split('.')[0] : '';\n\n return {\n session_id,\n id,\n name: file.metadata['original-filename'],\n };\n });\n\n postData.files = fileReferences;\n }\n } catch {\n // eslint-disable-next-line no-console\n console.warn(`Failed to fetch files for session: ${session_id}`);\n }\n }\n\n try {\n const fetchOptions: RequestInit = {\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 (process.env.PROXY != null && process.env.PROXY !== '') {\n fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);\n }\n const response = await fetch(EXEC_ENDPOINT, fetchOptions);\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 += emptyOutputMessage;\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 file = result.files[i];\n const isImage = imageExtRegex.test(file.name);\n formattedOutput += `- /mnt/data/${file.name} | ${isImage ? imageMessage : otherMessage}`;\n\n if (i < fileCount - 1) {\n formattedOutput += fileCount <= 3 ? ', ' : ',\\n';\n }\n }\n\n formattedOutput += `\\n\\n${accessMessage}`;\n return [\n formattedOutput.trim(),\n {\n session_id: result.session_id,\n files: result.files,\n },\n ];\n }\n\n return [formattedOutput.trim(), { session_id: result.session_id }];\n } catch (error) {\n throw new Error(\n `Execution error:\\n\\n${(error as Error | undefined)?.message}`\n );\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 };\n"],"names":["config","getEnvironmentVariable","EnvVar","Constants","tool","HttpsProxyAgent"],"mappings":";;;;;;;;;AAQAA,aAAM,EAAE;AAED,MAAM,aAAa,GAAG;AACtB,MAAM,cAAc,GAAG,MAC5BC,0BAAsB,CAACC,YAAM,CAAC,YAAY,CAAC;IAC3CC,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KAAK;;;AAIpD,gBAAA,eAAe,IAAI,CAAA,IAAA,EAAO,aAAa,CAAA,CAAE;gBACzC,OAAO;oBACL,eAAe,CAAC,IAAI,EAAE;AACtB,oBAAA;wBACE,UAAU,EAAE,MAAM,CAAC,UAAU;wBAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;AACpB,qBAAA;iBACF;;AAGH,YAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;;QAClE,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,CAAA,oBAAA,EAAwB,KAA2B,EAAE,OAAO,CAAE,CAAA,CAC/D;;AAEL,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;AACH;;;;;;;"}
|
|
@@ -60,9 +60,23 @@ const newsSchema = {
|
|
|
60
60
|
type: 'boolean',
|
|
61
61
|
description: 'Whether to also run a news search.',
|
|
62
62
|
};
|
|
63
|
+
/** Combined web search tool schema with all properties */
|
|
64
|
+
const WebSearchToolSchema = {
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
query: querySchema,
|
|
68
|
+
date: dateSchema,
|
|
69
|
+
country: countrySchema,
|
|
70
|
+
images: imagesSchema,
|
|
71
|
+
videos: videosSchema,
|
|
72
|
+
news: newsSchema,
|
|
73
|
+
},
|
|
74
|
+
required: ['query'],
|
|
75
|
+
};
|
|
63
76
|
|
|
64
77
|
exports.DEFAULT_COUNTRY_DESCRIPTION = DEFAULT_COUNTRY_DESCRIPTION;
|
|
65
78
|
exports.DEFAULT_QUERY_DESCRIPTION = DEFAULT_QUERY_DESCRIPTION;
|
|
79
|
+
exports.WebSearchToolSchema = WebSearchToolSchema;
|
|
66
80
|
exports.countrySchema = countrySchema;
|
|
67
81
|
exports.dateSchema = dateSchema;
|
|
68
82
|
exports.imagesSchema = imagesSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.cjs","sources":["../../../../src/tools/search/schema.ts"],"sourcesContent":["export enum DATE_RANGE {\n PAST_HOUR = 'h',\n PAST_24_HOURS = 'd',\n PAST_WEEK = 'w',\n PAST_MONTH = 'm',\n PAST_YEAR = 'y',\n}\n\nexport const DEFAULT_QUERY_DESCRIPTION = `\nGUIDELINES:\n- Start broad, then narrow: Begin with key concepts, then refine with specifics\n- Think like sources: Use terminology experts would use in the field\n- Consider perspective: Frame queries from different viewpoints for better results\n- Quality over quantity: A precise 3-4 word query often beats lengthy sentences\n\nTECHNIQUES (combine for power searches):\n- EXACT PHRASES: Use quotes (\"climate change report\")\n- EXCLUDE TERMS: Use minus to remove unwanted results (-wikipedia)\n- SITE-SPECIFIC: Restrict to websites (site:edu research)\n- FILETYPE: Find specific documents (filetype:pdf study)\n- OR OPERATOR: Find alternatives (electric OR hybrid cars)\n- DATE RANGE: Recent information (data after:2020)\n- WILDCARDS: Use * for unknown terms (how to * bread)\n- SPECIFIC QUESTIONS: Use who/what/when/where/why/how\n- DOMAIN TERMS: Include technical terminology for specialized topics\n- CONCISE TERMS: Prioritize keywords over sentences\n`.trim();\n\nexport const DEFAULT_COUNTRY_DESCRIPTION =\n `Country code to localize search results.\nUse standard 2-letter country codes: \"us\", \"uk\", \"ca\", \"de\", \"fr\", \"jp\", \"br\", etc.\nProvide this when the search should return results specific to a particular country.\nExamples:\n- \"us\" for United States (default)\n- \"de\" for Germany\n- \"in\" for India\n`.trim();\n\nexport const querySchema = {\n type: 'string',\n description: DEFAULT_QUERY_DESCRIPTION,\n} as const;\n\nexport const dateSchema = {\n type: 'string',\n enum: Object.values(DATE_RANGE),\n description: 'Date range for search results.',\n} as const;\n\nexport const countrySchema = {\n type: 'string',\n description: DEFAULT_COUNTRY_DESCRIPTION,\n} as const;\n\nexport const imagesSchema = {\n type: 'boolean',\n description: 'Whether to also run an image search.',\n} as const;\n\nexport const videosSchema = {\n type: 'boolean',\n description: 'Whether to also run a video search.',\n} as const;\n\nexport const newsSchema = {\n type: 'boolean',\n description: 'Whether to also run a news search.',\n} as const;\n"],"names":["DATE_RANGE"],"mappings":";;AAAYA;AAAZ,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACf,IAAA,UAAA,CAAA,eAAA,CAAA,GAAA,GAAmB;AACnB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACf,IAAA,UAAA,CAAA,YAAA,CAAA,GAAA,GAAgB;AAChB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACjB,CAAC,EANWA,kBAAU,KAAVA,kBAAU,GAMrB,EAAA,CAAA,CAAA;AAEY,MAAA,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;CAkBxC,CAAC,IAAI;AAEO,MAAA,2BAA2B,GACtC,CAAA;;;;;;;CAOD,CAAC,IAAI;AAEO,MAAA,WAAW,GAAG;AACzB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,WAAW,EAAE,yBAAyB;;AAG3B,MAAA,UAAU,GAAG;AACxB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,IAAI,EAAE,MAAM,CAAC,MAAM,CAACA,kBAAU,CAAC;AAC/B,IAAA,WAAW,EAAE,gCAAgC;;AAGlC,MAAA,aAAa,GAAG;AAC3B,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,WAAW,EAAE,2BAA2B;;AAG7B,MAAA,YAAY,GAAG;AAC1B,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,sCAAsC;;AAGxC,MAAA,YAAY,GAAG;AAC1B,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,qCAAqC;;AAGvC,MAAA,UAAU,GAAG;AACxB,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,oCAAoC
|
|
1
|
+
{"version":3,"file":"schema.cjs","sources":["../../../../src/tools/search/schema.ts"],"sourcesContent":["export enum DATE_RANGE {\n PAST_HOUR = 'h',\n PAST_24_HOURS = 'd',\n PAST_WEEK = 'w',\n PAST_MONTH = 'm',\n PAST_YEAR = 'y',\n}\n\nexport const DEFAULT_QUERY_DESCRIPTION = `\nGUIDELINES:\n- Start broad, then narrow: Begin with key concepts, then refine with specifics\n- Think like sources: Use terminology experts would use in the field\n- Consider perspective: Frame queries from different viewpoints for better results\n- Quality over quantity: A precise 3-4 word query often beats lengthy sentences\n\nTECHNIQUES (combine for power searches):\n- EXACT PHRASES: Use quotes (\"climate change report\")\n- EXCLUDE TERMS: Use minus to remove unwanted results (-wikipedia)\n- SITE-SPECIFIC: Restrict to websites (site:edu research)\n- FILETYPE: Find specific documents (filetype:pdf study)\n- OR OPERATOR: Find alternatives (electric OR hybrid cars)\n- DATE RANGE: Recent information (data after:2020)\n- WILDCARDS: Use * for unknown terms (how to * bread)\n- SPECIFIC QUESTIONS: Use who/what/when/where/why/how\n- DOMAIN TERMS: Include technical terminology for specialized topics\n- CONCISE TERMS: Prioritize keywords over sentences\n`.trim();\n\nexport const DEFAULT_COUNTRY_DESCRIPTION =\n `Country code to localize search results.\nUse standard 2-letter country codes: \"us\", \"uk\", \"ca\", \"de\", \"fr\", \"jp\", \"br\", etc.\nProvide this when the search should return results specific to a particular country.\nExamples:\n- \"us\" for United States (default)\n- \"de\" for Germany\n- \"in\" for India\n`.trim();\n\nexport const querySchema = {\n type: 'string',\n description: DEFAULT_QUERY_DESCRIPTION,\n} as const;\n\nexport const dateSchema = {\n type: 'string',\n enum: Object.values(DATE_RANGE),\n description: 'Date range for search results.',\n} as const;\n\nexport const countrySchema = {\n type: 'string',\n description: DEFAULT_COUNTRY_DESCRIPTION,\n} as const;\n\nexport const imagesSchema = {\n type: 'boolean',\n description: 'Whether to also run an image search.',\n} as const;\n\nexport const videosSchema = {\n type: 'boolean',\n description: 'Whether to also run a video search.',\n} as const;\n\nexport const newsSchema = {\n type: 'boolean',\n description: 'Whether to also run a news search.',\n} as const;\n\n/** Combined web search tool schema with all properties */\nexport const WebSearchToolSchema = {\n type: 'object',\n properties: {\n query: querySchema,\n date: dateSchema,\n country: countrySchema,\n images: imagesSchema,\n videos: videosSchema,\n news: newsSchema,\n },\n required: ['query'],\n} as const;\n"],"names":["DATE_RANGE"],"mappings":";;AAAYA;AAAZ,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACf,IAAA,UAAA,CAAA,eAAA,CAAA,GAAA,GAAmB;AACnB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACf,IAAA,UAAA,CAAA,YAAA,CAAA,GAAA,GAAgB;AAChB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACjB,CAAC,EANWA,kBAAU,KAAVA,kBAAU,GAMrB,EAAA,CAAA,CAAA;AAEY,MAAA,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;CAkBxC,CAAC,IAAI;AAEO,MAAA,2BAA2B,GACtC,CAAA;;;;;;;CAOD,CAAC,IAAI;AAEO,MAAA,WAAW,GAAG;AACzB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,WAAW,EAAE,yBAAyB;;AAG3B,MAAA,UAAU,GAAG;AACxB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,IAAI,EAAE,MAAM,CAAC,MAAM,CAACA,kBAAU,CAAC;AAC/B,IAAA,WAAW,EAAE,gCAAgC;;AAGlC,MAAA,aAAa,GAAG;AAC3B,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,WAAW,EAAE,2BAA2B;;AAG7B,MAAA,YAAY,GAAG;AAC1B,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,sCAAsC;;AAGxC,MAAA,YAAY,GAAG;AAC1B,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,qCAAqC;;AAGvC,MAAA,UAAU,GAAG;AACxB,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,oCAAoC;;AAGnD;AACa,MAAA,mBAAmB,GAAG;AACjC,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,UAAU,EAAE;AACV,QAAA,KAAK,EAAE,WAAW;AAClB,QAAA,IAAI,EAAE,UAAU;AAChB,QAAA,OAAO,EAAE,aAAa;AACtB,QAAA,MAAM,EAAE,YAAY;AACpB,QAAA,MAAM,EAAE,YAAY;AACpB,QAAA,IAAI,EAAE,UAAU;AACjB,KAAA;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;;;;;;;;;;;;;"}
|
package/dist/esm/main.mjs
CHANGED
|
@@ -11,14 +11,15 @@ export { formatContentStrings } from './messages/content.mjs';
|
|
|
11
11
|
export { extractToolDiscoveries, hasToolSearchInCurrentTurn } from './messages/tools.mjs';
|
|
12
12
|
export { Graph, StandardGraph } from './graphs/Graph.mjs';
|
|
13
13
|
export { MultiAgentGraph } from './graphs/MultiAgentGraph.mjs';
|
|
14
|
-
export { Calculator } from './tools/Calculator.mjs';
|
|
15
|
-
export { createCodeExecutionTool, getCodeBaseURL, imageExtRegex } from './tools/CodeExecutor.mjs';
|
|
14
|
+
export { Calculator, CalculatorSchema } from './tools/Calculator.mjs';
|
|
15
|
+
export { CodeExecutionToolSchema, createCodeExecutionTool, getCodeBaseURL, imageExtRegex } from './tools/CodeExecutor.mjs';
|
|
16
16
|
export { createProgrammaticToolCallingTool, executeTools, extractUsedToolNames, fetchSessionFiles, filterToolsByUsage, formatCompletedResponse, makeRequest, normalizeToPythonIdentifier, unwrapToolResponse } from './tools/ProgrammaticToolCalling.mjs';
|
|
17
17
|
export { countNestedGroups, createToolSearch, escapeRegexSpecialChars, extractMcpServerName, formatServerListing, getAvailableMcpServers, getBaseToolName, getDeferredToolsListing, hasNestedQuantifiers, isDangerousPattern, isFromAnyMcpServer, isFromMcpServer, normalizeServerFilter, performLocalSearch, sanitizeRegex } from './tools/ToolSearch.mjs';
|
|
18
18
|
export { ToolNode, toolsCondition } from './tools/ToolNode.mjs';
|
|
19
19
|
export { createSchemaOnlyTool, createSchemaOnlyTools } from './tools/schema.mjs';
|
|
20
20
|
export { handleServerToolResult, handleToolCallChunks, handleToolCalls, toolResultTypes } from './tools/handlers.mjs';
|
|
21
21
|
export { createSearchTool } from './tools/search/tool.mjs';
|
|
22
|
+
export { DATE_RANGE, DEFAULT_COUNTRY_DESCRIPTION, DEFAULT_QUERY_DESCRIPTION, WebSearchToolSchema, countrySchema, dateSchema, imagesSchema, newsSchema, querySchema, videosSchema } from './tools/search/schema.mjs';
|
|
22
23
|
export { Callback, CommonEvents, Constants, ContentTypes, EnvVar, GraphEvents, GraphNodeActions, GraphNodeKeys, Providers, StepTypes, TitleMethod, ToolCallTypes } from './common/enum.mjs';
|
|
23
24
|
export { joinKeys, resetIfNotEmpty } from './utils/graph.mjs';
|
|
24
25
|
export { isGoogleLike, isOpenAILike } from './utils/llm.mjs';
|
package/dist/esm/main.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { Tool } from '@langchain/core/tools';
|
|
2
2
|
import * as math from 'mathjs';
|
|
3
3
|
|
|
4
|
+
/** Calculator tool schema for structured input */
|
|
5
|
+
const CalculatorSchema = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
input: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
description: 'A valid mathematical expression to evaluate',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
required: ['input'],
|
|
14
|
+
};
|
|
4
15
|
class Calculator extends Tool {
|
|
5
16
|
static lc_name() {
|
|
6
17
|
return 'Calculator';
|
|
@@ -20,5 +31,5 @@ class Calculator extends Tool {
|
|
|
20
31
|
description = 'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.';
|
|
21
32
|
}
|
|
22
33
|
|
|
23
|
-
export { Calculator };
|
|
34
|
+
export { Calculator, CalculatorSchema };
|
|
24
35
|
//# sourceMappingURL=Calculator.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calculator.mjs","sources":["../../../src/tools/Calculator.ts"],"sourcesContent":["import { Tool } from '@langchain/core/tools';\nimport * as math from 'mathjs';\n\nexport class Calculator extends Tool {\n static lc_name(): string {\n return 'Calculator';\n }\n\n get lc_namespace(): string[] {\n return [...super.lc_namespace, 'calculator'];\n }\n\n name = 'calculator';\n\n async _call(input: string): Promise<string> {\n try {\n return math.evaluate(input).toString();\n } catch {\n return 'I don\\'t know how to do that.';\n }\n }\n\n description =\n 'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.';\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Calculator.mjs","sources":["../../../src/tools/Calculator.ts"],"sourcesContent":["import { Tool } from '@langchain/core/tools';\nimport * as math from 'mathjs';\n\n/** Calculator tool schema for structured input */\nexport const CalculatorSchema = {\n type: 'object',\n properties: {\n input: {\n type: 'string',\n description: 'A valid mathematical expression to evaluate',\n },\n },\n required: ['input'],\n} as const;\n\nexport class Calculator extends Tool {\n static lc_name(): string {\n return 'Calculator';\n }\n\n get lc_namespace(): string[] {\n return [...super.lc_namespace, 'calculator'];\n }\n\n name = 'calculator';\n\n async _call(input: string): Promise<string> {\n try {\n return math.evaluate(input).toString();\n } catch {\n return 'I don\\'t know how to do that.';\n }\n }\n\n description =\n 'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.';\n}\n"],"names":[],"mappings":";;;AAGA;AACa,MAAA,gBAAgB,GAAG;AAC9B,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,UAAU,EAAE;AACV,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,WAAW,EAAE,6CAA6C;AAC3D,SAAA;AACF,KAAA;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;;AAGf,MAAO,UAAW,SAAQ,IAAI,CAAA;AAClC,IAAA,OAAO,OAAO,GAAA;AACZ,QAAA,OAAO,YAAY;;AAGrB,IAAA,IAAI,YAAY,GAAA;QACd,OAAO,CAAC,GAAG,KAAK,CAAC,YAAY,EAAE,YAAY,CAAC;;IAG9C,IAAI,GAAG,YAAY;IAEnB,MAAM,KAAK,CAAC,KAAa,EAAA;AACvB,QAAA,IAAI;YACF,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;;AACtC,QAAA,MAAM;AACN,YAAA,OAAO,+BAA+B;;;IAI1C,WAAW,GACT,qKAAqK;AACxK;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.mjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { config } from 'dotenv';\nimport fetch, { RequestInit } from 'node-fetch';\nimport { HttpsProxyAgent } from 'https-proxy-agent';\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 =>\n getEnvironmentVariable(EnvVar.CODE_BASEURL) ??\n Constants.OFFICIAL_CODE_BASEURL;\n\nconst imageMessage = 'Image is already displayed to the user';\nconst otherMessage = 'File is already downloaded by the user';\nconst accessMessage =\n 'Note: Files from previous executions are automatically available and can be modified.';\nconst emptyOutputMessage =\n 'stdout: Empty. Ensure you\\'re writing output explicitly.\\n';\n\nconst SUPPORTED_LANGUAGES = [\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] as const;\n\nconst CodeExecutionToolSchema = {\n type: 'object',\n properties: {\n lang: {\n type: 'string',\n enum: SUPPORTED_LANGUAGES,\n description:\n 'The programming language or runtime to execute the code in.',\n },\n code: {\n type: 'string',\n description: `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- Generated files from previous executions are automatically available in \"/mnt/data/\".\n- Files from previous executions are automatically available and can be modified in place.\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 },\n args: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.',\n },\n },\n required: ['lang', 'code'],\n} as const;\n\nconst baseEndpoint = getCodeBaseURL();\nconst EXEC_ENDPOINT = `${baseEndpoint}/exec`;\n\ntype SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];\n\nfunction createCodeExecutionTool(\n params: t.CodeExecutionToolParams = {}\n): DynamicStructuredTool {\n const apiKey =\n params[EnvVar.CODE_API_KEY] ??\n params.apiKey ??\n getEnvironmentVariable(EnvVar.CODE_API_KEY) ??\n '';\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(\n async (rawInput, config) => {\n const { lang, code, ...rest } = rawInput as {\n lang: SupportedLanguage;\n code: string;\n args?: string[];\n };\n /**\n * Extract session context from config.toolCall (injected by ToolNode).\n * - session_id: For API to associate with previous session\n * - _injected_files: File refs to pass directly (avoids /files endpoint race condition)\n */\n const { session_id, _injected_files } = (config.toolCall ?? {}) as {\n session_id?: string;\n _injected_files?: t.CodeEnvFile[];\n };\n\n const postData: Record<string, unknown> = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n /**\n * File injection priority:\n * 1. Use _injected_files from ToolNode (avoids /files endpoint race condition)\n * 2. Fall back to fetching from /files endpoint if session_id provided but no injected files\n */\n if (_injected_files && _injected_files.length > 0) {\n postData.files = _injected_files;\n } else if (session_id != null && session_id.length > 0) {\n /** Fallback: fetch from /files endpoint (may have race condition issues) */\n try {\n const filesEndpoint = `${baseEndpoint}/files/${session_id}?detail=full`;\n const fetchOptions: RequestInit = {\n method: 'GET',\n headers: {\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n };\n\n if (process.env.PROXY != null && process.env.PROXY !== '') {\n fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);\n }\n\n const response = await fetch(filesEndpoint, fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch files for session: ${response.status}`\n );\n }\n\n const files = await response.json();\n if (Array.isArray(files) && files.length > 0) {\n const fileReferences: t.CodeEnvFile[] = files.map((file) => {\n const nameParts = file.name.split('/');\n const id = nameParts.length > 1 ? nameParts[1].split('.')[0] : '';\n\n return {\n session_id,\n id,\n name: file.metadata['original-filename'],\n };\n });\n\n postData.files = fileReferences;\n }\n } catch {\n // eslint-disable-next-line no-console\n console.warn(`Failed to fetch files for session: ${session_id}`);\n }\n }\n\n try {\n const fetchOptions: RequestInit = {\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 (process.env.PROXY != null && process.env.PROXY !== '') {\n fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);\n }\n const response = await fetch(EXEC_ENDPOINT, fetchOptions);\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 += emptyOutputMessage;\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 file = result.files[i];\n const isImage = imageExtRegex.test(file.name);\n formattedOutput += `- /mnt/data/${file.name} | ${isImage ? imageMessage : otherMessage}`;\n\n if (i < fileCount - 1) {\n formattedOutput += fileCount <= 3 ? ', ' : ',\\n';\n }\n }\n\n formattedOutput += `\\n\\n${accessMessage}`;\n return [\n formattedOutput.trim(),\n {\n session_id: result.session_id,\n files: result.files,\n },\n ];\n }\n\n return [formattedOutput.trim(), { session_id: result.session_id }];\n } catch (error) {\n throw new Error(\n `Execution error:\\n\\n${(error as Error | undefined)?.message}`\n );\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 };\n"],"names":[],"mappings":";;;;;;;AAQA,MAAM,EAAE;AAED,MAAM,aAAa,GAAG;AACtB,MAAM,cAAc,GAAG,MAC5B,sBAAsB,CAAC,MAAM,CAAC,YAAY,CAAC;IAC3C,SAAS,CAAC;AAEZ,MAAM,YAAY,GAAG,wCAAwC;AAC7D,MAAM,YAAY,GAAG,wCAAwC;AAC7D,MAAM,aAAa,GACjB,uFAAuF;AACzF,MAAM,kBAAkB,GACtB,4DAA4D;AAE9D,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UAAU;wBAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;AACpB,qBAAA;iBACF;;AAGH,YAAA,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;;QAClE,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,CAAA,oBAAA,EAAwB,KAA2B,EAAE,OAAO,CAAE,CAAA,CAC/D;;AAEL,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;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"CodeExecutor.mjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { config } from 'dotenv';\nimport fetch, { RequestInit } from 'node-fetch';\nimport { HttpsProxyAgent } from 'https-proxy-agent';\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 =>\n getEnvironmentVariable(EnvVar.CODE_BASEURL) ??\n Constants.OFFICIAL_CODE_BASEURL;\n\nconst imageMessage = 'Image is already displayed to the user';\nconst otherMessage = 'File is already downloaded by the user';\nconst accessMessage =\n 'Note: Files from previous executions are automatically available and can be modified.';\nconst emptyOutputMessage =\n 'stdout: Empty. Ensure you\\'re writing output explicitly.\\n';\n\nconst SUPPORTED_LANGUAGES = [\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] as const;\n\nexport const CodeExecutionToolSchema = {\n type: 'object',\n properties: {\n lang: {\n type: 'string',\n enum: SUPPORTED_LANGUAGES,\n description:\n 'The programming language or runtime to execute the code in.',\n },\n code: {\n type: 'string',\n description: `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- Generated files from previous executions are automatically available in \"/mnt/data/\".\n- Files from previous executions are automatically available and can be modified in place.\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 },\n args: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.',\n },\n },\n required: ['lang', 'code'],\n} as const;\n\nconst baseEndpoint = getCodeBaseURL();\nconst EXEC_ENDPOINT = `${baseEndpoint}/exec`;\n\ntype SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];\n\nfunction createCodeExecutionTool(\n params: t.CodeExecutionToolParams = {}\n): DynamicStructuredTool {\n const apiKey =\n params[EnvVar.CODE_API_KEY] ??\n params.apiKey ??\n getEnvironmentVariable(EnvVar.CODE_API_KEY) ??\n '';\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(\n async (rawInput, config) => {\n const { lang, code, ...rest } = rawInput as {\n lang: SupportedLanguage;\n code: string;\n args?: string[];\n };\n /**\n * Extract session context from config.toolCall (injected by ToolNode).\n * - session_id: For API to associate with previous session\n * - _injected_files: File refs to pass directly (avoids /files endpoint race condition)\n */\n const { session_id, _injected_files } = (config.toolCall ?? {}) as {\n session_id?: string;\n _injected_files?: t.CodeEnvFile[];\n };\n\n const postData: Record<string, unknown> = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n /**\n * File injection priority:\n * 1. Use _injected_files from ToolNode (avoids /files endpoint race condition)\n * 2. Fall back to fetching from /files endpoint if session_id provided but no injected files\n */\n if (_injected_files && _injected_files.length > 0) {\n postData.files = _injected_files;\n } else if (session_id != null && session_id.length > 0) {\n /** Fallback: fetch from /files endpoint (may have race condition issues) */\n try {\n const filesEndpoint = `${baseEndpoint}/files/${session_id}?detail=full`;\n const fetchOptions: RequestInit = {\n method: 'GET',\n headers: {\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n };\n\n if (process.env.PROXY != null && process.env.PROXY !== '') {\n fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);\n }\n\n const response = await fetch(filesEndpoint, fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch files for session: ${response.status}`\n );\n }\n\n const files = await response.json();\n if (Array.isArray(files) && files.length > 0) {\n const fileReferences: t.CodeEnvFile[] = files.map((file) => {\n const nameParts = file.name.split('/');\n const id = nameParts.length > 1 ? nameParts[1].split('.')[0] : '';\n\n return {\n session_id,\n id,\n name: file.metadata['original-filename'],\n };\n });\n\n postData.files = fileReferences;\n }\n } catch {\n // eslint-disable-next-line no-console\n console.warn(`Failed to fetch files for session: ${session_id}`);\n }\n }\n\n try {\n const fetchOptions: RequestInit = {\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 (process.env.PROXY != null && process.env.PROXY !== '') {\n fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);\n }\n const response = await fetch(EXEC_ENDPOINT, fetchOptions);\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 += emptyOutputMessage;\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 file = result.files[i];\n const isImage = imageExtRegex.test(file.name);\n formattedOutput += `- /mnt/data/${file.name} | ${isImage ? imageMessage : otherMessage}`;\n\n if (i < fileCount - 1) {\n formattedOutput += fileCount <= 3 ? ', ' : ',\\n';\n }\n }\n\n formattedOutput += `\\n\\n${accessMessage}`;\n return [\n formattedOutput.trim(),\n {\n session_id: result.session_id,\n files: result.files,\n },\n ];\n }\n\n return [formattedOutput.trim(), { session_id: result.session_id }];\n } catch (error) {\n throw new Error(\n `Execution error:\\n\\n${(error as Error | undefined)?.message}`\n );\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 };\n"],"names":[],"mappings":";;;;;;;AAQA,MAAM,EAAE;AAED,MAAM,aAAa,GAAG;AACtB,MAAM,cAAc,GAAG,MAC5B,sBAAsB,CAAC,MAAM,CAAC,YAAY,CAAC;IAC3C,SAAS,CAAC;AAEZ,MAAM,YAAY,GAAG,wCAAwC;AAC7D,MAAM,YAAY,GAAG,wCAAwC;AAC7D,MAAM,aAAa,GACjB,uFAAuF;AACzF,MAAM,kBAAkB,GACtB,4DAA4D;AAE9D,MAAM,mBAAmB,GAAG;IAC1B,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,KAAK;IACL,MAAM;IACN,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,KAAK;IACL,GAAG;CACK;AAEG,MAAA,uBAAuB,GAAG;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d,MAAM,IAAI,KAAK,CACb,CAAA,oBAAA,EAAwB,KAA2B,EAAE,OAAO,CAAE,CAAA,CAC/D;;AAEL,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;AACH;;;;"}
|
|
@@ -58,6 +58,19 @@ const newsSchema = {
|
|
|
58
58
|
type: 'boolean',
|
|
59
59
|
description: 'Whether to also run a news search.',
|
|
60
60
|
};
|
|
61
|
+
/** Combined web search tool schema with all properties */
|
|
62
|
+
const WebSearchToolSchema = {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
query: querySchema,
|
|
66
|
+
date: dateSchema,
|
|
67
|
+
country: countrySchema,
|
|
68
|
+
images: imagesSchema,
|
|
69
|
+
videos: videosSchema,
|
|
70
|
+
news: newsSchema,
|
|
71
|
+
},
|
|
72
|
+
required: ['query'],
|
|
73
|
+
};
|
|
61
74
|
|
|
62
|
-
export { DATE_RANGE, DEFAULT_COUNTRY_DESCRIPTION, DEFAULT_QUERY_DESCRIPTION, countrySchema, dateSchema, imagesSchema, newsSchema, querySchema, videosSchema };
|
|
75
|
+
export { DATE_RANGE, DEFAULT_COUNTRY_DESCRIPTION, DEFAULT_QUERY_DESCRIPTION, WebSearchToolSchema, countrySchema, dateSchema, imagesSchema, newsSchema, querySchema, videosSchema };
|
|
63
76
|
//# sourceMappingURL=schema.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","sources":["../../../../src/tools/search/schema.ts"],"sourcesContent":["export enum DATE_RANGE {\n PAST_HOUR = 'h',\n PAST_24_HOURS = 'd',\n PAST_WEEK = 'w',\n PAST_MONTH = 'm',\n PAST_YEAR = 'y',\n}\n\nexport const DEFAULT_QUERY_DESCRIPTION = `\nGUIDELINES:\n- Start broad, then narrow: Begin with key concepts, then refine with specifics\n- Think like sources: Use terminology experts would use in the field\n- Consider perspective: Frame queries from different viewpoints for better results\n- Quality over quantity: A precise 3-4 word query often beats lengthy sentences\n\nTECHNIQUES (combine for power searches):\n- EXACT PHRASES: Use quotes (\"climate change report\")\n- EXCLUDE TERMS: Use minus to remove unwanted results (-wikipedia)\n- SITE-SPECIFIC: Restrict to websites (site:edu research)\n- FILETYPE: Find specific documents (filetype:pdf study)\n- OR OPERATOR: Find alternatives (electric OR hybrid cars)\n- DATE RANGE: Recent information (data after:2020)\n- WILDCARDS: Use * for unknown terms (how to * bread)\n- SPECIFIC QUESTIONS: Use who/what/when/where/why/how\n- DOMAIN TERMS: Include technical terminology for specialized topics\n- CONCISE TERMS: Prioritize keywords over sentences\n`.trim();\n\nexport const DEFAULT_COUNTRY_DESCRIPTION =\n `Country code to localize search results.\nUse standard 2-letter country codes: \"us\", \"uk\", \"ca\", \"de\", \"fr\", \"jp\", \"br\", etc.\nProvide this when the search should return results specific to a particular country.\nExamples:\n- \"us\" for United States (default)\n- \"de\" for Germany\n- \"in\" for India\n`.trim();\n\nexport const querySchema = {\n type: 'string',\n description: DEFAULT_QUERY_DESCRIPTION,\n} as const;\n\nexport const dateSchema = {\n type: 'string',\n enum: Object.values(DATE_RANGE),\n description: 'Date range for search results.',\n} as const;\n\nexport const countrySchema = {\n type: 'string',\n description: DEFAULT_COUNTRY_DESCRIPTION,\n} as const;\n\nexport const imagesSchema = {\n type: 'boolean',\n description: 'Whether to also run an image search.',\n} as const;\n\nexport const videosSchema = {\n type: 'boolean',\n description: 'Whether to also run a video search.',\n} as const;\n\nexport const newsSchema = {\n type: 'boolean',\n description: 'Whether to also run a news search.',\n} as const;\n"],"names":[],"mappings":"IAAY;AAAZ,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACf,IAAA,UAAA,CAAA,eAAA,CAAA,GAAA,GAAmB;AACnB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACf,IAAA,UAAA,CAAA,YAAA,CAAA,GAAA,GAAgB;AAChB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACjB,CAAC,EANW,UAAU,KAAV,UAAU,GAMrB,EAAA,CAAA,CAAA;AAEY,MAAA,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;CAkBxC,CAAC,IAAI;AAEO,MAAA,2BAA2B,GACtC,CAAA;;;;;;;CAOD,CAAC,IAAI;AAEO,MAAA,WAAW,GAAG;AACzB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,WAAW,EAAE,yBAAyB;;AAG3B,MAAA,UAAU,GAAG;AACxB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;AAC/B,IAAA,WAAW,EAAE,gCAAgC;;AAGlC,MAAA,aAAa,GAAG;AAC3B,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,WAAW,EAAE,2BAA2B;;AAG7B,MAAA,YAAY,GAAG;AAC1B,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,sCAAsC;;AAGxC,MAAA,YAAY,GAAG;AAC1B,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,qCAAqC;;AAGvC,MAAA,UAAU,GAAG;AACxB,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,WAAW,EAAE,oCAAoC;;;;;"}
|
|
1
|
+
{"version":3,"file":"schema.mjs","sources":["../../../../src/tools/search/schema.ts"],"sourcesContent":["export enum DATE_RANGE {\n PAST_HOUR = 'h',\n PAST_24_HOURS = 'd',\n PAST_WEEK = 'w',\n PAST_MONTH = 'm',\n PAST_YEAR = 'y',\n}\n\nexport const DEFAULT_QUERY_DESCRIPTION = `\nGUIDELINES:\n- Start broad, then narrow: Begin with key concepts, then refine with specifics\n- Think like sources: Use terminology experts would use in the field\n- Consider perspective: Frame queries from different viewpoints for better results\n- Quality over quantity: A precise 3-4 word query often beats lengthy sentences\n\nTECHNIQUES (combine for power searches):\n- EXACT PHRASES: Use quotes (\"climate change report\")\n- EXCLUDE TERMS: Use minus to remove unwanted results (-wikipedia)\n- SITE-SPECIFIC: Restrict to websites (site:edu research)\n- FILETYPE: Find specific documents (filetype:pdf study)\n- OR OPERATOR: Find alternatives (electric OR hybrid cars)\n- DATE RANGE: Recent information (data after:2020)\n- WILDCARDS: Use * for unknown terms (how to * bread)\n- SPECIFIC QUESTIONS: Use who/what/when/where/why/how\n- DOMAIN TERMS: Include technical terminology for specialized topics\n- CONCISE TERMS: Prioritize keywords over sentences\n`.trim();\n\nexport const DEFAULT_COUNTRY_DESCRIPTION =\n `Country code to localize search results.\nUse standard 2-letter country codes: \"us\", \"uk\", \"ca\", \"de\", \"fr\", \"jp\", \"br\", etc.\nProvide this when the search should return results specific to a particular country.\nExamples:\n- \"us\" for United States (default)\n- \"de\" for Germany\n- \"in\" for India\n`.trim();\n\nexport const querySchema = {\n type: 'string',\n description: DEFAULT_QUERY_DESCRIPTION,\n} as const;\n\nexport const dateSchema = {\n type: 'string',\n enum: Object.values(DATE_RANGE),\n description: 'Date range for search results.',\n} as const;\n\nexport const countrySchema = {\n type: 'string',\n description: DEFAULT_COUNTRY_DESCRIPTION,\n} as const;\n\nexport const imagesSchema = {\n type: 'boolean',\n description: 'Whether to also run an image search.',\n} as const;\n\nexport const videosSchema = {\n type: 'boolean',\n description: 'Whether to also run a video search.',\n} as const;\n\nexport const newsSchema = {\n type: 'boolean',\n description: 'Whether to also run a news search.',\n} as const;\n\n/** Combined web search tool schema with all properties */\nexport const WebSearchToolSchema = {\n type: 'object',\n properties: {\n query: querySchema,\n date: dateSchema,\n country: countrySchema,\n images: imagesSchema,\n videos: videosSchema,\n news: newsSchema,\n },\n required: ['query'],\n} as const;\n"],"names":[],"mappings":"IAAY;AAAZ,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,GAAe;AACf,IAAA,UAA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AA;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;;;;;"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { Tool } from '@langchain/core/tools';
|
|
2
|
+
/** Calculator tool schema for structured input */
|
|
3
|
+
export declare const CalculatorSchema: {
|
|
4
|
+
readonly type: "object";
|
|
5
|
+
readonly properties: {
|
|
6
|
+
readonly input: {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly description: "A valid mathematical expression to evaluate";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
readonly required: readonly ["input"];
|
|
12
|
+
};
|
|
2
13
|
export declare class Calculator extends Tool {
|
|
3
14
|
static lc_name(): string;
|
|
4
15
|
get lc_namespace(): string[];
|
|
@@ -2,5 +2,27 @@ import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
|
2
2
|
import type * as t from '@/types';
|
|
3
3
|
export declare const imageExtRegex: RegExp;
|
|
4
4
|
export declare const getCodeBaseURL: () => string;
|
|
5
|
+
export declare const CodeExecutionToolSchema: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly properties: {
|
|
8
|
+
readonly lang: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
readonly enum: readonly ["py", "js", "ts", "c", "cpp", "java", "php", "rs", "go", "d", "f90", "r"];
|
|
11
|
+
readonly description: "The programming language or runtime to execute the code in.";
|
|
12
|
+
};
|
|
13
|
+
readonly code: {
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
readonly description: "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- Generated files from previous executions are automatically available in \"/mnt/data/\".\n- Files from previous executions are automatically available and can be modified in place.\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.";
|
|
16
|
+
};
|
|
17
|
+
readonly args: {
|
|
18
|
+
readonly type: "array";
|
|
19
|
+
readonly items: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
};
|
|
22
|
+
readonly description: "Additional arguments to execute the code with. This should only be used if the input code requires additional arguments to run.";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
readonly required: readonly ["lang", "code"];
|
|
26
|
+
};
|
|
5
27
|
declare function createCodeExecutionTool(params?: t.CodeExecutionToolParams): DynamicStructuredTool;
|
|
6
28
|
export { createCodeExecutionTool };
|
|
@@ -32,3 +32,35 @@ export declare const newsSchema: {
|
|
|
32
32
|
readonly type: "boolean";
|
|
33
33
|
readonly description: "Whether to also run a news search.";
|
|
34
34
|
};
|
|
35
|
+
/** Combined web search tool schema with all properties */
|
|
36
|
+
export declare const WebSearchToolSchema: {
|
|
37
|
+
readonly type: "object";
|
|
38
|
+
readonly properties: {
|
|
39
|
+
readonly query: {
|
|
40
|
+
readonly type: "string";
|
|
41
|
+
readonly description: string;
|
|
42
|
+
};
|
|
43
|
+
readonly date: {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
readonly enum: DATE_RANGE[];
|
|
46
|
+
readonly description: "Date range for search results.";
|
|
47
|
+
};
|
|
48
|
+
readonly country: {
|
|
49
|
+
readonly type: "string";
|
|
50
|
+
readonly description: string;
|
|
51
|
+
};
|
|
52
|
+
readonly images: {
|
|
53
|
+
readonly type: "boolean";
|
|
54
|
+
readonly description: "Whether to also run an image search.";
|
|
55
|
+
};
|
|
56
|
+
readonly videos: {
|
|
57
|
+
readonly type: "boolean";
|
|
58
|
+
readonly description: "Whether to also run a video search.";
|
|
59
|
+
};
|
|
60
|
+
readonly news: {
|
|
61
|
+
readonly type: "boolean";
|
|
62
|
+
readonly description: "Whether to also run a news search.";
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
readonly required: readonly ["query"];
|
|
66
|
+
};
|
package/package.json
CHANGED
package/src/tools/Calculator.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { Tool } from '@langchain/core/tools';
|
|
2
2
|
import * as math from 'mathjs';
|
|
3
3
|
|
|
4
|
+
/** Calculator tool schema for structured input */
|
|
5
|
+
export const CalculatorSchema = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
input: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
description: 'A valid mathematical expression to evaluate',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
required: ['input'],
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
4
16
|
export class Calculator extends Tool {
|
|
5
17
|
static lc_name(): string {
|
|
6
18
|
return 'Calculator';
|
|
@@ -66,3 +66,17 @@ export const newsSchema = {
|
|
|
66
66
|
type: 'boolean',
|
|
67
67
|
description: 'Whether to also run a news search.',
|
|
68
68
|
} as const;
|
|
69
|
+
|
|
70
|
+
/** Combined web search tool schema with all properties */
|
|
71
|
+
export const WebSearchToolSchema = {
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties: {
|
|
74
|
+
query: querySchema,
|
|
75
|
+
date: dateSchema,
|
|
76
|
+
country: countrySchema,
|
|
77
|
+
images: imagesSchema,
|
|
78
|
+
videos: videosSchema,
|
|
79
|
+
news: newsSchema,
|
|
80
|
+
},
|
|
81
|
+
required: ['query'],
|
|
82
|
+
} as const;
|