@adonis-agora/agent 0.61.0 → 0.63.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 (664) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +12 -7
  3. package/dist/configure.d.ts +7 -5
  4. package/dist/configure.d.ts.map +1 -1
  5. package/dist/configure.js +7 -5
  6. package/dist/configure.js.map +1 -1
  7. package/dist/providers/a2a_provider.d.ts +14 -0
  8. package/dist/providers/a2a_provider.d.ts.map +1 -0
  9. package/dist/providers/a2a_provider.js +136 -0
  10. package/dist/providers/a2a_provider.js.map +1 -0
  11. package/dist/providers/agent_provider.d.ts.map +1 -1
  12. package/dist/providers/agent_provider.js +81 -25
  13. package/dist/providers/agent_provider.js.map +1 -1
  14. package/dist/providers/mcp_provider.d.ts +3 -0
  15. package/dist/providers/mcp_provider.d.ts.map +1 -1
  16. package/dist/providers/mcp_provider.js +147 -62
  17. package/dist/providers/mcp_provider.js.map +1 -1
  18. package/dist/src/a2a/auth.d.ts +67 -0
  19. package/dist/src/a2a/auth.d.ts.map +1 -0
  20. package/dist/src/a2a/auth.js +47 -0
  21. package/dist/src/a2a/auth.js.map +1 -0
  22. package/dist/src/a2a/define_config.d.ts +74 -0
  23. package/dist/src/a2a/define_config.d.ts.map +1 -0
  24. package/dist/src/a2a/define_config.js +5 -0
  25. package/dist/src/a2a/define_config.js.map +1 -0
  26. package/dist/src/a2a/gate.d.ts +23 -0
  27. package/dist/src/a2a/gate.d.ts.map +1 -0
  28. package/dist/src/a2a/gate.js +56 -0
  29. package/dist/src/a2a/gate.js.map +1 -0
  30. package/dist/src/a2a/handler.d.ts +65 -0
  31. package/dist/src/a2a/handler.d.ts.map +1 -0
  32. package/dist/src/a2a/handler.js +322 -0
  33. package/dist/src/a2a/handler.js.map +1 -0
  34. package/dist/src/a2a/index.d.ts +15 -0
  35. package/dist/src/a2a/index.d.ts.map +1 -0
  36. package/dist/src/a2a/index.js +9 -0
  37. package/dist/src/a2a/index.js.map +1 -0
  38. package/dist/src/a2a/permission-tool.d.ts +17 -0
  39. package/dist/src/a2a/permission-tool.d.ts.map +1 -0
  40. package/dist/src/a2a/permission-tool.js +70 -0
  41. package/dist/src/a2a/permission-tool.js.map +1 -0
  42. package/dist/src/a2a/protocol.d.ts +100 -0
  43. package/dist/src/a2a/protocol.d.ts.map +1 -0
  44. package/dist/src/a2a/protocol.js +106 -0
  45. package/dist/src/a2a/protocol.js.map +1 -0
  46. package/dist/src/a2a/runtime.d.ts +6 -0
  47. package/dist/src/a2a/runtime.d.ts.map +1 -0
  48. package/dist/src/a2a/runtime.js +13 -0
  49. package/dist/src/a2a/runtime.js.map +1 -0
  50. package/dist/src/a2a/server_middleware.d.ts +13 -0
  51. package/dist/src/a2a/server_middleware.d.ts.map +1 -0
  52. package/dist/src/a2a/server_middleware.js +18 -0
  53. package/dist/src/a2a/server_middleware.js.map +1 -0
  54. package/dist/src/a2a/store.d.ts +79 -0
  55. package/dist/src/a2a/store.d.ts.map +1 -0
  56. package/dist/src/a2a/store.js +151 -0
  57. package/dist/src/a2a/store.js.map +1 -0
  58. package/dist/src/a2a/turn.d.ts +80 -0
  59. package/dist/src/a2a/turn.d.ts.map +1 -0
  60. package/dist/src/a2a/turn.js +211 -0
  61. package/dist/src/a2a/turn.js.map +1 -0
  62. package/dist/src/action-proposal-executor.d.ts +3 -0
  63. package/dist/src/action-proposal-executor.d.ts.map +1 -1
  64. package/dist/src/action-proposal-executor.js +10 -0
  65. package/dist/src/action-proposal-executor.js.map +1 -1
  66. package/dist/src/action-proposal-service.d.ts +7 -2
  67. package/dist/src/action-proposal-service.d.ts.map +1 -1
  68. package/dist/src/action-proposal-service.js +21 -16
  69. package/dist/src/action-proposal-service.js.map +1 -1
  70. package/dist/src/action-proposal-text.d.ts +42 -3
  71. package/dist/src/action-proposal-text.d.ts.map +1 -1
  72. package/dist/src/action-proposal-text.js +80 -12
  73. package/dist/src/action-proposal-text.js.map +1 -1
  74. package/dist/src/action-proposal-worker.d.ts +2 -1
  75. package/dist/src/action-proposal-worker.d.ts.map +1 -1
  76. package/dist/src/action-proposal-worker.js +9 -2
  77. package/dist/src/action-proposal-worker.js.map +1 -1
  78. package/dist/src/actor-resolver.d.ts +12 -4
  79. package/dist/src/actor-resolver.d.ts.map +1 -1
  80. package/dist/src/actor-resolver.js +24 -7
  81. package/dist/src/actor-resolver.js.map +1 -1
  82. package/dist/src/ag-ui/adapter.d.ts.map +1 -1
  83. package/dist/src/ag-ui/adapter.js +115 -17
  84. package/dist/src/ag-ui/adapter.js.map +1 -1
  85. package/dist/src/ag-ui/core/encoder.d.ts +106 -0
  86. package/dist/src/ag-ui/core/encoder.d.ts.map +1 -0
  87. package/dist/src/ag-ui/core/encoder.js +534 -0
  88. package/dist/src/ag-ui/core/encoder.js.map +1 -0
  89. package/dist/src/ag-ui/core/index.d.ts +12 -0
  90. package/dist/src/ag-ui/core/index.d.ts.map +1 -0
  91. package/dist/src/ag-ui/core/index.js +12 -0
  92. package/dist/src/ag-ui/core/index.js.map +1 -0
  93. package/dist/src/ag-ui/core/input.d.ts +92 -0
  94. package/dist/src/ag-ui/core/input.d.ts.map +1 -0
  95. package/dist/src/ag-ui/core/input.js +246 -0
  96. package/dist/src/ag-ui/core/input.js.map +1 -0
  97. package/dist/src/ag-ui/core/interrupt-id.d.ts +31 -0
  98. package/dist/src/ag-ui/core/interrupt-id.d.ts.map +1 -0
  99. package/dist/src/ag-ui/core/interrupt-id.js +48 -0
  100. package/dist/src/ag-ui/core/interrupt-id.js.map +1 -0
  101. package/dist/src/ag-ui/{proposal-decision.d.ts → core/proposal-decision.d.ts} +1 -1
  102. package/dist/src/ag-ui/core/proposal-decision.d.ts.map +1 -0
  103. package/dist/src/ag-ui/{proposal-decision.js → core/proposal-decision.js} +3 -6
  104. package/dist/src/ag-ui/core/proposal-decision.js.map +1 -0
  105. package/dist/src/ag-ui/core/stream.d.ts +49 -0
  106. package/dist/src/ag-ui/core/stream.d.ts.map +1 -0
  107. package/dist/src/ag-ui/core/stream.js +90 -0
  108. package/dist/src/ag-ui/core/stream.js.map +1 -0
  109. package/dist/src/ag-ui/core/types.d.ts +249 -0
  110. package/dist/src/ag-ui/core/types.d.ts.map +1 -0
  111. package/dist/src/ag-ui/core/types.js +35 -0
  112. package/dist/src/ag-ui/core/types.js.map +1 -0
  113. package/dist/src/ag-ui/encoder.d.ts +3 -4
  114. package/dist/src/ag-ui/encoder.d.ts.map +1 -1
  115. package/dist/src/ag-ui/encoder.js +10 -11
  116. package/dist/src/ag-ui/encoder.js.map +1 -1
  117. package/dist/src/ag-ui/frames.d.ts +8 -5
  118. package/dist/src/ag-ui/frames.d.ts.map +1 -1
  119. package/dist/src/ag-ui/frames.js +21 -7
  120. package/dist/src/ag-ui/frames.js.map +1 -1
  121. package/dist/src/ag-ui/index.d.ts +3 -5
  122. package/dist/src/ag-ui/index.d.ts.map +1 -1
  123. package/dist/src/ag-ui/index.js +3 -5
  124. package/dist/src/ag-ui/index.js.map +1 -1
  125. package/dist/src/ag-ui/stream.d.ts +3 -4
  126. package/dist/src/ag-ui/stream.d.ts.map +1 -1
  127. package/dist/src/ag-ui/stream.js +4 -5
  128. package/dist/src/ag-ui/stream.js.map +1 -1
  129. package/dist/src/agent-deps-factory.d.ts +3 -0
  130. package/dist/src/agent-deps-factory.d.ts.map +1 -1
  131. package/dist/src/agent-deps-factory.js +3 -0
  132. package/dist/src/agent-deps-factory.js.map +1 -1
  133. package/dist/src/agent-deps.d.ts +3 -0
  134. package/dist/src/agent-deps.d.ts.map +1 -1
  135. package/dist/src/agent-deps.js.map +1 -1
  136. package/dist/src/agent-loop.d.ts +4 -3
  137. package/dist/src/agent-loop.d.ts.map +1 -1
  138. package/dist/src/agent-loop.js +50 -25
  139. package/dist/src/agent-loop.js.map +1 -1
  140. package/dist/src/agent-service.d.ts +46 -4
  141. package/dist/src/agent-service.d.ts.map +1 -1
  142. package/dist/src/agent-service.js +87 -11
  143. package/dist/src/agent-service.js.map +1 -1
  144. package/dist/src/ai-sdk/ai-sdk-model.js +4 -1
  145. package/dist/src/ai-sdk/ai-sdk-model.js.map +1 -1
  146. package/dist/src/ai-tool-ref.d.ts +4 -0
  147. package/dist/src/ai-tool-ref.d.ts.map +1 -1
  148. package/dist/src/ai-tool-ref.js +10 -14
  149. package/dist/src/ai-tool-ref.js.map +1 -1
  150. package/dist/src/attachment-limits.d.ts +10 -0
  151. package/dist/src/attachment-limits.d.ts.map +1 -0
  152. package/dist/src/attachment-limits.js +13 -0
  153. package/dist/src/attachment-limits.js.map +1 -0
  154. package/dist/src/channels/adapters/evolution_api.d.ts +49 -0
  155. package/dist/src/channels/adapters/evolution_api.d.ts.map +1 -0
  156. package/dist/src/channels/adapters/evolution_api.js +241 -0
  157. package/dist/src/channels/adapters/evolution_api.js.map +1 -0
  158. package/dist/src/channels/adapters/telegram.d.ts +34 -0
  159. package/dist/src/channels/adapters/telegram.d.ts.map +1 -0
  160. package/dist/src/channels/adapters/telegram.js +196 -0
  161. package/dist/src/channels/adapters/telegram.js.map +1 -0
  162. package/dist/src/channels/adapters/whatsapp_cloud.d.ts +31 -0
  163. package/dist/src/channels/adapters/whatsapp_cloud.d.ts.map +1 -0
  164. package/dist/src/channels/adapters/whatsapp_cloud.js +177 -0
  165. package/dist/src/channels/adapters/whatsapp_cloud.js.map +1 -0
  166. package/dist/src/channels/handler.d.ts +167 -0
  167. package/dist/src/channels/handler.d.ts.map +1 -0
  168. package/dist/src/channels/handler.js +569 -0
  169. package/dist/src/channels/handler.js.map +1 -0
  170. package/dist/src/channels/http.d.ts +45 -0
  171. package/dist/src/channels/http.d.ts.map +1 -0
  172. package/dist/src/channels/http.js +147 -0
  173. package/dist/src/channels/http.js.map +1 -0
  174. package/dist/src/channels/index.d.ts +16 -0
  175. package/dist/src/channels/index.d.ts.map +1 -0
  176. package/dist/src/channels/index.js +15 -0
  177. package/dist/src/channels/index.js.map +1 -0
  178. package/dist/src/channels/markdown.d.ts +12 -0
  179. package/dist/src/channels/markdown.d.ts.map +1 -0
  180. package/dist/src/channels/markdown.js +120 -0
  181. package/dist/src/channels/markdown.js.map +1 -0
  182. package/dist/src/channels/questions.d.ts +43 -0
  183. package/dist/src/channels/questions.d.ts.map +1 -0
  184. package/dist/src/channels/questions.js +90 -0
  185. package/dist/src/channels/questions.js.map +1 -0
  186. package/dist/src/channels/split.d.ts +8 -0
  187. package/dist/src/channels/split.d.ts.map +1 -0
  188. package/dist/src/channels/split.js +45 -0
  189. package/dist/src/channels/split.js.map +1 -0
  190. package/dist/src/channels/store.d.ts +78 -0
  191. package/dist/src/channels/store.d.ts.map +1 -0
  192. package/dist/src/channels/store.js +151 -0
  193. package/dist/src/channels/store.js.map +1 -0
  194. package/dist/src/channels/types.d.ts +138 -0
  195. package/dist/src/channels/types.d.ts.map +1 -0
  196. package/dist/src/channels/types.js +7 -0
  197. package/dist/src/channels/types.js.map +1 -0
  198. package/dist/src/chat-queue-service.d.ts.map +1 -1
  199. package/dist/src/chat-queue-service.js +2 -0
  200. package/dist/src/chat-queue-service.js.map +1 -1
  201. package/dist/src/define_config.d.ts +61 -12
  202. package/dist/src/define_config.d.ts.map +1 -1
  203. package/dist/src/define_config.js.map +1 -1
  204. package/dist/src/engine.d.ts +77 -0
  205. package/dist/src/engine.d.ts.map +1 -0
  206. package/dist/src/engine.js +27 -0
  207. package/dist/src/engine.js.map +1 -0
  208. package/dist/src/genui/builtins.d.ts +73 -3
  209. package/dist/src/genui/builtins.d.ts.map +1 -1
  210. package/dist/src/genui/builtins.js +357 -3
  211. package/dist/src/genui/builtins.js.map +1 -1
  212. package/dist/src/genui/capabilities.d.ts +24 -0
  213. package/dist/src/genui/capabilities.d.ts.map +1 -0
  214. package/dist/src/genui/capabilities.js +81 -0
  215. package/dist/src/genui/capabilities.js.map +1 -0
  216. package/dist/src/genui/catalog.d.ts +86 -0
  217. package/dist/src/genui/catalog.d.ts.map +1 -0
  218. package/dist/src/genui/catalog.js +96 -0
  219. package/dist/src/genui/catalog.js.map +1 -0
  220. package/dist/src/genui/factory.d.ts +7 -14
  221. package/dist/src/genui/factory.d.ts.map +1 -1
  222. package/dist/src/genui/factory.js.map +1 -1
  223. package/dist/src/genui/index.d.ts +4 -12
  224. package/dist/src/genui/index.d.ts.map +1 -1
  225. package/dist/src/genui/index.js +5 -18
  226. package/dist/src/genui/index.js.map +1 -1
  227. package/dist/src/genui/public.d.ts +9 -0
  228. package/dist/src/genui/public.d.ts.map +1 -0
  229. package/dist/src/genui/public.js +9 -0
  230. package/dist/src/genui/public.js.map +1 -0
  231. package/dist/src/genui/registry.d.ts +65 -0
  232. package/dist/src/genui/registry.d.ts.map +1 -0
  233. package/dist/src/genui/registry.js +151 -0
  234. package/dist/src/genui/registry.js.map +1 -0
  235. package/dist/src/genui/schema.d.ts +71 -0
  236. package/dist/src/genui/schema.d.ts.map +1 -0
  237. package/dist/src/genui/schema.js +304 -0
  238. package/dist/src/genui/schema.js.map +1 -0
  239. package/dist/src/genui/text.d.ts +36 -0
  240. package/dist/src/genui/text.d.ts.map +1 -0
  241. package/dist/src/genui/text.js +157 -0
  242. package/dist/src/genui/text.js.map +1 -0
  243. package/dist/src/genui/tools.d.ts +92 -0
  244. package/dist/src/genui/tools.d.ts.map +1 -0
  245. package/dist/src/genui/tools.js +291 -0
  246. package/dist/src/genui/tools.js.map +1 -0
  247. package/dist/src/genui/tree.d.ts +56 -0
  248. package/dist/src/genui/tree.d.ts.map +1 -0
  249. package/dist/src/genui/tree.js +188 -0
  250. package/dist/src/genui/tree.js.map +1 -0
  251. package/dist/src/index.d.ts +6 -3
  252. package/dist/src/index.d.ts.map +1 -1
  253. package/dist/src/index.js +4 -2
  254. package/dist/src/index.js.map +1 -1
  255. package/dist/src/mcp/auth.d.ts +17 -1
  256. package/dist/src/mcp/auth.d.ts.map +1 -1
  257. package/dist/src/mcp/auth.js +14 -3
  258. package/dist/src/mcp/auth.js.map +1 -1
  259. package/dist/src/mcp/define_config.d.ts +81 -2
  260. package/dist/src/mcp/define_config.d.ts.map +1 -1
  261. package/dist/src/mcp/define_config.js.map +1 -1
  262. package/dist/src/mcp/index.d.ts +1 -1
  263. package/dist/src/mcp/index.d.ts.map +1 -1
  264. package/dist/src/mcp/index.js.map +1 -1
  265. package/dist/src/mcp/oauth-resource.d.ts +9 -0
  266. package/dist/src/mcp/oauth-resource.d.ts.map +1 -0
  267. package/dist/src/mcp/oauth-resource.js +16 -0
  268. package/dist/src/mcp/oauth-resource.js.map +1 -0
  269. package/dist/src/mcp/server.d.ts +5 -0
  270. package/dist/src/mcp/server.d.ts.map +1 -1
  271. package/dist/src/mcp/server.js +48 -16
  272. package/dist/src/mcp/server.js.map +1 -1
  273. package/dist/src/negotiated-tool-ui.d.ts.map +1 -1
  274. package/dist/src/negotiated-tool-ui.js +12 -8
  275. package/dist/src/negotiated-tool-ui.js.map +1 -1
  276. package/dist/src/opencode/client.d.ts +202 -0
  277. package/dist/src/opencode/client.d.ts.map +1 -0
  278. package/dist/src/opencode/client.js +2 -0
  279. package/dist/src/opencode/client.js.map +1 -0
  280. package/dist/src/opencode/durable/index.d.ts +33 -0
  281. package/dist/src/opencode/durable/index.d.ts.map +1 -0
  282. package/dist/src/opencode/durable/index.js +38 -0
  283. package/dist/src/opencode/durable/index.js.map +1 -0
  284. package/dist/src/opencode/durable/runner.d.ts +36 -0
  285. package/dist/src/opencode/durable/runner.d.ts.map +1 -0
  286. package/dist/src/opencode/durable/runner.js +88 -0
  287. package/dist/src/opencode/durable/runner.js.map +1 -0
  288. package/dist/src/opencode/durable/workflow.d.ts +40 -0
  289. package/dist/src/opencode/durable/workflow.d.ts.map +1 -0
  290. package/dist/src/opencode/durable/workflow.js +106 -0
  291. package/dist/src/opencode/durable/workflow.js.map +1 -0
  292. package/dist/src/opencode/engine.d.ts +48 -0
  293. package/dist/src/opencode/engine.d.ts.map +1 -0
  294. package/dist/src/opencode/engine.js +98 -0
  295. package/dist/src/opencode/engine.js.map +1 -0
  296. package/dist/src/opencode/event-hub.d.ts +23 -0
  297. package/dist/src/opencode/event-hub.d.ts.map +1 -0
  298. package/dist/src/opencode/event-hub.js +99 -0
  299. package/dist/src/opencode/event-hub.js.map +1 -0
  300. package/dist/src/opencode/forms.d.ts +19 -0
  301. package/dist/src/opencode/forms.d.ts.map +1 -0
  302. package/dist/src/opencode/forms.js +82 -0
  303. package/dist/src/opencode/forms.js.map +1 -0
  304. package/dist/src/opencode/host.d.ts +179 -0
  305. package/dist/src/opencode/host.d.ts.map +1 -0
  306. package/dist/src/opencode/host.js +34 -0
  307. package/dist/src/opencode/host.js.map +1 -0
  308. package/dist/src/opencode/index.d.ts +15 -0
  309. package/dist/src/opencode/index.d.ts.map +1 -0
  310. package/dist/src/opencode/index.js +9 -0
  311. package/dist/src/opencode/index.js.map +1 -0
  312. package/dist/src/opencode/log.d.ts +9 -0
  313. package/dist/src/opencode/log.d.ts.map +1 -0
  314. package/dist/src/opencode/log.js +15 -0
  315. package/dist/src/opencode/log.js.map +1 -0
  316. package/dist/src/opencode/mcp.d.ts +60 -0
  317. package/dist/src/opencode/mcp.d.ts.map +1 -0
  318. package/dist/src/opencode/mcp.js +258 -0
  319. package/dist/src/opencode/mcp.js.map +1 -0
  320. package/dist/src/opencode/runner.d.ts +40 -0
  321. package/dist/src/opencode/runner.d.ts.map +1 -0
  322. package/dist/src/opencode/runner.js +125 -0
  323. package/dist/src/opencode/runner.js.map +1 -0
  324. package/dist/src/opencode/turn.d.ts +167 -0
  325. package/dist/src/opencode/turn.d.ts.map +1 -0
  326. package/dist/src/opencode/turn.js +761 -0
  327. package/dist/src/opencode/turn.js.map +1 -0
  328. package/dist/src/opencode/turns.d.ts +247 -0
  329. package/dist/src/opencode/turns.d.ts.map +1 -0
  330. package/dist/src/opencode/turns.js +867 -0
  331. package/dist/src/opencode/turns.js.map +1 -0
  332. package/dist/src/personas.d.ts.map +1 -1
  333. package/dist/src/personas.js +4 -1
  334. package/dist/src/personas.js.map +1 -1
  335. package/dist/src/react/ag-ui.d.ts +4 -2
  336. package/dist/src/react/ag-ui.d.ts.map +1 -1
  337. package/dist/src/react/ag-ui.js +2 -2
  338. package/dist/src/react/ag-ui.js.map +1 -1
  339. package/dist/src/react/client.d.ts +1 -1
  340. package/dist/src/react/client.d.ts.map +1 -1
  341. package/dist/src/react/client.js +1 -1
  342. package/dist/src/react/client.js.map +1 -1
  343. package/dist/src/react/core/ag-ui-backend.d.ts +109 -0
  344. package/dist/src/react/core/ag-ui-backend.d.ts.map +1 -0
  345. package/dist/src/react/core/ag-ui-backend.js +574 -0
  346. package/dist/src/react/core/ag-ui-backend.js.map +1 -0
  347. package/dist/src/react/core/agent-chat-transport.d.ts +187 -0
  348. package/dist/src/react/core/agent-chat-transport.d.ts.map +1 -0
  349. package/dist/src/react/core/agent-chat-transport.js +817 -0
  350. package/dist/src/react/core/agent-chat-transport.js.map +1 -0
  351. package/dist/src/react/core/approvals/countdown.d.ts +22 -0
  352. package/dist/src/react/core/approvals/countdown.d.ts.map +1 -0
  353. package/dist/src/react/core/approvals/countdown.js +39 -0
  354. package/dist/src/react/core/approvals/countdown.js.map +1 -0
  355. package/dist/src/react/core/approvals/proposals.d.ts +15 -0
  356. package/dist/src/react/core/approvals/proposals.d.ts.map +1 -0
  357. package/dist/src/react/core/approvals/proposals.js +82 -0
  358. package/dist/src/react/core/approvals/proposals.js.map +1 -0
  359. package/dist/src/react/core/approvals/use-action-proposals.d.ts +10 -0
  360. package/dist/src/react/core/approvals/use-action-proposals.d.ts.map +1 -0
  361. package/dist/src/react/core/approvals/use-action-proposals.js +86 -0
  362. package/dist/src/react/core/approvals/use-action-proposals.js.map +1 -0
  363. package/dist/src/react/core/attachments/files.d.ts +39 -0
  364. package/dist/src/react/core/attachments/files.d.ts.map +1 -0
  365. package/dist/src/react/core/attachments/files.js +89 -0
  366. package/dist/src/react/core/attachments/files.js.map +1 -0
  367. package/dist/src/react/core/attachments/use-attachments.d.ts +106 -0
  368. package/dist/src/react/core/attachments/use-attachments.d.ts.map +1 -0
  369. package/dist/src/react/core/attachments/use-attachments.js +217 -0
  370. package/dist/src/react/core/attachments/use-attachments.js.map +1 -0
  371. package/dist/src/react/core/backend.d.ts +245 -0
  372. package/dist/src/react/core/backend.d.ts.map +1 -0
  373. package/dist/src/react/core/backend.js +21 -0
  374. package/dist/src/react/core/backend.js.map +1 -0
  375. package/dist/src/react/core/background-runs.d.ts +32 -0
  376. package/dist/src/react/core/background-runs.d.ts.map +1 -0
  377. package/dist/src/react/core/background-runs.js +47 -0
  378. package/dist/src/react/core/background-runs.js.map +1 -0
  379. package/dist/src/react/core/catalog/use-agents.d.ts +31 -0
  380. package/dist/src/react/core/catalog/use-agents.d.ts.map +1 -0
  381. package/dist/src/react/core/catalog/use-agents.js +28 -0
  382. package/dist/src/react/core/catalog/use-agents.js.map +1 -0
  383. package/dist/src/react/core/catalog/use-models.d.ts +41 -0
  384. package/dist/src/react/core/catalog/use-models.d.ts.map +1 -0
  385. package/dist/src/react/core/catalog/use-models.js +35 -0
  386. package/dist/src/react/core/catalog/use-models.js.map +1 -0
  387. package/dist/src/react/core/catalog/use-resource.d.ts +12 -0
  388. package/dist/src/react/core/catalog/use-resource.d.ts.map +1 -0
  389. package/dist/src/react/core/catalog/use-resource.js +41 -0
  390. package/dist/src/react/core/catalog/use-resource.js.map +1 -0
  391. package/dist/src/react/core/client-wire.d.ts +14 -0
  392. package/dist/src/react/core/client-wire.d.ts.map +1 -0
  393. package/dist/src/react/core/client-wire.js +2 -0
  394. package/dist/src/react/core/client-wire.js.map +1 -0
  395. package/dist/src/react/core/client.d.ts +222 -0
  396. package/dist/src/react/core/client.d.ts.map +1 -0
  397. package/dist/src/react/core/client.js +435 -0
  398. package/dist/src/react/core/client.js.map +1 -0
  399. package/dist/src/react/core/components/ambient-ui.d.ts +22 -0
  400. package/dist/src/react/core/components/ambient-ui.d.ts.map +1 -0
  401. package/dist/src/react/core/components/ambient-ui.js +30 -0
  402. package/dist/src/react/core/components/ambient-ui.js.map +1 -0
  403. package/dist/src/react/core/components/chat-input.d.ts +44 -0
  404. package/dist/src/react/core/components/chat-input.d.ts.map +1 -0
  405. package/dist/src/react/core/components/chat-input.js +69 -0
  406. package/dist/src/react/core/components/chat-input.js.map +1 -0
  407. package/dist/src/react/core/components/index.d.ts +7 -0
  408. package/dist/src/react/core/components/index.d.ts.map +1 -0
  409. package/dist/src/react/core/components/index.js +7 -0
  410. package/dist/src/react/core/components/index.js.map +1 -0
  411. package/dist/src/react/core/components/message-item.d.ts +101 -0
  412. package/dist/src/react/core/components/message-item.d.ts.map +1 -0
  413. package/dist/src/react/core/components/message-item.js +118 -0
  414. package/dist/src/react/core/components/message-item.js.map +1 -0
  415. package/dist/src/react/core/components/message-list.d.ts +85 -0
  416. package/dist/src/react/core/components/message-list.d.ts.map +1 -0
  417. package/dist/src/react/core/components/message-list.js +45 -0
  418. package/dist/src/react/core/components/message-list.js.map +1 -0
  419. package/dist/src/react/core/components/speech-languages.d.ts +22 -0
  420. package/dist/src/react/core/components/speech-languages.d.ts.map +1 -0
  421. package/dist/src/react/core/components/speech-languages.js +38 -0
  422. package/dist/src/react/core/components/speech-languages.js.map +1 -0
  423. package/dist/src/react/core/components/use-speech-recognition.d.ts +19 -0
  424. package/dist/src/react/core/components/use-speech-recognition.d.ts.map +1 -0
  425. package/dist/src/react/core/components/use-speech-recognition.js +92 -0
  426. package/dist/src/react/core/components/use-speech-recognition.js.map +1 -0
  427. package/dist/src/react/core/composer/index.d.ts +4 -0
  428. package/dist/src/react/core/composer/index.d.ts.map +1 -0
  429. package/dist/src/react/core/composer/index.js +4 -0
  430. package/dist/src/react/core/composer/index.js.map +1 -0
  431. package/dist/src/react/core/composer/model.d.ts +83 -0
  432. package/dist/src/react/core/composer/model.d.ts.map +1 -0
  433. package/dist/src/react/core/composer/model.js +53 -0
  434. package/dist/src/react/core/composer/model.js.map +1 -0
  435. package/dist/src/react/core/composer/skills-source.d.ts +29 -0
  436. package/dist/src/react/core/composer/skills-source.d.ts.map +1 -0
  437. package/dist/src/react/core/composer/skills-source.js +61 -0
  438. package/dist/src/react/core/composer/skills-source.js.map +1 -0
  439. package/dist/src/react/core/composer/use-composer-autocomplete.d.ts +78 -0
  440. package/dist/src/react/core/composer/use-composer-autocomplete.d.ts.map +1 -0
  441. package/dist/src/react/core/composer/use-composer-autocomplete.js +244 -0
  442. package/dist/src/react/core/composer/use-composer-autocomplete.js.map +1 -0
  443. package/dist/src/react/core/config/use-agent-config.d.ts +21 -0
  444. package/dist/src/react/core/config/use-agent-config.d.ts.map +1 -0
  445. package/dist/src/react/core/config/use-agent-config.js +57 -0
  446. package/dist/src/react/core/config/use-agent-config.js.map +1 -0
  447. package/dist/src/react/core/elicitation/answers.d.ts +22 -0
  448. package/dist/src/react/core/elicitation/answers.d.ts.map +1 -0
  449. package/dist/src/react/core/elicitation/answers.js +65 -0
  450. package/dist/src/react/core/elicitation/answers.js.map +1 -0
  451. package/dist/src/react/core/feedback/use-message-feedback.d.ts +32 -0
  452. package/dist/src/react/core/feedback/use-message-feedback.d.ts.map +1 -0
  453. package/dist/src/react/core/feedback/use-message-feedback.js +106 -0
  454. package/dist/src/react/core/feedback/use-message-feedback.js.map +1 -0
  455. package/dist/src/react/core/genui/generative-ui.d.ts +76 -0
  456. package/dist/src/react/core/genui/generative-ui.d.ts.map +1 -0
  457. package/dist/src/react/core/genui/generative-ui.js +210 -0
  458. package/dist/src/react/core/genui/generative-ui.js.map +1 -0
  459. package/dist/src/react/core/genui/index.d.ts +5 -0
  460. package/dist/src/react/core/genui/index.d.ts.map +1 -0
  461. package/dist/src/react/core/genui/index.js +5 -0
  462. package/dist/src/react/core/genui/index.js.map +1 -0
  463. package/dist/src/react/core/genui/json-render.d.ts +54 -0
  464. package/dist/src/react/core/genui/json-render.d.ts.map +1 -0
  465. package/dist/src/react/core/genui/json-render.js +64 -0
  466. package/dist/src/react/core/genui/json-render.js.map +1 -0
  467. package/dist/src/react/core/genui/playwright.d.ts +12 -0
  468. package/dist/src/react/core/genui/playwright.d.ts.map +1 -0
  469. package/dist/src/react/core/genui/playwright.js +141 -0
  470. package/dist/src/react/core/genui/playwright.js.map +1 -0
  471. package/dist/src/react/core/genui/react-registry.d.ts +22 -0
  472. package/dist/src/react/core/genui/react-registry.d.ts.map +1 -0
  473. package/dist/src/react/core/genui/react-registry.js +72 -0
  474. package/dist/src/react/core/genui/react-registry.js.map +1 -0
  475. package/dist/src/react/core/genui/server.d.ts +32 -0
  476. package/dist/src/react/core/genui/server.d.ts.map +1 -0
  477. package/dist/src/react/core/genui/server.js +66 -0
  478. package/dist/src/react/core/genui/server.js.map +1 -0
  479. package/dist/src/react/core/genui/types.d.ts +98 -0
  480. package/dist/src/react/core/genui/types.d.ts.map +1 -0
  481. package/dist/src/react/core/genui/types.js +3 -0
  482. package/dist/src/react/core/genui/types.js.map +1 -0
  483. package/dist/src/react/core/genui/use-generative-ui.d.ts +42 -0
  484. package/dist/src/react/core/genui/use-generative-ui.d.ts.map +1 -0
  485. package/dist/src/react/core/genui/use-generative-ui.js +186 -0
  486. package/dist/src/react/core/genui/use-generative-ui.js.map +1 -0
  487. package/dist/src/react/core/http-error.d.ts +33 -0
  488. package/dist/src/react/core/http-error.d.ts.map +1 -0
  489. package/dist/src/react/core/http-error.js +47 -0
  490. package/dist/src/react/core/http-error.js.map +1 -0
  491. package/dist/src/react/core/index.d.ts +35 -0
  492. package/dist/src/react/core/index.d.ts.map +1 -0
  493. package/dist/src/react/core/index.js +34 -0
  494. package/dist/src/react/core/index.js.map +1 -0
  495. package/dist/src/react/core/markdown/agent-markdown.d.ts +39 -0
  496. package/dist/src/react/core/markdown/agent-markdown.d.ts.map +1 -0
  497. package/dist/src/react/core/markdown/agent-markdown.js +22 -0
  498. package/dist/src/react/core/markdown/agent-markdown.js.map +1 -0
  499. package/dist/src/react/core/markdown/index.d.ts +2 -0
  500. package/dist/src/react/core/markdown/index.d.ts.map +1 -0
  501. package/dist/src/react/core/markdown/index.js +2 -0
  502. package/dist/src/react/core/markdown/index.js.map +1 -0
  503. package/dist/src/react/core/media/index.d.ts +64 -0
  504. package/dist/src/react/core/media/index.d.ts.map +1 -0
  505. package/dist/src/react/core/media/index.js +135 -0
  506. package/dist/src/react/core/media/index.js.map +1 -0
  507. package/dist/src/react/core/media/tus.d.ts +13 -0
  508. package/dist/src/react/core/media/tus.d.ts.map +1 -0
  509. package/dist/src/react/core/media/tus.js +59 -0
  510. package/dist/src/react/core/media/tus.js.map +1 -0
  511. package/dist/src/react/core/presentation/phrasing.d.ts +25 -0
  512. package/dist/src/react/core/presentation/phrasing.d.ts.map +1 -0
  513. package/dist/src/react/core/presentation/phrasing.js +58 -0
  514. package/dist/src/react/core/presentation/phrasing.js.map +1 -0
  515. package/dist/src/react/core/presentation/result-view.d.ts +43 -0
  516. package/dist/src/react/core/presentation/result-view.d.ts.map +1 -0
  517. package/dist/src/react/core/presentation/result-view.js +90 -0
  518. package/dist/src/react/core/presentation/result-view.js.map +1 -0
  519. package/dist/src/react/core/presentation/tool-activity.d.ts +106 -0
  520. package/dist/src/react/core/presentation/tool-activity.d.ts.map +1 -0
  521. package/dist/src/react/core/presentation/tool-activity.js +165 -0
  522. package/dist/src/react/core/presentation/tool-activity.js.map +1 -0
  523. package/dist/src/react/core/presentation/use-tool-catalog.d.ts +39 -0
  524. package/dist/src/react/core/presentation/use-tool-catalog.d.ts.map +1 -0
  525. package/dist/src/react/core/presentation/use-tool-catalog.js +77 -0
  526. package/dist/src/react/core/presentation/use-tool-catalog.js.map +1 -0
  527. package/dist/src/react/core/provider.d.ts +68 -0
  528. package/dist/src/react/core/provider.d.ts.map +1 -0
  529. package/dist/src/react/core/provider.js +61 -0
  530. package/dist/src/react/core/provider.js.map +1 -0
  531. package/dist/src/react/core/queue/model.d.ts +73 -0
  532. package/dist/src/react/core/queue/model.d.ts.map +1 -0
  533. package/dist/src/react/core/queue/model.js +2 -0
  534. package/dist/src/react/core/queue/model.js.map +1 -0
  535. package/dist/src/react/core/quota/use-quota.d.ts +35 -0
  536. package/dist/src/react/core/quota/use-quota.d.ts.map +1 -0
  537. package/dist/src/react/core/quota/use-quota.js +47 -0
  538. package/dist/src/react/core/quota/use-quota.js.map +1 -0
  539. package/dist/src/react/core/reasoning/timing.d.ts +38 -0
  540. package/dist/src/react/core/reasoning/timing.d.ts.map +1 -0
  541. package/dist/src/react/core/reasoning/timing.js +73 -0
  542. package/dist/src/react/core/reasoning/timing.js.map +1 -0
  543. package/dist/src/react/core/run-errors.d.ts +37 -0
  544. package/dist/src/react/core/run-errors.d.ts.map +1 -0
  545. package/dist/src/react/core/run-errors.js +37 -0
  546. package/dist/src/react/core/run-errors.js.map +1 -0
  547. package/dist/src/react/core/stored-message-to-ui-message.d.ts +4 -0
  548. package/dist/src/react/core/stored-message-to-ui-message.d.ts.map +1 -0
  549. package/dist/src/react/core/stored-message-to-ui-message.js +216 -0
  550. package/dist/src/react/core/stored-message-to-ui-message.js.map +1 -0
  551. package/dist/src/react/core/stored-thread-to-ui-messages.d.ts +82 -0
  552. package/dist/src/react/core/stored-thread-to-ui-messages.d.ts.map +1 -0
  553. package/dist/src/react/core/stored-thread-to-ui-messages.js +116 -0
  554. package/dist/src/react/core/stored-thread-to-ui-messages.js.map +1 -0
  555. package/dist/src/react/core/threads/threads-events.d.ts +22 -0
  556. package/dist/src/react/core/threads/threads-events.d.ts.map +1 -0
  557. package/dist/src/react/core/threads/threads-events.js +21 -0
  558. package/dist/src/react/core/threads/threads-events.js.map +1 -0
  559. package/dist/src/react/core/threads/use-threads.d.ts +31 -0
  560. package/dist/src/react/core/threads/use-threads.d.ts.map +1 -0
  561. package/dist/src/react/core/threads/use-threads.js +81 -0
  562. package/dist/src/react/core/threads/use-threads.js.map +1 -0
  563. package/dist/src/react/core/transcript/index.d.ts +4 -0
  564. package/dist/src/react/core/transcript/index.d.ts.map +1 -0
  565. package/dist/src/react/core/transcript/index.js +4 -0
  566. package/dist/src/react/core/transcript/index.js.map +1 -0
  567. package/dist/src/react/core/transcript/model.d.ts +399 -0
  568. package/dist/src/react/core/transcript/model.d.ts.map +1 -0
  569. package/dist/src/react/core/transcript/model.js +725 -0
  570. package/dist/src/react/core/transcript/model.js.map +1 -0
  571. package/dist/src/react/core/transcript/use-chat-transcript.d.ts +254 -0
  572. package/dist/src/react/core/transcript/use-chat-transcript.d.ts.map +1 -0
  573. package/dist/src/react/core/transcript/use-chat-transcript.js +572 -0
  574. package/dist/src/react/core/transcript/use-chat-transcript.js.map +1 -0
  575. package/dist/src/react/core/transcript/use-stick-to-bottom.d.ts +33 -0
  576. package/dist/src/react/core/transcript/use-stick-to-bottom.d.ts.map +1 -0
  577. package/dist/src/react/core/transcript/use-stick-to-bottom.js +48 -0
  578. package/dist/src/react/core/transcript/use-stick-to-bottom.js.map +1 -0
  579. package/dist/src/react/core/use-agent-chat.d.ts +341 -0
  580. package/dist/src/react/core/use-agent-chat.d.ts.map +1 -0
  581. package/dist/src/react/core/use-agent-chat.js +1118 -0
  582. package/dist/src/react/core/use-agent-chat.js.map +1 -0
  583. package/dist/src/react/genui/index.d.ts +1 -7
  584. package/dist/src/react/genui/index.d.ts.map +1 -1
  585. package/dist/src/react/genui/index.js +1 -7
  586. package/dist/src/react/genui/index.js.map +1 -1
  587. package/dist/src/react/genui/json-render.d.ts +1 -5
  588. package/dist/src/react/genui/json-render.d.ts.map +1 -1
  589. package/dist/src/react/genui/json-render.js +1 -5
  590. package/dist/src/react/genui/json-render.js.map +1 -1
  591. package/dist/src/react/genui/server.d.ts +2 -0
  592. package/dist/src/react/genui/server.d.ts.map +1 -0
  593. package/dist/src/react/genui/server.js +2 -0
  594. package/dist/src/react/genui/server.js.map +1 -0
  595. package/dist/src/react/genui/server_playwright.d.ts +2 -0
  596. package/dist/src/react/genui/server_playwright.d.ts.map +1 -0
  597. package/dist/src/react/genui/server_playwright.js +2 -0
  598. package/dist/src/react/genui/server_playwright.js.map +1 -0
  599. package/dist/src/react/index.d.ts +5 -7
  600. package/dist/src/react/index.d.ts.map +1 -1
  601. package/dist/src/react/index.js +5 -7
  602. package/dist/src/react/index.js.map +1 -1
  603. package/dist/src/react/markdown.d.ts +1 -6
  604. package/dist/src/react/markdown.d.ts.map +1 -1
  605. package/dist/src/react/markdown.js +1 -6
  606. package/dist/src/react/markdown.js.map +1 -1
  607. package/dist/src/react/media.d.ts +1 -17
  608. package/dist/src/react/media.d.ts.map +1 -1
  609. package/dist/src/react/media.js +1 -17
  610. package/dist/src/react/media.js.map +1 -1
  611. package/dist/src/refusal.d.ts +3 -0
  612. package/dist/src/refusal.d.ts.map +1 -0
  613. package/dist/src/refusal.js +3 -0
  614. package/dist/src/refusal.js.map +1 -0
  615. package/dist/src/spi/agent-runner.d.ts +6 -0
  616. package/dist/src/spi/agent-runner.d.ts.map +1 -1
  617. package/dist/src/spi/chat-queue.d.ts +4 -1
  618. package/dist/src/spi/chat-queue.d.ts.map +1 -1
  619. package/dist/src/spi/chat-queue.js.map +1 -1
  620. package/dist/src/spi/protocol-adapter.d.ts +3 -3
  621. package/dist/src/spi/roles-policy.d.ts +7 -0
  622. package/dist/src/spi/roles-policy.d.ts.map +1 -1
  623. package/dist/src/spi/tool.d.ts +18 -3
  624. package/dist/src/spi/tool.d.ts.map +1 -1
  625. package/dist/src/stores/lucid-schema.d.ts +24 -6
  626. package/dist/src/stores/lucid-schema.d.ts.map +1 -1
  627. package/dist/src/stores/lucid-schema.js +49 -6
  628. package/dist/src/stores/lucid-schema.js.map +1 -1
  629. package/dist/src/stores/lucid.d.ts +2 -0
  630. package/dist/src/stores/lucid.d.ts.map +1 -1
  631. package/dist/src/stores/lucid.js +7 -0
  632. package/dist/src/stores/lucid.js.map +1 -1
  633. package/dist/src/testing/chat-queue-store-contract.d.ts.map +1 -1
  634. package/dist/src/testing/chat-queue-store-contract.js +4 -0
  635. package/dist/src/testing/chat-queue-store-contract.js.map +1 -1
  636. package/dist/src/testing/in-memory-store.d.ts.map +1 -1
  637. package/dist/src/testing/in-memory-store.js +1 -0
  638. package/dist/src/testing/in-memory-store.js.map +1 -1
  639. package/dist/src/tool-discovery.d.ts +1 -1
  640. package/dist/src/tool-discovery.d.ts.map +1 -1
  641. package/dist/src/tool-discovery.js +5 -1
  642. package/dist/src/tool-discovery.js.map +1 -1
  643. package/dist/src/tool-registry.d.ts +3 -0
  644. package/dist/src/tool-registry.d.ts.map +1 -1
  645. package/dist/src/tool-registry.js +15 -3
  646. package/dist/src/tool-registry.js.map +1 -1
  647. package/dist/src/tool-result-presentation.d.ts +12 -0
  648. package/dist/src/tool-result-presentation.d.ts.map +1 -0
  649. package/dist/src/tool-result-presentation.js +44 -0
  650. package/dist/src/tool-result-presentation.js.map +1 -0
  651. package/dist/src/types.d.ts +20 -0
  652. package/dist/src/types.d.ts.map +1 -1
  653. package/dist/src/ui-capabilities.d.ts +1 -8
  654. package/dist/src/ui-capabilities.d.ts.map +1 -1
  655. package/dist/src/ui-capabilities.js +3 -24
  656. package/dist/src/ui-capabilities.js.map +1 -1
  657. package/package.json +128 -22
  658. package/skills/agent-governance/SKILL.md +12 -4
  659. package/skills/agent-personas-agents/SKILL.md +2 -1
  660. package/skills/agent-setup/SKILL.md +73 -14
  661. package/skills/agent-testing/SKILL.md +22 -0
  662. package/skills/agent-tools/SKILL.md +57 -9
  663. package/dist/src/ag-ui/proposal-decision.d.ts.map +0 -1
  664. package/dist/src/ag-ui/proposal-decision.js.map +0 -1
@@ -0,0 +1,177 @@
1
+ import { createHmac } from 'node:crypto';
2
+ import { ChannelDeliveryError, ChannelMediaTooLargeError, fetchBytes, postJson, queryParam, record, safeEqual, sizeOf, str, } from '../http.js';
3
+ /** Cloud API limits: text body, interactive body, button title. */
4
+ const MAX_TEXT = 4096;
5
+ const MAX_INTERACTIVE_BODY = 1024;
6
+ const MAX_BUTTON_TITLE = 20;
7
+ const MAX_BUTTONS = 3;
8
+ const MEDIA_TYPES = ['image', 'audio', 'video', 'document', 'sticker'];
9
+ /** The file a Cloud API message carries (`{ id, mime_type, caption?, filename? }`), and its caption. */
10
+ function mediaOf(message) {
11
+ const kind = MEDIA_TYPES.find((type) => type === message.type);
12
+ const body = kind === undefined ? undefined : record(message[kind]);
13
+ const mediaId = str(body?.id);
14
+ if (kind === undefined || !body || mediaId === undefined)
15
+ return undefined;
16
+ const contentType = str(body.mime_type);
17
+ const filename = str(body.filename);
18
+ return {
19
+ media: {
20
+ kind,
21
+ ref: mediaId,
22
+ ...(contentType !== undefined ? { contentType } : {}),
23
+ ...(filename !== undefined ? { filename } : {}),
24
+ },
25
+ caption: str(body.caption),
26
+ };
27
+ }
28
+ function parseMessage(message) {
29
+ const id = str(message.id);
30
+ const from = str(message.from);
31
+ if (!id || !from)
32
+ return null;
33
+ const interactive = record(message.interactive);
34
+ const reply = record(interactive?.button_reply) ?? record(interactive?.list_reply);
35
+ // A template's quick-reply button.
36
+ const button = record(message.button);
37
+ const buttonId = str(reply?.id) ?? str(button?.payload);
38
+ const file = mediaOf(message);
39
+ const text = file
40
+ ? (file.caption ?? '')
41
+ : (str(record(message.text)?.body) ?? str(reply?.title) ?? str(button?.text) ?? buttonId);
42
+ if (text === undefined || (text.trim() === '' && !file))
43
+ return null;
44
+ return {
45
+ id,
46
+ from,
47
+ conversation: from,
48
+ text: text.trim(),
49
+ ...(buttonId !== undefined ? { buttonId } : {}),
50
+ ...(file ? { media: [file.media] } : {}),
51
+ raw: message,
52
+ };
53
+ }
54
+ /**
55
+ * WhatsApp through Meta's [Cloud API](https://developers.facebook.com/docs/whatsapp/cloud-api).
56
+ * Route both `GET` (the subscription check) and `POST` (messages) to the same handler, and subscribe
57
+ * the app to the `messages` field.
58
+ *
59
+ * Verifies `X-Hub-Signature-256` over the raw body; reads text, interactive button/list replies,
60
+ * template quick replies and media (image, audio, video, document, sticker — downloaded through the
61
+ * Graph API media endpoint) addressed to `phoneNumberId` (status updates are ignored); sends text and
62
+ * interactive reply buttons (at most 3, 20-character titles).
63
+ */
64
+ export function whatsappCloud(options) {
65
+ const name = options.name ?? 'whatsapp';
66
+ const fetcher = options.fetch ?? globalThis.fetch;
67
+ const timeoutMs = options.timeoutMs ?? 20_000;
68
+ const graphVersion = options.graphVersion ?? 'v23.0';
69
+ const endpoint = `https://graph.facebook.com/${graphVersion}/${encodeURIComponent(options.phoneNumberId)}/messages`;
70
+ const post = (body) => postJson(name, fetcher, endpoint, { authorization: `Bearer ${options.accessToken}` }, { messaging_product: 'whatsapp', recipient_type: 'individual', ...body }, timeoutMs);
71
+ const sendText = (to, body) => post({ to, type: 'text', text: { body, preview_url: false } });
72
+ return {
73
+ name,
74
+ capabilities: { buttons: MAX_BUTTONS, markdown: 'whatsapp', maxLength: MAX_TEXT },
75
+ challenge(request) {
76
+ if (request.method !== 'GET')
77
+ return null;
78
+ const mode = queryParam(request.url, 'hub.mode');
79
+ const token = queryParam(request.url, 'hub.verify_token');
80
+ const challenge = queryParam(request.url, 'hub.challenge');
81
+ if (mode === 'subscribe' && challenge !== undefined && safeEqual(token, options.verifyToken))
82
+ return { status: 200, body: challenge, contentType: 'text/plain' };
83
+ return { status: 403, body: 'Forbidden', contentType: 'text/plain' };
84
+ },
85
+ verify(request) {
86
+ const signature = request.header('x-hub-signature-256');
87
+ if (request.rawBody === null || signature === undefined)
88
+ return false;
89
+ const expected = `sha256=${createHmac('sha256', options.appSecret).update(request.rawBody, 'utf8').digest('hex')}`;
90
+ return safeEqual(signature, expected);
91
+ },
92
+ parse(body) {
93
+ const envelope = record(body);
94
+ if (envelope?.object !== 'whatsapp_business_account' || !Array.isArray(envelope.entry))
95
+ return null;
96
+ const messages = [];
97
+ for (const entry of envelope.entry) {
98
+ const changes = record(entry)?.changes;
99
+ if (!Array.isArray(changes))
100
+ continue;
101
+ for (const change of changes) {
102
+ const value = record(record(change)?.value);
103
+ if (record(change)?.field !== 'messages' || !value)
104
+ continue;
105
+ if (str(record(value.metadata)?.phone_number_id) !== options.phoneNumberId)
106
+ continue;
107
+ if (!Array.isArray(value.messages))
108
+ continue;
109
+ for (const message of value.messages) {
110
+ const parsed = record(message) ? parseMessage(record(message)) : null;
111
+ if (parsed)
112
+ messages.push(parsed);
113
+ }
114
+ }
115
+ }
116
+ return messages;
117
+ },
118
+ async download(media, { maxBytes }) {
119
+ const auth = { authorization: `Bearer ${options.accessToken}` };
120
+ // The media id resolves to a short-lived url, which wants the same token.
121
+ const lookup = await fetchBytes(name, fetcher, `https://graph.facebook.com/${graphVersion}/${encodeURIComponent(String(media.ref))}`, auth, timeoutMs, 64 * 1024);
122
+ let info;
123
+ try {
124
+ info = record(JSON.parse(lookup.data.toString('utf8')));
125
+ }
126
+ catch {
127
+ info = undefined;
128
+ }
129
+ const url = str(info?.url);
130
+ if (url === undefined) {
131
+ throw new ChannelDeliveryError(name, null, `${name}: the media could not be resolved`);
132
+ }
133
+ const declared = sizeOf(info?.file_size);
134
+ if (declared !== undefined && declared > maxBytes)
135
+ throw new ChannelMediaTooLargeError(maxBytes);
136
+ const file = await fetchBytes(name, fetcher, url, auth, timeoutMs, maxBytes);
137
+ return {
138
+ data: file.data,
139
+ contentType: media.contentType ??
140
+ str(info?.mime_type) ??
141
+ file.contentType ??
142
+ 'application/octet-stream',
143
+ ...(media.filename !== undefined ? { filename: media.filename } : {}),
144
+ };
145
+ },
146
+ async send(conversation, message) {
147
+ if (message.buttons === undefined || message.buttons.length === 0) {
148
+ await sendText(conversation, message.buttons === undefined ? message.text : message.fallbackText);
149
+ return;
150
+ }
151
+ let body = message.text;
152
+ if (body.length > MAX_INTERACTIVE_BODY) {
153
+ // The interactive body is short: the text goes first, the buttons under its last paragraph.
154
+ const cut = body.lastIndexOf('\n\n', body.length - 1);
155
+ const tail = cut > 0 ? body.slice(cut + 2) : '';
156
+ const head = tail.length > 0 && tail.length <= MAX_INTERACTIVE_BODY ? body.slice(0, cut) : body;
157
+ await sendText(conversation, head);
158
+ body = head === body ? '…' : tail;
159
+ }
160
+ await post({
161
+ to: conversation,
162
+ type: 'interactive',
163
+ interactive: {
164
+ type: 'button',
165
+ body: { text: body },
166
+ action: {
167
+ buttons: message.buttons.slice(0, MAX_BUTTONS).map((button) => ({
168
+ type: 'reply',
169
+ reply: { id: button.id, title: button.label.slice(0, MAX_BUTTON_TITLE) },
170
+ })),
171
+ },
172
+ },
173
+ });
174
+ },
175
+ };
176
+ }
177
+ //# sourceMappingURL=whatsapp_cloud.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whatsapp_cloud.js","sourceRoot":"","sources":["../../../../src/channels/adapters/whatsapp_cloud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,oBAAoB,EAEpB,yBAAyB,EACzB,UAAU,EACV,QAAQ,EACR,UAAU,EACV,MAAM,EACN,SAAS,EACT,MAAM,EACN,GAAG,GACJ,MAAM,YAAY,CAAC;AA2BpB,mEAAmE;AACnE,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAU,CAAC;AAEhF,wGAAwG;AACxG,SAAS,OAAO,CACd,OAAgC;IAEhC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,IAAI,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9B,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3E,MAAM,WAAW,GAAG,GAAG,CAAC,IAA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AI,CAAC,MAAM,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBACrF,MAAM,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;gBACnC,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;YACpC,CAAC;YACD,MAAM,IAAI,CAAC;gBACT,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE;oBACX,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;oBACpB,MAAM,EAAE;wBACN,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;4BAC9D,IAAI,EAAE,OAAO;4BACb,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,EAAE;yBACzE,CAAC,CAAC;qBACJ;iBACF;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,167 @@
1
+ import type { HttpContext } from '@adonisjs/core/http';
2
+ import { AgentService } from '../agent-service.js';
3
+ import type { AttachmentLimits } from '../attachment-limits.js';
4
+ import type { ActionProposal } from '../spi/action-proposal-store.js';
5
+ import type { ToolConfirmation } from '../tool-presentation.js';
6
+ import type { Actor, PageContext } from '../types.js';
7
+ import { type ChannelQuestionTexts } from './questions.js';
8
+ import { type ChannelStore } from './store.js';
9
+ import type { ChannelAdapter, InboundMedia, InboundMessage } from './types.js';
10
+ /**
11
+ * What a channel turn needs from the agent — `AgentService` is one. The optional methods turn
12
+ * features on: proposals (buttons, outcomes), questions (`answer`), media (`stageAttachment`), and
13
+ * the Lucid default store (`lucidDatabase`).
14
+ */
15
+ export interface ChannelTurnService extends Pick<AgentService, 'send' | 'subscribe' | 'skip' | 'cancel' | 'actionProposalReply'>, Partial<Pick<AgentService, 'decideActionProposal' | 'listActionProposals' | 'actionProposalVocabulary' | 'actionApprovalMode' | 'answer' | 'attachmentLimits' | 'stageAttachment' | 'lucidDatabase'>> {
16
+ }
17
+ /** A proposal the turn left pending, as the channel puts it to the person. */
18
+ export interface ChannelProposal {
19
+ id: string;
20
+ toolName: string;
21
+ confirmation?: ToolConfirmation;
22
+ }
23
+ /** Why a media message could not be attached. */
24
+ export type ChannelMediaRefusal = 'disabled' | 'type' | 'size' | 'failed';
25
+ /** Everything the channel says on its own (not the model). English defaults; override any. */
26
+ export interface ChannelTexts {
27
+ /** The Confirm button's label. */
28
+ approve: string;
29
+ /** The Cancel button's label. */
30
+ reject: string;
31
+ /** What a proposal says above its buttons — default: its confirmation's bold title and detail. */
32
+ proposal(proposal: ChannelProposal): string;
33
+ /**
34
+ * How to answer a proposal by text, when there are no buttons. `approve`/`reject` are the reply
35
+ * commands, built from the configured `actionProposalText.vocabulary` — `#ID` included when more
36
+ * than one proposal is waiting.
37
+ */
38
+ instruction(commands: {
39
+ approve: string;
40
+ reject: string;
41
+ }): string;
42
+ /** An approval in blocking mode, which a text channel cannot settle. */
43
+ blockingApproval: string;
44
+ /** The turn failed. */
45
+ failed: string;
46
+ /** An approved action ran, and presented nothing the channel could show. */
47
+ actionSucceeded: string;
48
+ /** An approved action's execution failed. */
49
+ actionFailed: string;
50
+ /** A file that could not be attached — no attachment store, a type or size it refuses, a failed download. */
51
+ mediaRefused(reason: ChannelMediaRefusal, media: InboundMedia, limits: AttachmentLimits | null): string;
52
+ /** How questions (the `ask` tool, intakes) are worded. */
53
+ questions: ChannelQuestionTexts;
54
+ /** Answer a sender `actor()` maps to nobody. Omitted → say nothing. */
55
+ unknownSender?: string;
56
+ }
57
+ export declare const DEFAULT_CHANNEL_TEXTS: ChannelTexts;
58
+ /** `texts` as `channels.handle` takes it: any part, `questions` too. */
59
+ export type ChannelTextsOverrides = Partial<Omit<ChannelTexts, 'questions'>> & {
60
+ questions?: Partial<ChannelQuestionTexts>;
61
+ };
62
+ export interface ChannelHandleOptions {
63
+ /**
64
+ * The account the sender is — from `message.from` (a phone number, a Telegram id). `null` → the
65
+ * message is not answered (or answered with `texts.unknownSender`). This IS the authentication of
66
+ * every message, so map only senders the channel itself vouches for.
67
+ */
68
+ actor(message: InboundMessage): Actor | null | Promise<Actor | null>;
69
+ /**
70
+ * The thread this conversation continues; `null`/`undefined` → a new one, reported to
71
+ * {@link onThreadCreated} so you can store it.
72
+ */
73
+ thread(actor: Actor, message: InboundMessage): string | null | undefined | Promise<string | null | undefined>;
74
+ /** A new thread was created for the conversation — remember it for {@link thread}. */
75
+ onThreadCreated?(threadId: string, actor: Actor, message: InboundMessage): void | Promise<void>;
76
+ /**
77
+ * The turn's page context. Default `{ kind: adapter.name }`. The handler adds `channel: { name,
78
+ * conversation }` to it — what a proposal's outcome is routed back by.
79
+ */
80
+ pageContext?: PageContext | ((message: InboundMessage) => PageContext);
81
+ /** The agent that answers. Default: the thread's, else the configured default. */
82
+ agentName?: string;
83
+ /** The agent service. Default: `AgentService` from the container. */
84
+ service?: ChannelTurnService;
85
+ /**
86
+ * Where the channel's short-lived state lives: message ids already taken, questions waiting for an
87
+ * answer, outcomes already relayed. Default: `lucidChannelStore()` over the agent store's database
88
+ * when the agent store is Lucid, else this process's memory.
89
+ */
90
+ store?: ChannelStore;
91
+ /** How long a message id is remembered. Default 24 h. */
92
+ dedupeTtlMs?: number;
93
+ /** Stop waiting for a turn after this long (and cancel it). Default 5 minutes. */
94
+ timeoutMs?: number;
95
+ /**
96
+ * After a proposal is approved, wait this long for it to execute and relay its outcome. `0` → do
97
+ * not wait (the decision reply is all the person gets; `channels.onSettled` can still relay it).
98
+ * Default 60 s.
99
+ */
100
+ outcomeTimeoutMs?: number;
101
+ /** How long a question waits for its answer before the agent proceeds without it. Default 30 min. */
102
+ questionTimeoutMs?: number;
103
+ texts?: ChannelTextsOverrides;
104
+ /** A message whose handling failed. Default: `console.error`. */
105
+ onError?(error: unknown, message: InboundMessage): void;
106
+ }
107
+ /** The route handler `channels.handle()` returns. */
108
+ export interface ChannelRouteHandler {
109
+ (ctx: HttpContext): Promise<void>;
110
+ /** Resolves once every turn this handler started has been answered — for tests and shutdown. */
111
+ drain(): Promise<void>;
112
+ }
113
+ /** The button ids for a proposal: what {@link ChannelRouteHandler} maps back to its decision. */
114
+ export declare function proposalButtonIds(proposalId: string): {
115
+ approve: string;
116
+ reject: string;
117
+ };
118
+ /** Where a turn's output goes back to — `pageContext.channel`, recorded with every proposal. */
119
+ export interface ChannelAddress {
120
+ name: string;
121
+ conversation: string;
122
+ }
123
+ /**
124
+ * The webhook route for one channel. Each request is verified (`401` when it is not the provider's),
125
+ * parsed, deduplicated by the provider's message id, and acknowledged with `200` at once; the turn
126
+ * runs after the response, so a slow model never makes the provider retry. Then:
127
+ *
128
+ * - media are downloaded and attached (held to the attachment store's limits), or refused with a text;
129
+ * - the message is sent with text-only capabilities (components arrive as their `fallbackText`);
130
+ * a text decision ("yes", "confirm #ID") is answered with its reply instead of starting a turn;
131
+ * - a press on a proposal's button decides that proposal (`via` = the adapter's name);
132
+ * - a question the turn asks is sent as text, one at a time, and the next messages answer it;
133
+ * - the reply is converted to the channel's markdown, split at its length limit, and sent;
134
+ * - a proposal the turn left pending is sent with Confirm/Cancel buttons — or, on a channel without
135
+ * them, with a text instruction in the configured `actionProposalText` vocabulary;
136
+ * - an approved proposal's outcome is relayed once it executed (see `outcomeTimeoutMs`, and
137
+ * `channels.onSettled` for one that runs later).
138
+ *
139
+ * Wants `actionApprovalMode: 'independent'`: a blocking approval holds the turn open until someone
140
+ * decides it in the app, so the channel sends what it has and `texts.blockingApproval`.
141
+ *
142
+ * Registers the adapter under its `name` for `channels.onSettled` — names must be unique.
143
+ */
144
+ export declare function handleChannel(adapter: ChannelAdapter, options: ChannelHandleOptions): ChannelRouteHandler;
145
+ /**
146
+ * `actionProposalWorker.onSettled` for text channels: relays an executed proposal's outcome to the
147
+ * conversation it was proposed in, through the adapter registered under the recorded channel name.
148
+ * Proposals from other surfaces are ignored. Safe next to the handler's own wait: an outcome is
149
+ * relayed once.
150
+ *
151
+ * ```ts
152
+ * // config/agent.ts
153
+ * actionProposalWorker: { onSettled: channels.onSettled }
154
+ * ```
155
+ */
156
+ export declare function relayChannelOutcome(proposal: ActionProposal): Promise<void>;
157
+ export declare const channels: {
158
+ /** See {@link handleChannel}. */
159
+ handle: typeof handleChannel;
160
+ /** See {@link relayChannelOutcome}. */
161
+ onSettled: typeof relayChannelOutcome;
162
+ /** Relay one proposal's outcome now; `true` when it was sent. */
163
+ deliverOutcome: (proposal: ActionProposal, service?: ChannelTurnService) => Promise<boolean>;
164
+ /** The adapter registered under `name` (by `channels.handle`), if any. */
165
+ adapter: (name: string) => ChannelAdapter | undefined;
166
+ };
167
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/channels/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAA0B,MAAM,qBAAqB,CAAC;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAGtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGtD,OAAO,EACL,KAAK,oBAAoB,EAI1B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,YAAY,EAA2C,MAAM,YAAY,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