@librechat/agents 3.8.6 → 3.8.7
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 +1 -0
- package/dist/cjs/tools/BashExecutor.cjs +79 -27
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +47 -7
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +5 -2
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs +11 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +54 -8
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +52 -20
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/toolBatchReplay.cjs +3 -1
- package/dist/cjs/tools/toolBatchReplay.cjs.map +1 -1
- package/dist/esm/main.mjs +2 -2
- package/dist/esm/tools/BashExecutor.mjs +81 -29
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +48 -9
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +5 -2
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs +11 -2
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +55 -9
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +52 -20
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/toolBatchReplay.mjs +3 -1
- package/dist/esm/tools/toolBatchReplay.mjs.map +1 -1
- package/dist/types/tools/BashExecutor.d.ts +2 -0
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -0
- package/dist/types/tools/CodeExecutor.d.ts +1 -1
- package/dist/types/tools/CodeSessionFileSummary.d.ts +3 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/ToolNode.d.ts +2 -0
- package/dist/types/tools/toolBatchReplay.d.ts +2 -0
- package/dist/types/types/tools.d.ts +16 -2
- package/package.json +2 -2
- package/src/tools/BashExecutor.ts +143 -40
- package/src/tools/BashProgrammaticToolCalling.ts +82 -10
- package/src/tools/CodeExecutor.ts +12 -2
- package/src/tools/CodeSessionFileSummary.ts +25 -1
- package/src/tools/ProgrammaticToolCalling.ts +77 -6
- package/src/tools/ToolNode.ts +152 -26
- package/src/tools/toolBatchReplay.ts +23 -1
- package/src/types/tools.ts +19 -2
package/dist/cjs/main.cjs
CHANGED
|
@@ -730,6 +730,7 @@ exports.partitionAndMarkAnthropicToolCache = require_anthropicToolCache.partitio
|
|
|
730
730
|
exports.performLocalSearch = require_ToolSearch.performLocalSearch;
|
|
731
731
|
exports.preFlightTruncateToolCallInputs = require_prune.preFlightTruncateToolCallInputs;
|
|
732
732
|
exports.preFlightTruncateToolResults = require_prune.preFlightTruncateToolResults;
|
|
733
|
+
exports.prepareBashProgrammaticCode = require_BashProgrammaticToolCalling.prepareBashProgrammaticCode;
|
|
733
734
|
exports.prepareProviderRequest = require_prepareProviderRequest.prepareProviderRequest;
|
|
734
735
|
exports.probeLocalCommandAvailability = require_LocalExecutionEngine.probeLocalCommandAvailability;
|
|
735
736
|
exports.projectAgentContextUsage = require_projection.projectAgentContextUsage;
|
|
@@ -7,6 +7,8 @@ const require_ArtifactDelivery = require("./ArtifactDelivery.cjs");
|
|
|
7
7
|
const require_diagnostics = require("./diagnostics.cjs");
|
|
8
8
|
const require_CodeSessionFileSummary = require("./CodeSessionFileSummary.cjs");
|
|
9
9
|
const require_CodeExecutor = require("./CodeExecutor.cjs");
|
|
10
|
+
const require_ProgrammaticToolCalling = require("./ProgrammaticToolCalling.cjs");
|
|
11
|
+
const require_BashProgrammaticToolCalling = require("./BashProgrammaticToolCalling.cjs");
|
|
10
12
|
let _langchain_core_tools = require("@langchain/core/tools");
|
|
11
13
|
let dotenv = require("dotenv");
|
|
12
14
|
let node_fetch = require("node-fetch");
|
|
@@ -60,6 +62,16 @@ Usage:
|
|
|
60
62
|
- ${require_CodeExecutor.BASH_SHELL_GUIDANCE}
|
|
61
63
|
- NEVER use this tool to execute malicious commands.
|
|
62
64
|
`.trim();
|
|
65
|
+
const AttachedWorkspaceBashExecutionToolDescription = `
|
|
66
|
+
Runs bash commands in the selected persistent project through an isolated sandbox process.
|
|
67
|
+
|
|
68
|
+
Usage:
|
|
69
|
+
- Project file changes persist between calls; shell variables, background processes, and execution-private temporary files do not.
|
|
70
|
+
- Injected files and generated artifacts use \${LIBRECHAT_CODE_DATA_DIR:-/mnt/data}; write durable files to the project root.
|
|
71
|
+
- Generated artifacts are automatically delivered; **DO NOT** provide download links.
|
|
72
|
+
- ${require_CodeExecutor.BASH_SHELL_GUIDANCE}
|
|
73
|
+
- NEVER use this tool to execute malicious commands.
|
|
74
|
+
`.trim();
|
|
63
75
|
const BashToolOutputReferencesGuide = `
|
|
64
76
|
Referencing previous tool outputs:
|
|
65
77
|
- Every successful tool result is tagged with a reference key of the form \`tool<idx>turn<turn>\` (e.g., \`tool0turn0\`). The key appears either as a \`[ref: tool0turn0]\` prefix line or, when the output is a JSON object, as a \`_ref\` field on the object.
|
|
@@ -71,15 +83,23 @@ Referencing previous tool outputs:
|
|
|
71
83
|
- Unknown reference keys are left in place and surfaced as \`[unresolved refs: …]\` after the output.
|
|
72
84
|
`.trim();
|
|
73
85
|
function buildBashExecutionToolDescription(options) {
|
|
74
|
-
|
|
86
|
+
let base = BashExecutionToolDescription;
|
|
87
|
+
if (options?.attachedWorkspace === true) base = AttachedWorkspaceBashExecutionToolDescription;
|
|
88
|
+
else if (options?.statefulSessions === true) base = StatefulBashExecutionToolDescription;
|
|
75
89
|
if (options?.enableToolOutputReferences === true) return `${base}\n\n${BashToolOutputReferencesGuide}`;
|
|
76
90
|
return base;
|
|
77
91
|
}
|
|
78
92
|
const STATELESS_BASH_PARAM_NOTE = "The environment is stateless; variables and state don't persist between executions.";
|
|
79
93
|
const STATEFUL_BASH_PARAM_NOTE = "Files written to /mnt/data persist between calls on the same warm machine. Each call runs in a fresh sandbox: shell variables, cwd, /tmp, and background processes do NOT survive the call. Only /mnt/data is durable.";
|
|
94
|
+
const ATTACHED_BASH_PARAM_NOTE = "Commands start in the selected persistent project. Project file changes persist, but shell variables, background processes, and execution-private temporary files do not.";
|
|
95
|
+
const ATTACHED_BASH_ARTIFACT_PATH_GUIDANCE = "Injected files and generated artifacts use `${LIBRECHAT_CODE_DATA_DIR:-/mnt/data}` for this execution only. Write anything needed later into the selected project.";
|
|
96
|
+
const ATTACHED_BASH_TMP_REMINDER = "Note: /tmp files are same-call scratch only and were not persisted; write files needed later into the selected project.";
|
|
80
97
|
function buildBashExecutionToolSchema(opts) {
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
let note = STATELESS_BASH_PARAM_NOTE;
|
|
99
|
+
if (opts?.attachedWorkspace === true) note = ATTACHED_BASH_PARAM_NOTE;
|
|
100
|
+
else if (opts?.statefulSessions === true) note = STATEFUL_BASH_PARAM_NOTE;
|
|
101
|
+
let commandDescription = BashExecutionToolSchema.properties.command.description.replace(STATELESS_BASH_PARAM_NOTE, note);
|
|
102
|
+
if (opts?.attachedWorkspace === true) commandDescription = commandDescription.replace("- Prior /mnt/data files are available and can be modified in place.\n", "").replace(require_CodeExecutor.CODE_ARTIFACT_PATH_GUIDANCE, ATTACHED_BASH_ARTIFACT_PATH_GUIDANCE);
|
|
83
103
|
return {
|
|
84
104
|
...BashExecutionToolSchema,
|
|
85
105
|
properties: {
|
|
@@ -92,20 +112,33 @@ function buildBashExecutionToolSchema(opts) {
|
|
|
92
112
|
};
|
|
93
113
|
}
|
|
94
114
|
const BashExecutionToolName = "bash_tool";
|
|
115
|
+
function quoteBashArgument(value) {
|
|
116
|
+
return `'${value.replace(/'/g, "'\"'\"'")}'`;
|
|
117
|
+
}
|
|
118
|
+
function commandWithArguments(command, args) {
|
|
119
|
+
if (args == null || args.length === 0) return command;
|
|
120
|
+
return `bash -c ${quoteBashArgument(command)} -- ${args.map(quoteBashArgument).join(" ")}`;
|
|
121
|
+
}
|
|
95
122
|
const BashExecutionToolDefinition = {
|
|
96
123
|
name: BashExecutionToolName,
|
|
97
124
|
description: BashExecutionToolDescription,
|
|
98
125
|
schema: BashExecutionToolSchema
|
|
99
126
|
};
|
|
100
127
|
function createBashExecutionTool(params = {}) {
|
|
101
|
-
const
|
|
128
|
+
const workspaceId = params?.workspaceId?.trim();
|
|
129
|
+
const hasWorkspace = workspaceId != null && workspaceId !== "";
|
|
130
|
+
if (hasWorkspace && !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(workspaceId)) throw new Error("Invalid attached workspace identifier");
|
|
131
|
+
const execEndpoint = require_CodeExecutor.buildCodeApiEndpoint(params?.baseUrl ?? require_CodeExecutor.getCodeBaseURL(), hasWorkspace ? "exec/programmatic" : "exec");
|
|
102
132
|
return (0, _langchain_core_tools.tool)(async (rawInput, config) => {
|
|
103
|
-
const { authHeaders, baseUrl: _baseUrl, executionProfile, runtimeSessionHint, statefulSessions, ...executionParams } = params ?? {};
|
|
104
|
-
const { command, intent: _ignoredIntent, runtime_session_hint: _ignoredModelHint, ...rest } = rawInput;
|
|
133
|
+
const { authHeaders, baseUrl: _baseUrl, executionProfile, runtimeSessionHint, statefulSessions, workspaceId: _workspaceId, ...executionParams } = params ?? {};
|
|
134
|
+
const { command: rawCommand, intent: _ignoredIntent, runtime_session_hint: _ignoredModelHint, args, ...rest } = rawInput;
|
|
135
|
+
const command = hasWorkspace ? commandWithArguments(rawCommand, args) : rawCommand;
|
|
105
136
|
const { session_id, _injected_files, _runtime_session_hint } = config.toolCall ?? {};
|
|
106
137
|
const postData = {
|
|
107
138
|
lang: "bash",
|
|
108
|
-
code: command,
|
|
139
|
+
code: hasWorkspace ? require_BashProgrammaticToolCalling.prepareBashProgrammaticCode(command) : command,
|
|
140
|
+
...hasWorkspace ? { tools: [] } : {},
|
|
141
|
+
...!hasWorkspace && args != null ? { args } : {},
|
|
109
142
|
...rest,
|
|
110
143
|
...executionParams
|
|
111
144
|
};
|
|
@@ -114,40 +147,53 @@ function createBashExecutionTool(params = {}) {
|
|
|
114
147
|
if (_injected_files && _injected_files.length > 0) postData.files = _injected_files;
|
|
115
148
|
else if (session_id != null && session_id.length > 0 && !Array.isArray(postData.files)) require_diagnostics.logCodeApiDiagnostic("BashExecutor", "debug", "session carried no injected files; exec will run without input files", { files: "none" });
|
|
116
149
|
try {
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
150
|
+
const resolvedAuthHeaders = await require_CodeExecutor.resolveCodeApiAuthHeaders(authHeaders);
|
|
151
|
+
let result;
|
|
152
|
+
if (hasWorkspace) result = await require_ProgrammaticToolCalling.makeRequest(execEndpoint, postData, void 0, {
|
|
153
|
+
...resolvedAuthHeaders,
|
|
154
|
+
"X-LibreChat-Code-Workspace-ID": workspaceId
|
|
155
|
+
}, executionProfile, config.signal);
|
|
156
|
+
else {
|
|
157
|
+
const fetchOptions = {
|
|
158
|
+
method: "POST",
|
|
159
|
+
headers: {
|
|
160
|
+
"Content-Type": "application/json",
|
|
161
|
+
"User-Agent": "LibreChat/1.0",
|
|
162
|
+
...require_CodeExecutor.addCodeApiExecutionProfileHeader(resolvedAuthHeaders, executionProfile)
|
|
163
|
+
},
|
|
164
|
+
body: JSON.stringify(postData),
|
|
165
|
+
signal: config.signal
|
|
166
|
+
};
|
|
167
|
+
const proxyAgent = require_proxy.resolveFetchProxyAgent(execEndpoint);
|
|
168
|
+
if (proxyAgent != null) fetchOptions.agent = proxyAgent;
|
|
169
|
+
const response = await (0, node_fetch.default)(execEndpoint, fetchOptions);
|
|
170
|
+
if (!response.ok) throw new require_CodeExecutor.CodeApiRequestError(await require_CodeExecutor.buildCodeApiHttpErrorMessage("POST", execEndpoint, response, { profile: executionProfile }));
|
|
171
|
+
result = await response.json();
|
|
172
|
+
}
|
|
173
|
+
if (hasWorkspace && result.status !== "completed") throw new require_CodeExecutor.CodeApiRequestError(require_CodeExecutor.buildCodeApiExecutionErrorMessage(result));
|
|
131
174
|
let formattedOutput = "";
|
|
132
|
-
if (result.stdout) formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
175
|
+
if (typeof result.stdout === "string" && result.stdout.length > 0) formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
133
176
|
else formattedOutput += require_CodeExecutor.emptyOutputMessage;
|
|
134
|
-
if (result.stderr) formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
135
|
-
const outputWithReminder = require_CodeExecutor.appendTmpScratchReminder(formattedOutput, command);
|
|
177
|
+
if (typeof result.stderr === "string" && result.stderr.length > 0) formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
178
|
+
const outputWithReminder = require_CodeExecutor.appendTmpScratchReminder(formattedOutput, command, hasWorkspace ? ATTACHED_BASH_TMP_REMINDER : void 0);
|
|
136
179
|
const artifactDelivery = require_ArtifactDelivery.normalizeArtifactDeliveryFailure(result.artifact_delivery);
|
|
137
180
|
const outputWithDeliveryWarning = require_ArtifactDelivery.appendArtifactDeliveryWarning(outputWithReminder, artifactDelivery);
|
|
138
181
|
const hasFiles = result.files != null && result.files.length > 0;
|
|
182
|
+
const deletionEcho = result.deleted_files != null ? { deleted_files: result.deleted_files } : {};
|
|
139
183
|
const runtimeEcho = result.runtime_session_id != null ? {
|
|
140
184
|
runtime_session_id: result.runtime_session_id,
|
|
141
185
|
runtime_status: result.runtime_status
|
|
142
186
|
} : {};
|
|
143
|
-
return [require_CodeSessionFileSummary.appendCodeSessionFileSummary(outputWithDeliveryWarning, result.files), hasFiles ? {
|
|
187
|
+
return [hasWorkspace ? require_CodeSessionFileSummary.appendExecutionArtifactFileSummary(outputWithDeliveryWarning, result.files) : require_CodeSessionFileSummary.appendCodeSessionFileSummary(outputWithDeliveryWarning, result.files), hasFiles ? {
|
|
144
188
|
session_id: result.session_id,
|
|
145
189
|
files: result.files,
|
|
146
190
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
191
|
+
...deletionEcho,
|
|
147
192
|
...runtimeEcho
|
|
148
193
|
} : {
|
|
149
194
|
session_id: result.session_id,
|
|
150
195
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
196
|
+
...deletionEcho,
|
|
151
197
|
...runtimeEcho
|
|
152
198
|
}];
|
|
153
199
|
} catch (error) {
|
|
@@ -155,8 +201,14 @@ function createBashExecutionTool(params = {}) {
|
|
|
155
201
|
}
|
|
156
202
|
}, {
|
|
157
203
|
name: BashExecutionToolName,
|
|
158
|
-
description: buildBashExecutionToolDescription({
|
|
159
|
-
|
|
204
|
+
description: buildBashExecutionToolDescription({
|
|
205
|
+
statefulSessions: params?.statefulSessions,
|
|
206
|
+
attachedWorkspace: hasWorkspace
|
|
207
|
+
}),
|
|
208
|
+
schema: buildBashExecutionToolSchema({
|
|
209
|
+
statefulSessions: params?.statefulSessions,
|
|
210
|
+
attachedWorkspace: hasWorkspace
|
|
211
|
+
}),
|
|
160
212
|
responseFormat: "content_and_artifact"
|
|
161
213
|
});
|
|
162
214
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BashExecutor.cjs","names":["INTENT_PROPERTY","CODE_ARTIFACT_PATH_GUIDANCE","BASH_SHELL_GUIDANCE","buildCodeApiEndpoint","getCodeBaseURL","
|
|
1
|
+
{"version":3,"file":"BashExecutor.cjs","names":["INTENT_PROPERTY","CODE_ARTIFACT_PATH_GUIDANCE","BASH_SHELL_GUIDANCE","buildCodeApiEndpoint","getCodeBaseURL","prepareBashProgrammaticCode","selectRuntimeSessionHint","resolveCodeApiAuthHeaders","makeRequest","addCodeApiExecutionProfileHeader","resolveFetchProxyAgent","CodeApiRequestError","buildCodeApiHttpErrorMessage","buildCodeApiExecutionErrorMessage","emptyOutputMessage","appendTmpScratchReminder","normalizeArtifactDeliveryFailure","appendArtifactDeliveryWarning","appendExecutionArtifactFileSummary","appendCodeSessionFileSummary","appendFailedExecutionFileReminder","normalizeCodeApiRequestError"],"sources":["../../../src/tools/BashExecutor.ts"],"mappings":";;;;;;;;;;;;;;;;mBAiCO;AAEP,MAAa,0BAA0B;CACrC,MAAM;CACN,YAAY;EACV,QAAQ,EAAE,GAAGA,kBAAAA,gBAAgB;EAC7B,SAAS;GACP,MAAM;GACN,aAAa;;;IAGfC,qBAAAA,4BAA4B;IAC5BC,qBAAAA,oBAAoB;;;;;EAKpB;EACA,MAAM;GACJ,MAAM;GACN,OAAO,EAAE,MAAM,SAAS;GACxB,aACE;EACJ;CACF;CACA,UAAU,CAAC,SAAS;AACtB;AAEA,MAAa,+BAA+B;;;;;;IAMxCD,qBAAAA,4BAA4B;IAC5BC,qBAAAA,oBAAoB;;EAEtB,KAAK;AAUP,MAAa,qBACX;AAEF,MAAa,uCAAuC;;;EAGlD,mBAAmB;;;;;IAKjBD,qBAAAA,4BAA4B;IAC5BC,qBAAAA,oBAAoB;;EAEtB,KAAK;AAEP,MAAM,gDAAgD;;;;;;;IAOlDA,qBAAAA,oBAAoB;;EAEtB,KAAK;AAYP,MAAa,gCAAgC;;;;;;;;;EAS3C,KAAK;AASP,SAAgB,kCAAkC,SAIvC;CACT,IAAI,OAAO;CACX,IAAI,SAAS,sBAAsB,MACjC,OAAO;MACF,IAAI,SAAS,qBAAqB,MACvC,OAAO;CAET,IAAI,SAAS,+BAA+B,MAC1C,OAAO,GAAG,KAAK,MAAM;CAEvB,OAA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,IACtC,CAAC;IACL,GAAG;IACH,GAAG;GACL,CACJ;EACF,SAAS,OAAO;GAKd,MAAM,IAAIR,qBAAAA,oBACR,uBAL0BS,qBAAAA,kCAC1BC,qBAAAA,6BAA6B,KAAK,CAAC,CAAC,SACpC,OAGyC,GAC3C;EACF;CACF,GACA;EACE,MAAM;EACN,aAAa,kCAAkC;GAC7C,kBAAkB,QAAQ;GAC1B,mBAAmB;EACrB,CAAC;EACD,QAAQ,6BAA6B;GACnC,kBAAkB,QAAQ;GAC1B,mBAAmB;EACrB,CAAC;EACD,gBAAA;CACF,CACF;AACF"}
|
|
@@ -12,6 +12,9 @@ let _langchain_core_tools = require("@langchain/core/tools");
|
|
|
12
12
|
const DEFAULT_MAX_ROUND_TRIPS = 20;
|
|
13
13
|
const DEFAULT_RUN_TIMEOUT_MS = require_ptcTimeout.resolveCodeApiRunTimeoutMs();
|
|
14
14
|
const BASH_LAST_BACKGROUND_PID_GUARD = ": &\nwait \"$!\"";
|
|
15
|
+
const CODE_API_WORKSPACE_HEADER = "X-LibreChat-Code-Workspace-ID";
|
|
16
|
+
const ATTACHED_BASH_DATA_DIRECTORY = "\"${LIBRECHAT_CODE_DATA_DIR:-/mnt/data}\"";
|
|
17
|
+
const ATTACHED_BASH_ARTIFACT_PATH_GUIDANCE = `Use ${ATTACHED_BASH_DATA_DIRECTORY} for injected files and generated artifacts. The directory is execution-scoped; the selected workspace is the persistent project root.`;
|
|
15
18
|
const BASH_RESERVED = new Set([
|
|
16
19
|
"if",
|
|
17
20
|
"then",
|
|
@@ -41,6 +44,10 @@ const STATELESS_WARNING = `CRITICAL - STATELESS EXECUTION:
|
|
|
41
44
|
Each call is a fresh bash shell. Variables and state do NOT persist between calls.
|
|
42
45
|
You MUST complete your entire workflow in ONE code block.
|
|
43
46
|
DO NOT split work across multiple calls expecting to reuse variables.`;
|
|
47
|
+
const ATTACHED_WORKSPACE_WARNING = `ATTACHED WORKSPACE EXECUTION:
|
|
48
|
+
- Commands start in the selected persistent workspace; project file changes persist between calls.
|
|
49
|
+
- Each sandbox run is a fresh process, so shell variables, background processes, and temporary execution data do not persist.
|
|
50
|
+
- Injected files and generated artifacts use \${LIBRECHAT_CODE_DATA_DIR:-/mnt/data}; do not copy them into the project unless the task requires it.`;
|
|
44
51
|
const CORE_RULES = `Rules:
|
|
45
52
|
- One call: state does not persist
|
|
46
53
|
- Tools are pre-defined as bash functions—DO NOT redefine them
|
|
@@ -63,6 +70,28 @@ Example (Parallel calls):
|
|
|
63
70
|
wait
|
|
64
71
|
echo "SF: $(jq -r . /mnt/data/sf.json)"
|
|
65
72
|
echo "NY: $(jq -r . /mnt/data/ny.json)"`;
|
|
73
|
+
const ATTACHED_CORE_RULES = `Rules:
|
|
74
|
+
- One call: process state does not persist; project files do
|
|
75
|
+
- Tools are pre-defined as bash functions—DO NOT redefine them
|
|
76
|
+
- Each tool function accepts a JSON string argument
|
|
77
|
+
- Resolve tool calls into variables before changing project files; do not redirect a tool call directly into the project
|
|
78
|
+
- Set data_dir=${ATTACHED_BASH_DATA_DIRECTORY}; save generated artifacts there, and write durable project files relative to the working directory
|
|
79
|
+
- Tool stdout is normalized to one compact JSON value when possible; parse saved stdout once, then use fromjson? // . only for JSON-string fields
|
|
80
|
+
- Only echo/printf output returns to the model
|
|
81
|
+
- ${ATTACHED_BASH_ARTIFACT_PATH_GUIDANCE}
|
|
82
|
+
- ${require_CodeExecutor.BASH_SHELL_GUIDANCE}
|
|
83
|
+
- timeout caps one sandbox run/replay iteration, not the total multi-round-trip workflow`;
|
|
84
|
+
const ATTACHED_EXAMPLES = `Example (Complete workflow in one call):
|
|
85
|
+
data=$(query_database '{"sql": "SELECT * FROM users"}')
|
|
86
|
+
echo "$data" | jq '.[] | .name'
|
|
87
|
+
|
|
88
|
+
Example (Parallel calls):
|
|
89
|
+
data_dir=${ATTACHED_BASH_DATA_DIRECTORY}
|
|
90
|
+
{ sf=$(web_search '{"query": "SF weather"}'); printf '%s\n' "$sf" > "$data_dir/sf.json"; } &
|
|
91
|
+
{ ny=$(web_search '{"query": "NY weather"}'); printf '%s\n' "$ny" > "$data_dir/ny.json"; } &
|
|
92
|
+
wait
|
|
93
|
+
echo "SF: $(jq -r . "$data_dir/sf.json")"
|
|
94
|
+
echo "NY: $(jq -r . "$data_dir/ny.json")"`;
|
|
66
95
|
const CODE_PARAM_DESCRIPTION = `Bash code that calls tools programmatically. Tools are available as bash functions.
|
|
67
96
|
|
|
68
97
|
${STATELESS_WARNING}
|
|
@@ -174,7 +203,17 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
174
203
|
const maxRunTimeoutMs = require_ptcTimeout.resolveCodeApiRunTimeoutMs(initParams.runTimeoutMs);
|
|
175
204
|
const proxy = initParams.proxy ?? process.env.PROXY;
|
|
176
205
|
const debug = initParams.debug ?? process.env.BASH_PTC_DEBUG === "true";
|
|
206
|
+
const workspaceId = initParams.workspaceId?.trim();
|
|
207
|
+
const hasWorkspace = workspaceId != null && workspaceId !== "";
|
|
208
|
+
if (hasWorkspace && !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(workspaceId)) throw new Error("Invalid attached workspace identifier");
|
|
209
|
+
const requestAuthHeaders = hasWorkspace ? async () => ({
|
|
210
|
+
...await require_CodeExecutor.resolveCodeApiAuthHeaders(initParams.authHeaders),
|
|
211
|
+
[CODE_API_WORKSPACE_HEADER]: workspaceId
|
|
212
|
+
}) : initParams.authHeaders ?? {};
|
|
177
213
|
const EXEC_ENDPOINT = require_CodeExecutor.buildCodeApiEndpoint(baseUrl, "exec/programmatic");
|
|
214
|
+
const description = hasWorkspace ? BashProgrammaticToolCallingDescription.replace(STATELESS_WARNING, ATTACHED_WORKSPACE_WARNING).replace(CORE_RULES, ATTACHED_CORE_RULES).replace(EXAMPLES, ATTACHED_EXAMPLES) : BashProgrammaticToolCallingDescription;
|
|
215
|
+
const schema = createBashProgrammaticToolCallingSchema(maxRunTimeoutMs);
|
|
216
|
+
if (hasWorkspace) schema.properties.code.description = CODE_PARAM_DESCRIPTION.replace(STATELESS_WARNING, ATTACHED_WORKSPACE_WARNING).replace(CORE_RULES, ATTACHED_CORE_RULES).replace(EXAMPLES, ATTACHED_EXAMPLES);
|
|
178
217
|
return (0, _langchain_core_tools.tool)(async (rawParams, config) => {
|
|
179
218
|
const params = rawParams;
|
|
180
219
|
const { code } = params;
|
|
@@ -205,7 +244,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
205
244
|
else if (session_id != null && session_id.length > 0) require_diagnostics.logCodeApiDiagnostic("BashProgrammaticToolCalling", "debug", "session carried no injected files; exec will run without input files", { files: "none" });
|
|
206
245
|
const selectedRuntimeSessionHint = require_CodeExecutor.selectRuntimeSessionHint(initParams.runtimeSessionHint, _runtime_session_hint);
|
|
207
246
|
const runtimeSessionHint = initParams.executionProfile !== "default" && typeof selectedRuntimeSessionHint === "string" && selectedRuntimeSessionHint !== "" ? selectedRuntimeSessionHint : void 0;
|
|
208
|
-
if (needsNoTools) return await require_ProgrammaticToolCalling.runPlainExecution({
|
|
247
|
+
if (needsNoTools && !hasWorkspace) return await require_ProgrammaticToolCalling.runPlainExecution({
|
|
209
248
|
baseUrl,
|
|
210
249
|
lang: "bash",
|
|
211
250
|
code,
|
|
@@ -214,7 +253,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
214
253
|
files,
|
|
215
254
|
runtimeSessionHint,
|
|
216
255
|
proxy,
|
|
217
|
-
authHeaders:
|
|
256
|
+
authHeaders: requestAuthHeaders,
|
|
218
257
|
executionProfile: initParams.executionProfile
|
|
219
258
|
});
|
|
220
259
|
let response = await require_ProgrammaticToolCalling.makeRequest(EXEC_ENDPOINT, {
|
|
@@ -225,7 +264,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
225
264
|
timeout,
|
|
226
265
|
...files && files.length > 0 ? { files } : {},
|
|
227
266
|
...runtimeSessionHint != null ? { runtime_session_hint: runtimeSessionHint } : {}
|
|
228
|
-
}, proxy, initParams.
|
|
267
|
+
}, proxy, requestAuthHeaders, initParams.executionProfile, config.signal);
|
|
229
268
|
while (response.status === "tool_call_required") {
|
|
230
269
|
roundTrip++;
|
|
231
270
|
if (roundTrip > maxRoundTrips) throw new Error(`Exceeded maximum round trips (${maxRoundTrips}). This may indicate an infinite loop, excessive tool calls, or a logic error in your code.`);
|
|
@@ -234,9 +273,9 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
234
273
|
response = await require_ProgrammaticToolCalling.makeRequest(EXEC_ENDPOINT, {
|
|
235
274
|
continuation_token: response.continuation_token,
|
|
236
275
|
tool_results: toolResults
|
|
237
|
-
}, proxy, initParams.
|
|
276
|
+
}, proxy, requestAuthHeaders, initParams.executionProfile, config.signal);
|
|
238
277
|
}
|
|
239
|
-
if (response.status === "completed") return require_ProgrammaticToolCalling.formatCompletedResponse(response, code);
|
|
278
|
+
if (response.status === "completed") return require_ProgrammaticToolCalling.formatCompletedResponse(response, code, hasWorkspace ? "execution" : "session");
|
|
240
279
|
if (response.status === "error") throw new Error(require_CodeExecutor.buildCodeApiExecutionErrorMessage(response));
|
|
241
280
|
throw new require_CodeExecutor.CodeApiRequestError();
|
|
242
281
|
} catch (error) {
|
|
@@ -246,8 +285,8 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
246
285
|
}
|
|
247
286
|
}, {
|
|
248
287
|
name: "run_tools_with_bash",
|
|
249
|
-
description
|
|
250
|
-
schema
|
|
288
|
+
description,
|
|
289
|
+
schema,
|
|
251
290
|
responseFormat: "content_and_artifact"
|
|
252
291
|
});
|
|
253
292
|
}
|
|
@@ -262,5 +301,6 @@ exports.extractUsedBashToolNames = extractUsedBashToolNames;
|
|
|
262
301
|
exports.filterBashToolsByUsage = filterBashToolsByUsage;
|
|
263
302
|
exports.normalizeBashToolResultsForReplay = normalizeBashToolResultsForReplay;
|
|
264
303
|
exports.normalizeToBashIdentifier = normalizeToBashIdentifier;
|
|
304
|
+
exports.prepareBashProgrammaticCode = prepareBashProgrammaticCode;
|
|
265
305
|
|
|
266
306
|
//# sourceMappingURL=BashProgrammaticToolCalling.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BashProgrammaticToolCalling.cjs","names":["resolveCodeApiRunTimeoutMs","CODE_ARTIFACT_PATH_GUIDANCE","BASH_SHELL_GUIDANCE","INTENT_PROPERTY","createCodeApiRunTimeoutSchema","getCodeBaseURL","buildCodeApiEndpoint","clampCodeApiRunTimeoutMs","resolveProgrammaticToolDefinitions","selectProgrammaticTools","projectProgrammaticToolMap","selectRuntimeSessionHint","runPlainExecution","makeRequest","executeTools","formatCompletedResponse","buildCodeApiExecutionErrorMessage","CodeApiRequestError","appendFailedExecutionFileReminder"],"sources":["../../../src/tools/BashProgrammaticToolCalling.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"BashProgrammaticToolCalling.cjs","names":["resolveCodeApiRunTimeoutMs","CODE_ARTIFACT_PATH_GUIDANCE","BASH_SHELL_GUIDANCE","INTENT_PROPERTY","createCodeApiRunTimeoutSchema","getCodeBaseURL","resolveCodeApiAuthHeaders","buildCodeApiEndpoint","clampCodeApiRunTimeoutMs","resolveProgrammaticToolDefinitions","selectProgrammaticTools","projectProgrammaticToolMap","selectRuntimeSessionHint","runPlainExecution","makeRequest","executeTools","formatCompletedResponse","buildCodeApiExecutionErrorMessage","CodeApiRequestError","appendFailedExecutionFileReminder"],"sources":["../../../src/tools/BashProgrammaticToolCalling.ts"],"mappings":";;;;;;;;;;8BAsCO;AAMP,MAAM,0BAA0B;AAChC,MAAM,yBAAyBA,mBAAAA,2BAA2B;AAC1D,MAAM,iCAAiC;AACvC,MAAM,4BAA4B;AAClC,MAAM,+BAA+B;AACrC,MAAM,uCACJ,OAAO,6BAA6B;AAItC,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;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scratch only and were not persisted; use /mnt/data for files needed later.";
|
|
29
29
|
const FAILED_EXECUTION_FILE_REMINDER = "Note: any files written during this failed call were not registered for later calls; fix the error and rerun before relying on them.";
|
|
30
|
-
function appendTmpScratchReminder(output, code) {
|
|
30
|
+
function appendTmpScratchReminder(output, code, reminder = TMP_SCRATCH_OUTPUT_REMINDER) {
|
|
31
31
|
if (!TMP_PATH_PATTERN.test(code)) return output;
|
|
32
|
-
return `${output.trimEnd()}\n${
|
|
32
|
+
return `${output.trimEnd()}\n${reminder}\n`;
|
|
33
33
|
}
|
|
34
34
|
function appendFailedExecutionFileReminder(output, code) {
|
|
35
35
|
if (output.includes("Code execution is not supported by the selected environment.") || !MNT_DATA_PATH_PATTERN.test(code) || output.includes("Note: any files written during this failed call were not registered for later calls; fix the error and rerun before relying on them.")) return output;
|
|
@@ -312,6 +312,7 @@ function createCodeExecutionTool(params = {}) {
|
|
|
312
312
|
const artifactDelivery = require_ArtifactDelivery.normalizeArtifactDeliveryFailure(result.artifact_delivery);
|
|
313
313
|
const outputWithDeliveryWarning = require_ArtifactDelivery.appendArtifactDeliveryWarning(outputWithReminder, artifactDelivery);
|
|
314
314
|
const hasFiles = result.files != null && result.files.length > 0;
|
|
315
|
+
const deletionEcho = result.deleted_files != null ? { deleted_files: result.deleted_files } : {};
|
|
315
316
|
const runtimeEcho = result.runtime_session_id != null ? {
|
|
316
317
|
runtime_session_id: result.runtime_session_id,
|
|
317
318
|
runtime_status: result.runtime_status
|
|
@@ -320,10 +321,12 @@ function createCodeExecutionTool(params = {}) {
|
|
|
320
321
|
session_id: result.session_id,
|
|
321
322
|
files: result.files,
|
|
322
323
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
324
|
+
...deletionEcho,
|
|
323
325
|
...runtimeEcho
|
|
324
326
|
} : {
|
|
325
327
|
session_id: result.session_id,
|
|
326
328
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
329
|
+
...deletionEcho,
|
|
327
330
|
...runtimeEcho
|
|
328
331
|
}];
|
|
329
332
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.cjs","names":["INTENT_PROPERTY","describeCodeApiError","resolveFetchProxyAgent","normalizeArtifactDeliveryFailure","appendArtifactDeliveryWarning","appendCodeSessionFileSummary"],"sources":["../../../src/tools/CodeExecutor.ts"],"mappings":";;;;;;;;;;;;;;mBAyBO;AAEP,MAAa,wBAAA,GAAA,0BAAA,uBAAA,CAAA,wBAC+B,KAAA;AAG5C,SAAgB,qBAAqB,SAAiB,OAAuB;CAC3E,OAAO,GAAG,QAAQ,QAAQ,QAAQ,EAAE,EAAE,GAAG,MAAM,QAAQ,QAAQ,EAAE;AACnE;AAEA,SAAgB,yBACd,aACA,cACoB;CACpB,OAAO,eAAe,QAAQ,gBAAgB,KAAK,cAAc;AACnE;AAEA,MAAa,qBACX;AAEF,MAAa,8BACX;AAEF,MAAa,sBACX;AAEF,MAAM,mBAAmB;AACzB,MAAM,wBAAwB;AAE9B,MAAa,8BACX;AAEF,MAAa,iCACX;AAEF,SAAgB,
|
|
1
|
+
{"version":3,"file":"CodeExecutor.cjs","names":["INTENT_PROPERTY","describeCodeApiError","resolveFetchProxyAgent","normalizeArtifactDeliveryFailure","appendArtifactDeliveryWarning","appendCodeSessionFileSummary"],"sources":["../../../src/tools/CodeExecutor.ts"],"mappings":";;;;;;;;;;;;;;mBAyBO;AAEP,MAAa,wBAAA,GAAA,0BAAA,uBAAA,CAAA,wBAC+B,KAAA;AAG5C,SAAgB,qBAAqB,SAAiB,OAAuB;CAC3E,OAAO,GAAG,QAAQ,QAAQ,QAAQ,EAAE,EAAE,GAAG,MAAM,QAAQ,QAAQ,EAAE;AACnE;AAEA,SAAgB,yBACd,aACA,cACoB;CACpB,OAAO,eAAe,QAAQ,gBAAgB,KAAK,cAAc;AACnE;AAEA,MAAa,qBACX;AAEF,MAAa,8BACX;AAEF,MAAa,sBACX;AAEF,MAAM,m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ACF,CACF;AACF"}
|
|
@@ -12,6 +12,7 @@ const IMAGE_FILE_EXTENSIONS = new Set([
|
|
|
12
12
|
".webp"
|
|
13
13
|
]);
|
|
14
14
|
const CODE_SESSION_FILE_SUMMARY_PATTERN = /^Generated files:\nSession files: \d+ persisted file\(s\) are available in \/mnt\/data, including \d+ image\(s\)\. Use known \/mnt\/data paths directly in later code-tool calls\. The app displays files\/images automatically; do not invent download links or wrap generated images in Markdown\.$/;
|
|
15
|
+
const EXECUTION_ARTIFACT_FILE_SUMMARY_PATTERN = /^Generated files:\nExecution artifacts: \d+ file\(s\), including \d+ image\(s\), were delivered to the app\. They are not retained in the attached project; write durable files to the project root when later commands must reuse them\. The app displays files\/images automatically; do not invent download links or wrap generated images in Markdown\.$/;
|
|
15
16
|
function getFileExtension(name) {
|
|
16
17
|
const lastSlash = name.lastIndexOf("/");
|
|
17
18
|
const basename = lastSlash >= 0 ? name.slice(lastSlash + 1) : name;
|
|
@@ -35,7 +36,7 @@ function stripCodeSessionFileSummary(output) {
|
|
|
35
36
|
const beforeSummary = output.slice(0, summaryStart);
|
|
36
37
|
if (beforeSummary !== "" && !beforeSummary.endsWith("\n\n")) return output;
|
|
37
38
|
const maybeSummary = output.slice(summaryStart);
|
|
38
|
-
if (!CODE_SESSION_FILE_SUMMARY_PATTERN.test(maybeSummary)) return output;
|
|
39
|
+
if (!CODE_SESSION_FILE_SUMMARY_PATTERN.test(maybeSummary) && !EXECUTION_ARTIFACT_FILE_SUMMARY_PATTERN.test(maybeSummary)) return output;
|
|
39
40
|
return beforeSummary.trimEnd();
|
|
40
41
|
}
|
|
41
42
|
function appendCodeSessionFileSummary(output, files) {
|
|
@@ -46,8 +47,17 @@ function appendCodeSessionFileSummary(output, files) {
|
|
|
46
47
|
const summary = buildCodeSessionFileSummary(generatedFiles.length, imageCount);
|
|
47
48
|
return `${output.trimEnd()}\n\n${summary}`.trim();
|
|
48
49
|
}
|
|
50
|
+
function appendExecutionArtifactFileSummary(output, files) {
|
|
51
|
+
const generatedFiles = files?.filter(isGeneratedFile) ?? [];
|
|
52
|
+
if (generatedFiles.length === 0) return output.trim();
|
|
53
|
+
const imageCount = generatedFiles.filter(isImageFile).length;
|
|
54
|
+
const summary = `Generated files:
|
|
55
|
+
Execution artifacts: ${generatedFiles.length} file(s), including ${imageCount} image(s), were delivered to the app. They are not retained in the attached project; write durable files to the project root when later commands must reuse them. The app displays files/images automatically; do not invent download links or wrap generated images in Markdown.`;
|
|
56
|
+
return `${output.trimEnd()}\n\n${summary}`.trim();
|
|
57
|
+
}
|
|
49
58
|
//#endregion
|
|
50
59
|
exports.appendCodeSessionFileSummary = appendCodeSessionFileSummary;
|
|
60
|
+
exports.appendExecutionArtifactFileSummary = appendExecutionArtifactFileSummary;
|
|
51
61
|
exports.stripCodeSessionFileSummary = stripCodeSessionFileSummary;
|
|
52
62
|
|
|
53
63
|
//# sourceMappingURL=CodeSessionFileSummary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeSessionFileSummary.cjs","names":[],"sources":["../../../src/tools/CodeSessionFileSummary.ts"],"mappings":";AAEA,MAAM,wBAAwB,IAAI,IAAI;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,oCACJ;AAEF,SAAS,iBAAiB,MAAsB;CAC9C,MAAM,YAAY,KAAK,YAAY,GAAG;CACtC,MAAM,WAAW,aAAa,IAAI,KAAK,MAAM,YAAY,CAAC,IAAI;CAC9D,MAAM,UAAU,SAAS,YAAY,GAAG;CACxC,OAAO,WAAW,IAAI,SAAS,MAAM,OAAO,CAAC,CAAC,YAAY,IAAI;AAChE;AAEA,SAAS,YAAY,MAAsD;CACzE,MAAM,OAAO,MAAM;CACnB,OACE,OAAO,SAAS,YAChB,sBAAsB,IAAI,iBAAiB,IAAI,CAAC;AAEpD;AAEA,SAAS,4BACP,WACA,YACQ;CACR,OACE;iBACkB,UAAU,2DAA2D,WAAW;AAItG;AA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M,eAAe,OAAO,MAAM,YAAY;CAC9C,IACE,CAAC,kCAAkC,KAAK,YAAY,KACpD,CAAC,wCAAwC,KAAK,YAAY,GAE1D,OAAO;CAET,OAAO,cAAc,QAAQ;AAC/B;AAEA,SAAgB,6BACd,QACA,OACQ;CACR,IAAI,SAAS,QAAQ,MAAM,WAAW,GACpC,OAAO,OAAO,KAAK;CAGrB,MAAM,iBAAiB,MAAM,OAAO,eAAe;CACnD,IAAI,eAAe,WAAW,GAC5B,OAAO,OAAO,KAAK;CAGrB,MAAM,aAAa,eAAe,OAAO,WAAW,CAAC,CAAC;CACtD,MAAM,UAAU,4BACd,eAAe,QACf,UACF;CAEA,OAAO,GAAG,OAAO,QAAQ,EAAE,MAAM,UAAU,KAAK;AAClD;AAIA,SAAgB,mCACd,QACA,OACQ;CACR,MAAM,iBAAiB,OAAO,OAAO,eAAe,KAAK,CAAC;CAC1D,IAAI,eAAe,WAAW,GAAG,OAAO,OAAO,KAAK;CACpD,MAAM,aAAa,eAAe,OAAO,WAAW,CAAC,CAAC;CACtD,MAAM,UACJ;uBACwB,eAAe,OAAO,sBAAsB,WAAW;CAGjF,OAAO,GAAG,OAAO,QAAQ,EAAE,MAAM,UAAU,KAAK;AAClD"}
|
|
@@ -9,6 +9,7 @@ const require_CodeSessionFileSummary = require("./CodeSessionFileSummary.cjs");
|
|
|
9
9
|
const require_CodeExecutor = require("./CodeExecutor.cjs");
|
|
10
10
|
const require_ProgrammaticCallerPolicy = require("./ProgrammaticCallerPolicy.cjs");
|
|
11
11
|
const require_ptcTimeout = require("./ptcTimeout.cjs");
|
|
12
|
+
let node_crypto = require("node:crypto");
|
|
12
13
|
let _langchain_core_tools = require("@langchain/core/tools");
|
|
13
14
|
let dotenv = require("dotenv");
|
|
14
15
|
let node_fetch = require("node-fetch");
|
|
@@ -17,6 +18,8 @@ node_fetch = require_runtime.__toESM(node_fetch, 1);
|
|
|
17
18
|
(0, dotenv.config)();
|
|
18
19
|
const DEFAULT_MAX_ROUND_TRIPS = 20;
|
|
19
20
|
const DEFAULT_RUN_TIMEOUT_MS = require_ptcTimeout.resolveCodeApiRunTimeoutMs();
|
|
21
|
+
const CODE_API_PROGRAMMATIC_REQUEST_HEADER = "X-LibreChat-Code-Request-ID";
|
|
22
|
+
const CANCELLATION_REQUEST_TIMEOUT_MS = 2e3;
|
|
20
23
|
const STATELESS_WARNING = `CRITICAL - STATELESS EXECUTION:
|
|
21
24
|
Each call is a fresh Python interpreter. Variables, imports, and data do NOT persist between calls.
|
|
22
25
|
You MUST complete your entire workflow in ONE code block: query → process → output.
|
|
@@ -249,20 +252,61 @@ async function fetchSessionFiles(baseUrl, sessionId, scopeOrProxy, proxyOrAuthHe
|
|
|
249
252
|
return [];
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
|
-
async function makeRequest(endpoint, body, proxy, authHeaders, executionProfile) {
|
|
255
|
+
async function makeRequest(endpoint, body, proxy, authHeaders, executionProfile, signal) {
|
|
253
256
|
try {
|
|
257
|
+
const resolvedAuthHeaders = await require_CodeExecutor.resolveCodeApiAuthHeaders(authHeaders);
|
|
258
|
+
const requestId = signal != null ? (0, node_crypto.randomUUID)() : void 0;
|
|
254
259
|
const fetchOptions = {
|
|
255
260
|
method: "POST",
|
|
256
261
|
headers: {
|
|
257
262
|
"Content-Type": "application/json",
|
|
258
263
|
"User-Agent": "LibreChat/1.0",
|
|
259
|
-
...require_CodeExecutor.addCodeApiExecutionProfileHeader(
|
|
264
|
+
...require_CodeExecutor.addCodeApiExecutionProfileHeader(resolvedAuthHeaders, executionProfile),
|
|
265
|
+
...requestId != null ? { [CODE_API_PROGRAMMATIC_REQUEST_HEADER]: requestId } : {}
|
|
260
266
|
},
|
|
261
|
-
body: JSON.stringify(body)
|
|
267
|
+
body: JSON.stringify(body),
|
|
268
|
+
signal
|
|
262
269
|
};
|
|
263
270
|
const proxyAgent = require_proxy.resolveFetchProxyAgent(endpoint, proxy);
|
|
264
271
|
if (proxyAgent != null) fetchOptions.agent = proxyAgent;
|
|
265
|
-
|
|
272
|
+
let cancellationRequest;
|
|
273
|
+
const requestCancellation = () => {
|
|
274
|
+
if (requestId == null || cancellationRequest != null) return;
|
|
275
|
+
cancellationRequest = (async () => {
|
|
276
|
+
const cancellationController = new AbortController();
|
|
277
|
+
const timeout = setTimeout(() => cancellationController.abort(), CANCELLATION_REQUEST_TIMEOUT_MS);
|
|
278
|
+
try {
|
|
279
|
+
const cancelOptions = {
|
|
280
|
+
method: "POST",
|
|
281
|
+
headers: {
|
|
282
|
+
"Content-Type": "application/json",
|
|
283
|
+
"User-Agent": "LibreChat/1.0",
|
|
284
|
+
...require_CodeExecutor.addCodeApiExecutionProfileHeader(resolvedAuthHeaders, executionProfile)
|
|
285
|
+
},
|
|
286
|
+
body: JSON.stringify({ request_id: requestId }),
|
|
287
|
+
signal: cancellationController.signal
|
|
288
|
+
};
|
|
289
|
+
if (proxyAgent != null) cancelOptions.agent = proxyAgent;
|
|
290
|
+
await (0, node_fetch.default)(`${endpoint}/cancel`, cancelOptions);
|
|
291
|
+
} catch {} finally {
|
|
292
|
+
clearTimeout(timeout);
|
|
293
|
+
}
|
|
294
|
+
})();
|
|
295
|
+
};
|
|
296
|
+
signal?.addEventListener("abort", requestCancellation, { once: true });
|
|
297
|
+
if (signal?.aborted === true) requestCancellation();
|
|
298
|
+
let response;
|
|
299
|
+
try {
|
|
300
|
+
response = await (0, node_fetch.default)(endpoint, fetchOptions);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
if (signal?.aborted === true) {
|
|
303
|
+
requestCancellation();
|
|
304
|
+
await cancellationRequest;
|
|
305
|
+
}
|
|
306
|
+
throw error;
|
|
307
|
+
} finally {
|
|
308
|
+
signal?.removeEventListener("abort", requestCancellation);
|
|
309
|
+
}
|
|
266
310
|
if (!response.ok) throw new require_CodeExecutor.CodeApiRequestError(await require_CodeExecutor.buildCodeApiHttpErrorMessage("POST", endpoint, response, { profile: executionProfile }));
|
|
267
311
|
return await response.json();
|
|
268
312
|
} catch (error) {
|
|
@@ -405,16 +449,18 @@ async function executeTools(toolCalls, toolMap, programmaticToolName = "run_tool
|
|
|
405
449
|
});
|
|
406
450
|
return await Promise.all(executions);
|
|
407
451
|
}
|
|
408
|
-
function formatCompletedResponse(response, sourceCode = "") {
|
|
452
|
+
function formatCompletedResponse(response, sourceCode = "", filePersistence = "session") {
|
|
409
453
|
let formatted = "";
|
|
410
454
|
if (response.stdout != null && response.stdout !== "") formatted += `stdout:\n${response.stdout}\n`;
|
|
411
455
|
else formatted += require_CodeExecutor.emptyOutputMessage;
|
|
412
456
|
if (response.stderr != null && response.stderr !== "") formatted += `stderr:\n${response.stderr}\n`;
|
|
413
457
|
const outputWithReminder = require_CodeExecutor.appendTmpScratchReminder(formatted, sourceCode);
|
|
414
458
|
const artifactDelivery = require_ArtifactDelivery.normalizeArtifactDeliveryFailure(response.artifact_delivery);
|
|
415
|
-
|
|
459
|
+
const outputWithDeliveryWarning = require_ArtifactDelivery.appendArtifactDeliveryWarning(outputWithReminder, artifactDelivery);
|
|
460
|
+
return [filePersistence === "execution" ? require_CodeSessionFileSummary.appendExecutionArtifactFileSummary(outputWithDeliveryWarning, response.files) : require_CodeSessionFileSummary.appendCodeSessionFileSummary(outputWithDeliveryWarning, response.files), {
|
|
416
461
|
session_id: response.session_id,
|
|
417
462
|
files: response.files,
|
|
463
|
+
...response.deleted_files != null ? { deleted_files: response.deleted_files } : {},
|
|
418
464
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
419
465
|
...response.runtime_session_id != null ? {
|
|
420
466
|
runtime_session_id: response.runtime_session_id,
|
|
@@ -496,7 +542,7 @@ function createProgrammaticToolCallingTool(initParams = {}) {
|
|
|
496
542
|
timeout,
|
|
497
543
|
...files && files.length > 0 ? { files } : {},
|
|
498
544
|
...runtimeSessionHint != null ? { runtime_session_hint: runtimeSessionHint } : {}
|
|
499
|
-
}, proxy, initParams.authHeaders, initParams.executionProfile);
|
|
545
|
+
}, proxy, initParams.authHeaders, initParams.executionProfile, config.signal);
|
|
500
546
|
while (response.status === "tool_call_required") {
|
|
501
547
|
roundTrip++;
|
|
502
548
|
if (roundTrip > maxRoundTrips) throw new Error(`Exceeded maximum round trips (${maxRoundTrips}). This may indicate an infinite loop, excessive tool calls, or a logic error in your code.`);
|
|
@@ -505,7 +551,7 @@ function createProgrammaticToolCallingTool(initParams = {}) {
|
|
|
505
551
|
response = await makeRequest(EXEC_ENDPOINT, {
|
|
506
552
|
continuation_token: response.continuation_token,
|
|
507
553
|
tool_results: toolResults
|
|
508
|
-
}, proxy, initParams.authHeaders, initParams.executionProfile);
|
|
554
|
+
}, proxy, initParams.authHeaders, initParams.executionProfile, config.signal);
|
|
509
555
|
}
|
|
510
556
|
if (response.status === "completed") return formatCompletedResponse(response, code);
|
|
511
557
|
if (response.status === "error") throw new Error(require_CodeExecutor.buildCodeApiExecutionErrorMessage(response));
|