@librechat/agents 3.1.68-dev.0 → 3.1.68-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/enum.cjs +0 -1
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +0 -10
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +3 -12
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +0 -9
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +7 -23
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +2 -13
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/esm/common/enum.mjs +0 -1
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +1 -11
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +4 -13
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +0 -9
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +8 -24
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +3 -14
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/types/common/enum.d.ts +0 -1
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +4 -9
- package/dist/types/tools/ToolSearch.d.ts +2 -2
- package/dist/types/types/tools.d.ts +0 -9
- package/package.json +1 -1
- package/src/common/enum.ts +0 -1
- package/src/scripts/programmatic_exec.ts +1 -10
- package/src/scripts/test_code_api.ts +0 -7
- package/src/scripts/tool_search.ts +1 -10
- package/src/tools/BashExecutor.ts +1 -13
- package/src/tools/BashProgrammaticToolCalling.ts +2 -18
- package/src/tools/CodeExecutor.ts +0 -11
- package/src/tools/ProgrammaticToolCalling.ts +4 -29
- package/src/tools/ToolSearch.ts +3 -19
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +7 -8
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -1
- package/src/tools/__tests__/ToolSearch.integration.test.ts +7 -8
- package/src/types/tools.ts +0 -9
|
@@ -3,7 +3,6 @@ import type { RunnableToolLike } from '@langchain/core/runnables';
|
|
|
3
3
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
4
4
|
import type { HookRegistry } from '@/hooks';
|
|
5
5
|
import type { MessageContentComplex, ToolErrorData } from './stream';
|
|
6
|
-
import { EnvVar } from '@/common';
|
|
7
6
|
/** Replacement type for `import type { ToolCall } from '@langchain/core/messages/tool'` in order to have stringified args typed */
|
|
8
7
|
export type CustomToolCall = {
|
|
9
8
|
name: string;
|
|
@@ -72,9 +71,7 @@ export type CodeEnvFile = {
|
|
|
72
71
|
export type CodeExecutionToolParams = undefined | {
|
|
73
72
|
session_id?: string;
|
|
74
73
|
user_id?: string;
|
|
75
|
-
apiKey?: string;
|
|
76
74
|
files?: CodeEnvFile[];
|
|
77
|
-
[EnvVar.CODE_API_KEY]?: string;
|
|
78
75
|
};
|
|
79
76
|
export type FileRef = {
|
|
80
77
|
id: string;
|
|
@@ -212,7 +209,6 @@ export type ToolSearchMode = 'code_interpreter' | 'local';
|
|
|
212
209
|
export type McpNameFormat = 'full' | 'base';
|
|
213
210
|
/** Parameters for creating a Tool Search tool */
|
|
214
211
|
export type ToolSearchParams = {
|
|
215
|
-
apiKey?: string;
|
|
216
212
|
toolRegistry?: LCToolRegistry;
|
|
217
213
|
onlyDeferred?: boolean;
|
|
218
214
|
baseUrl?: string;
|
|
@@ -222,7 +218,6 @@ export type ToolSearchParams = {
|
|
|
222
218
|
mcpServer?: string | string[];
|
|
223
219
|
/** Format for MCP tool names: 'full' (tool_mcp_server) or 'base' (tool only). Default: 'full' */
|
|
224
220
|
mcpNameFormat?: McpNameFormat;
|
|
225
|
-
[key: string]: unknown;
|
|
226
221
|
};
|
|
227
222
|
/** Simplified tool metadata for search purposes */
|
|
228
223
|
export type ToolMetadata = {
|
|
@@ -307,8 +302,6 @@ export type BashProgrammaticToolCallingParams = ProgrammaticToolCallingParams;
|
|
|
307
302
|
* Initialization parameters for the PTC tool
|
|
308
303
|
*/
|
|
309
304
|
export type ProgrammaticToolCallingParams = {
|
|
310
|
-
/** Code API key (or use CODE_API_KEY env var) */
|
|
311
|
-
apiKey?: string;
|
|
312
305
|
/** Code API base URL (or use CODE_BASEURL env var) */
|
|
313
306
|
baseUrl?: string;
|
|
314
307
|
/** Safety limit for round-trips (default: 20) */
|
|
@@ -317,8 +310,6 @@ export type ProgrammaticToolCallingParams = {
|
|
|
317
310
|
proxy?: string;
|
|
318
311
|
/** Enable debug logging (or set PTC_DEBUG=true env var) */
|
|
319
312
|
debug?: boolean;
|
|
320
|
-
/** Environment variable key for API key */
|
|
321
|
-
[key: string]: unknown;
|
|
322
313
|
};
|
|
323
314
|
/**
|
|
324
315
|
* Tracks code execution session state for automatic file persistence.
|
package/package.json
CHANGED
package/src/common/enum.ts
CHANGED
|
@@ -94,15 +94,6 @@ async function main(): Promise<void> {
|
|
|
94
94
|
console.log('==============================================');
|
|
95
95
|
console.log('Demonstrating runtime toolMap injection\n');
|
|
96
96
|
|
|
97
|
-
const apiKey = process.env.LIBRECHAT_CODE_API_KEY;
|
|
98
|
-
if (!apiKey) {
|
|
99
|
-
console.error(
|
|
100
|
-
'Error: LIBRECHAT_CODE_API_KEY environment variable is not set.'
|
|
101
|
-
);
|
|
102
|
-
console.log('Please set it in your .env file or environment.');
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
97
|
console.log('Creating mock tools...');
|
|
107
98
|
const mockTools: StructuredToolInterface[] = [
|
|
108
99
|
createGetTeamMembersTool(),
|
|
@@ -119,7 +110,7 @@ async function main(): Promise<void> {
|
|
|
119
110
|
);
|
|
120
111
|
|
|
121
112
|
console.log('\nCreating PTC tool (without toolMap)...');
|
|
122
|
-
const ptcTool = createProgrammaticToolCallingTool(
|
|
113
|
+
const ptcTool = createProgrammaticToolCallingTool();
|
|
123
114
|
console.log('PTC tool created successfully!');
|
|
124
115
|
console.log(
|
|
125
116
|
'Note: toolMap will be passed at runtime with each invocation.\n'
|
|
@@ -11,16 +11,10 @@ config();
|
|
|
11
11
|
import fetch, { RequestInit } from 'node-fetch';
|
|
12
12
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
13
13
|
|
|
14
|
-
const API_KEY = process.env.LIBRECHAT_CODE_API_KEY ?? '';
|
|
15
14
|
const BASE_URL =
|
|
16
15
|
process.env.LIBRECHAT_CODE_BASEURL ?? 'https://api.librechat.ai/v1';
|
|
17
16
|
const PROXY = process.env.PROXY;
|
|
18
17
|
|
|
19
|
-
if (!API_KEY) {
|
|
20
|
-
console.error('LIBRECHAT_CODE_API_KEY not set');
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
18
|
interface FileRef {
|
|
25
19
|
id: string;
|
|
26
20
|
name: string;
|
|
@@ -53,7 +47,6 @@ async function makeRequest(
|
|
|
53
47
|
headers: {
|
|
54
48
|
'Content-Type': 'application/json',
|
|
55
49
|
'User-Agent': 'LibreChat/1.0',
|
|
56
|
-
'X-API-Key': API_KEY,
|
|
57
50
|
},
|
|
58
51
|
};
|
|
59
52
|
|
|
@@ -66,15 +66,6 @@ async function main(): Promise<void> {
|
|
|
66
66
|
console.log('================================');
|
|
67
67
|
console.log('Demonstrating runtime tool registry injection\n');
|
|
68
68
|
|
|
69
|
-
const apiKey = process.env.LIBRECHAT_CODE_API_KEY;
|
|
70
|
-
if (!apiKey) {
|
|
71
|
-
console.error(
|
|
72
|
-
'Error: LIBRECHAT_CODE_API_KEY environment variable is not set.'
|
|
73
|
-
);
|
|
74
|
-
console.log('Please set it in your .env file or environment.');
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
69
|
console.log('Creating sample tool registry...');
|
|
79
70
|
const toolRegistry = createToolSearchToolRegistry();
|
|
80
71
|
console.log(
|
|
@@ -82,7 +73,7 @@ async function main(): Promise<void> {
|
|
|
82
73
|
);
|
|
83
74
|
|
|
84
75
|
console.log('\nCreating Tool Search Regex tool WITH registry for testing...');
|
|
85
|
-
const searchTool = createToolSearch({
|
|
76
|
+
const searchTool = createToolSearch({ toolRegistry });
|
|
86
77
|
console.log('Tool created successfully!');
|
|
87
78
|
console.log(
|
|
88
79
|
'Note: In production, ToolNode injects toolRegistry via params when invoked through the graph.\n'
|
|
@@ -2,10 +2,9 @@ import { config } from 'dotenv';
|
|
|
2
2
|
import fetch, { RequestInit } from 'node-fetch';
|
|
3
3
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
4
4
|
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
5
|
-
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
6
5
|
import type * as t from '@/types';
|
|
7
6
|
import { imageExtRegex, getCodeBaseURL } from './CodeExecutor';
|
|
8
|
-
import {
|
|
7
|
+
import { Constants } from '@/common';
|
|
9
8
|
|
|
10
9
|
config();
|
|
11
10
|
|
|
@@ -63,15 +62,6 @@ export const BashExecutionToolDefinition = {
|
|
|
63
62
|
function createBashExecutionTool(
|
|
64
63
|
params: t.BashExecutionToolParams = {}
|
|
65
64
|
): DynamicStructuredTool {
|
|
66
|
-
const apiKey =
|
|
67
|
-
params[EnvVar.CODE_API_KEY] ??
|
|
68
|
-
params.apiKey ??
|
|
69
|
-
getEnvironmentVariable(EnvVar.CODE_API_KEY) ??
|
|
70
|
-
'';
|
|
71
|
-
if (!apiKey) {
|
|
72
|
-
throw new Error('No API key provided for bash execution tool.');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
65
|
return tool(
|
|
76
66
|
async (rawInput, config) => {
|
|
77
67
|
const { command, ...rest } = rawInput as {
|
|
@@ -99,7 +89,6 @@ function createBashExecutionTool(
|
|
|
99
89
|
method: 'GET',
|
|
100
90
|
headers: {
|
|
101
91
|
'User-Agent': 'LibreChat/1.0',
|
|
102
|
-
'X-API-Key': apiKey,
|
|
103
92
|
},
|
|
104
93
|
};
|
|
105
94
|
|
|
@@ -141,7 +130,6 @@ function createBashExecutionTool(
|
|
|
141
130
|
headers: {
|
|
142
131
|
'Content-Type': 'application/json',
|
|
143
132
|
'User-Agent': 'LibreChat/1.0',
|
|
144
|
-
'X-API-Key': apiKey,
|
|
145
133
|
},
|
|
146
134
|
body: JSON.stringify(postData),
|
|
147
135
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { config } from 'dotenv';
|
|
2
|
-
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
3
2
|
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
4
3
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
5
4
|
import type * as t from '@/types';
|
|
@@ -10,7 +9,7 @@ import {
|
|
|
10
9
|
formatCompletedResponse,
|
|
11
10
|
} from './ProgrammaticToolCalling';
|
|
12
11
|
import { getCodeBaseURL } from './CodeExecutor';
|
|
13
|
-
import {
|
|
12
|
+
import { Constants } from '@/common';
|
|
14
13
|
|
|
15
14
|
config();
|
|
16
15
|
|
|
@@ -242,19 +241,6 @@ export function filterBashToolsByUsage(
|
|
|
242
241
|
export function createBashProgrammaticToolCallingTool(
|
|
243
242
|
initParams: t.BashProgrammaticToolCallingParams = {}
|
|
244
243
|
): DynamicStructuredTool {
|
|
245
|
-
const apiKey =
|
|
246
|
-
(initParams[EnvVar.CODE_API_KEY] as string | undefined) ??
|
|
247
|
-
initParams.apiKey ??
|
|
248
|
-
getEnvironmentVariable(EnvVar.CODE_API_KEY) ??
|
|
249
|
-
'';
|
|
250
|
-
|
|
251
|
-
if (!apiKey) {
|
|
252
|
-
throw new Error(
|
|
253
|
-
'No API key provided for bash programmatic tool calling. ' +
|
|
254
|
-
'Set CODE_API_KEY environment variable or pass apiKey in initParams.'
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
244
|
const baseUrl = initParams.baseUrl ?? getCodeBaseURL();
|
|
259
245
|
const maxRoundTrips = initParams.maxRoundTrips ?? DEFAULT_MAX_ROUND_TRIPS;
|
|
260
246
|
const proxy = initParams.proxy ?? process.env.PROXY;
|
|
@@ -308,12 +294,11 @@ export function createBashProgrammaticToolCallingTool(
|
|
|
308
294
|
if (_injected_files && _injected_files.length > 0) {
|
|
309
295
|
files = _injected_files;
|
|
310
296
|
} else if (session_id != null && session_id.length > 0) {
|
|
311
|
-
files = await fetchSessionFiles(baseUrl,
|
|
297
|
+
files = await fetchSessionFiles(baseUrl, session_id, proxy);
|
|
312
298
|
}
|
|
313
299
|
|
|
314
300
|
let response = await makeRequest(
|
|
315
301
|
EXEC_ENDPOINT,
|
|
316
|
-
apiKey,
|
|
317
302
|
{
|
|
318
303
|
lang: 'bash',
|
|
319
304
|
code,
|
|
@@ -354,7 +339,6 @@ export function createBashProgrammaticToolCallingTool(
|
|
|
354
339
|
|
|
355
340
|
response = await makeRequest(
|
|
356
341
|
EXEC_ENDPOINT,
|
|
357
|
-
apiKey,
|
|
358
342
|
{
|
|
359
343
|
continuation_token: response.continuation_token,
|
|
360
344
|
tool_results: toolResults,
|
|
@@ -95,15 +95,6 @@ export const CodeExecutionToolDefinition = {
|
|
|
95
95
|
function createCodeExecutionTool(
|
|
96
96
|
params: t.CodeExecutionToolParams = {}
|
|
97
97
|
): DynamicStructuredTool {
|
|
98
|
-
const apiKey =
|
|
99
|
-
params[EnvVar.CODE_API_KEY] ??
|
|
100
|
-
params.apiKey ??
|
|
101
|
-
getEnvironmentVariable(EnvVar.CODE_API_KEY) ??
|
|
102
|
-
'';
|
|
103
|
-
if (!apiKey) {
|
|
104
|
-
throw new Error('No API key provided for code execution tool.');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
98
|
return tool(
|
|
108
99
|
async (rawInput, config) => {
|
|
109
100
|
const { lang, code, ...rest } = rawInput as {
|
|
@@ -143,7 +134,6 @@ function createCodeExecutionTool(
|
|
|
143
134
|
method: 'GET',
|
|
144
135
|
headers: {
|
|
145
136
|
'User-Agent': 'LibreChat/1.0',
|
|
146
|
-
'X-API-Key': apiKey,
|
|
147
137
|
},
|
|
148
138
|
};
|
|
149
139
|
|
|
@@ -185,7 +175,6 @@ function createCodeExecutionTool(
|
|
|
185
175
|
headers: {
|
|
186
176
|
'Content-Type': 'application/json',
|
|
187
177
|
'User-Agent': 'LibreChat/1.0',
|
|
188
|
-
'X-API-Key': apiKey,
|
|
189
178
|
},
|
|
190
179
|
body: JSON.stringify(postData),
|
|
191
180
|
};
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
import { config } from 'dotenv';
|
|
3
3
|
import fetch, { RequestInit } from 'node-fetch';
|
|
4
4
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
5
|
-
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
6
5
|
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
7
6
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
8
7
|
import type * as t from '@/types';
|
|
9
8
|
import { imageExtRegex, getCodeBaseURL } from './CodeExecutor';
|
|
10
|
-
import {
|
|
9
|
+
import { Constants } from '@/common';
|
|
11
10
|
|
|
12
11
|
config();
|
|
13
12
|
|
|
@@ -261,14 +260,12 @@ export function filterToolsByUsage(
|
|
|
261
260
|
* Fetches files from a previous session to make them available for the current execution.
|
|
262
261
|
* Files are returned as CodeEnvFile references to be included in the request.
|
|
263
262
|
* @param baseUrl - The base URL for the Code API
|
|
264
|
-
* @param apiKey - The API key for authentication
|
|
265
263
|
* @param sessionId - The session ID to fetch files from
|
|
266
264
|
* @param proxy - Optional HTTP proxy URL
|
|
267
265
|
* @returns Array of CodeEnvFile references, or empty array if fetch fails
|
|
268
266
|
*/
|
|
269
267
|
export async function fetchSessionFiles(
|
|
270
268
|
baseUrl: string,
|
|
271
|
-
apiKey: string,
|
|
272
269
|
sessionId: string,
|
|
273
270
|
proxy?: string
|
|
274
271
|
): Promise<t.CodeEnvFile[]> {
|
|
@@ -278,7 +275,6 @@ export async function fetchSessionFiles(
|
|
|
278
275
|
method: 'GET',
|
|
279
276
|
headers: {
|
|
280
277
|
'User-Agent': 'LibreChat/1.0',
|
|
281
|
-
'X-API-Key': apiKey,
|
|
282
278
|
},
|
|
283
279
|
};
|
|
284
280
|
|
|
@@ -321,14 +317,12 @@ export async function fetchSessionFiles(
|
|
|
321
317
|
/**
|
|
322
318
|
* Makes an HTTP request to the Code API.
|
|
323
319
|
* @param endpoint - The API endpoint URL
|
|
324
|
-
* @param apiKey - The API key for authentication
|
|
325
320
|
* @param body - The request body
|
|
326
321
|
* @param proxy - Optional HTTP proxy URL
|
|
327
322
|
* @returns The parsed API response
|
|
328
323
|
*/
|
|
329
324
|
export async function makeRequest(
|
|
330
325
|
endpoint: string,
|
|
331
|
-
apiKey: string,
|
|
332
326
|
body: Record<string, unknown>,
|
|
333
327
|
proxy?: string
|
|
334
328
|
): Promise<t.ProgrammaticExecutionResponse> {
|
|
@@ -337,7 +331,6 @@ export async function makeRequest(
|
|
|
337
331
|
headers: {
|
|
338
332
|
'Content-Type': 'application/json',
|
|
339
333
|
'User-Agent': 'LibreChat/1.0',
|
|
340
|
-
'X-API-Key': apiKey,
|
|
341
334
|
},
|
|
342
335
|
body: JSON.stringify(body),
|
|
343
336
|
};
|
|
@@ -596,14 +589,11 @@ export function formatCompletedResponse(
|
|
|
596
589
|
*
|
|
597
590
|
* The tool map must be provided at runtime via config.configurable.toolMap.
|
|
598
591
|
*
|
|
599
|
-
* @param params - Configuration parameters (
|
|
592
|
+
* @param params - Configuration parameters (baseUrl, maxRoundTrips, proxy)
|
|
600
593
|
* @returns A LangChain DynamicStructuredTool for programmatic tool calling
|
|
601
594
|
*
|
|
602
595
|
* @example
|
|
603
|
-
* const ptcTool = createProgrammaticToolCallingTool({
|
|
604
|
-
* apiKey: process.env.CODE_API_KEY,
|
|
605
|
-
* maxRoundTrips: 20
|
|
606
|
-
* });
|
|
596
|
+
* const ptcTool = createProgrammaticToolCallingTool({ maxRoundTrips: 20 });
|
|
607
597
|
*
|
|
608
598
|
* const [output, artifact] = await ptcTool.invoke(
|
|
609
599
|
* { code, tools },
|
|
@@ -613,19 +603,6 @@ export function formatCompletedResponse(
|
|
|
613
603
|
export function createProgrammaticToolCallingTool(
|
|
614
604
|
initParams: t.ProgrammaticToolCallingParams = {}
|
|
615
605
|
): DynamicStructuredTool {
|
|
616
|
-
const apiKey =
|
|
617
|
-
(initParams[EnvVar.CODE_API_KEY] as string | undefined) ??
|
|
618
|
-
initParams.apiKey ??
|
|
619
|
-
getEnvironmentVariable(EnvVar.CODE_API_KEY) ??
|
|
620
|
-
'';
|
|
621
|
-
|
|
622
|
-
if (!apiKey) {
|
|
623
|
-
throw new Error(
|
|
624
|
-
'No API key provided for programmatic tool calling. ' +
|
|
625
|
-
'Set CODE_API_KEY environment variable or pass apiKey in initParams.'
|
|
626
|
-
);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
606
|
const baseUrl = initParams.baseUrl ?? getCodeBaseURL();
|
|
630
607
|
const maxRoundTrips = initParams.maxRoundTrips ?? DEFAULT_MAX_ROUND_TRIPS;
|
|
631
608
|
const proxy = initParams.proxy ?? process.env.PROXY;
|
|
@@ -685,12 +662,11 @@ export function createProgrammaticToolCallingTool(
|
|
|
685
662
|
if (_injected_files && _injected_files.length > 0) {
|
|
686
663
|
files = _injected_files;
|
|
687
664
|
} else if (session_id != null && session_id.length > 0) {
|
|
688
|
-
files = await fetchSessionFiles(baseUrl,
|
|
665
|
+
files = await fetchSessionFiles(baseUrl, session_id, proxy);
|
|
689
666
|
}
|
|
690
667
|
|
|
691
668
|
let response = await makeRequest(
|
|
692
669
|
EXEC_ENDPOINT,
|
|
693
|
-
apiKey,
|
|
694
670
|
{
|
|
695
671
|
code,
|
|
696
672
|
tools: effectiveTools,
|
|
@@ -730,7 +706,6 @@ export function createProgrammaticToolCallingTool(
|
|
|
730
706
|
|
|
731
707
|
response = await makeRequest(
|
|
732
708
|
EXEC_ENDPOINT,
|
|
733
|
-
apiKey,
|
|
734
709
|
{
|
|
735
710
|
continuation_token: response.continuation_token,
|
|
736
711
|
tool_results: toolResults,
|
package/src/tools/ToolSearch.ts
CHANGED
|
@@ -22,11 +22,10 @@ function getBM25Function(): BM25Fn {
|
|
|
22
22
|
const BM25 = getBM25Function();
|
|
23
23
|
import fetch, { RequestInit } from 'node-fetch';
|
|
24
24
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
25
|
-
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
26
25
|
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
27
26
|
import type * as t from '@/types';
|
|
28
27
|
import { getCodeBaseURL } from './CodeExecutor';
|
|
29
|
-
import {
|
|
28
|
+
import { Constants } from '@/common';
|
|
30
29
|
|
|
31
30
|
config();
|
|
32
31
|
|
|
@@ -837,11 +836,11 @@ function formatServerListing(
|
|
|
837
836
|
*
|
|
838
837
|
* @example
|
|
839
838
|
* // Option 1: Code interpreter mode (regex via sandbox)
|
|
840
|
-
* const tool = createToolSearch({
|
|
839
|
+
* const tool = createToolSearch({ toolRegistry });
|
|
841
840
|
* await tool.invoke({ query: 'expense.*report' });
|
|
842
841
|
*
|
|
843
842
|
* @example
|
|
844
|
-
* // Option 2: Local mode (safe substring search
|
|
843
|
+
* // Option 2: Local mode (safe substring search)
|
|
845
844
|
* const tool = createToolSearch({ mode: 'local', toolRegistry });
|
|
846
845
|
* await tool.invoke({ query: 'expense' });
|
|
847
846
|
*/
|
|
@@ -853,20 +852,6 @@ function createToolSearch(
|
|
|
853
852
|
const mcpNameFormat: t.McpNameFormat = initParams.mcpNameFormat ?? 'full';
|
|
854
853
|
const schema = createToolSearchSchema(mode);
|
|
855
854
|
|
|
856
|
-
const apiKey: string =
|
|
857
|
-
mode === 'code_interpreter'
|
|
858
|
-
? ((initParams[EnvVar.CODE_API_KEY] as string | undefined) ??
|
|
859
|
-
initParams.apiKey ??
|
|
860
|
-
getEnvironmentVariable(EnvVar.CODE_API_KEY) ??
|
|
861
|
-
'')
|
|
862
|
-
: '';
|
|
863
|
-
|
|
864
|
-
if (mode === 'code_interpreter' && !apiKey) {
|
|
865
|
-
throw new Error(
|
|
866
|
-
'No API key provided for tool search in code_interpreter mode. Use mode: "local" to search without an API key.'
|
|
867
|
-
);
|
|
868
|
-
}
|
|
869
|
-
|
|
870
855
|
const baseEndpoint = initParams.baseUrl ?? getCodeBaseURL();
|
|
871
856
|
const EXEC_ENDPOINT = `${baseEndpoint}/exec`;
|
|
872
857
|
|
|
@@ -1052,7 +1037,6 @@ ${mcpNote}${toolsListSection}
|
|
|
1052
1037
|
headers: {
|
|
1053
1038
|
'Content-Type': 'application/json',
|
|
1054
1039
|
'User-Agent': 'LibreChat/1.0',
|
|
1055
|
-
'X-API-Key': apiKey,
|
|
1056
1040
|
},
|
|
1057
1041
|
body: JSON.stringify(postData),
|
|
1058
1042
|
};
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Integration tests for Programmatic Tool Calling.
|
|
4
4
|
* These tests hit the LIVE Code API and verify end-to-end functionality.
|
|
5
5
|
*
|
|
6
|
-
* Run with: npm test -- ProgrammaticToolCalling.integration.test.ts
|
|
6
|
+
* Run with: RUN_CODE_INTEGRATION_TESTS=1 npm test -- ProgrammaticToolCalling.integration.test.ts
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Opt-in via the `RUN_CODE_INTEGRATION_TESTS` environment variable —
|
|
9
|
+
* these tests hit a real sandbox so they don't run in CI by default.
|
|
10
10
|
*/
|
|
11
11
|
import { config as dotenvConfig } from 'dotenv';
|
|
12
12
|
dotenvConfig();
|
|
@@ -22,12 +22,11 @@ import {
|
|
|
22
22
|
createProgrammaticToolRegistry,
|
|
23
23
|
} from '@/test/mockTools';
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
const shouldSkip = apiKey == null || apiKey === '';
|
|
25
|
+
const shouldSkip = process.env.RUN_CODE_INTEGRATION_TESTS !== '1';
|
|
27
26
|
|
|
28
|
-
const
|
|
27
|
+
const describeIfLive = shouldSkip ? describe.skip : describe;
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
describeIfLive('ProgrammaticToolCalling - Live API Integration', () => {
|
|
31
30
|
let ptcTool: ReturnType<typeof createProgrammaticToolCallingTool>;
|
|
32
31
|
let toolMap: t.ToolMap;
|
|
33
32
|
let toolDefinitions: t.LCTool[];
|
|
@@ -43,7 +42,7 @@ describeIfApiKey('ProgrammaticToolCalling - Live API Integration', () => {
|
|
|
43
42
|
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
44
43
|
toolDefinitions = Array.from(createProgrammaticToolRegistry().values());
|
|
45
44
|
|
|
46
|
-
ptcTool = createProgrammaticToolCallingTool(
|
|
45
|
+
ptcTool = createProgrammaticToolCallingTool();
|
|
47
46
|
});
|
|
48
47
|
|
|
49
48
|
it('executes simple single tool call', async () => {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Integration tests for Tool Search Regex.
|
|
4
4
|
* These tests hit the LIVE Code API and verify end-to-end search functionality.
|
|
5
5
|
*
|
|
6
|
-
* Run with: npm test -- ToolSearch.integration.test.ts
|
|
6
|
+
* Run with: RUN_CODE_INTEGRATION_TESTS=1 npm test -- ToolSearch.integration.test.ts
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Opt-in via the `RUN_CODE_INTEGRATION_TESTS` environment variable —
|
|
9
|
+
* these tests hit a real sandbox so they don't run in CI by default.
|
|
10
10
|
*/
|
|
11
11
|
import { config as dotenvConfig } from 'dotenv';
|
|
12
12
|
dotenvConfig();
|
|
@@ -15,17 +15,16 @@ import { describe, it, expect, beforeAll } from '@jest/globals';
|
|
|
15
15
|
import { createToolSearch } from '../ToolSearch';
|
|
16
16
|
import { createToolSearchToolRegistry } from '@/test/mockTools';
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
const shouldSkip = apiKey == null || apiKey === '';
|
|
18
|
+
const shouldSkip = process.env.RUN_CODE_INTEGRATION_TESTS !== '1';
|
|
20
19
|
|
|
21
|
-
const
|
|
20
|
+
const describeIfLive = shouldSkip ? describe.skip : describe;
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
describeIfLive('ToolSearch - Live API Integration', () => {
|
|
24
23
|
let searchTool: ReturnType<typeof createToolSearch>;
|
|
25
24
|
const toolRegistry = createToolSearchToolRegistry();
|
|
26
25
|
|
|
27
26
|
beforeAll(() => {
|
|
28
|
-
searchTool = createToolSearch({
|
|
27
|
+
searchTool = createToolSearch({ toolRegistry });
|
|
29
28
|
});
|
|
30
29
|
|
|
31
30
|
it('searches for expense-related tools', async () => {
|
package/src/types/tools.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { RunnableToolLike } from '@langchain/core/runnables';
|
|
|
4
4
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
5
5
|
import type { HookRegistry } from '@/hooks';
|
|
6
6
|
import type { MessageContentComplex, ToolErrorData } from './stream';
|
|
7
|
-
import { EnvVar } from '@/common';
|
|
8
7
|
|
|
9
8
|
/** Replacement type for `import type { ToolCall } from '@langchain/core/messages/tool'` in order to have stringified args typed */
|
|
10
9
|
export type CustomToolCall = {
|
|
@@ -88,9 +87,7 @@ export type CodeExecutionToolParams =
|
|
|
88
87
|
| {
|
|
89
88
|
session_id?: string;
|
|
90
89
|
user_id?: string;
|
|
91
|
-
apiKey?: string;
|
|
92
90
|
files?: CodeEnvFile[];
|
|
93
|
-
[EnvVar.CODE_API_KEY]?: string;
|
|
94
91
|
};
|
|
95
92
|
|
|
96
93
|
export type FileRef = {
|
|
@@ -247,7 +244,6 @@ export type McpNameFormat = 'full' | 'base';
|
|
|
247
244
|
|
|
248
245
|
/** Parameters for creating a Tool Search tool */
|
|
249
246
|
export type ToolSearchParams = {
|
|
250
|
-
apiKey?: string;
|
|
251
247
|
toolRegistry?: LCToolRegistry;
|
|
252
248
|
onlyDeferred?: boolean;
|
|
253
249
|
baseUrl?: string;
|
|
@@ -257,7 +253,6 @@ export type ToolSearchParams = {
|
|
|
257
253
|
mcpServer?: string | string[];
|
|
258
254
|
/** Format for MCP tool names: 'full' (tool_mcp_server) or 'base' (tool only). Default: 'full' */
|
|
259
255
|
mcpNameFormat?: McpNameFormat;
|
|
260
|
-
[key: string]: unknown;
|
|
261
256
|
};
|
|
262
257
|
|
|
263
258
|
/** Simplified tool metadata for search purposes */
|
|
@@ -362,8 +357,6 @@ export type BashProgrammaticToolCallingParams = ProgrammaticToolCallingParams;
|
|
|
362
357
|
* Initialization parameters for the PTC tool
|
|
363
358
|
*/
|
|
364
359
|
export type ProgrammaticToolCallingParams = {
|
|
365
|
-
/** Code API key (or use CODE_API_KEY env var) */
|
|
366
|
-
apiKey?: string;
|
|
367
360
|
/** Code API base URL (or use CODE_BASEURL env var) */
|
|
368
361
|
baseUrl?: string;
|
|
369
362
|
/** Safety limit for round-trips (default: 20) */
|
|
@@ -372,8 +365,6 @@ export type ProgrammaticToolCallingParams = {
|
|
|
372
365
|
proxy?: string;
|
|
373
366
|
/** Enable debug logging (or set PTC_DEBUG=true env var) */
|
|
374
367
|
debug?: boolean;
|
|
375
|
-
/** Environment variable key for API key */
|
|
376
|
-
[key: string]: unknown;
|
|
377
368
|
};
|
|
378
369
|
|
|
379
370
|
// ============================================================================
|