agentfootprint 10.3.1 → 10.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/AGENTS.md +2 -2
  2. package/CAPABILITIES.md +6 -0
  3. package/README.md +44 -0
  4. package/ai-instructions/claude-code/SKILL.md +2 -2
  5. package/dist/adapters/mcp/agentcoreRuntime/errorType.js +24 -0
  6. package/dist/adapters/mcp/agentcoreRuntime/errorType.js.map +1 -0
  7. package/dist/adapters/mcp/agentcoreRuntime/invoke.js +265 -0
  8. package/dist/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -0
  9. package/dist/adapters/mcp/agentcoreRuntime/safeAnswer.js +415 -0
  10. package/dist/adapters/mcp/agentcoreRuntime/safeAnswer.js.map +1 -0
  11. package/dist/adapters/mcp/agentcoreRuntime/session.js +179 -0
  12. package/dist/adapters/mcp/agentcoreRuntime/session.js.map +1 -0
  13. package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js +117 -0
  14. package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -0
  15. package/dist/adapters/mcp/agentcoreRuntime/strictJson.js +220 -0
  16. package/dist/adapters/mcp/agentcoreRuntime/strictJson.js.map +1 -0
  17. package/dist/adapters/mcp/agentcoreRuntime/transport.js +204 -0
  18. package/dist/adapters/mcp/agentcoreRuntime/transport.js.map +1 -0
  19. package/dist/adapters/memory/agentcore.js +435 -20
  20. package/dist/adapters/memory/agentcore.js.map +1 -1
  21. package/dist/adapters/memory/memoryBank.js +16 -3
  22. package/dist/adapters/memory/memoryBank.js.map +1 -1
  23. package/dist/adapters/memory/pgVector.js +10 -4
  24. package/dist/adapters/memory/pgVector.js.map +1 -1
  25. package/dist/adapters/memory/redis.js +11 -3
  26. package/dist/adapters/memory/redis.js.map +1 -1
  27. package/dist/adapters/memory/s3Vectors.js +8 -3
  28. package/dist/adapters/memory/s3Vectors.js.map +1 -1
  29. package/dist/adapters/memory/sqliteVector.js +10 -4
  30. package/dist/adapters/memory/sqliteVector.js.map +1 -1
  31. package/dist/ag-ui/adapter.js +71 -0
  32. package/dist/ag-ui/adapter.js.map +1 -0
  33. package/dist/ag-ui/framing.js +66 -0
  34. package/dist/ag-ui/framing.js.map +1 -0
  35. package/dist/ag-ui/frontendTools.js +69 -0
  36. package/dist/ag-ui/frontendTools.js.map +1 -0
  37. package/dist/ag-ui/ids.js +54 -0
  38. package/dist/ag-ui/ids.js.map +1 -0
  39. package/dist/ag-ui/index.js +27 -0
  40. package/dist/ag-ui/index.js.map +1 -0
  41. package/dist/ag-ui/request.js +356 -0
  42. package/dist/ag-ui/request.js.map +1 -0
  43. package/dist/ag-ui/serializer.js +899 -0
  44. package/dist/ag-ui/serializer.js.map +1 -0
  45. package/dist/ag-ui/types.js +22 -0
  46. package/dist/ag-ui/types.js.map +1 -0
  47. package/dist/core/Agent.js +38 -5
  48. package/dist/core/Agent.js.map +1 -1
  49. package/dist/core/RunnerBase.js +16 -2
  50. package/dist/core/RunnerBase.js.map +1 -1
  51. package/dist/core/agent/buildAgentChart.js +4 -0
  52. package/dist/core/agent/buildAgentChart.js.map +1 -1
  53. package/dist/core/agent/buildDynamicAgentChart.js +4 -0
  54. package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
  55. package/dist/core/agent/callerIdentity.js +2 -1
  56. package/dist/core/agent/callerIdentity.js.map +1 -1
  57. package/dist/core/agent/stages/routeTurn.js +3 -3
  58. package/dist/core/agent/stages/routeTurn.js.map +1 -1
  59. package/dist/core/agent/stages/seed.js +49 -8
  60. package/dist/core/agent/stages/seed.js.map +1 -1
  61. package/dist/core/agent/stages/timeLayer.js +2 -2
  62. package/dist/core/agent/stages/timeLayer.js.map +1 -1
  63. package/dist/core/agent/stages/toolCalls.js +26 -5
  64. package/dist/core/agent/stages/toolCalls.js.map +1 -1
  65. package/dist/core/memberRun.js +244 -0
  66. package/dist/core/memberRun.js.map +1 -0
  67. package/dist/core/slots/buildToolsSlot.js +1 -1
  68. package/dist/core/slots/buildToolsSlot.js.map +1 -1
  69. package/dist/core-flow/Conditional.js +29 -8
  70. package/dist/core-flow/Conditional.js.map +1 -1
  71. package/dist/core-flow/Graph.js +38 -13
  72. package/dist/core-flow/Graph.js.map +1 -1
  73. package/dist/core-flow/Loop.js +29 -9
  74. package/dist/core-flow/Loop.js.map +1 -1
  75. package/dist/core-flow/Parallel.js +35 -14
  76. package/dist/core-flow/Parallel.js.map +1 -1
  77. package/dist/core-flow/Sequence.js +29 -8
  78. package/dist/core-flow/Sequence.js.map +1 -1
  79. package/dist/core-flow/Workflow.js +34 -10
  80. package/dist/core-flow/Workflow.js.map +1 -1
  81. package/dist/doors/ag-ui.js +36 -0
  82. package/dist/doors/ag-ui.js.map +1 -0
  83. package/dist/esm/adapters/mcp/agentcoreRuntime/errorType.d.ts +12 -0
  84. package/dist/esm/adapters/mcp/agentcoreRuntime/errorType.js +20 -0
  85. package/dist/esm/adapters/mcp/agentcoreRuntime/errorType.js.map +1 -0
  86. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.d.ts +116 -0
  87. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js +260 -0
  88. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -0
  89. package/dist/esm/adapters/mcp/agentcoreRuntime/safeAnswer.d.ts +49 -0
  90. package/dist/esm/adapters/mcp/agentcoreRuntime/safeAnswer.js +409 -0
  91. package/dist/esm/adapters/mcp/agentcoreRuntime/safeAnswer.js.map +1 -0
  92. package/dist/esm/adapters/mcp/agentcoreRuntime/session.d.ts +80 -0
  93. package/dist/esm/adapters/mcp/agentcoreRuntime/session.js +175 -0
  94. package/dist/esm/adapters/mcp/agentcoreRuntime/session.js.map +1 -0
  95. package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +61 -0
  96. package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js +112 -0
  97. package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -0
  98. package/dist/esm/adapters/mcp/agentcoreRuntime/strictJson.d.ts +37 -0
  99. package/dist/esm/adapters/mcp/agentcoreRuntime/strictJson.js +215 -0
  100. package/dist/esm/adapters/mcp/agentcoreRuntime/strictJson.js.map +1 -0
  101. package/dist/esm/adapters/mcp/agentcoreRuntime/transport.d.ts +176 -0
  102. package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js +199 -0
  103. package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js.map +1 -0
  104. package/dist/esm/adapters/memory/agentcore.d.ts +152 -7
  105. package/dist/esm/adapters/memory/agentcore.js +433 -19
  106. package/dist/esm/adapters/memory/agentcore.js.map +1 -1
  107. package/dist/esm/adapters/memory/memoryBank.d.ts +3 -2
  108. package/dist/esm/adapters/memory/memoryBank.js +16 -3
  109. package/dist/esm/adapters/memory/memoryBank.js.map +1 -1
  110. package/dist/esm/adapters/memory/pgVector.js +10 -4
  111. package/dist/esm/adapters/memory/pgVector.js.map +1 -1
  112. package/dist/esm/adapters/memory/redis.d.ts +8 -3
  113. package/dist/esm/adapters/memory/redis.js +11 -3
  114. package/dist/esm/adapters/memory/redis.js.map +1 -1
  115. package/dist/esm/adapters/memory/s3Vectors.js +8 -3
  116. package/dist/esm/adapters/memory/s3Vectors.js.map +1 -1
  117. package/dist/esm/adapters/memory/sqliteVector.js +10 -4
  118. package/dist/esm/adapters/memory/sqliteVector.js.map +1 -1
  119. package/dist/esm/ag-ui/adapter.d.ts +68 -0
  120. package/dist/esm/ag-ui/adapter.js +67 -0
  121. package/dist/esm/ag-ui/adapter.js.map +1 -0
  122. package/dist/esm/ag-ui/framing.d.ts +51 -0
  123. package/dist/esm/ag-ui/framing.js +62 -0
  124. package/dist/esm/ag-ui/framing.js.map +1 -0
  125. package/dist/esm/ag-ui/frontendTools.d.ts +37 -0
  126. package/dist/esm/ag-ui/frontendTools.js +64 -0
  127. package/dist/esm/ag-ui/frontendTools.js.map +1 -0
  128. package/dist/esm/ag-ui/ids.d.ts +43 -0
  129. package/dist/esm/ag-ui/ids.js +49 -0
  130. package/dist/esm/ag-ui/ids.js.map +1 -0
  131. package/dist/esm/ag-ui/index.d.ts +17 -0
  132. package/dist/esm/ag-ui/index.js +17 -0
  133. package/dist/esm/ag-ui/index.js.map +1 -0
  134. package/dist/esm/ag-ui/request.d.ts +72 -0
  135. package/dist/esm/ag-ui/request.js +350 -0
  136. package/dist/esm/ag-ui/request.js.map +1 -0
  137. package/dist/esm/ag-ui/serializer.d.ts +173 -0
  138. package/dist/esm/ag-ui/serializer.js +895 -0
  139. package/dist/esm/ag-ui/serializer.js.map +1 -0
  140. package/dist/esm/ag-ui/types.d.ts +305 -0
  141. package/dist/esm/ag-ui/types.js +19 -0
  142. package/dist/esm/ag-ui/types.js.map +1 -0
  143. package/dist/esm/core/Agent.d.ts +2 -0
  144. package/dist/esm/core/Agent.js +38 -5
  145. package/dist/esm/core/Agent.js.map +1 -1
  146. package/dist/esm/core/RunnerBase.js +17 -3
  147. package/dist/esm/core/RunnerBase.js.map +1 -1
  148. package/dist/esm/core/agent/buildAgentChart.js +4 -0
  149. package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
  150. package/dist/esm/core/agent/buildDynamicAgentChart.js +4 -0
  151. package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
  152. package/dist/esm/core/agent/callerIdentity.js +2 -1
  153. package/dist/esm/core/agent/callerIdentity.js.map +1 -1
  154. package/dist/esm/core/agent/stages/routeTurn.d.ts +1 -1
  155. package/dist/esm/core/agent/stages/routeTurn.js +3 -3
  156. package/dist/esm/core/agent/stages/routeTurn.js.map +1 -1
  157. package/dist/esm/core/agent/stages/seed.d.ts +11 -1
  158. package/dist/esm/core/agent/stages/seed.js +49 -8
  159. package/dist/esm/core/agent/stages/seed.js.map +1 -1
  160. package/dist/esm/core/agent/stages/timeLayer.js +2 -2
  161. package/dist/esm/core/agent/stages/timeLayer.js.map +1 -1
  162. package/dist/esm/core/agent/stages/toolCalls.d.ts +11 -1
  163. package/dist/esm/core/agent/stages/toolCalls.js +26 -5
  164. package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
  165. package/dist/esm/core/agent/types.d.ts +16 -6
  166. package/dist/esm/core/memberRun.d.ts +132 -0
  167. package/dist/esm/core/memberRun.js +227 -0
  168. package/dist/esm/core/memberRun.js.map +1 -0
  169. package/dist/esm/core/slots/buildToolsSlot.d.ts +1 -1
  170. package/dist/esm/core/slots/buildToolsSlot.js +1 -1
  171. package/dist/esm/core/slots/buildToolsSlot.js.map +1 -1
  172. package/dist/esm/core-flow/Conditional.d.ts +8 -0
  173. package/dist/esm/core-flow/Conditional.js +29 -8
  174. package/dist/esm/core-flow/Conditional.js.map +1 -1
  175. package/dist/esm/core-flow/Graph.js +38 -13
  176. package/dist/esm/core-flow/Graph.js.map +1 -1
  177. package/dist/esm/core-flow/Loop.d.ts +8 -0
  178. package/dist/esm/core-flow/Loop.js +29 -9
  179. package/dist/esm/core-flow/Loop.js.map +1 -1
  180. package/dist/esm/core-flow/Parallel.d.ts +8 -0
  181. package/dist/esm/core-flow/Parallel.js +35 -14
  182. package/dist/esm/core-flow/Parallel.js.map +1 -1
  183. package/dist/esm/core-flow/Sequence.d.ts +8 -0
  184. package/dist/esm/core-flow/Sequence.js +29 -8
  185. package/dist/esm/core-flow/Sequence.js.map +1 -1
  186. package/dist/esm/core-flow/Workflow.js +34 -10
  187. package/dist/esm/core-flow/Workflow.js.map +1 -1
  188. package/dist/esm/doors/ag-ui.d.ts +19 -0
  189. package/dist/esm/doors/ag-ui.js +20 -0
  190. package/dist/esm/doors/ag-ui.js.map +1 -0
  191. package/dist/esm/hosting/envelope.js +5 -0
  192. package/dist/esm/hosting/envelope.js.map +1 -1
  193. package/dist/esm/hosting/httpHost.js +5 -78
  194. package/dist/esm/hosting/httpHost.js.map +1 -1
  195. package/dist/esm/hosting/index.d.ts +4 -1
  196. package/dist/esm/hosting/index.js +2 -0
  197. package/dist/esm/hosting/index.js.map +1 -1
  198. package/dist/esm/hosting/pendingAsk.d.ts +19 -0
  199. package/dist/esm/hosting/pendingAsk.js +38 -0
  200. package/dist/esm/hosting/pendingAsk.js.map +1 -0
  201. package/dist/esm/hosting/protocolAdapter.d.ts +229 -0
  202. package/dist/esm/hosting/protocolAdapter.js +23 -0
  203. package/dist/esm/hosting/protocolAdapter.js.map +1 -0
  204. package/dist/esm/hosting/refusalStatus.d.ts +30 -0
  205. package/dist/esm/hosting/refusalStatus.js +81 -0
  206. package/dist/esm/hosting/refusalStatus.js.map +1 -0
  207. package/dist/esm/hosting/standingAgent.js +1 -31
  208. package/dist/esm/hosting/standingAgent.js.map +1 -1
  209. package/dist/esm/hosting/stream.d.ts +39 -0
  210. package/dist/esm/hosting/stream.js +34 -2
  211. package/dist/esm/hosting/stream.js.map +1 -1
  212. package/dist/esm/hosting/streamHandler.d.ts +134 -0
  213. package/dist/esm/hosting/streamHandler.js +493 -0
  214. package/dist/esm/hosting/streamHandler.js.map +1 -0
  215. package/dist/esm/hosting/types.d.ts +15 -0
  216. package/dist/esm/hosting/types.js.map +1 -1
  217. package/dist/esm/hosting/verifiedThreads.d.ts +29 -0
  218. package/dist/esm/hosting/verifiedThreads.js +46 -0
  219. package/dist/esm/hosting/verifiedThreads.js.map +1 -0
  220. package/dist/esm/index.d.ts +1 -0
  221. package/dist/esm/index.js +3 -0
  222. package/dist/esm/index.js.map +1 -1
  223. package/dist/esm/lib/humanizeLLMError.d.ts +15 -0
  224. package/dist/esm/lib/humanizeLLMError.js +22 -7
  225. package/dist/esm/lib/humanizeLLMError.js.map +1 -1
  226. package/dist/esm/mcp/throttleRetry.d.ts +51 -0
  227. package/dist/esm/mcp/throttleRetry.js +37 -4
  228. package/dist/esm/mcp/throttleRetry.js.map +1 -1
  229. package/dist/esm/memory/define.js +45 -1
  230. package/dist/esm/memory/define.js.map +1 -1
  231. package/dist/esm/memory/define.types.d.ts +24 -0
  232. package/dist/esm/memory/define.types.js.map +1 -1
  233. package/dist/esm/memory/stages/formatDefault.js +3 -1
  234. package/dist/esm/memory/stages/formatDefault.js.map +1 -1
  235. package/dist/esm/memory/store/InMemoryStore.d.ts +8 -3
  236. package/dist/esm/memory/store/InMemoryStore.js +12 -3
  237. package/dist/esm/memory/store/InMemoryStore.js.map +1 -1
  238. package/dist/esm/memory/store/index.d.ts +1 -0
  239. package/dist/esm/memory/store/index.js +5 -0
  240. package/dist/esm/memory/store/index.js.map +1 -1
  241. package/dist/esm/memory/store/types.d.ts +38 -4
  242. package/dist/esm/memory/store/writeOptions.d.ts +118 -0
  243. package/dist/esm/memory/store/writeOptions.js +242 -0
  244. package/dist/esm/memory/store/writeOptions.js.map +1 -0
  245. package/dist/esm/memory-providers.d.ts +1 -1
  246. package/dist/esm/memory-providers.js +4 -1
  247. package/dist/esm/memory-providers.js.map +1 -1
  248. package/dist/esm/patterns/MapReduce.js +8 -2
  249. package/dist/esm/patterns/MapReduce.js.map +1 -1
  250. package/dist/esm/tool-providers/index.d.ts +5 -0
  251. package/dist/esm/tool-providers/index.js +6 -0
  252. package/dist/esm/tool-providers/index.js.map +1 -1
  253. package/dist/esm/trace-toolpack/selfExplain.d.ts +8 -0
  254. package/dist/esm/trace-toolpack/selfExplain.js +25 -2
  255. package/dist/esm/trace-toolpack/selfExplain.js.map +1 -1
  256. package/dist/hosting/envelope.js +5 -0
  257. package/dist/hosting/envelope.js.map +1 -1
  258. package/dist/hosting/httpHost.js +5 -78
  259. package/dist/hosting/httpHost.js.map +1 -1
  260. package/dist/hosting/index.js +9 -3
  261. package/dist/hosting/index.js.map +1 -1
  262. package/dist/hosting/pendingAsk.js +42 -0
  263. package/dist/hosting/pendingAsk.js.map +1 -0
  264. package/dist/hosting/protocolAdapter.js +24 -0
  265. package/dist/hosting/protocolAdapter.js.map +1 -0
  266. package/dist/hosting/refusalStatus.js +84 -0
  267. package/dist/hosting/refusalStatus.js.map +1 -0
  268. package/dist/hosting/standingAgent.js +2 -32
  269. package/dist/hosting/standingAgent.js.map +1 -1
  270. package/dist/hosting/stream.js +35 -3
  271. package/dist/hosting/stream.js.map +1 -1
  272. package/dist/hosting/streamHandler.js +497 -0
  273. package/dist/hosting/streamHandler.js.map +1 -0
  274. package/dist/hosting/types.js.map +1 -1
  275. package/dist/hosting/verifiedThreads.js +50 -0
  276. package/dist/hosting/verifiedThreads.js.map +1 -0
  277. package/dist/index.js +9 -3
  278. package/dist/index.js.map +1 -1
  279. package/dist/lib/humanizeLLMError.js +23 -8
  280. package/dist/lib/humanizeLLMError.js.map +1 -1
  281. package/dist/mcp/throttleRetry.js +41 -6
  282. package/dist/mcp/throttleRetry.js.map +1 -1
  283. package/dist/memory/define.js +45 -1
  284. package/dist/memory/define.js.map +1 -1
  285. package/dist/memory/define.types.js.map +1 -1
  286. package/dist/memory/stages/formatDefault.js +3 -1
  287. package/dist/memory/stages/formatDefault.js.map +1 -1
  288. package/dist/memory/store/InMemoryStore.js +12 -3
  289. package/dist/memory/store/InMemoryStore.js.map +1 -1
  290. package/dist/memory/store/index.js +11 -1
  291. package/dist/memory/store/index.js.map +1 -1
  292. package/dist/memory/store/writeOptions.js +250 -0
  293. package/dist/memory/store/writeOptions.js.map +1 -0
  294. package/dist/memory-providers.js +4 -1
  295. package/dist/memory-providers.js.map +1 -1
  296. package/dist/patterns/MapReduce.js +8 -2
  297. package/dist/patterns/MapReduce.js.map +1 -1
  298. package/dist/tool-providers/index.js +10 -1
  299. package/dist/tool-providers/index.js.map +1 -1
  300. package/dist/trace-toolpack/selfExplain.js +25 -2
  301. package/dist/trace-toolpack/selfExplain.js.map +1 -1
  302. package/dist/types/adapters/mcp/agentcoreRuntime/errorType.d.ts +13 -0
  303. package/dist/types/adapters/mcp/agentcoreRuntime/errorType.d.ts.map +1 -0
  304. package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts +117 -0
  305. package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts.map +1 -0
  306. package/dist/types/adapters/mcp/agentcoreRuntime/safeAnswer.d.ts +50 -0
  307. package/dist/types/adapters/mcp/agentcoreRuntime/safeAnswer.d.ts.map +1 -0
  308. package/dist/types/adapters/mcp/agentcoreRuntime/session.d.ts +81 -0
  309. package/dist/types/adapters/mcp/agentcoreRuntime/session.d.ts.map +1 -0
  310. package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +62 -0
  311. package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts.map +1 -0
  312. package/dist/types/adapters/mcp/agentcoreRuntime/strictJson.d.ts +38 -0
  313. package/dist/types/adapters/mcp/agentcoreRuntime/strictJson.d.ts.map +1 -0
  314. package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts +177 -0
  315. package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts.map +1 -0
  316. package/dist/types/adapters/memory/agentcore.d.ts +152 -7
  317. package/dist/types/adapters/memory/agentcore.d.ts.map +1 -1
  318. package/dist/types/adapters/memory/memoryBank.d.ts +3 -2
  319. package/dist/types/adapters/memory/memoryBank.d.ts.map +1 -1
  320. package/dist/types/adapters/memory/pgVector.d.ts.map +1 -1
  321. package/dist/types/adapters/memory/redis.d.ts +8 -3
  322. package/dist/types/adapters/memory/redis.d.ts.map +1 -1
  323. package/dist/types/adapters/memory/s3Vectors.d.ts.map +1 -1
  324. package/dist/types/adapters/memory/sqliteVector.d.ts.map +1 -1
  325. package/dist/types/ag-ui/adapter.d.ts +69 -0
  326. package/dist/types/ag-ui/adapter.d.ts.map +1 -0
  327. package/dist/types/ag-ui/framing.d.ts +52 -0
  328. package/dist/types/ag-ui/framing.d.ts.map +1 -0
  329. package/dist/types/ag-ui/frontendTools.d.ts +38 -0
  330. package/dist/types/ag-ui/frontendTools.d.ts.map +1 -0
  331. package/dist/types/ag-ui/ids.d.ts +44 -0
  332. package/dist/types/ag-ui/ids.d.ts.map +1 -0
  333. package/dist/types/ag-ui/index.d.ts +18 -0
  334. package/dist/types/ag-ui/index.d.ts.map +1 -0
  335. package/dist/types/ag-ui/request.d.ts +73 -0
  336. package/dist/types/ag-ui/request.d.ts.map +1 -0
  337. package/dist/types/ag-ui/serializer.d.ts +174 -0
  338. package/dist/types/ag-ui/serializer.d.ts.map +1 -0
  339. package/dist/types/ag-ui/types.d.ts +306 -0
  340. package/dist/types/ag-ui/types.d.ts.map +1 -0
  341. package/dist/types/core/Agent.d.ts +2 -0
  342. package/dist/types/core/Agent.d.ts.map +1 -1
  343. package/dist/types/core/RunnerBase.d.ts.map +1 -1
  344. package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
  345. package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
  346. package/dist/types/core/agent/callerIdentity.d.ts.map +1 -1
  347. package/dist/types/core/agent/stages/routeTurn.d.ts +1 -1
  348. package/dist/types/core/agent/stages/routeTurn.d.ts.map +1 -1
  349. package/dist/types/core/agent/stages/seed.d.ts +11 -1
  350. package/dist/types/core/agent/stages/seed.d.ts.map +1 -1
  351. package/dist/types/core/agent/stages/toolCalls.d.ts +11 -1
  352. package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
  353. package/dist/types/core/agent/types.d.ts +16 -6
  354. package/dist/types/core/agent/types.d.ts.map +1 -1
  355. package/dist/types/core/memberRun.d.ts +133 -0
  356. package/dist/types/core/memberRun.d.ts.map +1 -0
  357. package/dist/types/core/slots/buildToolsSlot.d.ts +1 -1
  358. package/dist/types/core/slots/buildToolsSlot.d.ts.map +1 -1
  359. package/dist/types/core-flow/Conditional.d.ts +8 -0
  360. package/dist/types/core-flow/Conditional.d.ts.map +1 -1
  361. package/dist/types/core-flow/Graph.d.ts.map +1 -1
  362. package/dist/types/core-flow/Loop.d.ts +8 -0
  363. package/dist/types/core-flow/Loop.d.ts.map +1 -1
  364. package/dist/types/core-flow/Parallel.d.ts +8 -0
  365. package/dist/types/core-flow/Parallel.d.ts.map +1 -1
  366. package/dist/types/core-flow/Sequence.d.ts +8 -0
  367. package/dist/types/core-flow/Sequence.d.ts.map +1 -1
  368. package/dist/types/core-flow/Workflow.d.ts.map +1 -1
  369. package/dist/types/doors/ag-ui.d.ts +20 -0
  370. package/dist/types/doors/ag-ui.d.ts.map +1 -0
  371. package/dist/types/hosting/httpHost.d.ts.map +1 -1
  372. package/dist/types/hosting/index.d.ts +4 -1
  373. package/dist/types/hosting/index.d.ts.map +1 -1
  374. package/dist/types/hosting/pendingAsk.d.ts +20 -0
  375. package/dist/types/hosting/pendingAsk.d.ts.map +1 -0
  376. package/dist/types/hosting/protocolAdapter.d.ts +230 -0
  377. package/dist/types/hosting/protocolAdapter.d.ts.map +1 -0
  378. package/dist/types/hosting/refusalStatus.d.ts +31 -0
  379. package/dist/types/hosting/refusalStatus.d.ts.map +1 -0
  380. package/dist/types/hosting/standingAgent.d.ts.map +1 -1
  381. package/dist/types/hosting/stream.d.ts +39 -0
  382. package/dist/types/hosting/stream.d.ts.map +1 -1
  383. package/dist/types/hosting/streamHandler.d.ts +135 -0
  384. package/dist/types/hosting/streamHandler.d.ts.map +1 -0
  385. package/dist/types/hosting/types.d.ts +15 -0
  386. package/dist/types/hosting/types.d.ts.map +1 -1
  387. package/dist/types/hosting/verifiedThreads.d.ts +30 -0
  388. package/dist/types/hosting/verifiedThreads.d.ts.map +1 -0
  389. package/dist/types/index.d.ts +1 -0
  390. package/dist/types/index.d.ts.map +1 -1
  391. package/dist/types/lib/humanizeLLMError.d.ts +15 -0
  392. package/dist/types/lib/humanizeLLMError.d.ts.map +1 -1
  393. package/dist/types/mcp/throttleRetry.d.ts +51 -0
  394. package/dist/types/mcp/throttleRetry.d.ts.map +1 -1
  395. package/dist/types/memory/define.d.ts.map +1 -1
  396. package/dist/types/memory/define.types.d.ts +24 -0
  397. package/dist/types/memory/define.types.d.ts.map +1 -1
  398. package/dist/types/memory/stages/formatDefault.d.ts.map +1 -1
  399. package/dist/types/memory/store/InMemoryStore.d.ts +8 -3
  400. package/dist/types/memory/store/InMemoryStore.d.ts.map +1 -1
  401. package/dist/types/memory/store/index.d.ts +1 -0
  402. package/dist/types/memory/store/index.d.ts.map +1 -1
  403. package/dist/types/memory/store/types.d.ts +38 -4
  404. package/dist/types/memory/store/types.d.ts.map +1 -1
  405. package/dist/types/memory/store/writeOptions.d.ts +119 -0
  406. package/dist/types/memory/store/writeOptions.d.ts.map +1 -0
  407. package/dist/types/memory-providers.d.ts +1 -1
  408. package/dist/types/memory-providers.d.ts.map +1 -1
  409. package/dist/types/patterns/MapReduce.d.ts.map +1 -1
  410. package/dist/types/tool-providers/index.d.ts +5 -0
  411. package/dist/types/tool-providers/index.d.ts.map +1 -1
  412. package/dist/types/trace-toolpack/selfExplain.d.ts +8 -0
  413. package/dist/types/trace-toolpack/selfExplain.d.ts.map +1 -1
  414. package/package.json +25 -1
@@ -0,0 +1,895 @@
1
+ /**
2
+ * serializer — one run's served agentfootprint events → AG-UI events.
3
+ *
4
+ * Pattern: a per-run state machine (`RunTranslation`), pure — no I/O, no clock,
5
+ * no import of `@ag-ui/*`. Frames are the framing strategy's job
6
+ * (`framing.ts`); reading a request is the adapter's (`adapter.ts`).
7
+ * Role: the Lens over a run for an AG-UI reader. It composes what that reader
8
+ * is served, from the RECORD only: every value it writes comes from a
9
+ * served event (the placeholder wherever a redaction policy selected a
10
+ * value), from the record's address (`meta.runtimeStageId`,
11
+ * `meta.subflowPath` — never selected by a policy), or from the
12
+ * AG-UI request's own ids. It never reads the run's live values, so
13
+ * nothing a policy hides can reach an AG-UI event. The record's own
14
+ * run id is never written: it counts every run the process made.
15
+ *
16
+ * THE MAPPING
17
+ * agent.turn_start (nested) → SUBAGENT_STARTED (a sub-agent's turn)
18
+ * agent.turn_end → SUBAGENT_FINISHED / the root answer
19
+ * agent.iteration_start/_end → STEP_STARTED/_FINISHED `iteration <n>`
20
+ * composition.enter/exit → STEP_STARTED/_FINISHED `<Kind>[:<mount>]`
21
+ * stream.token → TEXT_MESSAGE_START/CONTENT/END
22
+ * stream.llm_end (no agent around) → one whole TEXT message (an LLM call that streams nothing)
23
+ * stream.thinking_delta/_end → REASONING_START … REASONING_END (only with `reasoning: true`)
24
+ * stream.tool_start → TOOL_CALL_START + TOOL_CALL_ARGS + TOOL_CALL_END
25
+ * stream.tool_end → TOOL_CALL_RESULT
26
+ * pause.request + settle('paused') → RUN_FINISHED { outcome: interrupt }
27
+ * settle('paused', awaiting caller) → RUN_FINISHED { outcome: success, pendingToolCallIds }
28
+ * (a tool the client runs: its call is left to answer)
29
+ * error.fatal + settle('failed') → RUN_ERROR — the served error.fatal's words when they
30
+ * are a fixed sentence, else "The run failed."
31
+ * an allow-listed event → CUSTOM { name: <event type>, value: <its listed fields> }
32
+ * anything else → nothing
33
+ *
34
+ * WHAT LEAVES THE PROCESS. An AG-UI stream goes to a browser, so nothing goes
35
+ * out by default that a person is not meant to read. Every value comes from a
36
+ * served payload; `CUSTOM` carries only the event types on an allow-list, each
37
+ * with the fields its projection picks ({@link AG_UI_CUSTOM_EVENTS} — the whole
38
+ * record, such as `context.injected`'s assembled prompt or `error.retried`'s
39
+ * raw error, stays off the wire unless the app lists it); the model's
40
+ * reasoning goes out only when the app says so; and a failure is described by
41
+ * the record, never by the thrown value. Identity on the meta (`principal`,
42
+ * `tenant`, `sessionId`) is never written.
43
+ *
44
+ * WHO OWNS AN EVENT. Each agent's turn opens a SCOPE at its mount — the
45
+ * subflow path its `turn_start` fired at (`[]` for the root agent, `step-p/x`
46
+ * for an agent in a parallel branch). An event belongs to the deepest open scope
47
+ * whose mount prefixes its own subflow path, segment by segment, and carries
48
+ * that scope's `subagentRunId`. Parallel branches have different mounts, so
49
+ * their interleaved events can never be attributed to each other.
50
+ *
51
+ * A RUN THAT CONTINUES A PAUSE. A paused run hands back `suspension()` — the
52
+ * ids it gave the client (the interrupt, the open call) and every scope and
53
+ * step open at the pause. The run that continues it passes that as `resume`:
54
+ * the same sub-agents re-open (AG-UI: "a later run may continue the same
55
+ * invocation"), their steps re-open, and the first result in the paused call's
56
+ * scope answers that call under its own id — or, for a tool the client ran, is
57
+ * not written at all, because the client holds the result it sent.
58
+ *
59
+ * TEXT. The reply is what the record streamed (`stream.token`) — the channel
60
+ * `toSSE({ format: 'text' })` and a hosted reply read. An agent turn whose
61
+ * answer streamed no token (a provider without `stream()`) is written whole
62
+ * from `turn_end.finalContent`, unless the record marks it refused. An
63
+ * agent's `llm_end.content` is a DRAFT the library may be holding back
64
+ * (answer validation, an output policy) and is never written.
65
+ */
66
+ import { CONSUMER_SCOPE_RUN_ID } from '../bridge/eventMeta.js';
67
+ import { LLM_ERROR_SENTENCES } from '../lib/humanizeLLMError.js';
68
+ import { toWireJson, withWireErrors } from '../lib/wireJson.js';
69
+ import { agUiIdMinter } from './ids.js';
70
+ import { AG_UI_PROTOCOL_VERSION, } from './types.js';
71
+ /** The listed fields of `payload`, where present. */
72
+ const pick = (payload, fields) => {
73
+ const out = {};
74
+ for (const field of fields)
75
+ if (payload[field] !== undefined)
76
+ out[field] = payload[field];
77
+ return out;
78
+ };
79
+ /**
80
+ * The agentfootprint events that go out as AG-UI `CUSTOM` by default, each with
81
+ * the fields it carries: progress (which call, which iteration), spend, the
82
+ * loop's route, the answer's standing and a provider's retries — counts and the
83
+ * library's own words. Content (a tool's own progress `payload`,
84
+ * `context.injected`'s assembled prompt, `error.retried`'s raw error, memory,
85
+ * permission and credential facts) stays off the wire unless an app lists it:
86
+ * `agUiSerializer({ ..., custom: { ...AG_UI_CUSTOM_EVENTS, [type]: projection } })`.
87
+ */
88
+ export const AG_UI_CUSTOM_EVENTS = Object.freeze({
89
+ // Which call and which iteration — never the tool author's `payload`, which
90
+ // is whatever the tool chose to report (list it to send it).
91
+ 'agentfootprint.stream.tool_progress': (payload, at) => ({
92
+ ...(at.toolCallId !== undefined && { toolCallId: at.toolCallId }),
93
+ ...pick(payload, ['iteration']),
94
+ }),
95
+ 'agentfootprint.cost.tick': (payload) => pick(payload, [
96
+ 'scope',
97
+ 'model',
98
+ 'provider',
99
+ 'tokensInput',
100
+ 'tokensOutput',
101
+ 'estimatedUsd',
102
+ 'cumulative',
103
+ ]),
104
+ 'agentfootprint.agent.route_decided': (payload) => pick(payload, ['iterIndex', 'chosen']),
105
+ 'agentfootprint.answer.assessed': (payload) => pick(payload, ['standing', 'assessment', 'reasons', 'checked', 'turn', 'iteration']),
106
+ 'agentfootprint.error.retried': (payload) => pick(payload, ['attempt', 'maxAttempts', 'backoffMs', 'statedWaitMs']),
107
+ 'agentfootprint.error.recovered': (payload) => pick(payload, ['attempt', 'totalDurationMs']),
108
+ });
109
+ /** Said by `TOOL_CALL_RESULT` for a failed call, unless `toolErrors: 'served'`. */
110
+ export const AG_UI_TOOL_FAILED = 'The tool failed.';
111
+ /** Said by `RUN_ERROR` when the run's `error.fatal` is not one of the record's fixed sentences. */
112
+ export const AG_UI_RUN_FAILED = 'The run failed.';
113
+ /** Is `said` one of the record's fixed failure sentences — the only `error.fatal` words a `RUN_ERROR` repeats? */
114
+ const isFixedFailure = (said) => Object.values(LLM_ERROR_SENTENCES).includes(said);
115
+ /** Said by `SUBAGENT_ERROR` for a sub-agent whose turn ended without an answer. */
116
+ export const AG_UI_SUBAGENT_UNFINISHED = "The sub-agent's turn ended without an answer.";
117
+ /** Said by `SUBAGENT_ERROR` for a sub-agent still running when its run was cancelled. */
118
+ export const AG_UI_SUBAGENT_CANCELLED = 'The run was cancelled before this sub-agent finished.';
119
+ const newScope = (mount, subagentRunId, name, parentSubagentRunId) => ({
120
+ mount,
121
+ subagentRunId,
122
+ ...(name !== undefined && { name }),
123
+ ...(parentSubagentRunId !== undefined && { parentSubagentRunId }),
124
+ llmAddress: undefined,
125
+ isAgent: false,
126
+ text: undefined,
127
+ callMessageId: undefined,
128
+ streamed: false,
129
+ reasoning: undefined,
130
+ steps: [],
131
+ calls: [],
132
+ });
133
+ /** Does `prefix` lead `path`, segment by segment? */
134
+ function leads(prefix, path) {
135
+ if (prefix.length > path.length)
136
+ return false;
137
+ for (let i = 0; i < prefix.length; i++)
138
+ if (prefix[i] !== path[i])
139
+ return false;
140
+ return true;
141
+ }
142
+ const sameMount = (a, b) => a.length === b.length && leads(a, b);
143
+ const record = (value) => typeof value === 'object' && value !== null ? value : {};
144
+ const text = (value) => typeof value === 'string' ? value : undefined;
145
+ /** A tool result as AG-UI text: a string as it is, anything else through the wire rule. */
146
+ const resultText = (value) => typeof value === 'string' ? value : value === undefined ? '' : toWireJson(value);
147
+ /**
148
+ * The AG-UI serializer for ONE run: feed it every served agentfootprint event
149
+ * of the run, in order, then settle it once. `RUN_STARTED` comes before the
150
+ * first event it returns; `RUN_FINISHED` or `RUN_ERROR` is the last thing
151
+ * `settle` returns, with everything still open closed before it.
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * const ag = agUiSerializer({ threadId, runId });
156
+ * const off = agent.on('*', (event) => send(ag.event(event)));
157
+ * try {
158
+ * const out = await agent.run({ message });
159
+ * send(ag.settle({ kind: isPaused(out) ? 'paused' : 'finished' }));
160
+ * } catch {
161
+ * send(ag.settle({ kind: 'failed' })); // described by the record, never by the thrown value
162
+ * } finally {
163
+ * off();
164
+ * }
165
+ * ```
166
+ */
167
+ export function agUiSerializer(options) {
168
+ const { threadId, runId } = options;
169
+ if (typeof threadId !== 'string' || threadId.length === 0) {
170
+ throw new TypeError('AG-UI: `threadId` must be a non-empty string.');
171
+ }
172
+ const ids = agUiIdMinter(runId);
173
+ const custom = options.custom ?? AG_UI_CUSTOM_EVENTS;
174
+ const reasoning = options.reasoning === true;
175
+ const owns = options.owns;
176
+ const toolErrors = options.toolErrors ?? 'withheld';
177
+ const root = newScope([], undefined);
178
+ /** Open scopes — the root always, then each nested agent turn in open order. */
179
+ const scopes = [root];
180
+ let started = false;
181
+ let settled = false;
182
+ /**
183
+ * The run the events name, once one did — how a translation without `owns`
184
+ * keeps to one run. Never written: the library's run ids count every run the
185
+ * PROCESS made, and a browser must not learn how many other callers ran.
186
+ */
187
+ let recordRunId;
188
+ /** The record's own words for a failure — the last served `error.fatal`. */
189
+ let fatal;
190
+ let pause;
191
+ /** The root agent's answer as the record serves it — `RUN_FINISHED.result`. */
192
+ let rootResult;
193
+ /** What a continuation needs — set when the run settles paused. */
194
+ let suspended;
195
+ const scopeOf = (path) => {
196
+ let best = root;
197
+ for (const scope of scopes) {
198
+ if (scope.mount.length > best.mount.length && leads(scope.mount, path))
199
+ best = scope;
200
+ }
201
+ return best;
202
+ };
203
+ /** The record's address of `event`, as AG-UI metadata. */
204
+ const addressOf = (event, extra) => ({
205
+ agentfootprint: {
206
+ runtimeStageId: event.meta.runtimeStageId,
207
+ subflowPath: [...event.meta.subflowPath],
208
+ ...extra,
209
+ },
210
+ });
211
+ /** The fields every event of `scope` carries. */
212
+ const owned = (scope, event) => ({
213
+ ...(event !== undefined && { timestamp: event.meta.wallClockMs }),
214
+ ...(scope.subagentRunId !== undefined && { subagentRunId: scope.subagentRunId }),
215
+ });
216
+ // ── closers — each leaves its entity closed and writes the events that say so ──
217
+ const closeText = (scope, out) => {
218
+ if (scope.text === undefined)
219
+ return;
220
+ out.push({ type: 'TEXT_MESSAGE_END', messageId: scope.text.id, ...owned(scope) });
221
+ scope.text = undefined;
222
+ };
223
+ const closeReasoning = (scope, out) => {
224
+ if (scope.reasoning === undefined)
225
+ return;
226
+ const { id } = scope.reasoning;
227
+ out.push({ type: 'REASONING_MESSAGE_END', messageId: id, ...owned(scope) });
228
+ out.push({ type: 'REASONING_END', messageId: id, ...owned(scope) });
229
+ scope.reasoning = undefined;
230
+ };
231
+ const closeSteps = (scope, out) => {
232
+ while (scope.steps.length > 0) {
233
+ const stepName = scope.steps.pop();
234
+ out.push({ type: 'STEP_FINISHED', stepName, ...owned(scope) });
235
+ }
236
+ };
237
+ /** Close what is open INSIDE a scope — the scope itself stays. */
238
+ const closeContents = (scope, out) => {
239
+ closeText(scope, out);
240
+ closeReasoning(scope, out);
241
+ closeSteps(scope, out);
242
+ };
243
+ /** Close one nested scope: what is open inside it, then its own terminal event. */
244
+ const closeScope = (scope, out, terminal) => {
245
+ closeContents(scope, out);
246
+ const at = scopes.indexOf(scope);
247
+ if (at > 0)
248
+ scopes.splice(at, 1);
249
+ if (scope.subagentRunId !== undefined)
250
+ out.push(terminal(scope.subagentRunId));
251
+ };
252
+ /** The open nested scopes mounted strictly under `mount`, deepest first. */
253
+ const scopesUnder = (mount) => scopes
254
+ .filter((s) => s !== root && s.mount.length > mount.length && leads(mount, s.mount))
255
+ .reverse()
256
+ .sort((a, b) => b.mount.length - a.mount.length);
257
+ /** End a nested scope: every turn still open under it first (they never answered), then it. */
258
+ const endScope = (scope, out, terminal) => {
259
+ for (const inner of scopesUnder(scope.mount))
260
+ closeScope(inner, out, unfinished);
261
+ closeScope(scope, out, terminal);
262
+ };
263
+ const unfinished = (subagentRunId) => ({
264
+ type: 'SUBAGENT_ERROR',
265
+ subagentRunId,
266
+ message: AG_UI_SUBAGENT_UNFINISHED,
267
+ });
268
+ // ── openers ──
269
+ const openStep = (scope, stepName, event, out) => {
270
+ const at = scope.steps.indexOf(stepName);
271
+ if (at >= 0) {
272
+ // The same name still open in this scope: the record never closed it.
273
+ scope.steps.splice(at, 1);
274
+ out.push({ type: 'STEP_FINISHED', stepName, ...owned(scope) });
275
+ }
276
+ scope.steps.push(stepName);
277
+ out.push({
278
+ type: 'STEP_STARTED',
279
+ stepName,
280
+ ...owned(scope, event),
281
+ metadata: addressOf(event),
282
+ });
283
+ };
284
+ const finishStep = (scope, stepName, event, out) => {
285
+ const at = scope.steps.indexOf(stepName);
286
+ if (at < 0)
287
+ return;
288
+ scope.steps.splice(at, 1);
289
+ out.push({ type: 'STEP_FINISHED', stepName, ...owned(scope, event) });
290
+ };
291
+ /** A whole text message in one go — an answer the record did not stream. */
292
+ const wholeText = (scope, content, event, out) => {
293
+ const { id } = ids.next('text', event.meta.runtimeStageId);
294
+ out.push({
295
+ type: 'TEXT_MESSAGE_START',
296
+ messageId: id,
297
+ role: 'assistant',
298
+ ...owned(scope, event),
299
+ metadata: addressOf(event),
300
+ });
301
+ out.push({
302
+ type: 'TEXT_MESSAGE_CONTENT',
303
+ messageId: id,
304
+ delta: content,
305
+ ...owned(scope, event),
306
+ });
307
+ out.push({ type: 'TEXT_MESSAGE_END', messageId: id, ...owned(scope, event) });
308
+ scope.callMessageId = id;
309
+ };
310
+ // ── the mapping ──
311
+ const translate = (event, out) => {
312
+ const path = event.meta.subflowPath;
313
+ const address = event.meta.runtimeStageId;
314
+ const payload = record(event.payload);
315
+ switch (event.type) {
316
+ case 'agentfootprint.agent.turn_start': {
317
+ if (path.length === 0) {
318
+ root.isAgent = true;
319
+ return;
320
+ }
321
+ const previous = scopes.find((s) => s !== root && sameMount(s.mount, path));
322
+ if (previous !== undefined)
323
+ endScope(previous, out, unfinished);
324
+ const parent = scopeOf(path);
325
+ const scope = newScope(path, ids.next('agent', address).id, path.join('/'), parent.subagentRunId);
326
+ scope.isAgent = true;
327
+ scopes.push(scope);
328
+ out.push({
329
+ type: 'SUBAGENT_STARTED',
330
+ subagentRunId: scope.subagentRunId,
331
+ name: scope.name,
332
+ ...(parent.subagentRunId !== undefined && { parentSubagentRunId: parent.subagentRunId }),
333
+ timestamp: event.meta.wallClockMs,
334
+ metadata: addressOf(event),
335
+ });
336
+ return;
337
+ }
338
+ case 'agentfootprint.agent.turn_end': {
339
+ const scope = scopeOf(path);
340
+ if (!scope.isAgent) {
341
+ // A turn this translation never saw open (it subscribed late): its
342
+ // answer has no scope to end, and the root's must not be guessed.
343
+ pushCustom(event, scope, out);
344
+ return;
345
+ }
346
+ closeText(scope, out);
347
+ closeReasoning(scope, out);
348
+ const refused = payload.refused !== undefined;
349
+ const answer = refused ? undefined : text(payload.finalContent);
350
+ if (!scope.streamed && answer !== undefined && answer.length > 0)
351
+ wholeText(scope, answer, event, out);
352
+ if (scope === root) {
353
+ rootResult = answer;
354
+ closeSteps(scope, out);
355
+ return;
356
+ }
357
+ endScope(scope, out, (subagentRunId) => ({
358
+ type: 'SUBAGENT_FINISHED',
359
+ subagentRunId,
360
+ ...(answer !== undefined && { result: answer }),
361
+ timestamp: event.meta.wallClockMs,
362
+ }));
363
+ return;
364
+ }
365
+ case 'agentfootprint.agent.iteration_start':
366
+ openStep(scopeOf(path), `iteration ${String(payload.iterIndex)}`, event, out);
367
+ return;
368
+ case 'agentfootprint.agent.iteration_end':
369
+ finishStep(scopeOf(path), `iteration ${String(payload.iterIndex)}`, event, out);
370
+ return;
371
+ case 'agentfootprint.composition.enter':
372
+ openStep(scopeOf(path), compositionStep(payload.kind, path), event, out);
373
+ return;
374
+ case 'agentfootprint.composition.exit': {
375
+ // A turn under this composition that is still open never answered — a
376
+ // branch a tolerant merge let fail. Said, never left dangling.
377
+ for (const inner of scopesUnder(path))
378
+ closeScope(inner, out, unfinished);
379
+ finishStep(scopeOf(path), compositionStep(payload.kind, path), event, out);
380
+ return;
381
+ }
382
+ case 'agentfootprint.stream.llm_start': {
383
+ const scope = scopeOf(path);
384
+ closeText(scope, out);
385
+ closeReasoning(scope, out);
386
+ scope.streamed = false;
387
+ scope.callMessageId = undefined;
388
+ scope.llmAddress = address;
389
+ return;
390
+ }
391
+ case 'agentfootprint.stream.token': {
392
+ const content = text(payload.content);
393
+ if (content === undefined)
394
+ return;
395
+ const scope = scopeOf(path);
396
+ const index = typeof payload.tokenIndex === 'number' ? payload.tokenIndex : Number.NaN;
397
+ const open = scope.text;
398
+ if (open === undefined || open.address !== address || !(index > open.lastTokenIndex)) {
399
+ // A new message: the first token of a call, another stage's tokens (an
400
+ // answer released after validation), or a stream that restarted.
401
+ closeText(scope, out);
402
+ const { id } = ids.next('text', address);
403
+ scope.text = { id, address, lastTokenIndex: Number.isNaN(index) ? -1 : index };
404
+ scope.callMessageId = id;
405
+ out.push({
406
+ type: 'TEXT_MESSAGE_START',
407
+ messageId: id,
408
+ role: 'assistant',
409
+ ...owned(scope, event),
410
+ metadata: addressOf(event),
411
+ });
412
+ }
413
+ else {
414
+ open.lastTokenIndex = index;
415
+ }
416
+ scope.streamed = true;
417
+ out.push({
418
+ type: 'TEXT_MESSAGE_CONTENT',
419
+ messageId: scope.text.id,
420
+ delta: content,
421
+ ...owned(scope, event),
422
+ });
423
+ return;
424
+ }
425
+ case 'agentfootprint.stream.llm_end': {
426
+ const scope = scopeOf(path);
427
+ closeText(scope, out);
428
+ // Inside an agent's turn the content is a draft; the turn's answer comes
429
+ // at turn_end. With no agent around (an LLMCall, a merge by LLM) it IS
430
+ // the answer — written whole when it streamed nothing.
431
+ const content = text(payload.content);
432
+ if (!scope.isAgent && !scope.streamed && payload.contentWithheld !== true && content)
433
+ wholeText(scope, content, event, out);
434
+ return;
435
+ }
436
+ case 'agentfootprint.stream.thinking_delta': {
437
+ const content = text(payload.content);
438
+ if (!reasoning || content === undefined)
439
+ return;
440
+ const scope = scopeOf(path);
441
+ if (scope.reasoning === undefined || scope.reasoning.iteration !== payload.iteration) {
442
+ closeReasoning(scope, out);
443
+ const { id } = ids.next('reasoning', address);
444
+ scope.reasoning = { id, iteration: payload.iteration };
445
+ out.push({
446
+ type: 'REASONING_START',
447
+ messageId: id,
448
+ ...owned(scope, event),
449
+ metadata: addressOf(event),
450
+ });
451
+ out.push({
452
+ type: 'REASONING_MESSAGE_START',
453
+ messageId: id,
454
+ role: 'reasoning',
455
+ ...owned(scope, event),
456
+ });
457
+ }
458
+ out.push({
459
+ type: 'REASONING_MESSAGE_CONTENT',
460
+ messageId: scope.reasoning.id,
461
+ delta: content,
462
+ ...owned(scope, event),
463
+ });
464
+ return;
465
+ }
466
+ case 'agentfootprint.stream.thinking_end': {
467
+ if (!reasoning)
468
+ return;
469
+ const scope = scopeOf(path);
470
+ if (scope.reasoning !== undefined && scope.reasoning.iteration === payload.iteration) {
471
+ closeReasoning(scope, out);
472
+ return;
473
+ }
474
+ // Nothing streamed for this call: the blocks are the reasoning, one
475
+ // message each, in one span. A redacted block carries no text to show.
476
+ const blocks = Array.isArray(payload.blocks) ? payload.blocks : [];
477
+ const thoughts = blocks
478
+ .map((block) => record(block))
479
+ .filter((block) => block.type === 'thinking')
480
+ .map((block) => text(block.content))
481
+ .filter((content) => content !== undefined && content.length > 0);
482
+ if (thoughts.length === 0)
483
+ return;
484
+ closeReasoning(scope, out);
485
+ const messageIds = thoughts.map(() => ids.next('reasoning', address).id);
486
+ const span = messageIds[0];
487
+ out.push({
488
+ type: 'REASONING_START',
489
+ messageId: span,
490
+ ...owned(scope, event),
491
+ metadata: addressOf(event),
492
+ });
493
+ thoughts.forEach((content, i) => {
494
+ const messageId = messageIds[i];
495
+ out.push({
496
+ type: 'REASONING_MESSAGE_START',
497
+ messageId,
498
+ role: 'reasoning',
499
+ ...owned(scope, event),
500
+ });
501
+ out.push({
502
+ type: 'REASONING_MESSAGE_CONTENT',
503
+ messageId,
504
+ delta: content,
505
+ ...owned(scope, event),
506
+ });
507
+ out.push({ type: 'REASONING_MESSAGE_END', messageId, ...owned(scope, event) });
508
+ });
509
+ out.push({ type: 'REASONING_END', messageId: span, ...owned(scope, event) });
510
+ return;
511
+ }
512
+ case 'agentfootprint.stream.tool_start': {
513
+ const scope = scopeOf(path);
514
+ // The call's arguments are complete before it runs: a model's text
515
+ // message for this call is over, and so is its reasoning.
516
+ closeText(scope, out);
517
+ closeReasoning(scope, out);
518
+ // Every call of one LLM response belongs to ONE assistant message: the
519
+ // call's text message when it wrote any, else a message minted at the
520
+ // LLM call's own address for the first call and held for the rest.
521
+ if (scope.callMessageId === undefined)
522
+ scope.callMessageId = ids.next('text', scope.llmAddress ?? address).id;
523
+ const { id, n } = ids.next('tool', address);
524
+ scope.calls.push({ id, n, address, servedId: payload.toolCallId });
525
+ const toolCallName = text(payload.toolName) ?? '';
526
+ out.push({
527
+ type: 'TOOL_CALL_START',
528
+ toolCallId: id,
529
+ toolCallName,
530
+ parentMessageId: scope.callMessageId,
531
+ ...owned(scope, event),
532
+ metadata: addressOf(event, { toolCallId: text(payload.toolCallId) }),
533
+ });
534
+ out.push({
535
+ type: 'TOOL_CALL_ARGS',
536
+ toolCallId: id,
537
+ delta: toWireJson(payload.args ?? {}),
538
+ ...owned(scope, event),
539
+ });
540
+ out.push({ type: 'TOOL_CALL_END', toolCallId: id, ...owned(scope, event) });
541
+ return;
542
+ }
543
+ case 'agentfootprint.stream.tool_end': {
544
+ const scope = scopeOf(path);
545
+ const call = takeCall(scope, address, payload.toolCallId);
546
+ if (call === undefined) {
547
+ // A result the record cannot tie to a call this run opened — never
548
+ // attached to a call it may not belong to (CUSTOM only if listed).
549
+ pushCustom(event, scope, out);
550
+ return;
551
+ }
552
+ // A frontend tool's result is the one the client sent: it holds it already.
553
+ if (call.client === true)
554
+ return;
555
+ // A FAILED call's result is the thrown text — a connection string, a
556
+ // stack line, a provider's body. A person reads the fixed words unless
557
+ // the app chose to serve the record's own.
558
+ // Any `error` but an explicit `false` counts — under a policy that
559
+ // selects the key, the flag itself is served as the placeholder.
560
+ const failed = payload.error !== undefined && payload.error !== false && toolErrors !== 'served';
561
+ out.push({
562
+ type: 'TOOL_CALL_RESULT',
563
+ messageId: call.n < 0 ? ids.next('result', address).id : ids.at('result', call.n, call.address),
564
+ toolCallId: call.id,
565
+ content: failed ? AG_UI_TOOL_FAILED : resultText(payload.result),
566
+ role: 'tool',
567
+ ...owned(scope, event),
568
+ });
569
+ return;
570
+ }
571
+ case 'agentfootprint.pause.request':
572
+ pause = { event, scope: scopeOf(path) };
573
+ return;
574
+ case 'agentfootprint.error.fatal': {
575
+ // Only a FIXED sentence goes to a browser. The record's own fallback
576
+ // quotes the raw thrown message ("The AI call failed: …"), which may
577
+ // hold anything a provider or a tool put in it.
578
+ const said = text(payload.error);
579
+ if (said !== undefined && isFixedFailure(said))
580
+ fatal = said;
581
+ return;
582
+ }
583
+ default:
584
+ pushCustom(event, scopeOf(path), out);
585
+ }
586
+ };
587
+ /**
588
+ * The open call a `tool_end` closes. One agent runs its calls one at a time,
589
+ * so the open call at the result's stage execution is the one it answers;
590
+ * where the record still names the call (no redaction policy), the id
591
+ * decides among several.
592
+ */
593
+ function takeCall(scope, address, servedId) {
594
+ let at = -1;
595
+ for (let i = scope.calls.length - 1; i >= 0; i--) {
596
+ const call = scope.calls[i];
597
+ if (call.address !== address)
598
+ continue;
599
+ if (at < 0)
600
+ at = i;
601
+ if (typeof servedId === 'string' && call.servedId === servedId) {
602
+ at = i;
603
+ break;
604
+ }
605
+ }
606
+ // The call a paused run left open is answered by the first result in its
607
+ // scope: the continuation's stage executions are new, so no address matches.
608
+ if (at < 0)
609
+ at = scope.calls.findIndex((call) => call.resumed === true);
610
+ return at < 0 ? undefined : scope.calls.splice(at, 1)[0];
611
+ }
612
+ /**
613
+ * Re-open what the paused run left open — the scopes (same `subagentRunId`),
614
+ * their steps and the call it stopped in — and return the events that say so,
615
+ * for `start` to write after `RUN_STARTED`.
616
+ */
617
+ function restore(from) {
618
+ const events = [];
619
+ root.isAgent = from.rootAgent;
620
+ for (const kept of from.scopes) {
621
+ let scope = root;
622
+ if (kept.subagentRunId !== undefined) {
623
+ scope = newScope(kept.mount, kept.subagentRunId, kept.name, kept.parentSubagentRunId);
624
+ scope.isAgent = true;
625
+ scopes.push(scope);
626
+ events.push({
627
+ type: 'SUBAGENT_STARTED',
628
+ subagentRunId: kept.subagentRunId,
629
+ name: kept.name ?? kept.mount.join('/'),
630
+ ...(kept.parentSubagentRunId !== undefined && {
631
+ parentSubagentRunId: kept.parentSubagentRunId,
632
+ }),
633
+ });
634
+ }
635
+ for (const stepName of kept.steps) {
636
+ scope.steps.push(stepName);
637
+ events.push({ type: 'STEP_STARTED', stepName, ...owned(scope) });
638
+ }
639
+ for (const call of kept.calls) {
640
+ scope.calls.push({
641
+ id: call.toolCallId,
642
+ n: -1,
643
+ address: '',
644
+ servedId: undefined,
645
+ resumed: true,
646
+ client: call.client,
647
+ });
648
+ }
649
+ if (kept.messageId !== undefined)
650
+ scope.callMessageId = kept.messageId;
651
+ }
652
+ return events;
653
+ }
654
+ /** The record a continuation resumes from: every scope open now, with its steps. */
655
+ function suspensionOf(interruptId, call) {
656
+ const kept = scopes.map((scope) => ({
657
+ mount: [...scope.mount],
658
+ ...(scope.subagentRunId !== undefined && { subagentRunId: scope.subagentRunId }),
659
+ ...(scope.name !== undefined && { name: scope.name }),
660
+ ...(scope.parentSubagentRunId !== undefined && {
661
+ parentSubagentRunId: scope.parentSubagentRunId,
662
+ }),
663
+ steps: [...scope.steps],
664
+ calls: scope.calls.map((open) => ({
665
+ toolCallId: open.id,
666
+ client: open.id === call?.toolCallId ? call.client : open.client === true,
667
+ })),
668
+ ...(scope.callMessageId !== undefined && { messageId: scope.callMessageId }),
669
+ }));
670
+ return {
671
+ version: 1,
672
+ runId,
673
+ ...(interruptId !== undefined && { interruptId }),
674
+ ...(call !== undefined && { call }),
675
+ rootAgent: root.isAgent,
676
+ scopes: kept,
677
+ };
678
+ }
679
+ /**
680
+ * `event` as CUSTOM — only when its type is on the allow-list, carrying only
681
+ * the fields its projection picks from the served payload, through the wire
682
+ * rule. An unlisted event writes nothing.
683
+ */
684
+ function pushCustom(event, scope, out) {
685
+ const project = Object.prototype.hasOwnProperty.call(custom, event.type)
686
+ ? custom[event.type]
687
+ : undefined;
688
+ if (typeof project !== 'function')
689
+ return;
690
+ const call = scope.calls[scope.calls.length - 1];
691
+ const value = project(record(event.payload), call === undefined ? {} : { toolCallId: call.id });
692
+ out.push({
693
+ type: 'CUSTOM',
694
+ name: event.type,
695
+ value: withWireErrors(value ?? null),
696
+ ...owned(scope, event),
697
+ metadata: addressOf(event),
698
+ });
699
+ }
700
+ /**
701
+ * What a pause leaves for its continuation, as of now: on whom it waits
702
+ * decides whether the open call is the client's (a frontend tool) or the
703
+ * interrupt's. Pure apart from minting the interrupt once.
704
+ */
705
+ const pausedRecord = (awaiting) => {
706
+ const at = pause?.scope ?? root;
707
+ const open = at.calls[at.calls.length - 1];
708
+ if (awaiting === 'caller' && open !== undefined) {
709
+ return {
710
+ record: suspensionOf(undefined, {
711
+ toolCallId: open.id,
712
+ mount: [...at.mount],
713
+ client: true,
714
+ }),
715
+ clientCall: open.id,
716
+ };
717
+ }
718
+ return {
719
+ record: suspensionOf(interruptOf().id, open === undefined
720
+ ? undefined
721
+ : { toolCallId: open.id, mount: [...at.mount], client: false }),
722
+ };
723
+ };
724
+ /** What `RUN_STARTED` is followed by in a continuation: the scopes and steps it re-opens. */
725
+ const reopened = options.resume === undefined ? [] : restore(options.resume);
726
+ const start = (out) => {
727
+ if (started)
728
+ return;
729
+ started = true;
730
+ out.push({
731
+ type: 'RUN_STARTED',
732
+ threadId,
733
+ runId,
734
+ protocolVersion: AG_UI_PROTOCOL_VERSION,
735
+ });
736
+ out.push(...reopened);
737
+ };
738
+ /** The interrupt a person-awaited pause hands out — minted once, so a record kept before settling names it. */
739
+ let interrupt;
740
+ const interruptOf = () => (interrupt ??= mintInterrupt());
741
+ const mintInterrupt = () => {
742
+ if (pause === undefined)
743
+ return { id: ids.next('interrupt', 'run').id, reason: 'paused' };
744
+ const { event, scope } = pause;
745
+ const payload = record(event.payload);
746
+ // The question a person is asked, as the record serves it — and nothing
747
+ // else of the pause's payload (a check-in's evidence pack, a typed ask's
748
+ // context), which a browser has no reason to receive.
749
+ const message = questionOf(record(payload.questionPayload));
750
+ const call = scope.calls[scope.calls.length - 1];
751
+ return {
752
+ id: ids.next('interrupt', event.meta.runtimeStageId).id,
753
+ reason: text(payload.reason) ?? 'paused',
754
+ ...(message !== undefined && { message }),
755
+ ...(call !== undefined && { toolCallId: call.id }),
756
+ ...(scope.subagentRunId !== undefined && { subagentRunId: scope.subagentRunId }),
757
+ metadata: addressOf(event),
758
+ };
759
+ };
760
+ /** Close every open nested scope, deepest first, each with the terminal `end` names for it. */
761
+ const endAllNested = (out, end) => {
762
+ for (const scope of scopesUnder(root.mount))
763
+ closeScope(scope, out, end(scope));
764
+ };
765
+ return {
766
+ event(event) {
767
+ if (settled)
768
+ return [];
769
+ if (owns !== undefined && !owns(event))
770
+ return [];
771
+ const named = event.meta?.runId;
772
+ const namesRun = typeof named === 'string' && named !== CONSUMER_SCOPE_RUN_ID;
773
+ if (namesRun) {
774
+ // Without `owns`, the first run an event names is this run's, and
775
+ // another run's event is never this run's to translate.
776
+ if (recordRunId === undefined)
777
+ recordRunId = named;
778
+ else if (owns === undefined && named !== recordRunId)
779
+ return [];
780
+ }
781
+ const body = [];
782
+ translate(event, body);
783
+ // `RUN_STARTED` waits for the run to name itself (or to say something):
784
+ // a continuation opens with the resume's own bookkeeping, which names no
785
+ // run, and the run's id belongs on its first event.
786
+ if (!started && !namesRun && body.length === 0)
787
+ return [];
788
+ const out = [];
789
+ start(out);
790
+ out.push(...body);
791
+ return out;
792
+ },
793
+ settle(settlement) {
794
+ if (settled)
795
+ return [];
796
+ settled = true;
797
+ const out = [];
798
+ start(out);
799
+ switch (settlement.kind) {
800
+ case 'failed':
801
+ // The record's own words for the failure, never the thrown value.
802
+ out.push({
803
+ type: 'RUN_ERROR',
804
+ message: fatal ?? AG_UI_RUN_FAILED,
805
+ });
806
+ return out;
807
+ case 'paused': {
808
+ const { record, clientCall } = pausedRecord(settlement.awaiting);
809
+ suspended = record;
810
+ if (clientCall !== undefined) {
811
+ // A tool the client runs: the run COMPLETED this segment and left
812
+ // the call for the application to answer in its next input.
813
+ endAllNested(out, () => (subagentRunId) => ({
814
+ type: 'SUBAGENT_FINISHED',
815
+ subagentRunId,
816
+ outcome: { type: 'suspended' },
817
+ }));
818
+ closeContents(root, out);
819
+ out.push({
820
+ type: 'RUN_FINISHED',
821
+ threadId,
822
+ runId,
823
+ outcome: { type: 'success', pendingToolCallIds: [clientCall] },
824
+ });
825
+ return out;
826
+ }
827
+ const interrupt = interruptOf();
828
+ endAllNested(out, (scope) => (subagentRunId) => ({
829
+ type: 'SUBAGENT_FINISHED',
830
+ subagentRunId,
831
+ outcome: {
832
+ type: 'suspended',
833
+ ...(pause?.scope === scope && { interruptIds: [interrupt.id] }),
834
+ },
835
+ }));
836
+ closeContents(root, out);
837
+ out.push({
838
+ type: 'RUN_FINISHED',
839
+ threadId,
840
+ runId,
841
+ outcome: { type: 'interrupt', interrupts: [interrupt] },
842
+ });
843
+ return out;
844
+ }
845
+ case 'cancelled':
846
+ endAllNested(out, () => (subagentRunId) => ({
847
+ type: 'SUBAGENT_ERROR',
848
+ subagentRunId,
849
+ message: AG_UI_SUBAGENT_CANCELLED,
850
+ code: 'cancelled',
851
+ }));
852
+ closeContents(root, out);
853
+ out.push({
854
+ type: 'RUN_FINISHED',
855
+ threadId,
856
+ runId,
857
+ outcome: { type: 'cancelled' },
858
+ });
859
+ return out;
860
+ case 'finished':
861
+ endAllNested(out, () => unfinished);
862
+ closeContents(root, out);
863
+ out.push({
864
+ type: 'RUN_FINISHED',
865
+ threadId,
866
+ runId,
867
+ ...(rootResult !== undefined && { result: rootResult }),
868
+ });
869
+ return out;
870
+ }
871
+ },
872
+ suspension: (awaiting) => {
873
+ if (settled)
874
+ return suspended;
875
+ return pausedRecord(awaiting).record;
876
+ },
877
+ };
878
+ }
879
+ /**
880
+ * The question a pause put to a person, from whichever home its kind keeps it
881
+ * in: a plain ask (`askHuman` / `pauseHere` / an input request) at the top, a
882
+ * middleware's ask on `ask.question`, a check-in as the plain-words claim of
883
+ * what the tool will do (`checkIn.evidence.willDo`).
884
+ */
885
+ function questionOf(payload) {
886
+ return (text(payload.question) ??
887
+ text(record(payload.ask).question) ??
888
+ text(record(record(payload.checkIn).evidence).willDo));
889
+ }
890
+ /** A composition's step name: its kind, and where it is mounted when it is not the run itself. */
891
+ function compositionStep(kind, path) {
892
+ const name = typeof kind === 'string' && kind.length > 0 ? kind : 'Composition';
893
+ return path.length === 0 ? name : `${name}:${path.join('/')}`;
894
+ }
895
+ //# sourceMappingURL=serializer.js.map