@librechat/agents 3.5.0 → 3.6.0
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 +5 -2
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +148 -22
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +2 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/main.cjs +4 -0
- package/dist/cjs/run.cjs +29 -11
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +8 -6
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +8 -7
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +5 -4
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +26 -7
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +7 -6
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +33 -10
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +1 -1
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/runStepResume.cjs +51 -0
- package/dist/cjs/tools/runStepResume.cjs.map +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +15 -43
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs +6 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
- package/dist/cjs/utils/toolSessions.cjs +63 -0
- package/dist/cjs/utils/toolSessions.cjs.map +1 -0
- package/dist/esm/agents/AgentContext.mjs +5 -2
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +148 -22
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +2 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/main.mjs +2 -2
- package/dist/esm/run.mjs +29 -11
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +8 -6
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +9 -8
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +6 -5
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +23 -8
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +8 -7
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +33 -10
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +2 -2
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/runStepResume.mjs +48 -0
- package/dist/esm/tools/runStepResume.mjs.map +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +15 -43
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs +6 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
- package/dist/esm/utils/toolSessions.mjs +62 -0
- package/dist/esm/utils/toolSessions.mjs.map +1 -0
- package/dist/types/agents/AgentContext.d.ts +7 -4
- package/dist/types/agents/projection.d.ts +1 -1
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphs/Graph.d.ts +22 -14
- package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
- package/dist/types/graphs/createGraph.d.ts +4 -4
- package/dist/types/graphs/graphFactory.d.ts +1 -1
- package/dist/types/hitl/askUserQuestion.d.ts +1 -1
- package/dist/types/hitl/askUserQuestions.d.ts +1 -1
- package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
- package/dist/types/hooks/types.d.ts +1 -1
- package/dist/types/instrumentation.d.ts +1 -1
- package/dist/types/langfuse.d.ts +3 -3
- package/dist/types/langfuseConfig.d.ts +2 -2
- package/dist/types/langfuseRuntimeContext.d.ts +1 -1
- package/dist/types/langfuseRuntimeScope.d.ts +2 -2
- package/dist/types/langfuseSpanRegistry.d.ts +1 -1
- package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
- package/dist/types/llm/anthropic/index.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +1 -1
- package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
- package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
- package/dist/types/llm/google/index.d.ts +1 -1
- package/dist/types/llm/init.d.ts +2 -2
- package/dist/types/llm/invoke.d.ts +6 -6
- package/dist/types/llm/mistral/index.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +2 -2
- package/dist/types/llm/openrouter/index.d.ts +2 -2
- package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
- package/dist/types/llm/providers.d.ts +2 -2
- package/dist/types/llm/request.d.ts +2 -2
- package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
- package/dist/types/llm/streamLimits.d.ts +1 -1
- package/dist/types/llm/truncation.d.ts +1 -1
- package/dist/types/llm/vertexai/index.d.ts +1 -1
- package/dist/types/messages/alternation.d.ts +1 -1
- package/dist/types/messages/anthropicToolCache.d.ts +2 -2
- package/dist/types/messages/assistantPhase.d.ts +3 -3
- package/dist/types/messages/budget.d.ts +1 -1
- package/dist/types/messages/cache.d.ts +1 -1
- package/dist/types/messages/contextPruning.d.ts +2 -2
- package/dist/types/messages/core.d.ts +2 -2
- package/dist/types/messages/format.d.ts +2 -2
- package/dist/types/messages/ids.d.ts +2 -2
- package/dist/types/messages/injected.d.ts +1 -1
- package/dist/types/messages/langchain.d.ts +1 -1
- package/dist/types/messages/prune.d.ts +3 -3
- package/dist/types/openai/index.d.ts +1 -1
- package/dist/types/prompts/activityLabel.d.ts +2 -2
- package/dist/types/responses/index.d.ts +1 -1
- package/dist/types/run.d.ts +3 -3
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/types.d.ts +1 -1
- package/dist/types/stream.d.ts +4 -4
- package/dist/types/summarization/index.d.ts +1 -1
- package/dist/types/summarization/node.d.ts +6 -6
- package/dist/types/tools/BashExecutor.d.ts +2 -2
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/CodeExecutor.d.ts +7 -3
- package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +3 -3
- package/dist/types/tools/ReadFile.d.ts +1 -1
- package/dist/types/tools/SkillTool.d.ts +1 -1
- package/dist/types/tools/SubagentTool.d.ts +3 -3
- package/dist/types/tools/ToolNode.d.ts +8 -6
- package/dist/types/tools/ToolSearch.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
- package/dist/types/tools/eagerEventExecution.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +3 -3
- package/dist/types/tools/intentArg.d.ts +1 -1
- package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
- package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
- package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
- package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/local/bashAst.d.ts +1 -1
- package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
- package/dist/types/tools/ptcTimeout.d.ts +1 -1
- package/dist/types/tools/runStepResume.d.ts +5 -0
- package/dist/types/tools/schema.d.ts +1 -1
- package/dist/types/tools/search/anthropic.d.ts +1 -1
- package/dist/types/tools/skillCatalog.d.ts +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +30 -5
- package/dist/types/tools/subagent/SubagentReplay.d.ts +4 -3
- package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
- package/dist/types/types/activityLabel.d.ts +3 -3
- package/dist/types/types/graph.d.ts +16 -7
- package/dist/types/types/llm.d.ts +9 -9
- package/dist/types/types/run.d.ts +7 -7
- package/dist/types/types/stream.d.ts +23 -5
- package/dist/types/types/summarize.d.ts +2 -2
- package/dist/types/types/tools.d.ts +41 -21
- package/dist/types/utils/errors.d.ts +1 -1
- package/dist/types/utils/events.d.ts +1 -1
- package/dist/types/utils/handlers.d.ts +3 -3
- package/dist/types/utils/llm.d.ts +1 -1
- package/dist/types/utils/llmConfig.d.ts +1 -1
- package/dist/types/utils/title.d.ts +1 -1
- package/dist/types/utils/toolSessions.d.ts +18 -0
- package/package.json +28 -32
- package/src/agents/AgentContext.ts +7 -0
- package/src/graphs/Graph.ts +192 -13
- package/src/graphs/MultiAgentGraph.ts +1 -0
- package/src/run.ts +62 -11
- package/src/stream.ts +28 -9
- package/src/tools/BashExecutor.ts +31 -13
- package/src/tools/BashProgrammaticToolCalling.ts +19 -9
- package/src/tools/CodeExecutor.ts +57 -16
- package/src/tools/ProgrammaticToolCalling.ts +26 -12
- package/src/tools/ToolNode.ts +58 -8
- package/src/tools/ToolSearch.ts +2 -2
- package/src/tools/runStepResume.ts +121 -0
- package/src/tools/subagent/SubagentExecutor.ts +67 -65
- package/src/tools/subagent/SubagentReplay.ts +22 -1
- package/src/types/graph.ts +10 -0
- package/src/types/stream.ts +17 -0
- package/src/types/tools.ts +50 -21
- package/src/utils/toolSessions.ts +113 -0
- package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +0 -52
- package/dist/types/test/mockTools.d.ts +0 -28
- package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +0 -40
|
@@ -3,13 +3,12 @@ import "../common/index.mjs";
|
|
|
3
3
|
import { resolveFetchProxyAgent } from "../utils/proxy.mjs";
|
|
4
4
|
import { INTENT_PROPERTY } from "./intentArg.mjs";
|
|
5
5
|
import { appendCodeSessionFileSummary } from "./CodeSessionFileSummary.mjs";
|
|
6
|
-
import { BASH_SHELL_GUIDANCE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiHttpErrorMessage, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders } from "./CodeExecutor.mjs";
|
|
6
|
+
import { BASH_SHELL_GUIDANCE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, addCodeApiExecutionProfileHeader, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiEndpoint, buildCodeApiHttpErrorMessage, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders, selectRuntimeSessionHint } from "./CodeExecutor.mjs";
|
|
7
7
|
import { tool } from "@langchain/core/tools";
|
|
8
8
|
import { config } from "dotenv";
|
|
9
9
|
import fetch from "node-fetch";
|
|
10
10
|
//#region src/tools/BashExecutor.ts
|
|
11
11
|
config();
|
|
12
|
-
const EXEC_ENDPOINT = `${getCodeBaseURL()}/exec`;
|
|
13
12
|
const BashExecutionToolSchema = {
|
|
14
13
|
type: "object",
|
|
15
14
|
properties: {
|
|
@@ -95,8 +94,9 @@ const BashExecutionToolDefinition = {
|
|
|
95
94
|
schema: BashExecutionToolSchema
|
|
96
95
|
};
|
|
97
96
|
function createBashExecutionTool(params = {}) {
|
|
97
|
+
const execEndpoint = buildCodeApiEndpoint(params?.baseUrl ?? getCodeBaseURL(), "exec");
|
|
98
98
|
return tool(async (rawInput, config) => {
|
|
99
|
-
const { authHeaders,
|
|
99
|
+
const { authHeaders, baseUrl: _baseUrl, executionProfile, runtimeSessionHint, statefulSessions, ...executionParams } = params ?? {};
|
|
100
100
|
const { command, intent: _ignoredIntent, runtime_session_hint: _ignoredModelHint, ...rest } = rawInput;
|
|
101
101
|
const { session_id, _injected_files, _runtime_session_hint } = config.toolCall ?? {};
|
|
102
102
|
const postData = {
|
|
@@ -105,7 +105,8 @@ function createBashExecutionTool(params = {}) {
|
|
|
105
105
|
...rest,
|
|
106
106
|
...executionParams
|
|
107
107
|
};
|
|
108
|
-
|
|
108
|
+
const effectiveRuntimeSessionHint = selectRuntimeSessionHint(runtimeSessionHint, _runtime_session_hint);
|
|
109
|
+
if (statefulSessions === true && executionProfile !== "default" && typeof effectiveRuntimeSessionHint === "string" && effectiveRuntimeSessionHint !== "") postData.runtime_session_hint = effectiveRuntimeSessionHint;
|
|
109
110
|
if (_injected_files && _injected_files.length > 0) postData.files = _injected_files;
|
|
110
111
|
else if (session_id != null && session_id.length > 0 && !Array.isArray(postData.files)) console.debug(`[BashExecutor] No injected files for session_id=${session_id} — exec will run without input files`);
|
|
111
112
|
try {
|
|
@@ -114,14 +115,14 @@ function createBashExecutionTool(params = {}) {
|
|
|
114
115
|
headers: {
|
|
115
116
|
"Content-Type": "application/json",
|
|
116
117
|
"User-Agent": "LibreChat/1.0",
|
|
117
|
-
...await resolveCodeApiAuthHeaders(authHeaders)
|
|
118
|
+
...addCodeApiExecutionProfileHeader(await resolveCodeApiAuthHeaders(authHeaders), executionProfile)
|
|
118
119
|
},
|
|
119
120
|
body: JSON.stringify(postData)
|
|
120
121
|
};
|
|
121
|
-
const proxyAgent = resolveFetchProxyAgent(
|
|
122
|
+
const proxyAgent = resolveFetchProxyAgent(execEndpoint);
|
|
122
123
|
if (proxyAgent) fetchOptions.agent = proxyAgent;
|
|
123
|
-
const response = await fetch(
|
|
124
|
-
if (!response.ok) throw new CodeApiRequestError(await buildCodeApiHttpErrorMessage("POST",
|
|
124
|
+
const response = await fetch(execEndpoint, fetchOptions);
|
|
125
|
+
if (!response.ok) throw new CodeApiRequestError(await buildCodeApiHttpErrorMessage("POST", execEndpoint, response));
|
|
125
126
|
const result = await response.json();
|
|
126
127
|
let formattedOutput = "";
|
|
127
128
|
if (result.stdout) formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
@@ -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":";;;;;;;;;;AAwBA,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;AAYP,MAAa,gCAAgC;;;;;;;;;EAS3C,KAAK;AASP,SAAgB,kCAAkC,SAGvC;CACT,MAAM,OACJ,SAAS,qBAAqB,OAC1B,uCACA;CACN,IAAI,SAAS,+BAA+B,MAC1C,OAAO,GAAG,KAAK,MAAM;CAEvB,OAAO;AACT;AAE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/B;GAEA,MAAM,aAAa,uBAAuB,YAAY;GACtD,IAAI,YACF,aAAa,QAAQ;GAEvB,MAAM,WAAW,MAAM,MAAM,cAAc,YAAY;GACvD,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,oBACR,MAAM,6BAA6B,QAAQ,cAAc,QAAQ,CACnE;GAGF,MAAM,SAA0B,MAAM,SAAS,KAAK;GACpD,IAAI,kBAAkB;GACtB,IAAI,OAAO,QACT,mBAAmB,YAAY,OAAO,OAAO;QAE7C,mBAAmB;GAErB,IAAI,OAAO,QAAQ,mBAAmB,YAAY,OAAO,OAAO;GAEhE,MAAM,qBAAqB,yBACzB,iBACA,OACF;GACA,MAAM,WAAW,OAAO,SAAS,QAAQ,OAAO,MAAM,SAAS;GAC/D,MAAM,cACJ,OAAO,sBAAsB,OACzB;IACA,oBAAoB,OAAO;IAC3B,gBAAgB,OAAO;GACzB,IACE,CAAC;GACP,OAAO,CACL,6BAA6B,oBAAoB,OAAO,KAAK,GAC5D,WACG;IACA,YAAY,OAAO;IACnB,OAAO,OAAO;IACd,GAAG;GACL,IACE;IACA,YAAY,OAAO;IACnB,GAAG;GACL,CACJ;EACF,SAAS,OAAO;GACd,MAAM,sBAAsB,kCAC1B,6BAA6B,KAAK,CAAC,CAAC,SACpC,OACF;GACA,MAAM,IAAI,MAAM,uBAAuB,qBAAqB;EAC9D;CACF,GACA;EACE,MAAM;EACN,aAAa,kCAAkC,EAC7C,kBAAkB,QAAQ,iBAC5B,CAAC;EACD,QAAQ,6BAA6B,UAAU,KAAA,CAAS;EACxD,gBAAA;CACF,CACF;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../common/enum.mjs";
|
|
2
2
|
import "../common/index.mjs";
|
|
3
3
|
import { INTENT_PROPERTY } from "./intentArg.mjs";
|
|
4
|
-
import { BASH_SHELL_GUIDANCE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, appendFailedExecutionFileReminder, buildCodeApiExecutionErrorMessage, getCodeBaseURL } from "./CodeExecutor.mjs";
|
|
4
|
+
import { BASH_SHELL_GUIDANCE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, appendFailedExecutionFileReminder, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, getCodeBaseURL, selectRuntimeSessionHint } from "./CodeExecutor.mjs";
|
|
5
5
|
import { clampCodeApiRunTimeoutMs, createCodeApiRunTimeoutSchema, resolveCodeApiRunTimeoutMs } from "./ptcTimeout.mjs";
|
|
6
6
|
import { executeTools, formatCompletedResponse, makeRequest } from "./ProgrammaticToolCalling.mjs";
|
|
7
7
|
import { tool } from "@langchain/core/tools";
|
|
@@ -162,7 +162,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
162
162
|
const maxRunTimeoutMs = resolveCodeApiRunTimeoutMs(initParams.runTimeoutMs);
|
|
163
163
|
const proxy = initParams.proxy ?? process.env.PROXY;
|
|
164
164
|
const debug = initParams.debug ?? process.env.BASH_PTC_DEBUG === "true";
|
|
165
|
-
const EXEC_ENDPOINT =
|
|
165
|
+
const EXEC_ENDPOINT = buildCodeApiEndpoint(baseUrl, "exec/programmatic");
|
|
166
166
|
return tool(async (rawParams, config) => {
|
|
167
167
|
const params = rawParams;
|
|
168
168
|
const { code } = params;
|
|
@@ -177,7 +177,8 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
177
177
|
let files;
|
|
178
178
|
if (_injected_files && _injected_files.length > 0) files = _injected_files;
|
|
179
179
|
else if (session_id != null && session_id.length > 0) console.debug(`[BashProgrammaticToolCalling] No injected files for session_id=${session_id} — exec will run without input files`);
|
|
180
|
-
const
|
|
180
|
+
const selectedRuntimeSessionHint = selectRuntimeSessionHint(initParams.runtimeSessionHint, _runtime_session_hint);
|
|
181
|
+
const runtimeSessionHint = initParams.executionProfile !== "default" && typeof selectedRuntimeSessionHint === "string" && selectedRuntimeSessionHint !== "" ? selectedRuntimeSessionHint : void 0;
|
|
181
182
|
let response = await makeRequest(EXEC_ENDPOINT, {
|
|
182
183
|
lang: "bash",
|
|
183
184
|
code,
|
|
@@ -186,7 +187,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
186
187
|
timeout,
|
|
187
188
|
...files && files.length > 0 ? { files } : {},
|
|
188
189
|
...runtimeSessionHint != null ? { runtime_session_hint: runtimeSessionHint } : {}
|
|
189
|
-
}, proxy, initParams.authHeaders);
|
|
190
|
+
}, proxy, initParams.authHeaders, initParams.executionProfile);
|
|
190
191
|
while (response.status === "tool_call_required") {
|
|
191
192
|
roundTrip++;
|
|
192
193
|
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.`);
|
|
@@ -195,7 +196,7 @@ function createBashProgrammaticToolCallingTool(initParams = {}) {
|
|
|
195
196
|
response = await makeRequest(EXEC_ENDPOINT, {
|
|
196
197
|
continuation_token: response.continuation_token,
|
|
197
198
|
tool_results: toolResults
|
|
198
|
-
}, proxy, initParams.authHeaders);
|
|
199
|
+
}, proxy, initParams.authHeaders, initParams.executionProfile);
|
|
199
200
|
}
|
|
200
201
|
if (response.status === "completed") return formatCompletedResponse(response, code);
|
|
201
202
|
if (response.status === "error") throw new Error(buildCodeApiExecutionErrorMessage(response));
|
|
@@ -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":";;;;;;;;;AA4BA,OAAO;AAMP,MAAM,0BAA0B;AAChC,MAAM,yBAAyB,2BAA2B;AAG1D,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAC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ACA;KACE,oBAAoB,SAAS;KAC7B,cAAc;IAChB,GACA,OACA,WAAW,aACX,WAAW,gBACb;GACF;GAMA,IAAI,SAAS,WAAW,aACtB,OAAO,wBAAwB,UAAU,IAAI;GAG/C,IAAI,SAAS,WAAW,SACtB,MAAM,IAAI,MAAM,kCAAkC,QAAQ,CAAC;GAG7D,MAAM,IAAI,oBAAoB;EAChC,SAAS,OAAO;GACd,MAAM,sBAAsB,kCACzB,MAAgB,SACjB,IACF;GACA,MAAM,IAAI,MACR,uCAAuC,qBACzC;EACF;CACF,GACA;EACE,MAAA;EACA,aAAa;EACb,QAAQ,wCAAwC,eAAe;EAC/D,gBAAA;CACF,CACF;AACF"}
|
|
@@ -10,6 +10,12 @@ import fetch from "node-fetch";
|
|
|
10
10
|
//#region src/tools/CodeExecutor.ts
|
|
11
11
|
config();
|
|
12
12
|
const getCodeBaseURL = () => getEnvironmentVariable("LIBRECHAT_CODE_BASEURL") ?? "https://api.librechat.ai/v1";
|
|
13
|
+
function buildCodeApiEndpoint(baseUrl, route) {
|
|
14
|
+
return `${baseUrl.replace(/\/+$/, "")}/${route.replace(/^\/+/, "")}`;
|
|
15
|
+
}
|
|
16
|
+
function selectRuntimeSessionHint(factoryHint, injectedHint) {
|
|
17
|
+
return factoryHint != null && factoryHint !== "" ? factoryHint : injectedHint;
|
|
18
|
+
}
|
|
13
19
|
const emptyOutputMessage = "stdout: Empty. Ensure you're writing output explicitly.\n";
|
|
14
20
|
const CODE_ARTIFACT_PATH_GUIDANCE = "Anything a later call needs (data, helper scripts/modules, partial results) MUST be written under `/mnt/data` in the same call that produces it; `/tmp` never survives the call. `/mnt/data` keeps files with recognized extensions, covering common source, text, data, document, image, and archive formats (.py/.sh/.sql/.md/.json/.csv/.parquet/.png/.pdf/.zip and similar); extensionless or unusual extensions are not kept. Failed executions register nothing; fix the error and rerun before relying on new files.";
|
|
15
21
|
const BASH_SHELL_GUIDANCE = "Bash: multi-line files use heredoc/printf; run Python via python3 -c/heredoc, not bare Python.";
|
|
@@ -72,7 +78,7 @@ const CodeExecutionToolSchema = {
|
|
|
72
78
|
},
|
|
73
79
|
required: ["lang", "code"]
|
|
74
80
|
};
|
|
75
|
-
const
|
|
81
|
+
const CODE_API_EXPECTED_PROFILE_HEADER = "X-CodeAPI-Expected-Profile";
|
|
76
82
|
const MAX_RETRY_AFTER_SECONDS = 3600;
|
|
77
83
|
const CODE_API_UNAVAILABLE_ERROR_MESSAGE = "Code execution is temporarily unavailable. Please retry.";
|
|
78
84
|
const CODE_API_AUTHORIZATION_ERROR_MESSAGE = "Code execution is not authorized. Verify access before trying again.";
|
|
@@ -127,6 +133,13 @@ async function resolveCodeApiAuthHeaders(authHeaders) {
|
|
|
127
133
|
}
|
|
128
134
|
return authHeaders;
|
|
129
135
|
}
|
|
136
|
+
function addCodeApiExecutionProfileHeader(headers, executionProfile) {
|
|
137
|
+
if (executionProfile == null) return headers;
|
|
138
|
+
return {
|
|
139
|
+
...headers,
|
|
140
|
+
[CODE_API_EXPECTED_PROFILE_HEADER]: executionProfile
|
|
141
|
+
};
|
|
142
|
+
}
|
|
130
143
|
async function buildCodeApiHttpErrorMessage(_method, _endpoint, response) {
|
|
131
144
|
let responseBody = "";
|
|
132
145
|
try {
|
|
@@ -189,8 +202,9 @@ const CodeExecutionToolDefinition = {
|
|
|
189
202
|
schema: CodeExecutionToolSchema
|
|
190
203
|
};
|
|
191
204
|
function createCodeExecutionTool(params = {}) {
|
|
205
|
+
const execEndpoint = buildCodeApiEndpoint(params?.baseUrl ?? getCodeBaseURL(), "exec");
|
|
192
206
|
return tool(async (rawInput, config) => {
|
|
193
|
-
const { authHeaders,
|
|
207
|
+
const { authHeaders, baseUrl: _baseUrl, executionProfile, runtimeSessionHint, statefulSessions, ...executionParams } = params ?? {};
|
|
194
208
|
const { lang, code, intent: _ignoredIntent, runtime_session_hint: _ignoredModelHint, ...rest } = rawInput;
|
|
195
209
|
const { session_id, _injected_files, _runtime_session_hint } = config.toolCall ?? {};
|
|
196
210
|
const postData = {
|
|
@@ -199,7 +213,8 @@ function createCodeExecutionTool(params = {}) {
|
|
|
199
213
|
...rest,
|
|
200
214
|
...executionParams
|
|
201
215
|
};
|
|
202
|
-
|
|
216
|
+
const effectiveRuntimeSessionHint = selectRuntimeSessionHint(runtimeSessionHint, _runtime_session_hint);
|
|
217
|
+
if (statefulSessions === true && executionProfile !== "default" && typeof effectiveRuntimeSessionHint === "string" && effectiveRuntimeSessionHint !== "") postData.runtime_session_hint = effectiveRuntimeSessionHint;
|
|
203
218
|
if (_injected_files && _injected_files.length > 0) postData.files = _injected_files;
|
|
204
219
|
else if (session_id != null && session_id.length > 0 && !Array.isArray(postData.files)) console.debug(`[CodeExecutor] No injected files for session_id=${session_id} — exec will run without input files`);
|
|
205
220
|
try {
|
|
@@ -208,14 +223,14 @@ function createCodeExecutionTool(params = {}) {
|
|
|
208
223
|
headers: {
|
|
209
224
|
"Content-Type": "application/json",
|
|
210
225
|
"User-Agent": "LibreChat/1.0",
|
|
211
|
-
...await resolveCodeApiAuthHeaders(authHeaders)
|
|
226
|
+
...addCodeApiExecutionProfileHeader(await resolveCodeApiAuthHeaders(authHeaders), executionProfile)
|
|
212
227
|
},
|
|
213
228
|
body: JSON.stringify(postData)
|
|
214
229
|
};
|
|
215
|
-
const proxyAgent = resolveFetchProxyAgent(
|
|
230
|
+
const proxyAgent = resolveFetchProxyAgent(execEndpoint);
|
|
216
231
|
if (proxyAgent) fetchOptions.agent = proxyAgent;
|
|
217
|
-
const response = await fetch(
|
|
218
|
-
if (!response.ok) throw new CodeApiRequestError(await buildCodeApiHttpErrorMessage("POST",
|
|
232
|
+
const response = await fetch(execEndpoint, fetchOptions);
|
|
233
|
+
if (!response.ok) throw new CodeApiRequestError(await buildCodeApiHttpErrorMessage("POST", execEndpoint, response));
|
|
219
234
|
const result = await response.json();
|
|
220
235
|
let formattedOutput = "";
|
|
221
236
|
if (result.stdout) formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
@@ -247,6 +262,6 @@ function createCodeExecutionTool(params = {}) {
|
|
|
247
262
|
});
|
|
248
263
|
}
|
|
249
264
|
//#endregion
|
|
250
|
-
export { BASH_SHELL_GUIDANCE, CODE_API_AUTHORIZATION_ERROR_MESSAGE, CODE_API_EXECUTION_FAILED_ERROR_MESSAGE, CODE_API_INVALID_REQUEST_ERROR_MESSAGE, CODE_API_RATE_LIMITED_ERROR_MESSAGE, CODE_API_UNAVAILABLE_ERROR_MESSAGE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, CodeExecutionToolDefinition, CodeExecutionToolDescription, CodeExecutionToolName, CodeExecutionToolSchema, FAILED_EXECUTION_FILE_REMINDER, STATEFUL_ENV_NOTE, StatefulCodeExecutionToolDescription, TMP_SCRATCH_OUTPUT_REMINDER, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiExecutionErrorMessage, buildCodeApiHttpErrorMessage, buildCodeExecutionToolDescription, buildCodeExecutionToolSchema, createCodeExecutionTool, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders };
|
|
265
|
+
export { BASH_SHELL_GUIDANCE, CODE_API_AUTHORIZATION_ERROR_MESSAGE, CODE_API_EXECUTION_FAILED_ERROR_MESSAGE, CODE_API_EXPECTED_PROFILE_HEADER, CODE_API_INVALID_REQUEST_ERROR_MESSAGE, CODE_API_RATE_LIMITED_ERROR_MESSAGE, CODE_API_UNAVAILABLE_ERROR_MESSAGE, CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, CodeExecutionToolDefinition, CodeExecutionToolDescription, CodeExecutionToolName, CodeExecutionToolSchema, FAILED_EXECUTION_FILE_REMINDER, STATEFUL_ENV_NOTE, StatefulCodeExecutionToolDescription, TMP_SCRATCH_OUTPUT_REMINDER, addCodeApiExecutionProfileHeader, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, buildCodeApiHttpErrorMessage, buildCodeExecutionToolDescription, buildCodeExecutionToolSchema, createCodeExecutionTool, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders, selectRuntimeSessionHint };
|
|
251
266
|
|
|
252
267
|
//# sourceMappingURL=CodeExecutor.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.mjs","names":[],"sources":["../../../src/tools/CodeExecutor.ts"],"mappings":";;;;;;;;;;AAeA,OAAO;AAEP,MAAa,uBACX,uBAAA,wBAA0C,KAAA;AAG5C,MAAa,qBACX;AAEF,MAAa,8BACX;AAEF,MAAa,sBACX;AAEF,MAAM,mBAAmB;AACzB,MAAM,wBAAwB;AAE9B,MAAa,8BACX;AAEF,MAAa,iCACX;AAEF,SAAgB,yBAAyB,QAAgB,MAAsB;CAC7E,IAAI,CAAC,iBAAiB,KAAK,IAAI,GAC7B,OAAO;CAET,OAAO,GAAG,OAAO,QAAQ,EAAE,IAAI,4BAA4B;AAC7D;AAEA,SAAgB,kCACd,QACA,MACQ;CACR,IACE,CAAC,sBAAsB,KAAK,IAAI,KAChC,OAAO,SAAA,sIAAuC,GAE9C,OAAO;CAET,OAAO,GAAG,OAAO,QAAQ,EAAE,IAAI,+BAA+B;AAChE;AAEA,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,0BAA0B;CACrC,MAAM;CACN,YAAY;EACV,QAAQ,EAAE,GAAG,gBAAgB;EAC7B,MAAM;GACJ,MAAM;GACN,MAAM;GACN,aACE;EACJ;EACA,MAAM;GACJ,MAAM;GACN,aAAa;;;IAGf,4BAA4B;;;;;;;;;EAS5B;EACA,MAAM;GACJ,MAAM;GACN,OAAO,EAAE,MAAM,SAAS;GACxB,aACE;EACJ;CACF;CACA,UAAU,CAAC,QAAQ,MAAM;AAC3B;
|
|
1
|
+
{"version":3,"file":"CodeExecutor.mjs","names":[],"sources":["../../../src/tools/Code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AoB,OAAO;IAC3B,gBAAgB,OAAO;GACzB,IACE,CAAC;GACP,OAAO,CACL,6BAA6B,oBAAoB,OAAO,KAAK,GAC5D,WACG;IACA,YAAY,OAAO;IACnB,OAAO,OAAO;IACd,GAAG;GACL,IACE;IACA,YAAY,OAAO;IACnB,GAAG;GACL,CACJ;EACF,SAAS,OAAO;GACd,MAAM,sBAAsB,kCAC1B,6BAA6B,KAAK,CAAC,CAAC,SACpC,IACF;GACA,MAAM,IAAI,MAAM,uBAAuB,qBAAqB;EAC9D;CACF,GACA;EACE,MAAM;EACN,aAAa,kCAAkC,UAAU,KAAA,CAAS;EAClE,QAAQ,6BAA6B,UAAU,KAAA,CAAS;EACxD,gBAAA;CACF,CACF;AACF"}
|
|
@@ -3,7 +3,7 @@ import "../common/index.mjs";
|
|
|
3
3
|
import { resolveFetchProxyAgent } from "../utils/proxy.mjs";
|
|
4
4
|
import { INTENT_PROPERTY } from "./intentArg.mjs";
|
|
5
5
|
import { appendCodeSessionFileSummary } from "./CodeSessionFileSummary.mjs";
|
|
6
|
-
import { CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiExecutionErrorMessage, buildCodeApiHttpErrorMessage, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders } from "./CodeExecutor.mjs";
|
|
6
|
+
import { CODE_ARTIFACT_PATH_GUIDANCE, CodeApiRequestError, addCodeApiExecutionProfileHeader, appendFailedExecutionFileReminder, appendTmpScratchReminder, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, buildCodeApiHttpErrorMessage, emptyOutputMessage, getCodeBaseURL, normalizeCodeApiRequestError, resolveCodeApiAuthHeaders, selectRuntimeSessionHint } from "./CodeExecutor.mjs";
|
|
7
7
|
import { clampCodeApiRunTimeoutMs, createCodeApiRunTimeoutSchema, resolveCodeApiRunTimeoutMs } from "./ptcTimeout.mjs";
|
|
8
8
|
import { tool } from "@langchain/core/tools";
|
|
9
9
|
import { config } from "dotenv";
|
|
@@ -237,14 +237,14 @@ async function fetchSessionFiles(baseUrl, sessionId, scopeOrProxy, proxyOrAuthHe
|
|
|
237
237
|
return [];
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
async function makeRequest(endpoint, body, proxy, authHeaders) {
|
|
240
|
+
async function makeRequest(endpoint, body, proxy, authHeaders, executionProfile) {
|
|
241
241
|
try {
|
|
242
242
|
const fetchOptions = {
|
|
243
243
|
method: "POST",
|
|
244
244
|
headers: {
|
|
245
245
|
"Content-Type": "application/json",
|
|
246
246
|
"User-Agent": "LibreChat/1.0",
|
|
247
|
-
...await resolveCodeApiAuthHeaders(authHeaders)
|
|
247
|
+
...addCodeApiExecutionProfileHeader(await resolveCodeApiAuthHeaders(authHeaders), executionProfile)
|
|
248
248
|
},
|
|
249
249
|
body: JSON.stringify(body)
|
|
250
250
|
};
|
|
@@ -413,7 +413,7 @@ function createProgrammaticToolCallingTool(initParams = {}) {
|
|
|
413
413
|
const maxRunTimeoutMs = resolveCodeApiRunTimeoutMs(initParams.runTimeoutMs);
|
|
414
414
|
const proxy = initParams.proxy ?? process.env.PROXY;
|
|
415
415
|
const debug = initParams.debug ?? process.env.PTC_DEBUG === "true";
|
|
416
|
-
const EXEC_ENDPOINT =
|
|
416
|
+
const EXEC_ENDPOINT = buildCodeApiEndpoint(baseUrl, "exec/programmatic");
|
|
417
417
|
return tool(async (rawParams, config) => {
|
|
418
418
|
const params = rawParams;
|
|
419
419
|
const { code } = params;
|
|
@@ -428,7 +428,8 @@ function createProgrammaticToolCallingTool(initParams = {}) {
|
|
|
428
428
|
let files;
|
|
429
429
|
if (_injected_files && _injected_files.length > 0) files = _injected_files;
|
|
430
430
|
else if (session_id != null && session_id.length > 0) console.debug(`[ProgrammaticToolCalling] No injected files for session_id=${session_id} — exec will run without input files`);
|
|
431
|
-
const
|
|
431
|
+
const selectedRuntimeSessionHint = selectRuntimeSessionHint(initParams.runtimeSessionHint, _runtime_session_hint);
|
|
432
|
+
const runtimeSessionHint = initParams.executionProfile !== "default" && typeof selectedRuntimeSessionHint === "string" && selectedRuntimeSessionHint !== "" ? selectedRuntimeSessionHint : void 0;
|
|
432
433
|
let response = await makeRequest(EXEC_ENDPOINT, {
|
|
433
434
|
code,
|
|
434
435
|
tools: effectiveTools,
|
|
@@ -436,7 +437,7 @@ function createProgrammaticToolCallingTool(initParams = {}) {
|
|
|
436
437
|
timeout,
|
|
437
438
|
...files && files.length > 0 ? { files } : {},
|
|
438
439
|
...runtimeSessionHint != null ? { runtime_session_hint: runtimeSessionHint } : {}
|
|
439
|
-
}, proxy, initParams.authHeaders);
|
|
440
|
+
}, proxy, initParams.authHeaders, initParams.executionProfile);
|
|
440
441
|
while (response.status === "tool_call_required") {
|
|
441
442
|
roundTrip++;
|
|
442
443
|
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.`);
|
|
@@ -445,7 +446,7 @@ function createProgrammaticToolCallingTool(initParams = {}) {
|
|
|
445
446
|
response = await makeRequest(EXEC_ENDPOINT, {
|
|
446
447
|
continuation_token: response.continuation_token,
|
|
447
448
|
tool_results: toolResults
|
|
448
|
-
}, proxy, initParams.authHeaders);
|
|
449
|
+
}, proxy, initParams.authHeaders, initParams.executionProfile);
|
|
449
450
|
}
|
|
450
451
|
if (response.status === "completed") return formatCompletedResponse(response, code);
|
|
451
452
|
if (response.status === "error") throw new Error(buildCodeApiExecutionErrorMessage(response));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgrammaticToolCalling.mjs","names":["obj"],"sources":["../../../src/tools/ProgrammaticToolCalling.ts"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ProgrammaticToolCalling.mjs","names":["obj"],"sources":["../../../src/tools/ProgrammaticToolCalling.ts"],"mappings":";;;;;;;;;;;AAgCA,OAAO;AAGP,MAAM,0BAA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;EACA,aAAa;EACb,QAAQ,oCAAoC,eAAe;EAC3D,gBAAA;CACF,CACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attachRunStepResumeState } from "./runStepResume.mjs";
|
|
1
2
|
import { SUBAGENT_PARENT_BATCH_CONFIG_KEY, SUBAGENT_REPLAY_CONTROLLER, attachSubagentResumeManifest } from "./subagent/SubagentReplay.mjs";
|
|
2
3
|
import { composeAbortSignals } from "../utils/misc.mjs";
|
|
3
4
|
import { CODE_EXECUTION_TOOLS } from "../common/enum.mjs";
|
|
@@ -188,11 +189,11 @@ function toInjectedFileRef(file, execSessionId) {
|
|
|
188
189
|
function fileIdentityKey(file) {
|
|
189
190
|
return `${file.storage_session_id ?? ""}\0${file.id}`;
|
|
190
191
|
}
|
|
191
|
-
function updateCodeSession(sessions, execSessionId, files) {
|
|
192
|
+
function updateCodeSession(sessions, sessionKey, execSessionId, files) {
|
|
192
193
|
const newFiles = files ?? [];
|
|
193
|
-
const existingFiles = sessions.get(
|
|
194
|
+
const existingFiles = sessions.get(sessionKey)?.files ?? [];
|
|
194
195
|
if (newFiles.length === 0) {
|
|
195
|
-
sessions.set(
|
|
196
|
+
sessions.set(sessionKey, {
|
|
196
197
|
session_id: execSessionId,
|
|
197
198
|
files: existingFiles,
|
|
198
199
|
lastUpdated: Date.now()
|
|
@@ -220,7 +221,7 @@ function updateCodeSession(sessions, execSessionId, files) {
|
|
|
220
221
|
};
|
|
221
222
|
if (!newFileNames.has(e.name)) filteredExisting.push(e);
|
|
222
223
|
}
|
|
223
|
-
sessions.set(
|
|
224
|
+
sessions.set(sessionKey, {
|
|
224
225
|
session_id: execSessionId,
|
|
225
226
|
files: [...filteredExisting, ...filesWithSession],
|
|
226
227
|
lastUpdated: Date.now()
|
|
@@ -243,6 +244,7 @@ var ToolNode = class extends RunnableCallable {
|
|
|
243
244
|
toolRegistry;
|
|
244
245
|
programmaticCache;
|
|
245
246
|
sessions;
|
|
247
|
+
codeSessionKey;
|
|
246
248
|
eventDrivenMode = false;
|
|
247
249
|
eagerEventToolExecution;
|
|
248
250
|
codeSessionToolNames;
|
|
@@ -262,11 +264,31 @@ var ToolNode = class extends RunnableCallable {
|
|
|
262
264
|
getBreakerSignal;
|
|
263
265
|
getRunScope;
|
|
264
266
|
anonBatchCounter = 0;
|
|
265
|
-
constructor({ tools, toolMap, name, tags, trace, runLangfuse, agentLangfuse, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, sessions, eventDrivenMode, eagerEventToolExecution, eagerEventToolExecutions, eagerEventToolUsageCount, eagerEventToolSuppressions, agentId, executingAgentId, directToolNames, interruptingToolNames, codeSessionToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, toolExecution, fileCheckpointer, getBreakerSignal, getRunScope }) {
|
|
267
|
+
constructor({ tools, toolMap, name, tags, trace, runLangfuse, agentLangfuse, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, sessions, codeSessionKey, eventDrivenMode, eagerEventToolExecution, eagerEventToolExecutions, eagerEventToolUsageCount, eagerEventToolSuppressions, agentId, executingAgentId, directToolNames, interruptingToolNames, codeSessionToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, toolExecution, fileCheckpointer, getBreakerSignal, getRunScope, restoreRunStepResumeState, createRunStepResumeState }) {
|
|
266
268
|
super({
|
|
267
269
|
name: name ?? TOOL_NODE_RUN_NAME,
|
|
268
270
|
tags,
|
|
269
|
-
func: (input, config) =>
|
|
271
|
+
func: async (input, config) => {
|
|
272
|
+
restoreRunStepResumeState?.(input.runStepState, config);
|
|
273
|
+
let result;
|
|
274
|
+
try {
|
|
275
|
+
result = await this.run(input, config);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (!isGraphInterrupt(error) || createRunStepResumeState == null) throw error;
|
|
278
|
+
const resumeState = createRunStepResumeState();
|
|
279
|
+
throw new GraphInterrupt(error.interrupts.map((pendingInterrupt) => ({
|
|
280
|
+
...pendingInterrupt,
|
|
281
|
+
value: attachRunStepResumeState(pendingInterrupt.value, resumeState)
|
|
282
|
+
})));
|
|
283
|
+
}
|
|
284
|
+
if (createRunStepResumeState == null) return result;
|
|
285
|
+
const runStepState = createRunStepResumeState();
|
|
286
|
+
if (Array.isArray(result)) return [...result, { runStepState }];
|
|
287
|
+
return {
|
|
288
|
+
...result,
|
|
289
|
+
runStepState
|
|
290
|
+
};
|
|
291
|
+
}
|
|
270
292
|
});
|
|
271
293
|
this.trace = trace ?? this.trace;
|
|
272
294
|
this.runLangfuse = runLangfuse;
|
|
@@ -282,6 +304,7 @@ var ToolNode = class extends RunnableCallable {
|
|
|
282
304
|
toolExecution
|
|
283
305
|
});
|
|
284
306
|
this.sessions = sessions;
|
|
307
|
+
this.codeSessionKey = codeSessionKey ?? "execute_code";
|
|
285
308
|
this.eventDrivenMode = eventDrivenMode ?? false;
|
|
286
309
|
this.eagerEventToolExecution = eagerEventToolExecution;
|
|
287
310
|
this.eagerEventToolExecutions = eagerEventToolExecutions;
|
|
@@ -475,7 +498,7 @@ var ToolNode = class extends RunnableCallable {
|
|
|
475
498
|
toolRegistry: this.toolRegistry
|
|
476
499
|
};
|
|
477
500
|
if (this.participatesInCodeSession(call.name)) {
|
|
478
|
-
const codeSession = this.sessions?.get(
|
|
501
|
+
const codeSession = this.sessions?.get(this.codeSessionKey);
|
|
479
502
|
const execSessionId = codeSession?.session_id;
|
|
480
503
|
if (execSessionId != null && execSessionId !== "") {
|
|
481
504
|
invokeParams = {
|
|
@@ -899,7 +922,7 @@ var ToolNode = class extends RunnableCallable {
|
|
|
899
922
|
}
|
|
900
923
|
getCodeSessionContext() {
|
|
901
924
|
if (!this.sessions) return;
|
|
902
|
-
const codeSession = this.sessions.get(
|
|
925
|
+
const codeSession = this.sessions.get(this.codeSessionKey);
|
|
903
926
|
if (!codeSession) return;
|
|
904
927
|
const execSessionId = codeSession.session_id;
|
|
905
928
|
const context = { session_id: execSessionId };
|
|
@@ -923,7 +946,7 @@ var ToolNode = class extends RunnableCallable {
|
|
|
923
946
|
const artifact = result.artifact;
|
|
924
947
|
const execSessionId = artifact?.session_id;
|
|
925
948
|
if (execSessionId == null || execSessionId === "") continue;
|
|
926
|
-
updateCodeSession(this.sessions, execSessionId, artifact?.files);
|
|
949
|
+
updateCodeSession(this.sessions, this.codeSessionKey, execSessionId, artifact?.files);
|
|
927
950
|
}
|
|
928
951
|
}
|
|
929
952
|
async handleRunToolCompletions(calls, outputs, config, resolvedArgsByCallId, errorOwnership) {
|
|
@@ -945,7 +968,7 @@ var ToolNode = class extends RunnableCallable {
|
|
|
945
968
|
if (this.sessions && this.participatesInCodeSession(call.name)) {
|
|
946
969
|
const artifact = toolMessage.artifact;
|
|
947
970
|
const execSessionId = artifact?.session_id;
|
|
948
|
-
if (execSessionId != null && execSessionId !== "") updateCodeSession(this.sessions, execSessionId, artifact?.files);
|
|
971
|
+
if (execSessionId != null && execSessionId !== "") updateCodeSession(this.sessions, this.codeSessionKey, execSessionId, artifact?.files);
|
|
949
972
|
}
|
|
950
973
|
const stepId = this.toolCallStepIds?.get(toolCallId) ?? "";
|
|
951
974
|
if (!stepId) continue;
|