@librechat/agents 3.4.6 → 3.5.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.
Files changed (1027) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +0 -356
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/agents/projection.cjs +0 -9
  4. package/dist/cjs/agents/projection.cjs.map +1 -1
  5. package/dist/cjs/common/constants.cjs +0 -26
  6. package/dist/cjs/common/constants.cjs.map +1 -1
  7. package/dist/cjs/common/enum.cjs +0 -85
  8. package/dist/cjs/common/enum.cjs.map +1 -1
  9. package/dist/cjs/events.cjs +0 -14
  10. package/dist/cjs/events.cjs.map +1 -1
  11. package/dist/cjs/graphs/Graph.cjs +1 -909
  12. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  13. package/dist/cjs/graphs/MultiAgentGraph.cjs +7 -272
  14. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  15. package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs.map +1 -1
  16. package/dist/cjs/graphs/createGraph.cjs.map +1 -1
  17. package/dist/cjs/hitl/askUserQuestion.cjs +0 -53
  18. package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -1
  19. package/dist/cjs/hitl/askUserQuestions.cjs +0 -20
  20. package/dist/cjs/hitl/askUserQuestions.cjs.map +1 -1
  21. package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs +0 -6
  22. package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs.map +1 -1
  23. package/dist/cjs/hooks/HookRegistry.cjs +0 -127
  24. package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
  25. package/dist/cjs/hooks/createToolPolicyHook.cjs +0 -38
  26. package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -1
  27. package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +0 -77
  28. package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -1
  29. package/dist/cjs/hooks/executeHooks.cjs +0 -79
  30. package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
  31. package/dist/cjs/hooks/index.cjs +0 -16
  32. package/dist/cjs/hooks/index.cjs.map +1 -1
  33. package/dist/cjs/hooks/matchers.cjs +0 -104
  34. package/dist/cjs/hooks/matchers.cjs.map +1 -1
  35. package/dist/cjs/hooks/types.cjs +0 -8
  36. package/dist/cjs/hooks/types.cjs.map +1 -1
  37. package/dist/cjs/instrumentation.cjs +0 -14
  38. package/dist/cjs/instrumentation.cjs.map +1 -1
  39. package/dist/cjs/langfuse.cjs +0 -75
  40. package/dist/cjs/langfuse.cjs.map +1 -1
  41. package/dist/cjs/langfuseConfig.cjs.map +1 -1
  42. package/dist/cjs/langfuseRuntimeContext.cjs +0 -13
  43. package/dist/cjs/langfuseRuntimeContext.cjs.map +1 -1
  44. package/dist/cjs/langfuseRuntimeScope.cjs +0 -4
  45. package/dist/cjs/langfuseRuntimeScope.cjs.map +1 -1
  46. package/dist/cjs/langfuseSpanRegistry.cjs +0 -28
  47. package/dist/cjs/langfuseSpanRegistry.cjs.map +1 -1
  48. package/dist/cjs/langfuseToolOutputTracing.cjs +0 -3
  49. package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
  50. package/dist/cjs/langfuseTraceShaping.cjs +0 -74
  51. package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
  52. package/dist/cjs/llm/anthropic/index.cjs +0 -3
  53. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  54. package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
  55. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -111
  56. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  57. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +0 -1
  58. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  59. package/dist/cjs/llm/anthropic/utils/stream_events.cjs +0 -8
  60. package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
  61. package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
  62. package/dist/cjs/llm/bedrock/cachePoints.cjs.map +1 -1
  63. package/dist/cjs/llm/bedrock/index.cjs +1 -95
  64. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  65. package/dist/cjs/llm/bedrock/toolCache.cjs.map +1 -1
  66. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +0 -78
  67. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
  68. package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +0 -24
  69. package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
  70. package/dist/cjs/llm/contextOverflowRecovery.cjs +0 -62
  71. package/dist/cjs/llm/contextOverflowRecovery.cjs.map +1 -1
  72. package/dist/cjs/llm/fake.cjs.map +1 -1
  73. package/dist/cjs/llm/google/index.cjs +2 -21
  74. package/dist/cjs/llm/google/index.cjs.map +1 -1
  75. package/dist/cjs/llm/google/utils/common.cjs +5 -35
  76. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  77. package/dist/cjs/llm/init.cjs +0 -9
  78. package/dist/cjs/llm/init.cjs.map +1 -1
  79. package/dist/cjs/llm/invoke.cjs +1 -270
  80. package/dist/cjs/llm/invoke.cjs.map +1 -1
  81. package/dist/cjs/llm/mistral/index.cjs.map +1 -1
  82. package/dist/cjs/llm/openai/index.cjs +0 -99
  83. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  84. package/dist/cjs/llm/openai/streamMetadata.cjs +0 -21
  85. package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
  86. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  87. package/dist/cjs/llm/openrouter/index.cjs +0 -1
  88. package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
  89. package/dist/cjs/llm/openrouter/toolCache.cjs +0 -6
  90. package/dist/cjs/llm/openrouter/toolCache.cjs.map +1 -1
  91. package/dist/cjs/llm/preempt.cjs +0 -75
  92. package/dist/cjs/llm/preempt.cjs.map +1 -1
  93. package/dist/cjs/llm/providers.cjs.map +1 -1
  94. package/dist/cjs/llm/request.cjs +0 -10
  95. package/dist/cjs/llm/request.cjs.map +1 -1
  96. package/dist/cjs/llm/stream/chunkAdapters.cjs +0 -62
  97. package/dist/cjs/llm/stream/chunkAdapters.cjs.map +1 -1
  98. package/dist/cjs/llm/stream/smoother.cjs +0 -58
  99. package/dist/cjs/llm/stream/smoother.cjs.map +1 -1
  100. package/dist/cjs/llm/streamLimits.cjs +4 -293
  101. package/dist/cjs/llm/streamLimits.cjs.map +1 -1
  102. package/dist/cjs/llm/truncation.cjs +0 -36
  103. package/dist/cjs/llm/truncation.cjs.map +1 -1
  104. package/dist/cjs/llm/vertexai/index.cjs +0 -330
  105. package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
  106. package/dist/cjs/messages/alternation.cjs +0 -43
  107. package/dist/cjs/messages/alternation.cjs.map +1 -1
  108. package/dist/cjs/messages/anthropicToolCache.cjs +0 -45
  109. package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -1
  110. package/dist/cjs/messages/assistantPhase.cjs +0 -12
  111. package/dist/cjs/messages/assistantPhase.cjs.map +1 -1
  112. package/dist/cjs/messages/budget.cjs +0 -9
  113. package/dist/cjs/messages/budget.cjs.map +1 -1
  114. package/dist/cjs/messages/cache.cjs +0 -172
  115. package/dist/cjs/messages/cache.cjs.map +1 -1
  116. package/dist/cjs/messages/content.cjs +0 -9
  117. package/dist/cjs/messages/content.cjs.map +1 -1
  118. package/dist/cjs/messages/contextPruning.cjs +0 -15
  119. package/dist/cjs/messages/contextPruning.cjs.map +1 -1
  120. package/dist/cjs/messages/contextPruningSettings.cjs +0 -3
  121. package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -1
  122. package/dist/cjs/messages/core.cjs +0 -48
  123. package/dist/cjs/messages/core.cjs.map +1 -1
  124. package/dist/cjs/messages/format.cjs +1 -345
  125. package/dist/cjs/messages/format.cjs.map +1 -1
  126. package/dist/cjs/messages/handoffCue.cjs +0 -36
  127. package/dist/cjs/messages/handoffCue.cjs.map +1 -1
  128. package/dist/cjs/messages/ids.cjs.map +1 -1
  129. package/dist/cjs/messages/injected.cjs +0 -33
  130. package/dist/cjs/messages/injected.cjs.map +1 -1
  131. package/dist/cjs/messages/langchain.cjs +0 -14
  132. package/dist/cjs/messages/langchain.cjs.map +1 -1
  133. package/dist/cjs/messages/prune.cjs +1 -184
  134. package/dist/cjs/messages/prune.cjs.map +1 -1
  135. package/dist/cjs/messages/recency.cjs +0 -32
  136. package/dist/cjs/messages/recency.cjs.map +1 -1
  137. package/dist/cjs/messages/reducer.cjs +0 -30
  138. package/dist/cjs/messages/reducer.cjs.map +1 -1
  139. package/dist/cjs/messages/tools.cjs +0 -14
  140. package/dist/cjs/messages/tools.cjs.map +1 -1
  141. package/dist/cjs/openai/index.cjs.map +1 -1
  142. package/dist/cjs/prompts/activityLabel.cjs +9 -79
  143. package/dist/cjs/prompts/activityLabel.cjs.map +1 -1
  144. package/dist/cjs/responses/index.cjs.map +1 -1
  145. package/dist/cjs/run.cjs +2 -538
  146. package/dist/cjs/run.cjs.map +1 -1
  147. package/dist/cjs/session/AgentSession.cjs +1 -17
  148. package/dist/cjs/session/AgentSession.cjs.map +1 -1
  149. package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
  150. package/dist/cjs/session/handlers.cjs +0 -7
  151. package/dist/cjs/session/handlers.cjs.map +1 -1
  152. package/dist/cjs/session/ids.cjs.map +1 -1
  153. package/dist/cjs/session/messageSerialization.cjs +0 -4
  154. package/dist/cjs/session/messageSerialization.cjs.map +1 -1
  155. package/dist/cjs/stream.cjs +1 -93
  156. package/dist/cjs/stream.cjs.map +1 -1
  157. package/dist/cjs/summarization/index.cjs +0 -27
  158. package/dist/cjs/summarization/index.cjs.map +1 -1
  159. package/dist/cjs/summarization/node.cjs +0 -273
  160. package/dist/cjs/summarization/node.cjs.map +1 -1
  161. package/dist/cjs/tools/BashExecutor.cjs +0 -35
  162. package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
  163. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +0 -24
  164. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
  165. package/dist/cjs/tools/Calculator.cjs.map +1 -1
  166. package/dist/cjs/tools/CodeExecutor.cjs +0 -13
  167. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  168. package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -1
  169. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +0 -101
  170. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  171. package/dist/cjs/tools/ReadFile.cjs.map +1 -1
  172. package/dist/cjs/tools/SkillTool.cjs +0 -5
  173. package/dist/cjs/tools/SkillTool.cjs.map +1 -1
  174. package/dist/cjs/tools/SubagentTool.cjs +0 -10
  175. package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
  176. package/dist/cjs/tools/ToolNode.cjs +6 -1038
  177. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  178. package/dist/cjs/tools/ToolSearch.cjs +0 -179
  179. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  180. package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -1
  181. package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -1
  182. package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +0 -39
  183. package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -1
  184. package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -1
  185. package/dist/cjs/tools/eagerEventExecution.cjs +0 -6
  186. package/dist/cjs/tools/eagerEventExecution.cjs.map +1 -1
  187. package/dist/cjs/tools/handlers.cjs +1 -41
  188. package/dist/cjs/tools/handlers.cjs.map +1 -1
  189. package/dist/cjs/tools/intentArg.cjs +1 -132
  190. package/dist/cjs/tools/intentArg.cjs.map +1 -1
  191. package/dist/cjs/tools/local/CompileCheckTool.cjs +0 -25
  192. package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -1
  193. package/dist/cjs/tools/local/FileCheckpointer.cjs +0 -23
  194. package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -1
  195. package/dist/cjs/tools/local/LocalCodingTools.cjs +0 -80
  196. package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
  197. package/dist/cjs/tools/local/LocalExecutionEngine.cjs +0 -126
  198. package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
  199. package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
  200. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +0 -12
  201. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
  202. package/dist/cjs/tools/local/attachments.cjs +0 -44
  203. package/dist/cjs/tools/local/attachments.cjs.map +1 -1
  204. package/dist/cjs/tools/local/bashAst.cjs +0 -16
  205. package/dist/cjs/tools/local/bashAst.cjs.map +1 -1
  206. package/dist/cjs/tools/local/editStrategies.cjs +0 -14
  207. package/dist/cjs/tools/local/editStrategies.cjs.map +1 -1
  208. package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
  209. package/dist/cjs/tools/local/syntaxCheck.cjs +0 -31
  210. package/dist/cjs/tools/local/syntaxCheck.cjs.map +1 -1
  211. package/dist/cjs/tools/local/textEncoding.cjs +0 -11
  212. package/dist/cjs/tools/local/textEncoding.cjs.map +1 -1
  213. package/dist/cjs/tools/local/workspaceFS.cjs +0 -33
  214. package/dist/cjs/tools/local/workspaceFS.cjs.map +1 -1
  215. package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
  216. package/dist/cjs/tools/schema.cjs +0 -8
  217. package/dist/cjs/tools/schema.cjs.map +1 -1
  218. package/dist/cjs/tools/search/anthropic.cjs +0 -9
  219. package/dist/cjs/tools/search/anthropic.cjs.map +1 -1
  220. package/dist/cjs/tools/search/content.cjs.map +1 -1
  221. package/dist/cjs/tools/search/crw-scraper.cjs +0 -33
  222. package/dist/cjs/tools/search/crw-scraper.cjs.map +1 -1
  223. package/dist/cjs/tools/search/crw-search.cjs +0 -2
  224. package/dist/cjs/tools/search/crw-search.cjs.map +1 -1
  225. package/dist/cjs/tools/search/firecrawl.cjs +0 -25
  226. package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
  227. package/dist/cjs/tools/search/format.cjs +0 -30
  228. package/dist/cjs/tools/search/format.cjs.map +1 -1
  229. package/dist/cjs/tools/search/highlights.cjs +0 -16
  230. package/dist/cjs/tools/search/highlights.cjs.map +1 -1
  231. package/dist/cjs/tools/search/keenable-scraper.cjs +0 -8
  232. package/dist/cjs/tools/search/keenable-scraper.cjs.map +1 -1
  233. package/dist/cjs/tools/search/keenable-search.cjs +0 -7
  234. package/dist/cjs/tools/search/keenable-search.cjs.map +1 -1
  235. package/dist/cjs/tools/search/rerankers.cjs +0 -35
  236. package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
  237. package/dist/cjs/tools/search/schema.cjs +0 -1
  238. package/dist/cjs/tools/search/schema.cjs.map +1 -1
  239. package/dist/cjs/tools/search/search.cjs +1 -14
  240. package/dist/cjs/tools/search/search.cjs.map +1 -1
  241. package/dist/cjs/tools/search/serper-scraper.cjs +0 -46
  242. package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
  243. package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -1
  244. package/dist/cjs/tools/search/tavily-search.cjs.map +1 -1
  245. package/dist/cjs/tools/search/tool.cjs +0 -25
  246. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  247. package/dist/cjs/tools/search/utils.cjs +0 -8
  248. package/dist/cjs/tools/search/utils.cjs.map +1 -1
  249. package/dist/cjs/tools/skillCatalog.cjs +0 -6
  250. package/dist/cjs/tools/skillCatalog.cjs.map +1 -1
  251. package/dist/cjs/tools/streamedToolCallSeals.cjs +0 -6
  252. package/dist/cjs/tools/streamedToolCallSeals.cjs.map +1 -1
  253. package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -2
  254. package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
  255. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +3 -213
  256. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  257. package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
  258. package/dist/cjs/tools/subagent/childGraphConfig.cjs +0 -4
  259. package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
  260. package/dist/cjs/tools/subagent/runtimeLimits.cjs.map +1 -1
  261. package/dist/cjs/tools/toolOutputReferences.cjs +1 -322
  262. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
  263. package/dist/cjs/types/hitl.cjs +0 -5
  264. package/dist/cjs/types/hitl.cjs.map +1 -1
  265. package/dist/cjs/utils/callbacks.cjs.map +1 -1
  266. package/dist/cjs/utils/errors.cjs +14 -165
  267. package/dist/cjs/utils/errors.cjs.map +1 -1
  268. package/dist/cjs/utils/events.cjs +0 -10
  269. package/dist/cjs/utils/events.cjs.map +1 -1
  270. package/dist/cjs/utils/graph.cjs.map +1 -1
  271. package/dist/cjs/utils/handlers.cjs +0 -3
  272. package/dist/cjs/utils/handlers.cjs.map +1 -1
  273. package/dist/cjs/utils/llm.cjs +0 -1
  274. package/dist/cjs/utils/llm.cjs.map +1 -1
  275. package/dist/cjs/utils/misc.cjs +0 -16
  276. package/dist/cjs/utils/misc.cjs.map +1 -1
  277. package/dist/cjs/utils/proxy.cjs +0 -26
  278. package/dist/cjs/utils/proxy.cjs.map +1 -1
  279. package/dist/cjs/utils/run.cjs +0 -6
  280. package/dist/cjs/utils/run.cjs.map +1 -1
  281. package/dist/cjs/utils/schema.cjs +0 -5
  282. package/dist/cjs/utils/schema.cjs.map +1 -1
  283. package/dist/cjs/utils/title.cjs +0 -6
  284. package/dist/cjs/utils/title.cjs.map +1 -1
  285. package/dist/cjs/utils/tokens.cjs +0 -113
  286. package/dist/cjs/utils/tokens.cjs.map +1 -1
  287. package/dist/cjs/utils/toolContent.cjs +0 -41
  288. package/dist/cjs/utils/toolContent.cjs.map +1 -1
  289. package/dist/cjs/utils/truncation.cjs +0 -61
  290. package/dist/cjs/utils/truncation.cjs.map +1 -1
  291. package/dist/esm/agents/AgentContext.mjs +0 -356
  292. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  293. package/dist/esm/agents/projection.mjs +0 -9
  294. package/dist/esm/agents/projection.mjs.map +1 -1
  295. package/dist/esm/common/constants.mjs +0 -26
  296. package/dist/esm/common/constants.mjs.map +1 -1
  297. package/dist/esm/common/enum.mjs +0 -85
  298. package/dist/esm/common/enum.mjs.map +1 -1
  299. package/dist/esm/events.mjs +0 -14
  300. package/dist/esm/events.mjs.map +1 -1
  301. package/dist/esm/graphs/Graph.mjs +1 -909
  302. package/dist/esm/graphs/Graph.mjs.map +1 -1
  303. package/dist/esm/graphs/MultiAgentGraph.mjs +7 -272
  304. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  305. package/dist/esm/graphs/applyGraphRuntimeConfig.mjs.map +1 -1
  306. package/dist/esm/graphs/createGraph.mjs.map +1 -1
  307. package/dist/esm/hitl/askUserQuestion.mjs +0 -53
  308. package/dist/esm/hitl/askUserQuestion.mjs.map +1 -1
  309. package/dist/esm/hitl/askUserQuestions.mjs +0 -20
  310. package/dist/esm/hitl/askUserQuestions.mjs.map +1 -1
  311. package/dist/esm/hitl/askUserQuestionsInterrupt.mjs +0 -6
  312. package/dist/esm/hitl/askUserQuestionsInterrupt.mjs.map +1 -1
  313. package/dist/esm/hooks/HookRegistry.mjs +0 -127
  314. package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
  315. package/dist/esm/hooks/createToolPolicyHook.mjs +0 -38
  316. package/dist/esm/hooks/createToolPolicyHook.mjs.map +1 -1
  317. package/dist/esm/hooks/createWorkspacePolicyHook.mjs +0 -77
  318. package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -1
  319. package/dist/esm/hooks/executeHooks.mjs +0 -79
  320. package/dist/esm/hooks/executeHooks.mjs.map +1 -1
  321. package/dist/esm/hooks/index.mjs +0 -16
  322. package/dist/esm/hooks/index.mjs.map +1 -1
  323. package/dist/esm/hooks/matchers.mjs +0 -104
  324. package/dist/esm/hooks/matchers.mjs.map +1 -1
  325. package/dist/esm/hooks/types.mjs +0 -8
  326. package/dist/esm/hooks/types.mjs.map +1 -1
  327. package/dist/esm/instrumentation.mjs +0 -14
  328. package/dist/esm/instrumentation.mjs.map +1 -1
  329. package/dist/esm/langfuse.mjs +0 -75
  330. package/dist/esm/langfuse.mjs.map +1 -1
  331. package/dist/esm/langfuseConfig.mjs.map +1 -1
  332. package/dist/esm/langfuseRuntimeContext.mjs +0 -13
  333. package/dist/esm/langfuseRuntimeContext.mjs.map +1 -1
  334. package/dist/esm/langfuseRuntimeScope.mjs +0 -4
  335. package/dist/esm/langfuseRuntimeScope.mjs.map +1 -1
  336. package/dist/esm/langfuseSpanRegistry.mjs +0 -28
  337. package/dist/esm/langfuseSpanRegistry.mjs.map +1 -1
  338. package/dist/esm/langfuseToolOutputTracing.mjs +0 -3
  339. package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
  340. package/dist/esm/langfuseTraceShaping.mjs +0 -74
  341. package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
  342. package/dist/esm/llm/anthropic/index.mjs +0 -3
  343. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  344. package/dist/esm/llm/anthropic/types.mjs.map +1 -1
  345. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +1 -111
  346. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  347. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +0 -1
  348. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  349. package/dist/esm/llm/anthropic/utils/stream_events.mjs +0 -8
  350. package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
  351. package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
  352. package/dist/esm/llm/bedrock/cachePoints.mjs.map +1 -1
  353. package/dist/esm/llm/bedrock/index.mjs +1 -95
  354. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  355. package/dist/esm/llm/bedrock/toolCache.mjs.map +1 -1
  356. package/dist/esm/llm/bedrock/utils/message_inputs.mjs +0 -78
  357. package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
  358. package/dist/esm/llm/bedrock/utils/message_outputs.mjs +0 -24
  359. package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
  360. package/dist/esm/llm/contextOverflowRecovery.mjs +0 -62
  361. package/dist/esm/llm/contextOverflowRecovery.mjs.map +1 -1
  362. package/dist/esm/llm/fake.mjs.map +1 -1
  363. package/dist/esm/llm/google/index.mjs +2 -21
  364. package/dist/esm/llm/google/index.mjs.map +1 -1
  365. package/dist/esm/llm/google/utils/common.mjs +5 -35
  366. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  367. package/dist/esm/llm/init.mjs +0 -9
  368. package/dist/esm/llm/init.mjs.map +1 -1
  369. package/dist/esm/llm/invoke.mjs +1 -270
  370. package/dist/esm/llm/invoke.mjs.map +1 -1
  371. package/dist/esm/llm/mistral/index.mjs.map +1 -1
  372. package/dist/esm/llm/openai/index.mjs +0 -99
  373. package/dist/esm/llm/openai/index.mjs.map +1 -1
  374. package/dist/esm/llm/openai/streamMetadata.mjs +0 -21
  375. package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
  376. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  377. package/dist/esm/llm/openrouter/index.mjs +0 -1
  378. package/dist/esm/llm/openrouter/index.mjs.map +1 -1
  379. package/dist/esm/llm/openrouter/toolCache.mjs +0 -6
  380. package/dist/esm/llm/openrouter/toolCache.mjs.map +1 -1
  381. package/dist/esm/llm/preempt.mjs +0 -75
  382. package/dist/esm/llm/preempt.mjs.map +1 -1
  383. package/dist/esm/llm/providers.mjs.map +1 -1
  384. package/dist/esm/llm/request.mjs +0 -10
  385. package/dist/esm/llm/request.mjs.map +1 -1
  386. package/dist/esm/llm/stream/chunkAdapters.mjs +0 -62
  387. package/dist/esm/llm/stream/chunkAdapters.mjs.map +1 -1
  388. package/dist/esm/llm/stream/smoother.mjs +0 -58
  389. package/dist/esm/llm/stream/smoother.mjs.map +1 -1
  390. package/dist/esm/llm/streamLimits.mjs +4 -293
  391. package/dist/esm/llm/streamLimits.mjs.map +1 -1
  392. package/dist/esm/llm/truncation.mjs +0 -36
  393. package/dist/esm/llm/truncation.mjs.map +1 -1
  394. package/dist/esm/llm/vertexai/index.mjs +0 -330
  395. package/dist/esm/llm/vertexai/index.mjs.map +1 -1
  396. package/dist/esm/messages/alternation.mjs +0 -43
  397. package/dist/esm/messages/alternation.mjs.map +1 -1
  398. package/dist/esm/messages/anthropicToolCache.mjs +0 -45
  399. package/dist/esm/messages/anthropicToolCache.mjs.map +1 -1
  400. package/dist/esm/messages/assistantPhase.mjs +0 -12
  401. package/dist/esm/messages/assistantPhase.mjs.map +1 -1
  402. package/dist/esm/messages/budget.mjs +0 -9
  403. package/dist/esm/messages/budget.mjs.map +1 -1
  404. package/dist/esm/messages/cache.mjs +0 -172
  405. package/dist/esm/messages/cache.mjs.map +1 -1
  406. package/dist/esm/messages/content.mjs +0 -9
  407. package/dist/esm/messages/content.mjs.map +1 -1
  408. package/dist/esm/messages/contextPruning.mjs +0 -15
  409. package/dist/esm/messages/contextPruning.mjs.map +1 -1
  410. package/dist/esm/messages/contextPruningSettings.mjs +0 -3
  411. package/dist/esm/messages/contextPruningSettings.mjs.map +1 -1
  412. package/dist/esm/messages/core.mjs +0 -48
  413. package/dist/esm/messages/core.mjs.map +1 -1
  414. package/dist/esm/messages/format.mjs +1 -345
  415. package/dist/esm/messages/format.mjs.map +1 -1
  416. package/dist/esm/messages/handoffCue.mjs +0 -36
  417. package/dist/esm/messages/handoffCue.mjs.map +1 -1
  418. package/dist/esm/messages/ids.mjs.map +1 -1
  419. package/dist/esm/messages/injected.mjs +0 -33
  420. package/dist/esm/messages/injected.mjs.map +1 -1
  421. package/dist/esm/messages/langchain.mjs +0 -14
  422. package/dist/esm/messages/langchain.mjs.map +1 -1
  423. package/dist/esm/messages/prune.mjs +1 -184
  424. package/dist/esm/messages/prune.mjs.map +1 -1
  425. package/dist/esm/messages/recency.mjs +0 -32
  426. package/dist/esm/messages/recency.mjs.map +1 -1
  427. package/dist/esm/messages/reducer.mjs +0 -30
  428. package/dist/esm/messages/reducer.mjs.map +1 -1
  429. package/dist/esm/messages/tools.mjs +0 -14
  430. package/dist/esm/messages/tools.mjs.map +1 -1
  431. package/dist/esm/openai/index.mjs.map +1 -1
  432. package/dist/esm/prompts/activityLabel.mjs +9 -79
  433. package/dist/esm/prompts/activityLabel.mjs.map +1 -1
  434. package/dist/esm/responses/index.mjs.map +1 -1
  435. package/dist/esm/run.mjs +2 -538
  436. package/dist/esm/run.mjs.map +1 -1
  437. package/dist/esm/session/AgentSession.mjs +1 -17
  438. package/dist/esm/session/AgentSession.mjs.map +1 -1
  439. package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
  440. package/dist/esm/session/handlers.mjs +0 -7
  441. package/dist/esm/session/handlers.mjs.map +1 -1
  442. package/dist/esm/session/ids.mjs.map +1 -1
  443. package/dist/esm/session/messageSerialization.mjs +0 -4
  444. package/dist/esm/session/messageSerialization.mjs.map +1 -1
  445. package/dist/esm/stream.mjs +1 -93
  446. package/dist/esm/stream.mjs.map +1 -1
  447. package/dist/esm/summarization/index.mjs +0 -27
  448. package/dist/esm/summarization/index.mjs.map +1 -1
  449. package/dist/esm/summarization/node.mjs +0 -273
  450. package/dist/esm/summarization/node.mjs.map +1 -1
  451. package/dist/esm/tools/BashExecutor.mjs +0 -35
  452. package/dist/esm/tools/BashExecutor.mjs.map +1 -1
  453. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -24
  454. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
  455. package/dist/esm/tools/Calculator.mjs.map +1 -1
  456. package/dist/esm/tools/CodeExecutor.mjs +0 -13
  457. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  458. package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
  459. package/dist/esm/tools/ProgrammaticToolCalling.mjs +0 -101
  460. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  461. package/dist/esm/tools/ReadFile.mjs.map +1 -1
  462. package/dist/esm/tools/SkillTool.mjs +0 -5
  463. package/dist/esm/tools/SkillTool.mjs.map +1 -1
  464. package/dist/esm/tools/SubagentTool.mjs +0 -10
  465. package/dist/esm/tools/SubagentTool.mjs.map +1 -1
  466. package/dist/esm/tools/ToolNode.mjs +6 -1038
  467. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  468. package/dist/esm/tools/ToolSearch.mjs +0 -179
  469. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  470. package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -1
  471. package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -1
  472. package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +0 -39
  473. package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -1
  474. package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -1
  475. package/dist/esm/tools/eagerEventExecution.mjs +0 -6
  476. package/dist/esm/tools/eagerEventExecution.mjs.map +1 -1
  477. package/dist/esm/tools/handlers.mjs +1 -41
  478. package/dist/esm/tools/handlers.mjs.map +1 -1
  479. package/dist/esm/tools/intentArg.mjs +1 -132
  480. package/dist/esm/tools/intentArg.mjs.map +1 -1
  481. package/dist/esm/tools/local/CompileCheckTool.mjs +0 -25
  482. package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
  483. package/dist/esm/tools/local/FileCheckpointer.mjs +0 -23
  484. package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -1
  485. package/dist/esm/tools/local/LocalCodingTools.mjs +0 -80
  486. package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
  487. package/dist/esm/tools/local/LocalExecutionEngine.mjs +0 -126
  488. package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
  489. package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
  490. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +0 -12
  491. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
  492. package/dist/esm/tools/local/attachments.mjs +0 -44
  493. package/dist/esm/tools/local/attachments.mjs.map +1 -1
  494. package/dist/esm/tools/local/bashAst.mjs +0 -16
  495. package/dist/esm/tools/local/bashAst.mjs.map +1 -1
  496. package/dist/esm/tools/local/editStrategies.mjs +0 -14
  497. package/dist/esm/tools/local/editStrategies.mjs.map +1 -1
  498. package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
  499. package/dist/esm/tools/local/syntaxCheck.mjs +0 -31
  500. package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -1
  501. package/dist/esm/tools/local/textEncoding.mjs +0 -11
  502. package/dist/esm/tools/local/textEncoding.mjs.map +1 -1
  503. package/dist/esm/tools/local/workspaceFS.mjs +0 -33
  504. package/dist/esm/tools/local/workspaceFS.mjs.map +1 -1
  505. package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
  506. package/dist/esm/tools/schema.mjs +0 -8
  507. package/dist/esm/tools/schema.mjs.map +1 -1
  508. package/dist/esm/tools/search/anthropic.mjs +0 -9
  509. package/dist/esm/tools/search/anthropic.mjs.map +1 -1
  510. package/dist/esm/tools/search/content.mjs.map +1 -1
  511. package/dist/esm/tools/search/crw-scraper.mjs +0 -33
  512. package/dist/esm/tools/search/crw-scraper.mjs.map +1 -1
  513. package/dist/esm/tools/search/crw-search.mjs +0 -2
  514. package/dist/esm/tools/search/crw-search.mjs.map +1 -1
  515. package/dist/esm/tools/search/firecrawl.mjs +0 -25
  516. package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
  517. package/dist/esm/tools/search/format.mjs +0 -30
  518. package/dist/esm/tools/search/format.mjs.map +1 -1
  519. package/dist/esm/tools/search/highlights.mjs +0 -16
  520. package/dist/esm/tools/search/highlights.mjs.map +1 -1
  521. package/dist/esm/tools/search/keenable-scraper.mjs +0 -8
  522. package/dist/esm/tools/search/keenable-scraper.mjs.map +1 -1
  523. package/dist/esm/tools/search/keenable-search.mjs +0 -7
  524. package/dist/esm/tools/search/keenable-search.mjs.map +1 -1
  525. package/dist/esm/tools/search/rerankers.mjs +0 -35
  526. package/dist/esm/tools/search/rerankers.mjs.map +1 -1
  527. package/dist/esm/tools/search/schema.mjs +0 -1
  528. package/dist/esm/tools/search/schema.mjs.map +1 -1
  529. package/dist/esm/tools/search/search.mjs +1 -14
  530. package/dist/esm/tools/search/search.mjs.map +1 -1
  531. package/dist/esm/tools/search/serper-scraper.mjs +0 -46
  532. package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
  533. package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -1
  534. package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
  535. package/dist/esm/tools/search/tool.mjs +0 -25
  536. package/dist/esm/tools/search/tool.mjs.map +1 -1
  537. package/dist/esm/tools/search/utils.mjs +0 -8
  538. package/dist/esm/tools/search/utils.mjs.map +1 -1
  539. package/dist/esm/tools/skillCatalog.mjs +0 -6
  540. package/dist/esm/tools/skillCatalog.mjs.map +1 -1
  541. package/dist/esm/tools/streamedToolCallSeals.mjs +0 -6
  542. package/dist/esm/tools/streamedToolCallSeals.mjs.map +1 -1
  543. package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -2
  544. package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
  545. package/dist/esm/tools/subagent/SubagentExecutor.mjs +3 -213
  546. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  547. package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
  548. package/dist/esm/tools/subagent/childGraphConfig.mjs +0 -4
  549. package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
  550. package/dist/esm/tools/subagent/runtimeLimits.mjs.map +1 -1
  551. package/dist/esm/tools/toolOutputReferences.mjs +1 -322
  552. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
  553. package/dist/esm/types/hitl.mjs +0 -5
  554. package/dist/esm/types/hitl.mjs.map +1 -1
  555. package/dist/esm/utils/callbacks.mjs.map +1 -1
  556. package/dist/esm/utils/errors.mjs +14 -165
  557. package/dist/esm/utils/errors.mjs.map +1 -1
  558. package/dist/esm/utils/events.mjs +0 -10
  559. package/dist/esm/utils/events.mjs.map +1 -1
  560. package/dist/esm/utils/graph.mjs.map +1 -1
  561. package/dist/esm/utils/handlers.mjs +0 -3
  562. package/dist/esm/utils/handlers.mjs.map +1 -1
  563. package/dist/esm/utils/llm.mjs +0 -1
  564. package/dist/esm/utils/llm.mjs.map +1 -1
  565. package/dist/esm/utils/misc.mjs +0 -16
  566. package/dist/esm/utils/misc.mjs.map +1 -1
  567. package/dist/esm/utils/proxy.mjs +0 -26
  568. package/dist/esm/utils/proxy.mjs.map +1 -1
  569. package/dist/esm/utils/run.mjs +0 -6
  570. package/dist/esm/utils/run.mjs.map +1 -1
  571. package/dist/esm/utils/schema.mjs +0 -5
  572. package/dist/esm/utils/schema.mjs.map +1 -1
  573. package/dist/esm/utils/title.mjs +0 -6
  574. package/dist/esm/utils/title.mjs.map +1 -1
  575. package/dist/esm/utils/tokens.mjs +0 -113
  576. package/dist/esm/utils/tokens.mjs.map +1 -1
  577. package/dist/esm/utils/toolContent.mjs +0 -41
  578. package/dist/esm/utils/toolContent.mjs.map +1 -1
  579. package/dist/esm/utils/truncation.mjs +0 -61
  580. package/dist/esm/utils/truncation.mjs.map +1 -1
  581. package/dist/types/agents/AgentContext.d.ts +3 -3
  582. package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +3 -3
  583. package/dist/types/agents/projection.d.ts +1 -1
  584. package/dist/types/events.d.ts +2 -2
  585. package/dist/types/graphs/Graph.d.ts +11 -11
  586. package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
  587. package/dist/types/graphs/createGraph.d.ts +4 -4
  588. package/dist/types/graphs/graphFactory.d.ts +1 -1
  589. package/dist/types/hitl/askUserQuestion.d.ts +1 -1
  590. package/dist/types/hitl/askUserQuestions.d.ts +1 -1
  591. package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
  592. package/dist/types/hooks/types.d.ts +1 -1
  593. package/dist/types/instrumentation.d.ts +1 -1
  594. package/dist/types/langfuse.d.ts +3 -3
  595. package/dist/types/langfuseConfig.d.ts +2 -2
  596. package/dist/types/langfuseRuntimeContext.d.ts +1 -1
  597. package/dist/types/langfuseRuntimeScope.d.ts +2 -2
  598. package/dist/types/langfuseSpanRegistry.d.ts +1 -1
  599. package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
  600. package/dist/types/llm/anthropic/index.d.ts +1 -1
  601. package/dist/types/llm/bedrock/index.d.ts +1 -1
  602. package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
  603. package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
  604. package/dist/types/llm/google/index.d.ts +1 -1
  605. package/dist/types/llm/init.d.ts +2 -2
  606. package/dist/types/llm/invoke.d.ts +6 -6
  607. package/dist/types/llm/mistral/index.d.ts +1 -1
  608. package/dist/types/llm/openai/index.d.ts +2 -2
  609. package/dist/types/llm/openrouter/index.d.ts +2 -2
  610. package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
  611. package/dist/types/llm/providers.d.ts +2 -2
  612. package/dist/types/llm/request.d.ts +2 -2
  613. package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
  614. package/dist/types/llm/streamLimits.d.ts +1 -1
  615. package/dist/types/llm/truncation.d.ts +1 -1
  616. package/dist/types/llm/vertexai/index.d.ts +1 -1
  617. package/dist/types/messages/alternation.d.ts +1 -1
  618. package/dist/types/messages/anthropicToolCache.d.ts +2 -2
  619. package/dist/types/messages/assistantPhase.d.ts +3 -3
  620. package/dist/types/messages/budget.d.ts +1 -1
  621. package/dist/types/messages/cache.d.ts +1 -1
  622. package/dist/types/messages/contextPruning.d.ts +2 -2
  623. package/dist/types/messages/core.d.ts +2 -2
  624. package/dist/types/messages/format.d.ts +2 -2
  625. package/dist/types/messages/ids.d.ts +2 -2
  626. package/dist/types/messages/injected.d.ts +1 -1
  627. package/dist/types/messages/langchain.d.ts +1 -1
  628. package/dist/types/messages/prune.d.ts +3 -3
  629. package/dist/types/openai/index.d.ts +1 -1
  630. package/dist/types/prompts/activityLabel.d.ts +2 -2
  631. package/dist/types/responses/index.d.ts +1 -1
  632. package/dist/types/run.d.ts +3 -3
  633. package/dist/types/session/handlers.d.ts +1 -1
  634. package/dist/types/session/types.d.ts +1 -1
  635. package/dist/types/stream.d.ts +4 -4
  636. package/dist/types/summarization/index.d.ts +1 -1
  637. package/dist/types/summarization/node.d.ts +6 -6
  638. package/dist/types/test/mockTools.d.ts +1 -1
  639. package/dist/types/tools/BashExecutor.d.ts +2 -2
  640. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
  641. package/dist/types/tools/CodeExecutor.d.ts +3 -3
  642. package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
  643. package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
  644. package/dist/types/tools/ReadFile.d.ts +1 -1
  645. package/dist/types/tools/SkillTool.d.ts +1 -1
  646. package/dist/types/tools/SubagentTool.d.ts +3 -3
  647. package/dist/types/tools/ToolNode.d.ts +5 -5
  648. package/dist/types/tools/ToolSearch.d.ts +2 -2
  649. package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
  650. package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
  651. package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
  652. package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
  653. package/dist/types/tools/eagerEventExecution.d.ts +1 -1
  654. package/dist/types/tools/handlers.d.ts +3 -3
  655. package/dist/types/tools/intentArg.d.ts +1 -1
  656. package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
  657. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  658. package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
  659. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  660. package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
  661. package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
  662. package/dist/types/tools/local/bashAst.d.ts +1 -1
  663. package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
  664. package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
  665. package/dist/types/tools/ptcTimeout.d.ts +1 -1
  666. package/dist/types/tools/schema.d.ts +1 -1
  667. package/dist/types/tools/search/anthropic.d.ts +1 -1
  668. package/dist/types/tools/skillCatalog.d.ts +1 -1
  669. package/dist/types/tools/subagent/SubagentExecutor.d.ts +5 -5
  670. package/dist/types/tools/subagent/SubagentReplay.d.ts +3 -3
  671. package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
  672. package/dist/types/types/activityLabel.d.ts +3 -3
  673. package/dist/types/types/graph.d.ts +7 -7
  674. package/dist/types/types/llm.d.ts +9 -9
  675. package/dist/types/types/run.d.ts +7 -7
  676. package/dist/types/types/stream.d.ts +5 -5
  677. package/dist/types/types/summarize.d.ts +2 -2
  678. package/dist/types/types/tools.d.ts +5 -5
  679. package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +1 -1
  680. package/dist/types/utils/errors.d.ts +1 -1
  681. package/dist/types/utils/events.d.ts +1 -1
  682. package/dist/types/utils/handlers.d.ts +3 -3
  683. package/dist/types/utils/llm.d.ts +1 -1
  684. package/dist/types/utils/llmConfig.d.ts +1 -1
  685. package/dist/types/utils/title.d.ts +1 -1
  686. package/package.json +10 -3
  687. package/src/llm/google/utils/common.ts +6 -4
  688. package/src/__tests__/stream.eagerArgsDivergence.test.ts +0 -911
  689. package/src/__tests__/stream.eagerEventExecution.test.ts +0 -5046
  690. package/src/__tests__/stream.streamLimits.test.ts +0 -1982
  691. package/src/agents/__tests__/AgentContext.anthropic.live.test.ts +0 -448
  692. package/src/agents/__tests__/AgentContext.bedrock.live.test.ts +0 -655
  693. package/src/agents/__tests__/AgentContext.openrouter.live.test.ts +0 -128
  694. package/src/agents/__tests__/AgentContext.overflow.test.ts +0 -205
  695. package/src/agents/__tests__/AgentContext.test.ts +0 -2425
  696. package/src/agents/__tests__/projection.test.ts +0 -73
  697. package/src/agents/__tests__/promptCacheLiveHelpers.ts +0 -175
  698. package/src/aggregator.test.ts +0 -1214
  699. package/src/graphs/__tests__/Graph.breakerLifecycle.test.ts +0 -273
  700. package/src/graphs/__tests__/Graph.closeRunStep.test.ts +0 -385
  701. package/src/graphs/__tests__/Graph.contextOverflow.test.ts +0 -1766
  702. package/src/graphs/__tests__/Graph.preemptSignal.test.ts +0 -126
  703. package/src/graphs/__tests__/Graph.reasoning.test.ts +0 -1717
  704. package/src/graphs/__tests__/Graph.subagentResumeState.test.ts +0 -80
  705. package/src/graphs/__tests__/MultiAgentGraph.test.ts +0 -177
  706. package/src/graphs/__tests__/composition.smoke.test.ts +0 -509
  707. package/src/graphs/__tests__/createGraph.test.ts +0 -206
  708. package/src/hooks/__tests__/HookRegistry.test.ts +0 -334
  709. package/src/hooks/__tests__/compactHooks.test.ts +0 -250
  710. package/src/hooks/__tests__/createToolPolicyHook.test.ts +0 -268
  711. package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +0 -405
  712. package/src/hooks/__tests__/executeHooks.test.ts +0 -1294
  713. package/src/hooks/__tests__/integration.test.ts +0 -337
  714. package/src/hooks/__tests__/matchers.test.ts +0 -238
  715. package/src/hooks/__tests__/preemptBoundary.test.ts +0 -152
  716. package/src/hooks/__tests__/toolHooks.test.ts +0 -669
  717. package/src/llm/__tests__/contextOverflowRecovery.test.ts +0 -401
  718. package/src/llm/__tests__/fallbackOverflow.test.ts +0 -287
  719. package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
  720. package/src/llm/anthropic/inherited-content-utils.spec.ts +0 -249
  721. package/src/llm/anthropic/inherited-stream-events.spec.ts +0 -1259
  722. package/src/llm/anthropic/inherited-strict.spec.ts +0 -302
  723. package/src/llm/anthropic/llm.spec.ts +0 -3394
  724. package/src/llm/anthropic/utils/cross-provider-reasoning.test.ts +0 -383
  725. package/src/llm/anthropic/utils/cross-provider-server-tools.test.ts +0 -110
  726. package/src/llm/anthropic/utils/server-tool-inputs.test.ts +0 -508
  727. package/src/llm/anthropic/utils/streaming-tool-input.test.ts +0 -361
  728. package/src/llm/anthropic/utils/stripPrefillCache.test.ts +0 -111
  729. package/src/llm/anthropic/utils/tool-id-normalization.test.ts +0 -287
  730. package/src/llm/bedrock/inherited-cache.spec.ts +0 -144
  731. package/src/llm/bedrock/inherited.spec.ts +0 -724
  732. package/src/llm/bedrock/llm.spec.ts +0 -1533
  733. package/src/llm/bedrock/streamSealDispatch.test.ts +0 -331
  734. package/src/llm/bedrock/toolCache.test.ts +0 -194
  735. package/src/llm/bedrock/utils/cross-provider-reasoning.test.ts +0 -131
  736. package/src/llm/bedrock/utils/cross-provider-server-tools.test.ts +0 -122
  737. package/src/llm/bedrock/utils/message_inputs.test.ts +0 -650
  738. package/src/llm/bedrock/utils/message_outputs.test.ts +0 -85
  739. package/src/llm/bedrock/utils/toolResultCachePoint.test.ts +0 -118
  740. package/src/llm/custom-chat-models.smoke.test.ts +0 -1966
  741. package/src/llm/google/data/gettysburg10.wav +0 -0
  742. package/src/llm/google/data/hotdog.jpg +0 -0
  743. package/src/llm/google/inherited-stream-events.spec.ts +0 -350
  744. package/src/llm/google/llm.spec.ts +0 -1388
  745. package/src/llm/google/streamSmoothing.test.ts +0 -121
  746. package/src/llm/google/utils/common.test.ts +0 -185
  747. package/src/llm/invoke.alternation.test.ts +0 -87
  748. package/src/llm/invoke.handoffCue.test.ts +0 -112
  749. package/src/llm/invoke.streamLimits.test.ts +0 -142
  750. package/src/llm/invoke.test.ts +0 -1198
  751. package/src/llm/mistral/streamSmoothing.test.ts +0 -97
  752. package/src/llm/openai/cacheWriteTokens.test.ts +0 -112
  753. package/src/llm/openai/contentBlocks.test.ts +0 -381
  754. package/src/llm/openai/deepseek.test.ts +0 -747
  755. package/src/llm/openai/inherited-deepseek.spec.ts +0 -347
  756. package/src/llm/openai/inherited-xai.spec.ts +0 -416
  757. package/src/llm/openai/llm.spec.ts +0 -1774
  758. package/src/llm/openai/managedRequests.test.ts +0 -182
  759. package/src/llm/openai/sequentialToolCallSeals.test.ts +0 -199
  760. package/src/llm/openai/streamMetadata.spec.ts +0 -86
  761. package/src/llm/openai/streamMetadataDedup.spec.ts +0 -166
  762. package/src/llm/openai/utils/isReasoningModel.test.ts +0 -90
  763. package/src/llm/openai/utils/messages.test.ts +0 -488
  764. package/src/llm/openrouter/reasoning.test.ts +0 -561
  765. package/src/llm/openrouter/toolCache.test.ts +0 -134
  766. package/src/llm/preempt.test.ts +0 -323
  767. package/src/llm/stream/chunkAdapters.test.ts +0 -202
  768. package/src/llm/stream/reassembly.test.ts +0 -241
  769. package/src/llm/stream/smoother.bench.test.ts +0 -155
  770. package/src/llm/stream/smoother.test.ts +0 -519
  771. package/src/llm/streamLimits.test.ts +0 -450
  772. package/src/llm/truncation.test.ts +0 -242
  773. package/src/llm/vertexai/fixThoughtSignatures.test.ts +0 -154
  774. package/src/llm/vertexai/inherited-stream-events.spec.ts +0 -271
  775. package/src/llm/vertexai/llm.spec.ts +0 -159
  776. package/src/llm/vertexai/repairUsageMetadata.test.ts +0 -54
  777. package/src/llm/vertexai/sealStreamedToolCalls.test.ts +0 -88
  778. package/src/llm/vertexai/streamSealDispatch.test.ts +0 -148
  779. package/src/llm/vertexai/streamSmoothing.test.ts +0 -109
  780. package/src/messages/__tests__/anthropicToolCache.test.ts +0 -339
  781. package/src/messages/__tests__/observationMasking.test.ts +0 -312
  782. package/src/messages/__tests__/recency.test.ts +0 -267
  783. package/src/messages/__tests__/tools.test.ts +0 -473
  784. package/src/messages/alternation.test.ts +0 -212
  785. package/src/messages/assistantPhase.test.ts +0 -75
  786. package/src/messages/cache.tail.test.ts +0 -533
  787. package/src/messages/cache.test.ts +0 -2166
  788. package/src/messages/content.test.ts +0 -362
  789. package/src/messages/contextPruning.test.ts +0 -184
  790. package/src/messages/ensureThinkingBlock.test.ts +0 -1427
  791. package/src/messages/foldToollessToolBlocks.test.ts +0 -596
  792. package/src/messages/formatAgentMessages.reducer.test.ts +0 -162
  793. package/src/messages/formatAgentMessages.skills.test.ts +0 -513
  794. package/src/messages/formatAgentMessages.steer.test.ts +0 -598
  795. package/src/messages/formatAgentMessages.test.ts +0 -8111
  796. package/src/messages/formatAgentMessages.tools.test.ts +0 -522
  797. package/src/messages/formatMessage.test.ts +0 -693
  798. package/src/messages/handoffCue.test.ts +0 -96
  799. package/src/messages/injected.test.ts +0 -107
  800. package/src/messages/labelContentByAgent.test.ts +0 -962
  801. package/src/messages/reducer.spec.ts +0 -32
  802. package/src/messages/shiftIndexTokenCountMap.test.ts +0 -81
  803. package/src/messages/tailCacheConversion.test.ts +0 -161
  804. package/src/openai/__tests__/openai.test.ts +0 -337
  805. package/src/responses/__tests__/responses.test.ts +0 -652
  806. package/src/scripts/abort.ts +0 -157
  807. package/src/scripts/activity-labels/captured.json +0 -56
  808. package/src/scripts/activity-labels/checks.cjs +0 -205
  809. package/src/scripts/activity-labels/corpus.cjs +0 -473
  810. package/src/scripts/activity-labels/report.cjs +0 -203
  811. package/src/scripts/activity-labels/rescore.cjs +0 -102
  812. package/src/scripts/activity-labels/run.ts +0 -705
  813. package/src/scripts/activity-labels/variants.ts +0 -71
  814. package/src/scripts/ant_web_search.ts +0 -159
  815. package/src/scripts/ant_web_search_edge_case.ts +0 -163
  816. package/src/scripts/ant_web_search_error_edge_case.ts +0 -149
  817. package/src/scripts/args.ts +0 -48
  818. package/src/scripts/bedrock-cache-debug.ts +0 -250
  819. package/src/scripts/bedrock-content-aggregation-test.ts +0 -266
  820. package/src/scripts/bedrock-merge-test.ts +0 -107
  821. package/src/scripts/bedrock-parallel-tools-test.ts +0 -204
  822. package/src/scripts/bench-prompt-cache.ts +0 -479
  823. package/src/scripts/caching.ts +0 -132
  824. package/src/scripts/cli.ts +0 -172
  825. package/src/scripts/cli2.ts +0 -133
  826. package/src/scripts/cli3.ts +0 -184
  827. package/src/scripts/cli4.ts +0 -191
  828. package/src/scripts/cli5.ts +0 -191
  829. package/src/scripts/code_exec.ts +0 -214
  830. package/src/scripts/code_exec_files.ts +0 -237
  831. package/src/scripts/code_exec_multi_session.ts +0 -237
  832. package/src/scripts/code_exec_ptc.ts +0 -335
  833. package/src/scripts/code_exec_session.ts +0 -283
  834. package/src/scripts/code_exec_simple.ts +0 -148
  835. package/src/scripts/compare_pi_vs_ours.ts +0 -1259
  836. package/src/scripts/content.ts +0 -139
  837. package/src/scripts/context-overflow-probe.ts +0 -997
  838. package/src/scripts/empty_input.ts +0 -137
  839. package/src/scripts/handoff-test.ts +0 -134
  840. package/src/scripts/local_engine.ts +0 -166
  841. package/src/scripts/local_engine_checkpointer.ts +0 -205
  842. package/src/scripts/local_engine_compile.ts +0 -263
  843. package/src/scripts/local_engine_hooks.ts +0 -226
  844. package/src/scripts/local_engine_image.ts +0 -201
  845. package/src/scripts/local_engine_ptc.ts +0 -151
  846. package/src/scripts/local_engine_workspace.ts +0 -258
  847. package/src/scripts/memory.ts +0 -107
  848. package/src/scripts/multi-agent-chain.ts +0 -332
  849. package/src/scripts/multi-agent-conditional.ts +0 -222
  850. package/src/scripts/multi-agent-document-review-chain.ts +0 -198
  851. package/src/scripts/multi-agent-hybrid-flow.ts +0 -311
  852. package/src/scripts/multi-agent-parallel-start.ts +0 -265
  853. package/src/scripts/multi-agent-parallel.ts +0 -395
  854. package/src/scripts/multi-agent-sequence.ts +0 -217
  855. package/src/scripts/multi-agent-subagent.ts +0 -246
  856. package/src/scripts/multi-agent-supervisor.ts +0 -366
  857. package/src/scripts/multi-agent-test.ts +0 -187
  858. package/src/scripts/openrouter_prompt_cache_live.ts +0 -310
  859. package/src/scripts/parallel-asymmetric-tools-test.ts +0 -275
  860. package/src/scripts/parallel-full-metadata-test.ts +0 -241
  861. package/src/scripts/parallel-tools-test.ts +0 -341
  862. package/src/scripts/preempt-probe.ts +0 -330
  863. package/src/scripts/preempt-scenarios.ts +0 -388
  864. package/src/scripts/programmatic_exec.ts +0 -387
  865. package/src/scripts/programmatic_exec_agent.ts +0 -232
  866. package/src/scripts/search.ts +0 -147
  867. package/src/scripts/sequential-full-metadata-test.ts +0 -198
  868. package/src/scripts/session_live.ts +0 -548
  869. package/src/scripts/simple.ts +0 -226
  870. package/src/scripts/single-agent-metadata-test.ts +0 -196
  871. package/src/scripts/stream.ts +0 -141
  872. package/src/scripts/subagent-configurable-inheritance.ts +0 -252
  873. package/src/scripts/subagent-event-driven-debug.ts +0 -190
  874. package/src/scripts/subagent-tools-debug.ts +0 -160
  875. package/src/scripts/subagent-usage-sink.ts +0 -176
  876. package/src/scripts/summarization-recency.ts +0 -462
  877. package/src/scripts/test-custom-prompt-key.ts +0 -145
  878. package/src/scripts/test-handoff-input.ts +0 -170
  879. package/src/scripts/test-handoff-preamble.ts +0 -278
  880. package/src/scripts/test-handoff-steering.ts +0 -430
  881. package/src/scripts/test-multi-agent-list-handoff.ts +0 -418
  882. package/src/scripts/test-parallel-agent-labeling.ts +0 -327
  883. package/src/scripts/test-parallel-handoffs.ts +0 -292
  884. package/src/scripts/test-thinking-handoff-bedrock.ts +0 -154
  885. package/src/scripts/test-thinking-handoff.ts +0 -156
  886. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +0 -166
  887. package/src/scripts/test-tool-before-handoff-role-order.ts +0 -276
  888. package/src/scripts/test-tools-before-handoff.ts +0 -222
  889. package/src/scripts/test_code_api.ts +0 -354
  890. package/src/scripts/thinking-bedrock.ts +0 -160
  891. package/src/scripts/thinking-vertexai.ts +0 -168
  892. package/src/scripts/thinking.ts +0 -172
  893. package/src/scripts/tool_search.ts +0 -153
  894. package/src/scripts/tools.ts +0 -163
  895. package/src/session/__tests__/JsonlSessionStore.test.ts +0 -1463
  896. package/src/session/__tests__/handlers.test.ts +0 -161
  897. package/src/specs/activity-label-observability.live.test.ts +0 -262
  898. package/src/specs/activity-label-observability.test.ts +0 -167
  899. package/src/specs/activity-label-prompt.test.ts +0 -359
  900. package/src/specs/activity-label-trace-seed.test.ts +0 -47
  901. package/src/specs/activity-phase-label.test.ts +0 -306
  902. package/src/specs/agent-handoffs.live.test.ts +0 -140
  903. package/src/specs/agent-handoffs.test.ts +0 -2465
  904. package/src/specs/anthropic.simple.test.ts +0 -453
  905. package/src/specs/ask-user-question-batch.test.ts +0 -289
  906. package/src/specs/ask-user-questions.live.test.ts +0 -185
  907. package/src/specs/ask-user-questions.test.ts +0 -293
  908. package/src/specs/azure.simple.test.ts +0 -502
  909. package/src/specs/bedrock-toolless.live.test.ts +0 -123
  910. package/src/specs/bedrock-truncation.live.test.ts +0 -191
  911. package/src/specs/cache.simple.test.ts +0 -416
  912. package/src/specs/context-accuracy.live.test.ts +0 -409
  913. package/src/specs/context-overflow-recovery.live.test.ts +0 -213
  914. package/src/specs/context-usage-event.test.ts +0 -117
  915. package/src/specs/context-usage.live.test.ts +0 -297
  916. package/src/specs/custom-event-await.test.ts +0 -304
  917. package/src/specs/deepseek.simple.test.ts +0 -290
  918. package/src/specs/deterministic-trace-id.test.ts +0 -43
  919. package/src/specs/discovered-tools.test.ts +0 -217
  920. package/src/specs/durability-checkpoint.integration.test.ts +0 -243
  921. package/src/specs/graph-subagent.live.test.ts +0 -242
  922. package/src/specs/graph-subagent.test.ts +0 -322
  923. package/src/specs/handoffCue.test.ts +0 -165
  924. package/src/specs/langfuse-callbacks.test.ts +0 -1578
  925. package/src/specs/langfuse-config.test.ts +0 -247
  926. package/src/specs/langfuse-instrumentation.test.ts +0 -393
  927. package/src/specs/langfuse-metadata.test.ts +0 -245
  928. package/src/specs/langfuse-routing.integration.test.ts +0 -844
  929. package/src/specs/langfuse-runtime-context.test.ts +0 -92
  930. package/src/specs/langfuse-span-registry.test.ts +0 -87
  931. package/src/specs/langfuse-tool-output-tracing.test.ts +0 -1858
  932. package/src/specs/langfuse-trace-shaping.test.ts +0 -591
  933. package/src/specs/moonshot.simple.test.ts +0 -367
  934. package/src/specs/multi-agent-summarization.test.ts +0 -396
  935. package/src/specs/openai.simple.test.ts +0 -315
  936. package/src/specs/openrouter.simple.test.ts +0 -275
  937. package/src/specs/preemptSeal.test.ts +0 -678
  938. package/src/specs/prune.test.ts +0 -3741
  939. package/src/specs/reasoning.test.ts +0 -201
  940. package/src/specs/run-step-timestamps.test.ts +0 -414
  941. package/src/specs/spec.utils.ts +0 -15
  942. package/src/specs/subagent.test.ts +0 -864
  943. package/src/specs/summarization-unit.test.ts +0 -973
  944. package/src/specs/summarization.test.ts +0 -3823
  945. package/src/specs/summarize-prune.test.ts +0 -376
  946. package/src/specs/thinking-handoff.test.ts +0 -621
  947. package/src/specs/thinking-prune.test.ts +0 -827
  948. package/src/specs/token-accounting-e2e.test.ts +0 -1034
  949. package/src/specs/token-accounting-pipeline.test.ts +0 -1008
  950. package/src/specs/token-distribution-edge-case.test.ts +0 -315
  951. package/src/specs/token-memoization.test.ts +0 -40
  952. package/src/specs/tokens.test.ts +0 -1000
  953. package/src/specs/tool-error-resume.test.ts +0 -194
  954. package/src/specs/tool-error.test.ts +0 -198
  955. package/src/specs/vllm-reasoning-toolcalls.test.ts +0 -340
  956. package/src/stream.dispatch.test.ts +0 -63
  957. package/src/stream.test.ts +0 -144
  958. package/src/summarization/__tests__/aggregator.test.ts +0 -236
  959. package/src/summarization/__tests__/node.test.ts +0 -1996
  960. package/src/summarization/__tests__/trigger.test.ts +0 -149
  961. package/src/summarization/chunkHandler.test.ts +0 -196
  962. package/src/test/mockTools.ts +0 -386
  963. package/src/tools/Calculator.test.ts +0 -278
  964. package/src/tools/__tests__/BashExecutor.test.ts +0 -108
  965. package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +0 -939
  966. package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +0 -858
  967. package/src/tools/__tests__/CodeExecutor.stateful.test.ts +0 -124
  968. package/src/tools/__tests__/LocalExecutionRoots.test.ts +0 -8
  969. package/src/tools/__tests__/LocalExecutionTools.test.ts +0 -2733
  970. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +0 -318
  971. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -1557
  972. package/src/tools/__tests__/ReadFile.test.ts +0 -44
  973. package/src/tools/__tests__/SkillTool.test.ts +0 -442
  974. package/src/tools/__tests__/SubagentExecutor.test.ts +0 -3728
  975. package/src/tools/__tests__/SubagentReplay.test.ts +0 -329
  976. package/src/tools/__tests__/SubagentTool.test.ts +0 -149
  977. package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +0 -595
  978. package/src/tools/__tests__/ToolNode.eagerEventExecution.test.ts +0 -1191
  979. package/src/tools/__tests__/ToolNode.invalidToolCalls.test.ts +0 -757
  980. package/src/tools/__tests__/ToolNode.langfuse.test.ts +0 -57
  981. package/src/tools/__tests__/ToolNode.onResultCompletion.test.ts +0 -736
  982. package/src/tools/__tests__/ToolNode.outputReferences.test.ts +0 -1710
  983. package/src/tools/__tests__/ToolNode.runtimeState.test.ts +0 -120
  984. package/src/tools/__tests__/ToolNode.session.test.ts +0 -1352
  985. package/src/tools/__tests__/ToolNode.streamLimits.test.ts +0 -69
  986. package/src/tools/__tests__/ToolSearch.integration.test.ts +0 -161
  987. package/src/tools/__tests__/ToolSearch.test.ts +0 -1227
  988. package/src/tools/__tests__/annotateMessagesForLLM.test.ts +0 -561
  989. package/src/tools/__tests__/directToolHITLResumeScope.test.ts +0 -980
  990. package/src/tools/__tests__/directToolHooks.test.ts +0 -700
  991. package/src/tools/__tests__/eagerEventExecution.session.test.ts +0 -92
  992. package/src/tools/__tests__/handlers.test.ts +0 -997
  993. package/src/tools/__tests__/hitl.test.ts +0 -4663
  994. package/src/tools/__tests__/intentArg.test.ts +0 -357
  995. package/src/tools/__tests__/intentCoverage.test.ts +0 -139
  996. package/src/tools/__tests__/localToolNames.test.ts +0 -75
  997. package/src/tools/__tests__/skillCatalog.test.ts +0 -161
  998. package/src/tools/__tests__/subagentHooks.test.ts +0 -1651
  999. package/src/tools/__tests__/toolOutputReferences.test.ts +0 -515
  1000. package/src/tools/__tests__/workspaceSeam.test.ts +0 -147
  1001. package/src/tools/local/__tests__/FileCheckpointer.test.ts +0 -162
  1002. package/src/tools/local/__tests__/editStrategies.test.ts +0 -134
  1003. package/src/tools/search/content.test.ts +0 -173
  1004. package/src/tools/search/crw.test.ts +0 -836
  1005. package/src/tools/search/format.test.ts +0 -242
  1006. package/src/tools/search/http-agent.test.ts +0 -133
  1007. package/src/tools/search/jina-reranker.test.ts +0 -306
  1008. package/src/tools/search/keenable-scraper.test.ts +0 -153
  1009. package/src/tools/search/keenable.test.ts +0 -183
  1010. package/src/tools/search/outcome.test.ts +0 -90
  1011. package/src/tools/search/output.md +0 -2775
  1012. package/src/tools/search/rag-api-reranker.test.ts +0 -891
  1013. package/src/tools/search/source-processing.test.ts +0 -516
  1014. package/src/tools/search/tavily.test.ts +0 -965
  1015. package/src/tools/search/test.html +0 -884
  1016. package/src/tools/search/test.md +0 -643
  1017. package/src/tools/subagent/__tests__/SubagentExecutionRegistry.test.ts +0 -637
  1018. package/src/tools/subagent/__tests__/SubagentExecutor.lazy.test.ts +0 -3054
  1019. package/src/tools/subagent/__tests__/childGraphConfig.test.ts +0 -521
  1020. package/src/utils/__tests__/apportion.test.ts +0 -32
  1021. package/src/utils/__tests__/errors.test.ts +0 -270
  1022. package/src/utils/__tests__/fixtures/contextOverflowSignatures.ts +0 -336
  1023. package/src/utils/__tests__/redactSecrets.test.ts +0 -56
  1024. package/src/utils/__tests__/truncation.test.ts +0 -66
  1025. package/src/utils/llm.test.ts +0 -18
  1026. package/src/utils/proxy.test.ts +0 -176
  1027. package/src/utils/toolContent.test.ts +0 -1432
@@ -24,8 +24,6 @@ let _langchain_langgraph = require("@langchain/langgraph");
24
24
  let _langchain_core_messages = require("@langchain/core/messages");
25
25
  let _langchain_core_singletons = require("@langchain/core/singletons");
26
26
  //#region src/tools/ToolNode.ts
27
- /** Host-facing batch requests must not carry the batch's breaker scope —
28
- * hosts spread `configurable` into their own run configs. */
29
27
  function stripRunBreakerScope(configurable) {
30
28
  if (configurable == null || !("lc_run_breaker_scope" in configurable)) return configurable;
31
29
  const { [require_streamLimits.RUN_BREAKER_SCOPE_CONFIG_KEY]: _scope, ...rest } = configurable;
@@ -63,12 +61,6 @@ function createToolErrorOwnership() {
63
61
  undispatched: /* @__PURE__ */ new Set()
64
62
  };
65
63
  }
66
- /**
67
- * Produces the provider preview and, when requested, the exact registry prefix
68
- * in one bounded traversal. String outputs already exist in memory when a tool
69
- * returns them; structured outputs must never be fully JSON-materialized before
70
- * either limit applies.
71
- */
72
64
  function serializeToolOutputWithinLimits(output, maxToolResultChars, registryPrefixChars = 0) {
73
65
  if (typeof output === "string") return {
74
66
  content: require_truncation.truncateToolResultContent(output, maxToolResultChars),
@@ -83,19 +75,12 @@ function serializeToolOutputWithinLimits(output, maxToolResultChars, registryPre
83
75
  const TOOL_NODE_RUN_NAME = "tool_batch";
84
76
  const NANOID_URL_ALPHABET = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
85
77
  const RUNTIME_HANDOFF_GROUP_OFFSET = 2 ** 48;
86
- /**
87
- * Helper to check if a value is a Send object
88
- */
89
78
  function isSend(value) {
90
79
  return value instanceof _langchain_langgraph.Send;
91
80
  }
92
81
  function isHandoffToolName(name) {
93
82
  return name.startsWith("lc_transfer_to_");
94
83
  }
95
- /**
96
- * Encodes 48 random bits from the persisted batch key into a safe integer.
97
- * The high offset keeps runtime groups disjoint from low, structural group IDs.
98
- */
99
84
  function getRuntimeHandoffGroupId(batch) {
100
85
  let value = 0;
101
86
  for (const char of batch.slice(0, 8)) {
@@ -114,13 +99,6 @@ function findHandoffMessage(messages, destination) {
114
99
  if (isStandardHandoff || isConditionalHandoff) return toolMessage;
115
100
  }
116
101
  }
117
- /**
118
- * Format a fail-closed diagnostic for malformed approval-decision
119
- * fields. Hosts deserialize resume payloads from untyped JSON, so
120
- * `responseText` and `updatedInput` can land here as anything; the
121
- * blocking ToolMessage carries this string so the host can debug the
122
- * exact wire shape that was rejected.
123
- */
124
102
  function describeOfferedShape(value) {
125
103
  if (value === void 0) return "<missing>";
126
104
  if (value === null) return "null";
@@ -146,13 +124,6 @@ function getAssistantBatchReplayKey(batch, runId, threadId) {
146
124
  batch.messageCount
147
125
  ]);
148
126
  }
149
- /**
150
- * Build the `tool_approval` interrupt payload from the set of pending
151
- * `ask`-decision entries collected during PreToolUse hook handling.
152
- * Pure function — doesn't touch ToolNode state — so it lives at module
153
- * scope. The interrupt itself is raised by the caller (which still
154
- * needs `interrupt()` plus the AsyncLocalStorage anchoring shim).
155
- */
156
127
  function buildToolApprovalInterruptPayload(askEntries, hookSessionId) {
157
128
  return {
158
129
  type: "tool_approval",
@@ -178,14 +149,6 @@ function buildToolApprovalInterruptPayload(askEntries, hookSessionId) {
178
149
  }))
179
150
  };
180
151
  }
181
- /**
182
- * Build a `tool_call_id → ToolApprovalDecision` map from the host's
183
- * resume value. Hosts may return decisions either as an array (one per
184
- * action_request, in order) or as a record keyed by `tool_call_id`. Any
185
- * unrecognized shape (or a decision missing for a given call id) is
186
- * treated as "no decision" by callers — typically rejected so the run
187
- * doesn't silently invoke a tool the human never approved.
188
- */
189
152
  function normalizeApprovalDecisions(callIds, resumeValue) {
190
153
  const map = /* @__PURE__ */ new Map();
191
154
  if (resumeValue == null) return map;
@@ -200,48 +163,6 @@ function normalizeApprovalDecisions(callIds, resumeValue) {
200
163
  }
201
164
  return map;
202
165
  }
203
- /**
204
- * Merges code execution session context into the sessions map.
205
- *
206
- * The codeapi worker reports two distinct ids on a code-execution result:
207
- * - `artifact.session_id` (the `sessionId` arg here) is the EXEC session
208
- * — the sandbox VM that ran the code. It's transient and torn down
209
- * post-execution; subsequent calls cannot reuse it as a sandbox.
210
- * - `file.storage_session_id` on each `artifact.files[i]` is the STORAGE
211
- * session — the file-server bucket prefix where the artifact actually
212
- * lives and is served from.
213
- *
214
- * Per-file `storage_session_id` is preserved (not overwritten with the
215
- * exec id) because `_injected_files` are looked up against the
216
- * file-server's storage path on subsequent tool calls. Stomping the
217
- * storage id with the exec id silently 404s every follow-up tool call
218
- * within the same run — `cat /mnt/data/foo.txt` reports "No such file
219
- * or directory" because the worker can't mount a file at a path the
220
- * storage doesn't know about. Fall back to the exec id only when the
221
- * per-file id is absent (e.g. inline `content` files have no persistent
222
- * storage location).
223
- */
224
- /**
225
- * Builds a `CodeEnvFile` ref from an arbitrary `FileRef`-like input,
226
- * narrowing onto the discriminated union: `kind: 'skill'` requires
227
- * `version`, other kinds forbid it.
228
- *
229
- * Defaults `kind` to `'user'` when unset — most ad-hoc files are
230
- * user-private; shared resources (skills/agents) populate their kind
231
- * upstream. A skill ref missing `version` falls back to `'user'` so
232
- * the upstream contract bug surfaces as a degraded sessionKey rather
233
- * than a runtime crash; primeSkillFiles is the only writer, and it
234
- * always sets `version` — see LC packages/api/src/agents/skillFiles.ts.
235
- *
236
- * `resource_id` carries the entity-that-owns-this-file's-session
237
- * identity (skill `_id` etc.); falls back to `id` (the storage
238
- * file_id) for inputs that haven't been updated to send the field
239
- * explicitly. The fallback degrades sessionKey resolution on the
240
- * codeapi side for shared kinds (it'll match the storage nanoid
241
- * against a skill _id and 403) — but won't crash, so an unmigrated
242
- * client still produces a diagnosable error instead of a stack
243
- * trace.
244
- */
245
166
  function toInjectedFileRef(file, execSessionId) {
246
167
  const base = {
247
168
  id: file.id,
@@ -314,121 +235,32 @@ var ToolNode = class extends require_run.RunnableCallable {
314
235
  agentLangfuse;
315
236
  toolCallStepIds;
316
237
  errorHandler;
317
- /**
318
- * Fallback error-completion ownership for calls that reach `runTool`
319
- * outside a batch context (direct `runTool` use in tests / embedders).
320
- * Batch-scoped ownership is threaded via `RunToolBatchContext` instead —
321
- * see {@link ToolErrorOwnership} for why per-invocation scoping matters.
322
- */
323
238
  looseErrorOwnership = createToolErrorOwnership();
324
239
  toolUsageCount;
325
- /** Maps toolCallId → turn captured in runTool, used by handleRunToolCompletions */
326
240
  toolCallTurns = /* @__PURE__ */ new Map();
327
- /**
328
- * `call.id → turn` map dedicated to the direct-path lifecycle so the
329
- * turn assigned on first entry is REUSED on LangGraph resume.
330
- * Distinct from `toolCallTurns` (which is cleared at the start of
331
- * every `run()` to keep per-batch event-dispatch metadata fresh) —
332
- * the direct path needs stability across re-entries triggered by
333
- * `interrupt()` resumes (Codex P2 #30). Cleared with the rest of
334
- * the per-Run state in `clearHeavyState`-equivalent flushes when
335
- * the Run ends.
336
- */
337
241
  directPathTurns = /* @__PURE__ */ new Map();
338
- /** Terminal results from interrupting siblings that must survive a
339
- * LangGraph replay of the containing ToolNode. Includes the sidecar data
340
- * the fresh batch needs for hook-context injection and completion events. */
341
242
  settledInterruptingResults = /* @__PURE__ */ new Map();
342
- /** Tool registry for filtering (lazy computation of programmatic maps) */
343
243
  toolRegistry;
344
- /** Cached programmatic tools (computed once on first PTC call) */
345
244
  programmaticCache;
346
- /** Reference to Graph's sessions map for automatic session injection */
347
245
  sessions;
348
- /** When true, dispatches ON_TOOL_EXECUTE events instead of invoking tools directly */
349
246
  eventDrivenMode = false;
350
- /** Opt-in stream-layer prestart config for event-driven tools. */
351
247
  eagerEventToolExecution;
352
- /** Host tools that write to the code sandbox and share its exec session. */
353
248
  codeSessionToolNames;
354
- /** Shared per-run prestarted tool registry populated by ChatModelStreamHandler. */
355
249
  eagerEventToolExecutions;
356
- /** Shared per-run per-tool turn counter used by eager and normal event dispatch. */
357
250
  eagerEventToolUsageCount;
358
- /**
359
- * Shared per-run eager prestart circuit breaker. Tool names added here
360
- * (when a prestarted execution's args mismatch the final request) are no
361
- * longer prestarted by the stream handler for the rest of the run.
362
- */
363
251
  eagerEventToolSuppressions;
364
- /** Agent ID for event-driven mode */
365
252
  agentId;
366
- /**
367
- * ID of the agent that owns this tool node, whenever the graph knows it
368
- * (including top-level agents in a multi-agent graph). Surfaced to hooks as
369
- * `executingAgentId` so they can attribute a tool batch to a specific agent
370
- * even where `agentId` (the subagent-scope marker) is undefined.
371
- */
372
253
  executingAgentId;
373
- /** Tool names that bypass event dispatch and execute directly (e.g., graph-managed handoff tools) */
374
254
  directToolNames;
375
- /**
376
- * Tool names whose in-process body may raise a LangGraph `interrupt()`
377
- * mid-execution (e.g. `ask_user_question`). Used only to REORDER within
378
- * the direct group: a tool named here that is *already* direct (a real
379
- * in-process graphTool — the only kind whose body can reach
380
- * `interrupt()`) is scheduled ahead of its non-interrupting direct
381
- * siblings, so a mid-body interrupt unwinds the ToolNode before a
382
- * non-idempotent sibling executes and LangGraph's resume-time batch
383
- * re-execution can't double it. This set is deliberately NOT folded
384
- * into direct classification: a name that resolves to a schema-only
385
- * event stub (an inherited `toolDefinition` with no executable
386
- * instance) stays event-dispatched — forcing it direct would invoke
387
- * the stub, which throws. See {@link t.ToolNodeOptions.interruptingToolNames}.
388
- */
389
255
  interruptingToolNames;
390
- /**
391
- * File checkpointer extracted from the local coding tool bundle when
392
- * `toolExecution.local.fileCheckpointing === true`. Exposed via
393
- * {@link getFileCheckpointer}. Undefined when checkpointing is off
394
- * or the local coding suite isn't bound to this node.
395
- */
396
256
  fileCheckpointer;
397
- /** Maximum characters allowed in a single tool result before truncation. */
398
257
  maxToolResultChars;
399
- /** Hook registry for PreToolUse/PostToolUse lifecycle hooks */
400
258
  hookRegistry;
401
- /**
402
- * Run-scoped HITL config. When `enabled`, `ask` decisions from
403
- * PreToolUse hooks raise a LangGraph `interrupt()` instead of being
404
- * treated as fail-closed denies.
405
- */
406
259
  humanInTheLoop;
407
- /**
408
- * Registry of tool outputs keyed by `tool<idx>turn<turn>`.
409
- *
410
- * Populated only when `toolOutputReferences.enabled` is true. The
411
- * registry owns the run-scoped state (turn counter, last-seen runId,
412
- * warn-once memo, stored outputs), so sharing a single instance
413
- * across multiple ToolNodes in a run lets cross-agent `{{…}}`
414
- * references resolve — which is why multi-agent graphs pass the
415
- * *same* instance to every ToolNode they compile rather than each
416
- * ToolNode building its own.
417
- */
418
260
  toolOutputRegistry;
419
- /** Run-scoped selection for swapping remote code tools to local executors. */
420
261
  toolExecution;
421
- /** Owning graph's run-scoped breaker signal, composed into each batch's config. */
422
262
  getBreakerSignal;
423
- /** Owning graph's immutable run scope; captured once per batch. */
424
263
  getRunScope;
425
- /**
426
- * Monotonic counter used to mint a unique scope id for anonymous
427
- * batches (ones invoked without a `run_id` in
428
- * `config.configurable`). Each such batch gets its own registry
429
- * partition so concurrent anonymous invocations can't delete each
430
- * other's in-flight state.
431
- */
432
264
  anonBatchCounter = 0;
433
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 }) {
434
266
  super({
@@ -468,17 +300,6 @@ var ToolNode = class extends require_run.RunnableCallable {
468
300
  this.getRunScope = getRunScope;
469
301
  this.fileCheckpointer = fileCheckpointer;
470
302
  this.applyToolExecutionOverrides();
471
- /**
472
- * Precedence: an explicitly passed `toolOutputRegistry` instance
473
- * wins over a config object so a host (`Graph`) can share one
474
- * registry across many ToolNodes. When only the config is
475
- * provided (direct ToolNode usage), build a local registry so
476
- * the feature still works without graph-level plumbing. Registry
477
- * caps are intentionally decoupled from `maxToolResultChars`:
478
- * the registry stores the raw untruncated output so a later
479
- * `{{…}}` substitution pipes the full payload into the next
480
- * tool, even when the LLM saw a truncated preview.
481
- */
482
303
  if (toolOutputRegistry != null) this.toolOutputRegistry = toolOutputRegistry;
483
304
  else if (toolOutputReferences?.enabled === true) this.toolOutputRegistry = new require_toolOutputReferences.ToolOutputReferenceRegistry({
484
305
  maxOutputSize: toolOutputReferences.maxOutputSize,
@@ -499,24 +320,9 @@ var ToolNode = class extends require_run.RunnableCallable {
499
320
  agentId: this.executingAgentId
500
321
  }), () => super.invoke(input, scopedOptions));
501
322
  }
502
- /**
503
- * Returns the run-scoped tool output registry, or `undefined` when
504
- * the feature is disabled.
505
- *
506
- * @internal Exposed for test observation only. Host code should rely
507
- * on `{{tool<i>turn<n>}}` substitution at tool-invocation time and
508
- * not mutate the registry directly.
509
- */
510
323
  _unsafeGetToolOutputRegistry() {
511
324
  return this.toolOutputRegistry;
512
325
  }
513
- /**
514
- * Replaces known remote Code API tools with local-process tools when
515
- * `RunConfig.toolExecution.engine === 'local'`. In event-driven mode those
516
- * names are also marked direct so the SDK executes them locally instead of
517
- * dispatching the batch to a host-side remote sandbox handler. When the
518
- * local coding suite is enabled, this also injects file/search/edit tools.
519
- */
520
326
  applyToolExecutionOverrides() {
521
327
  const resolved = require_resolveLocalExecutionTools.resolveLocalExecutionTools({
522
328
  toolMap: this.toolMap,
@@ -529,16 +335,6 @@ var ToolNode = class extends require_run.RunnableCallable {
529
335
  this.directToolNames = new Set([...this.directToolNames ?? /* @__PURE__ */ new Set(), ...resolved.directToolNames]);
530
336
  this.programmaticCache = void 0;
531
337
  }
532
- /**
533
- * Returns the per-Run file checkpointer when
534
- * `toolExecution.local.fileCheckpointing === true`. Hosts call
535
- * `rewind()` on the returned object to restore captured pre-write
536
- * file contents — the standard "undo a tool batch" pattern. Returns
537
- * undefined when checkpointing is disabled or the local coding suite
538
- * isn't bound. Manual review (finding E): without this getter, the
539
- * config flag was a silent no-op outside of direct
540
- * `createLocalCodingToolBundle()` use.
541
- */
542
338
  getFileCheckpointer() {
543
339
  return this.fileCheckpointer;
544
340
  }
@@ -571,22 +367,10 @@ var ToolNode = class extends require_run.RunnableCallable {
571
367
  if (suggestion == null) return `Tool "${callName}" not found.`;
572
368
  return `Tool "${callName}" not found. Did you mean "${suggestion}"? Handoff tool names must match exactly.`;
573
369
  }
574
- /**
575
- * Flush per-Run direct replay state. Called by the Graph at end-of-Run via
576
- * `clearHeavyState`. The state intentionally survives `run()` re-entry so
577
- * interrupt + resume keeps both original turn slots and terminal sibling
578
- * outputs, but it would otherwise grow linearly and could collide across
579
- * Runs if a provider reused call IDs. Hosts can also call this directly if
580
- * they reuse a ToolNode across batches outside of a Graph.
581
- */
582
370
  clearDirectPathTurns() {
583
371
  this.directPathTurns.clear();
584
372
  this.settledInterruptingResults.clear();
585
373
  }
586
- /**
587
- * Returns cached programmatic tools, computing once on first access.
588
- * Single iteration builds both toolMap and toolDefs simultaneously.
589
- */
590
374
  getProgrammaticTools() {
591
375
  if (this.programmaticCache) return this.programmaticCache;
592
376
  const toolMap = /* @__PURE__ */ new Map();
@@ -604,10 +388,6 @@ var ToolNode = class extends require_run.RunnableCallable {
604
388
  };
605
389
  return this.programmaticCache;
606
390
  }
607
- /**
608
- * Returns a snapshot of the current tool usage counts.
609
- * @returns A ReadonlyMap where keys are tool names and values are their usage counts.
610
- */
611
391
  getToolUsageCounts() {
612
392
  return new Map(this.toolUsageCount);
613
393
  }
@@ -642,14 +422,6 @@ var ToolNode = class extends require_run.RunnableCallable {
642
422
  this.recordToolUsageTurn(toolName, turn, callId);
643
423
  if (this.canConsumeEagerEventExecution(runId)) this.eagerEventToolUsageCount?.set(toolName, Math.max(this.eagerEventToolUsageCount.get(toolName) ?? 0, turn + 1));
644
424
  }
645
- /**
646
- * Runs a single tool call with error handling.
647
- *
648
- * `batchIndex` is the tool's position within the current ToolNode
649
- * batch and, together with `this.currentTurn`, forms the key used to
650
- * register the output for future `{{tool<idx>turn<turn>}}`
651
- * substitutions. Omit when no registration should occur.
652
- */
653
425
  async runTool(call, config, batchContext = {}) {
654
426
  const { batchIndex, turn, batchScopeId, resolvedArgsByCallId, preBatchSnapshot, runInput } = batchContext;
655
427
  const tool = this.toolMap.get(call.name);
@@ -658,42 +430,11 @@ var ToolNode = class extends require_run.RunnableCallable {
658
430
  const resolveOptions = { substituteIntentKey: this.toolDeclaresBusinessIntent(call.name) };
659
431
  if (preBatchSnapshot != null) resolveFn = (_runId, args) => preBatchSnapshot.resolve(args, resolveOptions);
660
432
  else if (registry != null) resolveFn = (runIdArg, args) => registry.resolve(runIdArg, args, resolveOptions);
661
- /**
662
- * Precompute the reference key once per call — captured locally
663
- * so concurrent `invoke()` calls on the same ToolNode cannot race
664
- * on a shared turn field.
665
- */
666
433
  const refKey = registry != null && batchIndex != null && turn != null ? require_toolOutputReferences.buildReferenceKey(batchIndex, turn) : void 0;
667
- /**
668
- * Hoisted outside the try so the catch branch can append
669
- * `[unresolved refs: …]` to error messages — otherwise the LLM
670
- * only sees a generic error when it references a bad key, losing
671
- * the self-correction signal this feature is meant to provide.
672
- */
673
434
  let unresolvedRefs = [];
674
- /**
675
- * Use the caller-provided `batchScopeId` when threaded from
676
- * `run()` (so anonymous batches get their own unique scope).
677
- * Fall back to the config's `run_id` when runTool is invoked
678
- * from a context that doesn't thread it — that still preserves
679
- * the runId-based partitioning for named runs.
680
- */
681
435
  const runId = batchScopeId ?? config.configurable?.run_id;
682
436
  try {
683
437
  if (tool === void 0) throw new Error(this.getUnknownToolErrorMessage(call.name));
684
- /**
685
- * `usageCount` is the per-tool-name invocation index that
686
- * web-search and other tools observe via `invokeParams.turn`.
687
- * It is intentionally distinct from the outer `turn` parameter
688
- * (the batch turn used for ref keys); the latter is captured
689
- * before the try block when constructing `refKey`.
690
- *
691
- * Prefer the value `runDirectToolWithLifecycleHooks` already
692
- * incremented (Codex P2 #27) — its hook wants the SAME turn
693
- * the tool will execute under. When called from a path that
694
- * doesn't pre-increment (event dispatch, the no-hooks
695
- * shortcut), do the read+increment here.
696
- */
697
438
  const usageCount = batchContext.usageCount ?? (() => {
698
439
  const next = this.toolUsageCount.get(call.name) ?? 0;
699
440
  this.toolUsageCount.set(call.name, next + 1);
@@ -705,12 +446,6 @@ var ToolNode = class extends require_run.RunnableCallable {
705
446
  const { resolved, unresolved } = resolveFn(runId, args);
706
447
  args = resolved;
707
448
  unresolvedRefs = unresolved;
708
- /**
709
- * Expose the post-substitution args to downstream completion
710
- * events so audit logs / host-side `ON_RUN_STEP_COMPLETED`
711
- * handlers observe what actually ran, not the `{{…}}`
712
- * template. Only string/object args are worth recording.
713
- */
714
449
  if (resolvedArgsByCallId != null && call.id != null && call.id !== "" && resolved !== call.args && typeof resolved === "object") resolvedArgsByCallId.set(call.id, resolved);
715
450
  }
716
451
  const stepId = this.toolCallStepIds?.get(call.id);
@@ -739,16 +474,6 @@ var ToolNode = class extends require_run.RunnableCallable {
739
474
  ...invokeParams,
740
475
  toolRegistry: this.toolRegistry
741
476
  };
742
- /**
743
- * Inject session context for code execution tools when available.
744
- * Each file uses its own session_id (supporting multi-session file tracking).
745
- * Both session_id and _injected_files are injected directly to invokeParams
746
- * (not inside args) so they bypass Zod schema validation and reach config.toolCall.
747
- *
748
- * session_id is always injected when available, but concrete file refs
749
- * still need to travel through `_injected_files`; the legacy
750
- * `/files/<session_id>` fallback was removed from the executors.
751
- */
752
477
  if (this.participatesInCodeSession(call.name)) {
753
478
  const codeSession = this.sessions?.get("execute_code");
754
479
  const execSessionId = codeSession?.session_id;
@@ -759,25 +484,12 @@ var ToolNode = class extends require_run.RunnableCallable {
759
484
  };
760
485
  if (codeSession?.files != null && codeSession.files.length > 0) invokeParams._injected_files = codeSession.files.map((file) => toInjectedFileRef(file, execSessionId));
761
486
  }
762
- /**
763
- * Stateful runtime session hint — orthogonal to the transient
764
- * exec-session above, and injected independently (a first call has a
765
- * hint but no exec session yet). Explicit host hint wins; otherwise
766
- * fall back to the conversation's thread_id.
767
- */
768
487
  const runtimeSessionHint = this.resolveRuntimeSessionHint(config);
769
488
  if (runtimeSessionHint != null) invokeParams = {
770
489
  ...invokeParams,
771
490
  _runtime_session_hint: runtimeSessionHint
772
491
  };
773
492
  }
774
- /**
775
- * Forward the graph state as langgraph 1.4's `runtime.state` so
776
- * tools can read it off their second argument instead of the
777
- * deprecated `getCurrentTaskInput()` (which relies on
778
- * `node:async_hooks` and is browser-incompatible). Shape mirrors
779
- * langgraph's prebuilt ToolNode runtime exactly.
780
- */
781
493
  const lgConfig = config;
782
494
  const runtime = {
783
495
  ...config,
@@ -788,9 +500,6 @@ var ToolNode = class extends require_run.RunnableCallable {
788
500
  store: lgConfig.store ?? null,
789
501
  writer: lgConfig.writer ?? config.configurable?.writer ?? null
790
502
  };
791
- /** A sibling can trip the breaker while the PreToolUse hooks above
792
- * are awaited; a tool that never inspects its runtime signal would
793
- * still run. Recheck at the last moment before execution. */
794
503
  this.throwIfBreakerTripped(config);
795
504
  const output = await tool.invoke(invokeParams, runtime);
796
505
  if ((0, _langchain_langgraph.isCommand)(output)) return output;
@@ -801,13 +510,6 @@ var ToolNode = class extends require_run.RunnableCallable {
801
510
  const compacted = require_toolContent.compactToolContent(originalContent, this.maxToolResultChars);
802
511
  if (compacted.changed) toolMsg.content = compacted.content;
803
512
  if (toolMsg.status === "error") {
804
- /**
805
- * Error ToolMessages bypass registration but still stamp the
806
- * unresolved-refs hint into `additional_kwargs` so the lazy
807
- * annotation transform surfaces it to the LLM, letting the
808
- * model self-correct when its reference key caused the
809
- * failure. Persisted `content` stays clean.
810
- */
811
513
  if (unresolvedRefs.length > 0) toolMsg.additional_kwargs = {
812
514
  ...toolMsg.additional_kwargs,
813
515
  _unresolvedRefs: unresolvedRefs
@@ -822,16 +524,6 @@ var ToolNode = class extends require_run.RunnableCallable {
822
524
  ...refMeta
823
525
  };
824
526
  } else {
825
- /**
826
- * Non-string content (multi-part content blocks — text +
827
- * image). It is now bounded for the LLM, but cannot register under a
828
- * reference key because there's no canonical serialized
829
- * form. Warn once per tool per run when the caller
830
- * intended to register. The unresolved-refs hint is still
831
- * stamped as metadata; the lazy transform prepends a text
832
- * block at request time so the LLM gets the self-correction
833
- * signal.
834
- */
835
527
  if (unresolvedRefs.length > 0) toolMsg.additional_kwargs = {
836
528
  ...toolMsg.additional_kwargs,
837
529
  _unresolvedRefs: unresolvedRefs
@@ -853,11 +545,6 @@ var ToolNode = class extends require_run.RunnableCallable {
853
545
  const e = _e;
854
546
  if (!this.handleToolErrors) throw e;
855
547
  if ((0, _langchain_langgraph.isGraphInterrupt)(e)) throw e;
856
- /**
857
- * A stream circuit breaker tripped by a child run (subagent) is a
858
- * safety abort, not a tool failure to report back to the model. It
859
- * passes through like an interrupt so the whole run rejects.
860
- */
861
548
  if (e instanceof require_streamLimits.StreamLimitExceededError) throw e;
862
549
  if (this.errorHandler) try {
863
550
  const dispatched = await this.errorHandler({
@@ -867,15 +554,7 @@ var ToolNode = class extends require_run.RunnableCallable {
867
554
  input: call.args
868
555
  }, config.metadata);
869
556
  const ownership = batchContext.errorOwnership ?? this.looseErrorOwnership;
870
- if (call.id != null && call.id !== "") if (dispatched === false)
871
- /**
872
- * The handler could not dispatch the error completion (typically
873
- * a resume pass, where a fast-failing tool errors before the
874
- * step replay registers its run step). Remember the call so the
875
- * output loop dispatches the completion itself instead of
876
- * assuming the handler covered it.
877
- */
878
- ownership.undispatched.add(call.id);
557
+ if (call.id != null && call.id !== "") if (dispatched === false) ownership.undispatched.add(call.id);
879
558
  else ownership.handlerOwned.add(call.id);
880
559
  } catch (handlerError) {
881
560
  if (call.id != null && call.id !== "") (batchContext.errorOwnership ?? this.looseErrorOwnership).handlerOwned.add(call.id);
@@ -909,53 +588,6 @@ var ToolNode = class extends require_run.RunnableCallable {
909
588
  });
910
589
  }
911
590
  }
912
- /**
913
- * Runs a single in-process tool call with the same lifecycle hooks
914
- * the event-dispatch path fires (`PreToolUse`, `PermissionDenied`,
915
- * `PostToolUse`, `PostToolUseFailure`). Used for any tool whose
916
- * implementation lives in the SDK process — i.e. every entry in
917
- * `directToolNames` — so host-supplied policy hooks gate
918
- * direct-invoked tools the same way they gate dispatched ones.
919
- *
920
- * Fast path: when the registry has none of the relevant events
921
- * registered for this run, falls through to `runTool` with zero
922
- * extra work. The hook list is also checked via
923
- * `hasHookFor(event, runId)`, which performs the registry's own
924
- * O(1) shortcut.
925
- *
926
- * Hook semantics intentionally mirror `dispatchToolEvents` for the
927
- * single-call case:
928
- * - `PreToolUse` returning `decision: 'deny'` synthesizes an error
929
- * `ToolMessage` and fires `PermissionDenied` (observational).
930
- * - `PreToolUse` returning `decision: 'ask'`:
931
- * • When `humanInTheLoop.enabled === true`: raises a real
932
- * `tool_approval` interrupt for this single tool call (the
933
- * same payload shape the event path produces). On resume:
934
- * `approve` runs the tool, `reject` blocks via
935
- * `blockDirectCall`, `respond` returns the host-supplied
936
- * `responseText` as a synthetic success ToolMessage,
937
- * `edit` re-runs with edited args. LangGraph re-enters
938
- * ToolNode.run from the start on resume. Reusable hooks fire
939
- * again; a consumed one-shot hook replays its pending approval
940
- * result. In both cases `interrupt()` consumes the resume value.
941
- * • When HITL is off: collapses to a fail-closed deny (matches
942
- * the rest of the SDK's HITL-disabled default). One-time
943
- * warning logged so hosts notice the gap.
944
- * - `PreToolUse.updatedInput` is applied to the call before
945
- * `runTool` runs; placeholder resolution inside `runTool` is
946
- * idempotent on already-resolved args.
947
- * - `PostToolUse.updatedOutput` replaces the returned
948
- * `ToolMessage` content (preserving id/name/status).
949
- * - `PostToolUseFailure` fires when `runTool` returns a
950
- * `ToolMessage` whose `status === 'error'`. Observational only;
951
- * the error message stays the source of truth.
952
- *
953
- * `PostToolBatch` aggregation across direct + dispatched outcomes is
954
- * a separate concern: `dispatchToolEvents` accumulates batch entries
955
- * locally and fires `PostToolBatch` at the end of its scope. Wiring
956
- * direct-call entries into that aggregation crosses the two paths'
957
- * scopes and is left to a follow-up.
958
- */
959
591
  async runDirectToolWithLifecycleHooks(call, config, batchContext = {}) {
960
592
  const replayController = this.toolMap.get(call.name)?.[require_SubagentReplay.SUBAGENT_REPLAY_CONTROLLER];
961
593
  const replayConfig = replayController == null ? config : withSubagentReplayBatch(config, batchContext.replayBatchKey);
@@ -1152,15 +784,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1152
784
  }
1153
785
  }
1154
786
  }
1155
- /**
1156
- * A hook (`PreToolUse.updatedInput`) or HITL `edit` decision rewrote the
1157
- * args: expose the EFFECTIVE args to downstream completion handling
1158
- * (`handleRunToolCompletions` reads this sink), so the emitted
1159
- * `tool_call.args` — and any intent/outcome label resolved from them —
1160
- * reflect what the tool actually ran with. `runTool`'s own placeholder
1161
- * substitution may overwrite this entry with the post-substitution args,
1162
- * which is strictly more accurate.
1163
- */
1164
787
  if (effectiveCall !== call && batchContext.resolvedArgsByCallId != null && call.id != null && call.id !== "") batchContext.resolvedArgsByCallId.set(call.id, effectiveCall.args);
1165
788
  const output = await this.runTool(effectiveCall, replayConfig, {
1166
789
  ...batchContext,
@@ -1230,13 +853,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1230
853
  }
1231
854
  return persistOutput(output);
1232
855
  }
1233
- /**
1234
- * `ask` decisions on direct-path tools collapse to fail-closed deny
1235
- * only when `humanInTheLoop.enabled !== true` (i.e. there's no host
1236
- * UI configured to actually prompt the user). Logged once per process
1237
- * so the gap is visible. When HITL IS enabled, `ask` raises a real
1238
- * LangGraph `interrupt()` instead — see `runDirectToolWithLifecycleHooks`.
1239
- */
1240
856
  askDirectWarningEmitted = false;
1241
857
  resolveAskDecisionForDirectTool(reason, toolName) {
1242
858
  if (!this.askDirectWarningEmitted) {
@@ -1245,12 +861,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1245
861
  }
1246
862
  return reason ?? "Blocked by hook";
1247
863
  }
1248
- /**
1249
- * Synthesize a Blocked ToolMessage AND fire `PermissionDenied`
1250
- * (observational) for a direct-path tool call. Centralised so the
1251
- * deny path looks identical whether the block came from `'deny'` or
1252
- * from a fail-closed/`'reject'`/policy-violation path.
1253
- */
1254
864
  blockDirectCall(args) {
1255
865
  const { call, resolvedArgs, reason, hookRegistry, runId, threadId } = args;
1256
866
  if (hookRegistry.hasHookFor("PermissionDenied", runId) === true) require_executeHooks.executeHooks({
@@ -1276,49 +886,17 @@ var ToolNode = class extends require_run.RunnableCallable {
1276
886
  tool_call_id: call.id ?? ""
1277
887
  });
1278
888
  }
1279
- /**
1280
- * Registers the full, raw output under `refKey` (when provided) and
1281
- * builds the per-message ref metadata stamped onto the resulting
1282
- * `ToolMessage.additional_kwargs`. The metadata is read at LLM-
1283
- * request time by `annotateMessagesForLLM` to produce a transient
1284
- * annotated copy of the message — the persisted `content` itself
1285
- * stays clean.
1286
- *
1287
- * @param registryContent The full, untruncated output to store in
1288
- * the registry so `{{tool<i>turn<n>}}` substitutions deliver the
1289
- * complete payload. Ignored when `refKey` is undefined.
1290
- * @param refKey Precomputed `tool<i>turn<n>` key, or undefined when
1291
- * the output is not to be registered (errors, disabled feature,
1292
- * unavailable batch/turn).
1293
- * @param unresolved Placeholder keys that did not resolve; surfaced
1294
- * to the LLM lazily so it can self-correct.
1295
- * @returns A `ToolMessageRefMetadata` object when there is anything
1296
- * to stamp, otherwise `undefined`.
1297
- */
1298
889
  recordOutputReference(runId, registryContent, refKey, unresolved) {
1299
890
  if (this.toolOutputRegistry != null && refKey != null) this.toolOutputRegistry.set(runId, refKey, registryContent);
1300
891
  if (refKey == null && unresolved.length === 0) return void 0;
1301
892
  const meta = {};
1302
893
  if (refKey != null) {
1303
894
  meta._refKey = refKey;
1304
- /**
1305
- * Stamp the registry scope alongside the key so the lazy
1306
- * annotation transform can look up the right bucket. Anonymous
1307
- * invocations get a synthetic per-batch scope (`\0anon-<n>`)
1308
- * that `attemptInvoke` cannot derive from
1309
- * `config.configurable.run_id` — without this, anonymous-run
1310
- * refs would silently fail registry lookup and the LLM would
1311
- * never see `[ref: …]` markers for outputs that were registered.
1312
- */
1313
895
  if (runId != null) meta._refScope = runId;
1314
896
  }
1315
897
  if (unresolved.length > 0) meta._unresolvedRefs = unresolved;
1316
898
  return meta;
1317
899
  }
1318
- /**
1319
- * Builds code session context for injection into event-driven tool calls.
1320
- * Mirrors the session injection logic in runTool() for direct execution.
1321
- */
1322
900
  getCodeSessionContext() {
1323
901
  if (!this.sessions) return;
1324
902
  const codeSession = this.sessions.get("execute_code");
@@ -1328,23 +906,10 @@ var ToolNode = class extends require_run.RunnableCallable {
1328
906
  if (codeSession.files && codeSession.files.length > 0) context.files = codeSession.files.map((file) => toInjectedFileRef(file, execSessionId));
1329
907
  return context;
1330
908
  }
1331
- /**
1332
- * Extracts code execution session context from tool results and stores in Graph.sessions.
1333
- * Mirrors the session storage logic in handleRunToolCompletions for direct execution.
1334
- */
1335
- /**
1336
- * True when a tool's successful result should fold its returned exec
1337
- * `session_id` into the shared code session: built-in `CODE_EXECUTION_TOOLS`,
1338
- * plus host-declared sandbox-writing tools (`codeSessionToolNames`, e.g.
1339
- * create_file/edit_file). Kept name-scoped rather than a blanket artifact
1340
- * opt-in so only host-declared tools can influence the shared session.
1341
- */
1342
909
  participatesInCodeSession(name) {
1343
910
  if (name === "") return false;
1344
911
  return require_enum.CODE_EXECUTION_TOOLS.has(name) || this.codeSessionToolNames?.has(name) === true;
1345
912
  }
1346
- /** Delegates to the shared resolver so the direct and event-driven planning
1347
- * paths derive the runtime session hint identically. */
1348
913
  resolveRuntimeSessionHint(config) {
1349
914
  return require_eagerEventExecution.resolveRuntimeSessionHint(this.toolExecution, config.configurable?.thread_id);
1350
915
  }
@@ -1361,19 +926,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1361
926
  updateCodeSession(this.sessions, execSessionId, artifact?.files);
1362
927
  }
1363
928
  }
1364
- /**
1365
- * Post-processes standard runTool outputs: dispatches ON_RUN_STEP_COMPLETED
1366
- * and stores code session context. Mirrors the completion handling in
1367
- * dispatchToolEvents for the event-driven path.
1368
- *
1369
- * By handling completions here in graph context (rather than in the
1370
- * stream consumer via ToolEndHandler), the race between the stream
1371
- * consumer and graph execution is eliminated.
1372
- *
1373
- * @param resolvedArgsByCallId Per-batch resolved-args sink populated
1374
- * by `runTool`. Threaded as a local map (instead of instance state)
1375
- * so concurrent batches cannot read each other's entries.
1376
- */
1377
929
  async handleRunToolCompletions(calls, outputs, config, resolvedArgsByCallId, errorOwnership) {
1378
930
  const ownership = errorOwnership ?? this.looseErrorOwnership;
1379
931
  for (let i = 0; i < calls.length; i++) {
@@ -1401,15 +953,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1401
953
  if (require_toolContent.isComputerCallOutputMessage(toolMessage)) contentString = require_truncation.truncateToolResultContent("[Computer screenshot omitted from completion event]", this.maxToolResultChars);
1402
954
  else if (typeof toolMessage.content === "string") contentString = toolMessage.content;
1403
955
  else contentString = require_toolContent.serializeStructuredValueBounded(toolMessage.content, this.maxToolResultChars).content;
1404
- /**
1405
- * Prefer the post-substitution args when a `{{…}}` placeholder
1406
- * was resolved in `runTool`. This keeps
1407
- * `ON_RUN_STEP_COMPLETED.tool_call.args` consistent with what
1408
- * the tool actually received rather than leaking the template.
1409
- */
1410
956
  const effectiveArgs = resolvedArgsByCallId?.get(toolCallId) ?? call.args;
1411
- /** Authored outcomes apply to failed calls too (“Search failed for…”);
1412
- * without one, an error call simply stays unlabeled. */
1413
957
  const outcome = require_intentArg.resolveToolOutcome(effectiveArgs, require_intentArg.readOutcomeFields(toolMessage.artifact), { isError: toolMessage.status === "error" });
1414
958
  const tool_call = {
1415
959
  args: require_toolContent.serializeToolContentBounded(effectiveArgs ?? {}, this.maxToolResultChars),
@@ -1428,25 +972,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1428
972
  } }, config);
1429
973
  }
1430
974
  }
1431
- /**
1432
- * Dispatches tool calls to the host via ON_TOOL_EXECUTE event and returns raw ToolMessages.
1433
- * Core logic for event-driven execution, separated from output shaping.
1434
- *
1435
- * Hook lifecycle (when `hookRegistry` is set):
1436
- * 1. **PreToolUse** fires per call in parallel before dispatch. Denied
1437
- * calls produce error ToolMessages and fire **PermissionDenied**;
1438
- * surviving calls proceed with optional `updatedInput`.
1439
- * 2. Surviving calls are dispatched to the host via `ON_TOOL_EXECUTE`.
1440
- * 3. **PostToolUse** / **PostToolUseFailure** fire per result. Post hooks
1441
- * can replace tool output via `updatedOutput`.
1442
- * 4. Injected messages from results are collected and returned alongside
1443
- * ToolMessages (appended AFTER to respect provider ordering).
1444
- */
1445
- /** Rethrows a stream-limit trip carried on the batch config's composed
1446
- * signal. Rechecked at each later execution/dispatch stage because a tool
1447
- * that ignores cancellation can complete normally across the trip, and
1448
- * the next stage would otherwise start fresh side effects on a failed
1449
- * run. */
1450
975
  throwIfBreakerTripped(config) {
1451
976
  const signal = config.signal;
1452
977
  if (signal?.aborted === true && signal.reason instanceof require_streamLimits.StreamLimitExceededError) throw signal.reason;
@@ -1455,13 +980,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1455
980
  this.throwIfBreakerTripped(config);
1456
981
  const { batchIndices, turn, batchScopeId, preResolvedArgs, preBatchSnapshot } = batchContext;
1457
982
  const runId = config.configurable?.run_id ?? "";
1458
- /**
1459
- * Registry-facing scope id — prefers the caller-threaded
1460
- * `batchScopeId` so anonymous batches target their own unique
1461
- * bucket and don't step on concurrent anonymous invocations.
1462
- * Hooks and event payloads keep using the empty-string coerced
1463
- * `runId` for backward compat.
1464
- */
1465
983
  const registryRunId = batchScopeId ?? config.configurable?.run_id;
1466
984
  const threadId = config.configurable?.thread_id;
1467
985
  const registry = this.toolOutputRegistry;
@@ -1469,14 +987,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1469
987
  const preToolCalls = toolCalls.map((call, i) => {
1470
988
  const originalArgs = call.args;
1471
989
  let resolvedArgs = originalArgs;
1472
- /**
1473
- * When the caller provided a pre-resolved map (the mixed
1474
- * direct+event path snapshots event args synchronously before
1475
- * awaiting directs so they can't accidentally resolve
1476
- * same-turn direct outputs), use those entries verbatim instead
1477
- * of re-resolving against a registry that may have changed
1478
- * since the batch started.
1479
- */
1480
990
  const pre = call.id != null ? preResolvedArgs?.get(call.id) : void 0;
1481
991
  if (pre != null) {
1482
992
  resolvedArgs = pre.resolved;
@@ -1495,26 +1005,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1495
1005
  });
1496
1006
  const messageByCallId = /* @__PURE__ */ new Map();
1497
1007
  const approvedEntries = [];
1498
- /**
1499
- * Batch-level accumulator for `additionalContext` strings returned
1500
- * by any PreToolUse / PostToolUse / PostToolUseFailure hook in this
1501
- * dispatch. We emit one consolidated `HumanMessage` after all tool
1502
- * results land so the next model turn sees the injected context
1503
- * exactly once, ordered after the ToolMessages.
1504
- */
1505
1008
  const batchAdditionalContexts = [];
1506
- /**
1507
- * Batch-level outcome record keyed by `tool_call_id`. Captures
1508
- * every tool call's final result (success / error from the host,
1509
- * blocked from HITL deny / reject, substituted from HITL respond)
1510
- * across the three call sites that touch it. We materialize the
1511
- * `PostToolBatch` entry array in `toolCalls` order at dispatch
1512
- * time so hooks correlating outcomes by position see exactly the
1513
- * same sequence the model emitted — independent of when each
1514
- * outcome was recorded (deny entries land synchronously in the
1515
- * hook loop, approved entries land after host execution, respond
1516
- * entries land in the resume branch).
1517
- */
1518
1009
  const postToolBatchEntryByCallId = /* @__PURE__ */ new Map();
1519
1010
  const HOOK_FALLBACK = Object.freeze({
1520
1011
  additionalContexts: [],
@@ -1525,15 +1016,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1525
1016
  const approvalReplaySessionId = getToolApprovalReplaySessionId(config, runId);
1526
1017
  const hasPendingApproval = preToolCalls.some((entry) => entry.call.id != null && hookRegistry?.getPendingToolApproval(approvalReplaySessionId, createToolApprovalReplayKey(config, this.executingAgentId ?? this.agentId ?? "", entry.call.id)) != null);
1527
1018
  if (hookRegistry != null && (hookRegistry.hasHookFor("PreToolUse", runId) || hasPendingApproval)) {
1528
- /**
1529
- * Pull each call's prestarted eager record BEFORE awaiting the hooks:
1530
- * an async deny must never race the eager host promise into emitting a
1531
- * successful completion (`dispatchEagerToolCompletions`' map-identity
1532
- * check skips deleted records). Allowed entries get their record
1533
- * restored in the decision loop below so consumption still works;
1534
- * denied entries stay deleted. Ask/interrupt configs never have eager
1535
- * records (HITL disables the reservation gate).
1536
- */
1537
1019
  const preemptedEagerRecords = /* @__PURE__ */ new Map();
1538
1020
  if (this.eagerEventToolExecutions != null) for (const entry of preToolCalls) {
1539
1021
  const callId = entry.call.id;
@@ -1567,20 +1049,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1567
1049
  onceReplaySessionId: approvalReplaySessionId
1568
1050
  }).catch(() => HOOK_FALLBACK);
1569
1051
  }));
1570
- /**
1571
- * Side effects deferred from `blockEntry` until after any pending
1572
- * `interrupt()` resolves. Without deferral, a batch that mixes a
1573
- * `deny` decision with an `ask` decision would dispatch
1574
- * `ON_RUN_STEP_COMPLETED` for the denied tool on the FIRST node
1575
- * execution (before `interrupt()` throws), then dispatch the
1576
- * same event AGAIN on the resume re-execution — hosts would
1577
- * observe two completion events for one logical denial. By
1578
- * queueing the dispatch + PermissionDenied hook here and
1579
- * flushing after the interrupt block, we ensure each side effect
1580
- * fires exactly once: never on the first pass when interrupt
1581
- * throws (the flush is unreachable), once on resume / no-ask
1582
- * passes when control reaches the flush.
1583
- */
1584
1052
  const deferredBlockedSideEffects = [];
1585
1053
  const blockEntry = (entry, reason) => {
1586
1054
  const contentString = `Blocked: ${reason}`;
@@ -1595,15 +1063,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1595
1063
  toolInput: entry.args,
1596
1064
  toolUseId: entry.call.id,
1597
1065
  stepId: entry.stepId,
1598
- /**
1599
- * Records the pre-invocation turn count — the same value the
1600
- * executed path captures before incrementing `toolUsageCount`.
1601
- * For a blocked tool the counter is never incremented (no
1602
- * invocation happened), so this is always the count of prior
1603
- * successful invocations of this tool name in earlier batches.
1604
- * Surfaces in the `PostToolBatch` entry so batch hooks see
1605
- * a uniform shape regardless of outcome.
1606
- */
1607
1066
  turn: this.toolUsageCount.get(entry.call.name) ?? 0,
1608
1067
  status: "error",
1609
1068
  error: contentString
@@ -1615,13 +1074,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1615
1074
  contentString,
1616
1075
  reason
1617
1076
  });
1618
- /**
1619
- * A prestarted eager execution for a now-blocked call must neither be
1620
- * consumed nor emit its completion — the run reports this call as
1621
- * blocked. Deleting the record makes `dispatchEagerToolCompletions`'
1622
- * map-identity check skip the pending emission (same pattern as the
1623
- * rejected-results cleanup below).
1624
- */
1625
1077
  this.eagerEventToolExecutions?.delete(entry.call.id);
1626
1078
  };
1627
1079
  const flushDeferredBlockedSideEffects = async () => {
@@ -1646,19 +1098,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1646
1098
  }
1647
1099
  deferredBlockedSideEffects.length = 0;
1648
1100
  };
1649
- /**
1650
- * Apply a hook-supplied or host-supplied input override to a pending
1651
- * entry, re-running the `{{tool<i>turn<n>}}` resolver so any new
1652
- * placeholders introduced by the override are substituted (and any
1653
- * formerly-unresolved refs cleared from the unresolved set).
1654
- *
1655
- * Mixed direct+event batches must use the pre-batch snapshot so a
1656
- * hook-introduced placeholder cannot accidentally resolve to a
1657
- * same-turn direct output that has just registered. Pure event
1658
- * batches don't have a snapshot and resolve against the live
1659
- * registry — safe because no event-side registrations have happened
1660
- * yet.
1661
- */
1662
1101
  const applyInputOverride = (entry, nextArgs) => {
1663
1102
  if (registry != null) {
1664
1103
  const { resolved, unresolved } = (preBatchSnapshot ?? { resolve: (args, options) => registry.resolve(registryRunId, args, options) }).resolve(nextArgs, { substituteIntentKey: this.toolDeclaresBusinessIntent(entry.call.name) });
@@ -1679,29 +1118,10 @@ var ToolNode = class extends require_run.RunnableCallable {
1679
1118
  continue;
1680
1119
  }
1681
1120
  if (hookResult.decision === "ask") {
1682
- /**
1683
- * HITL is OFF by default — hosts must explicitly opt in via
1684
- * `humanInTheLoop: { enabled: true }` to engage the
1685
- * `interrupt()` path. When opted out (or omitted), `ask`
1686
- * collapses into the pre-HITL fail-closed path: a blocked
1687
- * tool with an error `ToolMessage`. The default stays
1688
- * conservative until host UIs are ready to render
1689
- * `tool_approval` interrupts; see `HumanInTheLoopConfig`
1690
- * JSDoc for the full rationale and the migration plan.
1691
- */
1692
1121
  if (this.humanInTheLoop?.enabled !== true) {
1693
1122
  blockEntry(entry, hookResult.reason ?? "Blocked by hook");
1694
1123
  continue;
1695
1124
  }
1696
- /**
1697
- * Apply `updatedInput` BEFORE queuing into `askEntries` —
1698
- * a hook is allowed to return both a sanitization rewrite
1699
- * and an `ask` decision (e.g. one matcher redacts secrets,
1700
- * another matcher requires approval). Without this, the
1701
- * interrupt payload would surface the original args to the
1702
- * reviewer AND the post-approve execution would run with
1703
- * the original args, silently dropping the hook's rewrite.
1704
- */
1705
1125
  if (hookResult.updatedInput != null) applyInputOverride(entry, hookResult.updatedInput);
1706
1126
  askEntries.push({
1707
1127
  entry,
@@ -1717,26 +1137,8 @@ var ToolNode = class extends require_run.RunnableCallable {
1717
1137
  }
1718
1138
  approvedEntries.push(entry);
1719
1139
  }
1720
- /**
1721
- * If any entries asked for approval, raise a single LangGraph
1722
- * `interrupt()` carrying every pending request together. The host
1723
- * pauses, gathers human input, and resumes the run with one
1724
- * decision per request. On resume LangGraph re-executes this node
1725
- * from the start; `interrupt()` then returns the resume value
1726
- * instead of throwing. Reusable hooks rebuild their entries, while
1727
- * consumed one-shot hooks replay their pending approval aggregate.
1728
- */
1729
1140
  if (askEntries.length > 0) {
1730
1141
  const payload = buildToolApprovalInterruptPayload(askEntries, runId);
1731
- /**
1732
- * `interrupt()` reads the current `RunnableConfig` from
1733
- * AsyncLocalStorage. ToolNode usually runs with tracing disabled
1734
- * (unless Langfuse explicitly enables it), so the upstream
1735
- * `runWithConfig` frame may not exist. Re-anchor here using the
1736
- * node's own `config` — Pregel hands us a config that already
1737
- * carries every checkpoint/scratchpad key `interrupt()` needs to
1738
- * suspend and resume.
1739
- */
1740
1142
  const resumeValue = _langchain_core_singletons.AsyncLocalStorageProviderSingleton.runWithConfig(config, () => (0, _langchain_langgraph.interrupt)(payload));
1741
1143
  for (const { entry } of askEntries) hookRegistry.clearPendingToolApproval(approvalReplaySessionId, createToolApprovalReplayKey(config, this.executingAgentId ?? this.agentId ?? "", entry.call.id));
1742
1144
  const decisionByCallId = normalizeApprovalDecisions(askEntries.map(({ entry }) => entry.call.id), resumeValue);
@@ -1745,27 +1147,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1745
1147
  type: "reject",
1746
1148
  reason: "No decision provided for tool approval"
1747
1149
  };
1748
- /**
1749
- * Read `decision.type` through a widened view once: hosts
1750
- * deserialize resume payloads from untyped JSON, so the
1751
- * runtime value can be a typo, the wrong type, or missing
1752
- * entirely. Both the `allowedDecisions` enforcement
1753
- * immediately below and the unknown-type fallthrough at the
1754
- * end of this loop body share this single read so the
1755
- * fail-closed checks compare against the same source.
1756
- */
1757
1150
  const declaredType = decision.type;
1758
- /**
1759
- * Enforce the per-tool `allowedDecisions` allowlist that the
1760
- * `PreToolUse` hook surfaced in `review_configs`. The host
1761
- * UI is supposed to honor this when collecting the user's
1762
- * decision, but the wire is untrusted: a buggy or hostile
1763
- * host could submit a decision type the policy explicitly
1764
- * forbids (e.g. `'edit'` when the hook restricted to
1765
- * `['approve', 'reject']`), bypassing argument-mutation /
1766
- * response-substitution safeguards. Fail closed when the
1767
- * declared type isn't in the allowlist.
1768
- */
1769
1151
  if (allowedDecisions != null && (typeof declaredType !== "string" || !allowedDecisions.includes(declaredType))) {
1770
1152
  blockEntry(entry, `Decision "${typeof declaredType === "string" ? declaredType : "<missing>"}" not in allowedDecisions [${allowedDecisions.join(", ")}] — failing closed`);
1771
1153
  continue;
@@ -1774,38 +1156,12 @@ var ToolNode = class extends require_run.RunnableCallable {
1774
1156
  blockEntry(entry, decision.reason ?? askReason ?? "Rejected by user");
1775
1157
  continue;
1776
1158
  }
1777
- /**
1778
- * `respond` short-circuits tool execution: the human supplies
1779
- * the result the model should see in place of running the
1780
- * tool. We emit a successful `ToolMessage` directly and skip
1781
- * dispatch — no host event fires, no real tool side effect
1782
- * occurs. Mirrors LangChain HITL middleware semantics.
1783
- */
1784
1159
  if (decision.type === "respond") {
1785
- /**
1786
- * Validate the wire shape before touching it: hosts
1787
- * deserialize resume payloads from untyped JSON, so a
1788
- * malformed `{ type: 'respond' }` (no `responseText`) or
1789
- * `{ type: 'respond', responseText: 42 }` would crash
1790
- * `truncateToolResultContent` (which calls
1791
- * `content.length`) and turn a fail-closed approval path
1792
- * into a hard run failure. Route bad shapes through
1793
- * `blockEntry` like any other unusable decision.
1794
- */
1795
1160
  const responseText = decision.responseText;
1796
1161
  if (typeof responseText !== "string") {
1797
1162
  blockEntry(entry, `Decision "respond" missing string responseText (got ${describeOfferedShape(responseText)}) — failing closed`);
1798
1163
  continue;
1799
1164
  }
1800
- /**
1801
- * Truncate the human-supplied text just like the success
1802
- * path does for real tool output. Without this, a user
1803
- * pasting a large document as a manual response bypasses
1804
- * `maxToolResultChars` and can blow past the model's
1805
- * context window. The PostToolBatch entry surfaces the
1806
- * truncated text too so batch hooks see what the model
1807
- * will actually see.
1808
- */
1809
1165
  const truncatedResponse = require_truncation.truncateToolResultContent(responseText, this.maxToolResultChars);
1810
1166
  messageByCallId.set(entry.call.id, new _langchain_core_messages.ToolMessage({
1811
1167
  status: "success",
@@ -1822,30 +1178,10 @@ var ToolNode = class extends require_run.RunnableCallable {
1822
1178
  status: "success",
1823
1179
  toolOutput: truncatedResponse
1824
1180
  });
1825
- /**
1826
- * Safe to dispatch immediately — unlike `blockEntry` which
1827
- * defers, `respond` only executes inside the decision-
1828
- * processing loop, which is reachable only AFTER
1829
- * `interrupt()` has returned (the resume pass). There is
1830
- * no risk of being rolled back by a subsequent throw, so
1831
- * no risk of a duplicate `ON_RUN_STEP_COMPLETED` event.
1832
- */
1833
1181
  await this.dispatchStepCompleted(entry.call.id, entry.call.name, entry.args, truncatedResponse, config);
1834
1182
  continue;
1835
1183
  }
1836
1184
  if (decision.type === "edit") {
1837
- /**
1838
- * Validate the wire shape before touching it: hosts
1839
- * deserialize resume payloads from untyped JSON, so a
1840
- * malformed `{ type: 'edit' }` (no `updatedInput`),
1841
- * `{ type: 'edit', updatedInput: 'string' }` (non-object),
1842
- * or `{ type: 'edit', updatedInput: [...] }` (array, not a
1843
- * plain object) would feed garbage into
1844
- * `applyInputOverride` and silently approve a tool with
1845
- * undefined / wrong-shape args. Same trust boundary as
1846
- * the `respond` validation above — fail closed via
1847
- * `blockEntry` with a diagnostic.
1848
- */
1849
1185
  const updatedInput = decision.updatedInput;
1850
1186
  if (updatedInput === null || typeof updatedInput !== "object" || Array.isArray(updatedInput)) {
1851
1187
  blockEntry(entry, `Decision "edit" missing object updatedInput (got ${describeOfferedShape(updatedInput)}) — failing closed`);
@@ -1855,19 +1191,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1855
1191
  approvedEntries.push(entry);
1856
1192
  continue;
1857
1193
  }
1858
- /**
1859
- * Defensive type widening: hosts deserialize resume payloads
1860
- * from untyped JSON, so the `decision.type` value at runtime
1861
- * is whatever string the wire sent — not necessarily one of
1862
- * the four union variants TS knows about. We compare against
1863
- * the literal `'approve'` through the widened `declaredType`
1864
- * captured at the top of this iteration, so a typo or schema
1865
- * drift (`'aproved'`, `null`, `undefined`) hits the fail-
1866
- * closed branch below instead of silently approving the
1867
- * tool. Without this widening, TS narrows the union after
1868
- * the three earlier branches and treats `=== 'approve'` as
1869
- * trivially true.
1870
- */
1871
1194
  if (declaredType === "approve") {
1872
1195
  approvedEntries.push(entry);
1873
1196
  continue;
@@ -1875,18 +1198,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1875
1198
  blockEntry(entry, `Unknown approval decision type "${typeof declaredType === "string" ? declaredType : "<missing>"}" — failing closed`);
1876
1199
  }
1877
1200
  }
1878
- /**
1879
- * Flush deferred denial side effects exactly once. On the FIRST
1880
- * pass through a batch that contains an `ask`, `interrupt()`
1881
- * threw above and we never reach this line — so no
1882
- * `ON_RUN_STEP_COMPLETED` / `PermissionDenied` events fire
1883
- * for blocked tools yet. On resume the node re-executes from
1884
- * scratch, `blockEntry` re-queues the same entries, and the
1885
- * flush below dispatches them once. For batches without any
1886
- * `ask` (deny-only or empty), the flush still runs here and
1887
- * dispatches in the same relative position as the pre-deferral
1888
- * code did (after hook processing, before tool execution).
1889
- */
1890
1201
  await flushDeferredBlockedSideEffects();
1891
1202
  } else approvedEntries.push(...preToolCalls);
1892
1203
  const injected = [];
@@ -1926,33 +1237,13 @@ var ToolNode = class extends require_run.RunnableCallable {
1926
1237
  });
1927
1238
  else dispatchRequests.push(request);
1928
1239
  }
1929
- /**
1930
- * Per-call completion fast-path: when the host reports a result
1931
- * through `onResult` before the batch resolves, emit that call's
1932
- * completed run step immediately instead of waiting for the slowest
1933
- * call in the batch. Safe only when nothing can change the result
1934
- * after execution — post-tool hooks may rewrite output and HITL may
1935
- * deny a call, so those configurations keep batch-time emission.
1936
- * Ids are claimed synchronously before the async dispatch and
1937
- * released if the dispatch fails, letting the batch path re-emit.
1938
- */
1939
1240
  const canEmitEarlyCompletions = this.hookRegistry?.hasResultAlteringHooks(runId) !== true && this.humanInTheLoop?.enabled !== true;
1940
- /**
1941
- * Snapshot the post-hook gates at the same instant as the early-emission
1942
- * gate: a result-altering hook registered while this batch is in flight
1943
- * applies from the NEXT batch. Evaluating these after results settle
1944
- * would let a late hook rewrite the ToolMessage AFTER an early
1945
- * completion already emitted the pre-hook output — two views of the
1946
- * same call.
1947
- */
1948
1241
  const hasPostHook = this.hookRegistry?.hasHookFor("PostToolUse", runId) === true;
1949
1242
  const hasFailureHook = this.hookRegistry?.hasHookFor("PostToolUseFailure", runId) === true;
1950
1243
  const earlyCompletionDispatchedIds = /* @__PURE__ */ new Set();
1951
1244
  const earlyCompletionDispatches = [];
1952
1245
  const dispatchRequestById = new Map(dispatchRequests.map((request) => [request.id, request]));
1953
1246
  const onResult = (result) => {
1954
- /** Runtime-honest widening: hosts may omit the id despite the
1955
- * field type. */
1956
1247
  const resultToolCallId = result.toolCallId;
1957
1248
  const request = resultToolCallId != null ? dispatchRequestById.get(resultToolCallId) : void 0;
1958
1249
  if (request == null || earlyCompletionDispatchedIds.has(result.toolCallId)) return;
@@ -1963,9 +1254,6 @@ var ToolNode = class extends require_run.RunnableCallable {
1963
1254
  earlyCompletionDispatchedIds.delete(result.toolCallId);
1964
1255
  }));
1965
1256
  };
1966
- /** The approval hooks above are awaited; a sibling's trip during them
1967
- * must stop the approved batch before it reaches a host handler that
1968
- * may never inspect the request signal. */
1969
1257
  if (dispatchRequests.length > 0) this.throwIfBreakerTripped(config);
1970
1258
  const dispatchPromise = dispatchRequests.length === 0 ? Promise.resolve([]) : new Promise((resolve, reject) => {
1971
1259
  let dispatchSettled = false;
@@ -2021,24 +1309,9 @@ var ToolNode = class extends require_run.RunnableCallable {
2021
1309
  const toolName = request?.name ?? "unknown";
2022
1310
  let contentString;
2023
1311
  let toolMessage;
2024
- /**
2025
- * Tracks the post-PostToolUse-hook output so the
2026
- * `PostToolBatch` entry below sees the final transformed value
2027
- * even when a hook replaced the original via `updatedOutput`.
2028
- * Lives at the loop-iteration scope so the success branch can
2029
- * mutate it; the error branch leaves it unset (and the batch
2030
- * entry uses `error` instead of `toolOutput` in that case).
2031
- */
2032
1312
  let finalToolOutput = result.content;
2033
1313
  if (result.status === "error") {
2034
1314
  contentString = require_truncation.truncateToolResultContent(`Error: ${result.errorMessage ?? "Unknown error"}\n Please fix your mistakes.`, this.maxToolResultChars);
2035
- /**
2036
- * Error results bypass registration but stamp the
2037
- * unresolved-refs hint into `additional_kwargs` so the lazy
2038
- * annotation transform surfaces it to the LLM at request
2039
- * time, letting the model self-correct when its reference
2040
- * key caused the failure. Persisted `content` stays clean.
2041
- */
2042
1315
  const unresolved = unresolvedByCallId.get(result.toolCallId) ?? [];
2043
1316
  const errorRefMeta = unresolved.length > 0 ? this.recordOutputReference(registryRunId, contentString, void 0, unresolved) : void 0;
2044
1317
  toolMessage = new _langchain_core_messages.ToolMessage({
@@ -2067,15 +1340,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2067
1340
  sessionId: runId,
2068
1341
  matchQuery: toolName
2069
1342
  }).catch(() => void 0);
2070
- /**
2071
- * Collect `additionalContext` from failure hooks too. Without
2072
- * this, recovery guidance returned on tool errors (e.g.
2073
- * "if this tool errors with X, suggest Y to the user") is
2074
- * silently dropped even though the API surface advertises
2075
- * `additionalContext` for this event. PostToolUseFailure
2076
- * remains observational for errors thrown by the hook
2077
- * itself, but a successfully-returned result is honored.
2078
- */
2079
1343
  if (failureHookResult != null) for (const ctx of failureHookResult.additionalContexts) batchAdditionalContexts.push(ctx);
2080
1344
  }
2081
1345
  } else {
@@ -2109,14 +1373,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2109
1373
  registryRaw = serialized.registryContent;
2110
1374
  contentString = serialized.content;
2111
1375
  finalToolOutput = hookResult.updatedOutput;
2112
- /**
2113
- * The hook ACTUALLY rewrote this output: any completion the
2114
- * stream already emitted for the consumed eager result showed
2115
- * the raw content, so un-mark it and let the dispatch below
2116
- * re-emit the corrected version. Hooks that merely observe or
2117
- * add context leave the original emission final — no
2118
- * duplicates.
2119
- */
2120
1376
  eagerCompletionDispatchedIds.delete(result.toolCallId);
2121
1377
  }
2122
1378
  }
@@ -2158,7 +1414,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2158
1414
  injected
2159
1415
  };
2160
1416
  }
2161
- /** Run-scoped so another run's session hooks can't flip this run's gate. */
2162
1417
  canConsumeEagerEventExecution(runId) {
2163
1418
  return this.eventDrivenMode && this.eagerEventToolExecution?.enabled === true && this.hookRegistry?.hasResultAlteringHooks(runId) !== true && this.humanInTheLoop?.enabled !== true;
2164
1419
  }
@@ -2198,24 +1453,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2198
1453
  errorMessage: "Tool execution completed without a result for this tool call"
2199
1454
  }];
2200
1455
  }
2201
- /**
2202
- * Fires the `PostToolBatch` hook (if registered) and appends the
2203
- * accumulated batch-level `additionalContext` strings to `injected`
2204
- * as a single `HumanMessage`. Entries are materialized in the
2205
- * original `toolCalls` order so hooks correlating outcomes by
2206
- * position (as the type docs promise) see exactly the sequence
2207
- * the model emitted, regardless of when each individual outcome
2208
- * was recorded into the map (deny synchronous, approved
2209
- * post-execution, respond on resume).
2210
- *
2211
- * The PostToolBatch hook's `additionalContexts` flow into the same
2212
- * batch accumulator per-tool hooks already use, so a single
2213
- * batch-level convention message can be injected through one path.
2214
- *
2215
- * Mutates `batchAdditionalContexts` (push from batch hook) and
2216
- * `injected` (push the consolidated HumanMessage). The caller owns
2217
- * those arrays and consumes them right after this returns.
2218
- */
2219
1456
  async dispatchPostToolBatchAndInjectContext(args) {
2220
1457
  const { toolCalls, entriesByCallId, batchAdditionalContexts, injected, runId, threadId } = args;
2221
1458
  const orderedBatchEntries = [];
@@ -2244,40 +1481,19 @@ var ToolNode = class extends require_run.RunnableCallable {
2244
1481
  for (const msg of batchHookResult.injectedMessages) hookInjectedMessages.push(msg);
2245
1482
  }
2246
1483
  }
2247
- if (batchAdditionalContexts.length > 0)
2248
- /**
2249
- * `HumanMessage` carrying a metadata `role: 'system'` marker —
2250
- * see `convertInjectedMessages` for the wider rationale. Anthropic
2251
- * and Google reject mid-conversation `SystemMessage`s, so we use
2252
- * a user-role message and surface the system intent through
2253
- * `additional_kwargs` for hosts inspecting state. The model sees
2254
- * a user message; `role` is metadata only.
2255
- */
2256
- injected.push(new _langchain_core_messages.HumanMessage({
1484
+ if (batchAdditionalContexts.length > 0) injected.push(new _langchain_core_messages.HumanMessage({
2257
1485
  content: batchAdditionalContexts.join("\n\n"),
2258
1486
  additional_kwargs: {
2259
1487
  role: "system",
2260
1488
  source: "hook"
2261
1489
  }
2262
1490
  }));
2263
- /**
2264
- * Hook-returned `injectedMessages` land AFTER the consolidated context
2265
- * message: one converted `HumanMessage` per entry (role/source kept in
2266
- * `additional_kwargs`), preserving per-message identity so verbatim
2267
- * user speech (e.g. steering) sits closest to the next model call.
2268
- */
2269
1491
  if (hookInjectedMessages.length > 0) try {
2270
1492
  injected.push(...require_injected.convertInjectedMessages(hookInjectedMessages));
2271
1493
  } catch (e) {
2272
1494
  console.warn("[ToolNode] Failed to convert PostToolBatch injectedMessages:", e instanceof Error ? e.message : e);
2273
1495
  }
2274
1496
  }
2275
- /**
2276
- * Whether `name`'s own schema declares a BUSINESS parameter called
2277
- * `intent` (declared, and not the injected label contract — see
2278
- * `isIntentLabelProperty`). Such a parameter must keep participating in
2279
- * `{{tool…}}` placeholder substitution; only the display label is exempt.
2280
- */
2281
1497
  toolDeclaresBusinessIntent(name) {
2282
1498
  const instance = this.toolMap.get(name);
2283
1499
  const instanceProp = instance?.schema?.properties?.["intent"] ?? instance?.schema?.shape?.["intent"];
@@ -2304,50 +1520,10 @@ var ToolNode = class extends require_run.RunnableCallable {
2304
1520
  completed_at: Date.now()
2305
1521
  } }, config) !== false;
2306
1522
  }
2307
- /**
2308
- * Emits the completed run step for a single host-reported result before
2309
- * the batch resolves. Mirrors the batch loop's output formatting exactly;
2310
- * callers gate on the no-hooks/no-HITL configuration, so the raw result
2311
- * content here is also the final content. Returns whether the event was
2312
- * actually dispatched so the caller can fall back to batch-time emission.
2313
- */
2314
1523
  async dispatchEarlyToolCompletion(result, request, config) {
2315
1524
  const output = result.status === "error" ? require_truncation.truncateToolResultContent(`Error: ${result.errorMessage ?? "Unknown error"}\n Please fix your mistakes.`, this.maxToolResultChars) : serializeToolOutputWithinLimits(result.content, this.maxToolResultChars).content;
2316
1525
  return this.dispatchStepCompleted(result.toolCallId, request.name, request.args, output, config, request.turn, require_intentArg.resolveToolOutcome(request.args, require_intentArg.outcomeFieldsFromResult(result), { isError: result.status === "error" }));
2317
1526
  }
2318
- /**
2319
- * Execute a group of direct (in-process) tool calls with interrupt-safe
2320
- * ordering, returning outputs aligned 1:1 with `directCalls`.
2321
- *
2322
- * Fast path (the common case): when no call in the group is in
2323
- * `interruptingToolNames`, this is a single `Promise.all` — byte-for-byte
2324
- * the prior behavior, so ordinary batches are unaffected.
2325
- *
2326
- * Interrupt-safe path: when the group contains an interrupting tool (e.g.
2327
- * `ask_user_question`, whose body raises a LangGraph `interrupt()` to
2328
- * collect a human answer), the interrupting calls run as their own awaited
2329
- * group **first**; only after they all settle without interrupting do the
2330
- * remaining (potentially non-idempotent) siblings run. If an interrupting
2331
- * call throws a `GraphInterrupt`, the `await` below rejects and unwinds the
2332
- * whole ToolNode *before* any non-interrupting sibling has started — so a
2333
- * sibling with real side effects (send_email, billing) never executes on
2334
- * the first pass. Terminal interrupting siblings are cached by call id, so
2335
- * LangGraph replay reuses their complete lifecycle output instead of
2336
- * repeating model calls, hooks, or side effects.
2337
- *
2338
- * Without this ordering, a flat `Promise.all` starts every sibling
2339
- * concurrently, so a non-idempotent sibling can complete its side effect
2340
- * before the interrupt unwinds and then run a SECOND time on resume — the
2341
- * duplicate side effect this method exists to prevent. A tool that actually
2342
- * suspends re-enters until it reaches a terminal result; siblings that
2343
- * already settled do not re-enter.
2344
- *
2345
- * `batchIndices[i]` is `directCalls[i]`'s position within the parent
2346
- * ToolNode batch (used for `{{tool<i>turn<n>}}` registration); it is
2347
- * preserved regardless of execution order. `baseContext` carries the
2348
- * batch-scoped fields every call shares; `batchIndex` is filled in
2349
- * per-call here.
2350
- */
2351
1527
  async runDirectBatchInterruptSafe(directCalls, batchIndices, config, baseContext) {
2352
1528
  const settledBatchResults = baseContext.replayBatchKey == null ? void 0 : this.settledInterruptingResults.get(baseContext.replayBatchKey);
2353
1529
  const restoreResult = (call, result) => {
@@ -2379,9 +1555,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2379
1555
  for (let i = 0; i < directCalls.length; i++) if (interrupting.has(directCalls[i].name)) interruptingPositions.push(i);
2380
1556
  else regularPositions.push(i);
2381
1557
  const interruptingResults = await Promise.allSettled(interruptingPositions.map((i) => runOne(directCalls[i], i)));
2382
- /** A sibling may have tripped the run-wide breaker while another raised
2383
- * a GraphInterrupt. Safety failures take precedence over approval pauses
2384
- * regardless of input order. */
2385
1558
  this.throwIfBreakerTripped(config);
2386
1559
  let hasInterruptingError = false;
2387
1560
  let interruptingError;
@@ -2431,9 +1604,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2431
1604
  }
2432
1605
  throw interruptingError;
2433
1606
  }
2434
- /** The breaker can trip while the interrupting group is awaited — e.g.
2435
- * a tool that ignores cancellation and completes normally. Recheck
2436
- * before starting the non-idempotent siblings. */
2437
1607
  this.throwIfBreakerTripped(config);
2438
1608
  const regularOutputs = await Promise.all(regularPositions.map((i) => runOne(directCalls[i], i)));
2439
1609
  regularPositions.forEach((i, k) => {
@@ -2441,34 +1611,14 @@ var ToolNode = class extends require_run.RunnableCallable {
2441
1611
  });
2442
1612
  return outputs;
2443
1613
  }
2444
- /**
2445
- * Execute all tool calls via ON_TOOL_EXECUTE event dispatch.
2446
- * Injected messages are placed AFTER ToolMessages to respect provider
2447
- * message ordering (AIMessage tool_calls must be immediately followed
2448
- * by their ToolMessage results).
2449
- *
2450
- * `batchIndices` mirrors `toolCalls` and carries each call's position
2451
- * within the parent batch. `turn` is the per-`run()` batch index
2452
- * captured locally by the caller. Both are threaded so concurrent
2453
- * invocations cannot race on shared mutable state.
2454
- */
2455
1614
  async executeViaEvent(toolCalls, config, input, batchContext = {}) {
2456
1615
  const { toolMessages, injected } = await this.dispatchToolEvents(toolCalls, config, batchContext);
2457
1616
  const outputs = [...toolMessages, ...injected];
2458
1617
  return Array.isArray(input) ? outputs : { messages: outputs };
2459
1618
  }
2460
1619
  async run(input, config) {
2461
- /**
2462
- * Breaker read once at batch entry: every downstream path (direct
2463
- * `tool.invoke` runtimes and the ON_TOOL_EXECUTE dispatch) inherits this
2464
- * config, and a graph reset mid-batch must not detach in-flight tools
2465
- * from an already-tripped signal.
2466
- */
2467
1620
  const breakerSignal = this.getBreakerSignal?.();
2468
1621
  const composedSignal = require_misc.composeAbortSignals(config.signal, breakerSignal);
2469
- /** Immutable batch scope, captured with the signal BEFORE hooks: tools
2470
- * that spawn runs (subagents) bind their child to this controller, so a
2471
- * reset during a PreToolUse hook cannot hand them the new run's one. */
2472
1622
  const batchRunScope = this.getRunScope?.();
2473
1623
  if (composedSignal !== config.signal || batchRunScope != null) config = {
2474
1624
  ...config,
@@ -2478,41 +1628,16 @@ var ToolNode = class extends require_run.RunnableCallable {
2478
1628
  ["lc_run_breaker_scope"]: batchRunScope
2479
1629
  } }
2480
1630
  };
2481
- /** Already-tripped-at-entry: a parallel sibling's breach failed the run
2482
- * before this batch was scheduled. Rethrow before hooks, direct
2483
- * `tool.invoke` calls, or ON_TOOL_EXECUTE dispatch — a tool or host
2484
- * handler that doesn't synchronously inspect an aborted signal would
2485
- * otherwise perform side effects on a failed run. */
2486
1631
  if (composedSignal?.aborted === true && composedSignal.reason instanceof require_streamLimits.StreamLimitExceededError) throw composedSignal.reason;
2487
1632
  this.toolCallTurns.clear();
2488
- /**
2489
- * Per-batch local map for resolved (post-substitution) args.
2490
- * Lives on the stack so concurrent `run()` calls on the same
2491
- * ToolNode cannot read or wipe each other's entries.
2492
- */
2493
1633
  const resolvedArgsByCallId = /* @__PURE__ */ new Map();
2494
- /** Per-invocation error-completion ownership — see `ToolErrorOwnership`. */
2495
1634
  const errorOwnership = createToolErrorOwnership();
2496
- /**
2497
- * Claim this batch's turn synchronously from the registry (or
2498
- * fall back to 0 when the feature is disabled). The registry is
2499
- * partitioned by scope id so overlapping batches cannot
2500
- * overwrite each other's state even under a shared registry.
2501
- *
2502
- * For anonymous callers (no `run_id` in config), mint a unique
2503
- * per-batch scope id so two concurrent anonymous invocations
2504
- * don't target the same bucket. The scope is threaded down to
2505
- * every subsequent registry call on this batch.
2506
- */
2507
1635
  const incomingRunId = config.configurable?.run_id;
2508
1636
  const incomingThreadId = config.configurable?.thread_id;
2509
1637
  const batchScopeId = incomingRunId ?? `\0anon-${this.anonBatchCounter++}`;
2510
1638
  const turn = this.toolOutputRegistry?.nextTurn(batchScopeId) ?? 0;
2511
1639
  let outputs;
2512
1640
  let replayBatchKey;
2513
- /** Hoisted from the messages-state branch so the Command tail can carry
2514
- * the promotion into handoff updates (same-id state copies there would
2515
- * otherwise overwrite the replacement message). */
2516
1641
  let promotedAiMessage;
2517
1642
  let invalidCallResults = [];
2518
1643
  if (this.isSendInput(input)) {
@@ -2562,12 +1687,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2562
1687
  this.programmaticCache = void 0;
2563
1688
  }
2564
1689
  const filteredCalls = aiMessage.tool_calls?.filter((call) => {
2565
- /**
2566
- * Filter out:
2567
- * 1. Already processed tool calls (present in toolMessageIds)
2568
- * 2. Server tool calls (e.g., web_search with IDs starting with 'srvtoolu_')
2569
- * which are executed by the provider's API and don't require invocation
2570
- */
2571
1690
  return (call.id == null || !toolMessageIds.has(call.id)) && !(call.id?.startsWith("srvtoolu_") ?? false);
2572
1691
  }) ?? [];
2573
1692
  const attributableInvalidCalls = !(!Array.isArray(input) && typeof aiMessage.id === "string" && aiMessage.id.length > 0) ? [] : (aiMessage.invalid_tool_calls ?? []).filter((call) => call.id != null && call.id !== "" && !toolMessageIds.has(call.id) && !call.id.startsWith("srvtoolu_"));
@@ -2578,20 +1697,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2578
1697
  name: normalizeInvalidCallName(call.name),
2579
1698
  tool_call_id: call.id
2580
1699
  }));
2581
- /**
2582
- * Promote the answered invalid calls into well-formed `tool_calls` on a
2583
- * REPLACEMENT copy of the AI message (`messagesStateReducer` upserts by
2584
- * id). Without this, provider converters that rebuild the call side of
2585
- * the wire from `tool_calls` — OpenAI Completions `tool_calls`, OpenAI
2586
- * Responses `function_call` items, Gemini/Bedrock function-call parts —
2587
- * drop the invalid call while the synthesized result above still
2588
- * references it, inverting the dangling-pair rejection (an output whose
2589
- * call is missing). Promoting at this single seam keeps the call and
2590
- * result sides agreeing for EVERY provider; args become `{}` (the raw
2591
- * string never parsed — the paired error result tells the model why).
2592
- * Skipped when the message has no id: the reducer would append a
2593
- * duplicate instead of replacing, which is worse than the dangle.
2594
- */
2595
1700
  promotedAiMessage = attributableInvalidCalls.length > 0 ? new _langchain_core_messages.AIMessage({
2596
1701
  id: aiMessage.id,
2597
1702
  content: sanitizeInvalidToolUseBlocks(aiMessage.content, attributableInvalidCalls),
@@ -2630,27 +1735,7 @@ var ToolNode = class extends require_run.RunnableCallable {
2630
1735
  const directIndices = directEntries.map((e) => e.batchIndex);
2631
1736
  const eventCalls = eventEntries.map((e) => e.call);
2632
1737
  const eventIndices = eventEntries.map((e) => e.batchIndex);
2633
- /**
2634
- * Snapshot the event calls' args against the *pre-batch*
2635
- * registry state synchronously, before any await runs. The
2636
- * directs are then awaited first (preserving fail-fast
2637
- * semantics — a thrown error in a direct tool, e.g. with
2638
- * `handleToolErrors=false` or a `GraphInterrupt`, aborts
2639
- * before we dispatch any event-driven tools to the host).
2640
- * Because the event args were captured pre-await, they stay
2641
- * isolated from same-turn direct outputs that register
2642
- * during the await.
2643
- */
2644
1738
  const preResolvedEventArgs = /* @__PURE__ */ new Map();
2645
- /**
2646
- * Take a frozen snapshot of the registry state before any
2647
- * direct registrations land. The snapshot resolves
2648
- * placeholders against this point-in-time view, so a
2649
- * `PreToolUse` hook later rewriting event args via
2650
- * `updatedInput` can introduce placeholders that resolve
2651
- * cross-batch (against prior runs) without ever picking up
2652
- * same-turn direct outputs.
2653
- */
2654
1739
  const preBatchSnapshot = this.toolOutputRegistry?.snapshot(batchScopeId);
2655
1740
  if (preBatchSnapshot != null) {
2656
1741
  for (const entry of eventEntries) if (entry.call.id != null) {
@@ -2730,15 +1815,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2730
1815
  ...invalidCallResults
2731
1816
  ];
2732
1817
  }
2733
- /**
2734
- * Resolve the streamed tool-call cards for invalid calls, best-effort.
2735
- * Runs AFTER the direct batch settled: on an interrupting first pass
2736
- * this line is unreachable (the node unwound), so interrupt/resume
2737
- * flows emit the completion exactly once — same reasoning as the
2738
- * deferred blocked-call side effects. Skipped when the stream never
2739
- * registered a step for the call (non-streaming providers), where a
2740
- * completion could not be routed to a card anyway.
2741
- */
2742
1818
  for (const result of invalidCallResults) {
2743
1819
  const invalidStepId = this.toolCallStepIds?.get(result.tool_call_id);
2744
1820
  if (invalidStepId == null || invalidStepId === "") continue;
@@ -2749,64 +1825,28 @@ var ToolNode = class extends require_run.RunnableCallable {
2749
1825
  if (replayBatchKey != null) this.settledInterruptingResults.delete(replayBatchKey);
2750
1826
  return Array.isArray(input) ? outputs : { messages: outputs };
2751
1827
  }
2752
- /**
2753
- * Carry the invalid-call promotion into handoff commands. A handoff
2754
- * tool's Command snapshots `update.messages` from the PRE-promotion
2755
- * state (MultiAgentGraph builds a filtered same-id copy of the original
2756
- * AI message), and commands apply after the sibling reducer updates —
2757
- * so the stale copy would overwrite the replacement message, and a
2758
- * Send handoff's child state could omit the synthesized results
2759
- * entirely. Patch each command's same-id AI message with the promotion
2760
- * and append any missing synthesized results.
2761
- */
2762
1828
  if (promotedAiMessage != null) outputs = outputs.map((output) => (0, _langchain_langgraph.isCommand)(output) ? patchCommandUpdateForPromotedInvalidCalls(output, promotedAiMessage, invalidCallResults) : output);
2763
1829
  const combinedOutputs = [];
2764
1830
  let parentCommand = null;
2765
- /**
2766
- * Collect handoff commands (Commands with string goto and Command.PARENT)
2767
- * for potential parallel handoff aggregation
2768
- */
2769
1831
  const handoffCommands = [];
2770
1832
  const nonCommandOutputs = [];
2771
- for (const output of outputs) if ((0, _langchain_langgraph.isCommand)(output)) if (output.graph === _langchain_langgraph.Command.PARENT && Array.isArray(output.goto) && output.goto.every((send) => isSend(send)))
2772
- /** Aggregate Send-based commands */
2773
- if (parentCommand) parentCommand.goto.push(...output.goto);
1833
+ for (const output of outputs) if ((0, _langchain_langgraph.isCommand)(output)) if (output.graph === _langchain_langgraph.Command.PARENT && Array.isArray(output.goto) && output.goto.every((send) => isSend(send))) if (parentCommand) parentCommand.goto.push(...output.goto);
2774
1834
  else parentCommand = new _langchain_langgraph.Command({
2775
1835
  graph: _langchain_langgraph.Command.PARENT,
2776
1836
  goto: output.goto
2777
1837
  });
2778
1838
  else if (output.graph === _langchain_langgraph.Command.PARENT) {
2779
- /**
2780
- * Handoff Command with destination.
2781
- * Handle both string ('agent') and array (['agent']) formats.
2782
- * Collect for potential parallel aggregation.
2783
- */
2784
1839
  const goto = output.goto;
2785
1840
  const isSingleStringDest = typeof goto === "string";
2786
1841
  const isSingleArrayDest = Array.isArray(goto) && goto.length === 1 && typeof goto[0] === "string";
2787
1842
  if (isSingleStringDest || isSingleArrayDest) handoffCommands.push(output);
2788
- else
2789
- /** Multi-destination or other command - pass through */
2790
- combinedOutputs.push(output);
2791
- } else
2792
- /** Other commands - pass through */
2793
- combinedOutputs.push(output);
1843
+ else combinedOutputs.push(output);
1844
+ } else combinedOutputs.push(output);
2794
1845
  else {
2795
1846
  nonCommandOutputs.push(output);
2796
1847
  combinedOutputs.push(Array.isArray(input) ? [output] : { messages: [output] });
2797
1848
  }
2798
- /**
2799
- * Handle handoff commands - convert to Send objects for parallel execution
2800
- * when multiple handoffs are requested
2801
- */
2802
1849
  if (handoffCommands.length > 1) {
2803
- /**
2804
- * Multiple parallel handoffs - convert to Send objects.
2805
- * Each Send carries its own state with the appropriate messages.
2806
- * This enables LLM-initiated parallel execution when calling multiple
2807
- * transfer tools simultaneously.
2808
- */
2809
- /** Collect all destinations for sibling tracking */
2810
1850
  const allDestinations = handoffCommands.map((cmd) => {
2811
1851
  const goto = cmd.goto;
2812
1852
  return typeof goto === "string" ? goto : goto[0];
@@ -2815,7 +1855,6 @@ var ToolNode = class extends require_run.RunnableCallable {
2815
1855
  const parallelGroupId = getRuntimeHandoffGroupId(parallelBatch);
2816
1856
  const sends = handoffCommands.map((cmd, idx) => {
2817
1857
  const destination = allDestinations[idx];
2818
- /** Get siblings (other destinations, not this one) */
2819
1858
  const siblings = allDestinations.filter((d) => d !== destination);
2820
1859
  const update = cmd.update;
2821
1860
  const handoffMessage = update?.messages ? findHandoffMessage(update.messages, destination) : void 0;
@@ -2831,9 +1870,7 @@ var ToolNode = class extends require_run.RunnableCallable {
2831
1870
  goto: sends
2832
1871
  });
2833
1872
  combinedOutputs.push(parallelCommand);
2834
- } else if (handoffCommands.length === 1)
2835
- /** Single handoff - pass through as-is */
2836
- combinedOutputs.push(handoffCommands[0]);
1873
+ } else if (handoffCommands.length === 1) combinedOutputs.push(handoffCommands[0]);
2837
1874
  if (parentCommand) combinedOutputs.push(parentCommand);
2838
1875
  if (replayBatchKey != null) this.settledInterruptingResults.delete(replayBatchKey);
2839
1876
  return combinedOutputs;
@@ -2849,17 +1886,6 @@ function areToolCallsInvoked(message, invokedToolIds) {
2849
1886
  if (!invokedToolIds || invokedToolIds.size === 0) return false;
2850
1887
  return message.tool_calls?.every((toolCall) => toolCall.id != null && invokedToolIds.has(toolCall.id)) ?? false;
2851
1888
  }
2852
- /**
2853
- * Normalize the `tool_use` content blocks of promoted invalid calls so the
2854
- * replacement AI message is valid on EVERY provider surface, not just
2855
- * `tool_calls`. Anthropic formats an array-content AI message from its blocks
2856
- * verbatim, and a call whose streamed `input_json` never parsed leaves the
2857
- * block's `input` as the raw accumulated STRING — replayed as-is, the API
2858
- * rejects it with `tool_use.input: Input should be an object` before pairing
2859
- * is even checked. Blocks matching a promoted call id get `input: {}`
2860
- * (mirroring the promoted args); everything else passes through untouched.
2861
- * String content (OpenAI-style) is returned as-is.
2862
- */
2863
1889
  function sanitizeInvalidToolUseBlocks(content, promotedCalls) {
2864
1890
  if (!Array.isArray(content)) return content;
2865
1891
  const promotedNamesById = new Map(promotedCalls.filter((call) => call.id != null).map((call) => [call.id, normalizeInvalidCallName(call.name)]));
@@ -2868,9 +1894,6 @@ function sanitizeInvalidToolUseBlocks(content, promotedCalls) {
2868
1894
  const toolUse = block;
2869
1895
  if (toolUse.id == null || !promotedNamesById.has(toolUse.id)) return block;
2870
1896
  const inputIsObject = typeof toolUse.input === "object" && toolUse.input != null && !Array.isArray(toolUse.input);
2871
- /** `name` normalizes with the SAME fallback the promoted `tool_calls`
2872
- * entry uses — a nameless block would fail provider validation on its
2873
- * own even with a valid input. */
2874
1897
  const nameIsValid = typeof toolUse.name === "string" && toolUse.name !== "";
2875
1898
  if (inputIsObject && nameIsValid) return block;
2876
1899
  return {
@@ -2880,41 +1903,9 @@ function sanitizeInvalidToolUseBlocks(content, promotedCalls) {
2880
1903
  };
2881
1904
  });
2882
1905
  }
2883
- /**
2884
- * Name fallback for attributable invalid calls, shared by every surface that
2885
- * materializes them (synthesized result, promoted tool_calls entry, sanitized
2886
- * block, handoff patch): `''` is normalized like `undefined` — providers
2887
- * reject nameless calls, so an empty string would defeat the promotion.
2888
- *
2889
- * INVARIANT MAP — a tool call lives in several parallel representations, and
2890
- * any surface that materializes, copies, filters, routes on, or reports one
2891
- * must keep ALL of them agreeing (`tool_calls`, `invalid_tool_calls`,
2892
- * provider content blocks, paired results). The attribution predicate is:
2893
- * id-bearing (non-empty), non-server (`srvtoolu_`), unanswered
2894
- * (`toolMessageIds`), messages-state input, id-bearing AI message. Surfaces
2895
- * that apply it today — extend this list when adding another:
2896
- * - `run()`'s `canPromoteInvalidCalls` gate + attributable filter
2897
- * - `toolsCondition`'s invalid-only / server-mix routing branch
2898
- * - `sanitizeInvalidToolUseBlocks` (block input AND name)
2899
- * - `patchCommandUpdateForPromotedInvalidCalls` (handoff snapshots)
2900
- * - `processHandoffReception`'s transfer-block filtering (MultiAgentGraph)
2901
- * - `findPendingToolCalls` in langfuseTraceShaping (span claims)
2902
- * - `serializeMessage`/`deserializeMessage` (session round-trip keeps
2903
- * `invalid_tool_calls` with the content blocks they repair)
2904
- */
2905
1906
  function normalizeInvalidCallName(name) {
2906
1907
  return name != null && name !== "" ? name : "unknown";
2907
1908
  }
2908
- /**
2909
- * Rewrite a handoff Command's `update.messages` so the invalid-call promotion
2910
- * survives into the child state: the same-id AI message copy (snapshotted
2911
- * pre-promotion by the handoff tool) gets the sanitized content, the promoted
2912
- * `tool_calls` entries for the answered invalid calls, and the leftover
2913
- * `invalid_tool_calls`; synthesized results missing from the update are
2914
- * appended so the child's history keeps every call/result pair. The update
2915
- * copy's own `tool_calls` narrowing (parallel handoffs filter to a single
2916
- * call) is preserved. Commands without a same-id AI message pass through.
2917
- */
2918
1909
  function patchCommandUpdateForPromotedInvalidCalls(command, promoted, invalidResults) {
2919
1910
  const update = command.update;
2920
1911
  const messages = update?.messages;
@@ -2952,13 +1943,6 @@ function patchCommandUpdateForPromotedInvalidCalls(command, promoted, invalidRes
2952
1943
  }
2953
1944
  });
2954
1945
  }
2955
- /**
2956
- * Whether the message carries an `invalid_tool_calls` entry ToolNode can pair a
2957
- * synthesized error result with (id-bearing, non-server). Shared by the routing
2958
- * condition below so an invalid-only turn still enters ToolNode — otherwise the
2959
- * malformed `tool_use` block is committed with no `tool_result` and the next
2960
- * model call is rejected by pairing-strict providers.
2961
- */
2962
1946
  function hasAttributableInvalidToolCalls(message) {
2963
1947
  return message.invalid_tool_calls?.some((call) => call.id != null && call.id !== "" && !call.id.startsWith("srvtoolu_")) ?? false;
2964
1948
  }
@@ -2966,22 +1950,6 @@ function toolsCondition(state, toolNode, invokedToolIds) {
2966
1950
  const messages = Array.isArray(state) ? state : state.messages;
2967
1951
  const message = messages[messages.length - 1];
2968
1952
  if (message && "tool_calls" in message && (message.tool_calls?.length ?? 0) > 0 && !areToolCallsInvoked(message, invokedToolIds)) return toolNode;
2969
- /**
2970
- * The valid calls (if any) did not route above, but ToolNode still owes any
2971
- * malformed calls their synthesized error results. Route when EVERY valid
2972
- * call is provider-server-executed (`srvtoolu_` — ToolNode's batch filter
2973
- * excludes those before execution, so nothing re-runs): that covers both the
2974
- * invalid-only turn and the Anthropic server-call + malformed-client-call
2975
- * mix, where `handleAnthropicSearchResults` marks the server call invoked
2976
- * and the first branch declines. A valid NON-server call that was invoked
2977
- * externally stays conservative (no routing) — ToolNode does not filter on
2978
- * `invokedToolIds`, so entering it would re-execute that call.
2979
- *
2980
- * Mirrors ToolNode's own gating exactly, or the routed turn would no-op and
2981
- * bounce back to the model with the dangle intact: array-state graphs get a
2982
- * plain output list (no reducer upsert — ToolNode skips invalid handling
2983
- * there), and an id-less message cannot take the replacement upsert either.
2984
- */
2985
1953
  if (!Array.isArray(state) && message && typeof message.id === "string" && message.id.length > 0 && hasAttributableInvalidToolCalls(message) && (message.tool_calls ?? []).every((call) => call.id?.startsWith("srvtoolu_") === true)) return toolNode;
2986
1954
  return _langchain_langgraph.END;
2987
1955
  }