experimental-a2 0.16.1 → 0.17.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 (333) hide show
  1. package/CHANGELOG.md +352 -0
  2. package/dist/{actor-ohPC-81x.d.ts → actor-DBbe5xeE.d.ts} +21 -11
  3. package/dist/actor-DBbe5xeE.d.ts.map +1 -0
  4. package/dist/actor-client.d.ts +2 -5
  5. package/dist/actor-client.d.ts.map +1 -1
  6. package/dist/actor-client.js +13 -4
  7. package/dist/actor-client.js.map +1 -1
  8. package/dist/actor-react.d.ts +5 -3
  9. package/dist/actor-react.d.ts.map +1 -1
  10. package/dist/actor-react.js +20 -10
  11. package/dist/actor-react.js.map +1 -1
  12. package/dist/{actor-shared-B5tJfzt-.js → actor-shared-t7w8xIKP.js} +12 -7
  13. package/dist/actor-shared-t7w8xIKP.js.map +1 -0
  14. package/dist/actor.d.ts +1 -1
  15. package/dist/actor.js +42 -23
  16. package/dist/actor.js.map +1 -1
  17. package/dist/{ai-DgOBltJ_.js → ai-UrWfKeuv.js} +621 -216
  18. package/dist/ai-UrWfKeuv.js.map +1 -0
  19. package/dist/ai-client.d.ts +27 -0
  20. package/dist/ai-client.d.ts.map +1 -0
  21. package/dist/ai-client.js +29 -0
  22. package/dist/ai-client.js.map +1 -0
  23. package/dist/ai-react.d.ts +96 -0
  24. package/dist/ai-react.d.ts.map +1 -0
  25. package/dist/ai-react.js +142 -0
  26. package/dist/ai-react.js.map +1 -0
  27. package/dist/ai-server.browser.js +2 -2
  28. package/dist/ai-server.browser.js.map +1 -1
  29. package/dist/ai-server.d.ts +80 -36
  30. package/dist/ai-server.d.ts.map +1 -1
  31. package/dist/ai-server.js +432 -258
  32. package/dist/ai-server.js.map +1 -1
  33. package/dist/{ai-CrEf6p_W.d.ts → ai-vpGtcaCB.d.ts} +114 -100
  34. package/dist/ai-vpGtcaCB.d.ts.map +1 -0
  35. package/dist/ai.d.ts +2 -2
  36. package/dist/ai.js +2 -2
  37. package/dist/{client-BYzHjkwU.js → client-COaiaDub.js} +447 -80
  38. package/dist/client-COaiaDub.js.map +1 -0
  39. package/dist/{client-CzyacQpJ.d.ts → client-qRnRUzBS.d.ts} +14 -13
  40. package/dist/client-qRnRUzBS.d.ts.map +1 -0
  41. package/dist/client.d.ts +4 -2
  42. package/dist/client.js +1 -1
  43. package/dist/{contract-CKRg_E4q.js → contract-BYKASlCV.js} +12 -21
  44. package/dist/contract-BYKASlCV.js.map +1 -0
  45. package/dist/{idempotent-replay-DVOlyYbx.js → idempotent-replay-JdgMQRRm.js} +2 -2
  46. package/dist/{idempotent-replay-DVOlyYbx.js.map → idempotent-replay-JdgMQRRm.js.map} +1 -1
  47. package/dist/index.d.ts +6 -5
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +4 -3
  50. package/dist/{errors-DvhSXnxk.d.ts → initial-snapshot-BrLso5x_.d.ts} +7 -3
  51. package/dist/initial-snapshot-BrLso5x_.d.ts.map +1 -0
  52. package/dist/{internal-Dq2qYxou.js → internal-CbVvEwad.js} +23 -2
  53. package/dist/internal-CbVvEwad.js.map +1 -0
  54. package/dist/otel.d.ts +1 -1
  55. package/dist/react-BbJ-g6Uu.d.ts +86 -0
  56. package/dist/react-BbJ-g6Uu.d.ts.map +1 -0
  57. package/dist/react.d.ts +2 -122
  58. package/dist/react.js +107 -100
  59. package/dist/react.js.map +1 -1
  60. package/dist/reducer-BAXc8JyF.js +87 -0
  61. package/dist/reducer-BAXc8JyF.js.map +1 -0
  62. package/dist/{reducer-otzHjuJj.d.ts → reducer-BYu6DT7h.d.ts} +45 -29
  63. package/dist/reducer-BYu6DT7h.d.ts.map +1 -0
  64. package/dist/reducer-runtime-DQwz_J59.js +28 -0
  65. package/dist/reducer-runtime-DQwz_J59.js.map +1 -0
  66. package/dist/scheduler-qstash.d.ts +3 -3
  67. package/dist/scheduler-qstash.d.ts.map +1 -1
  68. package/dist/scheduler-qstash.js +33 -10
  69. package/dist/scheduler-qstash.js.map +1 -1
  70. package/dist/{scheduler-task-BpzhPnRS.js → scheduler-task-X1SToDjP.js} +18 -3
  71. package/dist/scheduler-task-X1SToDjP.js.map +1 -0
  72. package/dist/scheduler-vercel.d.ts +4 -9
  73. package/dist/scheduler-vercel.d.ts.map +1 -1
  74. package/dist/scheduler-vercel.js +25 -44
  75. package/dist/scheduler-vercel.js.map +1 -1
  76. package/dist/{server-DbD7IJVK.d.ts → server-CGM8WzRG.d.ts} +87 -26
  77. package/dist/server-CGM8WzRG.d.ts.map +1 -0
  78. package/dist/{server-BD5ckxZb.js → server-Rj64fNvX.js} +854 -202
  79. package/dist/server-Rj64fNvX.js.map +1 -0
  80. package/dist/server.d.ts +4 -4
  81. package/dist/server.js +2 -2
  82. package/dist/{errors-DCk6ch5n.js → session-clear-DGI4jTQ5.js} +17 -2
  83. package/dist/session-clear-DGI4jTQ5.js.map +1 -0
  84. package/dist/session-clear-Dshpuhff.d.ts +12 -0
  85. package/dist/session-clear-Dshpuhff.d.ts.map +1 -0
  86. package/dist/{store-DyZM6fS5.d.ts → store-Gpkq7WBo.d.ts} +44 -3
  87. package/dist/store-Gpkq7WBo.d.ts.map +1 -0
  88. package/dist/store-N8PXxDAS.js.map +1 -1
  89. package/dist/store-memory.d.ts +1 -1
  90. package/dist/store-memory.d.ts.map +1 -1
  91. package/dist/store-memory.js +182 -69
  92. package/dist/store-memory.js.map +1 -1
  93. package/dist/{store-polling-CmxUbV93.js → store-polling-4_y8lETm.js} +21 -4
  94. package/dist/store-polling-4_y8lETm.js.map +1 -0
  95. package/dist/store-postgres.d.ts +1 -1
  96. package/dist/store-postgres.d.ts.map +1 -1
  97. package/dist/store-postgres.js +399 -108
  98. package/dist/store-postgres.js.map +1 -1
  99. package/dist/{store-presence-polling-C7-XZyW9.js → store-presence-polling-Q1C-k2dd.js} +3 -3
  100. package/dist/{store-presence-polling-C7-XZyW9.js.map → store-presence-polling-Q1C-k2dd.js.map} +1 -1
  101. package/dist/store-redis-http.d.ts +1 -1
  102. package/dist/store-redis-http.d.ts.map +1 -1
  103. package/dist/store-redis-http.js +293 -11
  104. package/dist/store-redis-http.js.map +1 -1
  105. package/dist/store-redis-notify-tqWNnMRu.js +2374 -0
  106. package/dist/store-redis-notify-tqWNnMRu.js.map +1 -0
  107. package/dist/store-redis.d.ts +1 -1
  108. package/dist/store-redis.d.ts.map +1 -1
  109. package/dist/store-redis.js +11 -11
  110. package/dist/store-redis.js.map +1 -1
  111. package/dist/store-sqlite.d.ts +1 -1
  112. package/dist/store-sqlite.d.ts.map +1 -1
  113. package/dist/store-sqlite.js +166 -32
  114. package/dist/store-sqlite.js.map +1 -1
  115. package/dist/stream-buffer-Cx7AAPGq.js +23 -0
  116. package/dist/stream-buffer-Cx7AAPGq.js.map +1 -0
  117. package/dist/{telemetry-B5jzpy6y.d.ts → telemetry-cZH-cibj.d.ts} +2 -2
  118. package/dist/telemetry-cZH-cibj.d.ts.map +1 -0
  119. package/dist/{wire-BO5wWCb1.js → wire-DjfHOvdW.js} +132 -10
  120. package/dist/wire-DjfHOvdW.js.map +1 -0
  121. package/docs/01-quickstart.mdx +2 -2
  122. package/docs/actors/01-introduction.mdx +4 -0
  123. package/docs/actors/04-routes.mdx +14 -1
  124. package/docs/concepts/01-contracts.mdx +95 -0
  125. package/docs/concepts/04-state.mdx +3 -3
  126. package/docs/guides/01-timers.mdx +22 -14
  127. package/docs/guides/02-cancellation.mdx +1 -1
  128. package/docs/guides/03-react.mdx +268 -328
  129. package/docs/guides/04-local-first.mdx +32 -73
  130. package/docs/guides/05-production.mdx +40 -27
  131. package/docs/guides/06-ai-agents.mdx +671 -581
  132. package/docs/guides/09-presence.mdx +3 -7
  133. package/docs/guides/10-transports.mdx +5 -5
  134. package/docs/index.mdx +10 -18
  135. package/docs/reference/01-api.mdx +656 -194
  136. package/docs/reference/02-errors.mdx +2 -1
  137. package/examples/playground/DEPLOY.md +52 -6
  138. package/examples/playground/app/a0/[appId]/loading.tsx +16 -0
  139. package/examples/playground/app/a0/[appId]/page.tsx +48 -0
  140. package/examples/playground/app/a0/a0.css +818 -0
  141. package/examples/playground/app/a0/app-list.tsx +211 -0
  142. package/examples/playground/app/a0/app-view.tsx +55 -0
  143. package/examples/playground/app/a0/apps/[appId]/preview/route.ts +27 -0
  144. package/examples/playground/app/a0/apps/[appId]/route.ts +23 -0
  145. package/examples/playground/app/a0/apps.test.ts +116 -0
  146. package/examples/playground/app/a0/apps.ts +87 -0
  147. package/examples/playground/app/a0/chat.tsx +364 -0
  148. package/examples/playground/app/a0/columns.tsx +109 -0
  149. package/examples/playground/app/a0/context-menu.tsx +116 -0
  150. package/examples/playground/app/a0/cookies.ts +46 -0
  151. package/examples/playground/app/a0/crash-on-request.ts +72 -0
  152. package/examples/playground/app/a0/crashes/route.ts +3 -0
  153. package/examples/playground/app/a0/crashes.test.ts +33 -0
  154. package/examples/playground/app/a0/crashes.ts +28 -0
  155. package/examples/playground/app/a0/devtools.tsx +164 -0
  156. package/examples/playground/app/a0/events/route.ts +6 -0
  157. package/examples/playground/app/a0/flags.ts +30 -0
  158. package/examples/playground/app/a0/layout.tsx +38 -0
  159. package/examples/playground/app/a0/list/route.ts +10 -0
  160. package/examples/playground/app/a0/model.test.ts +56 -0
  161. package/examples/playground/app/a0/model.ts +58 -0
  162. package/examples/playground/app/a0/page.tsx +14 -0
  163. package/examples/playground/app/a0/preview-pane.tsx +145 -0
  164. package/examples/playground/app/a0/preview.test.ts +53 -0
  165. package/examples/playground/app/a0/preview.ts +26 -0
  166. package/examples/playground/app/a0/sandbox-log.ts +69 -0
  167. package/examples/playground/app/a0/sandbox.ts +191 -0
  168. package/examples/playground/app/a0/sandboxes/scheduler/route.ts +6 -0
  169. package/examples/playground/app/a0/scheduler/route.ts +7 -0
  170. package/examples/playground/app/a0/server.ts +158 -0
  171. package/examples/playground/app/a0/session.ts +47 -0
  172. package/examples/playground/app/a0/shell.tsx +150 -0
  173. package/examples/playground/app/a0/short/events/route.ts +9 -0
  174. package/examples/playground/app/a0/splitter.tsx +120 -0
  175. package/examples/playground/app/agent/[agentId]/agent-client.tsx +144 -174
  176. package/examples/playground/app/agent/[agentId]/command-receipt.test.tsx +65 -0
  177. package/examples/playground/app/agent/[agentId]/command-receipt.tsx +27 -0
  178. package/examples/playground/app/agent/[agentId]/compaction-event.tsx +25 -24
  179. package/examples/playground/app/agent/[agentId]/compaction-panel.test.tsx +119 -0
  180. package/examples/playground/app/agent/[agentId]/compaction-panel.tsx +208 -165
  181. package/examples/playground/app/agent/[agentId]/page.tsx +2 -16
  182. package/examples/playground/app/agent/events/route.ts +5 -2
  183. package/examples/playground/app/agent/ingress.test.ts +98 -0
  184. package/examples/playground/app/agent/model-input.test.tsx +58 -0
  185. package/examples/playground/app/agent/model-input.tsx +115 -0
  186. package/examples/playground/app/agent/model.test.ts +73 -0
  187. package/examples/playground/app/agent/model.ts +58 -26
  188. package/examples/playground/app/agent/new-agent-session.tsx +37 -19
  189. package/examples/playground/app/agent/page.tsx +4 -4
  190. package/examples/playground/app/agent/server.ts +15 -14
  191. package/examples/playground/app/agent/session.ts +5 -6
  192. package/examples/playground/app/agent/telemetry.test.ts +168 -0
  193. package/examples/playground/app/agent/telemetry.ts +30 -0
  194. package/examples/playground/app/agent/trace.test.ts +23 -0
  195. package/examples/playground/app/agent/trace.ts +18 -0
  196. package/examples/playground/app/canvas/[canvasId]/canvas-client.tsx +11 -11
  197. package/examples/playground/app/canvas/[canvasId]/page.tsx +1 -2
  198. package/examples/playground/app/canvas/[canvasId]/session.ts +2 -2
  199. package/examples/playground/app/canvas/model.ts +53 -53
  200. package/examples/playground/app/chat/[chatId]/agent-state.test.ts +176 -0
  201. package/examples/playground/app/chat/[chatId]/agent-stream-drawer.tsx +16 -1
  202. package/examples/playground/app/chat/[chatId]/chat-client.tsx +55 -77
  203. package/examples/playground/app/chat/[chatId]/chat-view.ts +37 -3
  204. package/examples/playground/app/chat/[chatId]/page.tsx +7 -15
  205. package/examples/playground/app/chat/[chatId]/session.ts +2 -19
  206. package/examples/playground/app/chat/agent/route.ts +9 -0
  207. package/examples/playground/app/chat/model.test.ts +46 -119
  208. package/examples/playground/app/chat/model.ts +82 -128
  209. package/examples/playground/app/chat/scheduler/route.ts +2 -2
  210. package/examples/playground/app/chat/server.test.ts +108 -0
  211. package/examples/playground/app/chat/server.ts +69 -73
  212. package/examples/playground/app/components/activity-feed.tsx +30 -1
  213. package/examples/playground/app/components/activity-history.test.tsx +35 -0
  214. package/examples/playground/app/components/demo-icons.tsx +89 -0
  215. package/examples/playground/app/components/demos.tsx +33 -0
  216. package/examples/playground/app/components/fast-link.test.tsx +58 -0
  217. package/examples/playground/app/components/fast-link.tsx +55 -0
  218. package/examples/playground/app/components/site-header.tsx +96 -0
  219. package/examples/playground/app/counter/counter-client.tsx +3 -3
  220. package/examples/playground/app/counter/model.test.ts +3 -3
  221. package/examples/playground/app/counter/model.ts +11 -21
  222. package/examples/playground/app/counter/page.tsx +2 -15
  223. package/examples/playground/app/counter/session.ts +2 -2
  224. package/examples/playground/app/documents/[documentId]/code-editor.tsx +12 -1
  225. package/examples/playground/app/documents/[documentId]/document-client.tsx +10 -11
  226. package/examples/playground/app/documents/[documentId]/page.tsx +1 -2
  227. package/examples/playground/app/documents/[documentId]/session.ts +2 -2
  228. package/examples/playground/app/documents/model.ts +27 -27
  229. package/examples/playground/app/globals.css +420 -207
  230. package/examples/playground/app/initial-state.test.tsx +54 -0
  231. package/examples/playground/app/layout.tsx +7 -23
  232. package/examples/playground/app/orders/[orderId]/page.tsx +1 -2
  233. package/examples/playground/app/orders/[orderId]/session.ts +2 -2
  234. package/examples/playground/app/orders/model.ts +49 -49
  235. package/examples/playground/app/page.tsx +13 -102
  236. package/examples/playground/app/recovery/[recoveryId]/page.tsx +1 -2
  237. package/examples/playground/app/recovery/[recoveryId]/session.ts +2 -2
  238. package/examples/playground/app/recovery/model.ts +30 -30
  239. package/examples/playground/instrumentation.ts +5 -0
  240. package/examples/playground/package.json +10 -2
  241. package/examples/playground/scripts/a0-template.ts +77 -0
  242. package/examples/playground/vercel.json +18 -0
  243. package/package.json +3 -1
  244. package/src/actor-client.ts +16 -4
  245. package/src/actor-react.ts +25 -11
  246. package/src/actor-shared.ts +21 -6
  247. package/src/actor.ts +76 -31
  248. package/src/ai-agent-actions.ts +219 -0
  249. package/src/ai-agent.ts +2343 -0
  250. package/src/ai-app-state.ts +91 -0
  251. package/src/ai-client-state.ts +6 -3
  252. package/src/ai-client.ts +62 -0
  253. package/src/ai-context-schema.ts +25 -5
  254. package/src/ai-context.ts +90 -40
  255. package/src/ai-control-server.ts +92 -72
  256. package/src/ai-coordinator.ts +23 -22
  257. package/src/ai-message-base.ts +209 -0
  258. package/src/ai-message-projection.ts +262 -64
  259. package/src/ai-progress-batches.ts +26 -0
  260. package/src/ai-projector.ts +95 -14
  261. package/src/ai-react.ts +146 -0
  262. package/src/ai-server.browser.ts +2 -2
  263. package/src/ai-server.ts +20 -1964
  264. package/src/ai-stored-state.ts +48 -163
  265. package/src/ai.ts +339 -155
  266. package/src/bootstrap-stream.ts +72 -0
  267. package/src/bounded-cache.ts +55 -0
  268. package/src/client-render-session.ts +49 -0
  269. package/src/client.ts +688 -151
  270. package/src/contract.ts +92 -42
  271. package/src/deterministic-id.ts +37 -0
  272. package/src/equal-json.ts +32 -0
  273. package/src/errors.ts +13 -1
  274. package/src/index.ts +5 -1
  275. package/src/initial-snapshot.ts +39 -0
  276. package/src/internal.ts +45 -0
  277. package/src/postgres-notification-scope.ts +14 -3
  278. package/src/react.ts +171 -206
  279. package/src/redis-http-reply.ts +256 -0
  280. package/src/redis-http-stream.ts +73 -0
  281. package/src/redis-http-subscriptions.ts +13 -5
  282. package/src/reducer-runtime.ts +52 -0
  283. package/src/reducer.ts +92 -10
  284. package/src/scheduler-qstash.ts +49 -20
  285. package/src/scheduler-task.ts +34 -2
  286. package/src/scheduler-vercel.ts +32 -84
  287. package/src/server-fetch.ts +139 -35
  288. package/src/server.ts +957 -237
  289. package/src/session-clear.ts +23 -0
  290. package/src/session-socket.ts +154 -49
  291. package/src/sse.ts +71 -4
  292. package/src/store-memory.ts +220 -78
  293. package/src/store-polling.ts +18 -4
  294. package/src/store-postgres.ts +461 -114
  295. package/src/store-redis-core.ts +1260 -434
  296. package/src/store-redis-http.ts +18 -2
  297. package/src/store-redis-notify.ts +260 -85
  298. package/src/store-redis.ts +19 -9
  299. package/src/store-sqlite.ts +259 -45
  300. package/src/store.ts +46 -1
  301. package/src/stream-buffer.ts +43 -0
  302. package/src/telemetry.ts +13 -1
  303. package/src/wire.ts +241 -13
  304. package/dist/actor-ohPC-81x.d.ts.map +0 -1
  305. package/dist/actor-shared-B5tJfzt-.js.map +0 -1
  306. package/dist/ai-CrEf6p_W.d.ts.map +0 -1
  307. package/dist/ai-DgOBltJ_.js.map +0 -1
  308. package/dist/client-BYzHjkwU.js.map +0 -1
  309. package/dist/client-CzyacQpJ.d.ts.map +0 -1
  310. package/dist/contract-CKRg_E4q.js.map +0 -1
  311. package/dist/errors-DCk6ch5n.js.map +0 -1
  312. package/dist/errors-DvhSXnxk.d.ts.map +0 -1
  313. package/dist/internal-Dq2qYxou.js.map +0 -1
  314. package/dist/react.d.ts.map +0 -1
  315. package/dist/reducer-DEMjEY_O.js +0 -29
  316. package/dist/reducer-DEMjEY_O.js.map +0 -1
  317. package/dist/reducer-otzHjuJj.d.ts.map +0 -1
  318. package/dist/scheduler-task-BpzhPnRS.js.map +0 -1
  319. package/dist/server-BD5ckxZb.js.map +0 -1
  320. package/dist/server-DbD7IJVK.d.ts.map +0 -1
  321. package/dist/store-DyZM6fS5.d.ts.map +0 -1
  322. package/dist/store-polling-CmxUbV93.js.map +0 -1
  323. package/dist/store-redis-notify-BVLUfI3j.js +0 -1583
  324. package/dist/store-redis-notify-BVLUfI3j.js.map +0 -1
  325. package/dist/telemetry-B5jzpy6y.d.ts.map +0 -1
  326. package/dist/validate-XKT4FSNn.js +0 -30
  327. package/dist/validate-XKT4FSNn.js.map +0 -1
  328. package/dist/wire-BO5wWCb1.js.map +0 -1
  329. package/examples/playground/app/agent/[agentId]/compaction/route.ts +0 -14
  330. package/examples/playground/app/agent/compaction-settings.test.ts +0 -144
  331. package/examples/playground/app/agent/compaction-settings.ts +0 -49
  332. package/examples/playground/app/agent/compaction-timeline.test.ts +0 -377
  333. package/examples/playground/app/agent/compaction-timeline.ts +0 -208
@@ -0,0 +1,27 @@
1
+ import { s as CreateClientOptions, t as A2Client } from "./client-qRnRUzBS.js";
2
+ import { a as AI_STATE_REDUCER, i as AIState, r as AIMessageOf, t as AIEventDefs } from "./ai-vpGtcaCB.js";
3
+ //#region src/ai-client.d.ts
4
+ /**
5
+ * The structural shape of `typeof` an `agent({ name })` server: one whose
6
+ * state the built-in reducer folds. Agents built from an extended contract
7
+ * use `createClient({ contract })` instead.
8
+ */
9
+ type AnyAgent = {
10
+ readonly contract: {
11
+ readonly events: object;
12
+ readonly reducer: {
13
+ readonly name: typeof AI_STATE_REDUCER;
14
+ };
15
+ };
16
+ };
17
+ type AgentMessage<A extends AnyAgent> = AIMessageOf<A["contract"]["events"]>;
18
+ type AgentClient<A extends AnyAgent = AnyAgent> = A2Client<AIEventDefs<AgentMessage<A>>, AIState<AgentMessage<A>>>;
19
+ type CreateAgentClientOptions = Omit<CreateClientOptions<AIEventDefs, AIState>, "contract">;
20
+ /**
21
+ * A client for the built-in AI protocol. Agents built from a shared
22
+ * `agentContract()` use `createClient({ contract })` instead.
23
+ */
24
+ declare function createAgentClient<A extends AnyAgent = AnyAgent>(options: CreateAgentClientOptions): AgentClient<A>;
25
+ //#endregion
26
+ export { AgentClient, AgentMessage, AnyAgent, CreateAgentClientOptions, createAgentClient };
27
+ //# sourceMappingURL=ai-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-client.d.ts","names":[],"sources":["../src/ai-client.ts"],"mappings":";;;;;;;;KA8BY;WACD;aACE;aACA;eAAoB,aAAa;;;;KAIlC,aAAa,UAAU,YAAY,YAC7C;KAGU,YAAY,UAAU,WAAW,YAAY,SACvD,YAAY,aAAa,KACzB,QAAQ,aAAa;KAGX,2BAA2B,KACrC,oBAAoB,aAAa;;;;;iBAUnB,kBAAkB,UAAU,WAAW,UACrD,SAAS,2BACR,YAAY"}
@@ -0,0 +1,29 @@
1
+ import { t as createClient } from "./client-COaiaDub.js";
2
+ import { n as agentContract } from "./ai-UrWfKeuv.js";
3
+ //#region src/ai-client.ts
4
+ /**
5
+ * experimental-a2/ai/client — a client for an `agent()` route that needs no
6
+ * contract: the AI protocol and its `AIState` reducer are library code, and
7
+ * the agent's types arrive through a type-only `typeof` import.
8
+ *
9
+ * ```ts
10
+ * import type { assistant } from '@/server/assistant' // erased at build
11
+ * const client = createAgentClient<typeof assistant>({ api: '/api/agent' })
12
+ * await client.session(id).push(...inputs.message(message))
13
+ * ```
14
+ */
15
+ const protocol = agentContract({ name: "a2.ai" });
16
+ /**
17
+ * A client for the built-in AI protocol. Agents built from a shared
18
+ * `agentContract()` use `createClient({ contract })` instead.
19
+ */
20
+ function createAgentClient(options) {
21
+ return createClient({
22
+ ...options,
23
+ contract: protocol
24
+ });
25
+ }
26
+ //#endregion
27
+ export { createAgentClient };
28
+
29
+ //# sourceMappingURL=ai-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-client.js","names":[],"sources":["../src/ai-client.ts"],"sourcesContent":["/**\n * experimental-a2/ai/client — a client for an `agent()` route that needs no\n * contract: the AI protocol and its `AIState` reducer are library code, and\n * the agent's types arrive through a type-only `typeof` import.\n *\n * ```ts\n * import type { assistant } from '@/server/assistant' // erased at build\n * const client = createAgentClient<typeof assistant>({ api: '/api/agent' })\n * await client.session(id).push(...inputs.message(message))\n * ```\n */\n\nimport {\n agentContract,\n type AI_STATE_REDUCER,\n type AIEventDefs,\n type AIMessageOf,\n type AIState,\n} from './ai.ts'\nimport {\n createClient,\n type A2Client,\n type CreateClientOptions,\n} from './client.ts'\n\n/**\n * The structural shape of `typeof` an `agent({ name })` server: one whose\n * state the built-in reducer folds. Agents built from an extended contract\n * use `createClient({ contract })` instead.\n */\nexport type AnyAgent = {\n readonly contract: {\n readonly events: object\n readonly reducer: { readonly name: typeof AI_STATE_REDUCER }\n }\n}\n\nexport type AgentMessage<A extends AnyAgent> = AIMessageOf<\n A['contract']['events']\n>\n\nexport type AgentClient<A extends AnyAgent = AnyAgent> = A2Client<\n AIEventDefs<AgentMessage<A>>,\n AIState<AgentMessage<A>>\n>\n\nexport type CreateAgentClientOptions = Omit<\n CreateClientOptions<AIEventDefs, AIState>,\n 'contract'\n>\n\nconst protocol = agentContract({ name: 'a2.ai' })\n\n/**\n * A client for the built-in AI protocol. Agents built from a shared\n * `agentContract()` use `createClient({ contract })` instead.\n */\nexport function createAgentClient<A extends AnyAgent = AnyAgent>(\n options: CreateAgentClientOptions,\n): AgentClient<A> {\n return createClient({ ...options, contract: protocol }) as AgentClient<A>\n}\n"],"mappings":";;;;;;;;;;;;;;AAmDA,MAAM,WAAW,cAAc,EAAE,MAAM,QAAQ,CAAC;;;;;AAMhD,SAAgB,kBACd,SACgB;CAChB,OAAO,aAAa;EAAE,GAAG;EAAS,UAAU;CAAS,CAAC;AACxD"}
@@ -0,0 +1,96 @@
1
+ import { s as Contract, t as Reducer, u as EventDefs } from "./reducer-BYu6DT7h.js";
2
+ import { t as InitialSnapshot } from "./initial-snapshot-BrLso5x_.js";
3
+ import { t as A2Client, u as PushResult } from "./client-qRnRUzBS.js";
4
+ import { B as PendingApproval, V as PendingInput, d as AgentStatus, i as AIState, t as AIEventDefs } from "./ai-vpGtcaCB.js";
5
+ import { AgentClient, AgentMessage, AnyAgent } from "./ai-client.js";
6
+ import { c as UseSessionResult } from "./react-BbJ-g6Uu.js";
7
+ import { JSONValue, UIMessage } from "ai";
8
+ //#region src/ai-agent-actions.d.ts
9
+ /** The input message type of a state: what its inbox holds. */
10
+ type InputOf<S extends AIState> = S["inbox"]["items"][number]["message"];
11
+ /** What the UI shows while nothing new is visible in the response. */
12
+ type AgentIndicator = "starting" | "thinking" | "compacting" | null;
13
+ /**
14
+ * Every action resolves like `push()`: to the persisted command events, whose
15
+ * `id` is the `commandId` of its `ai.control.decided` receipt. An action with
16
+ * nothing to address (Stop with no active turn) resolves to no events.
17
+ */
18
+ type AgentActions<D extends EventDefs, M extends UIMessage> = {
19
+ /** Queue a user message. A string becomes one text part. */
20
+ sendMessage: (message: string | M, options?: {
21
+ generate?: boolean;
22
+ }) => PushResult<D>;
23
+ /** Hand off after the active turn's current step, or send when idle. */
24
+ steer: (message: string | M) => PushResult<D>;
25
+ /** Stop the active turn at the frontier this render showed. */
26
+ stop: () => PushResult<D>;
27
+ approve: (approval: PendingApproval) => PushResult<D>;
28
+ deny: (approval: PendingApproval, options?: {
29
+ reason?: string;
30
+ }) => PushResult<D>;
31
+ respond: (input: PendingInput, value: JSONValue) => PushResult<D>;
32
+ /** Rerun the failed model step of the active turn. */
33
+ retry: () => PushResult<D>;
34
+ pause: (options: {
35
+ when: "now" | "after-turn";
36
+ }) => PushResult<D>;
37
+ resume: () => PushResult<D>;
38
+ queue: {
39
+ edit: (message: M) => PushResult<D>;
40
+ move: (options: {
41
+ inputId: string;
42
+ beforeId: string | null;
43
+ }) => PushResult<D>;
44
+ remove: (inputId: string) => PushResult<D>;
45
+ /** Prioritize a queued input and hand off after the current step. */
46
+ sendNow: (inputId: string) => PushResult<D>;
47
+ };
48
+ };
49
+ type UseAgentResult<D extends EventDefs, S extends AIState> = UseSessionResult<D, S> & AgentActions<D, InputOf<S>> & {
50
+ messages: S["messages"];
51
+ status: AgentStatus;
52
+ indicator: AgentIndicator;
53
+ };
54
+ //#endregion
55
+ //#region src/ai-react.d.ts
56
+ type UseAgentOptions<A extends AnyAgent> = {
57
+ /** The session id. */
58
+ id: string;
59
+ /** The server-rendered `assistant.session(id).state()`. */
60
+ initial?: InitialSnapshot<AIState<AgentMessage<A>>>;
61
+ participant?: string;
62
+ } & ({
63
+ /** The route serving the agent's `fetch`; its client is shared. */
64
+ api: string;
65
+ contract?: never;
66
+ } | {
67
+ client: AgentClient<A>;
68
+ });
69
+ /**
70
+ * Use a session of an agent served from a shared `agentContract()`, folding
71
+ * its application state in the browser. The contract is a real import here.
72
+ */
73
+ type UseContractAgentOptions<D extends EventDefs, S extends AIState> = {
74
+ /** The session id. */
75
+ id: string;
76
+ /** The server-rendered `agent.session(id).state()`. */
77
+ initial?: InitialSnapshot<S>;
78
+ participant?: string;
79
+ } & ({
80
+ /** The route serving the agent's `fetch`; its client is shared. */
81
+ api: string;
82
+ contract: Contract<D, Record<never, never>, Reducer<D, S>>;
83
+ } | {
84
+ /** `createClient({ contract, api })`, shared with pushes outside React. */
85
+ client: A2Client<D, S>;
86
+ });
87
+ /** Use a session of an agent served from a shared `agentContract()`. */
88
+ declare function useAgent<D extends EventDefs, S extends AIState>(options: UseContractAgentOptions<D, S>): UseAgentResult<D, S>;
89
+ /**
90
+ * Use one agent session. Pass `typeof` the server's `agent()` for its
91
+ * message types; the import is type-only and erased.
92
+ */
93
+ declare function useAgent<A extends AnyAgent = AnyAgent>(options: UseAgentOptions<A>): UseAgentResult<AIEventDefs<AgentMessage<A>>, AIState<AgentMessage<A>>>;
94
+ //#endregion
95
+ export { type AgentActions, type AgentClient, type AgentIndicator, type AgentMessage, type AnyAgent, UseAgentOptions, type UseAgentResult, UseContractAgentOptions, useAgent };
96
+ //# sourceMappingURL=ai-react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-react.d.ts","names":[],"sources":["../src/ai-agent-actions.ts","../src/ai-react.ts"],"mappings":";;;;;;;;;KAcK,QAAQ,UAAU,WAAW;;KAGtB;;;;;;KAOA,aAAa,UAAU,WAAW,UAAU;;EAEtD,cACE,kBAAkB,GAClB;IAAY;QACT,WAAW;;EAEhB,QAAQ,kBAAkB,MAAM,WAAW;;EAE3C,YAAY,WAAW;EACvB,UAAU,UAAU,oBAAoB,WAAW;EACnD,OACE,UAAU,iBACV;IAAY;QACT,WAAW;EAChB,UAAU,OAAO,cAAc,OAAO,cAAc,WAAW;;EAE/D,aAAa,WAAW;EACxB,QAAQ;IAAW;QAAiC,WAAW;EAC/D,cAAc,WAAW;EACzB;IACE,OAAO,SAAS,MAAM,WAAW;IACjC,OAAO;MACL;MACA;UACI,WAAW;IACjB,SAAS,oBAAoB,WAAW;;IAExC,UAAU,oBAAoB,WAAW;;;KAIjC,eACV,UAAU,WACV,UAAU,WACR,iBAAiB,GAAG,KACtB,aAAa,GAAG,QAAQ;EACtB,UAAU;EACV,QAAQ;EACR,WAAW;;;;KClCH,gBAAgB,UAAU;;EAEpC;;EAEA,UAAU,gBAAgB,QAAQ,aAAa;EAC/C;;;EAII;EACA;;EAEA,QAAQ,YAAY;;;;;;KAOd,wBAAwB,UAAU,WAAW,UAAU;;EAEjE;;EAEA,UAAU,gBAAgB;EAC1B;;;EAII;EACA,UAAU,SAAS,GAAG,sBAAsB,QAAQ,GAAG;;;EAIvD,QAAQ,SAAS,GAAG;;;iBA+CV,SAAS,UAAU,WAAW,UAAU,SACtD,SAAS,wBAAwB,GAAG,KACnC,eAAe,GAAG;;;;;iBAKL,SAAS,UAAU,WAAW,UAC5C,SAAS,gBAAgB,KACxB,eAAe,YAAY,aAAa,KAAK,QAAQ,aAAa"}
@@ -0,0 +1,142 @@
1
+ "use client";
2
+ import { t as createClient } from "./client-COaiaDub.js";
3
+ import { useSession } from "./react.js";
4
+ import { s as inputs, x as isCompactionPart } from "./ai-UrWfKeuv.js";
5
+ import { createAgentClient } from "./ai-client.js";
6
+ //#region src/ai-agent-actions.ts
7
+ const visible = (part) => part.type === "text" ? part.text.length > 0 : part.type !== "reasoning" && part.type !== "step-start" && !isCompactionPart(part);
8
+ const indicatorOf = (state) => {
9
+ if (state.starting) return "starting";
10
+ if (state.status !== "generating") return null;
11
+ if (state.compaction?.status === "running") return "compacting";
12
+ const responseId = state.activeGeneration?.responseMessageId ?? state.activeResponseMessageId ?? state.activeProjection?.responseMessageId;
13
+ const response = responseId === void 0 || responseId === null ? void 0 : state.messages.findLast((message) => message.id === responseId);
14
+ if (response === void 0 || state.activeGeneration === null && state.activeResponseMessageId !== null) return "thinking";
15
+ const projection = state.activeProjection;
16
+ const start = state.activeGeneration !== null && projection?.generationId === state.activeGeneration.generationId && projection.base !== void 0 ? projection.base.partCount : response.parts.findLastIndex((part) => part.type === "step-start") + 1;
17
+ return response.parts.slice(start).some(visible) ? null : "thinking";
18
+ };
19
+ const userMessage = (message) => typeof message === "string" ? {
20
+ id: crypto.randomUUID(),
21
+ role: "user",
22
+ parts: [{
23
+ type: "text",
24
+ text: message
25
+ }]
26
+ } : message;
27
+ function withAgentActions(session) {
28
+ const { state, index, push } = session;
29
+ const send = (events) => events.length === 0 ? Object.assign(Promise.resolve([]), { confirmed: Promise.resolve([]) }) : push(...events);
30
+ const active = state.active;
31
+ const lastSeenIndex = index;
32
+ const actions = {
33
+ sendMessage: (message, options) => send(inputs.message(userMessage(message), options)),
34
+ steer: (message) => send(active === null ? inputs.message(userMessage(message)) : inputs.steer({
35
+ turnId: active.turnId,
36
+ message: userMessage(message),
37
+ lastSeenIndex
38
+ })),
39
+ stop: () => send(active === null ? [] : inputs.stop({
40
+ turnId: active.turnId,
41
+ lastSeenIndex
42
+ })),
43
+ approve: (approval) => send(inputs.approval({
44
+ ...approvalOwner(approval),
45
+ approved: true
46
+ })),
47
+ deny: (approval, options) => send(inputs.approval({
48
+ ...approvalOwner(approval),
49
+ approved: false,
50
+ ...options?.reason === void 0 ? {} : { reason: options.reason }
51
+ })),
52
+ respond: (input, value) => send(inputs.input({
53
+ requestId: input.requestId,
54
+ messageId: input.messageId,
55
+ generationId: input.generationId,
56
+ inputId: input.inputId,
57
+ name: input.name,
58
+ value
59
+ })),
60
+ retry: () => {
61
+ const responseMessageId = state.activeProjection?.responseMessageId;
62
+ return send(state.status !== "failed" || active === null || responseMessageId === void 0 ? [] : inputs.retry({
63
+ messageId: active.input.id,
64
+ responseMessageId,
65
+ retryId: crypto.randomUUID()
66
+ }));
67
+ },
68
+ pause: (options) => send(inputs.pause(options)),
69
+ resume: () => send(inputs.resume()),
70
+ queue: {
71
+ edit: (message) => send(inputs.queue.edit({ message })),
72
+ move: (options) => send(inputs.queue.move(options)),
73
+ remove: (inputId) => send(inputs.queue.remove({ inputId })),
74
+ sendNow: (inputId) => send(inputs.queue.sendNow({
75
+ inputId,
76
+ turnId: active?.turnId ?? null,
77
+ lastSeenIndex
78
+ }))
79
+ }
80
+ };
81
+ return {
82
+ ...session,
83
+ ...actions,
84
+ messages: state.messages,
85
+ status: state.status,
86
+ indicator: indicatorOf(state)
87
+ };
88
+ }
89
+ const approvalOwner = (approval) => ({
90
+ requestId: approval.requestId,
91
+ messageId: approval.messageId,
92
+ generationId: approval.generationId,
93
+ approvalId: approval.approvalId
94
+ });
95
+ //#endregion
96
+ //#region src/ai-react.ts
97
+ const clients = /* @__PURE__ */ new Map();
98
+ const contractClients = /* @__PURE__ */ new WeakMap();
99
+ /**
100
+ * One client per route for the page's lifetime; its idle sessions expire
101
+ * after the default `gcTime`. It reads `globalThis.fetch` per request, so
102
+ * instrumentation installed later still applies.
103
+ */
104
+ const clientFor = (api) => {
105
+ let client = clients.get(api);
106
+ if (client === void 0) {
107
+ client = createAgentClient({
108
+ api,
109
+ fetch: (input, init) => globalThis.fetch(input, init)
110
+ });
111
+ clients.set(api, client);
112
+ }
113
+ return client;
114
+ };
115
+ /** One client per contract and route, like `clientFor`. */
116
+ const contractClientFor = (contract, api) => {
117
+ let byApi = contractClients.get(contract);
118
+ if (byApi === void 0) {
119
+ byApi = /* @__PURE__ */ new Map();
120
+ contractClients.set(contract, byApi);
121
+ }
122
+ let client = byApi.get(api);
123
+ if (client === void 0) {
124
+ client = createClient({
125
+ contract,
126
+ api,
127
+ fetch: (input, init) => globalThis.fetch(input, init)
128
+ });
129
+ byApi.set(api, client);
130
+ }
131
+ return client;
132
+ };
133
+ function useAgent(options) {
134
+ return withAgentActions(useSession("client" in options ? options.client : options.contract !== void 0 ? contractClientFor(options.contract, options.api) : clientFor(options.api), options.id, {
135
+ ...options.initial === void 0 ? {} : { initial: options.initial },
136
+ ...options.participant === void 0 ? {} : { participant: options.participant }
137
+ }));
138
+ }
139
+ //#endregion
140
+ export { useAgent };
141
+
142
+ //# sourceMappingURL=ai-react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-react.js","names":[],"sources":["../src/ai-agent-actions.ts","../src/ai-react.ts"],"sourcesContent":["import type { JSONValue, UIMessage } from 'ai'\nimport {\n inputs,\n isCompactionPart,\n type AIState,\n type AgentStatus,\n type PendingApproval,\n type PendingInput,\n} from './ai.ts'\nimport type { AppendInput, EventDefs } from './contract.ts'\nimport type { PushResult } from './client.ts'\nimport type { UseSessionResult } from './react.ts'\n\n/** The input message type of a state: what its inbox holds. */\ntype InputOf<S extends AIState> = S['inbox']['items'][number]['message']\n\n/** What the UI shows while nothing new is visible in the response. */\nexport type AgentIndicator = 'starting' | 'thinking' | 'compacting' | null\n\n/**\n * Every action resolves like `push()`: to the persisted command events, whose\n * `id` is the `commandId` of its `ai.control.decided` receipt. An action with\n * nothing to address (Stop with no active turn) resolves to no events.\n */\nexport type AgentActions<D extends EventDefs, M extends UIMessage> = {\n /** Queue a user message. A string becomes one text part. */\n sendMessage: (\n message: string | M,\n options?: { generate?: boolean },\n ) => PushResult<D>\n /** Hand off after the active turn's current step, or send when idle. */\n steer: (message: string | M) => PushResult<D>\n /** Stop the active turn at the frontier this render showed. */\n stop: () => PushResult<D>\n approve: (approval: PendingApproval) => PushResult<D>\n deny: (\n approval: PendingApproval,\n options?: { reason?: string },\n ) => PushResult<D>\n respond: (input: PendingInput, value: JSONValue) => PushResult<D>\n /** Rerun the failed model step of the active turn. */\n retry: () => PushResult<D>\n pause: (options: { when: 'now' | 'after-turn' }) => PushResult<D>\n resume: () => PushResult<D>\n queue: {\n edit: (message: M) => PushResult<D>\n move: (options: {\n inputId: string\n beforeId: string | null\n }) => PushResult<D>\n remove: (inputId: string) => PushResult<D>\n /** Prioritize a queued input and hand off after the current step. */\n sendNow: (inputId: string) => PushResult<D>\n }\n}\n\nexport type UseAgentResult<\n D extends EventDefs,\n S extends AIState,\n> = UseSessionResult<D, S> &\n AgentActions<D, InputOf<S>> & {\n messages: S['messages']\n status: AgentStatus\n indicator: AgentIndicator\n }\n\nconst visible = (part: UIMessage['parts'][number]): boolean =>\n part.type === 'text'\n ? part.text.length > 0\n : part.type !== 'reasoning' &&\n part.type !== 'step-start' &&\n !isCompactionPart(part)\n\nconst indicatorOf = (state: AIState): AgentIndicator => {\n if (state.starting) return 'starting'\n if (state.status !== 'generating') return null\n if (state.compaction?.status === 'running') return 'compacting'\n const responseId =\n state.activeGeneration?.responseMessageId ??\n state.activeResponseMessageId ??\n state.activeProjection?.responseMessageId\n const response =\n responseId === undefined || responseId === null\n ? undefined\n : state.messages.findLast((message) => message.id === responseId)\n // A requested step that has not started has produced nothing yet.\n if (\n response === undefined ||\n (state.activeGeneration === null && state.activeResponseMessageId !== null)\n )\n return 'thinking'\n const projection = state.activeProjection\n // A started step's own output begins after its base; before its first chunk\n // the previous step's parts are not this step's progress.\n const start =\n state.activeGeneration !== null &&\n projection?.generationId === state.activeGeneration.generationId &&\n projection.base !== undefined\n ? projection.base.partCount\n : response.parts.findLastIndex((part) => part.type === 'step-start') + 1\n return response.parts.slice(start).some(visible) ? null : 'thinking'\n}\n\nconst userMessage = <M extends UIMessage>(message: string | M): M =>\n typeof message === 'string'\n ? ({\n id: crypto.randomUUID(),\n role: 'user',\n parts: [{ type: 'text', text: message }],\n } as UIMessage as M)\n : message\n\nexport function withAgentActions<D extends EventDefs, S extends AIState>(\n session: UseSessionResult<D, S>,\n): UseAgentResult<D, S> {\n type M = InputOf<S>\n const { state, index, push } = session\n const send = (\n events: { type: 'ai.control.requested'; payload: unknown }[],\n ): PushResult<D> =>\n events.length === 0\n ? Object.assign(Promise.resolve([]), {\n confirmed: Promise.resolve([]),\n })\n : push(...(events as AppendInput<D>[]))\n const active = state.active\n // `index` is this render's frontier: Stop freezes the response the user\n // saw, not whatever arrived before the click was handled.\n const lastSeenIndex = index\n const actions: AgentActions<D, M> = {\n sendMessage: (message, options) =>\n send(inputs.message(userMessage(message), options)),\n steer: (message) =>\n send(\n active === null\n ? inputs.message(userMessage(message))\n : inputs.steer({\n turnId: active.turnId,\n message: userMessage(message),\n lastSeenIndex,\n }),\n ),\n stop: () =>\n send(\n active === null\n ? []\n : inputs.stop({ turnId: active.turnId, lastSeenIndex }),\n ),\n approve: (approval) =>\n send(inputs.approval({ ...approvalOwner(approval), approved: true })),\n deny: (approval, options) =>\n send(\n inputs.approval({\n ...approvalOwner(approval),\n approved: false,\n ...(options?.reason === undefined ? {} : { reason: options.reason }),\n }),\n ),\n respond: (input, value) =>\n send(\n inputs.input({\n requestId: input.requestId,\n messageId: input.messageId,\n generationId: input.generationId,\n inputId: input.inputId,\n name: input.name,\n value,\n }),\n ),\n retry: () => {\n const responseMessageId = state.activeProjection?.responseMessageId\n return send(\n state.status !== 'failed' ||\n active === null ||\n responseMessageId === undefined\n ? []\n : inputs.retry({\n messageId: active.input.id,\n responseMessageId,\n retryId: crypto.randomUUID(),\n }),\n )\n },\n pause: (options) => send(inputs.pause(options)),\n resume: () => send(inputs.resume()),\n queue: {\n edit: (message) => send(inputs.queue.edit({ message })),\n move: (options) => send(inputs.queue.move(options)),\n remove: (inputId) => send(inputs.queue.remove({ inputId })),\n sendNow: (inputId) =>\n send(\n inputs.queue.sendNow({\n inputId,\n turnId: active?.turnId ?? null,\n lastSeenIndex,\n }),\n ),\n },\n }\n return {\n ...session,\n ...actions,\n messages: state.messages,\n status: state.status,\n indicator: indicatorOf(state as AIState),\n }\n}\n\nconst approvalOwner = (\n approval: PendingApproval,\n): Pick<\n PendingApproval,\n 'requestId' | 'messageId' | 'generationId' | 'approvalId'\n> => ({\n requestId: approval.requestId,\n messageId: approval.messageId,\n generationId: approval.generationId,\n approvalId: approval.approvalId,\n})\n","'use client'\n/**\n * experimental-a2/ai/react — one hook for an agent session: its live\n * optimistic `AIState`, and actions that fill in protocol identities.\n *\n * ```tsx\n * import type { assistant } from '@/server/assistant' // erased at build\n * const { messages, indicator, sendMessage, stop } =\n * useAgent<typeof assistant>({ api: '/api/agent', id, initial })\n * ```\n *\n * With a shared `agentContract()`, pass it as `contract` to fold its\n * application state in the browser too.\n */\n\nimport type { AIEventDefs, AIState } from './ai.ts'\nimport { withAgentActions, type UseAgentResult } from './ai-agent-actions.ts'\nimport {\n createAgentClient,\n type AgentClient,\n type AgentMessage,\n type AnyAgent,\n} from './ai-client.ts'\nimport type { Contract, EventDefs } from './contract.ts'\nimport type { InitialSnapshot } from './initial-snapshot.ts'\nimport { createClient, type A2Client } from './client.ts'\nimport type { Reducer } from './reducer.ts'\nimport { useSession, type UseSessionResult } from './react.ts'\n\nexport type UseAgentOptions<A extends AnyAgent> = {\n /** The session id. */\n id: string\n /** The server-rendered `assistant.session(id).state()`. */\n initial?: InitialSnapshot<AIState<AgentMessage<A>>>\n participant?: string\n} & (\n | {\n /** The route serving the agent's `fetch`; its client is shared. */\n api: string\n contract?: never\n }\n | { client: AgentClient<A> }\n)\n\n/**\n * Use a session of an agent served from a shared `agentContract()`, folding\n * its application state in the browser. The contract is a real import here.\n */\nexport type UseContractAgentOptions<D extends EventDefs, S extends AIState> = {\n /** The session id. */\n id: string\n /** The server-rendered `agent.session(id).state()`. */\n initial?: InitialSnapshot<S>\n participant?: string\n} & (\n | {\n /** The route serving the agent's `fetch`; its client is shared. */\n api: string\n contract: Contract<D, Record<never, never>, Reducer<D, S>>\n }\n | {\n /** `createClient({ contract, api })`, shared with pushes outside React. */\n client: A2Client<D, S>\n }\n)\n\nconst clients = new Map<string, AgentClient>()\nconst contractClients = new WeakMap<object, Map<string, object>>()\n\n/**\n * One client per route for the page's lifetime; its idle sessions expire\n * after the default `gcTime`. It reads `globalThis.fetch` per request, so\n * instrumentation installed later still applies.\n */\nconst clientFor = (api: string): AgentClient => {\n let client = clients.get(api)\n if (client === undefined) {\n client = createAgentClient({\n api,\n fetch: (input, init) => globalThis.fetch(input, init),\n })\n clients.set(api, client)\n }\n return client\n}\n\n/** One client per contract and route, like `clientFor`. */\nconst contractClientFor = <D extends EventDefs, S>(\n contract: Contract<D, Record<never, never>, Reducer<D, S>>,\n api: string,\n): A2Client<D, S> => {\n let byApi = contractClients.get(contract)\n if (byApi === undefined) {\n byApi = new Map()\n contractClients.set(contract, byApi)\n }\n let client = byApi.get(api) as A2Client<D, S> | undefined\n if (client === undefined) {\n client = createClient({\n contract,\n api,\n fetch: (input, init) => globalThis.fetch(input, init),\n })\n byApi.set(api, client)\n }\n return client\n}\n\n/** Use a session of an agent served from a shared `agentContract()`. */\nexport function useAgent<D extends EventDefs, S extends AIState>(\n options: UseContractAgentOptions<D, S>,\n): UseAgentResult<D, S>\n/**\n * Use one agent session. Pass `typeof` the server's `agent()` for its\n * message types; the import is type-only and erased.\n */\nexport function useAgent<A extends AnyAgent = AnyAgent>(\n options: UseAgentOptions<A>,\n): UseAgentResult<AIEventDefs<AgentMessage<A>>, AIState<AgentMessage<A>>>\nexport function useAgent(\n options:\n UseAgentOptions<AnyAgent> | UseContractAgentOptions<AIEventDefs, AIState>,\n): object {\n const session: UseSessionResult<AIEventDefs, AIState> = useSession(\n 'client' in options\n ? options.client\n : options.contract !== undefined\n ? contractClientFor(options.contract, options.api)\n : clientFor(options.api),\n options.id,\n {\n ...(options.initial === undefined ? {} : { initial: options.initial }),\n ...(options.participant === undefined\n ? {}\n : { participant: options.participant }),\n },\n )\n return withAgentActions(session)\n}\n\nexport type { AgentClient, AgentMessage, AnyAgent }\nexport type {\n AgentActions,\n AgentIndicator,\n UseAgentResult,\n} from './ai-agent-actions.ts'\n"],"mappings":";;;;;;AAkEA,MAAM,WAAW,SACf,KAAK,SAAS,SACV,KAAK,KAAK,SAAS,IACnB,KAAK,SAAS,eACd,KAAK,SAAS,gBACd,CAAC,iBAAiB,IAAI;AAE5B,MAAM,eAAe,UAAmC;CACtD,IAAI,MAAM,UAAU,OAAO;CAC3B,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,cAII;CACJ,WAAW,SAAS;CACpB,WAAW,SAAS;CACpB,cAAc,SAAS;CACvB,YAAY,SAAS;AACvB;;;ACxJA,MAAM,0BAAU,IAAI,IAAyB;AAC7C,MAAM,kCAAkB,IAAI,QAAqC;;;;;;AAOjE,MAAM,aAAa,QAA6B;CAC9C,IAAI,SAAS,QAAQ,IAAI,GAAG;CAC5B,IAAI,WAAW,KAAA,GAAW;EACxB,SAAS,kBAAkB;GACzB;GACA,QAAQ,OAAO,SAAS,WAAW,MAAM,OAAO,IAAI;EACtD,CAAC;EACD,QAAQ,IAAI,KAAK,MAAM;CACzB;CACA,OAAO;AACT;;AAGA,MAAM,qBACJ,UACA,QACmB;CACnB,IAAI,QAAQ,gBAAgB,IAAI,QAAQ;CACxC,IAAI,UAAU,KAAA,GAAW;EACvB,wBAAQ,IAAI,IAAI;EAChB,gBAAgB,IAAI,UAAU,KAAK;CACrC;CACA,IAAI,SAAS,MAAM,IAAI,GAAG;CAC1B,IAAI,WAAW,KAAA,GAAW;EACxB,SAAS,aAAa;GACpB;GACA;GACA,QAAQ,OAAO,SAAS,WAAW,MAAM,OAAO,IAAI;EACtD,CAAC;EACD,MAAM,IAAI,KAAK,MAAM;CACvB;CACA,OAAO;AACT;AAaA,SAAgB,SACd,SAEQ;CAeR,OAAO,iBAdiD,WACtD,YAAY,UACR,QAAQ,SACR,QAAQ,aAAa,KAAA,IACnB,kBAAkB,QAAQ,UAAU,QAAQ,GAAG,IAC/C,UAAU,QAAQ,GAAG,GAC3B,QAAQ,IACR;EACE,GAAI,QAAQ,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ;EACpE,GAAI,QAAQ,gBAAgB,KAAA,IACxB,CAAC,IACD,EAAE,aAAa,QAAQ,YAAY;CACzC,CAEsB,CAAO;AACjC"}
@@ -1,6 +1,6 @@
1
1
  //#region src/ai-server.browser.ts
2
- /** experimental-a2/ai/server is server-only; agent definitions live in experimental-a2/ai. */
3
- throw new Error("experimental-a2/ai/server is server-only — a client bundle imported it. Import agent from experimental-a2/ai in browser code instead.");
2
+ /** experimental-a2/ai/server is server-only; browsers use experimental-a2/ai/react or /ai/client. */
3
+ throw new Error("experimental-a2/ai/server is server-only — a client bundle imported it. Import its agent's type with `import type`, and use experimental-a2/ai/react or experimental-a2/ai/client in browser code.");
4
4
  //#endregion
5
5
 
6
6
  //# sourceMappingURL=ai-server.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai-server.browser.js","names":[],"sources":["../src/ai-server.browser.ts"],"sourcesContent":["/** experimental-a2/ai/server is server-only; agent definitions live in experimental-a2/ai. */\nthrow new Error(\n 'experimental-a2/ai/server is server-only — a client bundle imported it. Import agent from experimental-a2/ai in browser code instead.',\n)\nexport {}\n"],"mappings":";;AACA,MAAM,IAAI,MACR,uIACF"}
1
+ {"version":3,"file":"ai-server.browser.js","names":[],"sources":["../src/ai-server.browser.ts"],"sourcesContent":["/** experimental-a2/ai/server is server-only; browsers use experimental-a2/ai/react or /ai/client. */\nthrow new Error(\n \"experimental-a2/ai/server is server-only — a client bundle imported it. Import its agent's type with `import type`, and use experimental-a2/ai/react or experimental-a2/ai/client in browser code.\",\n)\nexport {}\n"],"mappings":";;AACA,MAAM,IAAI,MACR,oMACF"}
@@ -1,6 +1,6 @@
1
- import { a as ContractEvent, s as EventDefs } from "./reducer-otzHjuJj.js";
2
- import { n as A2Server, p as ServerOptions, s as HandlerContext } from "./server-DbD7IJVK.js";
3
- import { l as AgentToolContext, o as AgentDefinition, t as AIEventDefs, u as AgentToolEventDefs } from "./ai-CrEf6p_W.js";
1
+ import { c as ContractEvent, s as Contract, t as Reducer, u as EventDefs, v as StandardSchemaV1 } from "./reducer-BYu6DT7h.js";
2
+ import { n as A2Server, p as ServerOptions, s as HandlerContext } from "./server-CGM8WzRG.js";
3
+ import { H as ReasoningLevel, a as AI_STATE_REDUCER, f as AgentToolContext, i as AIState, p as AgentToolEventDefs, r as AIMessageOf, t as AIEventDefs } from "./ai-vpGtcaCB.js";
4
4
  import { Instructions, LanguageModel, ModelMessage, TextStreamPart, ToolSet, ToolSet as ToolSet$1, UIMessage, UIMessageChunk, streamText } from "ai";
5
5
  //#region src/ai-sdk-step.d.ts
6
6
  type StreamTextOptions<T extends ToolSet$1> = Parameters<typeof streamText<T>>[0];
@@ -37,39 +37,46 @@ type AISDKStepSettings<T extends ToolSet$1> = Partial<Omit<StreamTextOptions<T>,
37
37
  experimental_transform?: ModelPhaseTransform<T> | Array<ModelPhaseTransform<T>>;
38
38
  };
39
39
  //#endregion
40
- //#region src/ai-server.d.ts
41
- type AgentGenerateContext<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet> = {
42
- request: ContractEvent<D, "ai.generation.requested">;
43
- requestId: string;
40
+ //#region src/ai-agent.d.ts
41
+ type AgentGenerateContext<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet, X extends object = Record<never, never>> = AgentResolverContext<M, D, X> & {
44
42
  generationId: string;
45
- responseMessageId: string;
46
- messages: M[];
47
43
  modelMessages: ModelMessage[];
48
- session: Pick<HandlerContext<D>["session"], "state">;
49
- signal: AbortSignal;
50
44
  model: LanguageModel;
51
45
  tools: T;
52
46
  instructions?: Instructions;
53
47
  generation: AgentGenerationSettings<T>;
54
48
  };
55
- type AgentGenerate<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet> = (context: AgentGenerateContext<M, D, T>) => ReadableStream<UIMessageChunk> | Promise<ReadableStream<UIMessageChunk>>;
49
+ type AgentGenerate<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet, X extends object = Record<never, never>> = (context: AgentGenerateContext<M, D, T, X>) => ReadableStream<UIMessageChunk> | Promise<ReadableStream<UIMessageChunk>>;
56
50
  type UIMessageMetadata<M extends UIMessage> = M extends UIMessage<infer Metadata> ? Metadata : unknown;
57
- type AgentMessageMetadata<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet> = (context: AgentGenerateContext<M, D, T> & {
51
+ type AgentMessageMetadata<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet, X extends object = Record<never, never>> = (context: AgentGenerateContext<M, D, T, X> & {
58
52
  part: TextStreamPart<T>;
59
53
  }) => UIMessageMetadata<M> | undefined;
60
- type AgentResolverContext<M extends UIMessage, D extends AIEventDefs<M> & EventDefs> = {
54
+ type AgentResolverContext<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, X extends object = Record<never, never>> = {
61
55
  event: ContractEvent<D, "ai.generation.requested">;
62
56
  messages: M[];
57
+ /**
58
+ * The contract's application state, as of the captured snapshot. It rides
59
+ * in the checkpoint the generation already reads, so it costs no I/O.
60
+ */
61
+ state: X;
63
62
  session: Pick<HandlerContext<D>["session"], "state">;
64
63
  signal: AbortSignal;
65
64
  };
66
65
  type Resolvable<T, C> = T | ((context: C) => T | Promise<T>);
67
- type CompactionPolicy<M extends UIMessage, D extends AIEventDefs<M> & EventDefs> = {
68
- shouldCompact(context: AgentResolverContext<M, D> & {
66
+ /** A model with its reasoning level and speed, chosen together. */
67
+ type ModelSettings = {
68
+ model: LanguageModel;
69
+ /** Overrides `generation.reasoning`. */
70
+ reasoning?: ReasoningLevel;
71
+ /** `fast` prefers AI Gateway's faster tier when the model offers one. */
72
+ speed?: "fast" | "standard";
73
+ };
74
+ type CompactionPolicy<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, X extends object = Record<never, never>> = {
75
+ shouldCompact(context: AgentResolverContext<M, D, X> & {
69
76
  messages: M[];
70
77
  modelMessages: ModelMessage[];
71
78
  }): boolean | Promise<boolean>;
72
- compact(context: AgentResolverContext<M, D> & {
79
+ compact(context: AgentResolverContext<M, D, X> & {
73
80
  messages: M[];
74
81
  modelMessages: ModelMessage[];
75
82
  }): M[] | Promise<M[]>;
@@ -78,46 +85,83 @@ type AutomaticCompaction = {
78
85
  thresholdTokens?: number;
79
86
  instructions?: string;
80
87
  };
81
- type CompactionOptions<M extends UIMessage, D extends AIEventDefs<M> & EventDefs> = false | AutomaticCompaction | CompactionPolicy<M, D>;
88
+ type CompactionOptions<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, X extends object = Record<never, never>> = false | AutomaticCompaction | CompactionPolicy<M, D, X>;
82
89
  type AgentGenerationSettings<T extends ToolSet> = AISDKStepSettings<T>;
83
- type CreateHandlersOptions<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet = ToolSet> = {
84
- agent: AgentDefinition<M, D>;
85
- /** AI SDK model string or provider model, optionally resolved per generation. */
86
- model: Resolvable<LanguageModel, AgentResolverContext<M, D>>;
90
+ type AgentModelOptions<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet = ToolSet, X extends object = Record<never, never>> = {
91
+ /**
92
+ * AI SDK model string or provider model, or `ModelSettings` to choose its
93
+ * reasoning level and speed with it, optionally resolved per generation.
94
+ */
95
+ model: Resolvable<LanguageModel | ModelSettings, AgentResolverContext<M, D, X>>;
87
96
  tools?: T;
88
- instructions?: Resolvable<Instructions | undefined, AgentResolverContext<M, D>>;
89
- /** Settings for each one-step AI SDK streamText call. */
90
- generation?: AgentGenerationSettings<T>;
97
+ instructions?: Resolvable<Instructions | undefined, AgentResolverContext<M, D, X>>;
98
+ /** Settings for each one-step AI SDK streamText call, resolved per generation. */
99
+ generation?: Resolvable<AgentGenerationSettings<T>, AgentResolverContext<M, D, X>>;
91
100
  /**
92
101
  * Maximum model steps in one assistant response. Defaults to Infinity.
93
102
  */
94
103
  maxSteps?: number;
95
104
  /** Map default AI SDK stream parts to typed assistant message metadata. */
96
- messageMetadata?: AgentMessageMetadata<M, D, T>;
105
+ messageMetadata?: AgentMessageMetadata<M, D, T, X>;
97
106
  /**
98
107
  * Replace model generation with an AI SDK UI message chunk stream.
99
108
  * The custom stream owns its metadata chunks.
100
109
  */
101
- generate?: AgentGenerate<M, D, T>;
102
- compaction?: Resolvable<CompactionOptions<M, D>, AgentResolverContext<M, D>>;
110
+ generate?: AgentGenerate<M, D, T, X>;
111
+ compaction?: Resolvable<CompactionOptions<M, D, X>, AgentResolverContext<M, D, X>>;
103
112
  /** Progress is durably flushed at either limit, whichever is reached first. */
104
113
  progress?: {
105
114
  maxChunks?: number;
106
115
  maxDelayMs?: number;
107
116
  };
117
+ /**
118
+ * Run local tool executions one at a time on this lane. By default,
119
+ * independent tools run concurrently.
120
+ */
121
+ toolLane?: string;
108
122
  };
109
- type CreateAgentServerOptions<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet = ToolSet> = CreateHandlersOptions<M, D, T> & Omit<ServerOptions<D>, "contract" | "handlers"> & {
110
- handlers?: ServerOptions<D>["handlers"];
123
+ type AgentServerOptions<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, S, T extends ToolSet, X extends object = Record<never, never>> = AgentModelOptions<M, D, T, X> & Omit<ServerOptions<D, Record<never, never>, Reducer<D, S>>, "contract" | "handlers"> & {
124
+ /** Handlers for application events. */
125
+ handlers?: ServerOptions<D, Record<never, never>, Reducer<D, S>>["handlers"];
111
126
  };
127
+ type AgentOptions<M extends UIMessage, E extends EventDefs, T extends ToolSet> = AgentServerOptions<NoInfer<M>, AIEventDefs<NoInfer<M>> & E, AIState<NoInfer<M>>, T> & {
128
+ /** Identity: prefixes storage keys and queue messages. */
129
+ name: string;
130
+ /**
131
+ * Server-only application events. Browsers push application events through
132
+ * a shared `agentContract()`.
133
+ */
134
+ events?: E;
135
+ /** Optional stricter schema for custom UIMessage metadata/data/tool types. */
136
+ messageSchema?: StandardSchemaV1<M>;
137
+ };
138
+ type AgentFromContractOptions<D extends AIEventDefs<AIMessageOf<D>> & EventDefs, S, T extends ToolSet, Name extends string = string, X extends object = Record<never, never>> = AgentServerOptions<AIMessageOf<D>, D, S, T, X> & {
139
+ /**
140
+ * A shared `agentContract()`. Its application state reaches every resolver
141
+ * as `state`; a fully custom contract is core A2, served by `createServer()`.
142
+ */
143
+ contract: Contract<D, Record<never, never>, Reducer<D, S> & {
144
+ readonly name: Name;
145
+ readonly "~appState": X;
146
+ }>;
147
+ };
148
+ /**
149
+ * An A2 server for the AI protocol; `typeof` it types `useAgent`. `Name` is
150
+ * its reducer's name: the built-in one lets contract-free clients fold state.
151
+ */
152
+ type Agent<D extends EventDefs, S, Name extends string = string> = A2Server<D, Record<never, never>, Reducer<D, S> & {
153
+ readonly name: Name;
154
+ }>;
112
155
  /** Run `fn` with `ctx` as the ambient tool handler context, for direct tool tests. */
113
156
  declare function runWithHandlerContext<D extends AgentToolEventDefs, R>(ctx: AgentToolContext<D>, fn: () => R): R;
114
157
  /**
115
- * Build the ordinary A2 handler table for the built-in agent protocol.
116
- * Application handlers can be spread beside this table.
158
+ * Serve an AI agent: the built-in protocol, its handlers, and A2's store,
159
+ * scheduler, and telemetry, as one ordinary A2 server. Pass `name` for the
160
+ * built-in protocol, or a shared `agentContract()` when clients fold
161
+ * application state.
117
162
  */
118
- declare function createHandlers<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet = ToolSet>(options: CreateHandlersOptions<M, D, T>): NonNullable<ServerOptions<D>["handlers"]>;
119
- /** Assemble an A2 server with the built-in agent handlers and app extensions. */
120
- declare function createAgentServer<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet = ToolSet>(options: CreateAgentServerOptions<M, D, T>): A2Server<D>;
163
+ declare function agent<T extends ToolSet = ToolSet, M extends UIMessage = UIMessage, E extends EventDefs = Record<never, never>>(options: AgentOptions<M, E, T>): Agent<AIEventDefs<M> & E, AIState<M>, typeof AI_STATE_REDUCER>;
164
+ declare function agent<D extends AIEventDefs<AIMessageOf<D>> & EventDefs, S, T extends ToolSet = ToolSet, Name extends string = string, X extends object = Record<never, never>>(options: AgentFromContractOptions<D, S, T, Name, X>): Agent<D, S, Name>;
121
165
  //#endregion
122
- export { AgentGenerate, AgentGenerateContext, AgentGenerationSettings, AgentMessageMetadata, AgentResolverContext, AutomaticCompaction, CompactionOptions, CompactionPolicy, CreateAgentServerOptions, CreateHandlersOptions, type Instructions, type LanguageModel, Resolvable, type ToolSet, createAgentServer, createHandlers, runWithHandlerContext };
166
+ export { type Agent, type AgentFromContractOptions, type AgentGenerate, type AgentGenerateContext, type AgentGenerationSettings, type AgentMessageMetadata, type AgentModelOptions, type AgentOptions, type AgentResolverContext, type AutomaticCompaction, type CompactionOptions, type CompactionPolicy, type Instructions, type LanguageModel, type ModelSettings, type Resolvable, type ToolSet, agent, runWithHandlerContext };
123
167
  //# sourceMappingURL=ai-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai-server.d.ts","names":[],"sources":["../src/ai-sdk-step.ts","../src/ai-server.ts"],"mappings":";;;;;KAkBK,kBAAkB,UAAU,aAAW,kBAAkB,WAAW;KAKpE,iBAAiB,UAAU,sBAE5B,KACE,QAAQ,kBAAkB;KAI3B;KAmBA;KASA,iBAAiB,UAAU,yBACpB,WAAW,IAAI,KAAK,EAAE;KAG7B,aAAa,UAAU,WAAS,gBAAgB,kBAAkB,MACrE,YAAY,kBAAkB,GAAG,cAAa,aAAa,qBACvD;KAGD,qBAAqB,UAAU,aAAW,KAC7C,aAAa;WAGJ,OAAO,iBAAiB;;KAG9B,yBAAyB,UAAU,aAAW,KACjD,aAAa;WAGJ,OAAO,iBAAiB;;KAG9B,mBAAmB,UAAU,OAAO,iBAAiB;KAErD,yBAAyB,UAAU,aAAW,YACjD,kBAAkB;KAGf,yBAAyB,UAAU,cACtC,SAAS,KAAK,WAAW,yBAAyB;EAChD,OAAO,iBAAiB;MAEvB,WAAW,yBAAyB;KAEpC,2BAA2B,UAAU,aAAW,YACnD,kBAAkB;KAGf,oBAAoB,UAAU,aAAW,QAC5C,2BAA2B,QACvB;KAGD,oBAAoB,UAAU,cACjC,SAAS,KAAK,WAAW,oBAAoB;EAC3C,OAAO,iBAAiB;MAEvB,WAAW,oBAAoB;;KAGxB,kBAAkB,UAAU,aAAW,QACjD,KACE,kBAAkB,IAClB,8BAA8B;EAGhC,UAAU,iBAAiB;EAC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