@librechat/agents 4.2.12 → 4.2.13

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 (280) hide show
  1. package/dist/cjs/graphs/Graph.cjs +11 -3
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/llm/anthropic/index.cjs +4 -3
  4. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  5. package/dist/cjs/llm/anthropic/utils/container.cjs +37 -0
  6. package/dist/cjs/llm/anthropic/utils/container.cjs.map +1 -0
  7. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +25 -23
  8. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  9. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +15 -21
  10. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  11. package/dist/cjs/llm/anthropic/utils/stream_events.cjs +16 -14
  12. package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
  13. package/dist/cjs/llm/bedrock/index.cjs +1 -1
  14. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  15. package/dist/cjs/llm/bedrock/toolCache.cjs +1 -1
  16. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +19 -13
  17. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
  18. package/dist/cjs/llm/google/utils/common.cjs +59 -13
  19. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  20. package/dist/cjs/llm/init.cjs +12 -2
  21. package/dist/cjs/llm/init.cjs.map +1 -1
  22. package/dist/cjs/llm/openai/index.cjs +1 -1
  23. package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
  24. package/dist/cjs/llm/prepareProviderRequest.cjs +1 -1
  25. package/dist/cjs/main.cjs +6 -3
  26. package/dist/cjs/messages/alternation.cjs +1 -1
  27. package/dist/cjs/messages/anthropicServerTools.cjs +20 -0
  28. package/dist/cjs/messages/anthropicServerTools.cjs.map +1 -0
  29. package/dist/cjs/messages/budget.cjs +1 -1
  30. package/dist/cjs/messages/core.cjs +3 -2
  31. package/dist/cjs/messages/core.cjs.map +1 -1
  32. package/dist/cjs/messages/format.cjs +2 -2
  33. package/dist/cjs/messages/index.cjs +1 -1
  34. package/dist/cjs/messages/prune.cjs +1 -1
  35. package/dist/cjs/messages/recency.cjs +1 -1
  36. package/dist/cjs/messages/toolResultTypes.cjs +21 -45
  37. package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
  38. package/dist/cjs/protection/providerText.cjs +4 -0
  39. package/dist/cjs/protection/providerText.cjs.map +1 -1
  40. package/dist/cjs/protection/toolResult.cjs +119 -0
  41. package/dist/cjs/protection/toolResult.cjs.map +1 -0
  42. package/dist/cjs/run.cjs +7 -1
  43. package/dist/cjs/run.cjs.map +1 -1
  44. package/dist/cjs/runtime/client.cjs +2 -0
  45. package/dist/cjs/runtime/client.cjs.map +1 -1
  46. package/dist/cjs/stream.cjs +1 -0
  47. package/dist/cjs/stream.cjs.map +1 -1
  48. package/dist/cjs/summarization/node.cjs +1 -1
  49. package/dist/cjs/tools/ToolNode.cjs +46 -13
  50. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  51. package/dist/cjs/tools/search/content.cjs +163 -42
  52. package/dist/cjs/tools/search/content.cjs.map +1 -1
  53. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +4 -0
  54. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  55. package/dist/cjs/utils/tokens.cjs +7 -2
  56. package/dist/cjs/utils/tokens.cjs.map +1 -1
  57. package/dist/esm/graphs/Graph.mjs +11 -3
  58. package/dist/esm/graphs/Graph.mjs.map +1 -1
  59. package/dist/esm/llm/anthropic/index.mjs +4 -3
  60. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  61. package/dist/esm/llm/anthropic/utils/container.mjs +37 -0
  62. package/dist/esm/llm/anthropic/utils/container.mjs.map +1 -0
  63. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +25 -23
  64. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  65. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +15 -21
  66. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  67. package/dist/esm/llm/anthropic/utils/stream_events.mjs +16 -14
  68. package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
  69. package/dist/esm/llm/bedrock/index.mjs +2 -2
  70. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  71. package/dist/esm/llm/bedrock/toolCache.mjs +1 -1
  72. package/dist/esm/llm/bedrock/utils/message_inputs.mjs +19 -14
  73. package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
  74. package/dist/esm/llm/google/utils/common.mjs +59 -13
  75. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  76. package/dist/esm/llm/init.mjs +12 -2
  77. package/dist/esm/llm/init.mjs.map +1 -1
  78. package/dist/esm/llm/openai/index.mjs +1 -1
  79. package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
  80. package/dist/esm/llm/prepareProviderRequest.mjs +1 -1
  81. package/dist/esm/main.mjs +5 -4
  82. package/dist/esm/messages/alternation.mjs +1 -1
  83. package/dist/esm/messages/anthropicServerTools.mjs +18 -0
  84. package/dist/esm/messages/anthropicServerTools.mjs.map +1 -0
  85. package/dist/esm/messages/budget.mjs +1 -1
  86. package/dist/esm/messages/core.mjs +3 -2
  87. package/dist/esm/messages/core.mjs.map +1 -1
  88. package/dist/esm/messages/format.mjs +2 -2
  89. package/dist/esm/messages/index.mjs +1 -1
  90. package/dist/esm/messages/prune.mjs +1 -1
  91. package/dist/esm/messages/recency.mjs +1 -1
  92. package/dist/esm/messages/toolResultTypes.mjs +21 -45
  93. package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
  94. package/dist/esm/protection/providerText.mjs +4 -1
  95. package/dist/esm/protection/providerText.mjs.map +1 -1
  96. package/dist/esm/protection/toolResult.mjs +114 -0
  97. package/dist/esm/protection/toolResult.mjs.map +1 -0
  98. package/dist/esm/run.mjs +7 -1
  99. package/dist/esm/run.mjs.map +1 -1
  100. package/dist/esm/runtime/client.mjs +2 -0
  101. package/dist/esm/runtime/client.mjs.map +1 -1
  102. package/dist/esm/stream.mjs +1 -0
  103. package/dist/esm/stream.mjs.map +1 -1
  104. package/dist/esm/summarization/node.mjs +1 -1
  105. package/dist/esm/tools/ToolNode.mjs +46 -13
  106. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  107. package/dist/esm/tools/search/content.mjs +163 -42
  108. package/dist/esm/tools/search/content.mjs.map +1 -1
  109. package/dist/esm/tools/subagent/SubagentExecutor.mjs +4 -0
  110. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  111. package/dist/esm/utils/tokens.mjs +7 -2
  112. package/dist/esm/utils/tokens.mjs.map +1 -1
  113. package/dist/types/common/index.d.ts +2 -2
  114. package/dist/types/decisions/breaker.d.ts +2 -2
  115. package/dist/types/decisions/core.d.ts +13 -13
  116. package/dist/types/decisions/dialect.d.ts +1 -1
  117. package/dist/types/decisions/http.d.ts +2 -2
  118. package/dist/types/decisions/index.d.ts +5 -5
  119. package/dist/types/decisions/node.d.ts +2 -2
  120. package/dist/types/decisions/presets.d.ts +2 -2
  121. package/dist/types/decisions/probe.d.ts +1 -1
  122. package/dist/types/decisions/questions.d.ts +1 -1
  123. package/dist/types/decisions/structuredChat.d.ts +2 -2
  124. package/dist/types/decisions/transport.d.ts +1 -1
  125. package/dist/types/eventActor/EventActorExecutor.d.ts +1 -1
  126. package/dist/types/eventActor/index.d.ts +2 -2
  127. package/dist/types/graphs/Graph.d.ts +4 -2
  128. package/dist/types/graphs/MultiAgentGraph.d.ts +1 -1
  129. package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +1 -1
  130. package/dist/types/graphs/graphFactory.d.ts +1 -1
  131. package/dist/types/graphs/index.d.ts +5 -5
  132. package/dist/types/harness/fileBindings.d.ts +2 -2
  133. package/dist/types/harness/fileService.d.ts +2 -2
  134. package/dist/types/harness/fileStream.d.ts +1 -1
  135. package/dist/types/harness/index.d.ts +15 -15
  136. package/dist/types/harness/model.d.ts +1 -1
  137. package/dist/types/harness/modelService.d.ts +2 -2
  138. package/dist/types/harness/modelStreamCallbacks.d.ts +1 -1
  139. package/dist/types/harness/providerText.d.ts +1 -1
  140. package/dist/types/hitl/index.d.ts +3 -3
  141. package/dist/types/hooks/HookRegistry.d.ts +1 -1
  142. package/dist/types/hooks/createToolPolicyHook.d.ts +1 -1
  143. package/dist/types/hooks/createWorkspacePolicyHook.d.ts +1 -1
  144. package/dist/types/hooks/executeHooks.d.ts +2 -2
  145. package/dist/types/hooks/index.d.ts +11 -11
  146. package/dist/types/index.d.ts +62 -60
  147. package/dist/types/langchain/index.d.ts +8 -8
  148. package/dist/types/llm/anthropic/utils/container.d.ts +4 -0
  149. package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
  150. package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
  151. package/dist/types/llm/anthropic/utils/stream_events.d.ts +1 -1
  152. package/dist/types/llm/bedrock/index.d.ts +2 -3
  153. package/dist/types/llm/bedrock/utils/harmony.d.ts +1 -1
  154. package/dist/types/llm/bedrock/utils/index.d.ts +2 -2
  155. package/dist/types/llm/bedrock/utils/message_inputs.d.ts +3 -12
  156. package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
  157. package/dist/types/llm/google/index.d.ts +2 -2
  158. package/dist/types/llm/google/utils/common.d.ts +1 -1
  159. package/dist/types/llm/google/utils/tools.d.ts +1 -1
  160. package/dist/types/llm/openai/index.d.ts +1 -1
  161. package/dist/types/llm/providerRegistry.d.ts +1 -1
  162. package/dist/types/llm/providers.d.ts +1 -1
  163. package/dist/types/messages/anthropicServerTools.d.ts +13 -0
  164. package/dist/types/messages/contextPruning.d.ts +1 -1
  165. package/dist/types/messages/core.d.ts +4 -4
  166. package/dist/types/messages/format.d.ts +1 -1
  167. package/dist/types/messages/index.d.ts +21 -21
  168. package/dist/types/messages/prune.d.ts +1 -1
  169. package/dist/types/openai/index.d.ts +2 -2
  170. package/dist/types/openai/toolProjection.d.ts +1 -1
  171. package/dist/types/prompts/index.d.ts +2 -2
  172. package/dist/types/protection/providerText.d.ts +3 -1
  173. package/dist/types/protection/toolResult.d.ts +69 -0
  174. package/dist/types/provider-registration.d.ts +1 -1
  175. package/dist/types/rerank/bm25.d.ts +1 -1
  176. package/dist/types/rerank/core.d.ts +17 -17
  177. package/dist/types/rerank/crossEncoder.d.ts +3 -3
  178. package/dist/types/rerank/fallback.d.ts +1 -1
  179. package/dist/types/rerank/index.d.ts +2 -2
  180. package/dist/types/rerank/outcome.d.ts +2 -2
  181. package/dist/types/rerank/pin.d.ts +2 -2
  182. package/dist/types/rerank/search.d.ts +1 -1
  183. package/dist/types/rerank/systemone.d.ts +4 -4
  184. package/dist/types/rerank/types.d.ts +1 -1
  185. package/dist/types/run.d.ts +1 -0
  186. package/dist/types/runtime/admission.d.ts +1 -1
  187. package/dist/types/runtime/checkpoint.d.ts +1 -1
  188. package/dist/types/runtime/client.d.ts +2 -2
  189. package/dist/types/runtime/files.d.ts +3 -3
  190. package/dist/types/runtime/hostTools.d.ts +2 -2
  191. package/dist/types/runtime/index.d.ts +12 -12
  192. package/dist/types/runtime/model.d.ts +5 -5
  193. package/dist/types/runtime/policy.d.ts +3 -3
  194. package/dist/types/runtime/recovery/client.d.ts +3 -3
  195. package/dist/types/runtime/recovery/log.d.ts +2 -2
  196. package/dist/types/runtime/recovery/redis.d.ts +1 -1
  197. package/dist/types/runtime/recovery/server.d.ts +3 -3
  198. package/dist/types/runtime/resume.d.ts +1 -1
  199. package/dist/types/runtime/server.d.ts +3 -3
  200. package/dist/types/runtime/snapshot.d.ts +1 -1
  201. package/dist/types/runtime/types.d.ts +2 -2
  202. package/dist/types/session/AgentSession.d.ts +2 -2
  203. package/dist/types/session/JsonlSessionStore.d.ts +1 -1
  204. package/dist/types/session/deriveMessages.d.ts +1 -1
  205. package/dist/types/session/handlers.d.ts +1 -1
  206. package/dist/types/session/index.d.ts +7 -7
  207. package/dist/types/session/messageSerialization.d.ts +1 -1
  208. package/dist/types/session/sessionProjection.d.ts +3 -3
  209. package/dist/types/summarization/index.d.ts +2 -2
  210. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -1
  211. package/dist/types/tools/GitHubCompare.d.ts +6 -6
  212. package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -1
  213. package/dist/types/tools/ReadFile.d.ts +6 -6
  214. package/dist/types/tools/SkillTool.d.ts +6 -6
  215. package/dist/types/tools/ToolNode.d.ts +5 -1
  216. package/dist/types/tools/cloudflare/index.d.ts +4 -4
  217. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  218. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  219. package/dist/types/tools/local/attachments.d.ts +1 -1
  220. package/dist/types/tools/local/index.d.ts +12 -12
  221. package/dist/types/tools/search/anthropic.d.ts +1 -1
  222. package/dist/types/tools/search/content.d.ts +38 -1
  223. package/dist/types/tools/search/crw-scraper.d.ts +1 -1
  224. package/dist/types/tools/search/crw-search.d.ts +1 -1
  225. package/dist/types/tools/search/firecrawl.d.ts +1 -1
  226. package/dist/types/tools/search/format.d.ts +1 -1
  227. package/dist/types/tools/search/highlights.d.ts +1 -1
  228. package/dist/types/tools/search/index.d.ts +3 -3
  229. package/dist/types/tools/search/keenable-scraper.d.ts +1 -1
  230. package/dist/types/tools/search/keenable-search.d.ts +1 -1
  231. package/dist/types/tools/search/metrics.d.ts +1 -1
  232. package/dist/types/tools/search/rerankers.d.ts +1 -1
  233. package/dist/types/tools/search/schema.d.ts +6 -6
  234. package/dist/types/tools/search/search.d.ts +1 -1
  235. package/dist/types/tools/search/serper-scraper.d.ts +1 -1
  236. package/dist/types/tools/search/tavily-scraper.d.ts +1 -1
  237. package/dist/types/tools/search/tavily-search.d.ts +1 -1
  238. package/dist/types/tools/search/tool.d.ts +3 -3
  239. package/dist/types/tools/search/types.d.ts +2 -2
  240. package/dist/types/tools/search/utils.d.ts +3 -3
  241. package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +1 -1
  242. package/dist/types/tools/subagent/SubagentExecutor.d.ts +6 -3
  243. package/dist/types/tools/subagent/diagnostics.d.ts +1 -1
  244. package/dist/types/tools/subagent/index.d.ts +7 -7
  245. package/dist/types/types/attachments.d.ts +1 -1
  246. package/dist/types/types/graph.d.ts +4 -1
  247. package/dist/types/types/index.d.ts +14 -14
  248. package/dist/types/types/llm.d.ts +2 -2
  249. package/dist/types/types/run.d.ts +3 -1
  250. package/dist/types/types/subagentTasks.d.ts +2 -2
  251. package/dist/types/types/tools.d.ts +6 -3
  252. package/dist/types/utils/index.d.ts +10 -10
  253. package/dist/types/utils/tokens.d.ts +1 -0
  254. package/package.json +3 -2
  255. package/src/graphs/Graph.ts +22 -0
  256. package/src/index.ts +8 -0
  257. package/src/llm/anthropic/index.ts +11 -3
  258. package/src/llm/anthropic/utils/container.ts +63 -0
  259. package/src/llm/anthropic/utils/message_inputs.ts +57 -51
  260. package/src/llm/anthropic/utils/message_outputs.ts +12 -39
  261. package/src/llm/anthropic/utils/stream_events.ts +17 -12
  262. package/src/llm/bedrock/index.ts +7 -5
  263. package/src/llm/bedrock/utils/message_inputs.ts +28 -35
  264. package/src/llm/google/utils/common.ts +88 -36
  265. package/src/llm/init.ts +35 -3
  266. package/src/messages/anthropicServerTools.ts +24 -0
  267. package/src/messages/core.ts +12 -11
  268. package/src/messages/toolResultTypes.ts +80 -88
  269. package/src/protection/providerText.ts +127 -40
  270. package/src/protection/toolResult.ts +272 -0
  271. package/src/run.ts +15 -4
  272. package/src/runtime/client.ts +3 -0
  273. package/src/stream.ts +5 -0
  274. package/src/tools/ToolNode.ts +112 -17
  275. package/src/tools/search/content.ts +282 -62
  276. package/src/tools/subagent/SubagentExecutor.ts +6 -0
  277. package/src/types/graph.ts +3 -0
  278. package/src/types/run.ts +3 -0
  279. package/src/types/tools.ts +3 -0
  280. package/src/utils/tokens.ts +28 -2
@@ -50,6 +50,7 @@ import type {
50
50
  } from '@/hooks';
51
51
  import type { SettledToolBatchResult } from '@/tools/toolBatchReplay';
52
52
  import type { PreparedSubagents } from '@/tools/preparedSubagents';
53
+ import type { ToolResultGate } from '@/protection/toolResult';
53
54
  import type { RunBreakerScope } from '@/llm/streamLimits';
54
55
  import type * as t from '@/types';
55
56
  import {
@@ -114,6 +115,12 @@ import {
114
115
  isIntentLabelProperty,
115
116
  outcomeFieldsFromResult,
116
117
  } from '@/tools/intentArg';
118
+ import {
119
+ inspectToolExecuteResult,
120
+ createToolResultGate,
121
+ inspectToolOutput,
122
+ inspectToolText,
123
+ } from '@/protection/toolResult';
117
124
  import {
118
125
  snapshotResolvedArgs,
119
126
  buildReferenceKey,
@@ -310,6 +317,20 @@ function withSubagentReplayBatch(
310
317
  };
311
318
  }
312
319
 
320
+ /**
321
+ * A stream circuit breaker or protection failure raised under a tool (for
322
+ * example by a subagent's run) is a safety abort, not a tool failure to
323
+ * report back to the model. It passes through like an interrupt so the whole
324
+ * run rejects.
325
+ */
326
+ function isRunSafetyError(error: unknown): boolean {
327
+ return (
328
+ error instanceof StreamLimitExceededError ||
329
+ error instanceof PreparedSubagentError ||
330
+ error instanceof ProviderTextProtectionError
331
+ );
332
+ }
333
+
313
334
  type SettledDirectToolResult = SettledToolBatchResult;
314
335
 
315
336
  /** Positional identity is safe within the immutable full-proposal batch key. */
@@ -883,6 +904,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
883
904
  private agentLangfuse?: t.LangfuseConfig;
884
905
  toolCallStepIds?: Map<string, string>;
885
906
  errorHandler?: t.ToolNodeConstructorParams['errorHandler'];
907
+ private toolResultGate?: ToolResultGate;
886
908
  /**
887
909
  * Fallback error-completion ownership for calls that reach `runTool`
888
910
  * outside a batch context (direct `runTool` use in tests / embedders).
@@ -1053,6 +1075,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
1053
1075
  humanInTheLoop,
1054
1076
  toolOutputReferences,
1055
1077
  toolOutputRegistry,
1078
+ toolResultProtection,
1056
1079
  toolExecution,
1057
1080
  fileCheckpointer,
1058
1081
  getBreakerSignal,
@@ -1314,6 +1337,10 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
1314
1337
  this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;
1315
1338
  this.loadRuntimeTools = loadRuntimeTools;
1316
1339
  this.errorHandler = errorHandler;
1340
+ this.toolResultGate =
1341
+ toolResultProtection == null
1342
+ ? undefined
1343
+ : createToolResultGate(toolResultProtection);
1317
1344
  this.toolUsageCount = new Map<string, number>();
1318
1345
  this.toolRegistry = resolveLocalToolRegistry({
1319
1346
  toolRegistry,
@@ -1622,7 +1649,12 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
1622
1649
  this.toolRegistry?.values() ?? [],
1623
1650
  (toolDef) => isToolDefinitionActive(toolDef, discoveredToolNames)
1624
1651
  );
1652
+ const protectedToolDefs: t.LCTool[] = [];
1625
1653
  for (const toolDef of executableCapabilities.codeExecutionTools) {
1654
+ if (this.protectedResultGate(toolDef.name) != null) {
1655
+ protectedToolDefs.push({ name: toolDef.name });
1656
+ continue;
1657
+ }
1626
1658
  if (
1627
1659
  this.eventDrivenMode &&
1628
1660
  this.directToolNames?.has(toolDef.name) !== true &&
@@ -1643,7 +1675,8 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
1643
1675
  toolDefs,
1644
1676
  disallowedToolDefs: activeCapabilities.directOnlyTools
1645
1677
  .filter((toolDef) => !isProgrammaticControlTool(toolDef.name))
1646
- .map((toolDef) => ({ name: toolDef.name })),
1678
+ .map((toolDef) => ({ name: toolDef.name }))
1679
+ .concat(protectedToolDefs),
1647
1680
  };
1648
1681
  }
1649
1682
 
@@ -1788,7 +1821,8 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
1788
1821
  this.humanInTheLoop?.enabled === true ||
1789
1822
  this.hookRegistry?.hasResultAlteringHooks(runId) === true ||
1790
1823
  this.eagerEventToolExecution?.excludeToolNames?.includes(call.name) ===
1791
- true
1824
+ true ||
1825
+ this.protectedResultGate(call.name) != null
1792
1826
  ) {
1793
1827
  return;
1794
1828
  }
@@ -2111,10 +2145,20 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
2111
2145
  }
2112
2146
 
2113
2147
  this.throwIfBreakerTripped(config);
2114
- const output = await (this.preparedSubagents?.take(
2148
+ const returned = await (this.preparedSubagents?.take(
2115
2149
  this.executingAgentId ?? '',
2116
2150
  { ...call, args }
2117
2151
  ) ?? this.invokeWithRuntime(tool, invokeParams, call, config, runInput));
2152
+ const gate = this.protectedResultGate(call.name);
2153
+ const output =
2154
+ gate == null
2155
+ ? returned
2156
+ : await inspectToolOutput(
2157
+ gate,
2158
+ { name: call.name, id: call.id ?? '' },
2159
+ returned,
2160
+ config.signal
2161
+ );
2118
2162
  if (isCommand(output)) {
2119
2163
  return output;
2120
2164
  }
@@ -2195,23 +2239,32 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
2195
2239
  }),
2196
2240
  });
2197
2241
  } catch (_e: unknown) {
2198
- const e = _e as Error;
2242
+ const thrown = _e as Error;
2243
+ /** Control flow and safety aborts pass through; any other failure of a
2244
+ * protected tool is inspected before it can leave, rethrown or not. */
2245
+ const gate =
2246
+ isGraphInterrupt(thrown) || isRunSafetyError(thrown)
2247
+ ? undefined
2248
+ : this.protectedResultGate(call.name);
2249
+ const e =
2250
+ gate == null
2251
+ ? thrown
2252
+ : new Error(
2253
+ await inspectToolText(
2254
+ gate,
2255
+ { name: call.name, id: call.id ?? '' },
2256
+ typeof thrown.message === 'string' ? thrown.message : '',
2257
+ 'error',
2258
+ config.signal
2259
+ )
2260
+ );
2199
2261
  if (!this.handleToolErrors) {
2200
2262
  throw e;
2201
2263
  }
2202
2264
  if (isGraphInterrupt(e)) {
2203
2265
  throw e;
2204
2266
  }
2205
- /**
2206
- * A stream circuit breaker tripped by a child run (subagent) is a
2207
- * safety abort, not a tool failure to report back to the model. It
2208
- * passes through like an interrupt so the whole run rejects.
2209
- */
2210
- if (
2211
- e instanceof StreamLimitExceededError ||
2212
- e instanceof PreparedSubagentError ||
2213
- e instanceof ProviderTextProtectionError
2214
- ) {
2267
+ if (isRunSafetyError(e)) {
2215
2268
  throw e;
2216
2269
  }
2217
2270
  if (this.errorHandler) {
@@ -2293,6 +2346,35 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
2293
2346
  }
2294
2347
  }
2295
2348
 
2349
+ /** The gate when host result protection selects `toolName`. */
2350
+ private protectedResultGate(toolName: string): ToolResultGate | undefined {
2351
+ return this.toolResultGate?.toolNames.has(toolName) === true
2352
+ ? this.toolResultGate
2353
+ : undefined;
2354
+ }
2355
+
2356
+ private inspectHostResults(
2357
+ results: t.ToolExecuteResult[],
2358
+ requests: ReadonlyMap<string, t.ToolCallRequest>,
2359
+ config: RunnableConfig
2360
+ ): Promise<t.ToolExecuteResult[]> {
2361
+ return Promise.all(
2362
+ results.map((result) => {
2363
+ const request = requests.get(result.toolCallId);
2364
+ const gate =
2365
+ request == null ? undefined : this.protectedResultGate(request.name);
2366
+ return gate == null || request == null
2367
+ ? result
2368
+ : inspectToolExecuteResult(
2369
+ gate,
2370
+ { name: request.name, id: request.id },
2371
+ result,
2372
+ config.signal
2373
+ );
2374
+ })
2375
+ );
2376
+ }
2377
+
2296
2378
  private unresolvedReferenceMessage(
2297
2379
  call: ToolCall,
2298
2380
  resolution: Pick<ResolveResult<ToolCall['args']>, 'unresolved'>,
@@ -4512,7 +4594,8 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
4512
4594
  : undefined;
4513
4595
  if (
4514
4596
  request == null ||
4515
- earlyCompletionDispatchedIds.has(result.toolCallId)
4597
+ earlyCompletionDispatchedIds.has(result.toolCallId) ||
4598
+ this.protectedResultGate(request.name) != null
4516
4599
  ) {
4517
4600
  return;
4518
4601
  }
@@ -4663,10 +4746,22 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
4663
4746
  const flattenedEagerResults = eagerResults.flatMap(
4664
4747
  (result) => result.results
4665
4748
  );
4749
+ const hostResults = [...flattenedEagerResults, ...dispatchedResults];
4666
4750
  const results = [
4667
4751
  ...plan.rejectedResults,
4668
- ...flattenedEagerResults,
4669
- ...dispatchedResults,
4752
+ ...(this.toolResultGate == null
4753
+ ? hostResults
4754
+ : await this.inspectHostResults(
4755
+ hostResults,
4756
+ requestMap,
4757
+ config
4758
+ ).catch((error: unknown) => {
4759
+ this.retainCodeSessionInputsFromRequests(
4760
+ requestMap.values(),
4761
+ codeSessionBaselineByRequestId
4762
+ );
4763
+ throw error;
4764
+ })),
4670
4765
  ];
4671
4766
  /* Hosts may lazily refresh codeSessionContext while dispatching. The
4672
4767
  * pre-dispatch snapshot above remains the authority for detecting those
@@ -1,6 +1,280 @@
1
1
  import * as cheerio from 'cheerio';
2
2
  import type { References, MediaReference } from './types';
3
3
 
4
+ type ReferenceType = 'image' | 'video' | 'iframe' | 'link';
5
+
6
+ interface ReferenceTarget {
7
+ type: ReferenceType;
8
+ idx: number;
9
+ }
10
+
11
+ interface ReferenceEntry extends ReferenceTarget {
12
+ url: string;
13
+ }
14
+
15
+ /**
16
+ * Aho-Corasick automaton over `(` followed by every referenced URL, held in
17
+ * typed arrays: 18 bytes per node and no object per node. Nodes are numbered
18
+ * breadth first, so the children of `node` are the nodes from
19
+ * `firstChild[node]` up to `firstChild[node + 1]`, sorted by `code`.
20
+ */
21
+ export interface ReferenceMatcher {
22
+ firstChild: Int32Array;
23
+ code: Uint16Array;
24
+ depth: Int32Array;
25
+ fail: Int32Array;
26
+ /** Nearest node on the fail chain, itself included, that ends a URL, or -1. */
27
+ output: Int32Array;
28
+ targets: Map<number, ReferenceTarget>;
29
+ }
30
+
31
+ interface ReferenceClose {
32
+ end: number;
33
+ title?: string;
34
+ }
35
+
36
+ /**
37
+ * Largest automaton built for one page. Nodes are the distinct URL prefixes, at
38
+ * most the URL characters on the page: 2^21 of them measured 36 MiB and 0.15 s
39
+ * to build, about 100 times a long Wikipedia article. A page above the cap
40
+ * keeps its markdown as is.
41
+ */
42
+ export const MAX_MATCHER_NODES = 1 << 21;
43
+ const OPEN_PAREN = 0x28;
44
+ const CLOSE_PAREN = 0x29;
45
+ const QUOTE = 0x22;
46
+ const WHITESPACE = /\s/;
47
+
48
+ function compareUrls(a: ReferenceEntry, b: ReferenceEntry): number {
49
+ if (a.url === b.url) {
50
+ return 0;
51
+ }
52
+ return a.url < b.url ? -1 : 1;
53
+ }
54
+
55
+ function sharedPrefixLength(a: string, b: string): number {
56
+ const limit = Math.min(a.length, b.length);
57
+ let length = 0;
58
+ while (length < limit && a.charCodeAt(length) === b.charCodeAt(length)) {
59
+ length++;
60
+ }
61
+ return length;
62
+ }
63
+
64
+ /**
65
+ * Indexes every referenced URL once, or returns `undefined` when the automaton
66
+ * would exceed `MAX_MATCHER_NODES`. A URL listed under several types keeps the
67
+ * first, in image, video, iframe, link order, which is the order the replacement
68
+ * has always preferred. Sorting the URLs gives the exact node count before
69
+ * anything is allocated, and lets each node take its children from one
70
+ * contiguous run of URLs.
71
+ */
72
+ export function buildMatcher(
73
+ groups: ReadonlyArray<[ReferenceType, Map<string, MediaReference>]>
74
+ ): ReferenceMatcher | undefined {
75
+ const entries: ReferenceEntry[] = [];
76
+ for (const [type, references] of groups) {
77
+ let idx = 0;
78
+ for (const url of references.keys()) {
79
+ entries.push({ url, type, idx: ++idx });
80
+ }
81
+ }
82
+ entries.sort(compareUrls);
83
+ let size = 2;
84
+ for (let i = 0; i < entries.length; i++) {
85
+ const { url } = entries[i];
86
+ size +=
87
+ url.length - (i === 0 ? 0 : sharedPrefixLength(entries[i - 1].url, url));
88
+ }
89
+ if (size > MAX_MATCHER_NODES) {
90
+ return undefined;
91
+ }
92
+
93
+ const matcher: ReferenceMatcher = {
94
+ firstChild: new Int32Array(size + 1),
95
+ code: new Uint16Array(size),
96
+ depth: new Int32Array(size),
97
+ fail: new Int32Array(size),
98
+ output: new Int32Array(size).fill(-1),
99
+ targets: new Map<number, ReferenceTarget>(),
100
+ };
101
+ const { firstChild, code, depth, fail, output, targets } = matcher;
102
+ /** Nodes awaiting their children span two trie levels, each at most one node per URL. */
103
+ const pending = 2 * entries.length + 2;
104
+ const from = new Int32Array(pending);
105
+ const to = new Int32Array(pending);
106
+ firstChild[0] = 1;
107
+ code[1] = OPEN_PAREN;
108
+ depth[1] = 1;
109
+ to[1] = entries.length;
110
+ let next = 2;
111
+ for (let node = 1; node < next; node++) {
112
+ const consumed = depth[node] - 1;
113
+ const end = to[node % pending];
114
+ let i = from[node % pending];
115
+ const endsUrl = i < end && entries[i].url.length === consumed;
116
+ if (endsUrl) {
117
+ targets.set(node, entries[i]);
118
+ }
119
+ while (i < end && entries[i].url.length === consumed) {
120
+ i++;
121
+ }
122
+ output[node] = endsUrl ? node : output[fail[node]];
123
+ firstChild[node] = next;
124
+ while (i < end) {
125
+ const charCode = entries[i].url.charCodeAt(consumed);
126
+ code[next] = charCode;
127
+ depth[next] = consumed + 2;
128
+ fail[next] = transition(matcher, fail[node], charCode);
129
+ from[next % pending] = i;
130
+ do {
131
+ i++;
132
+ } while (i < end && entries[i].url.charCodeAt(consumed) === charCode);
133
+ to[next % pending] = i;
134
+ next++;
135
+ }
136
+ }
137
+ firstChild[next] = next;
138
+ return matcher;
139
+ }
140
+
141
+ function childOf(
142
+ matcher: ReferenceMatcher,
143
+ node: number,
144
+ charCode: number
145
+ ): number {
146
+ const { firstChild, code } = matcher;
147
+ const end = firstChild[node + 1];
148
+ let low = firstChild[node];
149
+ let high = end;
150
+ while (low < high) {
151
+ const middle = (low + high) >>> 1;
152
+ if (code[middle] < charCode) {
153
+ low = middle + 1;
154
+ } else {
155
+ high = middle;
156
+ }
157
+ }
158
+ return low < end && code[low] === charCode ? low : -1;
159
+ }
160
+
161
+ function transition(
162
+ matcher: ReferenceMatcher,
163
+ from: number,
164
+ charCode: number
165
+ ): number {
166
+ let state = from;
167
+ let next = childOf(matcher, state, charCode);
168
+ while (next === -1 && state !== 0) {
169
+ state = matcher.fail[state];
170
+ next = childOf(matcher, state, charCode);
171
+ }
172
+ return next === -1 ? 0 : next;
173
+ }
174
+
175
+ /**
176
+ * Closes a reference whose URL ends just before `urlEnd` with `)` or
177
+ * ` "title")`. Whitespace runs and quote pairs are resolved once each and
178
+ * cached, so checking many URL ends never rescans the same text.
179
+ */
180
+ function createCloser(
181
+ markdown: string
182
+ ): (urlEnd: number) => ReferenceClose | undefined {
183
+ const closingQuote = new Map<number, number>();
184
+ let nonSpaceFrom: Int32Array | undefined;
185
+ const firstNonSpace = (index: number): number => {
186
+ if (nonSpaceFrom == null) {
187
+ nonSpaceFrom = new Int32Array(markdown.length + 1);
188
+ nonSpaceFrom[markdown.length] = markdown.length;
189
+ for (let i = markdown.length - 1; i >= 0; i--) {
190
+ nonSpaceFrom[i] = WHITESPACE.test(markdown[i])
191
+ ? nonSpaceFrom[i + 1]
192
+ : i;
193
+ }
194
+ }
195
+ return nonSpaceFrom[index];
196
+ };
197
+ return (urlEnd) => {
198
+ const next = markdown.charCodeAt(urlEnd);
199
+ if (next === CLOSE_PAREN) {
200
+ return { end: urlEnd + 1 };
201
+ }
202
+ if (!WHITESPACE.test(markdown[urlEnd] ?? '')) {
203
+ return undefined;
204
+ }
205
+ const open = firstNonSpace(urlEnd);
206
+ if (markdown.charCodeAt(open) !== QUOTE) {
207
+ return undefined;
208
+ }
209
+ let close = closingQuote.get(open);
210
+ if (close == null) {
211
+ close = markdown.indexOf('"', open + 1);
212
+ closingQuote.set(open, close);
213
+ }
214
+ if (close === -1 || markdown.charCodeAt(close + 1) !== CLOSE_PAREN) {
215
+ return undefined;
216
+ }
217
+ return { end: close + 2, title: markdown.slice(open + 1, close) };
218
+ };
219
+ }
220
+
221
+ /**
222
+ * Rewrites every markdown reference to a known URL. One scan finds each
223
+ * `(url` occurrence that is closed as a reference; the longest at each opening
224
+ * parenthesis is applied left to right. The work is linear in the markdown
225
+ * plus the occurrences found, where one regex per URL over the whole page grew
226
+ * with links times page size and blocked the event loop for seconds.
227
+ * Occurrences exceed the markdown length only when URLs are suffixes of one
228
+ * another; n such URLs need about n * n characters of HTML, so the worst case
229
+ * stays near the input size to the power 1.5.
230
+ */
231
+ function replaceReferences(
232
+ markdown: string,
233
+ matcher: ReferenceMatcher
234
+ ): string {
235
+ if (matcher.targets.size === 0) {
236
+ return markdown;
237
+ }
238
+ const { depth, fail, output, targets } = matcher;
239
+ const closeAt = createCloser(markdown);
240
+ const longest = new Map<number, { node: number; close: ReferenceClose }>();
241
+ let state = 0;
242
+ for (let i = 0; i < markdown.length; i++) {
243
+ state = transition(matcher, state, markdown.charCodeAt(i));
244
+ let node = output[state];
245
+ if (node === -1) {
246
+ continue;
247
+ }
248
+ const close = closeAt(i + 1);
249
+ if (close == null) {
250
+ continue;
251
+ }
252
+ for (; node !== -1; node = output[fail[node]]) {
253
+ const start = i - depth[node] + 1;
254
+ const current = longest.get(start);
255
+ if (current == null || depth[current.node] < depth[node]) {
256
+ longest.set(start, { node, close });
257
+ }
258
+ }
259
+ }
260
+
261
+ let result = '';
262
+ let copied = 0;
263
+ const ordered = Array.from(longest.entries()).sort((a, b) => a[0] - b[0]);
264
+ for (const [start, { node, close }] of ordered) {
265
+ const target = targets.get(node);
266
+ if (start < copied || target == null) {
267
+ continue;
268
+ }
269
+ const label = `${target.type}#${target.idx}`;
270
+ const text =
271
+ close.title == null ? `(${label})` : `(${label} "${close.title}")`;
272
+ result += markdown.slice(copied, start) + text;
273
+ copied = close.end;
274
+ }
275
+ return result + markdown.slice(copied);
276
+ }
277
+
4
278
  export function processContent(
5
279
  html: string,
6
280
  markdown: string
@@ -67,68 +341,14 @@ export function processContent(
67
341
  }
68
342
  });
69
343
 
70
- // Create lookup maps with indices
71
- const linkIndexMap = new Map<string, number>();
72
- const imageIndexMap = new Map<string, number>();
73
- const videoIndexMap = new Map<string, number>();
74
- const iframeIndexMap = new Map<string, number>();
75
-
76
- Array.from(linkMap.keys()).forEach((url, i) => linkIndexMap.set(url, i + 1));
77
- Array.from(imageMap.keys()).forEach((url, i) =>
78
- imageIndexMap.set(url, i + 1)
79
- );
80
- Array.from(videoMap.keys()).forEach((url, i) =>
81
- videoIndexMap.set(url, i + 1)
82
- );
83
- Array.from(iframeMap.keys()).forEach((url, i) =>
84
- iframeIndexMap.set(url, i + 1)
85
- );
86
-
87
- // Process the markdown
88
- let result = markdown;
89
-
90
- // Replace each URL one by one, starting with the longest URLs first to avoid partial matches
91
- const allUrls = [
92
- ...Array.from(imageMap.keys()).map((url) => ({
93
- url,
94
- type: 'image',
95
- idx: imageIndexMap.get(url),
96
- })),
97
- ...Array.from(videoMap.keys()).map((url) => ({
98
- url,
99
- type: 'video',
100
- idx: videoIndexMap.get(url),
101
- })),
102
- ...Array.from(iframeMap.keys()).map((url) => ({
103
- url,
104
- type: 'iframe',
105
- idx: iframeIndexMap.get(url),
106
- })),
107
- ...Array.from(linkMap.keys()).map((url) => ({
108
- url,
109
- type: 'link',
110
- idx: linkIndexMap.get(url),
111
- })),
112
- ].sort((a, b) => b.url.length - a.url.length);
113
-
114
- // Create a function to escape special characters in URLs for regex
115
- function escapeRegex(string: string): string {
116
- return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
117
- }
118
-
119
- // Replace each URL in the markdown
120
- for (const { url, type, idx } of allUrls) {
121
- // Create a regex that captures URLs in markdown links
122
- const regex = new RegExp(`\\(${escapeRegex(url)}(?:\\s+"[^"]*")?\\)`, 'g');
123
-
124
- result = result.replace(regex, (match) => {
125
- // Keep any title attribute that might exist
126
- const titleMatch = match.match(/\s+"([^"]*)"/);
127
- const titlePart = titleMatch ? ` "${titleMatch[1]}"` : '';
128
-
129
- return `(${type}#${idx}${titlePart})`;
130
- });
131
- }
344
+ const matcher = buildMatcher([
345
+ ['image', imageMap],
346
+ ['video', videoMap],
347
+ ['iframe', iframeMap],
348
+ ['link', linkMap],
349
+ ]);
350
+ const result =
351
+ matcher == null ? markdown : replaceReferences(markdown, matcher);
132
352
 
133
353
  iframeMap.clear();
134
354
  const links = Array.from(linkMap.values());
@@ -1174,6 +1174,8 @@ export type SubagentExecutorOptions = {
1174
1174
  * revert to the defaults.
1175
1175
  */
1176
1176
  providerTextProtection?: StandardGraphInput['providerTextProtection'];
1177
+ /** The parent's tool result protection, so a child inspects the same tools. */
1178
+ toolResultProtection?: StandardGraphInput['toolResultProtection'];
1177
1179
  /** The parent's attachment resolver, so a child resolves the references it inherits. */
1178
1180
  resolveAttachment?: StandardGraphInput['resolveAttachment'];
1179
1181
  streamLimits?: StandardGraphInput['streamLimits'];
@@ -1254,6 +1256,7 @@ export class SubagentExecutor {
1254
1256
  private readonly langfuse?: StandardGraphInput['langfuse'];
1255
1257
  private readonly tokenCounter?: TokenCounter;
1256
1258
  private readonly providerTextProtection?: StandardGraphInput['providerTextProtection'];
1259
+ private readonly toolResultProtection?: StandardGraphInput['toolResultProtection'];
1257
1260
  private readonly resolveAttachment?: StandardGraphInput['resolveAttachment'];
1258
1261
  private readonly streamLimits?: StandardGraphInput['streamLimits'];
1259
1262
  private readonly humanInTheLoop?: HumanInTheLoopConfig;
@@ -1296,6 +1299,7 @@ export class SubagentExecutor {
1296
1299
  this.tokenCounter = options.tokenCounter;
1297
1300
  this.streamLimits = options.streamLimits;
1298
1301
  this.providerTextProtection = options.providerTextProtection;
1302
+ this.toolResultProtection = options.toolResultProtection;
1299
1303
  this.resolveAttachment = options.resolveAttachment;
1300
1304
  this.humanInTheLoop = options.humanInTheLoop;
1301
1305
  this.checkpointer = isCheckpointSaver(options.checkpointer)
@@ -1582,6 +1586,7 @@ export class SubagentExecutor {
1582
1586
  onResolutionFailure: this.onResolutionFailure,
1583
1587
  streamLimits: this.streamLimits,
1584
1588
  providerTextProtection: this.providerTextProtection,
1589
+ toolResultProtection: this.toolResultProtection,
1585
1590
  resolveAttachment: this.resolveAttachment,
1586
1591
  humanInTheLoop:
1587
1592
  this.humanInTheLoop?.enabled === true ||
@@ -3192,6 +3197,7 @@ export class SubagentExecutor {
3192
3197
  tokenCounter: this.tokenCounter,
3193
3198
  streamLimits: this.streamLimits,
3194
3199
  providerTextProtection: this.providerTextProtection,
3200
+ toolResultProtection: this.toolResultProtection,
3195
3201
  resolveAttachment: this.resolveAttachment,
3196
3202
  subagentScope: true,
3197
3203
  subagentExecutionContext: childExecutionContext,
@@ -1,4 +1,5 @@
1
1
  import type { ProviderTextProtection } from '@/protection/providerText';
2
+ import type { ToolResultProtection } from '@/protection/toolResult';
2
3
  import type { AttachmentResolver } from './attachments';
3
4
  // src/types/graph.ts
4
5
  import type {
@@ -411,6 +412,8 @@ export type ModelEndData =
411
412
  export type GraphTools = GenericTool[] | BindToolsInput[] | GoogleAIToolType[];
412
413
  export type StandardGraphInput = {
413
414
  providerTextProtection?: ProviderTextProtection;
415
+ /** Host inspection of selected tools' result text, for every graph of the run. */
416
+ toolResultProtection?: ToolResultProtection;
414
417
  /** Resolves attachments that messages carry by reference; see {@link AttachmentResolver}. */
415
418
  resolveAttachment?: AttachmentResolver;
416
419
  runId?: string;
package/src/types/run.ts CHANGED
@@ -40,6 +40,7 @@ export type LegacyGraphConfig = BaseGraphConfig & {
40
40
  | 'agents'
41
41
  | 'streamLimits'
42
42
  | 'providerTextProtection'
43
+ | 'toolResultProtection'
43
44
  | 'resolveAttachment'
44
45
  > &
45
46
  Omit<g.AgentInputs, 'provider' | 'clientOptions' | 'agentId'>;
@@ -343,6 +344,8 @@ export type RunConfig = {
343
344
  * opt-in. See {@link StreamLimits}.
344
345
  */
345
346
  providerTextProtection?: g.StandardGraphInput['providerTextProtection'];
347
+ /** Host inspection of selected tools' result text. Default off. */
348
+ toolResultProtection?: g.StandardGraphInput['toolResultProtection'];
346
349
  /** Resolves attachments that messages carry by reference, for every graph of the run. */
347
350
  resolveAttachment?: g.StandardGraphInput['resolveAttachment'];
348
351
  streamLimits?: StreamLimits;
@@ -12,6 +12,7 @@ import type {
12
12
  } from './stream';
13
13
  import type { ToolOutputReferenceRegistry } from '@/tools/toolOutputReferences';
14
14
  import type { LangfuseConfig, SubagentExecutionContext } from './graph';
15
+ import type { ToolResultProtection } from '@/protection/toolResult';
15
16
  import type { PreparedSubagents } from '@/tools/preparedSubagents';
16
17
  import type { RunBreakerScope } from '@/llm/streamLimits';
17
18
  import type { HandoffRouting } from '@/graphs/handoff';
@@ -271,6 +272,8 @@ export type ToolNodeOptions = {
271
272
  * precedence over `toolOutputReferences` when both are set.
272
273
  */
273
274
  toolOutputRegistry?: ToolOutputReferenceRegistry;
275
+ /** Host inspection of selected tools' result text; see {@link ToolResultProtection}. */
276
+ toolResultProtection?: ToolResultProtection;
274
277
  /**
275
278
  * Selects where built-in code execution tools run. Defaults to the
276
279
  * remote LibreChat Code API sandbox; `local` swaps those same tool names