@librechat/agents 3.1.90 → 3.1.92

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.
Files changed (94) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +9 -5
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/graphs/Graph.cjs +48 -14
  4. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  5. package/dist/cjs/instrumentation.cjs +2 -7
  6. package/dist/cjs/instrumentation.cjs.map +1 -1
  7. package/dist/cjs/langfuse.cjs +285 -0
  8. package/dist/cjs/langfuse.cjs.map +1 -0
  9. package/dist/cjs/main.cjs +25 -0
  10. package/dist/cjs/main.cjs.map +1 -1
  11. package/dist/cjs/run.cjs +75 -44
  12. package/dist/cjs/run.cjs.map +1 -1
  13. package/dist/cjs/stream.cjs +10 -3
  14. package/dist/cjs/stream.cjs.map +1 -1
  15. package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs +380 -0
  16. package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -0
  17. package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs +997 -0
  18. package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -0
  19. package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +575 -0
  20. package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -0
  21. package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs +165 -0
  22. package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -0
  23. package/dist/cjs/tools/local/LocalExecutionEngine.cjs +17 -5
  24. package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
  25. package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +110 -6
  26. package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
  27. package/dist/cjs/utils/callbacks.cjs +27 -0
  28. package/dist/cjs/utils/callbacks.cjs.map +1 -0
  29. package/dist/esm/agents/AgentContext.mjs +9 -5
  30. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  31. package/dist/esm/graphs/Graph.mjs +48 -14
  32. package/dist/esm/graphs/Graph.mjs.map +1 -1
  33. package/dist/esm/instrumentation.mjs +2 -7
  34. package/dist/esm/instrumentation.mjs.map +1 -1
  35. package/dist/esm/langfuse.mjs +275 -0
  36. package/dist/esm/langfuse.mjs.map +1 -0
  37. package/dist/esm/main.mjs +5 -1
  38. package/dist/esm/main.mjs.map +1 -1
  39. package/dist/esm/run.mjs +75 -44
  40. package/dist/esm/run.mjs.map +1 -1
  41. package/dist/esm/stream.mjs +10 -3
  42. package/dist/esm/stream.mjs.map +1 -1
  43. package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs +378 -0
  44. package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -0
  45. package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs +994 -0
  46. package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -0
  47. package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +566 -0
  48. package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -0
  49. package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs +155 -0
  50. package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -0
  51. package/dist/esm/tools/local/LocalExecutionEngine.mjs +17 -6
  52. package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
  53. package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +111 -7
  54. package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
  55. package/dist/esm/utils/callbacks.mjs +24 -0
  56. package/dist/esm/utils/callbacks.mjs.map +1 -0
  57. package/dist/types/agents/AgentContext.d.ts +4 -1
  58. package/dist/types/graphs/Graph.d.ts +6 -5
  59. package/dist/types/index.d.ts +1 -0
  60. package/dist/types/langfuse.d.ts +57 -0
  61. package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +23 -0
  62. package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +4 -0
  63. package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +21 -0
  64. package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +22 -0
  65. package/dist/types/tools/cloudflare/index.d.ts +4 -0
  66. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -0
  67. package/dist/types/types/graph.d.ts +8 -0
  68. package/dist/types/types/run.d.ts +2 -2
  69. package/dist/types/types/tools.d.ts +118 -2
  70. package/dist/types/utils/callbacks.d.ts +5 -0
  71. package/package.json +4 -4
  72. package/src/__tests__/stream.eagerEventExecution.test.ts +66 -0
  73. package/src/agents/AgentContext.ts +13 -3
  74. package/src/graphs/Graph.ts +57 -16
  75. package/src/index.ts +1 -0
  76. package/src/instrumentation.ts +2 -7
  77. package/src/langfuse.ts +441 -0
  78. package/src/run.ts +105 -59
  79. package/src/specs/langfuse-callbacks.test.ts +75 -0
  80. package/src/specs/langfuse-config.test.ts +114 -0
  81. package/src/specs/langfuse-metadata.test.ts +19 -1
  82. package/src/stream.ts +13 -3
  83. package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +537 -0
  84. package/src/tools/cloudflare/CloudflareBridgeRuntime.ts +480 -0
  85. package/src/tools/cloudflare/CloudflareProgrammaticToolCalling.ts +1162 -0
  86. package/src/tools/cloudflare/CloudflareSandboxExecutionEngine.ts +744 -0
  87. package/src/tools/cloudflare/CloudflareSandboxTools.ts +225 -0
  88. package/src/tools/cloudflare/index.ts +4 -0
  89. package/src/tools/local/LocalExecutionEngine.ts +20 -4
  90. package/src/tools/local/resolveLocalExecutionTools.ts +169 -7
  91. package/src/types/graph.ts +9 -0
  92. package/src/types/run.ts +2 -7
  93. package/src/types/tools.ts +141 -2
  94. package/src/utils/callbacks.ts +39 -0
@@ -4,13 +4,53 @@ var _enum = require('../../common/enum.cjs');
4
4
  var LocalExecutionTools = require('./LocalExecutionTools.cjs');
5
5
  var LocalCodingTools = require('./LocalCodingTools.cjs');
6
6
  var LocalProgrammaticToolCalling = require('./LocalProgrammaticToolCalling.cjs');
7
+ require('path');
8
+ require('../cloudflare/CloudflareProgrammaticToolCalling.cjs');
9
+ require('events');
10
+ require('stream');
11
+ require('./LocalExecutionEngine.cjs');
12
+ var CloudflareSandboxTools = require('../cloudflare/CloudflareSandboxTools.cjs');
7
13
 
8
14
  function shouldUseLocalExecution(config) {
9
15
  return config?.engine === 'local';
10
16
  }
17
+ function shouldUseCloudflareSandboxExecution(config) {
18
+ return config?.engine === 'cloudflare-sandbox';
19
+ }
11
20
  function shouldIncludeCodingTools(config) {
12
- return (shouldUseLocalExecution(config) &&
13
- config?.local?.includeCodingTools !== false);
21
+ return ((shouldUseLocalExecution(config) &&
22
+ config?.local?.includeCodingTools !== false) ||
23
+ (shouldUseCloudflareSandboxExecution(config) &&
24
+ config?.cloudflare?.includeCodingTools !== false));
25
+ }
26
+ function getCloudflareConfig(config) {
27
+ if (config?.cloudflare == null) {
28
+ throw new Error('toolExecution.cloudflare is required when engine is "cloudflare-sandbox".');
29
+ }
30
+ return config.cloudflare;
31
+ }
32
+ function getSelectedCloudflareCodingToolNames(config) {
33
+ return new Set(config.codingToolNames ?? _enum.LOCAL_CODING_BUNDLE_NAMES);
34
+ }
35
+ function filterCloudflareCodingToolAllowlist(tools, selectedNames) {
36
+ const existingTools = tools ?? [];
37
+ if (existingTools.length === 0) {
38
+ return tools;
39
+ }
40
+ return existingTools.filter((existingTool) => {
41
+ if (!('name' in existingTool) || typeof existingTool.name !== 'string') {
42
+ return true;
43
+ }
44
+ return (!_enum.LOCAL_CODING_BUNDLE_NAMES.includes(existingTool.name) ||
45
+ selectedNames.has(existingTool.name));
46
+ });
47
+ }
48
+ function pruneCloudflareCodingToolAllowlist(toolMap, selectedNames) {
49
+ for (const name of _enum.LOCAL_CODING_BUNDLE_NAMES) {
50
+ if (!selectedNames.has(name)) {
51
+ toolMap.delete(name);
52
+ }
53
+ }
14
54
  }
15
55
  function createLocalExecutionTool(name, config) {
16
56
  switch (name) {
@@ -47,9 +87,26 @@ function mergeToolsByName(baseTools, localTools) {
47
87
  return orderedTools;
48
88
  }
49
89
  function resolveLocalToolsForBinding(args) {
50
- if (!shouldUseLocalExecution(args.toolExecution)) {
90
+ if (!shouldUseLocalExecution(args.toolExecution) &&
91
+ !shouldUseCloudflareSandboxExecution(args.toolExecution)) {
51
92
  return args.tools;
52
93
  }
94
+ if (shouldUseCloudflareSandboxExecution(args.toolExecution)) {
95
+ const cloudflareConfig = getCloudflareConfig(args.toolExecution);
96
+ if (shouldIncludeCodingTools(args.toolExecution)) {
97
+ const selectedNames = getSelectedCloudflareCodingToolNames(cloudflareConfig);
98
+ return mergeToolsByName(filterCloudflareCodingToolAllowlist(args.tools, selectedNames), CloudflareSandboxTools.createCloudflareCodingTools(cloudflareConfig));
99
+ }
100
+ const replacements = (args.tools ?? [])
101
+ .filter((existingTool) => 'name' in existingTool &&
102
+ typeof existingTool.name === 'string' &&
103
+ _enum.CODE_EXECUTION_TOOLS.has(existingTool.name))
104
+ .map((existingTool) => CloudflareSandboxTools.createCloudflareExecutionTool(existingTool.name, cloudflareConfig))
105
+ .filter((cloudflareTool) => cloudflareTool != null);
106
+ return replacements.length === 0
107
+ ? args.tools
108
+ : mergeToolsByName(args.tools, replacements);
109
+ }
53
110
  const localConfig = args.toolExecution?.local ?? {};
54
111
  if (shouldIncludeCodingTools(args.toolExecution)) {
55
112
  return mergeToolsByName(args.tools, LocalCodingTools.createLocalCodingTools(localConfig));
@@ -69,22 +126,68 @@ function resolveLocalToolRegistry(args) {
69
126
  return args.toolRegistry;
70
127
  }
71
128
  const registry = new Map(args.toolRegistry ?? []);
129
+ const selectedNames = shouldUseCloudflareSandboxExecution(args.toolExecution)
130
+ ? getSelectedCloudflareCodingToolNames(getCloudflareConfig(args.toolExecution))
131
+ : undefined;
72
132
  for (const definition of LocalCodingTools.createLocalCodingToolDefinitions()) {
133
+ if (selectedNames != null && !selectedNames.has(definition.name)) {
134
+ registry.delete(definition.name);
135
+ continue;
136
+ }
73
137
  registry.set(definition.name, definition);
74
138
  }
75
139
  return registry;
76
140
  }
77
141
  function resolveLocalExecutionTools(args) {
78
142
  const directToolNames = new Set();
79
- if (!shouldUseLocalExecution(args.toolExecution)) {
143
+ if (!shouldUseLocalExecution(args.toolExecution) &&
144
+ !shouldUseCloudflareSandboxExecution(args.toolExecution)) {
80
145
  return {
81
146
  toolMap: args.toolMap,
82
147
  directToolNames,
83
148
  };
84
149
  }
85
- const localConfig = args.toolExecution?.local ?? {};
86
150
  const toolMap = new Map(args.toolMap);
87
151
  let fileCheckpointer;
152
+ if (shouldUseCloudflareSandboxExecution(args.toolExecution)) {
153
+ const cloudflareConfig = getCloudflareConfig(args.toolExecution);
154
+ if (shouldIncludeCodingTools(args.toolExecution)) {
155
+ const selectedNames = getSelectedCloudflareCodingToolNames(cloudflareConfig);
156
+ pruneCloudflareCodingToolAllowlist(toolMap, selectedNames);
157
+ if (cloudflareConfig.fileCheckpointing === true ||
158
+ args.fileCheckpointer != null) {
159
+ const bundle = CloudflareSandboxTools.createCloudflareCodingToolBundle(cloudflareConfig, {
160
+ checkpointer: args.fileCheckpointer,
161
+ });
162
+ fileCheckpointer = bundle.checkpointer;
163
+ for (const cloudflareTool of bundle.tools) {
164
+ toolMap.set(cloudflareTool.name, cloudflareTool);
165
+ directToolNames.add(cloudflareTool.name);
166
+ }
167
+ }
168
+ else {
169
+ for (const cloudflareTool of CloudflareSandboxTools.createCloudflareCodingTools(cloudflareConfig)) {
170
+ toolMap.set(cloudflareTool.name, cloudflareTool);
171
+ directToolNames.add(cloudflareTool.name);
172
+ }
173
+ }
174
+ }
175
+ const includeCodingTools = shouldIncludeCodingTools(args.toolExecution);
176
+ for (const name of _enum.CODE_EXECUTION_TOOLS) {
177
+ if (includeCodingTools)
178
+ continue;
179
+ if (!toolMap.has(name))
180
+ continue;
181
+ const cloudflareTool = CloudflareSandboxTools.createCloudflareExecutionTool(name, cloudflareConfig);
182
+ if (cloudflareTool == null) {
183
+ continue;
184
+ }
185
+ toolMap.set(name, cloudflareTool);
186
+ directToolNames.add(name);
187
+ }
188
+ return { toolMap, directToolNames, fileCheckpointer };
189
+ }
190
+ const localConfig = args.toolExecution?.local ?? {};
88
191
  if (shouldIncludeCodingTools(args.toolExecution)) {
89
192
  // Use the bundle factory when fileCheckpointing is on so we can
90
193
  // surface the checkpointer back to the caller — without this, the
@@ -92,7 +195,8 @@ function resolveLocalExecutionTools(args) {
92
195
  // immediately discarded, making the public `fileCheckpointing`
93
196
  // config flag a silent no-op outside of direct
94
197
  // `createLocalCodingToolBundle()` use.
95
- if (localConfig.fileCheckpointing === true || args.fileCheckpointer != null) {
198
+ if (localConfig.fileCheckpointing === true ||
199
+ args.fileCheckpointer != null) {
96
200
  const bundle = LocalCodingTools.createLocalCodingToolBundle(localConfig, {
97
201
  checkpointer: args.fileCheckpointer,
98
202
  });
@@ -1 +1 @@
1
- {"version":3,"file":"resolveLocalExecutionTools.cjs","sources":["../../../../src/tools/local/resolveLocalExecutionTools.ts"],"sourcesContent":["import { Constants, CODE_EXECUTION_TOOLS } from '@/common';\nimport {\n createLocalBashExecutionTool,\n createLocalCodeExecutionTool,\n} from './LocalExecutionTools';\nimport {\n createLocalCodingToolBundle,\n createLocalCodingToolDefinitions,\n createLocalCodingTools,\n} from './LocalCodingTools';\nimport {\n createLocalBashProgrammaticToolCallingTool,\n createLocalProgrammaticToolCallingTool,\n} from './LocalProgrammaticToolCalling';\nimport type * as t from '@/types';\n\ntype ResolveLocalToolsResult = {\n toolMap: t.ToolMap;\n directToolNames: Set<string>;\n /**\n * Set when `local.fileCheckpointing === true` AND the auto-bind\n * coding suite is in use. ToolNode stashes this on the node and\n * exposes it via `getFileCheckpointer()` so the host can call\n * `rewind()` after a failed batch. Manual review (finding E)\n * flagged that the config flag was previously a no-op in the\n * Run/ToolNode auto-bind path — only direct\n * `createLocalCodingToolBundle()` callers could access the\n * checkpointer.\n */\n fileCheckpointer?: t.LocalFileCheckpointer;\n};\n\nfunction shouldUseLocalExecution(config?: t.ToolExecutionConfig): boolean {\n return config?.engine === 'local';\n}\n\nfunction shouldIncludeCodingTools(config?: t.ToolExecutionConfig): boolean {\n return (\n shouldUseLocalExecution(config) &&\n config?.local?.includeCodingTools !== false\n );\n}\n\nfunction createLocalExecutionTool(\n name: string,\n config: t.LocalExecutionConfig\n): t.GenericTool | undefined {\n switch (name) {\n case Constants.EXECUTE_CODE:\n return createLocalCodeExecutionTool(config);\n case Constants.BASH_TOOL:\n return createLocalBashExecutionTool({ config });\n case Constants.PROGRAMMATIC_TOOL_CALLING:\n return createLocalProgrammaticToolCallingTool(config);\n case Constants.BASH_PROGRAMMATIC_TOOL_CALLING:\n return createLocalBashProgrammaticToolCallingTool(config);\n default:\n return undefined;\n }\n}\n\nfunction mergeToolsByName(\n baseTools: t.GraphTools | undefined,\n localTools: t.GenericTool[]\n): t.GraphTools {\n const orderedTools: t.GenericTool[] = [];\n const indexByName = new Map<string, number>();\n\n for (const tool of (baseTools as t.GenericTool[] | undefined) ?? []) {\n if ('name' in tool && typeof tool.name === 'string') {\n indexByName.set(tool.name, orderedTools.length);\n }\n orderedTools.push(tool);\n }\n\n for (const tool of localTools) {\n const existingIndex = indexByName.get(tool.name);\n if (existingIndex == null) {\n indexByName.set(tool.name, orderedTools.length);\n orderedTools.push(tool);\n continue;\n }\n orderedTools[existingIndex] = tool;\n }\n\n return orderedTools;\n}\n\nexport function resolveLocalToolsForBinding(args: {\n tools?: t.GraphTools;\n toolExecution?: t.ToolExecutionConfig;\n}): t.GraphTools | undefined {\n if (!shouldUseLocalExecution(args.toolExecution)) {\n return args.tools;\n }\n\n const localConfig = args.toolExecution?.local ?? {};\n if (shouldIncludeCodingTools(args.toolExecution)) {\n return mergeToolsByName(args.tools, createLocalCodingTools(localConfig));\n }\n\n const replacements = ((args.tools as t.GenericTool[] | undefined) ?? [])\n .filter(\n (existingTool): existingTool is t.GenericTool & { name: string } =>\n 'name' in existingTool &&\n typeof existingTool.name === 'string' &&\n CODE_EXECUTION_TOOLS.has(existingTool.name)\n )\n .map((existingTool) =>\n createLocalExecutionTool(existingTool.name, localConfig)\n )\n .filter((localTool): localTool is t.GenericTool => localTool != null);\n\n return replacements.length === 0\n ? args.tools\n : mergeToolsByName(args.tools, replacements);\n}\n\nexport function resolveLocalToolRegistry(args: {\n toolRegistry?: t.LCToolRegistry;\n toolExecution?: t.ToolExecutionConfig;\n}): t.LCToolRegistry | undefined {\n if (!shouldIncludeCodingTools(args.toolExecution)) {\n return args.toolRegistry;\n }\n\n const registry = new Map(args.toolRegistry ?? []);\n for (const definition of createLocalCodingToolDefinitions()) {\n registry.set(definition.name, definition);\n }\n return registry;\n}\n\nexport function resolveLocalExecutionTools(args: {\n toolMap: t.ToolMap;\n toolExecution?: t.ToolExecutionConfig;\n /**\n * Caller-provided checkpointer that overrides the bundle's\n * auto-created one. The Graph layer threads a single per-Run\n * instance so every ToolNode it compiles shares one snapshot\n * store — without that, a multi-agent graph would each get a\n * private checkpointer and `Run.rewindFiles()` couldn't reach\n * any of them.\n */\n fileCheckpointer?: t.LocalFileCheckpointer;\n}): ResolveLocalToolsResult {\n const directToolNames = new Set<string>();\n if (!shouldUseLocalExecution(args.toolExecution)) {\n return {\n toolMap: args.toolMap,\n directToolNames,\n };\n }\n\n const localConfig = args.toolExecution?.local ?? {};\n const toolMap = new Map(args.toolMap);\n let fileCheckpointer: t.LocalFileCheckpointer | undefined;\n\n if (shouldIncludeCodingTools(args.toolExecution)) {\n // Use the bundle factory when fileCheckpointing is on so we can\n // surface the checkpointer back to the caller — without this, the\n // execution-path tools each captured into a checkpointer that was\n // immediately discarded, making the public `fileCheckpointing`\n // config flag a silent no-op outside of direct\n // `createLocalCodingToolBundle()` use.\n if (localConfig.fileCheckpointing === true || args.fileCheckpointer != null) {\n const bundle = createLocalCodingToolBundle(localConfig, {\n checkpointer: args.fileCheckpointer,\n });\n fileCheckpointer = bundle.checkpointer;\n for (const localTool of bundle.tools) {\n toolMap.set(localTool.name, localTool);\n directToolNames.add(localTool.name);\n }\n } else {\n for (const localTool of createLocalCodingTools(localConfig)) {\n toolMap.set(localTool.name, localTool);\n directToolNames.add(localTool.name);\n }\n }\n }\n\n // When the coding-tool bundle was already installed above, it\n // already created `bash_tool` / `execute_code` / programmatic-tool\n // variants. Skip re-creating them here — the audit-of-audit (manual\n // finding #4) flagged that the original loop overwrote those bundle\n // instances with fresh ones via `createLocalExecutionTool`, wasting\n // work and (more importantly) replacing tools the bundle had\n // already wired up with shared state. The CODE_EXECUTION_TOOLS\n // loop is now only relevant when the host pre-bound a tool with\n // one of these names (the `toolMap.has(name)` branch) and coding\n // tools are off.\n const includeCodingTools = shouldIncludeCodingTools(args.toolExecution);\n for (const name of CODE_EXECUTION_TOOLS) {\n if (includeCodingTools) continue;\n if (!toolMap.has(name)) continue;\n\n const localTool = createLocalExecutionTool(name, localConfig);\n if (localTool == null) {\n continue;\n }\n\n toolMap.set(name, localTool);\n directToolNames.add(name);\n }\n\n return { toolMap, directToolNames, fileCheckpointer };\n}\n"],"names":["Constants","createLocalCodeExecutionTool","createLocalBashExecutionTool","createLocalProgrammaticToolCallingTool","createLocalBashProgrammaticToolCallingTool","createLocalCodingTools","CODE_EXECUTION_TOOLS","createLocalCodingToolDefinitions","createLocalCodingToolBundle"],"mappings":";;;;;;;AAgCA,SAAS,uBAAuB,CAAC,MAA8B,EAAA;AAC7D,IAAA,OAAO,MAAM,EAAE,MAAM,KAAK,OAAO;AACnC;AAEA,SAAS,wBAAwB,CAAC,MAA8B,EAAA;AAC9D,IAAA,QACE,uBAAuB,CAAC,MAAM,CAAC;AAC/B,QAAA,MAAM,EAAE,KAAK,EAAE,kBAAkB,KAAK,KAAK;AAE/C;AAEA,SAAS,wBAAwB,CAC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C,0BAAoB,EAAE;AACvC,QAAA,IAAI,kBAAkB;YAAE;AACxB,QAAA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE;QAExB,MAAM,SAAS,GAAG,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAC;AAC7D,QAAA,IAAI,SAAS,IAAI,IAAI,EAAE;YACrB;QACF;AAEA,QAAA,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC;AAC5B,QAAA,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;IAC3B;AAEA,IAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE;AACvD;;;;;;"}
1
+ {"version":3,"file":"resolveLocalExecutionTools.cjs","sources":["../../../../src/tools/local/resolveLocalExecutionTools.ts"],"sourcesContent":["import {\n Constants,\n CODE_EXECUTION_TOOLS,\n LOCAL_CODING_BUNDLE_NAMES,\n} from '@/common';\nimport {\n createLocalBashExecutionTool,\n createLocalCodeExecutionTool,\n} from './LocalExecutionTools';\nimport {\n createLocalCodingToolBundle,\n createLocalCodingToolDefinitions,\n createLocalCodingTools,\n} from './LocalCodingTools';\nimport {\n createLocalBashProgrammaticToolCallingTool,\n createLocalProgrammaticToolCallingTool,\n} from './LocalProgrammaticToolCalling';\nimport {\n createCloudflareCodingToolBundle,\n createCloudflareCodingTools,\n createCloudflareExecutionTool,\n} from '@/tools/cloudflare';\nimport type * as t from '@/types';\n\ntype ResolveLocalToolsResult = {\n toolMap: t.ToolMap;\n directToolNames: Set<string>;\n /**\n * Set when `local.fileCheckpointing === true` AND the auto-bind\n * coding suite is in use. ToolNode stashes this on the node and\n * exposes it via `getFileCheckpointer()` so the host can call\n * `rewind()` after a failed batch. Manual review (finding E)\n * flagged that the config flag was previously a no-op in the\n * Run/ToolNode auto-bind path — only direct\n * `createLocalCodingToolBundle()` callers could access the\n * checkpointer.\n */\n fileCheckpointer?: t.LocalFileCheckpointer;\n};\n\nfunction shouldUseLocalExecution(config?: t.ToolExecutionConfig): boolean {\n return config?.engine === 'local';\n}\n\nfunction shouldUseCloudflareSandboxExecution(\n config?: t.ToolExecutionConfig\n): boolean {\n return config?.engine === 'cloudflare-sandbox';\n}\n\nfunction shouldIncludeCodingTools(config?: t.ToolExecutionConfig): boolean {\n return (\n (shouldUseLocalExecution(config) &&\n config?.local?.includeCodingTools !== false) ||\n (shouldUseCloudflareSandboxExecution(config) &&\n config?.cloudflare?.includeCodingTools !== false)\n );\n}\n\nfunction getCloudflareConfig(\n config?: t.ToolExecutionConfig\n): t.CloudflareSandboxExecutionConfig {\n if (config?.cloudflare == null) {\n throw new Error(\n 'toolExecution.cloudflare is required when engine is \"cloudflare-sandbox\".'\n );\n }\n return config.cloudflare;\n}\n\nfunction getSelectedCloudflareCodingToolNames(\n config: t.CloudflareSandboxExecutionConfig\n): Set<string> {\n return new Set(config.codingToolNames ?? LOCAL_CODING_BUNDLE_NAMES);\n}\n\nfunction filterCloudflareCodingToolAllowlist(\n tools: t.GraphTools | undefined,\n selectedNames: Set<string>\n): t.GraphTools | undefined {\n const existingTools = (tools as t.GenericTool[] | undefined) ?? [];\n if (existingTools.length === 0) {\n return tools;\n }\n return existingTools.filter((existingTool) => {\n if (!('name' in existingTool) || typeof existingTool.name !== 'string') {\n return true;\n }\n return (\n !LOCAL_CODING_BUNDLE_NAMES.includes(existingTool.name) ||\n selectedNames.has(existingTool.name)\n );\n });\n}\n\nfunction pruneCloudflareCodingToolAllowlist(\n toolMap: t.ToolMap,\n selectedNames: Set<string>\n): void {\n for (const name of LOCAL_CODING_BUNDLE_NAMES) {\n if (!selectedNames.has(name)) {\n toolMap.delete(name);\n }\n }\n}\n\nfunction createLocalExecutionTool(\n name: string,\n config: t.LocalExecutionConfig\n): t.GenericTool | undefined {\n switch (name) {\n case Constants.EXECUTE_CODE:\n return createLocalCodeExecutionTool(config);\n case Constants.BASH_TOOL:\n return createLocalBashExecutionTool({ config });\n case Constants.PROGRAMMATIC_TOOL_CALLING:\n return createLocalProgrammaticToolCallingTool(config);\n case Constants.BASH_PROGRAMMATIC_TOOL_CALLING:\n return createLocalBashProgrammaticToolCallingTool(config);\n default:\n return undefined;\n }\n}\n\nfunction mergeToolsByName(\n baseTools: t.GraphTools | undefined,\n localTools: t.GenericTool[]\n): t.GraphTools {\n const orderedTools: t.GenericTool[] = [];\n const indexByName = new Map<string, number>();\n\n for (const tool of (baseTools as t.GenericTool[] | undefined) ?? []) {\n if ('name' in tool && typeof tool.name === 'string') {\n indexByName.set(tool.name, orderedTools.length);\n }\n orderedTools.push(tool);\n }\n\n for (const tool of localTools) {\n const existingIndex = indexByName.get(tool.name);\n if (existingIndex == null) {\n indexByName.set(tool.name, orderedTools.length);\n orderedTools.push(tool);\n continue;\n }\n orderedTools[existingIndex] = tool;\n }\n\n return orderedTools;\n}\n\nexport function resolveLocalToolsForBinding(args: {\n tools?: t.GraphTools;\n toolExecution?: t.ToolExecutionConfig;\n}): t.GraphTools | undefined {\n if (\n !shouldUseLocalExecution(args.toolExecution) &&\n !shouldUseCloudflareSandboxExecution(args.toolExecution)\n ) {\n return args.tools;\n }\n\n if (shouldUseCloudflareSandboxExecution(args.toolExecution)) {\n const cloudflareConfig = getCloudflareConfig(args.toolExecution);\n if (shouldIncludeCodingTools(args.toolExecution)) {\n const selectedNames =\n getSelectedCloudflareCodingToolNames(cloudflareConfig);\n return mergeToolsByName(\n filterCloudflareCodingToolAllowlist(args.tools, selectedNames),\n createCloudflareCodingTools(cloudflareConfig)\n );\n }\n\n const replacements = ((args.tools as t.GenericTool[] | undefined) ?? [])\n .filter(\n (existingTool): existingTool is t.GenericTool & { name: string } =>\n 'name' in existingTool &&\n typeof existingTool.name === 'string' &&\n CODE_EXECUTION_TOOLS.has(existingTool.name)\n )\n .map((existingTool) =>\n createCloudflareExecutionTool(existingTool.name, cloudflareConfig)\n )\n .filter(\n (cloudflareTool): cloudflareTool is t.GenericTool =>\n cloudflareTool != null\n );\n\n return replacements.length === 0\n ? args.tools\n : mergeToolsByName(args.tools, replacements);\n }\n\n const localConfig = args.toolExecution?.local ?? {};\n if (shouldIncludeCodingTools(args.toolExecution)) {\n return mergeToolsByName(args.tools, createLocalCodingTools(localConfig));\n }\n\n const replacements = ((args.tools as t.GenericTool[] | undefined) ?? [])\n .filter(\n (existingTool): existingTool is t.GenericTool & { name: string } =>\n 'name' in existingTool &&\n typeof existingTool.name === 'string' &&\n CODE_EXECUTION_TOOLS.has(existingTool.name)\n )\n .map((existingTool) =>\n createLocalExecutionTool(existingTool.name, localConfig)\n )\n .filter((localTool): localTool is t.GenericTool => localTool != null);\n\n return replacements.length === 0\n ? args.tools\n : mergeToolsByName(args.tools, replacements);\n}\n\nexport function resolveLocalToolRegistry(args: {\n toolRegistry?: t.LCToolRegistry;\n toolExecution?: t.ToolExecutionConfig;\n}): t.LCToolRegistry | undefined {\n if (!shouldIncludeCodingTools(args.toolExecution)) {\n return args.toolRegistry;\n }\n\n const registry = new Map(args.toolRegistry ?? []);\n const selectedNames = shouldUseCloudflareSandboxExecution(args.toolExecution)\n ? getSelectedCloudflareCodingToolNames(\n getCloudflareConfig(args.toolExecution)\n )\n : undefined;\n for (const definition of createLocalCodingToolDefinitions()) {\n if (selectedNames != null && !selectedNames.has(definition.name)) {\n registry.delete(definition.name);\n continue;\n }\n registry.set(definition.name, definition);\n }\n return registry;\n}\n\nexport function resolveLocalExecutionTools(args: {\n toolMap: t.ToolMap;\n toolExecution?: t.ToolExecutionConfig;\n /**\n * Caller-provided checkpointer that overrides the bundle's\n * auto-created one. The Graph layer threads a single per-Run\n * instance so every ToolNode it compiles shares one snapshot\n * store — without that, a multi-agent graph would each get a\n * private checkpointer and `Run.rewindFiles()` couldn't reach\n * any of them.\n */\n fileCheckpointer?: t.LocalFileCheckpointer;\n}): ResolveLocalToolsResult {\n const directToolNames = new Set<string>();\n if (\n !shouldUseLocalExecution(args.toolExecution) &&\n !shouldUseCloudflareSandboxExecution(args.toolExecution)\n ) {\n return {\n toolMap: args.toolMap,\n directToolNames,\n };\n }\n\n const toolMap = new Map(args.toolMap);\n let fileCheckpointer: t.LocalFileCheckpointer | undefined;\n\n if (shouldUseCloudflareSandboxExecution(args.toolExecution)) {\n const cloudflareConfig = getCloudflareConfig(args.toolExecution);\n if (shouldIncludeCodingTools(args.toolExecution)) {\n const selectedNames =\n getSelectedCloudflareCodingToolNames(cloudflareConfig);\n pruneCloudflareCodingToolAllowlist(toolMap, selectedNames);\n if (\n cloudflareConfig.fileCheckpointing === true ||\n args.fileCheckpointer != null\n ) {\n const bundle = createCloudflareCodingToolBundle(cloudflareConfig, {\n checkpointer: args.fileCheckpointer,\n });\n fileCheckpointer = bundle.checkpointer;\n for (const cloudflareTool of bundle.tools) {\n toolMap.set(cloudflareTool.name, cloudflareTool);\n directToolNames.add(cloudflareTool.name);\n }\n } else {\n for (const cloudflareTool of createCloudflareCodingTools(\n cloudflareConfig\n )) {\n toolMap.set(cloudflareTool.name, cloudflareTool);\n directToolNames.add(cloudflareTool.name);\n }\n }\n }\n\n const includeCodingTools = shouldIncludeCodingTools(args.toolExecution);\n for (const name of CODE_EXECUTION_TOOLS) {\n if (includeCodingTools) continue;\n if (!toolMap.has(name)) continue;\n\n const cloudflareTool = createCloudflareExecutionTool(\n name,\n cloudflareConfig\n );\n if (cloudflareTool == null) {\n continue;\n }\n\n toolMap.set(name, cloudflareTool);\n directToolNames.add(name);\n }\n\n return { toolMap, directToolNames, fileCheckpointer };\n }\n\n const localConfig = args.toolExecution?.local ?? {};\n\n if (shouldIncludeCodingTools(args.toolExecution)) {\n // Use the bundle factory when fileCheckpointing is on so we can\n // surface the checkpointer back to the caller — without this, the\n // execution-path tools each captured into a checkpointer that was\n // immediately discarded, making the public `fileCheckpointing`\n // config flag a silent no-op outside of direct\n // `createLocalCodingToolBundle()` use.\n if (\n localConfig.fileCheckpointing === true ||\n args.fileCheckpointer != null\n ) {\n const bundle = createLocalCodingToolBundle(localConfig, {\n checkpointer: args.fileCheckpointer,\n });\n fileCheckpointer = bundle.checkpointer;\n for (const localTool of bundle.tools) {\n toolMap.set(localTool.name, localTool);\n directToolNames.add(localTool.name);\n }\n } else {\n for (const localTool of createLocalCodingTools(localConfig)) {\n toolMap.set(localTool.name, localTool);\n directToolNames.add(localTool.name);\n }\n }\n }\n\n // When the coding-tool bundle was already installed above, it\n // already created `bash_tool` / `execute_code` / programmatic-tool\n // variants. Skip re-creating them here — the audit-of-audit (manual\n // finding #4) flagged that the original loop overwrote those bundle\n // instances with fresh ones via `createLocalExecutionTool`, wasting\n // work and (more importantly) replacing tools the bundle had\n // already wired up with shared state. The CODE_EXECUTION_TOOLS\n // loop is now only relevant when the host pre-bound a tool with\n // one of these names (the `toolMap.has(name)` branch) and coding\n // tools are off.\n const includeCodingTools = shouldIncludeCodingTools(args.toolExecution);\n for (const name of CODE_EXECUTION_TOOLS) {\n if (includeCodingTools) continue;\n if (!toolMap.has(name)) continue;\n\n const localTool = createLocalExecutionTool(name, localConfig);\n if (localTool == null) {\n continue;\n }\n\n toolMap.set(name, localTool);\n directToolNames.add(name);\n }\n\n return { toolMap, directToolNames, fileCheckpointer };\n}\n"],"names":["LOCAL_CODING_BUNDLE_NAMES","Constants","createLocalCodeExecutionTool","createLocalBashExecutionTool","createLocalProgrammaticToolCallingTool","createLocalBashProgrammaticToolCallingTool","createCloudflareCodingTools","CODE_EXECUTION_TOOLS","createCloudflareExecutionTool","createLocalCodingTools","createLocalCodingToolDefinitions","createCloudflareCodingToolBundle","createLocalCodingToolBundle"],"mappings":";;;;;;;;;;;;;AAyCA,SAAS,uBAAuB,CAAC,MAA8B,EAAA;AAC7D,IAAA,OAAO,MAAM,EAAE,MAAM,KAAK,OAAO;AACnC;AAEA,SAAS,mCAAmC,CAC1C,MAA8B,EAAA;AAE9B,IAAA,OAAO,MAAM,EAAE,MAAM,KAAK,oBAAoB;AAChD;AAEA,SAAS,wBAAwB,CAAC,MAA8B,EAAA;AAC9D,IAAA,QACE,CAAC,uBAAuB,CAAC,MAAM,CAAC;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AAA,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC;YACrC;QACF;aAAO;YACL,KAAK,MAAM,SAAS,IAAIH,uCAAsB,CAAC,WAAW,CAAC,EAAE;gBAC3D,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC;AACtC,gBAAA,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC;YACrC;QACF;IACF;;;;;;;;;;;IAYA,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,IAAI,CAAC,aAAa,CAAC;AACvE,IAAA,KAAK,MAAM,IAAI,IAAIF,0BAAoB,EAAE;AACvC,QAAA,IAAI,kBAAkB;YAAE;AACxB,QAAA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE;QAExB,MAAM,SAAS,GAAG,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAC;AAC7D,QAAA,IAAI,SAAS,IAAI,IAAI,EAAE;YACrB;QACF;AAEA,QAAA,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC;AAC5B,QAAA,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;IAC3B;AAEA,IAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE;AACvD;;;;;;"}
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var manager = require('@langchain/core/callbacks/manager');
4
+
5
+ function appendCallbacks(callbacks, additions) {
6
+ if (additions.length === 0) {
7
+ return callbacks ?? [];
8
+ }
9
+ if (callbacks == null) {
10
+ return [...additions];
11
+ }
12
+ if (Array.isArray(callbacks)) {
13
+ return callbacks.concat(additions);
14
+ }
15
+ return callbacks.copy(additions.map(manager.ensureHandler));
16
+ }
17
+ function findCallback(callbacks, predicate) {
18
+ if (callbacks == null) {
19
+ return undefined;
20
+ }
21
+ const handlers = Array.isArray(callbacks) ? callbacks : callbacks.handlers;
22
+ return handlers.find(predicate);
23
+ }
24
+
25
+ exports.appendCallbacks = appendCallbacks;
26
+ exports.findCallback = findCallback;
27
+ //# sourceMappingURL=callbacks.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callbacks.cjs","sources":["../../../src/utils/callbacks.ts"],"sourcesContent":["import { ensureHandler } from '@langchain/core/callbacks/manager';\nimport type {\n BaseCallbackHandler,\n CallbackHandlerMethods,\n} from '@langchain/core/callbacks/base';\nimport type { Callbacks } from '@langchain/core/callbacks/manager';\n\nexport type CallbackEntry = BaseCallbackHandler | CallbackHandlerMethods;\n\nexport function appendCallbacks(\n callbacks: Callbacks | undefined,\n additions: readonly CallbackEntry[]\n): Callbacks {\n if (additions.length === 0) {\n return callbacks ?? [];\n }\n\n if (callbacks == null) {\n return [...additions];\n }\n\n if (Array.isArray(callbacks)) {\n return callbacks.concat(additions);\n }\n\n return callbacks.copy(additions.map(ensureHandler));\n}\n\nexport function findCallback(\n callbacks: Callbacks | undefined,\n predicate: (callback: CallbackEntry) => boolean\n): CallbackEntry | undefined {\n if (callbacks == null) {\n return undefined;\n }\n\n const handlers = Array.isArray(callbacks) ? callbacks : callbacks.handlers;\n return handlers.find(predicate);\n}\n"],"names":["ensureHandler"],"mappings":";;;;AASM,SAAU,eAAe,CAC7B,SAAgC,EAChC,SAAmC,EAAA;AAEnC,IAAA,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QAC1B,OAAO,SAAS,IAAI,EAAE;IACxB;AAEA,IAAA,IAAI,SAAS,IAAI,IAAI,EAAE;AACrB,QAAA,OAAO,CAAC,GAAG,SAAS,CAAC;IACvB;AAEA,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;AAC5B,QAAA,OAAO,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC;IACpC;IAEA,OAAO,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAACA,qBAAa,CAAC,CAAC;AACrD;AAEM,SAAU,YAAY,CAC1B,SAAgC,EAChC,SAA+C,EAAA;AAE/C,IAAA,IAAI,SAAS,IAAI,IAAI,EAAE;AACrB,QAAA,OAAO,SAAS;IAClB;AAEA,IAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS,CAAC,QAAQ;AAC1E,IAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AACjC;;;;;"}
@@ -20,12 +20,13 @@ class AgentContext {
20
20
  * Create an AgentContext from configuration with token accounting initialization
21
21
  */
22
22
  static fromConfig(agentConfig, tokenCounter, indexTokenCountMap) {
23
- const { agentId, name, provider, clientOptions, tools, toolMap, toolEnd, toolRegistry, toolDefinitions, instructions, additional_instructions, streamBuffer, maxContextTokens, reasoningKey, useLegacyContent, discoveredTools, summarizationEnabled, summarizationConfig, initialSummary, contextPruningConfig, maxToolResultChars, toolSchemaTokens, subagentConfigs, maxSubagentDepth, } = agentConfig;
23
+ const { agentId, name, provider, clientOptions, langfuse, tools, toolMap, toolEnd, toolRegistry, toolDefinitions, instructions, additional_instructions, streamBuffer, maxContextTokens, reasoningKey, useLegacyContent, discoveredTools, summarizationEnabled, summarizationConfig, initialSummary, contextPruningConfig, maxToolResultChars, toolSchemaTokens, subagentConfigs, maxSubagentDepth, } = agentConfig;
24
24
  const agentContext = new AgentContext({
25
25
  agentId,
26
26
  name: name ?? agentId,
27
27
  provider,
28
28
  clientOptions,
29
+ langfuse,
29
30
  maxContextTokens,
30
31
  streamBuffer,
31
32
  tools,
@@ -87,6 +88,8 @@ class AgentContext {
87
88
  provider;
88
89
  /** Client options for this agent */
89
90
  clientOptions;
91
+ /** Per-agent Langfuse tracing configuration. */
92
+ langfuse;
90
93
  /** Token count map indexed by message position */
91
94
  indexTokenCountMap = {};
92
95
  /** Canonical pre-run token map used to restore token accounting on reset */
@@ -221,11 +224,12 @@ class AgentContext {
221
224
  * Contains source and parallel execution info for system message context.
222
225
  */
223
226
  handoffContext;
224
- constructor({ agentId, name, provider, clientOptions, maxContextTokens, streamBuffer, tokenCounter, tools, toolMap, toolRegistry, toolDefinitions, instructions, additionalInstructions, reasoningKey, toolEnd, instructionTokens, useLegacyContent, discoveredTools, summarizationEnabled, summarizationConfig, contextPruningConfig, maxToolResultChars, }) {
227
+ constructor({ agentId, name, provider, clientOptions, langfuse, maxContextTokens, streamBuffer, tokenCounter, tools, toolMap, toolRegistry, toolDefinitions, instructions, additionalInstructions, reasoningKey, toolEnd, instructionTokens, useLegacyContent, discoveredTools, summarizationEnabled, summarizationConfig, contextPruningConfig, maxToolResultChars, }) {
225
228
  this.agentId = agentId;
226
229
  this.name = name;
227
230
  this.provider = provider;
228
231
  this.clientOptions = clientOptions;
232
+ this.langfuse = langfuse;
229
233
  this.maxContextTokens = maxContextTokens;
230
234
  this.streamBuffer = streamBuffer;
231
235
  this.tokenCounter = tokenCounter;
@@ -313,12 +317,12 @@ class AgentContext {
313
317
  return { name: Constants.BASH_PROGRAMMATIC_TOOL_CALLING, language: 'bash' };
314
318
  }
315
319
  hasAvailableTool(name) {
316
- if (this.toolDefinitions?.some((tool) => tool.name === name))
320
+ if (this.toolDefinitions?.some((tool) => tool.name === name) === true)
317
321
  return true;
318
- if (this.tools?.some((tool) => 'name' in tool && tool.name === name)) {
322
+ if (this.tools?.some((tool) => 'name' in tool && tool.name === name) === true) {
319
323
  return true;
320
324
  }
321
- if (this.toolMap?.has(name))
325
+ if (this.toolMap?.has(name) === true)
322
326
  return true;
323
327
  return this.toolRegistry?.has(name) === true;
324
328
  }