@illuma-ai/agents 1.0.90 → 1.0.94

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 (839) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +98 -49
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/common/constants.cjs +25 -0
  4. package/dist/cjs/common/constants.cjs.map +1 -0
  5. package/dist/cjs/common/enum.cjs +30 -0
  6. package/dist/cjs/common/enum.cjs.map +1 -1
  7. package/dist/cjs/events.cjs +9 -4
  8. package/dist/cjs/events.cjs.map +1 -1
  9. package/dist/cjs/graphs/Graph.cjs +397 -92
  10. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  11. package/dist/cjs/graphs/MultiAgentGraph.cjs +223 -92
  12. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  13. package/dist/cjs/instrumentation.cjs +30 -14
  14. package/dist/cjs/instrumentation.cjs.map +1 -1
  15. package/dist/cjs/llm/anthropic/index.cjs +43 -11
  16. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  17. package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
  18. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +10 -7
  19. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  20. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +32 -0
  21. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  22. package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
  23. package/dist/cjs/llm/bedrock/index.cjs +129 -101
  24. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  25. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +489 -0
  26. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -0
  27. package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +176 -0
  28. package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -0
  29. package/dist/cjs/llm/fake.cjs.map +1 -1
  30. package/dist/cjs/llm/google/index.cjs.map +1 -1
  31. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  32. package/dist/cjs/llm/openai/index.cjs +1 -1
  33. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  34. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  35. package/dist/cjs/llm/openrouter/index.cjs +59 -5
  36. package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
  37. package/dist/cjs/llm/providers.cjs.map +1 -1
  38. package/dist/cjs/llm/text.cjs.map +1 -1
  39. package/dist/cjs/llm/vertexai/index.cjs +80 -2
  40. package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
  41. package/dist/cjs/main.cjs +60 -27
  42. package/dist/cjs/main.cjs.map +1 -1
  43. package/dist/cjs/messages/cache.cjs +131 -108
  44. package/dist/cjs/messages/cache.cjs.map +1 -1
  45. package/dist/cjs/messages/content.cjs.map +1 -1
  46. package/dist/cjs/messages/core.cjs +3 -0
  47. package/dist/cjs/messages/core.cjs.map +1 -1
  48. package/dist/cjs/messages/format.cjs +265 -47
  49. package/dist/cjs/messages/format.cjs.map +1 -1
  50. package/dist/cjs/messages/ids.cjs.map +1 -1
  51. package/dist/cjs/messages/prune.cjs +55 -2
  52. package/dist/cjs/messages/prune.cjs.map +1 -1
  53. package/dist/cjs/messages/summarize.cjs +170 -0
  54. package/dist/cjs/messages/summarize.cjs.map +1 -0
  55. package/dist/cjs/messages/tools.cjs.map +1 -1
  56. package/dist/cjs/run.cjs +87 -30
  57. package/dist/cjs/run.cjs.map +1 -1
  58. package/dist/cjs/schemas/validate.cjs.map +1 -1
  59. package/dist/cjs/splitStream.cjs.map +1 -1
  60. package/dist/cjs/stream.cjs +59 -25
  61. package/dist/cjs/stream.cjs.map +1 -1
  62. package/dist/cjs/tools/AskUser.cjs +131 -0
  63. package/dist/cjs/tools/AskUser.cjs.map +1 -0
  64. package/dist/cjs/tools/BrowserTools.cjs +11 -7
  65. package/dist/cjs/tools/BrowserTools.cjs.map +1 -1
  66. package/dist/cjs/tools/Calculator.cjs.map +1 -1
  67. package/dist/cjs/tools/CodeExecutor.cjs +60 -5
  68. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  69. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +36 -53
  70. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  71. package/dist/cjs/tools/StreamingToolCallBuffer.cjs +208 -0
  72. package/dist/cjs/tools/StreamingToolCallBuffer.cjs.map +1 -0
  73. package/dist/cjs/tools/ToolNode.cjs +333 -30
  74. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  75. package/dist/cjs/tools/ToolSearch.cjs +66 -30
  76. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  77. package/dist/cjs/tools/handlers.cjs +94 -8
  78. package/dist/cjs/tools/handlers.cjs.map +1 -1
  79. package/dist/cjs/tools/schema.cjs.map +1 -1
  80. package/dist/cjs/tools/search/content.cjs.map +1 -1
  81. package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
  82. package/dist/cjs/tools/search/format.cjs.map +1 -1
  83. package/dist/cjs/tools/search/highlights.cjs.map +1 -1
  84. package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
  85. package/dist/cjs/tools/search/schema.cjs.map +1 -1
  86. package/dist/cjs/tools/search/search.cjs +1 -0
  87. package/dist/cjs/tools/search/search.cjs.map +1 -1
  88. package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
  89. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  90. package/dist/cjs/tools/search/utils.cjs.map +1 -1
  91. package/dist/cjs/types/graph.cjs +1 -1
  92. package/dist/cjs/types/graph.cjs.map +1 -1
  93. package/dist/cjs/utils/contextAnalytics.cjs +23 -6
  94. package/dist/cjs/utils/contextAnalytics.cjs.map +1 -1
  95. package/dist/cjs/utils/events.cjs.map +1 -1
  96. package/dist/cjs/utils/graph.cjs.map +1 -1
  97. package/dist/cjs/utils/handlers.cjs.map +1 -1
  98. package/dist/cjs/utils/llm.cjs.map +1 -1
  99. package/dist/cjs/utils/misc.cjs.map +1 -1
  100. package/dist/cjs/utils/run.cjs +3 -1
  101. package/dist/cjs/utils/run.cjs.map +1 -1
  102. package/dist/cjs/utils/schema.cjs.map +1 -1
  103. package/dist/cjs/utils/title.cjs.map +1 -1
  104. package/dist/cjs/utils/tokens.cjs +33 -58
  105. package/dist/cjs/utils/tokens.cjs.map +1 -1
  106. package/dist/cjs/utils/toolCallContinuation.cjs +55 -0
  107. package/dist/cjs/utils/toolCallContinuation.cjs.map +1 -0
  108. package/dist/cjs/utils/toonFormat.cjs.map +1 -1
  109. package/dist/esm/agents/AgentContext.mjs +98 -49
  110. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  111. package/dist/esm/common/constants.mjs +22 -0
  112. package/dist/esm/common/constants.mjs.map +1 -0
  113. package/dist/esm/common/enum.mjs +31 -1
  114. package/dist/esm/common/enum.mjs.map +1 -1
  115. package/dist/esm/events.mjs +9 -4
  116. package/dist/esm/events.mjs.map +1 -1
  117. package/dist/esm/graphs/Graph.mjs +393 -88
  118. package/dist/esm/graphs/Graph.mjs.map +1 -1
  119. package/dist/esm/graphs/MultiAgentGraph.mjs +224 -93
  120. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  121. package/dist/esm/instrumentation.mjs +30 -14
  122. package/dist/esm/instrumentation.mjs.map +1 -1
  123. package/dist/esm/llm/anthropic/index.mjs +43 -11
  124. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  125. package/dist/esm/llm/anthropic/types.mjs.map +1 -1
  126. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +10 -7
  127. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  128. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +32 -0
  129. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  130. package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
  131. package/dist/esm/llm/bedrock/index.mjs +128 -101
  132. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  133. package/dist/esm/llm/bedrock/utils/message_inputs.mjs +484 -0
  134. package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -0
  135. package/dist/esm/llm/bedrock/utils/message_outputs.mjs +171 -0
  136. package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -0
  137. package/dist/esm/llm/fake.mjs.map +1 -1
  138. package/dist/esm/llm/google/index.mjs.map +1 -1
  139. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  140. package/dist/esm/llm/openai/index.mjs +1 -1
  141. package/dist/esm/llm/openai/index.mjs.map +1 -1
  142. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  143. package/dist/esm/llm/openrouter/index.mjs +59 -5
  144. package/dist/esm/llm/openrouter/index.mjs.map +1 -1
  145. package/dist/esm/llm/providers.mjs.map +1 -1
  146. package/dist/esm/llm/text.mjs.map +1 -1
  147. package/dist/esm/llm/vertexai/index.mjs +80 -2
  148. package/dist/esm/llm/vertexai/index.mjs.map +1 -1
  149. package/dist/esm/main.mjs +8 -3
  150. package/dist/esm/main.mjs.map +1 -1
  151. package/dist/esm/messages/cache.mjs +131 -108
  152. package/dist/esm/messages/cache.mjs.map +1 -1
  153. package/dist/esm/messages/content.mjs.map +1 -1
  154. package/dist/esm/messages/core.mjs +4 -1
  155. package/dist/esm/messages/core.mjs.map +1 -1
  156. package/dist/esm/messages/format.mjs +267 -49
  157. package/dist/esm/messages/format.mjs.map +1 -1
  158. package/dist/esm/messages/ids.mjs.map +1 -1
  159. package/dist/esm/messages/prune.mjs +56 -4
  160. package/dist/esm/messages/prune.mjs.map +1 -1
  161. package/dist/esm/messages/summarize.mjs +161 -0
  162. package/dist/esm/messages/summarize.mjs.map +1 -0
  163. package/dist/esm/messages/tools.mjs.map +1 -1
  164. package/dist/esm/run.mjs +88 -31
  165. package/dist/esm/run.mjs.map +1 -1
  166. package/dist/esm/schemas/validate.mjs.map +1 -1
  167. package/dist/esm/splitStream.mjs.map +1 -1
  168. package/dist/esm/stream.mjs +60 -26
  169. package/dist/esm/stream.mjs.map +1 -1
  170. package/dist/esm/tools/AskUser.mjs +125 -0
  171. package/dist/esm/tools/AskUser.mjs.map +1 -0
  172. package/dist/esm/tools/BrowserTools.mjs +11 -7
  173. package/dist/esm/tools/BrowserTools.mjs.map +1 -1
  174. package/dist/esm/tools/Calculator.mjs.map +1 -1
  175. package/dist/esm/tools/CodeExecutor.mjs +60 -5
  176. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  177. package/dist/esm/tools/ProgrammaticToolCalling.mjs +37 -54
  178. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  179. package/dist/esm/tools/StreamingToolCallBuffer.mjs +206 -0
  180. package/dist/esm/tools/StreamingToolCallBuffer.mjs.map +1 -0
  181. package/dist/esm/tools/ToolNode.mjs +333 -30
  182. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  183. package/dist/esm/tools/ToolSearch.mjs +66 -30
  184. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  185. package/dist/esm/tools/handlers.mjs +95 -9
  186. package/dist/esm/tools/handlers.mjs.map +1 -1
  187. package/dist/esm/tools/schema.mjs.map +1 -1
  188. package/dist/esm/tools/search/content.mjs.map +1 -1
  189. package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
  190. package/dist/esm/tools/search/format.mjs.map +1 -1
  191. package/dist/esm/tools/search/highlights.mjs.map +1 -1
  192. package/dist/esm/tools/search/rerankers.mjs.map +1 -1
  193. package/dist/esm/tools/search/schema.mjs.map +1 -1
  194. package/dist/esm/tools/search/search.mjs +1 -0
  195. package/dist/esm/tools/search/search.mjs.map +1 -1
  196. package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
  197. package/dist/esm/tools/search/tool.mjs.map +1 -1
  198. package/dist/esm/tools/search/utils.mjs.map +1 -1
  199. package/dist/esm/types/graph.mjs +1 -1
  200. package/dist/esm/types/graph.mjs.map +1 -1
  201. package/dist/esm/utils/contextAnalytics.mjs +23 -6
  202. package/dist/esm/utils/contextAnalytics.mjs.map +1 -1
  203. package/dist/esm/utils/events.mjs.map +1 -1
  204. package/dist/esm/utils/graph.mjs.map +1 -1
  205. package/dist/esm/utils/handlers.mjs.map +1 -1
  206. package/dist/esm/utils/llm.mjs.map +1 -1
  207. package/dist/esm/utils/misc.mjs.map +1 -1
  208. package/dist/esm/utils/run.mjs +3 -1
  209. package/dist/esm/utils/run.mjs.map +1 -1
  210. package/dist/esm/utils/schema.mjs.map +1 -1
  211. package/dist/esm/utils/title.mjs.map +1 -1
  212. package/dist/esm/utils/tokens.mjs +33 -59
  213. package/dist/esm/utils/tokens.mjs.map +1 -1
  214. package/dist/esm/utils/toolCallContinuation.mjs +52 -0
  215. package/dist/esm/utils/toolCallContinuation.mjs.map +1 -0
  216. package/dist/esm/utils/toonFormat.mjs.map +1 -1
  217. package/dist/types/agents/AgentContext.d.ts +14 -7
  218. package/dist/types/common/constants.d.ts +18 -0
  219. package/dist/types/common/enum.d.ts +28 -0
  220. package/dist/types/common/index.d.ts +1 -0
  221. package/dist/types/events.d.ts +10 -3
  222. package/dist/types/graphs/Graph.d.ts +37 -0
  223. package/dist/types/index.d.ts +4 -0
  224. package/dist/types/llm/anthropic/index.d.ts +7 -1
  225. package/dist/types/llm/anthropic/types.d.ts +5 -2
  226. package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
  227. package/dist/types/llm/bedrock/index.d.ts +40 -33
  228. package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
  229. package/dist/types/llm/google/index.d.ts +2 -3
  230. package/dist/types/llm/openrouter/index.d.ts +21 -1
  231. package/dist/types/llm/vertexai/index.d.ts +3 -2
  232. package/dist/types/messages/cache.d.ts +1 -1
  233. package/dist/types/messages/index.d.ts +1 -0
  234. package/dist/types/messages/prune.d.ts +2 -7
  235. package/dist/types/messages/summarize.d.ts +33 -0
  236. package/dist/types/run.d.ts +6 -0
  237. package/dist/types/tools/AskUser.d.ts +408 -0
  238. package/dist/types/tools/BrowserTools.d.ts +2 -2
  239. package/dist/types/tools/CodeExecutor.d.ts +28 -4
  240. package/dist/types/tools/StreamingToolCallBuffer.d.ts +106 -0
  241. package/dist/types/tools/ToolNode.d.ts +55 -3
  242. package/dist/types/tools/ToolSearch.d.ts +9 -5
  243. package/dist/types/tools/handlers.d.ts +2 -2
  244. package/dist/types/types/graph.d.ts +9 -2
  245. package/dist/types/types/llm.d.ts +8 -3
  246. package/dist/types/types/run.d.ts +2 -0
  247. package/dist/types/types/tools.d.ts +20 -2
  248. package/dist/types/utils/contextAnalytics.d.ts +5 -4
  249. package/dist/types/utils/index.d.ts +1 -0
  250. package/dist/types/utils/tokens.d.ts +6 -19
  251. package/dist/types/utils/toolCallContinuation.d.ts +30 -0
  252. package/package.json +15 -8
  253. package/src/agents/AgentContext.js +782 -0
  254. package/src/agents/AgentContext.js.map +1 -0
  255. package/src/agents/AgentContext.test.js +421 -0
  256. package/src/agents/AgentContext.test.js.map +1 -0
  257. package/src/agents/AgentContext.ts +132 -64
  258. package/src/agents/__tests__/AgentContext.test.js +678 -0
  259. package/src/agents/__tests__/AgentContext.test.js.map +1 -0
  260. package/src/agents/__tests__/AgentContext.test.ts +25 -4
  261. package/src/agents/__tests__/resolveStructuredOutputMode.test.js +117 -0
  262. package/src/agents/__tests__/resolveStructuredOutputMode.test.js.map +1 -0
  263. package/src/common/__tests__/enum.test.ts +135 -0
  264. package/src/common/constants.ts +21 -0
  265. package/src/common/enum.js +192 -0
  266. package/src/common/enum.js.map +1 -0
  267. package/src/common/enum.ts +30 -0
  268. package/src/common/index.js +3 -0
  269. package/src/common/index.js.map +1 -0
  270. package/src/common/index.ts +2 -1
  271. package/src/events.js +166 -0
  272. package/src/events.js.map +1 -0
  273. package/src/events.ts +11 -14
  274. package/src/graphs/Graph.js +1857 -0
  275. package/src/graphs/Graph.js.map +1 -0
  276. package/src/graphs/Graph.ts +580 -162
  277. package/src/graphs/MultiAgentGraph.js +1092 -0
  278. package/src/graphs/MultiAgentGraph.js.map +1 -0
  279. package/src/graphs/MultiAgentGraph.ts +331 -112
  280. package/src/graphs/__tests__/adaptive-thinking.test.ts +369 -0
  281. package/src/graphs/__tests__/graph-direct-tool-names.test.ts +210 -0
  282. package/src/graphs/__tests__/multi-agent-edges.test.ts +237 -0
  283. package/src/graphs/__tests__/structured-output.integration.test.js +624 -0
  284. package/src/graphs/__tests__/structured-output.integration.test.js.map +1 -0
  285. package/src/graphs/__tests__/structured-output.test.js +144 -0
  286. package/src/graphs/__tests__/structured-output.test.js.map +1 -0
  287. package/src/graphs/contextManagement.e2e.test.js +718 -0
  288. package/src/graphs/contextManagement.e2e.test.js.map +1 -0
  289. package/src/graphs/contextManagement.e2e.test.ts +990 -0
  290. package/src/graphs/contextManagement.test.js +485 -0
  291. package/src/graphs/contextManagement.test.js.map +1 -0
  292. package/src/graphs/contextManagement.test.ts +625 -0
  293. package/src/graphs/handoffValidation.test.js +276 -0
  294. package/src/graphs/handoffValidation.test.js.map +1 -0
  295. package/src/graphs/handoffValidation.test.ts +353 -0
  296. package/src/graphs/index.js +3 -0
  297. package/src/graphs/index.js.map +1 -0
  298. package/src/index.js +28 -0
  299. package/src/index.js.map +1 -0
  300. package/src/index.ts +13 -0
  301. package/src/instrumentation.js +21 -0
  302. package/src/instrumentation.js.map +1 -0
  303. package/src/instrumentation.ts +38 -17
  304. package/src/llm/anthropic/index.js +319 -0
  305. package/src/llm/anthropic/index.js.map +1 -0
  306. package/src/llm/anthropic/index.ts +68 -15
  307. package/src/llm/anthropic/llm.spec.ts +402 -0
  308. package/src/llm/anthropic/types.js +46 -0
  309. package/src/llm/anthropic/types.js.map +1 -0
  310. package/src/llm/anthropic/types.ts +8 -2
  311. package/src/llm/anthropic/utils/message_inputs.js +627 -0
  312. package/src/llm/anthropic/utils/message_inputs.js.map +1 -0
  313. package/src/llm/anthropic/utils/message_inputs.ts +16 -33
  314. package/src/llm/anthropic/utils/message_outputs.js +290 -0
  315. package/src/llm/anthropic/utils/message_outputs.js.map +1 -0
  316. package/src/llm/anthropic/utils/message_outputs.ts +40 -1
  317. package/src/llm/anthropic/utils/output_parsers.js +89 -0
  318. package/src/llm/anthropic/utils/output_parsers.js.map +1 -0
  319. package/src/llm/anthropic/utils/tools.js +25 -0
  320. package/src/llm/anthropic/utils/tools.js.map +1 -0
  321. package/src/llm/bedrock/__tests__/bedrock-caching.test.js +392 -0
  322. package/src/llm/bedrock/__tests__/bedrock-caching.test.js.map +1 -0
  323. package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +24 -40
  324. package/src/llm/bedrock/index.js +303 -0
  325. package/src/llm/bedrock/index.js.map +1 -0
  326. package/src/llm/bedrock/index.ts +171 -134
  327. package/src/llm/bedrock/llm.spec.ts +395 -52
  328. package/src/llm/bedrock/types.js +2 -0
  329. package/src/llm/bedrock/types.js.map +1 -0
  330. package/src/llm/bedrock/utils/index.js +6 -0
  331. package/src/llm/bedrock/utils/index.js.map +1 -0
  332. package/src/llm/bedrock/utils/message_inputs.js +463 -0
  333. package/src/llm/bedrock/utils/message_inputs.js.map +1 -0
  334. package/src/llm/bedrock/utils/message_inputs.ts +30 -5
  335. package/src/llm/bedrock/utils/message_outputs.js +269 -0
  336. package/src/llm/bedrock/utils/message_outputs.js.map +1 -0
  337. package/src/llm/bedrock/utils/message_outputs.ts +70 -22
  338. package/src/llm/fake.js +92 -0
  339. package/src/llm/fake.js.map +1 -0
  340. package/src/llm/google/index.js +215 -0
  341. package/src/llm/google/index.js.map +1 -0
  342. package/src/llm/google/index.ts +2 -3
  343. package/src/llm/google/types.js +12 -0
  344. package/src/llm/google/types.js.map +1 -0
  345. package/src/llm/google/utils/common.js +670 -0
  346. package/src/llm/google/utils/common.js.map +1 -0
  347. package/src/llm/google/utils/tools.js +111 -0
  348. package/src/llm/google/utils/tools.js.map +1 -0
  349. package/src/llm/google/utils/zod_to_genai_parameters.js +47 -0
  350. package/src/llm/google/utils/zod_to_genai_parameters.js.map +1 -0
  351. package/src/llm/openai/index.js +1033 -0
  352. package/src/llm/openai/index.js.map +1 -0
  353. package/src/llm/openai/types.js +2 -0
  354. package/src/llm/openai/types.js.map +1 -0
  355. package/src/llm/openai/utils/index.js +756 -0
  356. package/src/llm/openai/utils/index.js.map +1 -0
  357. package/src/llm/openai/utils/isReasoningModel.test.js +79 -0
  358. package/src/llm/openai/utils/isReasoningModel.test.js.map +1 -0
  359. package/src/llm/openrouter/index.js +261 -0
  360. package/src/llm/openrouter/index.js.map +1 -0
  361. package/src/llm/openrouter/index.ts +117 -6
  362. package/src/llm/openrouter/reasoning.test.js +181 -0
  363. package/src/llm/openrouter/reasoning.test.js.map +1 -0
  364. package/src/llm/openrouter/reasoning.test.ts +207 -0
  365. package/src/llm/providers.js +36 -0
  366. package/src/llm/providers.js.map +1 -0
  367. package/src/llm/text.js +65 -0
  368. package/src/llm/text.js.map +1 -0
  369. package/src/llm/vertexai/index.js +402 -0
  370. package/src/llm/vertexai/index.js.map +1 -0
  371. package/src/llm/vertexai/index.ts +115 -5
  372. package/src/llm/vertexai/llm.spec.ts +114 -0
  373. package/src/messages/__tests__/tools.test.js +392 -0
  374. package/src/messages/__tests__/tools.test.js.map +1 -0
  375. package/src/messages/cache.js +404 -0
  376. package/src/messages/cache.js.map +1 -0
  377. package/src/messages/cache.test.js +1167 -0
  378. package/src/messages/cache.test.js.map +1 -0
  379. package/src/messages/cache.test.ts +178 -16
  380. package/src/messages/cache.ts +152 -147
  381. package/src/messages/content.js +48 -0
  382. package/src/messages/content.js.map +1 -0
  383. package/src/messages/content.test.js +314 -0
  384. package/src/messages/content.test.js.map +1 -0
  385. package/src/messages/core.js +359 -0
  386. package/src/messages/core.js.map +1 -0
  387. package/src/messages/core.ts +5 -0
  388. package/src/messages/ensureThinkingBlock.test.js +997 -0
  389. package/src/messages/ensureThinkingBlock.test.js.map +1 -0
  390. package/src/messages/ensureThinkingBlock.test.ts +751 -10
  391. package/src/messages/format.js +973 -0
  392. package/src/messages/format.js.map +1 -0
  393. package/src/messages/format.ts +334 -57
  394. package/src/messages/formatAgentMessages.test.js +2278 -0
  395. package/src/messages/formatAgentMessages.test.js.map +1 -0
  396. package/src/messages/formatAgentMessages.test.ts +1175 -1
  397. package/src/messages/formatAgentMessages.tools.test.js +362 -0
  398. package/src/messages/formatAgentMessages.tools.test.js.map +1 -0
  399. package/src/messages/formatMessage.test.js +608 -0
  400. package/src/messages/formatMessage.test.js.map +1 -0
  401. package/src/messages/ids.js +18 -0
  402. package/src/messages/ids.js.map +1 -0
  403. package/src/messages/index.js +9 -0
  404. package/src/messages/index.js.map +1 -0
  405. package/src/messages/index.ts +1 -0
  406. package/src/messages/labelContentByAgent.test.js +725 -0
  407. package/src/messages/labelContentByAgent.test.js.map +1 -0
  408. package/src/messages/prune.js +438 -0
  409. package/src/messages/prune.js.map +1 -0
  410. package/src/messages/prune.ts +87 -25
  411. package/src/messages/reducer.js +60 -0
  412. package/src/messages/reducer.js.map +1 -0
  413. package/src/messages/shiftIndexTokenCountMap.test.js +63 -0
  414. package/src/messages/shiftIndexTokenCountMap.test.js.map +1 -0
  415. package/src/messages/summarize.js +146 -0
  416. package/src/messages/summarize.js.map +1 -0
  417. package/src/messages/summarize.test.js +332 -0
  418. package/src/messages/summarize.test.js.map +1 -0
  419. package/src/messages/summarize.test.ts +466 -0
  420. package/src/messages/summarize.ts +222 -0
  421. package/src/messages/tools.js +90 -0
  422. package/src/messages/tools.js.map +1 -0
  423. package/src/mockStream.js +81 -0
  424. package/src/mockStream.js.map +1 -0
  425. package/src/prompts/collab.js +7 -0
  426. package/src/prompts/collab.js.map +1 -0
  427. package/src/prompts/index.js +3 -0
  428. package/src/prompts/index.js.map +1 -0
  429. package/src/prompts/taskmanager.js +58 -0
  430. package/src/prompts/taskmanager.js.map +1 -0
  431. package/src/run.js +427 -0
  432. package/src/run.js.map +1 -0
  433. package/src/run.ts +101 -33
  434. package/src/schemas/index.js +3 -0
  435. package/src/schemas/index.js.map +1 -0
  436. package/src/schemas/schema-preparation.test.js +370 -0
  437. package/src/schemas/schema-preparation.test.js.map +1 -0
  438. package/src/schemas/validate.js +314 -0
  439. package/src/schemas/validate.js.map +1 -0
  440. package/src/schemas/validate.test.js +264 -0
  441. package/src/schemas/validate.test.js.map +1 -0
  442. package/src/scripts/abort.js +127 -0
  443. package/src/scripts/abort.js.map +1 -0
  444. package/src/scripts/ant_web_search.js +130 -0
  445. package/src/scripts/ant_web_search.js.map +1 -0
  446. package/src/scripts/ant_web_search.ts +1 -0
  447. package/src/scripts/ant_web_search_edge_case.js +133 -0
  448. package/src/scripts/ant_web_search_edge_case.js.map +1 -0
  449. package/src/scripts/ant_web_search_edge_case.ts +1 -0
  450. package/src/scripts/ant_web_search_error_edge_case.js +119 -0
  451. package/src/scripts/ant_web_search_error_edge_case.js.map +1 -0
  452. package/src/scripts/ant_web_search_error_edge_case.ts +1 -0
  453. package/src/scripts/args.js +41 -0
  454. package/src/scripts/args.js.map +1 -0
  455. package/src/scripts/bedrock-cache-debug.js +186 -0
  456. package/src/scripts/bedrock-cache-debug.js.map +1 -0
  457. package/src/scripts/bedrock-cache-debug.ts +250 -0
  458. package/src/scripts/bedrock-content-aggregation-test.js +195 -0
  459. package/src/scripts/bedrock-content-aggregation-test.js.map +1 -0
  460. package/src/scripts/bedrock-content-aggregation-test.ts +266 -0
  461. package/src/scripts/bedrock-merge-test.js +80 -0
  462. package/src/scripts/bedrock-merge-test.js.map +1 -0
  463. package/src/scripts/bedrock-merge-test.ts +107 -0
  464. package/src/scripts/bedrock-parallel-tools-test.js +150 -0
  465. package/src/scripts/bedrock-parallel-tools-test.js.map +1 -0
  466. package/src/scripts/bedrock-parallel-tools-test.ts +204 -0
  467. package/src/scripts/caching.js +106 -0
  468. package/src/scripts/caching.js.map +1 -0
  469. package/src/scripts/caching.ts +1 -0
  470. package/src/scripts/cli.js +152 -0
  471. package/src/scripts/cli.js.map +1 -0
  472. package/src/scripts/cli2.js +119 -0
  473. package/src/scripts/cli2.js.map +1 -0
  474. package/src/scripts/cli3.js +163 -0
  475. package/src/scripts/cli3.js.map +1 -0
  476. package/src/scripts/cli4.js +165 -0
  477. package/src/scripts/cli4.js.map +1 -0
  478. package/src/scripts/cli5.js +165 -0
  479. package/src/scripts/cli5.js.map +1 -0
  480. package/src/scripts/code_exec.js +171 -0
  481. package/src/scripts/code_exec.js.map +1 -0
  482. package/src/scripts/code_exec.ts +1 -0
  483. package/src/scripts/code_exec_files.js +180 -0
  484. package/src/scripts/code_exec_files.js.map +1 -0
  485. package/src/scripts/code_exec_files.ts +1 -0
  486. package/src/scripts/code_exec_multi_session.js +185 -0
  487. package/src/scripts/code_exec_multi_session.js.map +1 -0
  488. package/src/scripts/code_exec_multi_session.ts +9 -13
  489. package/src/scripts/code_exec_ptc.js +265 -0
  490. package/src/scripts/code_exec_ptc.js.map +1 -0
  491. package/src/scripts/code_exec_ptc.ts +1 -0
  492. package/src/scripts/code_exec_session.js +217 -0
  493. package/src/scripts/code_exec_session.js.map +1 -0
  494. package/src/scripts/code_exec_session.ts +1 -0
  495. package/src/scripts/code_exec_simple.js +120 -0
  496. package/src/scripts/code_exec_simple.js.map +1 -0
  497. package/src/scripts/code_exec_simple.ts +1 -0
  498. package/src/scripts/content.js +111 -0
  499. package/src/scripts/content.js.map +1 -0
  500. package/src/scripts/content.ts +1 -0
  501. package/src/scripts/empty_input.js +125 -0
  502. package/src/scripts/empty_input.js.map +1 -0
  503. package/src/scripts/handoff-test.js +96 -0
  504. package/src/scripts/handoff-test.js.map +1 -0
  505. package/src/scripts/image.js +138 -0
  506. package/src/scripts/image.js.map +1 -0
  507. package/src/scripts/image.ts +3 -1
  508. package/src/scripts/memory.js +83 -0
  509. package/src/scripts/memory.js.map +1 -0
  510. package/src/scripts/memory.ts +16 -6
  511. package/src/scripts/multi-agent-chain.js +271 -0
  512. package/src/scripts/multi-agent-chain.js.map +1 -0
  513. package/src/scripts/multi-agent-chain.ts +1 -0
  514. package/src/scripts/multi-agent-conditional.js +185 -0
  515. package/src/scripts/multi-agent-conditional.js.map +1 -0
  516. package/src/scripts/multi-agent-conditional.ts +1 -0
  517. package/src/scripts/multi-agent-document-review-chain.js +171 -0
  518. package/src/scripts/multi-agent-document-review-chain.js.map +1 -0
  519. package/src/scripts/multi-agent-document-review-chain.ts +1 -0
  520. package/src/scripts/multi-agent-hybrid-flow.js +264 -0
  521. package/src/scripts/multi-agent-hybrid-flow.js.map +1 -0
  522. package/src/scripts/multi-agent-hybrid-flow.ts +1 -0
  523. package/src/scripts/multi-agent-parallel-start.js +214 -0
  524. package/src/scripts/multi-agent-parallel-start.js.map +1 -0
  525. package/src/scripts/multi-agent-parallel-start.ts +4 -4
  526. package/src/scripts/multi-agent-parallel.js +346 -0
  527. package/src/scripts/multi-agent-parallel.js.map +1 -0
  528. package/src/scripts/multi-agent-parallel.ts +1 -0
  529. package/src/scripts/multi-agent-sequence.js +184 -0
  530. package/src/scripts/multi-agent-sequence.js.map +1 -0
  531. package/src/scripts/multi-agent-sequence.ts +4 -4
  532. package/src/scripts/multi-agent-supervisor.js +324 -0
  533. package/src/scripts/multi-agent-supervisor.js.map +1 -0
  534. package/src/scripts/multi-agent-supervisor.ts +1 -0
  535. package/src/scripts/multi-agent-test.js +147 -0
  536. package/src/scripts/multi-agent-test.js.map +1 -0
  537. package/src/scripts/multi-agent-test.ts +1 -0
  538. package/src/scripts/parallel-asymmetric-tools-test.js +202 -0
  539. package/src/scripts/parallel-asymmetric-tools-test.js.map +1 -0
  540. package/src/scripts/parallel-asymmetric-tools-test.ts +1 -0
  541. package/src/scripts/parallel-full-metadata-test.js +176 -0
  542. package/src/scripts/parallel-full-metadata-test.js.map +1 -0
  543. package/src/scripts/parallel-full-metadata-test.ts +1 -0
  544. package/src/scripts/parallel-tools-test.js +256 -0
  545. package/src/scripts/parallel-tools-test.js.map +1 -0
  546. package/src/scripts/parallel-tools-test.ts +1 -0
  547. package/src/scripts/poc-multi-agent-comprehensive.ts +1222 -0
  548. package/src/scripts/programmatic_exec.js +277 -0
  549. package/src/scripts/programmatic_exec.js.map +1 -0
  550. package/src/scripts/programmatic_exec_agent.js +168 -0
  551. package/src/scripts/programmatic_exec_agent.js.map +1 -0
  552. package/src/scripts/programmatic_exec_agent.ts +1 -0
  553. package/src/scripts/search.js +118 -0
  554. package/src/scripts/search.js.map +1 -0
  555. package/src/scripts/search.ts +1 -0
  556. package/src/scripts/sequential-full-metadata-test.js +143 -0
  557. package/src/scripts/sequential-full-metadata-test.js.map +1 -0
  558. package/src/scripts/sequential-full-metadata-test.ts +1 -0
  559. package/src/scripts/simple.js +174 -0
  560. package/src/scripts/simple.js.map +1 -0
  561. package/src/scripts/simple.ts +2 -1
  562. package/src/scripts/single-agent-metadata-test.js +152 -0
  563. package/src/scripts/single-agent-metadata-test.js.map +1 -0
  564. package/src/scripts/single-agent-metadata-test.ts +4 -6
  565. package/src/scripts/stream.js +113 -0
  566. package/src/scripts/stream.js.map +1 -0
  567. package/src/scripts/stream.ts +1 -0
  568. package/src/scripts/test-custom-prompt-key.js +132 -0
  569. package/src/scripts/test-custom-prompt-key.js.map +1 -0
  570. package/src/scripts/test-handoff-input.js +143 -0
  571. package/src/scripts/test-handoff-input.js.map +1 -0
  572. package/src/scripts/test-handoff-preamble.js +227 -0
  573. package/src/scripts/test-handoff-preamble.js.map +1 -0
  574. package/src/scripts/test-handoff-preamble.ts +1 -0
  575. package/src/scripts/test-handoff-steering.js +353 -0
  576. package/src/scripts/test-handoff-steering.js.map +1 -0
  577. package/src/scripts/test-handoff-steering.ts +430 -0
  578. package/src/scripts/test-multi-agent-list-handoff.js +318 -0
  579. package/src/scripts/test-multi-agent-list-handoff.js.map +1 -0
  580. package/src/scripts/test-multi-agent-list-handoff.ts +1 -0
  581. package/src/scripts/test-parallel-agent-labeling.js +253 -0
  582. package/src/scripts/test-parallel-agent-labeling.js.map +1 -0
  583. package/src/scripts/test-parallel-agent-labeling.ts +2 -0
  584. package/src/scripts/test-parallel-handoffs.js +229 -0
  585. package/src/scripts/test-parallel-handoffs.js.map +1 -0
  586. package/src/scripts/test-parallel-handoffs.ts +1 -0
  587. package/src/scripts/test-thinking-handoff-bedrock.js +132 -0
  588. package/src/scripts/test-thinking-handoff-bedrock.js.map +1 -0
  589. package/src/scripts/test-thinking-handoff-bedrock.ts +1 -0
  590. package/src/scripts/test-thinking-handoff.js +132 -0
  591. package/src/scripts/test-thinking-handoff.js.map +1 -0
  592. package/src/scripts/test-thinking-handoff.ts +1 -0
  593. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +140 -0
  594. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js.map +1 -0
  595. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +166 -0
  596. package/src/scripts/test-tool-before-handoff-role-order.js +223 -0
  597. package/src/scripts/test-tool-before-handoff-role-order.js.map +1 -0
  598. package/src/scripts/test-tool-before-handoff-role-order.ts +276 -0
  599. package/src/scripts/test-tools-before-handoff.js +187 -0
  600. package/src/scripts/test-tools-before-handoff.js.map +1 -0
  601. package/src/scripts/test-tools-before-handoff.ts +4 -8
  602. package/src/scripts/test_code_api.js +263 -0
  603. package/src/scripts/test_code_api.js.map +1 -0
  604. package/src/scripts/thinking-bedrock.js +128 -0
  605. package/src/scripts/thinking-bedrock.js.map +1 -0
  606. package/src/scripts/thinking-bedrock.ts +1 -0
  607. package/src/scripts/thinking-vertexai.js +130 -0
  608. package/src/scripts/thinking-vertexai.js.map +1 -0
  609. package/src/scripts/thinking-vertexai.ts +168 -0
  610. package/src/scripts/thinking.js +134 -0
  611. package/src/scripts/thinking.js.map +1 -0
  612. package/src/scripts/thinking.ts +1 -0
  613. package/src/scripts/tool_search.js +114 -0
  614. package/src/scripts/tool_search.js.map +1 -0
  615. package/src/scripts/tools.js +125 -0
  616. package/src/scripts/tools.js.map +1 -0
  617. package/src/scripts/tools.ts +5 -19
  618. package/src/specs/agent-handoffs-bedrock.integration.test.js +280 -0
  619. package/src/specs/agent-handoffs-bedrock.integration.test.js.map +1 -0
  620. package/src/specs/agent-handoffs-bedrock.integration.test.ts +412 -375
  621. package/src/specs/agent-handoffs.test.js +924 -0
  622. package/src/specs/agent-handoffs.test.js.map +1 -0
  623. package/src/specs/agent-handoffs.test.ts +152 -39
  624. package/src/specs/anthropic.simple.test.js +287 -0
  625. package/src/specs/anthropic.simple.test.js.map +1 -0
  626. package/src/specs/anthropic.simple.test.ts +7 -4
  627. package/src/specs/azure.simple.test.js +381 -0
  628. package/src/specs/azure.simple.test.js.map +1 -0
  629. package/src/specs/azure.simple.test.ts +143 -5
  630. package/src/specs/cache.simple.test.js +282 -0
  631. package/src/specs/cache.simple.test.js.map +1 -0
  632. package/src/specs/cache.simple.test.ts +9 -2
  633. package/src/specs/custom-event-await.test.js +148 -0
  634. package/src/specs/custom-event-await.test.js.map +1 -0
  635. package/src/specs/custom-event-await.test.ts +215 -0
  636. package/src/specs/deepseek.simple.test.js +189 -0
  637. package/src/specs/deepseek.simple.test.js.map +1 -0
  638. package/src/specs/deepseek.simple.test.ts +4 -2
  639. package/src/specs/emergency-prune.test.js +308 -0
  640. package/src/specs/emergency-prune.test.js.map +1 -0
  641. package/src/specs/moonshot.simple.test.js +237 -0
  642. package/src/specs/moonshot.simple.test.js.map +1 -0
  643. package/src/specs/moonshot.simple.test.ts +6 -2
  644. package/src/specs/observability.integration.test.js +1337 -0
  645. package/src/specs/observability.integration.test.js.map +1 -0
  646. package/src/specs/observability.integration.test.ts +2223 -0
  647. package/src/specs/openai.simple.test.js +233 -0
  648. package/src/specs/openai.simple.test.js.map +1 -0
  649. package/src/specs/openai.simple.test.ts +4 -2
  650. package/src/specs/openrouter.simple.test.js +202 -0
  651. package/src/specs/openrouter.simple.test.js.map +1 -0
  652. package/src/specs/openrouter.simple.test.ts +165 -4
  653. package/src/specs/prune.test.js +733 -0
  654. package/src/specs/prune.test.js.map +1 -0
  655. package/src/specs/prune.test.ts +1 -0
  656. package/src/specs/reasoning.test.js +144 -0
  657. package/src/specs/reasoning.test.js.map +1 -0
  658. package/src/specs/reasoning.test.ts +2 -2
  659. package/src/specs/spec.utils.js +4 -0
  660. package/src/specs/spec.utils.js.map +1 -0
  661. package/src/specs/thinking-handoff.test.js +486 -0
  662. package/src/specs/thinking-handoff.test.js.map +1 -0
  663. package/src/specs/thinking-handoff.test.ts +3 -2
  664. package/src/specs/thinking-prune.test.js +600 -0
  665. package/src/specs/thinking-prune.test.js.map +1 -0
  666. package/src/specs/token-distribution-edge-case.test.js +246 -0
  667. package/src/specs/token-distribution-edge-case.test.js.map +1 -0
  668. package/src/specs/token-memoization.test.js +32 -0
  669. package/src/specs/token-memoization.test.js.map +1 -0
  670. package/src/specs/token-memoization.test.ts +14 -5
  671. package/src/specs/tokens.test.js +49 -0
  672. package/src/specs/tokens.test.js.map +1 -0
  673. package/src/specs/tokens.test.ts +64 -0
  674. package/src/specs/tool-error.test.js +139 -0
  675. package/src/specs/tool-error.test.js.map +1 -0
  676. package/src/specs/tool-error.test.ts +2 -2
  677. package/src/splitStream.js +204 -0
  678. package/src/splitStream.js.map +1 -0
  679. package/src/splitStream.test.js +504 -0
  680. package/src/splitStream.test.js.map +1 -0
  681. package/src/stream.js +650 -0
  682. package/src/stream.js.map +1 -0
  683. package/src/stream.test.js +225 -0
  684. package/src/stream.test.js.map +1 -0
  685. package/src/stream.test.ts +25 -15
  686. package/src/stream.ts +82 -32
  687. package/src/test/mockTools.js +340 -0
  688. package/src/test/mockTools.js.map +1 -0
  689. package/src/tools/AskUser.ts +159 -0
  690. package/src/tools/BrowserTools.js +245 -0
  691. package/src/tools/BrowserTools.js.map +1 -0
  692. package/src/tools/BrowserTools.ts +12 -8
  693. package/src/tools/Calculator.js +38 -0
  694. package/src/tools/Calculator.js.map +1 -0
  695. package/src/tools/Calculator.test.js +225 -0
  696. package/src/tools/Calculator.test.js.map +1 -0
  697. package/src/tools/CodeExecutor.js +233 -0
  698. package/src/tools/CodeExecutor.js.map +1 -0
  699. package/src/tools/CodeExecutor.selfhealing.test.ts +435 -0
  700. package/src/tools/CodeExecutor.ts +82 -5
  701. package/src/tools/ProgrammaticToolCalling.js +602 -0
  702. package/src/tools/ProgrammaticToolCalling.js.map +1 -0
  703. package/src/tools/ProgrammaticToolCalling.ts +40 -52
  704. package/src/tools/StreamingToolCallBuffer.js +179 -0
  705. package/src/tools/StreamingToolCallBuffer.js.map +1 -0
  706. package/src/tools/StreamingToolCallBuffer.ts +218 -0
  707. package/src/tools/ToolNode.js +930 -0
  708. package/src/tools/ToolNode.js.map +1 -0
  709. package/src/tools/ToolNode.ts +454 -41
  710. package/src/tools/ToolSearch.js +904 -0
  711. package/src/tools/ToolSearch.js.map +1 -0
  712. package/src/tools/ToolSearch.ts +84 -33
  713. package/src/tools/__tests__/AskUser.test.ts +537 -0
  714. package/src/tools/__tests__/BrowserTools.test.js +306 -0
  715. package/src/tools/__tests__/BrowserTools.test.js.map +1 -0
  716. package/src/tools/__tests__/BrowserTools.test.ts +131 -6
  717. package/src/tools/__tests__/CodeExecutor.test.ts +76 -0
  718. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +276 -0
  719. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js.map +1 -0
  720. package/src/tools/__tests__/ProgrammaticToolCalling.test.js +807 -0
  721. package/src/tools/__tests__/ProgrammaticToolCalling.test.js.map +1 -0
  722. package/src/tools/__tests__/StreamingToolCallBuffer.test.js +175 -0
  723. package/src/tools/__tests__/StreamingToolCallBuffer.test.js.map +1 -0
  724. package/src/tools/__tests__/StreamingToolCallBuffer.test.ts +263 -0
  725. package/src/tools/__tests__/ToolApproval.test.js +675 -0
  726. package/src/tools/__tests__/ToolApproval.test.js.map +1 -0
  727. package/src/tools/__tests__/ToolApproval.test.ts +194 -20
  728. package/src/tools/__tests__/ToolNode.hitl.test.ts +267 -0
  729. package/src/tools/__tests__/ToolNode.recovery.test.js +200 -0
  730. package/src/tools/__tests__/ToolNode.recovery.test.js.map +1 -0
  731. package/src/tools/__tests__/ToolNode.recovery.test.ts +276 -0
  732. package/src/tools/__tests__/ToolNode.session.test.js +319 -0
  733. package/src/tools/__tests__/ToolNode.session.test.js.map +1 -0
  734. package/src/tools/__tests__/ToolNode.session.test.ts +465 -0
  735. package/src/tools/__tests__/ToolSearch.integration.test.js +125 -0
  736. package/src/tools/__tests__/ToolSearch.integration.test.js.map +1 -0
  737. package/src/tools/__tests__/ToolSearch.test.js +812 -0
  738. package/src/tools/__tests__/ToolSearch.test.js.map +1 -0
  739. package/src/tools/__tests__/ToolSearch.test.ts +78 -5
  740. package/src/tools/__tests__/handlers.test.js +799 -0
  741. package/src/tools/__tests__/handlers.test.js.map +1 -0
  742. package/src/tools/__tests__/handlers.test.ts +1100 -0
  743. package/src/tools/__tests__/truncation-recovery.integration.test.js +362 -0
  744. package/src/tools/__tests__/truncation-recovery.integration.test.js.map +1 -0
  745. package/src/tools/__tests__/truncation-recovery.integration.test.ts +560 -0
  746. package/src/tools/handlers.js +306 -0
  747. package/src/tools/handlers.js.map +1 -0
  748. package/src/tools/handlers.ts +119 -16
  749. package/src/tools/schema.js +25 -0
  750. package/src/tools/schema.js.map +1 -0
  751. package/src/tools/search/anthropic.js +34 -0
  752. package/src/tools/search/anthropic.js.map +1 -0
  753. package/src/tools/search/content.js +116 -0
  754. package/src/tools/search/content.js.map +1 -0
  755. package/src/tools/search/content.test.js +133 -0
  756. package/src/tools/search/content.test.js.map +1 -0
  757. package/src/tools/search/firecrawl.js +173 -0
  758. package/src/tools/search/firecrawl.js.map +1 -0
  759. package/src/tools/search/format.js +198 -0
  760. package/src/tools/search/format.js.map +1 -0
  761. package/src/tools/search/highlights.js +241 -0
  762. package/src/tools/search/highlights.js.map +1 -0
  763. package/src/tools/search/index.js +3 -0
  764. package/src/tools/search/index.js.map +1 -0
  765. package/src/tools/search/jina-reranker.test.js +106 -0
  766. package/src/tools/search/jina-reranker.test.js.map +1 -0
  767. package/src/tools/search/rerankers.js +165 -0
  768. package/src/tools/search/rerankers.js.map +1 -0
  769. package/src/tools/search/schema.js +102 -0
  770. package/src/tools/search/schema.js.map +1 -0
  771. package/src/tools/search/search.js +561 -0
  772. package/src/tools/search/search.js.map +1 -0
  773. package/src/tools/search/serper-scraper.js +126 -0
  774. package/src/tools/search/serper-scraper.js.map +1 -0
  775. package/src/tools/search/test.js +129 -0
  776. package/src/tools/search/test.js.map +1 -0
  777. package/src/tools/search/tool.js +453 -0
  778. package/src/tools/search/tool.js.map +1 -0
  779. package/src/tools/search/types.js +2 -0
  780. package/src/tools/search/types.js.map +1 -0
  781. package/src/tools/search/utils.js +59 -0
  782. package/src/tools/search/utils.js.map +1 -0
  783. package/src/types/graph.js +24 -0
  784. package/src/types/graph.js.map +1 -0
  785. package/src/types/graph.test.js +192 -0
  786. package/src/types/graph.test.js.map +1 -0
  787. package/src/types/graph.ts +26 -6
  788. package/src/types/index.js +7 -0
  789. package/src/types/index.js.map +1 -0
  790. package/src/types/llm.js +2 -0
  791. package/src/types/llm.js.map +1 -0
  792. package/src/types/llm.ts +8 -3
  793. package/src/types/messages.js +2 -0
  794. package/src/types/messages.js.map +1 -0
  795. package/src/types/run.js +2 -0
  796. package/src/types/run.js.map +1 -0
  797. package/src/types/run.ts +2 -0
  798. package/src/types/stream.js +2 -0
  799. package/src/types/stream.js.map +1 -0
  800. package/src/types/tools.js +2 -0
  801. package/src/types/tools.js.map +1 -0
  802. package/src/types/tools.ts +21 -2
  803. package/src/utils/contextAnalytics.js +79 -0
  804. package/src/utils/contextAnalytics.js.map +1 -0
  805. package/src/utils/contextAnalytics.test.js +166 -0
  806. package/src/utils/contextAnalytics.test.js.map +1 -0
  807. package/src/utils/contextAnalytics.test.ts +222 -0
  808. package/src/utils/contextAnalytics.ts +27 -9
  809. package/src/utils/events.js +26 -0
  810. package/src/utils/events.js.map +1 -0
  811. package/src/utils/graph.js +11 -0
  812. package/src/utils/graph.js.map +1 -0
  813. package/src/utils/handlers.js +65 -0
  814. package/src/utils/handlers.js.map +1 -0
  815. package/src/utils/index.js +10 -0
  816. package/src/utils/index.js.map +1 -0
  817. package/src/utils/index.ts +1 -0
  818. package/src/utils/llm.js +21 -0
  819. package/src/utils/llm.js.map +1 -0
  820. package/src/utils/llmConfig.js +205 -0
  821. package/src/utils/llmConfig.js.map +1 -0
  822. package/src/utils/llmConfig.ts +5 -5
  823. package/src/utils/logging.js +37 -0
  824. package/src/utils/logging.js.map +1 -0
  825. package/src/utils/misc.js +51 -0
  826. package/src/utils/misc.js.map +1 -0
  827. package/src/utils/run.js +69 -0
  828. package/src/utils/run.js.map +1 -0
  829. package/src/utils/run.ts +108 -106
  830. package/src/utils/schema.js +21 -0
  831. package/src/utils/schema.js.map +1 -0
  832. package/src/utils/title.js +119 -0
  833. package/src/utils/title.js.map +1 -0
  834. package/src/utils/tokens.js +92 -0
  835. package/src/utils/tokens.js.map +1 -0
  836. package/src/utils/tokens.ts +118 -142
  837. package/src/utils/toolCallContinuation.ts +55 -0
  838. package/src/utils/toonFormat.js +379 -0
  839. package/src/utils/toonFormat.js.map +1 -0
@@ -0,0 +1,1100 @@
1
+ import { describe, it, expect, beforeEach, jest } from '@jest/globals';
2
+ import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
3
+ import type { StandardGraph } from '@/graphs';
4
+ import type { AgentContext } from '@/agents/AgentContext';
5
+ import type * as t from '@/types';
6
+ import { StepTypes, ToolCallTypes, Providers, GraphEvents } from '@/common';
7
+ import {
8
+ handleToolCallChunks,
9
+ handleToolCalls,
10
+ handleServerToolResult,
11
+ } from '../handlers';
12
+
13
+ type MockGraph = {
14
+ getStepKey: jest.Mock;
15
+ getStepIdByKey: jest.Mock;
16
+ getRunStep: jest.Mock;
17
+ dispatchRunStep: jest.Mock;
18
+ dispatchRunStepDelta: jest.Mock;
19
+ toolCallStepIds: Map<string, string>;
20
+ messageStepHasToolCalls: Map<string, boolean>;
21
+ messageIdsByStepKey: Map<string, string>;
22
+ prelimMessageIdsByStepKey: Map<string, string>;
23
+ invokedToolIds?: Set<string>;
24
+ handlerRegistry?: {
25
+ getHandler: jest.Mock;
26
+ };
27
+ streamingToolCallBuffer: {
28
+ append: jest.Mock;
29
+ setToolName: jest.Mock;
30
+ getToolName: jest.Mock;
31
+ getRawArgs: jest.Mock;
32
+ extractFieldValue: jest.Mock;
33
+ has: jest.Mock;
34
+ clear: jest.Mock;
35
+ clearAll: jest.Mock;
36
+ setIndexMapping: jest.Mock;
37
+ getIdByIndex: jest.Mock;
38
+ };
39
+ };
40
+
41
+ function createMockGraph(overrides?: Partial<MockGraph>): MockGraph {
42
+ let stepCounter = 0;
43
+ return {
44
+ getStepKey: jest.fn<() => string>().mockReturnValue('step-key'),
45
+ getStepIdByKey: jest.fn<() => string>().mockReturnValue('prev-step-id'),
46
+ getRunStep: jest
47
+ .fn<() => t.RunStep | undefined>()
48
+ .mockReturnValue(undefined),
49
+ dispatchRunStep: jest
50
+ .fn<() => Promise<string>>()
51
+ .mockImplementation(async () => `new-step-${++stepCounter}`),
52
+ dispatchRunStepDelta: jest
53
+ .fn<() => Promise<void>>()
54
+ .mockResolvedValue(undefined),
55
+ toolCallStepIds: new Map(),
56
+ messageStepHasToolCalls: new Map(),
57
+ messageIdsByStepKey: new Map(),
58
+ prelimMessageIdsByStepKey: new Map(),
59
+ invokedToolIds: undefined,
60
+ handlerRegistry: undefined,
61
+ streamingToolCallBuffer: {
62
+ append: jest.fn(),
63
+ setToolName: jest.fn(),
64
+ getToolName: jest.fn(),
65
+ getRawArgs: jest.fn(),
66
+ extractFieldValue: jest.fn(),
67
+ has: jest.fn().mockReturnValue(false),
68
+ clear: jest.fn(),
69
+ clearAll: jest.fn(),
70
+ setIndexMapping: jest.fn(),
71
+ getIdByIndex: jest.fn().mockReturnValue(undefined),
72
+ },
73
+ ...overrides,
74
+ };
75
+ }
76
+
77
+ function makeRunStep(
78
+ type: StepTypes,
79
+ opts?: { tool_calls?: t.AgentToolCall[]; id?: string; index?: number }
80
+ ): t.RunStep {
81
+ const stepDetails: t.StepDetails =
82
+ type === StepTypes.MESSAGE_CREATION
83
+ ? {
84
+ type: StepTypes.MESSAGE_CREATION,
85
+ message_creation: { message_id: 'msg-1' },
86
+ }
87
+ : { type: StepTypes.TOOL_CALLS, tool_calls: opts?.tool_calls ?? [] };
88
+ return {
89
+ type,
90
+ id: opts?.id ?? 'run-step-1',
91
+ index: opts?.index ?? 0,
92
+ stepDetails,
93
+ usage: null,
94
+ };
95
+ }
96
+
97
+ function makeToolCall(id: string, name = 'calculator'): ToolCall {
98
+ return { id, name, args: {}, type: 'tool_call' };
99
+ }
100
+
101
+ function makeToolCallChunk(opts?: {
102
+ id?: string;
103
+ name?: string;
104
+ index?: number;
105
+ }): ToolCallChunk {
106
+ return {
107
+ id: opts?.id,
108
+ name: opts?.name,
109
+ args: '',
110
+ index: opts?.index ?? 0,
111
+ type: 'tool_call_chunk',
112
+ };
113
+ }
114
+
115
+ const defaultMetadata = { run_id: 'test-run' };
116
+
117
+ describe('handleToolCallChunks', () => {
118
+ let graph: MockGraph;
119
+
120
+ beforeEach(() => {
121
+ graph = createMockGraph();
122
+ });
123
+
124
+ it('creates TOOL_CALLS step when previous step is MESSAGE_CREATION', async () => {
125
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
126
+ graph.getRunStep.mockReturnValue(msgStep);
127
+
128
+ const chunks = [makeToolCallChunk({ index: 2 })];
129
+ await handleToolCallChunks({
130
+ graph: graph as unknown as StandardGraph,
131
+ stepKey: 'step-key',
132
+ toolCallChunks: chunks,
133
+ metadata: defaultMetadata,
134
+ });
135
+
136
+ const dispatchCalls = graph.dispatchRunStep.mock.calls;
137
+ expect(dispatchCalls).toHaveLength(1);
138
+ expect(dispatchCalls[0][1]).toEqual(
139
+ expect.objectContaining({ type: StepTypes.TOOL_CALLS })
140
+ );
141
+ expect(graph.messageStepHasToolCalls.has('prev-step-id')).toBe(true);
142
+ expect(graph.dispatchRunStepDelta).toHaveBeenCalledTimes(1);
143
+ });
144
+
145
+ it('reuses existing TOOL_CALLS step without dispatching a new one', async () => {
146
+ const toolStep = makeRunStep(StepTypes.TOOL_CALLS);
147
+ graph.getRunStep.mockReturnValue(toolStep);
148
+
149
+ const chunks = [makeToolCallChunk({ index: 2 })];
150
+ await handleToolCallChunks({
151
+ graph: graph as unknown as StandardGraph,
152
+ stepKey: 'step-key',
153
+ toolCallChunks: chunks,
154
+ metadata: defaultMetadata,
155
+ });
156
+
157
+ expect(graph.dispatchRunStep).not.toHaveBeenCalled();
158
+ expect(graph.dispatchRunStepDelta).toHaveBeenCalledTimes(1);
159
+ expect(graph.dispatchRunStepDelta).toHaveBeenCalledWith(
160
+ 'prev-step-id',
161
+ expect.objectContaining({ type: StepTypes.TOOL_CALLS })
162
+ );
163
+ });
164
+
165
+ it('creates MESSAGE_CREATION when no previous step exists', async () => {
166
+ let callCount = 0;
167
+ graph.getStepIdByKey.mockImplementation(() => {
168
+ callCount++;
169
+ if (callCount === 1) {
170
+ throw new Error('No step found');
171
+ }
172
+ return 'new-step-1';
173
+ });
174
+ graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.MESSAGE_CREATION));
175
+
176
+ const chunks = [makeToolCallChunk({ index: 0 })];
177
+ await handleToolCallChunks({
178
+ graph: graph as unknown as StandardGraph,
179
+ stepKey: 'step-key',
180
+ toolCallChunks: chunks,
181
+ metadata: defaultMetadata,
182
+ });
183
+
184
+ const dispatchCalls = graph.dispatchRunStep.mock.calls;
185
+ expect(dispatchCalls.length).toBeGreaterThanOrEqual(2);
186
+ expect(dispatchCalls[0][1]).toEqual(
187
+ expect.objectContaining({ type: StepTypes.MESSAGE_CREATION })
188
+ );
189
+ expect(dispatchCalls[1][1]).toEqual(
190
+ expect.objectContaining({ type: StepTypes.TOOL_CALLS })
191
+ );
192
+ });
193
+
194
+ it('skips TOOL_CALLS dispatch when already dispatched for this MESSAGE_CREATION', async () => {
195
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
196
+ graph.getRunStep.mockReturnValue(msgStep);
197
+ graph.messageStepHasToolCalls.set('prev-step-id', true);
198
+
199
+ const chunks = [makeToolCallChunk({ index: 2 })];
200
+ await handleToolCallChunks({
201
+ graph: graph as unknown as StandardGraph,
202
+ stepKey: 'step-key',
203
+ toolCallChunks: chunks,
204
+ metadata: defaultMetadata,
205
+ });
206
+
207
+ expect(graph.dispatchRunStep).not.toHaveBeenCalled();
208
+ expect(graph.dispatchRunStepDelta).toHaveBeenCalledTimes(1);
209
+ });
210
+
211
+ it('sanitizes empty string id and name to undefined', async () => {
212
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
213
+ graph.getRunStep.mockReturnValue(msgStep);
214
+
215
+ const chunk = makeToolCallChunk({ id: '', name: '' });
216
+ await handleToolCallChunks({
217
+ graph: graph as unknown as StandardGraph,
218
+ stepKey: 'step-key',
219
+ toolCallChunks: [chunk],
220
+ metadata: defaultMetadata,
221
+ });
222
+
223
+ expect(chunk.id).toBeUndefined();
224
+ expect(chunk.name).toBeUndefined();
225
+ });
226
+
227
+ it('populates tool_calls when chunk has valid id and name', async () => {
228
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
229
+ graph.getRunStep.mockReturnValue(msgStep);
230
+
231
+ const chunks = [
232
+ makeToolCallChunk({ id: 'tooluse_abc', name: 'calculator', index: 2 }),
233
+ ];
234
+ await handleToolCallChunks({
235
+ graph: graph as unknown as StandardGraph,
236
+ stepKey: 'step-key',
237
+ toolCallChunks: chunks,
238
+ metadata: defaultMetadata,
239
+ });
240
+
241
+ const toolCallsArg = graph.dispatchRunStep.mock
242
+ .calls[0][1] as t.ToolCallsDetails;
243
+ expect(toolCallsArg.tool_calls).toEqual([
244
+ expect.objectContaining({
245
+ id: 'tooluse_abc',
246
+ name: 'calculator',
247
+ type: ToolCallTypes.TOOL_CALL,
248
+ }),
249
+ ]);
250
+ });
251
+
252
+ it('never dispatches empty text block alongside TOOL_CALLS step', async () => {
253
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
254
+ graph.getRunStep.mockReturnValue(msgStep);
255
+
256
+ const chunks = [
257
+ makeToolCallChunk({ id: 'tooluse_abc', name: 'calculator', index: 2 }),
258
+ ];
259
+ await handleToolCallChunks({
260
+ graph: graph as unknown as StandardGraph,
261
+ stepKey: 'step-key',
262
+ toolCallChunks: chunks,
263
+ metadata: defaultMetadata,
264
+ });
265
+
266
+ const allDispatches = graph.dispatchRunStep.mock.calls;
267
+ expect(allDispatches).toHaveLength(1);
268
+ const stepDetails = allDispatches[0][1] as t.StepDetails;
269
+ expect(stepDetails.type).toBe(StepTypes.TOOL_CALLS);
270
+ expect(stepDetails).not.toHaveProperty('content');
271
+ expect(stepDetails).not.toHaveProperty('text');
272
+ });
273
+
274
+ it('feeds buffer with id+args on same chunk (OpenAI/Anthropic pattern)', async () => {
275
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
276
+ graph.getRunStep.mockReturnValue(msgStep);
277
+
278
+ const chunk: ToolCallChunk = {
279
+ id: 'tc_1',
280
+ name: 'content_tool',
281
+ args: '{"action":"wri',
282
+ index: 0,
283
+ type: 'tool_call_chunk',
284
+ };
285
+ await handleToolCallChunks({
286
+ graph: graph as unknown as StandardGraph,
287
+ stepKey: 'step-key',
288
+ toolCallChunks: [chunk],
289
+ metadata: defaultMetadata,
290
+ });
291
+
292
+ expect(graph.streamingToolCallBuffer.setIndexMapping).toHaveBeenCalledWith(
293
+ 0,
294
+ 'tc_1'
295
+ );
296
+ expect(graph.streamingToolCallBuffer.setToolName).toHaveBeenCalledWith(
297
+ 'tc_1',
298
+ 'content_tool'
299
+ );
300
+ expect(graph.streamingToolCallBuffer.append).toHaveBeenCalledWith(
301
+ 'tc_1',
302
+ '{"action":"wri'
303
+ );
304
+ });
305
+
306
+ it('feeds buffer via index lookup for Bedrock DELTA chunks (no id)', async () => {
307
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
308
+ graph.getRunStep.mockReturnValue(msgStep);
309
+ // Simulate: index 0 was previously mapped to 'tc_1'
310
+ graph.streamingToolCallBuffer.getIdByIndex.mockReturnValue('tc_1');
311
+
312
+ const deltaChunk: ToolCallChunk = {
313
+ id: undefined,
314
+ name: undefined,
315
+ args: 'te","content":"hello',
316
+ index: 0,
317
+ type: 'tool_call_chunk',
318
+ };
319
+ await handleToolCallChunks({
320
+ graph: graph as unknown as StandardGraph,
321
+ stepKey: 'step-key',
322
+ toolCallChunks: [deltaChunk],
323
+ metadata: defaultMetadata,
324
+ });
325
+
326
+ expect(graph.streamingToolCallBuffer.getIdByIndex).toHaveBeenCalledWith(0);
327
+ expect(graph.streamingToolCallBuffer.append).toHaveBeenCalledWith(
328
+ 'tc_1',
329
+ 'te","content":"hello'
330
+ );
331
+ });
332
+
333
+ it('does not feed buffer when DELTA chunk has no index mapping', async () => {
334
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
335
+ graph.getRunStep.mockReturnValue(msgStep);
336
+ // No index mapping exists
337
+ graph.streamingToolCallBuffer.getIdByIndex.mockReturnValue(undefined);
338
+
339
+ const deltaChunk: ToolCallChunk = {
340
+ id: undefined,
341
+ name: undefined,
342
+ args: 'some args',
343
+ index: 5,
344
+ type: 'tool_call_chunk',
345
+ };
346
+ await handleToolCallChunks({
347
+ graph: graph as unknown as StandardGraph,
348
+ stepKey: 'step-key',
349
+ toolCallChunks: [deltaChunk],
350
+ metadata: defaultMetadata,
351
+ });
352
+
353
+ expect(graph.streamingToolCallBuffer.append).not.toHaveBeenCalled();
354
+ });
355
+
356
+ it('dispatches delta even when chunks lack id/name (Bedrock pattern)', async () => {
357
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
358
+ graph.getRunStep.mockReturnValue(msgStep);
359
+
360
+ const chunks = [makeToolCallChunk({ index: 2 })];
361
+ await handleToolCallChunks({
362
+ graph: graph as unknown as StandardGraph,
363
+ stepKey: 'step-key',
364
+ toolCallChunks: chunks,
365
+ metadata: defaultMetadata,
366
+ });
367
+
368
+ expect(graph.dispatchRunStepDelta).toHaveBeenCalledTimes(1);
369
+ const toolCallsArg = graph.dispatchRunStep.mock
370
+ .calls[0][1] as t.ToolCallsDetails;
371
+ expect(toolCallsArg.tool_calls).toEqual([]);
372
+ });
373
+ });
374
+
375
+ describe('handleToolCalls', () => {
376
+ let graph: MockGraph;
377
+
378
+ beforeEach(() => {
379
+ graph = createMockGraph();
380
+ });
381
+
382
+ it('returns early when metadata is missing', async () => {
383
+ await handleToolCalls(
384
+ [makeToolCall('id-1')],
385
+ undefined,
386
+ graph as unknown as StandardGraph
387
+ );
388
+ expect(graph.dispatchRunStep).not.toHaveBeenCalled();
389
+ });
390
+
391
+ it('returns early when toolCalls is undefined', async () => {
392
+ await handleToolCalls(
393
+ undefined,
394
+ defaultMetadata,
395
+ graph as unknown as StandardGraph
396
+ );
397
+ expect(graph.dispatchRunStep).not.toHaveBeenCalled();
398
+ });
399
+
400
+ it('returns early when toolCalls is empty', async () => {
401
+ await handleToolCalls(
402
+ [],
403
+ defaultMetadata,
404
+ graph as unknown as StandardGraph
405
+ );
406
+ expect(graph.dispatchRunStep).not.toHaveBeenCalled();
407
+ });
408
+
409
+ it('skips tool call when id already in toolCallStepIds', async () => {
410
+ graph.toolCallStepIds.set('id-1', 'existing-step');
411
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
412
+ graph.getRunStep.mockReturnValue(msgStep);
413
+
414
+ await handleToolCalls(
415
+ [makeToolCall('id-1')],
416
+ defaultMetadata,
417
+ graph as unknown as StandardGraph
418
+ );
419
+
420
+ expect(graph.dispatchRunStep).not.toHaveBeenCalled();
421
+ });
422
+
423
+ it('assigns fallback id when tool_call.id is undefined', async () => {
424
+ const tc: ToolCall = {
425
+ id: undefined as unknown as string,
426
+ name: 'calc',
427
+ args: {},
428
+ type: 'tool_call',
429
+ };
430
+ graph.getStepIdByKey.mockImplementation(() => {
431
+ throw new Error('no step');
432
+ });
433
+
434
+ await handleToolCalls(
435
+ [tc],
436
+ defaultMetadata,
437
+ graph as unknown as StandardGraph
438
+ );
439
+
440
+ expect(tc.id).toBeDefined();
441
+ expect(tc.id!.startsWith('toolu_')).toBe(true);
442
+ expect(graph.dispatchRunStep).toHaveBeenCalled();
443
+ });
444
+
445
+ it('flags messageStepHasToolCalls and dispatches TOOL_CALLS when prev step is MESSAGE_CREATION', async () => {
446
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
447
+ graph.getRunStep.mockReturnValue(msgStep);
448
+
449
+ await handleToolCalls(
450
+ [makeToolCall('id-1')],
451
+ defaultMetadata,
452
+ graph as unknown as StandardGraph
453
+ );
454
+
455
+ expect(graph.messageStepHasToolCalls.get('prev-step-id')).toBe(true);
456
+ const calls = graph.dispatchRunStep.mock.calls;
457
+ expect(calls).toHaveLength(1);
458
+ expect(calls[0][1]).toEqual(
459
+ expect.objectContaining({ type: StepTypes.TOOL_CALLS })
460
+ );
461
+ });
462
+
463
+ it('creates MESSAGE_CREATION when no previous step exists', async () => {
464
+ graph.getStepIdByKey.mockImplementation(() => {
465
+ throw new Error('no step');
466
+ });
467
+
468
+ await handleToolCalls(
469
+ [makeToolCall('id-1')],
470
+ defaultMetadata,
471
+ graph as unknown as StandardGraph
472
+ );
473
+
474
+ const calls = graph.dispatchRunStep.mock.calls;
475
+ expect(calls).toHaveLength(2);
476
+ expect(calls[0][1]).toEqual(
477
+ expect.objectContaining({ type: StepTypes.MESSAGE_CREATION })
478
+ );
479
+ expect(calls[1][1]).toEqual(
480
+ expect.objectContaining({ type: StepTypes.TOOL_CALLS })
481
+ );
482
+ });
483
+
484
+ it('reuses empty TOOL_CALLS step exactly once', async () => {
485
+ const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, {
486
+ id: 'empty-step',
487
+ tool_calls: [],
488
+ });
489
+ graph.getRunStep.mockReturnValue(emptyToolStep);
490
+ graph.getStepIdByKey.mockReturnValue('empty-step-id');
491
+
492
+ await handleToolCalls(
493
+ [makeToolCall('id-1'), makeToolCall('id-2')],
494
+ defaultMetadata,
495
+ graph as unknown as StandardGraph
496
+ );
497
+
498
+ expect(graph.toolCallStepIds.get('id-1')).toBe('empty-step-id');
499
+
500
+ const calls = graph.dispatchRunStep.mock.calls;
501
+ expect(calls).toHaveLength(1);
502
+ expect(calls[0][1]).toEqual(
503
+ expect.objectContaining({
504
+ type: StepTypes.TOOL_CALLS,
505
+ tool_calls: [expect.objectContaining({ id: 'id-2' })],
506
+ })
507
+ );
508
+ });
509
+
510
+ it('gives each parallel tool call its own step (3 tool calls)', async () => {
511
+ const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, { tool_calls: [] });
512
+ graph.getStepIdByKey.mockReturnValue('chunk-step-id');
513
+
514
+ let callCount = 0;
515
+ graph.getRunStep.mockImplementation(() => {
516
+ if (callCount === 0) {
517
+ callCount++;
518
+ return emptyToolStep;
519
+ }
520
+ return makeRunStep(StepTypes.TOOL_CALLS, {
521
+ tool_calls: [
522
+ {
523
+ id: 'prev',
524
+ name: 'calc',
525
+ args: {},
526
+ type: 'tool_call',
527
+ } as t.AgentToolCall,
528
+ ],
529
+ });
530
+ });
531
+
532
+ await handleToolCalls(
533
+ [makeToolCall('id-1'), makeToolCall('id-2'), makeToolCall('id-3')],
534
+ defaultMetadata,
535
+ graph as unknown as StandardGraph
536
+ );
537
+
538
+ expect(graph.toolCallStepIds.get('id-1')).toBe('chunk-step-id');
539
+
540
+ const calls = graph.dispatchRunStep.mock.calls;
541
+ expect(calls).toHaveLength(2);
542
+ expect((calls[0][1] as t.ToolCallsDetails).tool_calls![0].id).toBe('id-2');
543
+ expect((calls[1][1] as t.ToolCallsDetails).tool_calls![0].id).toBe('id-3');
544
+ });
545
+
546
+ it('never creates MESSAGE_CREATION for parallel tool calls after TOOL_CALLS prev', async () => {
547
+ const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, { tool_calls: [] });
548
+ graph.getStepIdByKey.mockReturnValue('chunk-step-id');
549
+
550
+ let callCount = 0;
551
+ graph.getRunStep.mockImplementation(() => {
552
+ if (callCount === 0) {
553
+ callCount++;
554
+ return emptyToolStep;
555
+ }
556
+ return makeRunStep(StepTypes.TOOL_CALLS, {
557
+ tool_calls: [
558
+ {
559
+ id: 'prev',
560
+ name: 'calc',
561
+ args: {},
562
+ type: 'tool_call',
563
+ } as t.AgentToolCall,
564
+ ],
565
+ });
566
+ });
567
+
568
+ await handleToolCalls(
569
+ [makeToolCall('id-1'), makeToolCall('id-2'), makeToolCall('id-3')],
570
+ defaultMetadata,
571
+ graph as unknown as StandardGraph
572
+ );
573
+
574
+ const msgCreationCalls = graph.dispatchRunStep.mock.calls.filter(
575
+ (call) => (call[1] as t.StepDetails).type === StepTypes.MESSAGE_CREATION
576
+ );
577
+ expect(msgCreationCalls).toHaveLength(0);
578
+ });
579
+
580
+ it('dispatches new TOOL_CALLS directly when prev TOOL_CALLS has existing data', async () => {
581
+ const populatedToolStep = makeRunStep(StepTypes.TOOL_CALLS, {
582
+ tool_calls: [
583
+ {
584
+ id: 'existing',
585
+ name: 'calc',
586
+ args: {},
587
+ type: 'tool_call',
588
+ } as t.AgentToolCall,
589
+ ],
590
+ });
591
+ graph.getRunStep.mockReturnValue(populatedToolStep);
592
+
593
+ await handleToolCalls(
594
+ [makeToolCall('id-1')],
595
+ defaultMetadata,
596
+ graph as unknown as StandardGraph
597
+ );
598
+
599
+ const calls = graph.dispatchRunStep.mock.calls;
600
+ expect(calls).toHaveLength(1);
601
+ expect(calls[0][1]).toEqual(
602
+ expect.objectContaining({ type: StepTypes.TOOL_CALLS })
603
+ );
604
+ });
605
+
606
+ it('never dispatches empty text block with tool_call_ids (MESSAGE_CREATION path)', async () => {
607
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
608
+ graph.getRunStep.mockReturnValue(msgStep);
609
+
610
+ await handleToolCalls(
611
+ [makeToolCall('id-1')],
612
+ defaultMetadata,
613
+ graph as unknown as StandardGraph
614
+ );
615
+
616
+ for (const call of graph.dispatchRunStep.mock.calls) {
617
+ const stepDetails = call[1] as t.StepDetails;
618
+ if (stepDetails.type === StepTypes.TOOL_CALLS) {
619
+ expect(stepDetails).not.toHaveProperty('content');
620
+ expect(stepDetails).not.toHaveProperty('text');
621
+ }
622
+ }
623
+ });
624
+
625
+ it('never dispatches empty text block with tool_call_ids (no prev step path)', async () => {
626
+ graph.getStepIdByKey.mockImplementation(() => {
627
+ throw new Error('no step');
628
+ });
629
+
630
+ await handleToolCalls(
631
+ [makeToolCall('id-1')],
632
+ defaultMetadata,
633
+ graph as unknown as StandardGraph
634
+ );
635
+
636
+ for (const call of graph.dispatchRunStep.mock.calls) {
637
+ const stepDetails = call[1] as t.StepDetails;
638
+ if (stepDetails.type === StepTypes.TOOL_CALLS) {
639
+ expect(stepDetails).not.toHaveProperty('content');
640
+ expect(stepDetails).not.toHaveProperty('text');
641
+ }
642
+ if (stepDetails.type === StepTypes.MESSAGE_CREATION) {
643
+ const msgDetails = stepDetails as t.MessageCreationDetails;
644
+ expect(msgDetails.message_creation.message_id).toBeDefined();
645
+ expect(msgDetails).not.toHaveProperty('tool_call_ids');
646
+ }
647
+ }
648
+ });
649
+ });
650
+
651
+ describe('handleToolCallChunks + handleToolCalls integration', () => {
652
+ let graph: MockGraph;
653
+ const stepKey = 'step-key';
654
+
655
+ beforeEach(() => {
656
+ graph = createMockGraph();
657
+ });
658
+
659
+ it('Bedrock single tool: chunks create empty TOOL_CALLS, then handleToolCalls reuses it', async () => {
660
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
661
+ graph.getRunStep.mockReturnValue(msgStep);
662
+
663
+ await handleToolCallChunks({
664
+ graph: graph as unknown as StandardGraph,
665
+ stepKey,
666
+ toolCallChunks: [makeToolCallChunk({ index: 2 })],
667
+ metadata: defaultMetadata,
668
+ });
669
+
670
+ const chunkStepId = graph.dispatchRunStep.mock.results[0].value as string;
671
+ const resolvedChunkStepId = await chunkStepId;
672
+
673
+ const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, { tool_calls: [] });
674
+ graph.getRunStep.mockReturnValue(emptyToolStep);
675
+ graph.getStepIdByKey.mockReturnValue(resolvedChunkStepId);
676
+ graph.dispatchRunStep.mockClear();
677
+
678
+ await handleToolCalls(
679
+ [makeToolCall('tooluse_abc')],
680
+ defaultMetadata,
681
+ graph as unknown as StandardGraph
682
+ );
683
+
684
+ expect(graph.toolCallStepIds.get('tooluse_abc')).toBe(resolvedChunkStepId);
685
+ expect(graph.dispatchRunStep).not.toHaveBeenCalled();
686
+ });
687
+
688
+ it('Bedrock parallel: 3 chunks then 3 tool calls yields 3 unique step IDs', async () => {
689
+ const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
690
+ graph.getRunStep.mockReturnValue(msgStep);
691
+
692
+ await handleToolCallChunks({
693
+ graph: graph as unknown as StandardGraph,
694
+ stepKey,
695
+ toolCallChunks: [makeToolCallChunk({ index: 2 })],
696
+ metadata: defaultMetadata,
697
+ });
698
+
699
+ const chunkStepId = await (graph.dispatchRunStep.mock.results[0]
700
+ .value as Promise<string>);
701
+
702
+ const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, { tool_calls: [] });
703
+ graph.getStepIdByKey.mockReturnValue(chunkStepId);
704
+
705
+ let callIdx = 0;
706
+ graph.getRunStep.mockImplementation(() => {
707
+ if (callIdx === 0) {
708
+ callIdx++;
709
+ return emptyToolStep;
710
+ }
711
+ return makeRunStep(StepTypes.TOOL_CALLS, {
712
+ tool_calls: [
713
+ {
714
+ id: 'prev',
715
+ name: 'calc',
716
+ args: {},
717
+ type: 'tool_call',
718
+ } as t.AgentToolCall,
719
+ ],
720
+ });
721
+ });
722
+ graph.dispatchRunStep.mockClear();
723
+
724
+ let newStepCounter = 10;
725
+ graph.dispatchRunStep.mockImplementation(
726
+ async () => `new-step-${++newStepCounter}`
727
+ );
728
+
729
+ await handleToolCalls(
730
+ [makeToolCall('id-1'), makeToolCall('id-2'), makeToolCall('id-3')],
731
+ defaultMetadata,
732
+ graph as unknown as StandardGraph
733
+ );
734
+
735
+ expect(graph.toolCallStepIds.get('id-1')).toBe(chunkStepId);
736
+
737
+ const dispatchedIds = graph.dispatchRunStep.mock.calls.map(
738
+ (_, i) => graph.dispatchRunStep.mock.results[i].value
739
+ );
740
+ expect(dispatchedIds).toHaveLength(2);
741
+
742
+ const allStepIds = new Set([
743
+ chunkStepId,
744
+ graph.toolCallStepIds.get('id-1'),
745
+ ...graph.dispatchRunStep.mock.calls.map((call) => {
746
+ const tc = (call[1] as t.ToolCallsDetails).tool_calls;
747
+ return tc?.[0]?.id;
748
+ }),
749
+ ]);
750
+
751
+ expect(graph.toolCallStepIds.get('id-1')).toBe(chunkStepId);
752
+ expect(allStepIds.size).toBeGreaterThanOrEqual(2);
753
+
754
+ const msgCreationCalls = graph.dispatchRunStep.mock.calls.filter(
755
+ (call) => (call[1] as t.StepDetails).type === StepTypes.MESSAGE_CREATION
756
+ );
757
+ expect(msgCreationCalls).toHaveLength(0);
758
+ });
759
+ });
760
+
761
+ describe('handleServerToolResult', () => {
762
+ let graph: MockGraph;
763
+ const anthropicContext = { provider: Providers.ANTHROPIC } as AgentContext;
764
+
765
+ beforeEach(() => {
766
+ graph = createMockGraph();
767
+ });
768
+
769
+ it('returns false when provider is not Anthropic', async () => {
770
+ const result = await handleServerToolResult({
771
+ graph: graph as unknown as StandardGraph,
772
+ content: [{ type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' }],
773
+ agentContext: { provider: Providers.OPENAI } as AgentContext,
774
+ });
775
+ expect(result).toBe(false);
776
+ });
777
+
778
+ it('returns false when content is a string', async () => {
779
+ const result = await handleServerToolResult({
780
+ graph: graph as unknown as StandardGraph,
781
+ content: 'plain text',
782
+ agentContext: anthropicContext,
783
+ });
784
+ expect(result).toBe(false);
785
+ });
786
+
787
+ it('returns false when content is null/undefined', async () => {
788
+ const result = await handleServerToolResult({
789
+ graph: graph as unknown as StandardGraph,
790
+ content: undefined,
791
+ agentContext: anthropicContext,
792
+ });
793
+ expect(result).toBe(false);
794
+ });
795
+
796
+ it('returns false when content is empty array', async () => {
797
+ const result = await handleServerToolResult({
798
+ graph: graph as unknown as StandardGraph,
799
+ content: [],
800
+ agentContext: anthropicContext,
801
+ });
802
+ expect(result).toBe(false);
803
+ });
804
+
805
+ it('returns false when single content item has no tool_use_id', async () => {
806
+ const result = await handleServerToolResult({
807
+ graph: graph as unknown as StandardGraph,
808
+ content: [{ type: 'tool_result', content: 'ok' } as t.ToolResultContent],
809
+ agentContext: anthropicContext,
810
+ });
811
+ expect(result).toBe(false);
812
+ });
813
+
814
+ it('skips content parts with empty tool_use_id', async () => {
815
+ const result = await handleServerToolResult({
816
+ graph: graph as unknown as StandardGraph,
817
+ content: [
818
+ { type: 'tool_result', tool_use_id: '', content: 'ok' },
819
+ { type: 'tool_result', tool_use_id: 'tu-valid', content: 'ok' },
820
+ ] as t.MessageContentComplex[],
821
+ agentContext: anthropicContext,
822
+ });
823
+ expect(result).toBe(false);
824
+ });
825
+
826
+ it('warns and skips when toolCallStepIds has no mapping for tool_use_id', async () => {
827
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
828
+ const result = await handleServerToolResult({
829
+ graph: graph as unknown as StandardGraph,
830
+ content: [
831
+ { type: 'tool_result', tool_use_id: 'tu-missing', content: 'ok' },
832
+ ] as t.MessageContentComplex[],
833
+ agentContext: anthropicContext,
834
+ });
835
+ expect(result).toBe(false);
836
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('tu-missing'));
837
+ warnSpy.mockRestore();
838
+ });
839
+
840
+ it('warns when run step does not exist for stepId', async () => {
841
+ graph.toolCallStepIds.set('tu-1', 'step-1');
842
+ graph.getRunStep.mockReturnValue(undefined);
843
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
844
+
845
+ const result = await handleServerToolResult({
846
+ graph: graph as unknown as StandardGraph,
847
+ content: [
848
+ { type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' },
849
+ ] as t.MessageContentComplex[],
850
+ agentContext: anthropicContext,
851
+ });
852
+ expect(result).toBe(false);
853
+ expect(warnSpy).toHaveBeenCalledWith(
854
+ expect.stringContaining('does not exist')
855
+ );
856
+ warnSpy.mockRestore();
857
+ });
858
+
859
+ it('warns when run step is not a TOOL_CALLS type', async () => {
860
+ graph.toolCallStepIds.set('tu-1', 'step-1');
861
+ graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.MESSAGE_CREATION));
862
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
863
+
864
+ const result = await handleServerToolResult({
865
+ graph: graph as unknown as StandardGraph,
866
+ content: [
867
+ { type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' },
868
+ ] as t.MessageContentComplex[],
869
+ agentContext: anthropicContext,
870
+ });
871
+ expect(result).toBe(false);
872
+ expect(warnSpy).toHaveBeenCalledWith(
873
+ expect.stringContaining('not a tool call step')
874
+ );
875
+ warnSpy.mockRestore();
876
+ });
877
+
878
+ it('skips when no matching tool call found in step details', async () => {
879
+ graph.toolCallStepIds.set('tu-1', 'step-1');
880
+ graph.getRunStep.mockReturnValue(
881
+ makeRunStep(StepTypes.TOOL_CALLS, {
882
+ tool_calls: [
883
+ {
884
+ id: 'tu-other',
885
+ name: 'calc',
886
+ args: {},
887
+ type: 'tool_call',
888
+ } as t.AgentToolCall,
889
+ ],
890
+ })
891
+ );
892
+
893
+ const result = await handleServerToolResult({
894
+ graph: graph as unknown as StandardGraph,
895
+ content: [
896
+ { type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' },
897
+ ] as t.MessageContentComplex[],
898
+ agentContext: anthropicContext,
899
+ });
900
+ expect(result).toBe(false);
901
+ });
902
+
903
+ it('returns true and sets skipHandling when a valid tool result is found', async () => {
904
+ graph.toolCallStepIds.set('tu-1', 'step-1');
905
+ graph.getRunStep.mockReturnValue(
906
+ makeRunStep(StepTypes.TOOL_CALLS, {
907
+ tool_calls: [
908
+ {
909
+ id: 'tu-1',
910
+ name: 'calc',
911
+ args: {},
912
+ type: 'tool_call',
913
+ } as t.AgentToolCall,
914
+ ],
915
+ })
916
+ );
917
+
918
+ const result = await handleServerToolResult({
919
+ graph: graph as unknown as StandardGraph,
920
+ content: [
921
+ { type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' },
922
+ ] as t.MessageContentComplex[],
923
+ agentContext: anthropicContext,
924
+ });
925
+ expect(result).toBe(true);
926
+ });
927
+
928
+ it('calls handleAnthropicSearchResults for web_search_result type', async () => {
929
+ const mockToolEndHandle = jest
930
+ .fn<(...args: unknown[]) => Promise<void>>()
931
+ .mockResolvedValue(undefined);
932
+ graph.handlerRegistry = {
933
+ getHandler: jest.fn().mockReturnValue({ handle: mockToolEndHandle }),
934
+ };
935
+ graph.toolCallStepIds.set('tu-1', 'step-1');
936
+ graph.getRunStep.mockReturnValue(
937
+ makeRunStep(StepTypes.TOOL_CALLS, {
938
+ tool_calls: [
939
+ {
940
+ id: 'tu-1',
941
+ name: 'web_search',
942
+ args: { query: 'test' },
943
+ type: 'tool_call',
944
+ } as t.AgentToolCall,
945
+ ],
946
+ })
947
+ );
948
+
949
+ const webSearchContent: t.ToolResultContent = {
950
+ type: 'web_search_result',
951
+ tool_use_id: 'tu-1',
952
+ content: [
953
+ {
954
+ type: 'web_search_result',
955
+ url: 'https://example.com',
956
+ title: 'Example',
957
+ encrypted_index: 'abc',
958
+ page_age: '2024-01-01',
959
+ },
960
+ ],
961
+ };
962
+
963
+ const result = await handleServerToolResult({
964
+ graph: graph as unknown as StandardGraph,
965
+ content: [webSearchContent] as t.MessageContentComplex[],
966
+ metadata: defaultMetadata,
967
+ agentContext: anthropicContext,
968
+ });
969
+
970
+ expect(result).toBe(true);
971
+ expect(mockToolEndHandle).toHaveBeenCalledWith(
972
+ GraphEvents.TOOL_END,
973
+ expect.objectContaining({ input: { query: 'test' } }),
974
+ defaultMetadata,
975
+ graph
976
+ );
977
+ expect(graph.invokedToolIds).toBeDefined();
978
+ expect(graph.invokedToolIds!.has('tu-1')).toBe(true);
979
+ });
980
+
981
+ it('initializes invokedToolIds set when null', async () => {
982
+ const mockToolEndHandle = jest
983
+ .fn<(...args: unknown[]) => Promise<void>>()
984
+ .mockResolvedValue(undefined);
985
+ graph.handlerRegistry = {
986
+ getHandler: jest.fn().mockReturnValue({ handle: mockToolEndHandle }),
987
+ };
988
+ graph.invokedToolIds = undefined;
989
+ graph.toolCallStepIds.set('tu-1', 'step-1');
990
+ graph.getRunStep.mockReturnValue(
991
+ makeRunStep(StepTypes.TOOL_CALLS, {
992
+ tool_calls: [
993
+ {
994
+ id: 'tu-1',
995
+ name: 'web_search',
996
+ args: {},
997
+ type: 'tool_call',
998
+ } as t.AgentToolCall,
999
+ ],
1000
+ })
1001
+ );
1002
+
1003
+ const webSearchContent: t.ToolResultContent = {
1004
+ type: 'web_search_tool_result',
1005
+ tool_use_id: 'tu-1',
1006
+ content: [
1007
+ {
1008
+ type: 'web_search_result',
1009
+ url: 'https://example.com',
1010
+ title: 'Test',
1011
+ encrypted_index: 'x',
1012
+ },
1013
+ ],
1014
+ };
1015
+
1016
+ await handleServerToolResult({
1017
+ graph: graph as unknown as StandardGraph,
1018
+ content: [webSearchContent] as t.MessageContentComplex[],
1019
+ metadata: defaultMetadata,
1020
+ agentContext: anthropicContext,
1021
+ });
1022
+
1023
+ expect(graph.invokedToolIds).toBeInstanceOf(Set);
1024
+ expect(graph.invokedToolIds!.has('tu-1')).toBe(true);
1025
+ });
1026
+
1027
+ it('warns when web search content is not an array', async () => {
1028
+ graph.toolCallStepIds.set('tu-1', 'step-1');
1029
+ graph.getRunStep.mockReturnValue(
1030
+ makeRunStep(StepTypes.TOOL_CALLS, {
1031
+ tool_calls: [
1032
+ {
1033
+ id: 'tu-1',
1034
+ name: 'web_search',
1035
+ args: {},
1036
+ type: 'tool_call',
1037
+ } as t.AgentToolCall,
1038
+ ],
1039
+ })
1040
+ );
1041
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1042
+
1043
+ const webSearchContent: t.ToolResultContent = {
1044
+ type: 'web_search_result',
1045
+ tool_use_id: 'tu-1',
1046
+ content: 'not an array',
1047
+ };
1048
+
1049
+ const result = await handleServerToolResult({
1050
+ graph: graph as unknown as StandardGraph,
1051
+ content: [webSearchContent] as t.MessageContentComplex[],
1052
+ metadata: defaultMetadata,
1053
+ agentContext: anthropicContext,
1054
+ });
1055
+
1056
+ expect(result).toBe(true);
1057
+ expect(warnSpy).toHaveBeenCalledWith(
1058
+ expect.stringContaining('Expected content to be an array')
1059
+ );
1060
+ warnSpy.mockRestore();
1061
+ });
1062
+
1063
+ it('warns when content is not an Anthropic web search result', async () => {
1064
+ graph.toolCallStepIds.set('tu-1', 'step-1');
1065
+ graph.getRunStep.mockReturnValue(
1066
+ makeRunStep(StepTypes.TOOL_CALLS, {
1067
+ tool_calls: [
1068
+ {
1069
+ id: 'tu-1',
1070
+ name: 'web_search',
1071
+ args: {},
1072
+ type: 'tool_call',
1073
+ } as t.AgentToolCall,
1074
+ ],
1075
+ })
1076
+ );
1077
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1078
+
1079
+ const webSearchContent: t.ToolResultContent = {
1080
+ type: 'web_search_result',
1081
+ tool_use_id: 'tu-1',
1082
+ content: [{ type: 'text', text: 'not a search result' }],
1083
+ };
1084
+
1085
+ const result = await handleServerToolResult({
1086
+ graph: graph as unknown as StandardGraph,
1087
+ content: [webSearchContent] as t.MessageContentComplex[],
1088
+ metadata: defaultMetadata,
1089
+ agentContext: anthropicContext,
1090
+ });
1091
+
1092
+ expect(result).toBe(true);
1093
+ expect(warnSpy).toHaveBeenCalledWith(
1094
+ expect.stringContaining(
1095
+ 'Expected content to be an Anthropic web search result'
1096
+ )
1097
+ );
1098
+ warnSpy.mockRestore();
1099
+ });
1100
+ });