@librechat/agents 3.4.7 → 3.5.1

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 (924) 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 +0 -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 +0 -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/package.json +35 -32
  582. package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +0 -52
  583. package/dist/types/test/mockTools.d.ts +0 -28
  584. package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +0 -40
  585. package/src/__tests__/stream.eagerArgsDivergence.test.ts +0 -911
  586. package/src/__tests__/stream.eagerEventExecution.test.ts +0 -5046
  587. package/src/__tests__/stream.streamLimits.test.ts +0 -1982
  588. package/src/agents/__tests__/AgentContext.anthropic.live.test.ts +0 -448
  589. package/src/agents/__tests__/AgentContext.bedrock.live.test.ts +0 -655
  590. package/src/agents/__tests__/AgentContext.openrouter.live.test.ts +0 -128
  591. package/src/agents/__tests__/AgentContext.overflow.test.ts +0 -205
  592. package/src/agents/__tests__/AgentContext.test.ts +0 -2425
  593. package/src/agents/__tests__/projection.test.ts +0 -73
  594. package/src/agents/__tests__/promptCacheLiveHelpers.ts +0 -175
  595. package/src/aggregator.test.ts +0 -1214
  596. package/src/graphs/__tests__/Graph.breakerLifecycle.test.ts +0 -273
  597. package/src/graphs/__tests__/Graph.closeRunStep.test.ts +0 -385
  598. package/src/graphs/__tests__/Graph.contextOverflow.test.ts +0 -1766
  599. package/src/graphs/__tests__/Graph.preemptSignal.test.ts +0 -126
  600. package/src/graphs/__tests__/Graph.reasoning.test.ts +0 -1717
  601. package/src/graphs/__tests__/Graph.subagentResumeState.test.ts +0 -80
  602. package/src/graphs/__tests__/MultiAgentGraph.test.ts +0 -177
  603. package/src/graphs/__tests__/composition.smoke.test.ts +0 -509
  604. package/src/graphs/__tests__/createGraph.test.ts +0 -206
  605. package/src/hooks/__tests__/HookRegistry.test.ts +0 -334
  606. package/src/hooks/__tests__/compactHooks.test.ts +0 -250
  607. package/src/hooks/__tests__/createToolPolicyHook.test.ts +0 -268
  608. package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +0 -405
  609. package/src/hooks/__tests__/executeHooks.test.ts +0 -1294
  610. package/src/hooks/__tests__/integration.test.ts +0 -337
  611. package/src/hooks/__tests__/matchers.test.ts +0 -238
  612. package/src/hooks/__tests__/preemptBoundary.test.ts +0 -152
  613. package/src/hooks/__tests__/toolHooks.test.ts +0 -669
  614. package/src/llm/__tests__/contextOverflowRecovery.test.ts +0 -401
  615. package/src/llm/__tests__/fallbackOverflow.test.ts +0 -287
  616. package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
  617. package/src/llm/anthropic/inherited-content-utils.spec.ts +0 -249
  618. package/src/llm/anthropic/inherited-stream-events.spec.ts +0 -1259
  619. package/src/llm/anthropic/inherited-strict.spec.ts +0 -302
  620. package/src/llm/anthropic/llm.spec.ts +0 -3394
  621. package/src/llm/anthropic/utils/cross-provider-reasoning.test.ts +0 -383
  622. package/src/llm/anthropic/utils/cross-provider-server-tools.test.ts +0 -110
  623. package/src/llm/anthropic/utils/server-tool-inputs.test.ts +0 -508
  624. package/src/llm/anthropic/utils/streaming-tool-input.test.ts +0 -361
  625. package/src/llm/anthropic/utils/stripPrefillCache.test.ts +0 -111
  626. package/src/llm/anthropic/utils/tool-id-normalization.test.ts +0 -287
  627. package/src/llm/bedrock/inherited-cache.spec.ts +0 -144
  628. package/src/llm/bedrock/inherited.spec.ts +0 -724
  629. package/src/llm/bedrock/llm.spec.ts +0 -1533
  630. package/src/llm/bedrock/streamSealDispatch.test.ts +0 -331
  631. package/src/llm/bedrock/toolCache.test.ts +0 -194
  632. package/src/llm/bedrock/utils/cross-provider-reasoning.test.ts +0 -131
  633. package/src/llm/bedrock/utils/cross-provider-server-tools.test.ts +0 -122
  634. package/src/llm/bedrock/utils/message_inputs.test.ts +0 -650
  635. package/src/llm/bedrock/utils/message_outputs.test.ts +0 -85
  636. package/src/llm/bedrock/utils/toolResultCachePoint.test.ts +0 -118
  637. package/src/llm/custom-chat-models.smoke.test.ts +0 -1966
  638. package/src/llm/google/data/gettysburg10.wav +0 -0
  639. package/src/llm/google/data/hotdog.jpg +0 -0
  640. package/src/llm/google/inherited-stream-events.spec.ts +0 -350
  641. package/src/llm/google/llm.spec.ts +0 -1388
  642. package/src/llm/google/streamSmoothing.test.ts +0 -121
  643. package/src/llm/google/utils/common.test.ts +0 -196
  644. package/src/llm/invoke.alternation.test.ts +0 -87
  645. package/src/llm/invoke.handoffCue.test.ts +0 -112
  646. package/src/llm/invoke.streamLimits.test.ts +0 -142
  647. package/src/llm/invoke.test.ts +0 -1198
  648. package/src/llm/mistral/streamSmoothing.test.ts +0 -97
  649. package/src/llm/openai/cacheWriteTokens.test.ts +0 -112
  650. package/src/llm/openai/contentBlocks.test.ts +0 -381
  651. package/src/llm/openai/deepseek.test.ts +0 -747
  652. package/src/llm/openai/inherited-deepseek.spec.ts +0 -347
  653. package/src/llm/openai/inherited-xai.spec.ts +0 -416
  654. package/src/llm/openai/llm.spec.ts +0 -1774
  655. package/src/llm/openai/managedRequests.test.ts +0 -182
  656. package/src/llm/openai/sequentialToolCallSeals.test.ts +0 -199
  657. package/src/llm/openai/streamMetadata.spec.ts +0 -86
  658. package/src/llm/openai/streamMetadataDedup.spec.ts +0 -166
  659. package/src/llm/openai/utils/isReasoningModel.test.ts +0 -90
  660. package/src/llm/openai/utils/messages.test.ts +0 -488
  661. package/src/llm/openrouter/reasoning.test.ts +0 -561
  662. package/src/llm/openrouter/toolCache.test.ts +0 -134
  663. package/src/llm/preempt.test.ts +0 -323
  664. package/src/llm/stream/chunkAdapters.test.ts +0 -202
  665. package/src/llm/stream/reassembly.test.ts +0 -241
  666. package/src/llm/stream/smoother.bench.test.ts +0 -155
  667. package/src/llm/stream/smoother.test.ts +0 -519
  668. package/src/llm/streamLimits.test.ts +0 -450
  669. package/src/llm/truncation.test.ts +0 -242
  670. package/src/llm/vertexai/fixThoughtSignatures.test.ts +0 -154
  671. package/src/llm/vertexai/inherited-stream-events.spec.ts +0 -271
  672. package/src/llm/vertexai/llm.spec.ts +0 -159
  673. package/src/llm/vertexai/repairUsageMetadata.test.ts +0 -54
  674. package/src/llm/vertexai/sealStreamedToolCalls.test.ts +0 -88
  675. package/src/llm/vertexai/streamSealDispatch.test.ts +0 -148
  676. package/src/llm/vertexai/streamSmoothing.test.ts +0 -109
  677. package/src/messages/__tests__/anthropicToolCache.test.ts +0 -339
  678. package/src/messages/__tests__/observationMasking.test.ts +0 -312
  679. package/src/messages/__tests__/recency.test.ts +0 -267
  680. package/src/messages/__tests__/tools.test.ts +0 -473
  681. package/src/messages/alternation.test.ts +0 -212
  682. package/src/messages/assistantPhase.test.ts +0 -75
  683. package/src/messages/cache.tail.test.ts +0 -533
  684. package/src/messages/cache.test.ts +0 -2166
  685. package/src/messages/content.test.ts +0 -362
  686. package/src/messages/contextPruning.test.ts +0 -184
  687. package/src/messages/ensureThinkingBlock.test.ts +0 -1427
  688. package/src/messages/foldToollessToolBlocks.test.ts +0 -596
  689. package/src/messages/formatAgentMessages.reducer.test.ts +0 -162
  690. package/src/messages/formatAgentMessages.skills.test.ts +0 -513
  691. package/src/messages/formatAgentMessages.steer.test.ts +0 -598
  692. package/src/messages/formatAgentMessages.test.ts +0 -8111
  693. package/src/messages/formatAgentMessages.tools.test.ts +0 -522
  694. package/src/messages/formatMessage.test.ts +0 -693
  695. package/src/messages/handoffCue.test.ts +0 -96
  696. package/src/messages/injected.test.ts +0 -107
  697. package/src/messages/labelContentByAgent.test.ts +0 -962
  698. package/src/messages/reducer.spec.ts +0 -32
  699. package/src/messages/shiftIndexTokenCountMap.test.ts +0 -81
  700. package/src/messages/tailCacheConversion.test.ts +0 -161
  701. package/src/openai/__tests__/openai.test.ts +0 -337
  702. package/src/responses/__tests__/responses.test.ts +0 -652
  703. package/src/scripts/abort.ts +0 -157
  704. package/src/scripts/activity-labels/captured.json +0 -56
  705. package/src/scripts/activity-labels/checks.cjs +0 -205
  706. package/src/scripts/activity-labels/corpus.cjs +0 -473
  707. package/src/scripts/activity-labels/report.cjs +0 -203
  708. package/src/scripts/activity-labels/rescore.cjs +0 -102
  709. package/src/scripts/activity-labels/run.ts +0 -705
  710. package/src/scripts/activity-labels/variants.ts +0 -71
  711. package/src/scripts/ant_web_search.ts +0 -159
  712. package/src/scripts/ant_web_search_edge_case.ts +0 -163
  713. package/src/scripts/ant_web_search_error_edge_case.ts +0 -149
  714. package/src/scripts/args.ts +0 -48
  715. package/src/scripts/bedrock-cache-debug.ts +0 -250
  716. package/src/scripts/bedrock-content-aggregation-test.ts +0 -266
  717. package/src/scripts/bedrock-merge-test.ts +0 -107
  718. package/src/scripts/bedrock-parallel-tools-test.ts +0 -204
  719. package/src/scripts/bench-prompt-cache.ts +0 -479
  720. package/src/scripts/caching.ts +0 -132
  721. package/src/scripts/cli.ts +0 -172
  722. package/src/scripts/cli2.ts +0 -133
  723. package/src/scripts/cli3.ts +0 -184
  724. package/src/scripts/cli4.ts +0 -191
  725. package/src/scripts/cli5.ts +0 -191
  726. package/src/scripts/code_exec.ts +0 -214
  727. package/src/scripts/code_exec_files.ts +0 -237
  728. package/src/scripts/code_exec_multi_session.ts +0 -237
  729. package/src/scripts/code_exec_ptc.ts +0 -335
  730. package/src/scripts/code_exec_session.ts +0 -283
  731. package/src/scripts/code_exec_simple.ts +0 -148
  732. package/src/scripts/compare_pi_vs_ours.ts +0 -1259
  733. package/src/scripts/content.ts +0 -139
  734. package/src/scripts/context-overflow-probe.ts +0 -997
  735. package/src/scripts/empty_input.ts +0 -137
  736. package/src/scripts/handoff-test.ts +0 -134
  737. package/src/scripts/local_engine.ts +0 -166
  738. package/src/scripts/local_engine_checkpointer.ts +0 -205
  739. package/src/scripts/local_engine_compile.ts +0 -263
  740. package/src/scripts/local_engine_hooks.ts +0 -226
  741. package/src/scripts/local_engine_image.ts +0 -201
  742. package/src/scripts/local_engine_ptc.ts +0 -151
  743. package/src/scripts/local_engine_workspace.ts +0 -258
  744. package/src/scripts/memory.ts +0 -107
  745. package/src/scripts/multi-agent-chain.ts +0 -332
  746. package/src/scripts/multi-agent-conditional.ts +0 -222
  747. package/src/scripts/multi-agent-document-review-chain.ts +0 -198
  748. package/src/scripts/multi-agent-hybrid-flow.ts +0 -311
  749. package/src/scripts/multi-agent-parallel-start.ts +0 -265
  750. package/src/scripts/multi-agent-parallel.ts +0 -395
  751. package/src/scripts/multi-agent-sequence.ts +0 -217
  752. package/src/scripts/multi-agent-subagent.ts +0 -246
  753. package/src/scripts/multi-agent-supervisor.ts +0 -366
  754. package/src/scripts/multi-agent-test.ts +0 -187
  755. package/src/scripts/openrouter_prompt_cache_live.ts +0 -310
  756. package/src/scripts/parallel-asymmetric-tools-test.ts +0 -275
  757. package/src/scripts/parallel-full-metadata-test.ts +0 -241
  758. package/src/scripts/parallel-tools-test.ts +0 -341
  759. package/src/scripts/preempt-probe.ts +0 -330
  760. package/src/scripts/preempt-scenarios.ts +0 -388
  761. package/src/scripts/programmatic_exec.ts +0 -387
  762. package/src/scripts/programmatic_exec_agent.ts +0 -232
  763. package/src/scripts/search.ts +0 -147
  764. package/src/scripts/sequential-full-metadata-test.ts +0 -198
  765. package/src/scripts/session_live.ts +0 -548
  766. package/src/scripts/simple.ts +0 -226
  767. package/src/scripts/single-agent-metadata-test.ts +0 -196
  768. package/src/scripts/stream.ts +0 -141
  769. package/src/scripts/subagent-configurable-inheritance.ts +0 -252
  770. package/src/scripts/subagent-event-driven-debug.ts +0 -190
  771. package/src/scripts/subagent-tools-debug.ts +0 -160
  772. package/src/scripts/subagent-usage-sink.ts +0 -176
  773. package/src/scripts/summarization-recency.ts +0 -462
  774. package/src/scripts/test-custom-prompt-key.ts +0 -145
  775. package/src/scripts/test-handoff-input.ts +0 -170
  776. package/src/scripts/test-handoff-preamble.ts +0 -278
  777. package/src/scripts/test-handoff-steering.ts +0 -430
  778. package/src/scripts/test-multi-agent-list-handoff.ts +0 -418
  779. package/src/scripts/test-parallel-agent-labeling.ts +0 -327
  780. package/src/scripts/test-parallel-handoffs.ts +0 -292
  781. package/src/scripts/test-thinking-handoff-bedrock.ts +0 -154
  782. package/src/scripts/test-thinking-handoff.ts +0 -156
  783. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +0 -166
  784. package/src/scripts/test-tool-before-handoff-role-order.ts +0 -276
  785. package/src/scripts/test-tools-before-handoff.ts +0 -222
  786. package/src/scripts/test_code_api.ts +0 -354
  787. package/src/scripts/thinking-bedrock.ts +0 -160
  788. package/src/scripts/thinking-vertexai.ts +0 -168
  789. package/src/scripts/thinking.ts +0 -172
  790. package/src/scripts/tool_search.ts +0 -153
  791. package/src/scripts/tools.ts +0 -163
  792. package/src/session/__tests__/JsonlSessionStore.test.ts +0 -1463
  793. package/src/session/__tests__/handlers.test.ts +0 -161
  794. package/src/specs/activity-label-observability.live.test.ts +0 -262
  795. package/src/specs/activity-label-observability.test.ts +0 -167
  796. package/src/specs/activity-label-prompt.test.ts +0 -359
  797. package/src/specs/activity-label-trace-seed.test.ts +0 -47
  798. package/src/specs/activity-phase-label.test.ts +0 -306
  799. package/src/specs/agent-handoffs.live.test.ts +0 -140
  800. package/src/specs/agent-handoffs.test.ts +0 -2465
  801. package/src/specs/anthropic.simple.test.ts +0 -453
  802. package/src/specs/ask-user-question-batch.test.ts +0 -289
  803. package/src/specs/ask-user-questions.live.test.ts +0 -185
  804. package/src/specs/ask-user-questions.test.ts +0 -293
  805. package/src/specs/azure.simple.test.ts +0 -502
  806. package/src/specs/bedrock-toolless.live.test.ts +0 -123
  807. package/src/specs/bedrock-truncation.live.test.ts +0 -191
  808. package/src/specs/cache.simple.test.ts +0 -416
  809. package/src/specs/context-accuracy.live.test.ts +0 -409
  810. package/src/specs/context-overflow-recovery.live.test.ts +0 -213
  811. package/src/specs/context-usage-event.test.ts +0 -117
  812. package/src/specs/context-usage.live.test.ts +0 -297
  813. package/src/specs/custom-event-await.test.ts +0 -304
  814. package/src/specs/deepseek.simple.test.ts +0 -290
  815. package/src/specs/deterministic-trace-id.test.ts +0 -43
  816. package/src/specs/discovered-tools.test.ts +0 -217
  817. package/src/specs/durability-checkpoint.integration.test.ts +0 -243
  818. package/src/specs/graph-subagent.live.test.ts +0 -242
  819. package/src/specs/graph-subagent.test.ts +0 -322
  820. package/src/specs/handoffCue.test.ts +0 -165
  821. package/src/specs/langfuse-callbacks.test.ts +0 -1578
  822. package/src/specs/langfuse-config.test.ts +0 -247
  823. package/src/specs/langfuse-instrumentation.test.ts +0 -393
  824. package/src/specs/langfuse-metadata.test.ts +0 -245
  825. package/src/specs/langfuse-routing.integration.test.ts +0 -844
  826. package/src/specs/langfuse-runtime-context.test.ts +0 -92
  827. package/src/specs/langfuse-span-registry.test.ts +0 -87
  828. package/src/specs/langfuse-tool-output-tracing.test.ts +0 -1858
  829. package/src/specs/langfuse-trace-shaping.test.ts +0 -591
  830. package/src/specs/moonshot.simple.test.ts +0 -367
  831. package/src/specs/multi-agent-summarization.test.ts +0 -396
  832. package/src/specs/openai.simple.test.ts +0 -315
  833. package/src/specs/openrouter.simple.test.ts +0 -275
  834. package/src/specs/preemptSeal.test.ts +0 -678
  835. package/src/specs/prune.test.ts +0 -3741
  836. package/src/specs/reasoning.test.ts +0 -201
  837. package/src/specs/run-step-timestamps.test.ts +0 -414
  838. package/src/specs/spec.utils.ts +0 -15
  839. package/src/specs/subagent.test.ts +0 -864
  840. package/src/specs/summarization-unit.test.ts +0 -973
  841. package/src/specs/summarization.test.ts +0 -3823
  842. package/src/specs/summarize-prune.test.ts +0 -376
  843. package/src/specs/thinking-handoff.test.ts +0 -621
  844. package/src/specs/thinking-prune.test.ts +0 -827
  845. package/src/specs/token-accounting-e2e.test.ts +0 -1034
  846. package/src/specs/token-accounting-pipeline.test.ts +0 -1008
  847. package/src/specs/token-distribution-edge-case.test.ts +0 -315
  848. package/src/specs/token-memoization.test.ts +0 -40
  849. package/src/specs/tokens.test.ts +0 -1000
  850. package/src/specs/tool-error-resume.test.ts +0 -194
  851. package/src/specs/tool-error.test.ts +0 -198
  852. package/src/specs/vllm-reasoning-toolcalls.test.ts +0 -340
  853. package/src/stream.dispatch.test.ts +0 -63
  854. package/src/stream.test.ts +0 -144
  855. package/src/summarization/__tests__/aggregator.test.ts +0 -236
  856. package/src/summarization/__tests__/node.test.ts +0 -1996
  857. package/src/summarization/__tests__/trigger.test.ts +0 -149
  858. package/src/summarization/chunkHandler.test.ts +0 -196
  859. package/src/test/mockTools.ts +0 -386
  860. package/src/tools/Calculator.test.ts +0 -278
  861. package/src/tools/__tests__/BashExecutor.test.ts +0 -108
  862. package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +0 -939
  863. package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +0 -858
  864. package/src/tools/__tests__/CodeExecutor.stateful.test.ts +0 -124
  865. package/src/tools/__tests__/LocalExecutionRoots.test.ts +0 -8
  866. package/src/tools/__tests__/LocalExecutionTools.test.ts +0 -2733
  867. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +0 -318
  868. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -1557
  869. package/src/tools/__tests__/ReadFile.test.ts +0 -44
  870. package/src/tools/__tests__/SkillTool.test.ts +0 -442
  871. package/src/tools/__tests__/SubagentExecutor.test.ts +0 -3728
  872. package/src/tools/__tests__/SubagentReplay.test.ts +0 -329
  873. package/src/tools/__tests__/SubagentTool.test.ts +0 -149
  874. package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +0 -595
  875. package/src/tools/__tests__/ToolNode.eagerEventExecution.test.ts +0 -1191
  876. package/src/tools/__tests__/ToolNode.invalidToolCalls.test.ts +0 -757
  877. package/src/tools/__tests__/ToolNode.langfuse.test.ts +0 -57
  878. package/src/tools/__tests__/ToolNode.onResultCompletion.test.ts +0 -736
  879. package/src/tools/__tests__/ToolNode.outputReferences.test.ts +0 -1710
  880. package/src/tools/__tests__/ToolNode.runtimeState.test.ts +0 -120
  881. package/src/tools/__tests__/ToolNode.session.test.ts +0 -1352
  882. package/src/tools/__tests__/ToolNode.streamLimits.test.ts +0 -69
  883. package/src/tools/__tests__/ToolSearch.integration.test.ts +0 -161
  884. package/src/tools/__tests__/ToolSearch.test.ts +0 -1227
  885. package/src/tools/__tests__/annotateMessagesForLLM.test.ts +0 -561
  886. package/src/tools/__tests__/directToolHITLResumeScope.test.ts +0 -980
  887. package/src/tools/__tests__/directToolHooks.test.ts +0 -700
  888. package/src/tools/__tests__/eagerEventExecution.session.test.ts +0 -92
  889. package/src/tools/__tests__/handlers.test.ts +0 -997
  890. package/src/tools/__tests__/hitl.test.ts +0 -4663
  891. package/src/tools/__tests__/intentArg.test.ts +0 -357
  892. package/src/tools/__tests__/intentCoverage.test.ts +0 -139
  893. package/src/tools/__tests__/localToolNames.test.ts +0 -75
  894. package/src/tools/__tests__/skillCatalog.test.ts +0 -161
  895. package/src/tools/__tests__/subagentHooks.test.ts +0 -1651
  896. package/src/tools/__tests__/toolOutputReferences.test.ts +0 -515
  897. package/src/tools/__tests__/workspaceSeam.test.ts +0 -147
  898. package/src/tools/local/__tests__/FileCheckpointer.test.ts +0 -162
  899. package/src/tools/local/__tests__/editStrategies.test.ts +0 -134
  900. package/src/tools/search/content.test.ts +0 -173
  901. package/src/tools/search/crw.test.ts +0 -836
  902. package/src/tools/search/format.test.ts +0 -242
  903. package/src/tools/search/http-agent.test.ts +0 -133
  904. package/src/tools/search/jina-reranker.test.ts +0 -306
  905. package/src/tools/search/keenable-scraper.test.ts +0 -153
  906. package/src/tools/search/keenable.test.ts +0 -183
  907. package/src/tools/search/outcome.test.ts +0 -90
  908. package/src/tools/search/output.md +0 -2775
  909. package/src/tools/search/rag-api-reranker.test.ts +0 -891
  910. package/src/tools/search/source-processing.test.ts +0 -516
  911. package/src/tools/search/tavily.test.ts +0 -965
  912. package/src/tools/search/test.html +0 -884
  913. package/src/tools/search/test.md +0 -643
  914. package/src/tools/subagent/__tests__/SubagentExecutionRegistry.test.ts +0 -637
  915. package/src/tools/subagent/__tests__/SubagentExecutor.lazy.test.ts +0 -3054
  916. package/src/tools/subagent/__tests__/childGraphConfig.test.ts +0 -521
  917. package/src/utils/__tests__/apportion.test.ts +0 -32
  918. package/src/utils/__tests__/errors.test.ts +0 -270
  919. package/src/utils/__tests__/fixtures/contextOverflowSignatures.ts +0 -336
  920. package/src/utils/__tests__/redactSecrets.test.ts +0 -56
  921. package/src/utils/__tests__/truncation.test.ts +0 -66
  922. package/src/utils/llm.test.ts +0 -18
  923. package/src/utils/proxy.test.ts +0 -176
  924. package/src/utils/toolContent.test.ts +0 -1432
@@ -1,1710 +0,0 @@
1
- import { z } from 'zod';
2
- import { tool } from '@langchain/core/tools';
3
- import { AIMessage, ToolMessage } from '@langchain/core/messages';
4
- import { describe, it, expect, jest, afterEach } from '@jest/globals';
5
- import type { StructuredToolInterface } from '@langchain/core/tools';
6
- import type { PostToolUseHookOutput, PreToolUseHookOutput } from '@/hooks';
7
- import type * as t from '@/types';
8
- import { ToolOutputReferenceRegistry } from '../toolOutputReferences';
9
- import * as events from '@/utils/events';
10
- import { HookRegistry } from '@/hooks';
11
- import { ToolNode } from '../ToolNode';
12
-
13
- /**
14
- * Reads the lazy ref-metadata stamped onto a `ToolMessage` by ToolNode.
15
- * The metadata replaces the durable `[ref: …]` content mutation that the
16
- * earlier eager-annotation design used; the LLM-facing annotation is
17
- * applied at request time by `annotateMessagesForLLM` instead.
18
- */
19
- function getRefKey(msg: ToolMessage): string | undefined {
20
- return (msg.additional_kwargs as { _refKey?: string } | undefined)?._refKey;
21
- }
22
- function getRefScope(msg: ToolMessage): string | undefined {
23
- return (msg.additional_kwargs as { _refScope?: string } | undefined)
24
- ?._refScope;
25
- }
26
- function getUnresolvedRefs(msg: ToolMessage): string[] {
27
- return (
28
- (msg.additional_kwargs as { _unresolvedRefs?: string[] } | undefined)
29
- ?._unresolvedRefs ?? []
30
- );
31
- }
32
-
33
- /**
34
- * Captures the `command` arg each time the tool is invoked and returns
35
- * a configurable string output. The tool shape matches a typical bash
36
- * executor: single required string arg, string response.
37
- */
38
- function createEchoTool(options: {
39
- capturedArgs: string[];
40
- outputs: string[];
41
- name?: string;
42
- }): StructuredToolInterface {
43
- const { capturedArgs, outputs, name = 'echo' } = options;
44
- let callCount = 0;
45
- return tool(
46
- async (input) => {
47
- const args = input as { command: string };
48
- capturedArgs.push(args.command);
49
- const output = outputs[callCount] ?? outputs[outputs.length - 1];
50
- callCount++;
51
- return output;
52
- },
53
- {
54
- name,
55
- description: 'Echo test tool',
56
- schema: z.object({ command: z.string() }),
57
- }
58
- ) as unknown as StructuredToolInterface;
59
- }
60
-
61
- function aiMsgWithCalls(
62
- calls: Array<{ id: string; name: string; command: string }>
63
- ): AIMessage {
64
- return new AIMessage({
65
- content: '',
66
- tool_calls: calls.map((c) => ({
67
- id: c.id,
68
- name: c.name,
69
- args: { command: c.command },
70
- })),
71
- });
72
- }
73
-
74
- async function invokeBatch(
75
- toolNode: ToolNode,
76
- calls: Array<{ id: string; name: string; command: string }>,
77
- runId: string = 'test-run'
78
- ): Promise<ToolMessage[]> {
79
- const aiMsg = aiMsgWithCalls(calls);
80
- const result = (await toolNode.invoke(
81
- { messages: [aiMsg] },
82
- { configurable: { run_id: runId } }
83
- )) as ToolMessage[] | { messages: ToolMessage[] };
84
- return Array.isArray(result) ? result : result.messages;
85
- }
86
-
87
- describe('ToolNode tool output references', () => {
88
- describe('disabled (default)', () => {
89
- it('does not annotate outputs or register anything when disabled', async () => {
90
- const capturedArgs: string[] = [];
91
- const t1 = createEchoTool({
92
- capturedArgs,
93
- outputs: ['plain-output'],
94
- });
95
- const node = new ToolNode({ tools: [t1] });
96
-
97
- const [msg] = await invokeBatch(node, [
98
- { id: 'c1', name: 'echo', command: 'hello' },
99
- ]);
100
-
101
- expect(msg.content).toBe('plain-output');
102
- expect(node._unsafeGetToolOutputRegistry()).toBeUndefined();
103
- });
104
-
105
- it('does not substitute placeholders when disabled', async () => {
106
- const capturedArgs: string[] = [];
107
- const t1 = createEchoTool({ capturedArgs, outputs: ['X'] });
108
- const node = new ToolNode({ tools: [t1] });
109
-
110
- await invokeBatch(node, [
111
- { id: 'c1', name: 'echo', command: 'raw {{tool0turn0}}' },
112
- ]);
113
-
114
- expect(capturedArgs).toEqual(['raw {{tool0turn0}}']);
115
- });
116
-
117
- it('bounds structured ToolMessage output before its first model call', async () => {
118
- const structuredTool = tool(
119
- async () =>
120
- new ToolMessage({
121
- status: 'success',
122
- content: [
123
- {
124
- type: 'json',
125
- rows: Array.from({ length: 20 }, (_, index) => ({
126
- id: index,
127
- value: `${'x'.repeat(100)}-${index}`,
128
- })),
129
- },
130
- ],
131
- artifact: { source: 'clickhouse' },
132
- metadata: { requestId: 'request-1' },
133
- name: 'run_select_query',
134
- tool_call_id: 'c1',
135
- }),
136
- {
137
- name: 'run_select_query',
138
- description: 'returns structured rows',
139
- schema: z.object({ command: z.string() }),
140
- }
141
- ) as unknown as StructuredToolInterface;
142
- const node = new ToolNode({
143
- tools: [structuredTool],
144
- maxToolResultChars: 200,
145
- });
146
-
147
- const [msg] = await invokeBatch(node, [
148
- {
149
- id: 'c1',
150
- name: 'run_select_query',
151
- command: 'SELECT * FROM events',
152
- },
153
- ]);
154
-
155
- expect(typeof msg.content).toBe('string');
156
- expect(msg.content).toContain('truncated');
157
- expect((msg.content as string).length).toBeLessThanOrEqual(200);
158
- expect(msg.tool_call_id).toBe('c1');
159
- expect(msg.name).toBe('run_select_query');
160
- expect(msg.status).toBe('success');
161
- expect(msg.artifact).toEqual({ source: 'clickhouse' });
162
- expect(msg.metadata).toEqual({ requestId: 'request-1' });
163
- });
164
- });
165
-
166
- describe('enabled', () => {
167
- it('keeps string outputs clean and stamps the ref key as metadata', async () => {
168
- const t1 = createEchoTool({
169
- capturedArgs: [],
170
- outputs: ['hello world'],
171
- });
172
- const node = new ToolNode({
173
- tools: [t1],
174
- toolOutputReferences: { enabled: true },
175
- });
176
-
177
- const [msg] = await invokeBatch(node, [
178
- { id: 'c1', name: 'echo', command: 'run' },
179
- ]);
180
-
181
- expect(msg.content).toBe('hello world');
182
- expect(getRefKey(msg)).toBe('tool0turn0');
183
- /**
184
- * `_refScope` is what lets `annotateMessagesForLLM` recover the
185
- * registry bucket at request time without re-deriving it from
186
- * `config.configurable.run_id` (which fails for anonymous
187
- * batches). For named runs it equals the run_id.
188
- */
189
- expect(getRefScope(msg)).toBe('test-run');
190
- expect(getUnresolvedRefs(msg)).toEqual([]);
191
- });
192
-
193
- it('keeps JSON-object string outputs unmodified and stamps ref metadata', async () => {
194
- const t1 = createEchoTool({
195
- capturedArgs: [],
196
- outputs: ['{"a":1,"b":"x"}'],
197
- });
198
- const node = new ToolNode({
199
- tools: [t1],
200
- toolOutputReferences: { enabled: true },
201
- });
202
-
203
- const [msg] = await invokeBatch(node, [
204
- { id: 'c1', name: 'echo', command: 'run' },
205
- ]);
206
-
207
- const parsed = JSON.parse(msg.content as string);
208
- expect(parsed.a).toBe(1);
209
- expect(parsed.b).toBe('x');
210
- expect(parsed._ref).toBeUndefined();
211
- expect(getRefKey(msg)).toBe('tool0turn0');
212
- });
213
-
214
- it('keeps JSON array outputs unmodified and stamps ref metadata', async () => {
215
- const t1 = createEchoTool({ capturedArgs: [], outputs: ['[1,2,3]'] });
216
- const node = new ToolNode({
217
- tools: [t1],
218
- toolOutputReferences: { enabled: true },
219
- });
220
-
221
- const [msg] = await invokeBatch(node, [
222
- { id: 'c1', name: 'echo', command: 'run' },
223
- ]);
224
-
225
- expect(msg.content).toBe('[1,2,3]');
226
- expect(getRefKey(msg)).toBe('tool0turn0');
227
- });
228
-
229
- it('registers the un-annotated output for piping into later calls', async () => {
230
- const capturedArgs: string[] = [];
231
- const t1 = createEchoTool({
232
- capturedArgs,
233
- outputs: ['raw-payload', 'second-call'],
234
- });
235
- const node = new ToolNode({
236
- tools: [t1],
237
- toolOutputReferences: { enabled: true },
238
- });
239
-
240
- await invokeBatch(node, [{ id: 'c1', name: 'echo', command: 'first' }]);
241
- await invokeBatch(node, [
242
- {
243
- id: 'c2',
244
- name: 'echo',
245
- command: 'echo {{tool0turn0}}',
246
- },
247
- ]);
248
-
249
- expect(capturedArgs).toEqual(['first', 'echo raw-payload']);
250
- });
251
-
252
- it('keeps generated-file summaries out of registered outputs', async () => {
253
- const rawOutput = [
254
- 'stdout:',
255
- '{"ok":true}',
256
- '',
257
- 'Generated files:',
258
- 'Session files: 1 persisted file(s) are available in /mnt/data, including 0 image(s). Use known /mnt/data paths directly in later code-tool calls. The app displays files/images automatically; do not invent download links or wrap generated images in Markdown.',
259
- ].join('\n');
260
- const cleanOutput = 'stdout:\n{"ok":true}';
261
- const capturedArgs: string[] = [];
262
- const filesTool = tool(
263
- async () =>
264
- new ToolMessage({
265
- status: 'success',
266
- content: rawOutput,
267
- name: 'files',
268
- tool_call_id: 'c1',
269
- }),
270
- {
271
- name: 'files',
272
- description: 'returns generated-file summary output',
273
- schema: z.object({ command: z.string() }),
274
- }
275
- ) as unknown as StructuredToolInterface;
276
- const echo = createEchoTool({
277
- capturedArgs,
278
- outputs: ['resolved'],
279
- });
280
- const node = new ToolNode({
281
- tools: [filesTool, echo],
282
- toolOutputReferences: { enabled: true },
283
- });
284
-
285
- const [msg] = await invokeBatch(node, [
286
- { id: 'c1', name: 'files', command: 'first' },
287
- ]);
288
- await invokeBatch(node, [
289
- {
290
- id: 'c2',
291
- name: 'echo',
292
- command: 'echo {{tool0turn0}}',
293
- },
294
- ]);
295
-
296
- expect(msg.content).toBe(rawOutput);
297
- expect(getRefKey(msg)).toBe('tool0turn0');
298
- expect(
299
- node._unsafeGetToolOutputRegistry()!.get('test-run', 'tool0turn0')
300
- ).toBe(cleanOutput);
301
- expect(capturedArgs).toEqual([`echo ${cleanOutput}`]);
302
- });
303
-
304
- it('increments the turn counter per ToolNode batch', async () => {
305
- const capturedArgs: string[] = [];
306
- const t1 = createEchoTool({
307
- capturedArgs,
308
- outputs: ['one', 'two', 'three'],
309
- });
310
- const node = new ToolNode({
311
- tools: [t1],
312
- toolOutputReferences: { enabled: true },
313
- });
314
-
315
- const [m0] = await invokeBatch(node, [
316
- { id: 'b1c1', name: 'echo', command: 'a' },
317
- ]);
318
- const [m1] = await invokeBatch(node, [
319
- { id: 'b2c1', name: 'echo', command: 'b' },
320
- ]);
321
- const [m2] = await invokeBatch(node, [
322
- { id: 'b3c1', name: 'echo', command: '{{tool0turn1}}' },
323
- ]);
324
-
325
- expect(getRefKey(m0)).toBe('tool0turn0');
326
- expect(getRefKey(m1)).toBe('tool0turn1');
327
- expect(getRefKey(m2)).toBe('tool0turn2');
328
- expect(capturedArgs[2]).toBe('two');
329
- });
330
-
331
- it('uses array index within a batch for the tool<idx> segment', async () => {
332
- const capturedA: string[] = [];
333
- const capturedB: string[] = [];
334
- const tA = createEchoTool({
335
- capturedArgs: capturedA,
336
- outputs: ['A-out'],
337
- name: 'alpha',
338
- });
339
- const tB = createEchoTool({
340
- capturedArgs: capturedB,
341
- outputs: ['B-out'],
342
- name: 'beta',
343
- });
344
- const node = new ToolNode({
345
- tools: [tA, tB],
346
- toolOutputReferences: { enabled: true },
347
- });
348
-
349
- const messages = await invokeBatch(node, [
350
- { id: 'c1', name: 'alpha', command: 'a' },
351
- { id: 'c2', name: 'beta', command: 'b' },
352
- ]);
353
-
354
- expect(getRefKey(messages[0])).toBe('tool0turn0');
355
- expect(getRefKey(messages[1])).toBe('tool1turn0');
356
- });
357
-
358
- it('reports unresolved placeholders after the output', async () => {
359
- const capturedArgs: string[] = [];
360
- const t1 = createEchoTool({ capturedArgs, outputs: ['done'] });
361
- const node = new ToolNode({
362
- tools: [t1],
363
- toolOutputReferences: { enabled: true },
364
- });
365
-
366
- const [msg] = await invokeBatch(node, [
367
- {
368
- id: 'c1',
369
- name: 'echo',
370
- command: 'see {{tool9turn9}}',
371
- },
372
- ]);
373
-
374
- expect(capturedArgs[0]).toBe('see {{tool9turn9}}');
375
- expect(msg.content).toBe('done');
376
- expect(getUnresolvedRefs(msg)).toEqual(['tool9turn9']);
377
- });
378
-
379
- it('stores the raw untruncated output in the registry, independent of the LLM-visible truncation', async () => {
380
- const raw = 'X'.repeat(8_000);
381
- const capturedArgs: string[] = [];
382
- const t1 = createEchoTool({
383
- capturedArgs,
384
- outputs: [raw, 'second'],
385
- });
386
- const node = new ToolNode({
387
- tools: [t1],
388
- maxToolResultChars: 200,
389
- toolOutputReferences: { enabled: true },
390
- });
391
-
392
- const [first] = await invokeBatch(
393
- node,
394
- [{ id: 'c1', name: 'echo', command: 'first' }],
395
- 'raw-preservation'
396
- );
397
-
398
- expect((first.content as string).length).toBeLessThan(raw.length);
399
- expect(first.content).toContain('truncated');
400
-
401
- await invokeBatch(
402
- node,
403
- [{ id: 'c2', name: 'echo', command: 'echo {{tool0turn0}}' }],
404
- 'raw-preservation'
405
- );
406
-
407
- expect(capturedArgs[1]).toBe(`echo ${raw}`);
408
- expect(
409
- node
410
- ._unsafeGetToolOutputRegistry()!
411
- .get('raw-preservation', 'tool0turn0')
412
- ).toBe(raw);
413
- });
414
-
415
- it('preserves structured output exactly up to the registry limit', async () => {
416
- const structured = {
417
- rows: Array.from({ length: 10 }, (_, index) => ({
418
- id: index,
419
- value: `row-${index}-${'x'.repeat(100)}`,
420
- })),
421
- };
422
- const exact = JSON.stringify(structured);
423
- const capturedArgs: string[] = [];
424
- let callCount = 0;
425
- const structuredTool = createEchoTool({
426
- capturedArgs: [],
427
- outputs: ['unused'],
428
- name: 'structured',
429
- });
430
- (
431
- structuredTool as unknown as {
432
- invoke: (input: {
433
- args: { command: string };
434
- }) => Promise<typeof structured | string>;
435
- }
436
- ).invoke = async (input) => {
437
- capturedArgs.push(input.args.command);
438
- return callCount++ === 0 ? structured : 'done';
439
- };
440
- const node = new ToolNode({
441
- tools: [structuredTool],
442
- maxToolResultChars: 100,
443
- toolOutputReferences: {
444
- enabled: true,
445
- maxOutputSize: exact.length,
446
- },
447
- });
448
-
449
- const [first] = await invokeBatch(
450
- node,
451
- [{ id: 'c1', name: 'structured', command: 'first' }],
452
- 'structured-raw-preservation'
453
- );
454
- await invokeBatch(
455
- node,
456
- [
457
- {
458
- id: 'c2',
459
- name: 'structured',
460
- command: '{{tool0turn0}}',
461
- },
462
- ],
463
- 'structured-raw-preservation'
464
- );
465
-
466
- expect((first.content as string).length).toBeLessThanOrEqual(100);
467
- expect(first.content).toContain('truncated');
468
- expect(capturedArgs[1]).toBe(exact);
469
- expect(
470
- node
471
- ._unsafeGetToolOutputRegistry()!
472
- .get('structured-raw-preservation', 'tool0turn0')
473
- ).toBe(exact);
474
- });
475
-
476
- it('uses each batch\'s own turn when ToolNode is invoked concurrently within a run', async () => {
477
- const gates: Record<string, () => void> = {};
478
- const slowTool = tool(
479
- async (input) => {
480
- const args = input as { command: string };
481
- await new Promise<void>((resolve) => {
482
- gates[args.command] = resolve;
483
- });
484
- return `output-${args.command}`;
485
- },
486
- {
487
- name: 'slow',
488
- description: 'awaits a per-command gate',
489
- schema: z.object({ command: z.string() }),
490
- }
491
- ) as unknown as StructuredToolInterface;
492
-
493
- const node = new ToolNode({
494
- tools: [slowTool],
495
- toolOutputReferences: { enabled: true },
496
- });
497
-
498
- // Two batches of the SAME run, started concurrently — batch A
499
- // captures turn 0 in its sync prefix, batch B captures turn 1.
500
- // If the turn were read from shared state after the awaits, the
501
- // reads would race and both batches would see the latest value.
502
- const first = node.invoke(
503
- {
504
- messages: [aiMsgWithCalls([{ id: 'a', name: 'slow', command: 'A' }])],
505
- },
506
- { configurable: { run_id: 'concurrent-run' } }
507
- );
508
- const second = node.invoke(
509
- {
510
- messages: [aiMsgWithCalls([{ id: 'b', name: 'slow', command: 'B' }])],
511
- },
512
- { configurable: { run_id: 'concurrent-run' } }
513
- );
514
-
515
- await new Promise<void>((resolve) => {
516
- const check = (): void => {
517
- if (
518
- Object.prototype.hasOwnProperty.call(gates, 'A') &&
519
- Object.prototype.hasOwnProperty.call(gates, 'B')
520
- ) {
521
- resolve();
522
- } else {
523
- setTimeout(check, 5);
524
- }
525
- };
526
- check();
527
- });
528
- // Release B first (the later-scheduled batch), then A. Under the
529
- // old code this would bake turn=1 into BOTH results because
530
- // `currentTurn` was overwritten during B's sync prefix.
531
- gates.B();
532
- gates.A();
533
-
534
- const [resA, resB] = (await Promise.all([first, second])) as Array<{
535
- messages: ToolMessage[];
536
- }>;
537
-
538
- expect(getRefKey(resA.messages[0])).toBe('tool0turn0');
539
- expect(resA.messages[0].content).toBe('output-A');
540
- expect(getRefKey(resB.messages[0])).toBe('tool0turn1');
541
- expect(resB.messages[0].content).toBe('output-B');
542
-
543
- const registry = node._unsafeGetToolOutputRegistry()!;
544
- expect(registry.get('concurrent-run', 'tool0turn0')).toBe('output-A');
545
- expect(registry.get('concurrent-run', 'tool0turn1')).toBe('output-B');
546
- });
547
-
548
- it('clips registered outputs to maxOutputSize', async () => {
549
- const t1 = createEchoTool({
550
- capturedArgs: [],
551
- outputs: ['{"payload":"' + 'y'.repeat(200) + '"}'],
552
- });
553
- const node = new ToolNode({
554
- tools: [t1],
555
- toolOutputReferences: { enabled: true, maxOutputSize: 40 },
556
- });
557
-
558
- await invokeBatch(node, [{ id: 'c1', name: 'echo', command: 'x' }]);
559
-
560
- const registry = node._unsafeGetToolOutputRegistry();
561
- expect(registry).toBeDefined();
562
- expect(
563
- registry!.get('test-run', 'tool0turn0')!.length
564
- ).toBeLessThanOrEqual(40);
565
- });
566
-
567
- it('honors maxTotalSize via FIFO eviction across batches', async () => {
568
- const t1 = createEchoTool({
569
- capturedArgs: [],
570
- outputs: ['aaaaa', 'bbbbb', 'ccccc'],
571
- });
572
- const node = new ToolNode({
573
- tools: [t1],
574
- toolOutputReferences: {
575
- enabled: true,
576
- maxOutputSize: 10,
577
- maxTotalSize: 10,
578
- },
579
- });
580
-
581
- await invokeBatch(node, [{ id: 'c1', name: 'echo', command: 'x' }]);
582
- await invokeBatch(node, [{ id: 'c2', name: 'echo', command: 'x' }]);
583
- await invokeBatch(node, [{ id: 'c3', name: 'echo', command: 'x' }]);
584
-
585
- const registry = node._unsafeGetToolOutputRegistry()!;
586
- expect(registry.get('test-run', 'tool0turn0')).toBeUndefined();
587
- expect(registry.get('test-run', 'tool0turn1')).toBe('bbbbb');
588
- expect(registry.get('test-run', 'tool0turn2')).toBe('ccccc');
589
- });
590
-
591
- it('does not register error outputs', async () => {
592
- const boom = tool(
593
- async () => {
594
- throw new Error('nope');
595
- },
596
- {
597
- name: 'boom',
598
- description: 'always errors',
599
- schema: z.object({ command: z.string() }),
600
- }
601
- ) as unknown as StructuredToolInterface;
602
-
603
- const node = new ToolNode({
604
- tools: [boom],
605
- toolOutputReferences: { enabled: true },
606
- });
607
-
608
- const [msg] = await invokeBatch(node, [
609
- { id: 'c1', name: 'boom', command: 'x' },
610
- ]);
611
-
612
- expect(getRefKey(msg)).toBeUndefined();
613
- expect(
614
- node._unsafeGetToolOutputRegistry()!.get('test-run', 'tool0turn0')
615
- ).toBeUndefined();
616
- });
617
-
618
- it('surfaces unresolved refs on thrown-error ToolMessages', async () => {
619
- const boom = tool(
620
- async () => {
621
- throw new Error('nope');
622
- },
623
- {
624
- name: 'boom',
625
- description: 'always errors',
626
- schema: z.object({ command: z.string() }),
627
- }
628
- ) as unknown as StructuredToolInterface;
629
-
630
- const node = new ToolNode({
631
- tools: [boom],
632
- toolOutputReferences: { enabled: true },
633
- });
634
-
635
- const [msg] = await invokeBatch(node, [
636
- { id: 'c1', name: 'boom', command: 'see {{tool9turn9}}' },
637
- ]);
638
-
639
- expect(msg.content).toContain('Error: nope');
640
- expect(msg.content as string).not.toContain('[unresolved refs:');
641
- expect(getUnresolvedRefs(msg)).toEqual(['tool9turn9']);
642
- });
643
-
644
- it('surfaces unresolved refs on tool-returned error ToolMessages', async () => {
645
- const errReturn = tool(
646
- async () =>
647
- new ToolMessage({
648
- status: 'error',
649
- content: 'handled failure',
650
- name: 'errReturn',
651
- tool_call_id: 'c1',
652
- }),
653
- {
654
- name: 'errReturn',
655
- description: 'returns error ToolMessage',
656
- schema: z.object({ command: z.string() }),
657
- }
658
- ) as unknown as StructuredToolInterface;
659
-
660
- const node = new ToolNode({
661
- tools: [errReturn],
662
- toolOutputReferences: { enabled: true },
663
- });
664
-
665
- const [msg] = await invokeBatch(node, [
666
- { id: 'c1', name: 'errReturn', command: 'see {{tool9turn9}}' },
667
- ]);
668
-
669
- expect(msg.content).toBe('handled failure');
670
- expect(getUnresolvedRefs(msg)).toEqual(['tool9turn9']);
671
- });
672
-
673
- it('isolates state between overlapping runs on the same ToolNode', async () => {
674
- const sharedRegistry = new ToolOutputReferenceRegistry();
675
- const capturedArgs: string[] = [];
676
- const tl = createEchoTool({
677
- capturedArgs,
678
- outputs: ['out-A', 'out-B', 'resolved-in-B'],
679
- });
680
-
681
- const node = new ToolNode({
682
- tools: [tl],
683
- toolOutputRegistry: sharedRegistry,
684
- });
685
-
686
- // Run A records `tool0turn0` → 'out-A' in its bucket.
687
- await node.invoke(
688
- {
689
- messages: [
690
- aiMsgWithCalls([{ id: 'a1', name: 'echo', command: 'a' }]),
691
- ],
692
- },
693
- { configurable: { run_id: 'run-A' } }
694
- );
695
- expect(sharedRegistry.get('run-A', 'tool0turn0')).toBe('out-A');
696
-
697
- // Run B records `tool0turn0` → 'out-B' in its own bucket.
698
- // Under the old global-reset design, starting run B would have
699
- // wiped run A's registered output; with partitioning, A's
700
- // bucket survives untouched.
701
- await node.invoke(
702
- {
703
- messages: [
704
- aiMsgWithCalls([{ id: 'b1', name: 'echo', command: 'b' }]),
705
- ],
706
- },
707
- { configurable: { run_id: 'run-B' } }
708
- );
709
- expect(sharedRegistry.get('run-A', 'tool0turn0')).toBe('out-A');
710
- expect(sharedRegistry.get('run-B', 'tool0turn0')).toBe('out-B');
711
-
712
- // Run B's next batch resolves `{{tool0turn0}}` against its own
713
- // partition (out-B), not run A's partition (out-A).
714
- await node.invoke(
715
- {
716
- messages: [
717
- aiMsgWithCalls([
718
- { id: 'b2', name: 'echo', command: 'see {{tool0turn0}}' },
719
- ]),
720
- ],
721
- },
722
- { configurable: { run_id: 'run-B' } }
723
- );
724
- expect(capturedArgs[2]).toBe('see out-B');
725
- });
726
-
727
- it('gives concurrent anonymous invocations independent scopes', async () => {
728
- const gates: Record<string, () => void> = {};
729
- const slowTool = tool(
730
- async (input) => {
731
- const args = input as { command: string };
732
- await new Promise<void>((resolve) => {
733
- gates[args.command] = resolve;
734
- });
735
- return `out-${args.command}`;
736
- },
737
- {
738
- name: 'slow',
739
- description: 'awaits a per-command gate',
740
- schema: z.object({ command: z.string() }),
741
- }
742
- ) as unknown as StructuredToolInterface;
743
-
744
- const node = new ToolNode({
745
- tools: [slowTool],
746
- toolOutputReferences: { enabled: true },
747
- });
748
-
749
- // Two invocations without `run_id`, started concurrently. Before
750
- // the unique-anon-scope fix, the second invocation's sync prefix
751
- // would have deleted the shared anonymous bucket that the first
752
- // invocation's tool was about to register into.
753
- const first = node.invoke({
754
- messages: [aiMsgWithCalls([{ id: 'a1', name: 'slow', command: 'A' }])],
755
- });
756
- const second = node.invoke({
757
- messages: [aiMsgWithCalls([{ id: 'b1', name: 'slow', command: 'B' }])],
758
- });
759
-
760
- await new Promise<void>((resolve) => {
761
- const check = (): void => {
762
- if (
763
- Object.prototype.hasOwnProperty.call(gates, 'A') &&
764
- Object.prototype.hasOwnProperty.call(gates, 'B')
765
- ) {
766
- resolve();
767
- } else {
768
- setTimeout(check, 5);
769
- }
770
- };
771
- check();
772
- });
773
- gates.B();
774
- gates.A();
775
-
776
- const [resA, resB] = (await Promise.all([first, second])) as Array<{
777
- messages: ToolMessage[];
778
- }>;
779
-
780
- // Each invocation stamps its own ref metadata — neither's
781
- // registered tool0turn0 was clobbered by the other's sync-prefix
782
- // reset.
783
- expect(getRefKey(resA.messages[0])).toBe('tool0turn0');
784
- expect(resA.messages[0].content).toBe('out-A');
785
- expect(getRefKey(resB.messages[0])).toBe('tool0turn0');
786
- expect(resB.messages[0].content).toBe('out-B');
787
-
788
- /**
789
- * Each anonymous invocation stamps a distinct synthetic
790
- * `_refScope` so the lazy annotation transform can later look
791
- * up the right registry bucket — `config.configurable.run_id`
792
- * is undefined for both calls and would collapse them to the
793
- * same `\0anon` bucket without this stamping.
794
- */
795
- const scopeA = getRefScope(resA.messages[0]);
796
- const scopeB = getRefScope(resB.messages[0]);
797
- expect(scopeA).toMatch(/^\0anon-\d+$/);
798
- expect(scopeB).toMatch(/^\0anon-\d+$/);
799
- expect(scopeA).not.toBe(scopeB);
800
- });
801
-
802
- it('clears state on every batch when run_id is absent (anonymous caller)', async () => {
803
- const capturedArgs: string[] = [];
804
- const t1 = createEchoTool({
805
- capturedArgs,
806
- outputs: ['first-anonymous', 'second-anonymous'],
807
- });
808
- const node = new ToolNode({
809
- tools: [t1],
810
- toolOutputReferences: { enabled: true },
811
- });
812
-
813
- await node.invoke({
814
- messages: [aiMsgWithCalls([{ id: 'a1', name: 'echo', command: 'a' }])],
815
- });
816
- const result = (await node.invoke({
817
- messages: [
818
- aiMsgWithCalls([
819
- { id: 'a2', name: 'echo', command: 'echo {{tool0turn0}}' },
820
- ]),
821
- ],
822
- })) as { messages: ToolMessage[] };
823
-
824
- expect(capturedArgs[1]).toBe('echo {{tool0turn0}}');
825
- expect(getUnresolvedRefs(result.messages[0])).toEqual(['tool0turn0']);
826
- });
827
-
828
- it('lets two ToolNodes sharing a registry resolve each other\'s refs', async () => {
829
- const sharedRegistry = new ToolOutputReferenceRegistry();
830
- const capturedA: string[] = [];
831
- const capturedB: string[] = [];
832
- const toolA = createEchoTool({
833
- capturedArgs: capturedA,
834
- outputs: ['agent-A-output'],
835
- name: 'alpha',
836
- });
837
- const toolB = createEchoTool({
838
- capturedArgs: capturedB,
839
- outputs: ['agent-B-output'],
840
- name: 'beta',
841
- });
842
-
843
- // Two independent ToolNodes (simulating one per agent in a
844
- // multi-agent graph) sharing one registry instance.
845
- const nodeA = new ToolNode({
846
- tools: [toolA],
847
- toolOutputRegistry: sharedRegistry,
848
- });
849
- const nodeB = new ToolNode({
850
- tools: [toolB],
851
- toolOutputRegistry: sharedRegistry,
852
- });
853
-
854
- await nodeA.invoke(
855
- {
856
- messages: [
857
- aiMsgWithCalls([{ id: 'a1', name: 'alpha', command: 'first' }]),
858
- ],
859
- },
860
- { configurable: { run_id: 'shared-run' } }
861
- );
862
-
863
- await nodeB.invoke(
864
- {
865
- messages: [
866
- aiMsgWithCalls([
867
- { id: 'b1', name: 'beta', command: 'see {{tool0turn0}}' },
868
- ]),
869
- ],
870
- },
871
- { configurable: { run_id: 'shared-run' } }
872
- );
873
-
874
- // nodeB resolved nodeA's tool0turn0 placeholder (cross-node),
875
- // and its own output landed under the *next* turn (1), not 0.
876
- expect(capturedB[0]).toBe('see agent-A-output');
877
- expect(sharedRegistry.get('shared-run', 'tool0turn0')).toBe(
878
- 'agent-A-output'
879
- );
880
- expect(sharedRegistry.get('shared-run', 'tool0turn1')).toBe(
881
- 'agent-B-output'
882
- );
883
- });
884
-
885
- it('emits resolved args in ON_RUN_STEP_COMPLETED, not the template', async () => {
886
- const capturedArgs: string[] = [];
887
- const t1 = createEchoTool({
888
- capturedArgs,
889
- outputs: ['STORED', 'second'],
890
- });
891
- const stepCompletedArgs: string[] = [];
892
- jest
893
- .spyOn(events, 'safeDispatchCustomEvent')
894
- .mockImplementation(async (event, data) => {
895
- if (event === 'on_run_step_completed') {
896
- const step = data as {
897
- result: { tool_call: { args: string } };
898
- };
899
- stepCompletedArgs.push(step.result.tool_call.args);
900
- }
901
- });
902
-
903
- const node = new ToolNode({
904
- tools: [t1],
905
- toolCallStepIds: new Map([
906
- ['a1', 'step_a1'],
907
- ['a2', 'step_a2'],
908
- ]),
909
- toolOutputReferences: { enabled: true },
910
- });
911
-
912
- await invokeBatch(
913
- node,
914
- [{ id: 'a1', name: 'echo', command: 'first' }],
915
- 'resolved-args'
916
- );
917
- await invokeBatch(
918
- node,
919
- [
920
- {
921
- id: 'a2',
922
- name: 'echo',
923
- command: 'echo {{tool0turn0}}',
924
- },
925
- ],
926
- 'resolved-args'
927
- );
928
-
929
- // Second step-completed event should reflect the post-
930
- // substitution command, not the `{{…}}` template.
931
- expect(stepCompletedArgs).toHaveLength(2);
932
- expect(JSON.parse(stepCompletedArgs[1]).command).toBe('echo STORED');
933
- });
934
-
935
- it('records unresolved refs on multipart ToolMessage content within the cap', async () => {
936
- const complexTool = tool(
937
- async () =>
938
- new ToolMessage({
939
- status: 'success',
940
- content: [
941
- { type: 'text', text: 'data' },
942
- { type: 'image_url', image_url: { url: 'data:...' } },
943
- ],
944
- name: 'complex',
945
- tool_call_id: 'c1',
946
- }),
947
- {
948
- name: 'complex',
949
- description: 'returns multi-part content',
950
- schema: z.object({ command: z.string() }),
951
- }
952
- ) as unknown as StructuredToolInterface;
953
-
954
- const node = new ToolNode({
955
- tools: [complexTool],
956
- toolOutputReferences: { enabled: true },
957
- });
958
-
959
- const [msg] = await invokeBatch(
960
- node,
961
- [{ id: 'c1', name: 'complex', command: 'see {{tool9turn9}}' }],
962
- 'non-string'
963
- );
964
-
965
- expect(Array.isArray(msg.content)).toBe(true);
966
- const blocks = msg.content as Array<{ type: string; text?: string }>;
967
- // In-budget multi-part content stays intact; the lazy transform handles
968
- // the unresolved-refs warning at request time.
969
- expect(blocks).toHaveLength(2);
970
- expect(blocks[0].type).toBe('text');
971
- expect(blocks[0].text).toBe('data');
972
- expect(blocks[1].type).toBe('image_url');
973
- expect(getUnresolvedRefs(msg)).toEqual(['tool9turn9']);
974
- });
975
-
976
- it('resets the registry and turn counter when the runId changes', async () => {
977
- const capturedArgs: string[] = [];
978
- const t1 = createEchoTool({
979
- capturedArgs,
980
- outputs: ['from-run-A', 'from-run-B'],
981
- });
982
- const node = new ToolNode({
983
- tools: [t1],
984
- toolOutputReferences: { enabled: true },
985
- });
986
-
987
- const aiMsgA = aiMsgWithCalls([
988
- { id: 'a1', name: 'echo', command: 'first' },
989
- ]);
990
- await node.invoke(
991
- { messages: [aiMsgA] },
992
- { configurable: { run_id: 'run-A' } }
993
- );
994
-
995
- const aiMsgB = aiMsgWithCalls([
996
- {
997
- id: 'b1',
998
- name: 'echo',
999
- command: 'echo {{tool0turn0}}',
1000
- },
1001
- ]);
1002
- const resultB = (await node.invoke(
1003
- { messages: [aiMsgB] },
1004
- { configurable: { run_id: 'run-B' } }
1005
- )) as { messages: ToolMessage[] };
1006
-
1007
- expect(capturedArgs[1]).toBe('echo {{tool0turn0}}');
1008
- expect(resultB.messages[0].content).toBe('from-run-B');
1009
- expect(getRefKey(resultB.messages[0])).toBe('tool0turn0');
1010
- expect(getUnresolvedRefs(resultB.messages[0])).toEqual(['tool0turn0']);
1011
- });
1012
- });
1013
-
1014
- describe('event-driven dispatch path', () => {
1015
- afterEach(() => {
1016
- jest.restoreAllMocks();
1017
- });
1018
-
1019
- function mockEventDispatch(mockResults: t.ToolExecuteResult[]): void {
1020
- jest
1021
- .spyOn(events, 'safeDispatchCustomEvent')
1022
- .mockImplementation(async (event, data) => {
1023
- if (event !== 'on_tool_execute') {
1024
- return;
1025
- }
1026
- const request = data as Record<string, unknown>;
1027
- if (typeof request.resolve === 'function') {
1028
- (request.resolve as (r: t.ToolExecuteResult[]) => void)(
1029
- mockResults
1030
- );
1031
- }
1032
- });
1033
- }
1034
-
1035
- function createSchemaStub(name: string): StructuredToolInterface {
1036
- return tool(async () => 'unused', {
1037
- name,
1038
- description: 'schema-only stub; host executes via ON_TOOL_EXECUTE',
1039
- schema: z.object({ command: z.string() }),
1040
- }) as unknown as StructuredToolInterface;
1041
- }
1042
-
1043
- it('keeps host-returned output clean and stamps the ref key as metadata', async () => {
1044
- const node = new ToolNode({
1045
- tools: [createSchemaStub('echo')],
1046
- eventDrivenMode: true,
1047
- agentId: 'agent-x',
1048
- toolCallStepIds: new Map([['ec1', 'step_ec1']]),
1049
- toolOutputReferences: { enabled: true },
1050
- });
1051
-
1052
- mockEventDispatch([
1053
- { toolCallId: 'ec1', content: 'host-output', status: 'success' },
1054
- ]);
1055
-
1056
- const aiMsg = new AIMessage({
1057
- content: '',
1058
- tool_calls: [{ id: 'ec1', name: 'echo', args: { command: 'run' } }],
1059
- });
1060
- const result = (await node.invoke(
1061
- { messages: [aiMsg] },
1062
- { configurable: { run_id: 'run-host' } }
1063
- )) as { messages: ToolMessage[] };
1064
-
1065
- expect(result.messages[0].content).toBe('host-output');
1066
- expect(getRefKey(result.messages[0])).toBe('tool0turn0');
1067
- expect(
1068
- node._unsafeGetToolOutputRegistry()!.get('run-host', 'tool0turn0')
1069
- ).toBe('host-output');
1070
- });
1071
-
1072
- it('substitutes `{{…}}` in the request sent to the host', async () => {
1073
- const node = new ToolNode({
1074
- tools: [createSchemaStub('echo')],
1075
- eventDrivenMode: true,
1076
- agentId: 'agent-x',
1077
- toolCallStepIds: new Map([
1078
- ['ec1', 'step_ec1'],
1079
- ['ec2', 'step_ec2'],
1080
- ]),
1081
- toolOutputReferences: { enabled: true },
1082
- });
1083
-
1084
- mockEventDispatch([
1085
- { toolCallId: 'ec1', content: 'FIRST', status: 'success' },
1086
- ]);
1087
- await node.invoke(
1088
- {
1089
- messages: [
1090
- new AIMessage({
1091
- content: '',
1092
- tool_calls: [{ id: 'ec1', name: 'echo', args: { command: 'a' } }],
1093
- }),
1094
- ],
1095
- },
1096
- { configurable: { run_id: 'run-subst' } }
1097
- );
1098
-
1099
- jest.restoreAllMocks();
1100
- const capturedRequests: t.ToolCallRequest[] = [];
1101
- jest
1102
- .spyOn(events, 'safeDispatchCustomEvent')
1103
- .mockImplementation(async (event, data) => {
1104
- if (event !== 'on_tool_execute') {
1105
- return;
1106
- }
1107
- const batch = data as t.ToolExecuteBatchRequest;
1108
- for (const req of batch.toolCalls) {
1109
- capturedRequests.push(req);
1110
- }
1111
- batch.resolve([
1112
- { toolCallId: 'ec2', content: 'SECOND', status: 'success' },
1113
- ]);
1114
- });
1115
-
1116
- await node.invoke(
1117
- {
1118
- messages: [
1119
- new AIMessage({
1120
- content: '',
1121
- tool_calls: [
1122
- {
1123
- id: 'ec2',
1124
- name: 'echo',
1125
- args: { command: 'see {{tool0turn0}}' },
1126
- },
1127
- ],
1128
- }),
1129
- ],
1130
- },
1131
- { configurable: { run_id: 'run-subst' } }
1132
- );
1133
-
1134
- expect(capturedRequests).toHaveLength(1);
1135
- expect(capturedRequests[0].args).toEqual({ command: 'see FIRST' });
1136
- });
1137
-
1138
- it('surfaces unresolved refs on host-returned error results', async () => {
1139
- const node = new ToolNode({
1140
- tools: [createSchemaStub('echo')],
1141
- eventDrivenMode: true,
1142
- agentId: 'agent-x',
1143
- toolCallStepIds: new Map([['ec1', 'step_ec1']]),
1144
- toolOutputReferences: { enabled: true },
1145
- });
1146
-
1147
- mockEventDispatch([
1148
- {
1149
- toolCallId: 'ec1',
1150
- content: '',
1151
- status: 'error',
1152
- errorMessage: 'host failure',
1153
- },
1154
- ]);
1155
- const result = (await node.invoke({
1156
- messages: [
1157
- new AIMessage({
1158
- content: '',
1159
- tool_calls: [
1160
- {
1161
- id: 'ec1',
1162
- name: 'echo',
1163
- args: { command: 'see {{tool9turn9}}' },
1164
- },
1165
- ],
1166
- }),
1167
- ],
1168
- })) as { messages: ToolMessage[] };
1169
-
1170
- expect(result.messages[0].content).toContain('Error: host failure');
1171
- expect(result.messages[0].content as string).not.toContain(
1172
- '[unresolved refs:'
1173
- );
1174
- expect(getUnresolvedRefs(result.messages[0])).toEqual(['tool9turn9']);
1175
- });
1176
-
1177
- it('reports unresolved refs even when the host succeeds', async () => {
1178
- const node = new ToolNode({
1179
- tools: [createSchemaStub('echo')],
1180
- eventDrivenMode: true,
1181
- agentId: 'agent-x',
1182
- toolCallStepIds: new Map([['ec1', 'step_ec1']]),
1183
- toolOutputReferences: { enabled: true },
1184
- });
1185
-
1186
- mockEventDispatch([
1187
- { toolCallId: 'ec1', content: 'done', status: 'success' },
1188
- ]);
1189
- const result = (await node.invoke({
1190
- messages: [
1191
- new AIMessage({
1192
- content: '',
1193
- tool_calls: [
1194
- {
1195
- id: 'ec1',
1196
- name: 'echo',
1197
- args: { command: 'see {{tool9turn9}}' },
1198
- },
1199
- ],
1200
- }),
1201
- ],
1202
- })) as { messages: ToolMessage[] };
1203
-
1204
- expect(result.messages[0].content).toBe('done');
1205
- expect(getUnresolvedRefs(result.messages[0])).toEqual(['tool9turn9']);
1206
- });
1207
-
1208
- it('registers the post-hook output when PostToolUse replaces it', async () => {
1209
- const hooks = new HookRegistry();
1210
- hooks.register('PostToolUse', {
1211
- hooks: [
1212
- async (): Promise<{ updatedOutput: string }> => ({
1213
- updatedOutput: 'hooked-output',
1214
- }),
1215
- ],
1216
- });
1217
- const node = new ToolNode({
1218
- tools: [createSchemaStub('echo')],
1219
- eventDrivenMode: true,
1220
- agentId: 'agent-x',
1221
- toolCallStepIds: new Map([['ec1', 'step_ec1']]),
1222
- toolOutputReferences: { enabled: true },
1223
- hookRegistry: hooks,
1224
- });
1225
-
1226
- mockEventDispatch([
1227
- { toolCallId: 'ec1', content: 'raw-output', status: 'success' },
1228
- ]);
1229
- const result = (await node.invoke(
1230
- {
1231
- messages: [
1232
- new AIMessage({
1233
- content: '',
1234
- tool_calls: [
1235
- { id: 'ec1', name: 'echo', args: { command: 'run' } },
1236
- ],
1237
- }),
1238
- ],
1239
- },
1240
- { configurable: { run_id: 'run-posthook' } }
1241
- )) as { messages: ToolMessage[] };
1242
-
1243
- expect(result.messages[0].content).toBe('hooked-output');
1244
- expect(getRefKey(result.messages[0])).toBe('tool0turn0');
1245
- expect(
1246
- node._unsafeGetToolOutputRegistry()!.get('run-posthook', 'tool0turn0')
1247
- ).toBe('hooked-output');
1248
- });
1249
-
1250
- it('aborts event dispatch when a direct tool throws with handleToolErrors=false', async () => {
1251
- const directBoom = tool(
1252
- async () => {
1253
- throw new Error('direct branch failed');
1254
- },
1255
- {
1256
- name: 'directBoom',
1257
- description: 'direct tool that throws',
1258
- schema: z.object({ command: z.string() }),
1259
- }
1260
- ) as unknown as StructuredToolInterface;
1261
- const eventStub = tool(async () => 'unused', {
1262
- name: 'eventTool',
1263
- description: 'schema-only stub',
1264
- schema: z.object({ command: z.string() }),
1265
- }) as unknown as StructuredToolInterface;
1266
-
1267
- let hostCalled = false;
1268
- jest
1269
- .spyOn(events, 'safeDispatchCustomEvent')
1270
- .mockImplementation(async (event, data) => {
1271
- if (event === 'on_tool_execute') {
1272
- hostCalled = true;
1273
- (data as t.ToolExecuteBatchRequest).resolve([]);
1274
- }
1275
- });
1276
-
1277
- const node = new ToolNode({
1278
- tools: [directBoom, eventStub],
1279
- eventDrivenMode: true,
1280
- handleToolErrors: false,
1281
- agentId: 'agent-failfast',
1282
- directToolNames: new Set(['directBoom']),
1283
- toolCallStepIds: new Map([
1284
- ['d1', 'step_d1'],
1285
- ['e1', 'step_e1'],
1286
- ]),
1287
- toolOutputReferences: { enabled: true },
1288
- });
1289
-
1290
- await expect(
1291
- node.invoke(
1292
- {
1293
- messages: [
1294
- new AIMessage({
1295
- content: '',
1296
- tool_calls: [
1297
- { id: 'd1', name: 'directBoom', args: { command: 'x' } },
1298
- { id: 'e1', name: 'eventTool', args: { command: 'y' } },
1299
- ],
1300
- }),
1301
- ],
1302
- },
1303
- { configurable: { run_id: 'failfast-run' } }
1304
- )
1305
- ).rejects.toThrow('direct branch failed');
1306
-
1307
- expect(hostCalled).toBe(false);
1308
- });
1309
-
1310
- it('isolates PreToolUse-injected refs from same-turn direct outputs in the mixed path', async () => {
1311
- // PreToolUse hook rewrites the event call's args to include
1312
- // `{{tool0turn0}}`. In the mixed direct+event path that
1313
- // placeholder must NOT resolve to the same-turn direct
1314
- // output that just registered — it should be reported as
1315
- // unresolved (matching cross-batch resolution semantics).
1316
- const directCapturedArgs: string[] = [];
1317
- const directTool = createEchoTool({
1318
- capturedArgs: directCapturedArgs,
1319
- outputs: ['direct-same-turn'],
1320
- name: 'directTool',
1321
- });
1322
- const eventStub = tool(async () => 'unused', {
1323
- name: 'eventTool',
1324
- description: 'schema-only stub',
1325
- schema: z.object({ command: z.string() }),
1326
- }) as unknown as StructuredToolInterface;
1327
-
1328
- const hooks = new HookRegistry();
1329
- hooks.register('PreToolUse', {
1330
- pattern: 'eventTool',
1331
- hooks: [
1332
- async (): Promise<{ updatedInput: { command: string } }> => ({
1333
- updatedInput: { command: 'see {{tool0turn0}}' },
1334
- }),
1335
- ],
1336
- });
1337
-
1338
- const hostCapturedArgs: Record<string, unknown>[] = [];
1339
- jest
1340
- .spyOn(events, 'safeDispatchCustomEvent')
1341
- .mockImplementation(async (event, data) => {
1342
- if (event !== 'on_tool_execute') {
1343
- return;
1344
- }
1345
- const batch = data as t.ToolExecuteBatchRequest;
1346
- for (const req of batch.toolCalls) {
1347
- hostCapturedArgs.push(req.args);
1348
- }
1349
- batch.resolve(
1350
- batch.toolCalls.map((req) => ({
1351
- toolCallId: req.id,
1352
- content: 'event-out',
1353
- status: 'success' as const,
1354
- }))
1355
- );
1356
- });
1357
-
1358
- const node = new ToolNode({
1359
- tools: [directTool, eventStub],
1360
- eventDrivenMode: true,
1361
- agentId: 'agent-snap',
1362
- directToolNames: new Set(['directTool']),
1363
- toolCallStepIds: new Map([
1364
- ['d1', 'step_d1'],
1365
- ['e1', 'step_e1'],
1366
- ]),
1367
- hookRegistry: hooks,
1368
- toolOutputReferences: { enabled: true },
1369
- });
1370
-
1371
- await node.invoke(
1372
- {
1373
- messages: [
1374
- new AIMessage({
1375
- content: '',
1376
- tool_calls: [
1377
- {
1378
- id: 'd1',
1379
- name: 'directTool',
1380
- args: { command: 'first' },
1381
- },
1382
- {
1383
- id: 'e1',
1384
- name: 'eventTool',
1385
- args: { command: 'orig' },
1386
- },
1387
- ],
1388
- }),
1389
- ],
1390
- },
1391
- { configurable: { run_id: 'snap-run' } }
1392
- );
1393
-
1394
- // Hook injected `{{tool0turn0}}`. The direct tool registered
1395
- // `tool0turn0` in the same batch, but the snapshot was taken
1396
- // pre-direct so the placeholder must remain unresolved.
1397
- expect(hostCapturedArgs).toHaveLength(1);
1398
- expect(hostCapturedArgs[0]).toEqual({
1399
- command: 'see {{tool0turn0}}',
1400
- });
1401
- });
1402
-
1403
- it('keeps same-turn refs isolated in the mixed direct+event path', async () => {
1404
- // Build a ToolNode with both a direct tool (via directToolNames)
1405
- // and an event-driven schema stub. Share one registry across
1406
- // both batches so refs only cross batch boundaries.
1407
- const sharedRegistry = new ToolOutputReferenceRegistry();
1408
-
1409
- const directCapturedArgs: string[] = [];
1410
- const directTool = createEchoTool({
1411
- capturedArgs: directCapturedArgs,
1412
- outputs: ['direct-A-output', 'direct-B-output'],
1413
- name: 'directTool',
1414
- });
1415
- const eventStub = tool(async () => 'unused', {
1416
- name: 'eventTool',
1417
- description: 'schema-only stub',
1418
- schema: z.object({ command: z.string() }),
1419
- }) as unknown as StructuredToolInterface;
1420
-
1421
- const hostCapturedArgs: Record<string, unknown>[] = [];
1422
- jest
1423
- .spyOn(events, 'safeDispatchCustomEvent')
1424
- .mockImplementation(async (event, data) => {
1425
- if (event !== 'on_tool_execute') {
1426
- return;
1427
- }
1428
- const batch = data as t.ToolExecuteBatchRequest;
1429
- for (const req of batch.toolCalls) {
1430
- hostCapturedArgs.push(req.args);
1431
- }
1432
- batch.resolve(
1433
- batch.toolCalls.map((req) => ({
1434
- toolCallId: req.id,
1435
- content: `event-${(req.args as { command: string }).command}`,
1436
- status: 'success' as const,
1437
- }))
1438
- );
1439
- });
1440
-
1441
- const node = new ToolNode({
1442
- tools: [directTool, eventStub],
1443
- eventDrivenMode: true,
1444
- agentId: 'agent-mixed',
1445
- directToolNames: new Set(['directTool']),
1446
- toolCallStepIds: new Map([
1447
- ['d1', 'step_d1'],
1448
- ['e1', 'step_e1'],
1449
- ['d2', 'step_d2'],
1450
- ['e2', 'step_e2'],
1451
- ]),
1452
- toolOutputRegistry: sharedRegistry,
1453
- });
1454
-
1455
- // Batch 1: mixed direct (index 0) + event (index 1). The event
1456
- // call attempts `{{tool0turn0}}` — which points at the direct
1457
- // call running *in the same batch*. Correct behavior: the
1458
- // placeholder stays unresolved (cross-batch only), and the
1459
- // event args received by the host carry the literal template
1460
- // string. The unresolved-refs hint is stamped into the resulting
1461
- // ToolMessage's `additional_kwargs._unresolvedRefs` so the lazy
1462
- // annotation transform surfaces it to the LLM at request time.
1463
- await node.invoke(
1464
- {
1465
- messages: [
1466
- new AIMessage({
1467
- content: '',
1468
- tool_calls: [
1469
- {
1470
- id: 'd1',
1471
- name: 'directTool',
1472
- args: { command: 'first' },
1473
- },
1474
- {
1475
- id: 'e1',
1476
- name: 'eventTool',
1477
- args: { command: 'echo {{tool0turn0}}' },
1478
- },
1479
- ],
1480
- }),
1481
- ],
1482
- },
1483
- { configurable: { run_id: 'mixed-run' } }
1484
- );
1485
-
1486
- expect(hostCapturedArgs).toHaveLength(1);
1487
- expect(hostCapturedArgs[0]).toEqual({
1488
- command: 'echo {{tool0turn0}}',
1489
- });
1490
-
1491
- // Batch 2: ref across the boundary now resolves — direct's
1492
- // registered output from batch 1 (tool0turn0) is available.
1493
- await node.invoke(
1494
- {
1495
- messages: [
1496
- new AIMessage({
1497
- content: '',
1498
- tool_calls: [
1499
- {
1500
- id: 'd2',
1501
- name: 'directTool',
1502
- args: { command: 'second' },
1503
- },
1504
- {
1505
- id: 'e2',
1506
- name: 'eventTool',
1507
- args: { command: 'echo {{tool0turn0}}' },
1508
- },
1509
- ],
1510
- }),
1511
- ],
1512
- },
1513
- { configurable: { run_id: 'mixed-run' } }
1514
- );
1515
-
1516
- expect(hostCapturedArgs[1]).toEqual({
1517
- command: 'echo direct-A-output',
1518
- });
1519
- });
1520
-
1521
- it('re-resolves placeholders when PreToolUse rewrites args', async () => {
1522
- const hooks = new HookRegistry();
1523
- hooks.register('PreToolUse', {
1524
- hooks: [
1525
- async (): Promise<{ updatedInput: { command: string } }> => ({
1526
- updatedInput: { command: 'rewritten {{tool0turn0}}' },
1527
- }),
1528
- ],
1529
- });
1530
- const node = new ToolNode({
1531
- tools: [createSchemaStub('echo')],
1532
- eventDrivenMode: true,
1533
- agentId: 'agent-x',
1534
- toolCallStepIds: new Map([
1535
- ['ec1', 'step_ec1'],
1536
- ['ec2', 'step_ec2'],
1537
- ]),
1538
- toolOutputReferences: { enabled: true },
1539
- hookRegistry: hooks,
1540
- });
1541
-
1542
- mockEventDispatch([
1543
- { toolCallId: 'ec1', content: 'STORED', status: 'success' },
1544
- ]);
1545
- await node.invoke(
1546
- {
1547
- messages: [
1548
- new AIMessage({
1549
- content: '',
1550
- tool_calls: [
1551
- { id: 'ec1', name: 'echo', args: { command: 'first' } },
1552
- ],
1553
- }),
1554
- ],
1555
- },
1556
- { configurable: { run_id: 'run-hookresolve' } }
1557
- );
1558
-
1559
- jest.restoreAllMocks();
1560
- const capturedRequests: t.ToolCallRequest[] = [];
1561
- jest
1562
- .spyOn(events, 'safeDispatchCustomEvent')
1563
- .mockImplementation(async (event, data) => {
1564
- if (event !== 'on_tool_execute') {
1565
- return;
1566
- }
1567
- const batch = data as t.ToolExecuteBatchRequest;
1568
- for (const req of batch.toolCalls) {
1569
- capturedRequests.push(req);
1570
- }
1571
- batch.resolve([
1572
- { toolCallId: 'ec2', content: 'done', status: 'success' },
1573
- ]);
1574
- });
1575
-
1576
- await node.invoke(
1577
- {
1578
- messages: [
1579
- new AIMessage({
1580
- content: '',
1581
- tool_calls: [
1582
- {
1583
- id: 'ec2',
1584
- name: 'echo',
1585
- args: { command: 'input-without-placeholder' },
1586
- },
1587
- ],
1588
- }),
1589
- ],
1590
- },
1591
- { configurable: { run_id: 'run-hookresolve' } }
1592
- );
1593
-
1594
- expect(capturedRequests).toHaveLength(1);
1595
- expect(capturedRequests[0].args).toEqual({
1596
- command: 'rewritten STORED',
1597
- });
1598
- });
1599
- });
1600
-
1601
- describe('PostToolUse updatedOutput updates the registry (Codex P2 #17)', () => {
1602
- it('subsequent {{tool0turn0}} substitutions deliver the post-hook content, not the pre-hook content', async () => {
1603
- const capturedArgs: string[] = [];
1604
- const echoT = createEchoTool({
1605
- capturedArgs,
1606
- outputs: ['original-output', 'second-call-result'],
1607
- });
1608
-
1609
- const registry = new HookRegistry();
1610
- registry.register('PostToolUse', {
1611
- hooks: [
1612
- // Replace the tool's content. Pre-fix the registry kept the
1613
- // pre-hook string ("original-output"), so a later
1614
- // {{tool0turn0}} substitution would deliver stale bytes.
1615
- async (): Promise<PostToolUseHookOutput> => ({
1616
- updatedOutput: 'redacted-by-hook',
1617
- }),
1618
- ],
1619
- });
1620
-
1621
- const node = new ToolNode({
1622
- tools: [echoT],
1623
- toolOutputReferences: { enabled: true },
1624
- hookRegistry: registry,
1625
- });
1626
-
1627
- const [first] = await invokeBatch(
1628
- node,
1629
- [{ id: 'c1', name: 'echo', command: 'first' }],
1630
- 'run-posthook-ref'
1631
- );
1632
- // Sanity: the model sees the replaced content.
1633
- expect(first.content).toBe('redacted-by-hook');
1634
-
1635
- // Second call references the first via {{tool0turn0}}. The
1636
- // tool's `command` arg should resolve to the post-hook content.
1637
- await invokeBatch(
1638
- node,
1639
- [{ id: 'c2', name: 'echo', command: 'value={{tool0turn0}}' }],
1640
- 'run-posthook-ref'
1641
- );
1642
- expect(capturedArgs).toEqual(['first', 'value=redacted-by-hook']);
1643
- // Pre-fix: the second call would have seen 'value=original-output'
1644
- // because the registry was never updated after the post-hook.
1645
- expect(capturedArgs[1]).not.toContain('original-output');
1646
- });
1647
- });
1648
-
1649
- describe('direct-batch snapshot isolation (Codex P1 #18)', () => {
1650
- it('does not let a slow PreToolUse hook on one call leak a sibling output into another call args', async () => {
1651
- // Two direct calls in a single batch:
1652
- // c0: has a slow PreToolUse hook (await) + args containing
1653
- // `{{tool1turn0}}` (a same-turn placeholder).
1654
- // c1: no hook, returns 'sibling-output' instantly.
1655
- //
1656
- // Same-turn refs are intentionally isolated (the snapshot is
1657
- // taken pre-batch). Pre-fix, runTool's late re-resolve against
1658
- // the *live* registry meant c0 (waiting on its hook) saw c1's
1659
- // already-registered output and substituted it into its args
1660
- // — order-dependent leakage. With the snapshot, c0 sees the
1661
- // placeholder unresolved.
1662
- const capturedArgs: string[] = [];
1663
- const echoT = createEchoTool({
1664
- capturedArgs,
1665
- outputs: ['c0-output', 'sibling-output'],
1666
- name: 'echo',
1667
- });
1668
-
1669
- const registry = new HookRegistry();
1670
- registry.register('PreToolUse', {
1671
- hooks: [
1672
- // Slow hook gates ONLY c0; c1 has no hook to wait on. The
1673
- // delay gives c1 time to finish and register its output
1674
- // before c0's `runTool` runs.
1675
- async (input): Promise<PreToolUseHookOutput> => {
1676
- const cmd = (input.toolInput as { command?: string }).command ?? '';
1677
- if (cmd.includes('{{tool1turn0}}')) {
1678
- await new Promise<void>((resolve) => setTimeout(resolve, 50));
1679
- }
1680
- return { decision: 'allow' };
1681
- },
1682
- ],
1683
- });
1684
-
1685
- const node = new ToolNode({
1686
- tools: [echoT],
1687
- toolOutputReferences: { enabled: true },
1688
- hookRegistry: registry,
1689
- });
1690
-
1691
- await invokeBatch(
1692
- node,
1693
- [
1694
- { id: 'c0', name: 'echo', command: 'leak={{tool1turn0}}' },
1695
- { id: 'c1', name: 'echo', command: 'instant' },
1696
- ],
1697
- 'run-snapshot-iso'
1698
- );
1699
-
1700
- // Pre-fix: capturedArgs[0] would have been 'leak=sibling-output'
1701
- // because c1 won the race and c0's late re-resolve picked it up.
1702
- // With the snapshot fix: same-turn isolation holds — the
1703
- // placeholder stays unresolved in c0's args (and an
1704
- // `[unresolved refs: …]` marker shows up downstream).
1705
- const c0Index = capturedArgs.findIndex((a) => a.startsWith('leak='));
1706
- expect(c0Index).toBeGreaterThanOrEqual(0);
1707
- expect(capturedArgs[c0Index]).not.toContain('sibling-output');
1708
- });
1709
- });
1710
- });