@librechat/agents 3.8.5 → 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/agents/AgentContext.cjs +1 -1
- package/dist/cjs/common/constants.cjs +2 -0
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +18 -9
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hitl/approvalReview.cjs +1 -1
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/main.cjs +8 -6
- package/dist/cjs/messages/index.cjs +1 -1
- package/dist/cjs/messages/prune.cjs +1 -1
- package/dist/cjs/run.cjs +7 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +13 -3
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +3 -1
- package/dist/cjs/summarization/node.cjs.map +1 -1
- 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 +176 -43
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +1 -0
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +120 -26
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/toolBatchReplay.cjs +4 -2
- package/dist/cjs/tools/toolBatchReplay.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/esm/agents/AgentContext.mjs +1 -1
- package/dist/esm/common/constants.mjs +2 -1
- package/dist/esm/common/constants.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +17 -8
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hitl/approvalReview.mjs +1 -1
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/main.mjs +7 -7
- package/dist/esm/messages/index.mjs +1 -1
- package/dist/esm/messages/prune.mjs +1 -1
- package/dist/esm/run.mjs +7 -3
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +13 -3
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +3 -1
- package/dist/esm/summarization/node.mjs.map +1 -1
- 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 +176 -43
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +1 -0
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +120 -26
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/toolBatchReplay.mjs +4 -2
- package/dist/esm/tools/toolBatchReplay.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/types/common/constants.d.ts +2 -0
- package/dist/types/graphs/Graph.d.ts +3 -2
- package/dist/types/hooks/types.d.ts +3 -0
- package/dist/types/run.d.ts +1 -0
- package/dist/types/summarization/node.d.ts +1 -0
- 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 +6 -2
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +7 -4
- package/dist/types/tools/toolBatchReplay.d.ts +2 -0
- package/dist/types/types/graph.d.ts +28 -0
- package/dist/types/types/run.d.ts +2 -0
- package/dist/types/types/tools.d.ts +27 -3
- package/package.json +2 -2
- package/src/common/constants.ts +3 -0
- package/src/graphs/Graph.ts +32 -18
- package/src/hooks/types.ts +3 -0
- package/src/run.ts +30 -15
- package/src/stream.ts +27 -5
- package/src/summarization/node.ts +3 -0
- 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 +665 -170
- package/src/tools/local/LocalProgrammaticToolCalling.ts +1 -0
- package/src/tools/subagent/SubagentExecutionRegistry.ts +0 -1
- package/src/tools/subagent/SubagentExecutor.ts +214 -55
- package/src/tools/toolBatchReplay.ts +23 -1
- package/src/types/graph.ts +37 -0
- package/src/types/run.ts +2 -0
- package/src/types/tools.ts +30 -3
- package/src/utils/llmConfig.ts +0 -1
|
@@ -4,8 +4,10 @@ import { resolveFetchProxyAgent } from "../utils/proxy.mjs";
|
|
|
4
4
|
import { INTENT_PROPERTY } from "./intentArg.mjs";
|
|
5
5
|
import { appendArtifactDeliveryWarning, normalizeArtifactDeliveryFailure } from "./ArtifactDelivery.mjs";
|
|
6
6
|
import { logCodeApiDiagnostic } from "./diagnostics.mjs";
|
|
7
|
-
import { appendCodeSessionFileSummary } from "./CodeSessionFileSummary.mjs";
|
|
8
|
-
import { BASH_SHELL_GUIDANCE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, addCodeApiExecutionProfileHeader, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiEndpoint, buildCodeApiHttpErrorMessage, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders, selectRuntimeSessionHint } from "./CodeExecutor.mjs";
|
|
7
|
+
import { appendCodeSessionFileSummary, appendExecutionArtifactFileSummary } from "./CodeSessionFileSummary.mjs";
|
|
8
|
+
import { BASH_SHELL_GUIDANCE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, addCodeApiExecutionProfileHeader, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, buildCodeApiHttpErrorMessage, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders, selectRuntimeSessionHint } from "./CodeExecutor.mjs";
|
|
9
|
+
import { makeRequest } from "./ProgrammaticToolCalling.mjs";
|
|
10
|
+
import { prepareBashProgrammaticCode } from "./BashProgrammaticToolCalling.mjs";
|
|
9
11
|
import { tool } from "@langchain/core/tools";
|
|
10
12
|
import { config } from "dotenv";
|
|
11
13
|
import fetch from "node-fetch";
|
|
@@ -58,6 +60,16 @@ Usage:
|
|
|
58
60
|
- ${BASH_SHELL_GUIDANCE}
|
|
59
61
|
- NEVER use this tool to execute malicious commands.
|
|
60
62
|
`.trim();
|
|
63
|
+
const AttachedWorkspaceBashExecutionToolDescription = `
|
|
64
|
+
Runs bash commands in the selected persistent project through an isolated sandbox process.
|
|
65
|
+
|
|
66
|
+
Usage:
|
|
67
|
+
- Project file changes persist between calls; shell variables, background processes, and execution-private temporary files do not.
|
|
68
|
+
- Injected files and generated artifacts use \${LIBRECHAT_CODE_DATA_DIR:-/mnt/data}; write durable files to the project root.
|
|
69
|
+
- Generated artifacts are automatically delivered; **DO NOT** provide download links.
|
|
70
|
+
- ${BASH_SHELL_GUIDANCE}
|
|
71
|
+
- NEVER use this tool to execute malicious commands.
|
|
72
|
+
`.trim();
|
|
61
73
|
const BashToolOutputReferencesGuide = `
|
|
62
74
|
Referencing previous tool outputs:
|
|
63
75
|
- 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.
|
|
@@ -69,15 +81,23 @@ Referencing previous tool outputs:
|
|
|
69
81
|
- Unknown reference keys are left in place and surfaced as \`[unresolved refs: …]\` after the output.
|
|
70
82
|
`.trim();
|
|
71
83
|
function buildBashExecutionToolDescription(options) {
|
|
72
|
-
|
|
84
|
+
let base = BashExecutionToolDescription;
|
|
85
|
+
if (options?.attachedWorkspace === true) base = AttachedWorkspaceBashExecutionToolDescription;
|
|
86
|
+
else if (options?.statefulSessions === true) base = StatefulBashExecutionToolDescription;
|
|
73
87
|
if (options?.enableToolOutputReferences === true) return `${base}\n\n${BashToolOutputReferencesGuide}`;
|
|
74
88
|
return base;
|
|
75
89
|
}
|
|
76
90
|
const STATELESS_BASH_PARAM_NOTE = "The environment is stateless; variables and state don't persist between executions.";
|
|
77
91
|
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.";
|
|
92
|
+
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.";
|
|
93
|
+
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.";
|
|
94
|
+
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.";
|
|
78
95
|
function buildBashExecutionToolSchema(opts) {
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
let note = STATELESS_BASH_PARAM_NOTE;
|
|
97
|
+
if (opts?.attachedWorkspace === true) note = ATTACHED_BASH_PARAM_NOTE;
|
|
98
|
+
else if (opts?.statefulSessions === true) note = STATEFUL_BASH_PARAM_NOTE;
|
|
99
|
+
let commandDescription = BashExecutionToolSchema.properties.command.description.replace(STATELESS_BASH_PARAM_NOTE, note);
|
|
100
|
+
if (opts?.attachedWorkspace === true) commandDescription = commandDescription.replace("- Prior /mnt/data files are available and can be modified in place.\n", "").replace(CODE_ARTIFACT_PATH_GUIDANCE, ATTACHED_BASH_ARTIFACT_PATH_GUIDANCE);
|
|
81
101
|
return {
|
|
82
102
|
...BashExecutionToolSchema,
|
|
83
103
|
properties: {
|
|
@@ -90,20 +110,33 @@ function buildBashExecutionToolSchema(opts) {
|
|
|
90
110
|
};
|
|
91
111
|
}
|
|
92
112
|
const BashExecutionToolName = "bash_tool";
|
|
113
|
+
function quoteBashArgument(value) {
|
|
114
|
+
return `'${value.replace(/'/g, "'\"'\"'")}'`;
|
|
115
|
+
}
|
|
116
|
+
function commandWithArguments(command, args) {
|
|
117
|
+
if (args == null || args.length === 0) return command;
|
|
118
|
+
return `bash -c ${quoteBashArgument(command)} -- ${args.map(quoteBashArgument).join(" ")}`;
|
|
119
|
+
}
|
|
93
120
|
const BashExecutionToolDefinition = {
|
|
94
121
|
name: BashExecutionToolName,
|
|
95
122
|
description: BashExecutionToolDescription,
|
|
96
123
|
schema: BashExecutionToolSchema
|
|
97
124
|
};
|
|
98
125
|
function createBashExecutionTool(params = {}) {
|
|
99
|
-
const
|
|
126
|
+
const workspaceId = params?.workspaceId?.trim();
|
|
127
|
+
const hasWorkspace = workspaceId != null && workspaceId !== "";
|
|
128
|
+
if (hasWorkspace && !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(workspaceId)) throw new Error("Invalid attached workspace identifier");
|
|
129
|
+
const execEndpoint = buildCodeApiEndpoint(params?.baseUrl ?? getCodeBaseURL(), hasWorkspace ? "exec/programmatic" : "exec");
|
|
100
130
|
return tool(async (rawInput, config) => {
|
|
101
|
-
const { authHeaders, baseUrl: _baseUrl, executionProfile, runtimeSessionHint, statefulSessions, ...executionParams } = params ?? {};
|
|
102
|
-
const { command, intent: _ignoredIntent, runtime_session_hint: _ignoredModelHint, ...rest } = rawInput;
|
|
131
|
+
const { authHeaders, baseUrl: _baseUrl, executionProfile, runtimeSessionHint, statefulSessions, workspaceId: _workspaceId, ...executionParams } = params ?? {};
|
|
132
|
+
const { command: rawCommand, intent: _ignoredIntent, runtime_session_hint: _ignoredModelHint, args, ...rest } = rawInput;
|
|
133
|
+
const command = hasWorkspace ? commandWithArguments(rawCommand, args) : rawCommand;
|
|
103
134
|
const { session_id, _injected_files, _runtime_session_hint } = config.toolCall ?? {};
|
|
104
135
|
const postData = {
|
|
105
136
|
lang: "bash",
|
|
106
|
-
code: command,
|
|
137
|
+
code: hasWorkspace ? prepareBashProgrammaticCode(command) : command,
|
|
138
|
+
...hasWorkspace ? { tools: [] } : {},
|
|
139
|
+
...!hasWorkspace && args != null ? { args } : {},
|
|
107
140
|
...rest,
|
|
108
141
|
...executionParams
|
|
109
142
|
};
|
|
@@ -112,40 +145,53 @@ function createBashExecutionTool(params = {}) {
|
|
|
112
145
|
if (_injected_files && _injected_files.length > 0) postData.files = _injected_files;
|
|
113
146
|
else if (session_id != null && session_id.length > 0 && !Array.isArray(postData.files)) logCodeApiDiagnostic("BashExecutor", "debug", "session carried no injected files; exec will run without input files", { files: "none" });
|
|
114
147
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
148
|
+
const resolvedAuthHeaders = await resolveCodeApiAuthHeaders(authHeaders);
|
|
149
|
+
let result;
|
|
150
|
+
if (hasWorkspace) result = await makeRequest(execEndpoint, postData, void 0, {
|
|
151
|
+
...resolvedAuthHeaders,
|
|
152
|
+
"X-LibreChat-Code-Workspace-ID": workspaceId
|
|
153
|
+
}, executionProfile, config.signal);
|
|
154
|
+
else {
|
|
155
|
+
const fetchOptions = {
|
|
156
|
+
method: "POST",
|
|
157
|
+
headers: {
|
|
158
|
+
"Content-Type": "application/json",
|
|
159
|
+
"User-Agent": "LibreChat/1.0",
|
|
160
|
+
...addCodeApiExecutionProfileHeader(resolvedAuthHeaders, executionProfile)
|
|
161
|
+
},
|
|
162
|
+
body: JSON.stringify(postData),
|
|
163
|
+
signal: config.signal
|
|
164
|
+
};
|
|
165
|
+
const proxyAgent = resolveFetchProxyAgent(execEndpoint);
|
|
166
|
+
if (proxyAgent != null) fetchOptions.agent = proxyAgent;
|
|
167
|
+
const response = await fetch(execEndpoint, fetchOptions);
|
|
168
|
+
if (!response.ok) throw new CodeApiRequestError(await buildCodeApiHttpErrorMessage("POST", execEndpoint, response, { profile: executionProfile }));
|
|
169
|
+
result = await response.json();
|
|
170
|
+
}
|
|
171
|
+
if (hasWorkspace && result.status !== "completed") throw new CodeApiRequestError(buildCodeApiExecutionErrorMessage(result));
|
|
129
172
|
let formattedOutput = "";
|
|
130
|
-
if (result.stdout) formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
173
|
+
if (typeof result.stdout === "string" && result.stdout.length > 0) formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
131
174
|
else formattedOutput += emptyOutputMessage;
|
|
132
|
-
if (result.stderr) formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
133
|
-
const outputWithReminder = appendTmpScratchReminder(formattedOutput, command);
|
|
175
|
+
if (typeof result.stderr === "string" && result.stderr.length > 0) formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
176
|
+
const outputWithReminder = appendTmpScratchReminder(formattedOutput, command, hasWorkspace ? ATTACHED_BASH_TMP_REMINDER : void 0);
|
|
134
177
|
const artifactDelivery = normalizeArtifactDeliveryFailure(result.artifact_delivery);
|
|
135
178
|
const outputWithDeliveryWarning = appendArtifactDeliveryWarning(outputWithReminder, artifactDelivery);
|
|
136
179
|
const hasFiles = result.files != null && result.files.length > 0;
|
|
180
|
+
const deletionEcho = result.deleted_files != null ? { deleted_files: result.deleted_files } : {};
|
|
137
181
|
const runtimeEcho = result.runtime_session_id != null ? {
|
|
138
182
|
runtime_session_id: result.runtime_session_id,
|
|
139
183
|
runtime_status: result.runtime_status
|
|
140
184
|
} : {};
|
|
141
|
-
return [appendCodeSessionFileSummary(outputWithDeliveryWarning, result.files), hasFiles ? {
|
|
185
|
+
return [hasWorkspace ? appendExecutionArtifactFileSummary(outputWithDeliveryWarning, result.files) : appendCodeSessionFileSummary(outputWithDeliveryWarning, result.files), hasFiles ? {
|
|
142
186
|
session_id: result.session_id,
|
|
143
187
|
files: result.files,
|
|
144
188
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
189
|
+
...deletionEcho,
|
|
145
190
|
...runtimeEcho
|
|
146
191
|
} : {
|
|
147
192
|
session_id: result.session_id,
|
|
148
193
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
194
|
+
...deletionEcho,
|
|
149
195
|
...runtimeEcho
|
|
150
196
|
}];
|
|
151
197
|
} catch (error) {
|
|
@@ -153,8 +199,14 @@ function createBashExecutionTool(params = {}) {
|
|
|
153
199
|
}
|
|
154
200
|
}, {
|
|
155
201
|
name: BashExecutionToolName,
|
|
156
|
-
description: buildBashExecutionToolDescription({
|
|
157
|
-
|
|
202
|
+
description: buildBashExecutionToolDescription({
|
|
203
|
+
statefulSessions: params?.statefulSessions,
|
|
204
|
+
attachedWorkspace: hasWorkspace
|
|
205
|
+
}),
|
|
206
|
+
schema: buildBashExecutionToolSchema({
|
|
207
|
+
statefulSessions: params?.statefulSessions,
|
|
208
|
+
attachedWorkspace: hasWorkspace
|
|
209
|
+
}),
|
|
158
210
|
responseFormat: "content_and_artifact"
|
|
159
211
|
});
|
|
160
212
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BashExecutor.mjs","names":[],"sources":["../../../src/tools/BashExecutor.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"BashExecutor.mjs","names":[],"sources":["../../../src/tools/BashExecutor.ts"],"mappings":";;;;;;;;;;;;;;AAiCA,OAAO;AAEP,MAAa,0BAA0B;CACrC,MAAM;CACN,YAAY;EACV,QAAQ,EAAE,GAAG,gBAAgB;EAC7B,SAAS;GACP,MAAM;GACN,aAAa;;;IAGf,4BAA4B;IAC5B,oBAAoB;;;;;EAKpB;EACA,MAAM;GACJ,MAAM;GACN,OAAO,EAAE,MAAM,SAAS;GACxB,aACE;EACJ;CACF;CACA,UAAU,CAAC,SAAS;AACtB;AAEA,MAAa,+BAA+B;;;;;;IAMxC,4BAA4B;IAC5B,oBAAoB;;EAEtB,KAAK;AAUP,MAAa,qBACX;AAEF,MAAa,uCAAuC;;;EAGlD,mBAAmB;;;;;IAKjB,4BAA4B;IAC5B,oBAAoB;;EAEtB,KAAK;AAEP,MAAM,gDAAgD;;;;;;;IAOlD,oBAAoB;;EAEtB,KAAK;AAYP,MAAa,gCAAgC;;;;;;;;;EAS3C,KAAK;AASP,SAAgB,kCAAkC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OAAO;GAKd,MAAM,IAAI,oBACR,uBAL0B,kCAC1B,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"}
|
|
@@ -2,7 +2,7 @@ import "../common/enum.mjs";
|
|
|
2
2
|
import "../common/index.mjs";
|
|
3
3
|
import { INTENT_PROPERTY } from "./intentArg.mjs";
|
|
4
4
|
import { logCodeApiDiagnostic } from "./diagnostics.mjs";
|
|
5
|
-
import { BASH_SHELL_GUIDANCE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, appendFailedExecutionFileReminder, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, getCodeBaseURL, selectRuntimeSessionHint } from "./CodeExecutor.mjs";
|
|
5
|
+
import { BASH_SHELL_GUIDANCE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, appendFailedExecutionFileReminder, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, getCodeBaseURL, resolveCodeApiAuthHeaders, selectRuntimeSessionHint } from "./CodeExecutor.mjs";
|
|
6
6
|
import { assertUnambiguousIdentifiers, projectProgrammaticToolMap, resolveProgrammaticToolDefinitions, selectProgrammaticTools } from "./ProgrammaticCallerPolicy.mjs";
|
|
7
7
|
import { clampCodeApiRunTimeoutMs, createCodeApiRunTimeoutSchema, resolveCodeApiRunTimeoutMs } from "./ptcTimeout.mjs";
|
|
8
8
|
import { executeTools, formatCompletedResponse, makeRequest, runPlainExecution } from "./ProgrammaticToolCalling.mjs";
|
|
@@ -13,6 +13,9 @@ config();
|
|
|
13
13
|
const DEFAULT_MAX_ROUND_TRIPS = 20;
|
|
14
14
|
const DEFAULT_RUN_TIMEOUT_MS = resolveCodeApiRunTimeoutMs();
|
|
15
15
|
const BASH_LAST_BACKGROUND_PID_GUARD = ": &\nwait \"$!\"";
|
|
16
|
+
const CODE_API_WORKSPACE_HEADER = "X-LibreChat-Code-Workspace-ID";
|
|
17
|
+
const ATTACHED_BASH_DATA_DIRECTORY = "\"${LIBRECHAT_CODE_DATA_DIR:-/mnt/data}\"";
|
|
18
|
+
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.`;
|
|
16
19
|
const BASH_RESERVED = new Set([
|
|
17
20
|
"if",
|
|
18
21
|
"then",
|
|
@@ -42,6 +45,10 @@ const STATELESS_WARNING = `CRITICAL - STATELESS EXECUTION:
|
|
|
42
45
|
Each call is a fresh bash shell. Variables and state do NOT persist between calls.
|
|
43
46
|
You MUST complete your entire workflow in ONE code block.
|
|
44
47
|
DO NOT split work across multiple calls expecting to reuse variables.`;
|
|
48
|
+
const ATTACHED_WORKSPACE_WARNING = `ATTACHED WORKSPACE EXECUTION:
|
|
49
|
+
- Commands start in the selected persistent workspace; project file changes persist between calls.
|
|
50
|
+
- Each sandbox run is a fresh process, so shell variables, background processes, and temporary execution data do not persist.
|
|
51
|
+
- Injected files and generated artifacts use \${LIBRECHAT_CODE_DATA_DIR:-/mnt/data}; do not copy them into the project unless the task requires it.`;
|
|
45
52
|
const CORE_RULES = `Rules:
|
|
46
53
|
- One call: state does not persist
|
|
47
54
|
- Tools are pre-defined as bash functions—DO NOT redefine them
|
|
@@ -64,6 +71,28 @@ Example (Parallel calls):
|
|
|
64
71
|
wait
|
|
65
72
|
echo "SF: $(jq -r . /mnt/data/sf.json)"
|
|
66
73
|
echo "NY: $(jq -r . /mnt/data/ny.json)"`;
|
|
74
|
+
const ATTACHED_CORE_RULES = `Rules:
|
|
75
|
+
- One call: process state does not persist; project files do
|
|
76
|
+
- Tools are pre-defined as bash functions—DO NOT redefine them
|
|
77
|
+
- Each tool function accepts a JSON string argument
|
|
78
|
+
- Resolve tool calls into variables before changing project files; do not redirect a tool call directly into the project
|
|
79
|
+
- Set data_dir=${ATTACHED_BASH_DATA_DIRECTORY}; save generated artifacts there, and write durable project files relative to the working directory
|
|
80
|
+
- Tool stdout is normalized to one compact JSON value when possible; parse saved stdout once, then use fromjson? // . only for JSON-string fields
|
|
81
|
+
- Only echo/printf output returns to the model
|
|
82
|
+
- ${ATTACHED_BASH_ARTIFACT_PATH_GUIDANCE}
|
|
83
|
+
- ${BASH_SHELL_GUIDANCE}
|
|
84
|
+
- timeout caps one sandbox run/replay iteration, not the total multi-round-trip workflow`;
|
|
85
|
+
const ATTACHED_EXAMPLES = `Example (Complete workflow in one call):
|
|
86
|
+
data=$(query_database '{"sql": "SELECT * FROM users"}')
|
|
87
|
+
echo "$data" | jq '.[] | .name'
|
|
88
|
+
|
|
89
|
+
Example (Parallel calls):
|
|
90
|
+
data_dir=${ATTACHED_BASH_DATA_DIRECTORY}
|
|
91
|
+
{ sf=$(web_search '{"query": "SF weather"}'); printf '%s\n' "$sf" > "$data_dir/sf.json"; } &
|
|
92
|
+
{ ny=$(web_search '{"query": "NY weather"}'); printf '%s\n' "$ny" > "$data_dir/ny.json"; } &
|
|
93
|
+
wait
|
|
94
|
+
echo "SF: $(jq -r . "$data_dir/sf.json")"
|
|
95
|
+
echo "NY: $(jq -r . "$data_dir/ny.json")"`;
|
|
67
96
|
const CODE_PARAM_DESCRIPTION = `Bash code that calls tools programmatically. Tools are available as bash functions.
|
|
68
97
|
|
|
69
98
|
${STATELESS_WARNING}
|
|
@@ -175,7 +204,17 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
175
204
|
const maxRunTimeoutMs = resolveCodeApiRunTimeoutMs(initParams.runTimeoutMs);
|
|
176
205
|
const proxy = initParams.proxy ?? process.env.PROXY;
|
|
177
206
|
const debug = initParams.debug ?? process.env.BASH_PTC_DEBUG === "true";
|
|
207
|
+
const workspaceId = initParams.workspaceId?.trim();
|
|
208
|
+
const hasWorkspace = workspaceId != null && workspaceId !== "";
|
|
209
|
+
if (hasWorkspace && !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(workspaceId)) throw new Error("Invalid attached workspace identifier");
|
|
210
|
+
const requestAuthHeaders = hasWorkspace ? async () => ({
|
|
211
|
+
...await resolveCodeApiAuthHeaders(initParams.authHeaders),
|
|
212
|
+
[CODE_API_WORKSPACE_HEADER]: workspaceId
|
|
213
|
+
}) : initParams.authHeaders ?? {};
|
|
178
214
|
const EXEC_ENDPOINT = buildCodeApiEndpoint(baseUrl, "exec/programmatic");
|
|
215
|
+
const description = hasWorkspace ? BashProgrammaticToolCallingDescription.replace(STATELESS_WARNING, ATTACHED_WORKSPACE_WARNING).replace(CORE_RULES, ATTACHED_CORE_RULES).replace(EXAMPLES, ATTACHED_EXAMPLES) : BashProgrammaticToolCallingDescription;
|
|
216
|
+
const schema = createBashProgrammaticToolCallingSchema(maxRunTimeoutMs);
|
|
217
|
+
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);
|
|
179
218
|
return tool(async (rawParams, config) => {
|
|
180
219
|
const params = rawParams;
|
|
181
220
|
const { code } = params;
|
|
@@ -206,7 +245,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
206
245
|
else if (session_id != null && session_id.length > 0) logCodeApiDiagnostic("BashProgrammaticToolCalling", "debug", "session carried no injected files; exec will run without input files", { files: "none" });
|
|
207
246
|
const selectedRuntimeSessionHint = selectRuntimeSessionHint(initParams.runtimeSessionHint, _runtime_session_hint);
|
|
208
247
|
const runtimeSessionHint = initParams.executionProfile !== "default" && typeof selectedRuntimeSessionHint === "string" && selectedRuntimeSessionHint !== "" ? selectedRuntimeSessionHint : void 0;
|
|
209
|
-
if (needsNoTools) return await runPlainExecution({
|
|
248
|
+
if (needsNoTools && !hasWorkspace) return await runPlainExecution({
|
|
210
249
|
baseUrl,
|
|
211
250
|
lang: "bash",
|
|
212
251
|
code,
|
|
@@ -215,7 +254,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
215
254
|
files,
|
|
216
255
|
runtimeSessionHint,
|
|
217
256
|
proxy,
|
|
218
|
-
authHeaders:
|
|
257
|
+
authHeaders: requestAuthHeaders,
|
|
219
258
|
executionProfile: initParams.executionProfile
|
|
220
259
|
});
|
|
221
260
|
let response = await makeRequest(EXEC_ENDPOINT, {
|
|
@@ -226,7 +265,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
226
265
|
timeout,
|
|
227
266
|
...files && files.length > 0 ? { files } : {},
|
|
228
267
|
...runtimeSessionHint != null ? { runtime_session_hint: runtimeSessionHint } : {}
|
|
229
|
-
}, proxy, initParams.
|
|
268
|
+
}, proxy, requestAuthHeaders, initParams.executionProfile, config.signal);
|
|
230
269
|
while (response.status === "tool_call_required") {
|
|
231
270
|
roundTrip++;
|
|
232
271
|
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.`);
|
|
@@ -235,9 +274,9 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
235
274
|
response = await makeRequest(EXEC_ENDPOINT, {
|
|
236
275
|
continuation_token: response.continuation_token,
|
|
237
276
|
tool_results: toolResults
|
|
238
|
-
}, proxy, initParams.
|
|
277
|
+
}, proxy, requestAuthHeaders, initParams.executionProfile, config.signal);
|
|
239
278
|
}
|
|
240
|
-
if (response.status === "completed") return formatCompletedResponse(response, code);
|
|
279
|
+
if (response.status === "completed") return formatCompletedResponse(response, code, hasWorkspace ? "execution" : "session");
|
|
241
280
|
if (response.status === "error") throw new Error(buildCodeApiExecutionErrorMessage(response));
|
|
242
281
|
throw new CodeApiRequestError();
|
|
243
282
|
} catch (error) {
|
|
@@ -247,12 +286,12 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
247
286
|
}
|
|
248
287
|
}, {
|
|
249
288
|
name: "run_tools_with_bash",
|
|
250
|
-
description
|
|
251
|
-
schema
|
|
289
|
+
description,
|
|
290
|
+
schema,
|
|
252
291
|
responseFormat: "content_and_artifact"
|
|
253
292
|
});
|
|
254
293
|
}
|
|
255
294
|
//#endregion
|
|
256
|
-
export { BashProgrammaticToolCallingDefinition, BashProgrammaticToolCallingDescription, BashProgrammaticToolCallingName, BashProgrammaticToolCallingSchema, createBashProgrammaticToolCallingSchema, createBashProgrammaticToolCallingTool, extractUsedBashToolNames, filterBashToolsByUsage, normalizeBashToolResultsForReplay, normalizeToBashIdentifier };
|
|
295
|
+
export { BashProgrammaticToolCallingDefinition, BashProgrammaticToolCallingDescription, BashProgrammaticToolCallingName, BashProgrammaticToolCallingSchema, createBashProgrammaticToolCallingSchema, createBashProgrammaticToolCallingTool, extractUsedBashToolNames, filterBashToolsByUsage, normalizeBashToolResultsForReplay, normalizeToBashIdentifier, prepareBashProgrammaticCode };
|
|
257
296
|
|
|
258
297
|
//# sourceMappingURL=BashProgrammaticToolCalling.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BashProgrammaticToolCalling.mjs","names":[],"sources":["../../../src/tools/BashProgrammaticToolCalling.ts"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"BashProgrammaticToolCalling.mjs","names":[],"sources":["../../../src/tools/BashProgrammaticToolCalling.ts"],"mappings":";;;;;;;;;;;AAsCA,OAAO;AAMP,MAAM,0BAA0B;AAChC,MAAM,yBAAyB,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;CAC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,sBAAsB;IAC/C;IAEA,IAAI,YAAY,eACd,MAAM,IAAI,MACR,iCAAiC,cAAc,4FAGjD;IAGF,IAAI,OAEF,QAAQ,IACN,8BAA8B,UAAU,IAAI,SAAS,YAAY,UAAU,EAAE,oBAC/E;IAGF,MAAM,cAAc,kCAClB,MAAM,aACJ,SAAS,cAAc,CAAC,GACxB,kBAAA,qBAEF,CACF;IAEA,WAAW,MAAM,YACf,eACA;KACE,oBAAoB,SAAS;KAC7B,cAAc;IAChB,GACA,OACA,oBACA,WAAW,kBACX,OAAO,MACT;GACF;GAMA,IAAI,SAAS,WAAW,aACtB,OAAO,wBACL,UACA,MACA,eAAe,cAAc,SAC/B;GAGF,IAAI,SAAS,WAAW,SACtB,MAAM,IAAI,MAAM,kCAAkC,QAAQ,CAAC;GAG7D,MAAM,IAAI,oBAAoB;EAChC,SAAS,OAAO;GAKd,MAAM,UAAU,uCAJY,kCACzB,MAAgB,SACjB,IAEuE;GACzE,IAAI,iBAAiB,qBACnB,MAAM,IAAI,oBAAoB,OAAO;GAEvC,MAAM,IAAI,MAAM,SAAS,EAAE,OAAO,MAAM,CAAC;EAC3C;CACF,GACA;EACE,MAAA;EACA;EACA;EACA,gBAAA;CACF,CACF;AACF"}
|
|
@@ -25,9 +25,9 @@ const TMP_PATH_PATTERN = /(^|[^A-Za-z0-9_])\/tmp(?:\/|\b)/;
|
|
|
25
25
|
const MNT_DATA_PATH_PATTERN = /(^|[^A-Za-z0-9_])\/mnt\/data(?:\/|\b)/;
|
|
26
26
|
const TMP_SCRATCH_OUTPUT_REMINDER = "Note: /tmp files are same-call scratch only and were not persisted; use /mnt/data for files needed later.";
|
|
27
27
|
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.";
|
|
28
|
-
function appendTmpScratchReminder(output, code) {
|
|
28
|
+
function appendTmpScratchReminder(output, code, reminder = TMP_SCRATCH_OUTPUT_REMINDER) {
|
|
29
29
|
if (!TMP_PATH_PATTERN.test(code)) return output;
|
|
30
|
-
return `${output.trimEnd()}\n${
|
|
30
|
+
return `${output.trimEnd()}\n${reminder}\n`;
|
|
31
31
|
}
|
|
32
32
|
function appendFailedExecutionFileReminder(output, code) {
|
|
33
33
|
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;
|
|
@@ -310,6 +310,7 @@ function createCodeExecutionTool(params = {}) {
|
|
|
310
310
|
const artifactDelivery = normalizeArtifactDeliveryFailure(result.artifact_delivery);
|
|
311
311
|
const outputWithDeliveryWarning = appendArtifactDeliveryWarning(outputWithReminder, artifactDelivery);
|
|
312
312
|
const hasFiles = result.files != null && result.files.length > 0;
|
|
313
|
+
const deletionEcho = result.deleted_files != null ? { deleted_files: result.deleted_files } : {};
|
|
313
314
|
const runtimeEcho = result.runtime_session_id != null ? {
|
|
314
315
|
runtime_session_id: result.runtime_session_id,
|
|
315
316
|
runtime_status: result.runtime_status
|
|
@@ -318,10 +319,12 @@ function createCodeExecutionTool(params = {}) {
|
|
|
318
319
|
session_id: result.session_id,
|
|
319
320
|
files: result.files,
|
|
320
321
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
322
|
+
...deletionEcho,
|
|
321
323
|
...runtimeEcho
|
|
322
324
|
} : {
|
|
323
325
|
session_id: result.session_id,
|
|
324
326
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
327
|
+
...deletionEcho,
|
|
325
328
|
...runtimeEcho
|
|
326
329
|
}];
|
|
327
330
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.mjs","names":[],"sources":["../../../src/tools/CodeExecutor.ts"],"mappings":";;;;;;;;;;;;AAyBA,OAAO;AAEP,MAAa,uBACX,uBAAA,wBAA0C,KAAA;AAG5C,SAAgB,qBAAqB,SAAiB,OAAuB;CAC3E,OAAO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,CAAC;GAIP,MAAM,cACJ,OAAO,sBAAsB,OACzB;IACA,oBAAoB,OAAO;IAC3B,gBAAgB,OAAO;GACzB,IACE,CAAC;GACP,OAAO,CACL,6BAA6B,2BAA2B,OAAO,KAAK,GACnE,WACG;IACA,YAAY,OAAO;IACnB,OAAO,OAAO;IACd,GAAI,oBAAoB,OACpB,EAAE,mBAAmB,iBAAiB,IACtC,CAAC;IACL,GAAG;IACH,GAAG;GACL,IACE;IACA,YAAY,OAAO;IACnB,GAAI,oBAAoB,OACpB,EAAE,mBAAmB,iBAAiB,IACtC,CAAC;IACL,GAAG;IACH,GAAG;GACL,CACJ;EACF,SAAS,OAAO;GAKd,MAAM,IAAI,oBACR,uBAL0B,kCAC1B,6BAA6B,KAAK,CAAC,CAAC,SACpC,IAGyC,GAC3C;EACF;CACF,GACA;EACE,MAAM;EACN,aAAa,kCAAkC,UAAU,KAAA,CAAS;EAClE,QAAQ,6BAA6B,UAAU,KAAA,CAAS;EACxD,gBAAA;CACF,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,7 +47,15 @@ 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
|
-
export { appendCodeSessionFileSummary, stripCodeSessionFileSummary };
|
|
59
|
+
export { appendCodeSessionFileSummary, appendExecutionArtifactFileSummary, stripCodeSessionFileSummary };
|
|
51
60
|
|
|
52
61
|
//# sourceMappingURL=CodeSessionFileSummary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeSessionFileSummary.mjs","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;AAEA,SAAS,gBAAgB,MAAsD;CAC7E,OAAO,MAAM,cAAc;AAC7B;AAEA,SAAgB,4BAA4B,QAAwB;CAClE,MAAM,eAAe,OAAO,YAAY,kBAAkB;CAC1D,IAAI,eAAe,GAAG,OAAO;CAC7B,MAAM,gBAAgB,OAAO,MAAM,GAAG,YAAY;CAClD,IAAI,kBAAkB,MAAM,CAAC,cAAc,SAAS,MAAM,GAAG,OAAO;CACpE,MAAM,eAAe,OAAO,MAAM,YAAY;CAC9C,
|
|
1
|
+
{"version":3,"file":"CodeSessionFileSummary.mjs","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;AACF,MAAM,0CACJ;AAEF,SAAS,iBAAiB,MAAsB;CAC9C,MAAM,YAAY,KAAK,YAAY,GAAG;CACtC,MAAM,WAAW,aAAa,IAAI,KAAK,MAAM,YAAY,CAAC,IAAI;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,MAAM,UACJ;uBACwB,eAAe,OAAO,sBAAsB,WAAW;CAGjF,OAAO,GAAG,OAAO,QAAQ,EAAE,MAAM,UAAU,KAAK;AAClD"}
|
|
@@ -4,10 +4,11 @@ import { resolveFetchProxyAgent } from "../utils/proxy.mjs";
|
|
|
4
4
|
import { INTENT_PROPERTY } from "./intentArg.mjs";
|
|
5
5
|
import { appendArtifactDeliveryWarning, normalizeArtifactDeliveryFailure } from "./ArtifactDelivery.mjs";
|
|
6
6
|
import { describeCodeApiError, logCodeApiDiagnostic } from "./diagnostics.mjs";
|
|
7
|
-
import { appendCodeSessionFileSummary } from "./CodeSessionFileSummary.mjs";
|
|
7
|
+
import { appendCodeSessionFileSummary, appendExecutionArtifactFileSummary } from "./CodeSessionFileSummary.mjs";
|
|
8
8
|
import { CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, addCodeApiExecutionProfileHeader, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, buildCodeApiHttpErrorMessage, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders, selectRuntimeSessionHint } from "./CodeExecutor.mjs";
|
|
9
9
|
import { assertUnambiguousIdentifiers, projectProgrammaticToolMap, resolveProgrammaticToolDefinitions, selectProgrammaticTools } from "./ProgrammaticCallerPolicy.mjs";
|
|
10
10
|
import { clampCodeApiRunTimeoutMs, createCodeApiRunTimeoutSchema, resolveCodeApiRunTimeoutMs } from "./ptcTimeout.mjs";
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
11
12
|
import { tool } from "@langchain/core/tools";
|
|
12
13
|
import { config } from "dotenv";
|
|
13
14
|
import fetch from "node-fetch";
|
|
@@ -15,6 +16,8 @@ import fetch from "node-fetch";
|
|
|
15
16
|
config();
|
|
16
17
|
const DEFAULT_MAX_ROUND_TRIPS = 20;
|
|
17
18
|
const DEFAULT_RUN_TIMEOUT_MS = resolveCodeApiRunTimeoutMs();
|
|
19
|
+
const CODE_API_PROGRAMMATIC_REQUEST_HEADER = "X-LibreChat-Code-Request-ID";
|
|
20
|
+
const CANCELLATION_REQUEST_TIMEOUT_MS = 2e3;
|
|
18
21
|
const STATELESS_WARNING = `CRITICAL - STATELESS EXECUTION:
|
|
19
22
|
Each call is a fresh Python interpreter. Variables, imports, and data do NOT persist between calls.
|
|
20
23
|
You MUST complete your entire workflow in ONE code block: query → process → output.
|
|
@@ -247,20 +250,61 @@ async function fetchSessionFiles(baseUrl, sessionId, scopeOrProxy, proxyOrAuthHe
|
|
|
247
250
|
return [];
|
|
248
251
|
}
|
|
249
252
|
}
|
|
250
|
-
async function makeRequest(endpoint, body, proxy, authHeaders, executionProfile) {
|
|
253
|
+
async function makeRequest(endpoint, body, proxy, authHeaders, executionProfile, signal) {
|
|
251
254
|
try {
|
|
255
|
+
const resolvedAuthHeaders = await resolveCodeApiAuthHeaders(authHeaders);
|
|
256
|
+
const requestId = signal != null ? randomUUID() : void 0;
|
|
252
257
|
const fetchOptions = {
|
|
253
258
|
method: "POST",
|
|
254
259
|
headers: {
|
|
255
260
|
"Content-Type": "application/json",
|
|
256
261
|
"User-Agent": "LibreChat/1.0",
|
|
257
|
-
...addCodeApiExecutionProfileHeader(
|
|
262
|
+
...addCodeApiExecutionProfileHeader(resolvedAuthHeaders, executionProfile),
|
|
263
|
+
...requestId != null ? { [CODE_API_PROGRAMMATIC_REQUEST_HEADER]: requestId } : {}
|
|
258
264
|
},
|
|
259
|
-
body: JSON.stringify(body)
|
|
265
|
+
body: JSON.stringify(body),
|
|
266
|
+
signal
|
|
260
267
|
};
|
|
261
268
|
const proxyAgent = resolveFetchProxyAgent(endpoint, proxy);
|
|
262
269
|
if (proxyAgent != null) fetchOptions.agent = proxyAgent;
|
|
263
|
-
|
|
270
|
+
let cancellationRequest;
|
|
271
|
+
const requestCancellation = () => {
|
|
272
|
+
if (requestId == null || cancellationRequest != null) return;
|
|
273
|
+
cancellationRequest = (async () => {
|
|
274
|
+
const cancellationController = new AbortController();
|
|
275
|
+
const timeout = setTimeout(() => cancellationController.abort(), CANCELLATION_REQUEST_TIMEOUT_MS);
|
|
276
|
+
try {
|
|
277
|
+
const cancelOptions = {
|
|
278
|
+
method: "POST",
|
|
279
|
+
headers: {
|
|
280
|
+
"Content-Type": "application/json",
|
|
281
|
+
"User-Agent": "LibreChat/1.0",
|
|
282
|
+
...addCodeApiExecutionProfileHeader(resolvedAuthHeaders, executionProfile)
|
|
283
|
+
},
|
|
284
|
+
body: JSON.stringify({ request_id: requestId }),
|
|
285
|
+
signal: cancellationController.signal
|
|
286
|
+
};
|
|
287
|
+
if (proxyAgent != null) cancelOptions.agent = proxyAgent;
|
|
288
|
+
await fetch(`${endpoint}/cancel`, cancelOptions);
|
|
289
|
+
} catch {} finally {
|
|
290
|
+
clearTimeout(timeout);
|
|
291
|
+
}
|
|
292
|
+
})();
|
|
293
|
+
};
|
|
294
|
+
signal?.addEventListener("abort", requestCancellation, { once: true });
|
|
295
|
+
if (signal?.aborted === true) requestCancellation();
|
|
296
|
+
let response;
|
|
297
|
+
try {
|
|
298
|
+
response = await fetch(endpoint, fetchOptions);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
if (signal?.aborted === true) {
|
|
301
|
+
requestCancellation();
|
|
302
|
+
await cancellationRequest;
|
|
303
|
+
}
|
|
304
|
+
throw error;
|
|
305
|
+
} finally {
|
|
306
|
+
signal?.removeEventListener("abort", requestCancellation);
|
|
307
|
+
}
|
|
264
308
|
if (!response.ok) throw new CodeApiRequestError(await buildCodeApiHttpErrorMessage("POST", endpoint, response, { profile: executionProfile }));
|
|
265
309
|
return await response.json();
|
|
266
310
|
} catch (error) {
|
|
@@ -403,16 +447,18 @@ async function executeTools(toolCalls, toolMap, programmaticToolName = "run_tool
|
|
|
403
447
|
});
|
|
404
448
|
return await Promise.all(executions);
|
|
405
449
|
}
|
|
406
|
-
function formatCompletedResponse(response, sourceCode = "") {
|
|
450
|
+
function formatCompletedResponse(response, sourceCode = "", filePersistence = "session") {
|
|
407
451
|
let formatted = "";
|
|
408
452
|
if (response.stdout != null && response.stdout !== "") formatted += `stdout:\n${response.stdout}\n`;
|
|
409
453
|
else formatted += emptyOutputMessage;
|
|
410
454
|
if (response.stderr != null && response.stderr !== "") formatted += `stderr:\n${response.stderr}\n`;
|
|
411
455
|
const outputWithReminder = appendTmpScratchReminder(formatted, sourceCode);
|
|
412
456
|
const artifactDelivery = normalizeArtifactDeliveryFailure(response.artifact_delivery);
|
|
413
|
-
|
|
457
|
+
const outputWithDeliveryWarning = appendArtifactDeliveryWarning(outputWithReminder, artifactDelivery);
|
|
458
|
+
return [filePersistence === "execution" ? appendExecutionArtifactFileSummary(outputWithDeliveryWarning, response.files) : appendCodeSessionFileSummary(outputWithDeliveryWarning, response.files), {
|
|
414
459
|
session_id: response.session_id,
|
|
415
460
|
files: response.files,
|
|
461
|
+
...response.deleted_files != null ? { deleted_files: response.deleted_files } : {},
|
|
416
462
|
...artifactDelivery != null ? { artifact_delivery: artifactDelivery } : {},
|
|
417
463
|
...response.runtime_session_id != null ? {
|
|
418
464
|
runtime_session_id: response.runtime_session_id,
|
|
@@ -494,7 +540,7 @@ function createProgrammaticToolCallingTool(initParams = {}) {
|
|
|
494
540
|
timeout,
|
|
495
541
|
...files && files.length > 0 ? { files } : {},
|
|
496
542
|
...runtimeSessionHint != null ? { runtime_session_hint: runtimeSessionHint } : {}
|
|
497
|
-
}, proxy, initParams.authHeaders, initParams.executionProfile);
|
|
543
|
+
}, proxy, initParams.authHeaders, initParams.executionProfile, config.signal);
|
|
498
544
|
while (response.status === "tool_call_required") {
|
|
499
545
|
roundTrip++;
|
|
500
546
|
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.`);
|
|
@@ -503,7 +549,7 @@ function createProgrammaticToolCallingTool(initParams = {}) {
|
|
|
503
549
|
response = await makeRequest(EXEC_ENDPOINT, {
|
|
504
550
|
continuation_token: response.continuation_token,
|
|
505
551
|
tool_results: toolResults
|
|
506
|
-
}, proxy, initParams.authHeaders, initParams.executionProfile);
|
|
552
|
+
}, proxy, initParams.authHeaders, initParams.executionProfile, config.signal);
|
|
507
553
|
}
|
|
508
554
|
if (response.status === "completed") return formatCompletedResponse(response, code);
|
|
509
555
|
if (response.status === "error") throw new Error(buildCodeApiExecutionErrorMessage(response));
|