@athenaintel/react 0.41.3 → 0.42.2

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 (479) hide show
  1. package/README.md +132 -10
  2. package/dist/agent-runtime/src/asset-attachment.d.ts +98 -0
  3. package/dist/agent-runtime/src/athena-asset-drag.d.ts +32 -0
  4. package/dist/agent-runtime/src/auth-denial.d.ts +29 -0
  5. package/dist/agent-runtime/src/chat-outbox-attachments.cjs +41 -0
  6. package/dist/agent-runtime/src/chat-outbox-attachments.cjs.map +1 -0
  7. package/dist/agent-runtime/src/chat-outbox-attachments.d.ts +38 -0
  8. package/dist/agent-runtime/src/chat-outbox-attachments.js +41 -0
  9. package/dist/agent-runtime/src/chat-outbox-attachments.js.map +1 -0
  10. package/dist/agent-runtime/src/chat-outbox-signals.cjs +63 -0
  11. package/dist/agent-runtime/src/chat-outbox-signals.cjs.map +1 -0
  12. package/dist/agent-runtime/src/chat-outbox-signals.d.ts +12 -0
  13. package/dist/agent-runtime/src/chat-outbox-signals.js +63 -0
  14. package/dist/agent-runtime/src/chat-outbox-signals.js.map +1 -0
  15. package/dist/agent-runtime/src/chat-outbox-store.cjs +509 -0
  16. package/dist/agent-runtime/src/chat-outbox-store.cjs.map +1 -0
  17. package/dist/agent-runtime/src/chat-outbox-store.d.ts +203 -0
  18. package/dist/agent-runtime/src/chat-outbox-store.js +509 -0
  19. package/dist/agent-runtime/src/chat-outbox-store.js.map +1 -0
  20. package/dist/agent-runtime/src/chat-outbox-thread.cjs +136 -0
  21. package/dist/agent-runtime/src/chat-outbox-thread.cjs.map +1 -0
  22. package/dist/agent-runtime/src/chat-outbox-thread.d.ts +118 -0
  23. package/dist/agent-runtime/src/chat-outbox-thread.js +136 -0
  24. package/dist/agent-runtime/src/chat-outbox-thread.js.map +1 -0
  25. package/dist/agent-runtime/src/chat-outbox.cjs +696 -0
  26. package/dist/agent-runtime/src/chat-outbox.cjs.map +1 -0
  27. package/dist/agent-runtime/src/chat-outbox.d.ts +285 -0
  28. package/dist/agent-runtime/src/chat-outbox.js +696 -0
  29. package/dist/agent-runtime/src/chat-outbox.js.map +1 -0
  30. package/dist/agent-runtime/src/chat-socket-reachability.d.ts +45 -0
  31. package/dist/agent-runtime/src/client-tool-bridge.d.ts +152 -0
  32. package/dist/agent-runtime/src/client-tools.d.ts +133 -0
  33. package/dist/agent-runtime/src/composer-markdown.cjs +10 -0
  34. package/dist/agent-runtime/src/composer-markdown.cjs.map +1 -1
  35. package/dist/agent-runtime/src/composer-markdown.d.ts +108 -0
  36. package/dist/agent-runtime/src/composer-markdown.js +10 -0
  37. package/dist/agent-runtime/src/composer-markdown.js.map +1 -1
  38. package/dist/agent-runtime/src/config-mutations.d.ts +51 -0
  39. package/dist/agent-runtime/src/conversation-index.d.ts +110 -0
  40. package/dist/agent-runtime/src/conversation-list.d.ts +343 -0
  41. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs +3 -2
  42. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs.map +1 -1
  43. package/dist/agent-runtime/src/deep-agent-transport-recipe.d.ts +166 -0
  44. package/dist/agent-runtime/src/deep-agent-transport-recipe.js +3 -2
  45. package/dist/agent-runtime/src/deep-agent-transport-recipe.js.map +1 -1
  46. package/dist/agent-runtime/src/desktop-handoff.d.ts +139 -0
  47. package/dist/agent-runtime/src/durable-thread-snapshot-cache.d.ts +60 -0
  48. package/dist/agent-runtime/src/edit-command.d.ts +156 -0
  49. package/dist/agent-runtime/src/errors.d.ts +174 -0
  50. package/dist/agent-runtime/src/execute-output.d.ts +31 -0
  51. package/dist/agent-runtime/src/generated/runconfig-contract.cjs +16 -2
  52. package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  53. package/dist/agent-runtime/src/generated/runconfig-contract.d.ts +202 -0
  54. package/dist/agent-runtime/src/generated/runconfig-contract.js +16 -2
  55. package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  56. package/dist/agent-runtime/src/github-wake-event.d.ts +77 -0
  57. package/dist/agent-runtime/src/index.d.ts +74 -0
  58. package/dist/agent-runtime/src/interrupts.cjs +17 -0
  59. package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
  60. package/dist/agent-runtime/src/interrupts.d.ts +348 -0
  61. package/dist/agent-runtime/src/interrupts.js +17 -0
  62. package/dist/agent-runtime/src/interrupts.js.map +1 -1
  63. package/dist/agent-runtime/src/lane-follow.d.ts +121 -0
  64. package/dist/agent-runtime/src/lane-history.cjs +209 -0
  65. package/dist/agent-runtime/src/lane-history.cjs.map +1 -0
  66. package/dist/agent-runtime/src/lane-history.d.ts +175 -0
  67. package/dist/agent-runtime/src/lane-history.js +209 -0
  68. package/dist/agent-runtime/src/lane-history.js.map +1 -0
  69. package/dist/agent-runtime/src/lane-images.d.ts +184 -0
  70. package/dist/agent-runtime/src/message-author.d.ts +43 -0
  71. package/dist/agent-runtime/src/message-text.cjs +15 -0
  72. package/dist/agent-runtime/src/message-text.cjs.map +1 -0
  73. package/dist/agent-runtime/src/message-text.d.ts +47 -0
  74. package/dist/agent-runtime/src/message-text.js +15 -0
  75. package/dist/agent-runtime/src/message-text.js.map +1 -0
  76. package/dist/agent-runtime/src/message-window.cjs +15 -1
  77. package/dist/agent-runtime/src/message-window.cjs.map +1 -1
  78. package/dist/agent-runtime/src/message-window.d.ts +159 -0
  79. package/dist/agent-runtime/src/message-window.js +16 -2
  80. package/dist/agent-runtime/src/message-window.js.map +1 -1
  81. package/dist/agent-runtime/src/messages.cjs +123 -8
  82. package/dist/agent-runtime/src/messages.cjs.map +1 -1
  83. package/dist/agent-runtime/src/messages.d.ts +621 -0
  84. package/dist/agent-runtime/src/messages.js +123 -8
  85. package/dist/agent-runtime/src/messages.js.map +1 -1
  86. package/dist/agent-runtime/src/model-context.d.ts +22 -0
  87. package/dist/agent-runtime/src/offline-status.d.ts +157 -0
  88. package/dist/agent-runtime/src/optimistic-content.d.ts +21 -0
  89. package/dist/agent-runtime/src/protocol.cjs +12 -4
  90. package/dist/agent-runtime/src/protocol.cjs.map +1 -1
  91. package/dist/agent-runtime/src/protocol.d.ts +119 -0
  92. package/dist/agent-runtime/src/protocol.js +13 -5
  93. package/dist/agent-runtime/src/protocol.js.map +1 -1
  94. package/dist/agent-runtime/src/ptc-subcalls.d.ts +51 -0
  95. package/dist/agent-runtime/src/queue.d.ts +138 -0
  96. package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs +10 -0
  97. package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs.map +1 -1
  98. package/dist/agent-runtime/src/quota-safe-local-storage-session.d.ts +161 -0
  99. package/dist/agent-runtime/src/quota-safe-local-storage-session.js +10 -0
  100. package/dist/agent-runtime/src/quota-safe-local-storage-session.js.map +1 -1
  101. package/dist/agent-runtime/src/running-tool-placeholder.cjs +11 -0
  102. package/dist/agent-runtime/src/running-tool-placeholder.cjs.map +1 -0
  103. package/dist/agent-runtime/src/running-tool-placeholder.d.ts +25 -0
  104. package/dist/agent-runtime/src/running-tool-placeholder.js +11 -0
  105. package/dist/agent-runtime/src/running-tool-placeholder.js.map +1 -0
  106. package/dist/agent-runtime/src/runtime-messages.d.ts +104 -0
  107. package/dist/agent-runtime/src/screen-point.d.ts +151 -0
  108. package/dist/agent-runtime/src/sealed-idb.cjs +112 -0
  109. package/dist/agent-runtime/src/sealed-idb.cjs.map +1 -0
  110. package/dist/agent-runtime/src/sealed-idb.d.ts +106 -0
  111. package/dist/agent-runtime/src/sealed-idb.js +112 -0
  112. package/dist/agent-runtime/src/sealed-idb.js.map +1 -0
  113. package/dist/agent-runtime/src/send-recovery.d.ts +40 -0
  114. package/dist/agent-runtime/src/session-lane-scope.cjs +25 -0
  115. package/dist/agent-runtime/src/session-lane-scope.cjs.map +1 -0
  116. package/dist/agent-runtime/src/session-lane-scope.d.ts +59 -0
  117. package/dist/agent-runtime/src/session-lane-scope.js +25 -0
  118. package/dist/agent-runtime/src/session-lane-scope.js.map +1 -0
  119. package/dist/agent-runtime/src/statewire-attach-observer.d.ts +194 -0
  120. package/dist/agent-runtime/src/statewire-diagnostics.d.ts +74 -0
  121. package/dist/agent-runtime/src/statewire-state.d.ts +29 -0
  122. package/dist/agent-runtime/src/statewire-suspended.cjs.map +1 -1
  123. package/dist/agent-runtime/src/statewire-suspended.d.ts +27 -0
  124. package/dist/agent-runtime/src/statewire-suspended.js.map +1 -1
  125. package/dist/agent-runtime/src/statewire-transport.d.ts +40 -0
  126. package/dist/agent-runtime/src/streaming-markdown.d.ts +46 -0
  127. package/dist/agent-runtime/src/subagent-transcripts.cjs +209 -0
  128. package/dist/agent-runtime/src/subagent-transcripts.cjs.map +1 -0
  129. package/dist/agent-runtime/src/subagent-transcripts.d.ts +71 -0
  130. package/dist/agent-runtime/src/subagent-transcripts.js +209 -0
  131. package/dist/agent-runtime/src/subagent-transcripts.js.map +1 -0
  132. package/dist/agent-runtime/src/subagents.cjs +253 -0
  133. package/dist/agent-runtime/src/subagents.cjs.map +1 -0
  134. package/dist/agent-runtime/src/subagents.d.ts +311 -0
  135. package/dist/agent-runtime/src/subagents.js +253 -0
  136. package/dist/agent-runtime/src/subagents.js.map +1 -0
  137. package/dist/agent-runtime/src/subscription-wake-event.d.ts +111 -0
  138. package/dist/agent-runtime/src/thread-extras.d.ts +43 -0
  139. package/dist/agent-runtime/src/thread-handoff.d.ts +364 -0
  140. package/dist/agent-runtime/src/thread-prewarm-controller.d.ts +76 -0
  141. package/dist/agent-runtime/src/thread-prewarm.d.ts +118 -0
  142. package/dist/agent-runtime/src/thread-snapshot-cache.d.ts +99 -0
  143. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs +46 -117
  144. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs.map +1 -1
  145. package/dist/agent-runtime/src/thread-snapshot-mirror.d.ts +101 -0
  146. package/dist/agent-runtime/src/thread-snapshot-mirror.js +17 -88
  147. package/dist/agent-runtime/src/thread-snapshot-mirror.js.map +1 -1
  148. package/dist/agent-runtime/src/thread-status.d.ts +53 -0
  149. package/dist/agent-runtime/src/tool-metadata.d.ts +146 -0
  150. package/dist/agent-runtime/src/tool-names.cjs +71 -0
  151. package/dist/agent-runtime/src/tool-names.cjs.map +1 -1
  152. package/dist/agent-runtime/src/tool-names.d.ts +67 -0
  153. package/dist/agent-runtime/src/tool-names.js +72 -1
  154. package/dist/agent-runtime/src/tool-names.js.map +1 -1
  155. package/dist/agent-runtime/src/tool-outputs.d.ts +35 -0
  156. package/dist/agent-runtime/src/tool-result.cjs +1 -0
  157. package/dist/agent-runtime/src/tool-result.cjs.map +1 -1
  158. package/dist/agent-runtime/src/tool-result.d.ts +126 -0
  159. package/dist/agent-runtime/src/tool-result.js +1 -0
  160. package/dist/agent-runtime/src/tool-result.js.map +1 -1
  161. package/dist/agent-runtime/src/types.d.ts +159 -0
  162. package/dist/agent-runtime/src/use-conversation-list.d.ts +76 -0
  163. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +136 -0
  164. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -0
  165. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +64 -0
  166. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +136 -0
  167. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -0
  168. package/dist/agent-runtime/src/use-deep-agent-config.d.ts +169 -0
  169. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs +13 -0
  170. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs.map +1 -1
  171. package/dist/agent-runtime/src/use-deep-agent-edit-submit.d.ts +22 -0
  172. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js +13 -0
  173. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js.map +1 -1
  174. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +37 -2
  175. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  176. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +177 -0
  177. package/dist/agent-runtime/src/use-deep-agent-runtime.js +38 -3
  178. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  179. package/dist/agent-runtime/src/use-deep-agent-thread.cjs +39 -13
  180. package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
  181. package/dist/agent-runtime/src/use-deep-agent-thread.d.ts +352 -0
  182. package/dist/agent-runtime/src/use-deep-agent-thread.js +39 -13
  183. package/dist/agent-runtime/src/use-deep-agent-thread.js.map +1 -1
  184. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +1019 -0
  185. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -0
  186. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +409 -0
  187. package/dist/agent-runtime/src/use-deep-agent-voice.js +1019 -0
  188. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -0
  189. package/dist/agent-runtime/src/use-deep-agent-window-sync.d.ts +102 -0
  190. package/dist/agent-runtime/src/use-historical-edit-attachments.d.ts +2 -0
  191. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +84 -0
  192. package/dist/agent-runtime/src/voice-presentation.cjs +2 -0
  193. package/dist/agent-runtime/src/voice-presentation.cjs.map +1 -1
  194. package/dist/agent-runtime/src/voice-presentation.d.ts +80 -0
  195. package/dist/agent-runtime/src/voice-presentation.js +2 -0
  196. package/dist/agent-runtime/src/voice-presentation.js.map +1 -1
  197. package/dist/agent-runtime/src/voice-turn-grouping.d.ts +28 -0
  198. package/dist/agent-runtime/src/voice-wire-types.d.ts +15 -0
  199. package/dist/agent-runtime/src/withdrawn-turns.d.ts +97 -0
  200. package/dist/catalog/runtime-catalog.js +1 -1
  201. package/dist/chat/AthenaChat.cjs +192 -103
  202. package/dist/chat/AthenaChat.cjs.map +1 -1
  203. package/dist/chat/AthenaChat.d.ts +9 -0
  204. package/dist/chat/AthenaChat.js +194 -105
  205. package/dist/chat/AthenaChat.js.map +1 -1
  206. package/dist/chat/StatewireApprovalCard.d.ts +1 -1
  207. package/dist/chat/StatewireClientToolBridge.d.ts +1 -1
  208. package/dist/chat/StatewireQueuedMessages.cjs +11 -4
  209. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  210. package/dist/chat/StatewireQueuedMessages.d.ts +1 -1
  211. package/dist/chat/StatewireQueuedMessages.js +11 -4
  212. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  213. package/dist/chat/chat-outbox-rows.cjs +223 -0
  214. package/dist/chat/chat-outbox-rows.cjs.map +1 -0
  215. package/dist/chat/chat-outbox-rows.d.ts +29 -0
  216. package/dist/chat/chat-outbox-rows.js +223 -0
  217. package/dist/chat/chat-outbox-rows.js.map +1 -0
  218. package/dist/chat/chat-voice-controls.cjs +128 -0
  219. package/dist/chat/chat-voice-controls.cjs.map +1 -0
  220. package/dist/chat/chat-voice-controls.d.ts +19 -0
  221. package/dist/chat/chat-voice-controls.js +128 -0
  222. package/dist/chat/chat-voice-controls.js.map +1 -0
  223. package/dist/chat/statewire-approval.d.ts +1 -1
  224. package/dist/chat/statewire-client-tools.d.ts +1 -1
  225. package/dist/chat/super-grouping/SuperGroupingCard.cjs +3 -1
  226. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  227. package/dist/chat/super-grouping/SuperGroupingCard.d.ts +7 -1
  228. package/dist/chat/super-grouping/SuperGroupingCard.js +3 -1
  229. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  230. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +7 -2
  231. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  232. package/dist/chat/super-grouping/SuperGroupingTranscript.d.ts +2 -2
  233. package/dist/chat/super-grouping/SuperGroupingTranscript.js +7 -2
  234. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  235. package/dist/chat/super-grouping/activity-timeline.cjs +15 -8
  236. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  237. package/dist/chat/super-grouping/activity-timeline.d.ts +18 -8
  238. package/dist/chat/super-grouping/activity-timeline.js +15 -8
  239. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  240. package/dist/chat/use-statewire-approval-request.cjs +36 -0
  241. package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
  242. package/dist/chat/use-statewire-approval-request.d.ts +49 -1
  243. package/dist/chat/use-statewire-approval-request.js +39 -3
  244. package/dist/chat/use-statewire-approval-request.js.map +1 -1
  245. package/dist/chat-ui/composer/tiptap-composer.cjs +133 -14
  246. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  247. package/dist/chat-ui/composer/tiptap-composer.d.ts +33 -1
  248. package/dist/chat-ui/composer/tiptap-composer.js +135 -16
  249. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  250. package/dist/chat-ui/header/conversation-history-panel.d.ts +1 -1
  251. package/dist/chat-ui/index.d.ts +1 -1
  252. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs +2 -1
  253. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs.map +1 -1
  254. package/dist/chat-ui/mentions/suggestions/data/api-client.d.ts +3 -1
  255. package/dist/chat-ui/mentions/suggestions/data/api-client.js +2 -1
  256. package/dist/chat-ui/mentions/suggestions/data/api-client.js.map +1 -1
  257. package/dist/chat-ui/mentions/use-account-workspace-id.cjs +29 -51
  258. package/dist/chat-ui/mentions/use-account-workspace-id.cjs.map +1 -1
  259. package/dist/chat-ui/mentions/use-account-workspace-id.d.ts +2 -2
  260. package/dist/chat-ui/mentions/use-account-workspace-id.js +30 -52
  261. package/dist/chat-ui/mentions/use-account-workspace-id.js.map +1 -1
  262. package/dist/chat-ui/messages/message-components.cjs +15 -0
  263. package/dist/chat-ui/messages/message-components.cjs.map +1 -1
  264. package/dist/chat-ui/messages/message-components.js +15 -0
  265. package/dist/chat-ui/messages/message-components.js.map +1 -1
  266. package/dist/chat-ui/messages/runtime-message.d.ts +1 -1
  267. package/dist/chat-ui/messages/statewire-continue-run.d.ts +1 -1
  268. package/dist/chat-ui/messages/user-edit-composer.cjs +15 -2
  269. package/dist/chat-ui/messages/user-edit-composer.cjs.map +1 -1
  270. package/dist/chat-ui/messages/user-edit-composer.d.ts +4 -2
  271. package/dist/chat-ui/messages/user-edit-composer.js +15 -2
  272. package/dist/chat-ui/messages/user-edit-composer.js.map +1 -1
  273. package/dist/chat-ui/messages/wake-marker.d.ts +1 -1
  274. package/dist/chat-ui/rich-text/chat-text-schema.cjs +1 -0
  275. package/dist/chat-ui/rich-text/chat-text-schema.cjs.map +1 -1
  276. package/dist/chat-ui/rich-text/chat-text-schema.d.ts +3 -0
  277. package/dist/chat-ui/rich-text/chat-text-schema.js +1 -0
  278. package/dist/chat-ui/rich-text/chat-text-schema.js.map +1 -1
  279. package/dist/chat-ui/statewire.cjs +1 -0
  280. package/dist/chat-ui/statewire.cjs.map +1 -1
  281. package/dist/chat-ui/statewire.d.ts +2 -2
  282. package/dist/chat-ui/statewire.js +2 -1
  283. package/dist/chat-ui/thread/composer-send-or-stop.cjs +2 -1
  284. package/dist/chat-ui/thread/composer-send-or-stop.cjs.map +1 -1
  285. package/dist/chat-ui/thread/composer-send-or-stop.d.ts +2 -0
  286. package/dist/chat-ui/thread/composer-send-or-stop.js +2 -1
  287. package/dist/chat-ui/thread/composer-send-or-stop.js.map +1 -1
  288. package/dist/chat-ui/thread/statewire-history-edge.d.ts +1 -1
  289. package/dist/composer/AttachmentContext.cjs +8 -4
  290. package/dist/composer/AttachmentContext.cjs.map +1 -1
  291. package/dist/composer/AttachmentContext.d.ts +7 -0
  292. package/dist/composer/AttachmentContext.js +8 -4
  293. package/dist/composer/AttachmentContext.js.map +1 -1
  294. package/dist/composer/build-composed-message.cjs +34 -0
  295. package/dist/composer/build-composed-message.cjs.map +1 -1
  296. package/dist/composer/build-composed-message.d.ts +20 -0
  297. package/dist/composer/build-composed-message.js +35 -1
  298. package/dist/composer/build-composed-message.js.map +1 -1
  299. package/dist/composer/composer-handoff.cjs +39 -2
  300. package/dist/composer/composer-handoff.cjs.map +1 -1
  301. package/dist/composer/composer-handoff.d.ts +28 -3
  302. package/dist/composer/composer-handoff.js +39 -2
  303. package/dist/composer/composer-handoff.js.map +1 -1
  304. package/dist/composer/useAttachFiles.cjs +15 -2
  305. package/dist/composer/useAttachFiles.cjs.map +1 -1
  306. package/dist/composer/useAttachFiles.d.ts +11 -0
  307. package/dist/composer/useAttachFiles.js +15 -2
  308. package/dist/composer/useAttachFiles.js.map +1 -1
  309. package/dist/composer/useSendMessage.cjs.map +1 -1
  310. package/dist/composer/useSendMessage.d.ts +4 -3
  311. package/dist/composer/useSendMessage.js.map +1 -1
  312. package/dist/diagnostics/athena-diagnostics.cjs.map +1 -1
  313. package/dist/diagnostics/athena-diagnostics.d.ts +3 -1
  314. package/dist/diagnostics/athena-diagnostics.js.map +1 -1
  315. package/dist/index.cjs +13 -0
  316. package/dist/index.cjs.map +1 -1
  317. package/dist/index.d.ts +14 -7
  318. package/dist/index.js +14 -1
  319. package/dist/index.js.map +1 -1
  320. package/dist/offline/chat-outbox.cjs +57 -0
  321. package/dist/offline/chat-outbox.cjs.map +1 -0
  322. package/dist/offline/chat-outbox.d.ts +80 -0
  323. package/dist/offline/chat-outbox.js +57 -0
  324. package/dist/offline/chat-outbox.js.map +1 -0
  325. package/dist/offline/offline-history.d.ts +1 -1
  326. package/dist/provider/AthenaProvider.cjs +162 -8
  327. package/dist/provider/AthenaProvider.cjs.map +1 -1
  328. package/dist/provider/AthenaProvider.d.ts +15 -1
  329. package/dist/provider/AthenaProvider.js +163 -9
  330. package/dist/provider/AthenaProvider.js.map +1 -1
  331. package/dist/provider/statewire-window-context.d.ts +1 -1
  332. package/dist/react/package.json.cjs +1 -1
  333. package/dist/react/package.json.js +1 -1
  334. package/dist/references/src/anchors/file-line-range.d.ts +58 -0
  335. package/dist/references/src/anchors/format.d.ts +21 -0
  336. package/dist/references/src/anchors/message-anchors.d.ts +71 -0
  337. package/dist/references/src/anchors/parse.d.ts +8 -0
  338. package/dist/references/src/anchors/registry-contract.d.ts +24 -0
  339. package/dist/references/src/anchors/registry.d.ts +19 -0
  340. package/dist/references/src/anchors/schemas.d.ts +194 -0
  341. package/dist/references/src/anchors/serialize.d.ts +8 -0
  342. package/dist/references/src/anchors/time.d.ts +78 -0
  343. package/dist/references/src/anchors/types.d.ts +474 -0
  344. package/dist/references/src/asset-bounds.d.ts +27 -0
  345. package/dist/references/src/asset-links.d.ts +23 -0
  346. package/dist/references/src/asset-reference.d.ts +16 -0
  347. package/dist/references/src/formats/format-catalog.d.ts +79 -0
  348. package/dist/references/src/formats/markdown/parse-reference-markdown.d.ts +28 -0
  349. package/dist/references/src/formats/markdown/reference-display-name.d.ts +6 -0
  350. package/dist/references/src/formats/object/asset-object.d.ts +9 -0
  351. package/dist/references/src/formats/object/callable-object.d.ts +6 -0
  352. package/dist/references/src/formats/object/decode-reference-object-payload.d.ts +3 -0
  353. package/dist/references/src/formats/object/external-url-object.d.ts +9 -0
  354. package/dist/references/src/formats/object/group-object.d.ts +9 -0
  355. package/dist/references/src/formats/object/navigation-object.d.ts +9 -0
  356. package/dist/references/src/formats/object/parse-reference-object.d.ts +11 -0
  357. package/dist/references/src/formats/object/person-object.d.ts +9 -0
  358. package/dist/references/src/formats/uri/asset-mention-uri.d.ts +9 -0
  359. package/dist/references/src/formats/uri/asset-spaces-url.d.ts +9 -0
  360. package/dist/references/src/formats/uri/callable-mention-uris.d.ts +9 -0
  361. package/dist/references/src/formats/uri/detect-uri-wire.d.ts +9 -0
  362. package/dist/references/src/formats/uri/group-mention-uri.d.ts +12 -0
  363. package/dist/references/src/formats/uri/navigation-spaces-url.d.ts +14 -0
  364. package/dist/references/src/formats/uri/parse-reference-uri.d.ts +20 -0
  365. package/dist/references/src/formats/uri/person-mention-uri.d.ts +9 -0
  366. package/dist/references/src/formats/uri/template-placeholder.d.ts +12 -0
  367. package/dist/references/src/index.d.ts +47 -0
  368. package/dist/references/src/legacy/index.d.ts +14 -0
  369. package/dist/references/src/legacy/pre-reference-asset-url.d.ts +57 -0
  370. package/dist/references/src/legacy/pre-reference-citation-bridge.d.ts +22 -0
  371. package/dist/references/src/legacy/pre-reference-citation.d.ts +138 -0
  372. package/dist/references/src/legacy/pre-reference-external-url.d.ts +31 -0
  373. package/dist/references/src/legacy/pre-reference-format.d.ts +8 -0
  374. package/dist/references/src/legacy/pre-reference-mention.d.ts +27 -0
  375. package/dist/references/src/legacy/pre-reference-object.d.ts +8 -0
  376. package/dist/references/src/legacy/pre-reference-uri.d.ts +12 -0
  377. package/dist/references/src/legacy.d.ts +2 -0
  378. package/dist/references/src/mention-href-patterns.d.ts +19 -0
  379. package/dist/references/src/mention-node/index.d.ts +5 -0
  380. package/dist/references/src/mention-node/mention-node.d.ts +31 -0
  381. package/dist/references/src/mention-node/resolve-node-attrs.d.ts +27 -0
  382. package/dist/references/src/parse-reference.d.ts +23 -0
  383. package/dist/references/src/schemas.d.ts +463 -0
  384. package/dist/references/src/serialize-reference.d.ts +50 -0
  385. package/dist/references/src/sheet-name.d.ts +10 -0
  386. package/dist/references/src/tool-option-schemas.d.ts +597 -0
  387. package/dist/references/src/types.d.ts +125 -0
  388. package/dist/references/src/version-ref.d.ts +30 -0
  389. package/dist/runtime/statewire-lifecycle.d.ts +1 -1
  390. package/dist/runtime/statewire-model-lane.d.ts +1 -1
  391. package/dist/runtime/statewire-server-lane-context.d.ts +1 -1
  392. package/dist/runtime/statewire-session-key.cjs +7 -0
  393. package/dist/runtime/statewire-session-key.cjs.map +1 -1
  394. package/dist/runtime/statewire-session-key.d.ts +19 -0
  395. package/dist/runtime/statewire-session-key.js +8 -1
  396. package/dist/runtime/statewire-session-key.js.map +1 -1
  397. package/dist/runtime/statewire-session-lane.cjs +48 -0
  398. package/dist/runtime/statewire-session-lane.cjs.map +1 -0
  399. package/dist/runtime/statewire-session-lane.d.ts +29 -0
  400. package/dist/runtime/statewire-session-lane.js +48 -0
  401. package/dist/runtime/statewire-session-lane.js.map +1 -0
  402. package/dist/runtime/statewire-thread-config-lane.d.ts +1 -1
  403. package/dist/runtime/useAthenaStatewireRuntime.cjs +19 -5
  404. package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
  405. package/dist/runtime/useAthenaStatewireRuntime.d.ts +15 -1
  406. package/dist/runtime/useAthenaStatewireRuntime.js +20 -6
  407. package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
  408. package/dist/styles.css +1 -1
  409. package/dist/threads/api.d.ts +1 -1
  410. package/dist/threads/conversation-list-fetcher.d.ts +1 -1
  411. package/dist/threads/index-triggered-refresh.cjs +164 -0
  412. package/dist/threads/index-triggered-refresh.cjs.map +1 -0
  413. package/dist/threads/index-triggered-refresh.d.ts +70 -0
  414. package/dist/threads/index-triggered-refresh.js +164 -0
  415. package/dist/threads/index-triggered-refresh.js.map +1 -0
  416. package/dist/threads/offline-session-list.d.ts +1 -1
  417. package/dist/threads/pull-request-display.d.ts +1 -1
  418. package/dist/threads/session-list-model.d.ts +1 -1
  419. package/dist/threads/session-list-tab-share.cjs +150 -0
  420. package/dist/threads/session-list-tab-share.cjs.map +1 -0
  421. package/dist/threads/session-list-tab-share.d.ts +73 -0
  422. package/dist/threads/session-list-tab-share.js +150 -0
  423. package/dist/threads/session-list-tab-share.js.map +1 -0
  424. package/dist/threads/session-row-parts.d.ts +1 -1
  425. package/dist/threads/sessions-query.d.ts +1 -1
  426. package/dist/threads/statewire-thread-list.cjs +42 -16
  427. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  428. package/dist/threads/statewire-thread-list.d.ts +11 -2
  429. package/dist/threads/statewire-thread-list.js +43 -17
  430. package/dist/threads/statewire-thread-list.js.map +1 -1
  431. package/dist/threads/thread-prefetcher.d.ts +1 -1
  432. package/dist/threads/use-athena-session-attention.d.ts +1 -1
  433. package/dist/threads/use-athena-sessions.cjs +32 -22
  434. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  435. package/dist/threads/use-athena-sessions.js +33 -23
  436. package/dist/threads/use-athena-sessions.js.map +1 -1
  437. package/dist/threads/use-rest-conversation-history.d.ts +1 -1
  438. package/dist/threads/use-statewire-conversation-history.d.ts +5 -5
  439. package/dist/tiptap-markdown-table/src/markdown-table-serializer.d.ts +56 -0
  440. package/dist/tools/NestedPtcMessages.cjs +14 -9
  441. package/dist/tools/NestedPtcMessages.cjs.map +1 -1
  442. package/dist/tools/NestedPtcMessages.d.ts +9 -0
  443. package/dist/tools/NestedPtcMessages.js +6 -1
  444. package/dist/tools/NestedPtcMessages.js.map +1 -1
  445. package/dist/tools/index.d.ts +1 -1
  446. package/dist/tools/primitives.d.ts +1 -1
  447. package/dist/tools/subagent-task-tool-ui.cjs +494 -0
  448. package/dist/tools/subagent-task-tool-ui.cjs.map +1 -0
  449. package/dist/tools/subagent-task-tool-ui.d.ts +109 -0
  450. package/dist/tools/subagent-task-tool-ui.js +494 -0
  451. package/dist/tools/subagent-task-tool-ui.js.map +1 -0
  452. package/dist/tools/tool-fallback.d.ts +1 -1
  453. package/dist/tools/tool-icons.d.ts +1 -1
  454. package/dist/tools/tool-summary.d.ts +1 -1
  455. package/dist/tools/tool-uis.cjs +4 -0
  456. package/dist/tools/tool-uis.cjs.map +1 -1
  457. package/dist/tools/tool-uis.js +4 -0
  458. package/dist/tools/tool-uis.js.map +1 -1
  459. package/dist/voice/chat.cjs +6 -0
  460. package/dist/voice/chat.cjs.map +1 -0
  461. package/dist/voice/chat.d.ts +2 -0
  462. package/dist/voice/chat.js +6 -0
  463. package/dist/voice/chat.js.map +1 -0
  464. package/dist/voice/livekit-join.cjs +119 -0
  465. package/dist/voice/livekit-join.cjs.map +1 -0
  466. package/dist/voice/livekit-join.d.ts +8 -0
  467. package/dist/voice/livekit-join.js +119 -0
  468. package/dist/voice/livekit-join.js.map +1 -0
  469. package/dist/voice/livekit.cjs +32 -0
  470. package/dist/voice/livekit.cjs.map +1 -0
  471. package/dist/voice/livekit.d.ts +80 -0
  472. package/dist/voice/livekit.js +32 -0
  473. package/dist/voice/livekit.js.map +1 -0
  474. package/dist/voice/use-chat-voice-enabled.cjs +43 -0
  475. package/dist/voice/use-chat-voice-enabled.cjs.map +1 -0
  476. package/dist/voice/use-chat-voice-enabled.d.ts +9 -0
  477. package/dist/voice/use-chat-voice-enabled.js +43 -0
  478. package/dist/voice/use-chat-voice-enabled.js.map +1 -0
  479. package/package.json +22 -16
@@ -0,0 +1,64 @@
1
+ import type { ChatOutboxAttachmentCheck } from "./chat-outbox-attachments";
2
+ import { type ChatOutbox, type ChatOutboxCommandUpdate, type ChatOutboxEvent, type ChatOutboxSignal, type ChatOutboxSnapshot } from "./chat-outbox";
3
+ import type { ChatOutboxEntry, ChatOutboxStore } from "./chat-outbox-store";
4
+ import { type ChatOutboxClientHost } from "./chat-outbox-thread";
5
+ export interface UseDeepAgentChatOutboxOptions {
6
+ /** The thread's assistant-ui client (`useDeepAgentRuntime`'s result). */
7
+ client: ChatOutboxClientHost;
8
+ threadId: string;
9
+ /** The conversation has never started (a new chat). */
10
+ isNewChat: boolean;
11
+ /**
12
+ * This person's outbox store, one per person for the life of the page or app (a message the
13
+ * device cannot keep waits in its memory, across thread switches); `null` keeps waiting messages
14
+ * in this outbox alone.
15
+ */
16
+ store: ChatOutboxStore | null;
17
+ /** Athena's reachability (the host's own model: the browser online AND agora answering). */
18
+ reachability: ChatOutboxSignal;
19
+ /** The app is in front (a visible tab, an active app, a focused desktop window). */
20
+ foreground: ChatOutboxSignal;
21
+ /** Give a cancelled message's text back to the composer. */
22
+ restore: (entry: ChatOutboxEntry) => void;
23
+ /**
24
+ * Open another of the person's conversations holding waiting messages (the tray's Open); omit
25
+ * it where the host cannot switch conversations.
26
+ */
27
+ openThread?: (target: {
28
+ threadId: string;
29
+ newChat: boolean;
30
+ }) => void;
31
+ onEvent?: (event: ChatOutboxEvent) => void;
32
+ /**
33
+ * Asks Athena whether a waiting message's attachments can still be opened, right before it goes
34
+ * (`createChatOutboxAttachmentCheck`); omitted, attachments go unchecked.
35
+ */
36
+ checkAttachments?: ChatOutboxAttachmentCheck;
37
+ /** Off: no outbox (a read-only or suspended surface); sends behave as before. */
38
+ enabled?: boolean;
39
+ /** The countdown before a waiting message is sent (tests); defaults to `CHAT_OUTBOX_COUNTDOWN_MS`. */
40
+ countdownMs?: number;
41
+ }
42
+ /**
43
+ * The chat outbox for the mounted thread (`chat-outbox.ts`), one per thread and store: a thread
44
+ * switch disposes it and makes the next thread's. The host forwards statewire's command lifecycle
45
+ * to {@link ChatOutbox.observeCommand} (its `useDeepAgentRuntime` `onCommandChange`), shares the
46
+ * instance through {@link DeepAgentChatOutboxContext}, and has its composer call
47
+ * {@link ChatOutbox.shouldHold} / {@link ChatOutbox.hold} before sending.
48
+ */
49
+ export declare function useDeepAgentChatOutbox({ client, threadId, isNewChat, store, reachability, foreground, restore, openThread, onEvent, checkAttachments, enabled, countdownMs, }: UseDeepAgentChatOutboxOptions): ChatOutbox | null;
50
+ /** The outbox's rows and countdown, re-rendering on every change (`null` outbox: nothing waits). */
51
+ export declare function useChatOutboxSnapshot(outbox: ChatOutbox | null): ChatOutboxSnapshot;
52
+ /**
53
+ * Whether Athena can be reached, as the thread's outbox reads it: `true` without an outbox (a host
54
+ * that keeps none sends and edits as before). What a sent message's Edit is offered on; a boolean,
55
+ * so a reader re-renders only when it flips.
56
+ */
57
+ export declare function useChatOutboxReachable(outbox: ChatOutbox | null): boolean;
58
+ /** The mounted thread's chat outbox, shared from its runtime provider to its composer and tray. */
59
+ export declare const DeepAgentChatOutboxContext: import("react").Context<ChatOutbox | null>;
60
+ export declare function useDeepAgentChatOutboxContext(): ChatOutbox | null;
61
+ /** Forward statewire's command lifecycle to an outbox held in a ref (the runtime is made first). */
62
+ export declare function forwardChatOutboxCommand(outbox: {
63
+ current: ChatOutbox | null;
64
+ }, update: ChatOutboxCommandUpdate): void;
@@ -0,0 +1,136 @@
1
+ import { useContext, useCallback, useSyncExternalStore, createContext, useRef, useState, useEffect } from "react";
2
+ import { createChatOutbox } from "./chat-outbox.js";
3
+ import { createStatewireChatOutboxPort } from "./chat-outbox-thread.js";
4
+ function useDeepAgentChatOutbox({
5
+ client,
6
+ threadId,
7
+ isNewChat,
8
+ store,
9
+ reachability,
10
+ foreground,
11
+ restore,
12
+ openThread,
13
+ onEvent,
14
+ checkAttachments,
15
+ enabled = true,
16
+ countdownMs
17
+ }) {
18
+ const clientRef = useRef(client);
19
+ clientRef.current = client;
20
+ const restoreRef = useRef(restore);
21
+ restoreRef.current = restore;
22
+ const openThreadRef = useRef(openThread);
23
+ openThreadRef.current = openThread;
24
+ const canOpenThreads = openThread !== void 0;
25
+ const onEventRef = useRef(onEvent);
26
+ onEventRef.current = onEvent;
27
+ const checkAttachmentsRef = useRef(checkAttachments);
28
+ checkAttachmentsRef.current = checkAttachments;
29
+ const checksAttachments = checkAttachments !== void 0;
30
+ const reachabilityRef = useRef(reachability);
31
+ reachabilityRef.current = reachability;
32
+ const foregroundRef = useRef(foreground);
33
+ foregroundRef.current = foreground;
34
+ const [threadListeners] = useState(() => /* @__PURE__ */ new Set());
35
+ useEffect(() => {
36
+ if (!enabled) return void 0;
37
+ return client.subscribe(() => {
38
+ for (const listener of threadListeners) listener();
39
+ });
40
+ }, [client, threadListeners, enabled]);
41
+ const [stableSignals] = useState(() => {
42
+ const forward = (pick) => ({
43
+ get: () => pick().get(),
44
+ subscribe: (listener) => pick().subscribe(listener)
45
+ });
46
+ return {
47
+ reachability: forward(() => reachabilityRef.current),
48
+ foreground: forward(() => foregroundRef.current)
49
+ };
50
+ });
51
+ const isNewChatRef = useRef(isNewChat);
52
+ isNewChatRef.current = isNewChat;
53
+ const [outbox, setOutbox] = useState(null);
54
+ useEffect(() => {
55
+ if (!enabled || !threadId) {
56
+ setOutbox(null);
57
+ return void 0;
58
+ }
59
+ const created = createChatOutbox({
60
+ threadId,
61
+ // Read at each hold: a chat that starts while mounted stamps its later messages as started.
62
+ isNewChat: () => isNewChatRef.current,
63
+ store,
64
+ reachability: stableSignals.reachability,
65
+ foreground: stableSignals.foreground,
66
+ thread: {
67
+ ...createStatewireChatOutboxPort({ client: () => clientRef.current }),
68
+ subscribe: (listener) => {
69
+ threadListeners.add(listener);
70
+ return () => {
71
+ threadListeners.delete(listener);
72
+ };
73
+ }
74
+ },
75
+ restore: (entry) => restoreRef.current(entry),
76
+ ...canOpenThreads && {
77
+ openThread: (target) => {
78
+ var _a;
79
+ return (_a = openThreadRef.current) == null ? void 0 : _a.call(openThreadRef, target);
80
+ }
81
+ },
82
+ onEvent: (event) => {
83
+ var _a;
84
+ return (_a = onEventRef.current) == null ? void 0 : _a.call(onEventRef, event);
85
+ },
86
+ ...checksAttachments && {
87
+ checkAttachments: (attachments) => {
88
+ var _a;
89
+ return ((_a = checkAttachmentsRef.current) == null ? void 0 : _a.call(checkAttachmentsRef, attachments)) ?? Promise.resolve("ok");
90
+ }
91
+ },
92
+ ...countdownMs !== void 0 && { countdownMs }
93
+ });
94
+ setOutbox(created);
95
+ return () => {
96
+ created.dispose();
97
+ setOutbox((current) => current === created ? null : current);
98
+ };
99
+ }, [enabled, threadId, store, countdownMs, canOpenThreads, checksAttachments]);
100
+ return outbox !== null && outbox.threadId === threadId ? outbox : null;
101
+ }
102
+ const EMPTY_SNAPSHOT = {
103
+ rows: [],
104
+ countdownEndsAt: null,
105
+ durable: true,
106
+ loaded: true,
107
+ elsewhere: []
108
+ };
109
+ const noopSubscribe = () => () => void 0;
110
+ function useChatOutboxSnapshot(outbox) {
111
+ return useSyncExternalStore(
112
+ outbox ? outbox.subscribe : noopSubscribe,
113
+ () => (outbox == null ? void 0 : outbox.getSnapshot()) ?? EMPTY_SNAPSHOT,
114
+ () => (outbox == null ? void 0 : outbox.getSnapshot()) ?? EMPTY_SNAPSHOT
115
+ );
116
+ }
117
+ function useChatOutboxReachable(outbox) {
118
+ const subscribe = useCallback(
119
+ (listener) => outbox ? outbox.reachability.subscribe(listener) : () => void 0,
120
+ [outbox]
121
+ );
122
+ const reachable = () => (outbox == null ? void 0 : outbox.reachability.get()) ?? true;
123
+ return useSyncExternalStore(subscribe, reachable, reachable);
124
+ }
125
+ const DeepAgentChatOutboxContext = createContext(null);
126
+ function useDeepAgentChatOutboxContext() {
127
+ return useContext(DeepAgentChatOutboxContext);
128
+ }
129
+ export {
130
+ DeepAgentChatOutboxContext,
131
+ useChatOutboxReachable,
132
+ useChatOutboxSnapshot,
133
+ useDeepAgentChatOutbox,
134
+ useDeepAgentChatOutboxContext
135
+ };
136
+ //# sourceMappingURL=use-deep-agent-chat-outbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-deep-agent-chat-outbox.js","sources":["../../../../agent-runtime/src/use-deep-agent-chat-outbox.ts"],"sourcesContent":["import { createContext, useCallback, useContext, useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { ChatOutboxAttachmentCheck } from \"./chat-outbox-attachments\";\nimport {\n type ChatOutbox,\n type ChatOutboxCommandUpdate,\n type ChatOutboxEvent,\n type ChatOutboxSignal,\n type ChatOutboxSnapshot,\n createChatOutbox,\n} from \"./chat-outbox\";\nimport type { ChatOutboxEntry, ChatOutboxStore } from \"./chat-outbox-store\";\nimport { type ChatOutboxClientHost, createStatewireChatOutboxPort } from \"./chat-outbox-thread\";\n\nexport interface UseDeepAgentChatOutboxOptions {\n /** The thread's assistant-ui client (`useDeepAgentRuntime`'s result). */\n client: ChatOutboxClientHost;\n threadId: string;\n /** The conversation has never started (a new chat). */\n isNewChat: boolean;\n /**\n * This person's outbox store, one per person for the life of the page or app (a message the\n * device cannot keep waits in its memory, across thread switches); `null` keeps waiting messages\n * in this outbox alone.\n */\n store: ChatOutboxStore | null;\n /** Athena's reachability (the host's own model: the browser online AND agora answering). */\n reachability: ChatOutboxSignal;\n /** The app is in front (a visible tab, an active app, a focused desktop window). */\n foreground: ChatOutboxSignal;\n /** Give a cancelled message's text back to the composer. */\n restore: (entry: ChatOutboxEntry) => void;\n /**\n * Open another of the person's conversations holding waiting messages (the tray's Open); omit\n * it where the host cannot switch conversations.\n */\n openThread?: (target: { threadId: string; newChat: boolean }) => void;\n onEvent?: (event: ChatOutboxEvent) => void;\n /**\n * Asks Athena whether a waiting message's attachments can still be opened, right before it goes\n * (`createChatOutboxAttachmentCheck`); omitted, attachments go unchecked.\n */\n checkAttachments?: ChatOutboxAttachmentCheck;\n /** Off: no outbox (a read-only or suspended surface); sends behave as before. */\n enabled?: boolean;\n /** The countdown before a waiting message is sent (tests); defaults to `CHAT_OUTBOX_COUNTDOWN_MS`. */\n countdownMs?: number;\n}\n\n/**\n * The chat outbox for the mounted thread (`chat-outbox.ts`), one per thread and store: a thread\n * switch disposes it and makes the next thread's. The host forwards statewire's command lifecycle\n * to {@link ChatOutbox.observeCommand} (its `useDeepAgentRuntime` `onCommandChange`), shares the\n * instance through {@link DeepAgentChatOutboxContext}, and has its composer call\n * {@link ChatOutbox.shouldHold} / {@link ChatOutbox.hold} before sending.\n */\nexport function useDeepAgentChatOutbox({\n client,\n threadId,\n isNewChat,\n store,\n reachability,\n foreground,\n restore,\n openThread,\n onEvent,\n checkAttachments,\n enabled = true,\n countdownMs,\n}: UseDeepAgentChatOutboxOptions): ChatOutbox | null {\n const clientRef = useRef(client);\n clientRef.current = client;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n const openThreadRef = useRef(openThread);\n openThreadRef.current = openThread;\n const canOpenThreads = openThread !== undefined;\n const onEventRef = useRef(onEvent);\n onEventRef.current = onEvent;\n const checkAttachmentsRef = useRef(checkAttachments);\n checkAttachmentsRef.current = checkAttachments;\n const checksAttachments = checkAttachments !== undefined;\n const reachabilityRef = useRef(reachability);\n reachabilityRef.current = reachability;\n const foregroundRef = useRef(foreground);\n foregroundRef.current = foreground;\n // The client's notifications reach the port through this set, so a client whose identity\n // changes mid-thread is followed without remaking the outbox (and losing its countdown).\n const [threadListeners] = useState(() => new Set<() => void>());\n // A host without an outbox (`enabled` false) is never subscribed to.\n useEffect(() => {\n if (!enabled) return undefined;\n return client.subscribe(() => {\n for (const listener of threadListeners) listener();\n });\n }, [client, threadListeners, enabled]);\n // Signals read through refs for the same reason: a host rebuilding its signal objects per render\n // never remakes the outbox.\n const [stableSignals] = useState(() => {\n const forward = (pick: () => ChatOutboxSignal): ChatOutboxSignal => ({\n get: () => pick().get(),\n subscribe: (listener) => pick().subscribe(listener),\n });\n return {\n reachability: forward(() => reachabilityRef.current),\n foreground: forward(() => foregroundRef.current),\n };\n });\n const isNewChatRef = useRef(isNewChat);\n isNewChatRef.current = isNewChat;\n\n const [outbox, setOutbox] = useState<ChatOutbox | null>(null);\n // Made in an effect, not during render: the outbox subscribes to its signals and reads its\n // store, and a render React throws away must not leave those behind.\n // biome-ignore lint/correctness/useExhaustiveDependencies: one outbox per thread and store; everything else is read through refs.\n useEffect(() => {\n if (!enabled || !threadId) {\n setOutbox(null);\n return undefined;\n }\n const created = createChatOutbox({\n threadId,\n // Read at each hold: a chat that starts while mounted stamps its later messages as started.\n isNewChat: () => isNewChatRef.current,\n store,\n reachability: stableSignals.reachability,\n foreground: stableSignals.foreground,\n thread: {\n ...createStatewireChatOutboxPort({ client: () => clientRef.current }),\n subscribe: (listener) => {\n threadListeners.add(listener);\n return () => {\n threadListeners.delete(listener);\n };\n },\n },\n restore: (entry) => restoreRef.current(entry),\n ...(canOpenThreads && {\n openThread: (target: { threadId: string; newChat: boolean }) => openThreadRef.current?.(target),\n }),\n onEvent: (event) => onEventRef.current?.(event),\n ...(checksAttachments && {\n checkAttachments: (attachments: Parameters<ChatOutboxAttachmentCheck>[0]) =>\n checkAttachmentsRef.current?.(attachments) ?? Promise.resolve(\"ok\" as const),\n }),\n ...(countdownMs !== undefined && { countdownMs }),\n });\n setOutbox(created);\n return () => {\n created.dispose();\n setOutbox((current) => (current === created ? null : current));\n };\n }, [enabled, threadId, store, countdownMs, canOpenThreads, checksAttachments]);\n // During a thread switch's first render the previous thread's outbox is still in state.\n return outbox !== null && outbox.threadId === threadId ? outbox : null;\n}\n\nconst EMPTY_SNAPSHOT: ChatOutboxSnapshot = {\n rows: [],\n countdownEndsAt: null,\n durable: true,\n loaded: true,\n elsewhere: [],\n};\nconst noopSubscribe = () => () => undefined;\n\n/** The outbox's rows and countdown, re-rendering on every change (`null` outbox: nothing waits). */\nexport function useChatOutboxSnapshot(outbox: ChatOutbox | null): ChatOutboxSnapshot {\n return useSyncExternalStore(\n outbox ? outbox.subscribe : noopSubscribe,\n () => outbox?.getSnapshot() ?? EMPTY_SNAPSHOT,\n () => outbox?.getSnapshot() ?? EMPTY_SNAPSHOT,\n );\n}\n\n/**\n * Whether Athena can be reached, as the thread's outbox reads it: `true` without an outbox (a host\n * that keeps none sends and edits as before). What a sent message's Edit is offered on; a boolean,\n * so a reader re-renders only when it flips.\n */\nexport function useChatOutboxReachable(outbox: ChatOutbox | null): boolean {\n const subscribe = useCallback(\n (listener: () => void) => (outbox ? outbox.reachability.subscribe(listener) : () => undefined),\n [outbox],\n );\n const reachable = () => outbox?.reachability.get() ?? true;\n return useSyncExternalStore(subscribe, reachable, reachable);\n}\n\n/** The mounted thread's chat outbox, shared from its runtime provider to its composer and tray. */\nexport const DeepAgentChatOutboxContext = createContext<ChatOutbox | null>(null);\n\nexport function useDeepAgentChatOutboxContext(): ChatOutbox | null {\n return useContext(DeepAgentChatOutboxContext);\n}\n\n/** Forward statewire's command lifecycle to an outbox held in a ref (the runtime is made first). */\nexport function forwardChatOutboxCommand(\n outbox: { current: ChatOutbox | null },\n update: ChatOutboxCommandUpdate,\n): void {\n outbox.current?.observeCommand(update);\n}\n"],"names":[],"mappings":";;;AAuDO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AACF,GAAqD;AACnD,QAAM,YAAY,OAAO,MAAM;AAC/B,YAAU,UAAU;AACpB,QAAM,aAAa,OAAO,OAAO;AACjC,aAAW,UAAU;AACrB,QAAM,gBAAgB,OAAO,UAAU;AACvC,gBAAc,UAAU;AACxB,QAAM,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CAAC,MAAM;AAAA,EAAA;AAET,QAAM,YAAY,OAAM,iCAAQ,aAAa,UAAS;AACtD,SAAO,qBAAqB,WAAW,WAAW,SAAS;AAC7D;AAGO,MAAM,6BAA6B,cAAiC,IAAI;AAExE,SAAS,gCAAmD;AACjE,SAAO,WAAW,0BAA0B;AAC9C;"}
@@ -0,0 +1,169 @@
1
+ import { type ThreadConfigCustom, type ThreadConfigPatch } from './config-mutations';
2
+ import { DEEP_AGENT_CONFIG_COMMANDS } from './generated/runconfig-contract';
3
+ declare module '@assistant-ui/core' {
4
+ namespace Assistant {
5
+ interface Commands {
6
+ /** Set / unset top-level keys of the thread's server config (`null` unsets). */
7
+ configPatch: {
8
+ type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch;
9
+ patch: Record<string, unknown>;
10
+ };
11
+ /** Append ids to the thread's `enabled_tools`. */
12
+ configToolsEnable: {
13
+ type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable;
14
+ toolIds: string[];
15
+ };
16
+ /** Remove ids from the thread's `enabled_tools`. */
17
+ configToolsDisable: {
18
+ type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable;
19
+ toolIds: string[];
20
+ };
21
+ }
22
+ }
23
+ }
24
+ /**
25
+ * The replicated `state.config` lane of a thread with server-authoritative
26
+ * run config. Absent — and `readServerConfig` returns `null` — while the
27
+ * thread has never been configured (version 0: a brand-new thread, or one
28
+ * created by a client predating the lane).
29
+ */
30
+ export interface DeepAgentServerConfig {
31
+ /** Monotonic server-incremented version; always >= 1 when the lane exists. */
32
+ version: number;
33
+ /** The thread-config keys every run on this thread uses as its base. */
34
+ custom: ThreadConfigCustom;
35
+ }
36
+ /**
37
+ * Read the server-config lane off a raw statewire state.
38
+ *
39
+ * Identity-preserving (returns the raw `state.config` reference), so it is
40
+ * safe as a `useStatewireState` selector: the reference only changes when the
41
+ * server writes the lane.
42
+ */
43
+ export declare function readServerConfig(state: unknown): DeepAgentServerConfig | null;
44
+ /** The thread's server config version: 0 while the thread has never been configured. */
45
+ export declare function readConfigVersion(state: unknown): number;
46
+ /**
47
+ * {@link readServerConfig}, but only from a state `threadId`'s own attach
48
+ * produced (`readDeepAgentStateThreadId`); any other state reads as
49
+ * unconfigured. With no `threadId` it is {@link readServerConfig} unchanged.
50
+ *
51
+ * Identity-preserving like {@link readServerConfig}, so it is safe as a
52
+ * `useStatewireState` selector.
53
+ */
54
+ export declare function readThreadServerConfig({ state, threadId, }: {
55
+ state: unknown;
56
+ threadId: string | undefined;
57
+ }): DeepAgentServerConfig | null;
58
+ /**
59
+ * Whether a rejected `config/*` command was refused because the submitter
60
+ * only has view access to the session, or because the conversation is
61
+ * archived (`conversation_archived`, a 409: read-only until it is restored).
62
+ * The write is not retriable by that user; hosts disable their config
63
+ * controls.
64
+ */
65
+ export declare function isConfigWriteForbiddenRejection(error: unknown): boolean;
66
+ /**
67
+ * Whether a rejected `config/*` command was refused because the thread's
68
+ * workspace cannot hold server config at all (`config_sync_unavailable`, a
69
+ * regionally-pinned workspace). No write will ever succeed on the thread;
70
+ * hosts stop issuing them and send their full config per run instead.
71
+ */
72
+ export declare function isConfigSyncUnavailableRejection(error: unknown): boolean;
73
+ /** The settled result of a `config/*` command: the new server config. */
74
+ export interface DeepAgentConfigWriteResult {
75
+ version: number;
76
+ custom: ThreadConfigCustom;
77
+ }
78
+ /** An observed server-config version, delivered to the host callback. */
79
+ export interface DeepAgentServerConfigEvent {
80
+ version: number;
81
+ /** The server config with this client's still-pending writes folded over. */
82
+ custom: ThreadConfigCustom;
83
+ }
84
+ interface PendingOp {
85
+ id: number;
86
+ apply: (custom: ThreadConfigCustom) => ThreadConfigCustom;
87
+ /** The version the server assigned this op; retired once the lane reaches it. */
88
+ settledVersion: number | null;
89
+ }
90
+ /**
91
+ * Fold the pending optimistic ops over the server config — the effective
92
+ * config a client shows and sends against. Pure, for the tests.
93
+ */
94
+ export declare function foldPendingConfigOps(serverConfig: DeepAgentServerConfig | null, ops: readonly Pick<PendingOp, 'apply' | 'settledVersion'>[]): ThreadConfigCustom;
95
+ export interface UseDeepAgentConfigOptions {
96
+ /**
97
+ * Fired whenever the server writes a new version of the lane (another
98
+ * device, the seed, or the echo of our own command), with this client's
99
+ * still-pending writes folded over — hosts mirror it into their local
100
+ * store; nothing is ever clobbered because pending edits stay on top.
101
+ */
102
+ onServerConfig?: (event: DeepAgentServerConfigEvent) => void;
103
+ /**
104
+ * The thread this binding serves. When set, the lane is read only from a
105
+ * state that thread's own attach produced ({@link readThreadServerConfig}):
106
+ * for the first render after a thread switch the client still projects the
107
+ * previous thread's state, and adopting its lane would report the previous
108
+ * thread's config and version as this thread's.
109
+ */
110
+ threadId?: string;
111
+ }
112
+ export interface UseDeepAgentConfigResult {
113
+ /** Reactive server config version (0 while the thread has never been configured). */
114
+ configVersion: number;
115
+ /** Reactive server-config lane, or `null` at version 0. */
116
+ serverConfig: DeepAgentServerConfig | null;
117
+ /**
118
+ * The effective thread config: the server lane with this client's pending
119
+ * writes folded over. `{}` at version 0 with nothing pending.
120
+ */
121
+ custom: ThreadConfigCustom;
122
+ /** `true` while at least one `config/*` command is unacknowledged by the server. */
123
+ hasPendingWrites: boolean;
124
+ /** `config/patch` — set / unset top-level keys; `null` unsets. */
125
+ patchConfig: (patch: ThreadConfigPatch) => Promise<DeepAgentConfigWriteResult>;
126
+ /** `config/tools/enable`. */
127
+ enableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;
128
+ /** `config/tools/disable`. */
129
+ disableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;
130
+ }
131
+ type ConfigCommand = {
132
+ type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch;
133
+ patch: Record<string, unknown>;
134
+ } | {
135
+ type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable;
136
+ toolIds: string[];
137
+ } | {
138
+ type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable;
139
+ toolIds: string[];
140
+ };
141
+ /**
142
+ * The server-authoritative thread config of a deep-agent thread.
143
+ *
144
+ * Every capability a run depends on — model, agent binding, enabled tools,
145
+ * sandbox, environment, … — lives on the thread's server config lane and is
146
+ * changed only through the `config/*` commands. Sends carry per-send keys
147
+ * only (`pickPerSendCustom`). The commands are applied optimistically: each
148
+ * one folds its transform over the server config the moment it is issued
149
+ * (`custom`), and retires once the lane reaches the version the server
150
+ * assigned it; a rejection drops it, so the UI snaps back to the truth.
151
+ *
152
+ * Must be mounted under the thread's statewire context (an `AuiProvider`
153
+ * holding `useDeepAgentThread`'s element), keyed by the thread identity so a
154
+ * thread switch remounts it with an empty pending set. A binding that persists
155
+ * what it reads per thread passes `threadId`, so the render that still sees
156
+ * the previous thread's state after a switch reads no lane at all.
157
+ */
158
+ export declare function useDeepAgentConfig({ threadId, ...options }?: UseDeepAgentConfigOptions): UseDeepAgentConfigResult;
159
+ export interface DeepAgentConfigControllerInputs extends UseDeepAgentConfigOptions {
160
+ serverConfig: DeepAgentServerConfig | null;
161
+ sendCommand: (command: ConfigCommand) => Promise<unknown>;
162
+ }
163
+ /**
164
+ * The transport-agnostic body of {@link useDeepAgentConfig}, with the reactive
165
+ * inputs injected — so the optimistic-overlay behavior is testable without a
166
+ * statewire session.
167
+ */
168
+ export declare function useDeepAgentConfigController({ serverConfig, sendCommand, onServerConfig, }: DeepAgentConfigControllerInputs): UseDeepAgentConfigResult;
169
+ export {};
@@ -2,11 +2,16 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const store = require("@assistant-ui/store");
4
4
  const react = require("react");
5
+ const chatOutbox = require("./chat-outbox.cjs");
5
6
  const editCommand = require("./edit-command.cjs");
7
+ const useDeepAgentChatOutbox = require("./use-deep-agent-chat-outbox.cjs");
6
8
  const useHistoricalEditAttachments = require("./use-historical-edit-attachments.cjs");
7
9
  function useDeepAgentMessageEditSubmit() {
8
10
  useHistoricalEditAttachments.useHistoricalEditAttachments();
9
11
  const aui = store.useAui();
12
+ const outbox = useDeepAgentChatOutbox.useDeepAgentChatOutboxContext();
13
+ const outboxRef = react.useRef(outbox);
14
+ outboxRef.current = outbox;
10
15
  const alive = react.useRef(true);
11
16
  const submitting = react.useRef(false);
12
17
  react.useEffect(() => {
@@ -22,6 +27,12 @@ function useDeepAgentMessageEditSubmit() {
22
27
  const draft = composer.getState();
23
28
  const text = draft.text.trim();
24
29
  if (!text && draft.attachments.length === 0) return false;
30
+ const refuseWhileUnreachable = () => {
31
+ var _a2;
32
+ const reachability = (_a2 = outboxRef.current) == null ? void 0 : _a2.reachability;
33
+ if (reachability && !reachability.get()) throw new chatOutbox.ChatEditUnreachableError();
34
+ };
35
+ refuseWhileUnreachable();
25
36
  const files = [];
26
37
  const texts = text ? [text] : [];
27
38
  for (const attachment of draft.attachments) {
@@ -58,6 +69,7 @@ function useDeepAgentMessageEditSubmit() {
58
69
  if (preparedMetadata) (_b = extras.discardPreparedMessageMetadata) == null ? void 0 : _b.call(extras, preparedMetadata);
59
70
  return false;
60
71
  }
72
+ refuseWhileUnreachable();
61
73
  if (command) {
62
74
  void Promise.resolve(
63
75
  extras.sendCommand(
@@ -86,6 +98,7 @@ function useDeepAgentMessageEditSubmit() {
86
98
  throw error;
87
99
  }
88
100
  }
101
+ refuseWhileUnreachable();
89
102
  composer.send();
90
103
  return true;
91
104
  } finally {
@@ -1 +1 @@
1
- {"version":3,"file":"use-deep-agent-edit-submit.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-edit-submit.ts"],"sourcesContent":["import { useAui } from '@assistant-ui/store';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useRef } from 'react';\nimport { readDeepAgentStatewireExtras, resolveDeepAgentEditCommand } from './edit-command';\nimport { useHistoricalEditAttachments } from './use-historical-edit-attachments';\n\n/**\n * The submit handler of a message's edit composer on a deep-agent thread: the\n * edited text leaves as a `run/edit` anchored on the host's own parent of the\n * message (see `edit-command.ts`) — older pages stated first for a message at\n * or below the loaded window's edge — instead of the library's\n * converted-message anchor, which the host rejects `wrong-anchor` after a\n * chunked assistant turn and at the window edge.\n *\n * Read inside the message scope (`aui.message()`): the library's optimistic\n * fold shows the edited bubble and rewinds the visible history the moment the\n * command is dispatched, so the edit composer closes right away. Falls back\n * to the composer's own `send()` when the thread is not a statewire thread or\n * the host has not settled the message yet. Resolves `false` for an empty\n * draft, a duplicate submission, or an edit cancelled during preparation.\n */\nexport function useDeepAgentMessageEditSubmit(): () => Promise<boolean> {\n useHistoricalEditAttachments();\n const aui = useAui();\n const alive = useRef(true);\n const submitting = useRef(false);\n useEffect(() => {\n alive.current = true;\n return () => {\n alive.current = false;\n };\n }, []);\n return useCallback(async () => {\n if (submitting.current) return false;\n const composer = aui.message().composer();\n const draft = composer.getState();\n const text = draft.text.trim();\n if (!text && draft.attachments.length === 0) return false;\n const files: StatewireThread.FilePart[] = [];\n const texts = text ? [text] : [];\n // beginEdit lifts original inline images/files into completed composer\n // attachments. The anchored command must carry those too: a text-only\n // reconstruction silently deleted them when editing a cross-device turn.\n for (const attachment of draft.attachments) {\n if (attachment.status.type !== 'complete')\n throw new Error('Wait for attachments to finish before sending your edit.');\n for (const part of attachment.content ?? []) {\n if (part.type === 'text') texts.push(part.text);\n else if (part.type === 'image')\n files.push({ type: 'file', mediaType: 'image/*', url: part.image });\n else if (part.type === 'file')\n files.push({\n type: 'file',\n mediaType: part.mimeType,\n url: part.data,\n ...(part.filename && { filename: part.filename }),\n });\n else throw new Error('This attachment cannot be edited here.');\n }\n }\n submitting.current = true;\n try {\n const sourceId = aui.message().getState().id;\n const readExtras = () =>\n alive.current ? readDeepAgentStatewireExtras(aui.thread().getState().extras) : null;\n const extras = readExtras();\n if (extras) {\n const preparedMetadata = extras.prepareMessageMetadata?.();\n try {\n const command = await resolveDeepAgentEditCommand({\n readExtras,\n sourceId,\n text,\n });\n if (!alive.current || !composer.getState().isEditing) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n return false;\n }\n if (command) {\n void Promise.resolve(\n extras.sendCommand(\n {\n ...command,\n message: {\n ...command.message,\n parts: [\n ...files,\n ...(texts.length\n ? [{ type: 'text' as const, text: texts.join('\\n\\n') }]\n : []),\n ],\n },\n },\n preparedMetadata === undefined ? undefined : { preparedMetadata },\n ),\n ).catch(() => undefined);\n composer.cancel();\n return true;\n }\n if (preparedMetadata && extras.sendPreparedEdit) {\n extras.sendPreparedEdit(sourceId, preparedMetadata);\n return true;\n }\n } catch (error) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n throw error;\n }\n }\n composer.send();\n return true;\n } finally {\n submitting.current = false;\n }\n }, [aui]);\n}\n"],"names":["useHistoricalEditAttachments","useAui","useRef","useEffect","useCallback","readDeepAgentStatewireExtras","resolveDeepAgentEditCommand"],"mappings":";;;;;;AAqBO,SAAS,gCAAwD;AACtEA,4DAAA;AACA,QAAM,MAAMC,MAAAA,OAAA;AACZ,QAAM,QAAQC,MAAAA,OAAO,IAAI;AACzB,QAAM,aAAaA,MAAAA,OAAO,KAAK;AAC/BC,QAAAA,UAAU,MAAM;AACd,UAAM,UAAU;AAChB,WAAO,MAAM;AACX,YAAM,UAAU;AAAA,IAClB;AAAA,EACF,GAAG,CAAA,CAAE;AACL,SAAOC,MAAAA,YAAY,YAAY;;AAC7B,QAAI,WAAW,QAAS,QAAO;AAC/B,UAAM,WAAW,IAAI,QAAA,EAAU,SAAA;AAC/B,UAAM,QAAQ,SAAS,SAAA;AACvB,UAAM,OAAO,MAAM,KAAK,KAAA;AACxB,QAAI,CAAC,QAAQ,MAAM,YAAY,WAAW,EAAG,QAAO;AACpD,UAAM,QAAoC,CAAA;AAC1C,UAAM,QAAQ,OAAO,CAAC,IAAI,IAAI,CAAA;AAI9B,eAAW,cAAc,MAAM,aAAa;AAC1C,UAAI,WAAW,OAAO,SAAS;AAC7B,cAAM,IAAI,MAAM,0DAA0D;AAC5E,iBAAW,QAAQ,WAAW,WAAW,CAAA,GAAI;AAC3C,YAAI,KAAK,SAAS,O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A;AACT,mBAAO;AAAA,UACT;AACA,cAAI,oBAAoB,OAAO,kBAAkB;AAC/C,mBAAO,iBAAiB,UAAU,gBAAgB;AAClD,mBAAO;AAAA,UACT;AAAA,QACF,SAAS,OAAO;AACd,cAAI,iBAAkB,cAAO,mCAAP,gCAAwC;AAC9D,gBAAM;AAAA,QACR;AAAA,MACF;AACA,eAAS,KAAA;AACT,aAAO;AAAA,IACT,UAAA;AACE,iBAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AACV;;"}
1
+ {"version":3,"file":"use-deep-agent-edit-submit.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-edit-submit.ts"],"sourcesContent":["import { useAui } from '@assistant-ui/store';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useRef } from 'react';\nimport { ChatEditUnreachableError } from './chat-outbox';\nimport { readDeepAgentStatewireExtras, resolveDeepAgentEditCommand } from './edit-command';\nimport { useDeepAgentChatOutboxContext } from './use-deep-agent-chat-outbox';\nimport { useHistoricalEditAttachments } from './use-historical-edit-attachments';\n\n/**\n * The submit handler of a message's edit composer on a deep-agent thread: the\n * edited text leaves as a `run/edit` anchored on the host's own parent of the\n * message (see `edit-command.ts`) — older pages stated first for a message at\n * or below the loaded window's edge — instead of the library's\n * converted-message anchor, which the host rejects `wrong-anchor` after a\n * chunked assistant turn and at the window edge.\n *\n * Read inside the message scope (`aui.message()`): the library's optimistic\n * fold shows the edited bubble and rewinds the visible history the moment the\n * command is dispatched, so the edit composer closes right away. Falls back\n * to the composer's own `send()` when the thread is not a statewire thread or\n * the host has not settled the message yet. Resolves `false` for an empty\n * draft, a duplicate submission, or an edit cancelled during preparation.\n *\n * While the thread's chat outbox (a host that keeps one) says Athena can't be\n * reached, it rejects with {@link ChatEditUnreachableError} and sends nothing:\n * an edit rewinds and re-runs the conversation, and statewire would replay a\n * journaled one the moment its connection returns, from a hidden window too.\n * The draft stays in the edit composer, which says why.\n */\nexport function useDeepAgentMessageEditSubmit(): () => Promise<boolean> {\n useHistoricalEditAttachments();\n const aui = useAui();\n const outbox = useDeepAgentChatOutboxContext();\n const outboxRef = useRef(outbox);\n outboxRef.current = outbox;\n const alive = useRef(true);\n const submitting = useRef(false);\n useEffect(() => {\n alive.current = true;\n return () => {\n alive.current = false;\n };\n }, []);\n return useCallback(async () => {\n if (submitting.current) return false;\n const composer = aui.message().composer();\n const draft = composer.getState();\n const text = draft.text.trim();\n if (!text && draft.attachments.length === 0) return false;\n // Read at the submit (an edit begun while Athena answered and sent after it went is refused\n // too) and again right before anything is sent: preparing an edit can page older history in.\n const refuseWhileUnreachable = (): void => {\n const reachability = outboxRef.current?.reachability;\n if (reachability && !reachability.get()) throw new ChatEditUnreachableError();\n };\n refuseWhileUnreachable();\n const files: StatewireThread.FilePart[] = [];\n const texts = text ? [text] : [];\n // beginEdit lifts original inline images/files into completed composer\n // attachments. The anchored command must carry those too: a text-only\n // reconstruction silently deleted them when editing a cross-device turn.\n for (const attachment of draft.attachments) {\n if (attachment.status.type !== 'complete')\n throw new Error('Wait for attachments to finish before sending your edit.');\n for (const part of attachment.content ?? []) {\n if (part.type === 'text') texts.push(part.text);\n else if (part.type === 'image')\n files.push({ type: 'file', mediaType: 'image/*', url: part.image });\n else if (part.type === 'file')\n files.push({\n type: 'file',\n mediaType: part.mimeType,\n url: part.data,\n ...(part.filename && { filename: part.filename }),\n });\n else throw new Error('This attachment cannot be edited here.');\n }\n }\n submitting.current = true;\n try {\n const sourceId = aui.message().getState().id;\n const readExtras = () =>\n alive.current ? readDeepAgentStatewireExtras(aui.thread().getState().extras) : null;\n const extras = readExtras();\n if (extras) {\n const preparedMetadata = extras.prepareMessageMetadata?.();\n try {\n const command = await resolveDeepAgentEditCommand({\n readExtras,\n sourceId,\n text,\n });\n if (!alive.current || !composer.getState().isEditing) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n return false;\n }\n // Athena can have gone while older history was paged in: the edit stays a draft (the\n // catch below lets its prepared metadata go).\n refuseWhileUnreachable();\n if (command) {\n void Promise.resolve(\n extras.sendCommand(\n {\n ...command,\n message: {\n ...command.message,\n parts: [\n ...files,\n ...(texts.length\n ? [{ type: 'text' as const, text: texts.join('\\n\\n') }]\n : []),\n ],\n },\n },\n preparedMetadata === undefined ? undefined : { preparedMetadata },\n ),\n ).catch(() => undefined);\n composer.cancel();\n return true;\n }\n if (preparedMetadata && extras.sendPreparedEdit) {\n extras.sendPreparedEdit(sourceId, preparedMetadata);\n return true;\n }\n } catch (error) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n throw error;\n }\n }\n refuseWhileUnreachable();\n composer.send();\n return true;\n } finally {\n submitting.current = false;\n }\n }, [aui]);\n}\n"],"names":["useHistoricalEditAttachments","useAui","useDeepAgentChatOutboxContext","useRef","useEffect","useCallback","_a","ChatEditUnreachableError","readDeepAgentStatewireExtras","resolveDeepAgentEditCommand"],"mappings":";;;;;;;;AA6BO,SAAS,gCAAwD;AACtEA,4DAAA;AACA,QAAM,MAAMC,MAAAA,OAAA;AACZ,QAAM,SAASC,uBAAAA,8BAAA;AACf,QAAM,YAAYC,MAAAA,OAAO,MAAM;AAC/B,YAAU,UAAU;AACpB,QAAM,QAAQA,MAAAA,OAAO,IAAI;AACzB,QAAM,aAAaA,MAAAA,OAAO,KAAK;AAC/BC,QAAAA,UAAU,MAAM;AACd,UAAM,UAAU;AAChB,WAAO,MAAM;AACX,YAAM,UAAU;AAAA,IAClB;AAAA,EACF,GAAG,CAAA,CAAE;AACL,SAAOC,MAAAA,YAAY,YAAY;;AAC7B,QAAI,WAAW,QAAS,QAAO;AAC/B,UAAM,WAAW,IAAI,QAAA,EAAU,SAAA;AAC/B,UAAM,QAAQ,SAAS,SAAA;AACvB,UAAM,OAAO,MAAM,KAAK,KAAA;AACxB,QAAI,CAAC,QAAQ,MAAM,YAAY,WAAW,EAAG,QAAO;AAGpD,UAAM,yBAAyB,MAAY;;AACzC,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X,iBAAK,QAAQ;AAAA,cACX,OAAO;AAAA,gBACL;AAAA,kBACE,GAAG;AAAA,kBACH,SAAS;AAAA,oBACP,GAAG,QAAQ;AAAA,oBACX,OAAO;AAAA,sBACL,GAAG;AAAA,sBACH,GAAI,MAAM,SACN,CAAC,EAAE,MAAM,QAAiB,MAAM,MAAM,KAAK,MAAM,EAAA,CAAG,IACpD,CAAA;AAAA,oBAAC;AAAA,kBACP;AAAA,gBACF;AAAA,gBAEF,qBAAqB,SAAY,SAAY,EAAE,iBAAA;AAAA,cAAiB;AAAA,YAClE,EACA,MAAM,MAAM,MAAS;AACvB,qBAAS,OAAA;AACT,mBAAO;AAAA,UACT;AACA,cAAI,oBAAoB,OAAO,kBAAkB;AAC/C,mBAAO,iBAAiB,UAAU,gBAAgB;AAClD,mBAAO;AAAA,UACT;AAAA,QACF,SAAS,OAAO;AACd,cAAI,iBAAkB,cAAO,mCAAP,gCAAwC;AAC9D,gBAAM;AAAA,QACR;AAAA,MACF;AACA,6BAAA;AACA,eAAS,KAAA;AACT,aAAO;AAAA,IACT,UAAA;AACE,iBAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AACV;;"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The submit handler of a message's edit composer on a deep-agent thread: the
3
+ * edited text leaves as a `run/edit` anchored on the host's own parent of the
4
+ * message (see `edit-command.ts`) — older pages stated first for a message at
5
+ * or below the loaded window's edge — instead of the library's
6
+ * converted-message anchor, which the host rejects `wrong-anchor` after a
7
+ * chunked assistant turn and at the window edge.
8
+ *
9
+ * Read inside the message scope (`aui.message()`): the library's optimistic
10
+ * fold shows the edited bubble and rewinds the visible history the moment the
11
+ * command is dispatched, so the edit composer closes right away. Falls back
12
+ * to the composer's own `send()` when the thread is not a statewire thread or
13
+ * the host has not settled the message yet. Resolves `false` for an empty
14
+ * draft, a duplicate submission, or an edit cancelled during preparation.
15
+ *
16
+ * While the thread's chat outbox (a host that keeps one) says Athena can't be
17
+ * reached, it rejects with {@link ChatEditUnreachableError} and sends nothing:
18
+ * an edit rewinds and re-runs the conversation, and statewire would replay a
19
+ * journaled one the moment its connection returns, from a hidden window too.
20
+ * The draft stays in the edit composer, which says why.
21
+ */
22
+ export declare function useDeepAgentMessageEditSubmit(): () => Promise<boolean>;
@@ -1,10 +1,15 @@
1
1
  import { useAui } from "@assistant-ui/store";
2
2
  import { useRef, useEffect, useCallback } from "react";
3
+ import { ChatEditUnreachableError } from "./chat-outbox.js";
3
4
  import { readDeepAgentStatewireExtras, resolveDeepAgentEditCommand } from "./edit-command.js";
5
+ import { useDeepAgentChatOutboxContext } from "./use-deep-agent-chat-outbox.js";
4
6
  import { useHistoricalEditAttachments } from "./use-historical-edit-attachments.js";
5
7
  function useDeepAgentMessageEditSubmit() {
6
8
  useHistoricalEditAttachments();
7
9
  const aui = useAui();
10
+ const outbox = useDeepAgentChatOutboxContext();
11
+ const outboxRef = useRef(outbox);
12
+ outboxRef.current = outbox;
8
13
  const alive = useRef(true);
9
14
  const submitting = useRef(false);
10
15
  useEffect(() => {
@@ -20,6 +25,12 @@ function useDeepAgentMessageEditSubmit() {
20
25
  const draft = composer.getState();
21
26
  const text = draft.text.trim();
22
27
  if (!text && draft.attachments.length === 0) return false;
28
+ const refuseWhileUnreachable = () => {
29
+ var _a2;
30
+ const reachability = (_a2 = outboxRef.current) == null ? void 0 : _a2.reachability;
31
+ if (reachability && !reachability.get()) throw new ChatEditUnreachableError();
32
+ };
33
+ refuseWhileUnreachable();
23
34
  const files = [];
24
35
  const texts = text ? [text] : [];
25
36
  for (const attachment of draft.attachments) {
@@ -56,6 +67,7 @@ function useDeepAgentMessageEditSubmit() {
56
67
  if (preparedMetadata) (_b = extras.discardPreparedMessageMetadata) == null ? void 0 : _b.call(extras, preparedMetadata);
57
68
  return false;
58
69
  }
70
+ refuseWhileUnreachable();
59
71
  if (command) {
60
72
  void Promise.resolve(
61
73
  extras.sendCommand(
@@ -84,6 +96,7 @@ function useDeepAgentMessageEditSubmit() {
84
96
  throw error;
85
97
  }
86
98
  }
99
+ refuseWhileUnreachable();
87
100
  composer.send();
88
101
  return true;
89
102
  } finally {
@@ -1 +1 @@
1
- {"version":3,"file":"use-deep-agent-edit-submit.js","sources":["../../../../agent-runtime/src/use-deep-agent-edit-submit.ts"],"sourcesContent":["import { useAui } from '@assistant-ui/store';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useRef } from 'react';\nimport { readDeepAgentStatewireExtras, resolveDeepAgentEditCommand } from './edit-command';\nimport { useHistoricalEditAttachments } from './use-historical-edit-attachments';\n\n/**\n * The submit handler of a message's edit composer on a deep-agent thread: the\n * edited text leaves as a `run/edit` anchored on the host's own parent of the\n * message (see `edit-command.ts`) — older pages stated first for a message at\n * or below the loaded window's edge — instead of the library's\n * converted-message anchor, which the host rejects `wrong-anchor` after a\n * chunked assistant turn and at the window edge.\n *\n * Read inside the message scope (`aui.message()`): the library's optimistic\n * fold shows the edited bubble and rewinds the visible history the moment the\n * command is dispatched, so the edit composer closes right away. Falls back\n * to the composer's own `send()` when the thread is not a statewire thread or\n * the host has not settled the message yet. Resolves `false` for an empty\n * draft, a duplicate submission, or an edit cancelled during preparation.\n */\nexport function useDeepAgentMessageEditSubmit(): () => Promise<boolean> {\n useHistoricalEditAttachments();\n const aui = useAui();\n const alive = useRef(true);\n const submitting = useRef(false);\n useEffect(() => {\n alive.current = true;\n return () => {\n alive.current = false;\n };\n }, []);\n return useCallback(async () => {\n if (submitting.current) return false;\n const composer = aui.message().composer();\n const draft = composer.getState();\n const text = draft.text.trim();\n if (!text && draft.attachments.length === 0) return false;\n const files: StatewireThread.FilePart[] = [];\n const texts = text ? [text] : [];\n // beginEdit lifts original inline images/files into completed composer\n // attachments. The anchored command must carry those too: a text-only\n // reconstruction silently deleted them when editing a cross-device turn.\n for (const attachment of draft.attachments) {\n if (attachment.status.type !== 'complete')\n throw new Error('Wait for attachments to finish before sending your edit.');\n for (const part of attachment.content ?? []) {\n if (part.type === 'text') texts.push(part.text);\n else if (part.type === 'image')\n files.push({ type: 'file', mediaType: 'image/*', url: part.image });\n else if (part.type === 'file')\n files.push({\n type: 'file',\n mediaType: part.mimeType,\n url: part.data,\n ...(part.filename && { filename: part.filename }),\n });\n else throw new Error('This attachment cannot be edited here.');\n }\n }\n submitting.current = true;\n try {\n const sourceId = aui.message().getState().id;\n const readExtras = () =>\n alive.current ? readDeepAgentStatewireExtras(aui.thread().getState().extras) : null;\n const extras = readExtras();\n if (extras) {\n const preparedMetadata = extras.prepareMessageMetadata?.();\n try {\n const command = await resolveDeepAgentEditCommand({\n readExtras,\n sourceId,\n text,\n });\n if (!alive.current || !composer.getState().isEditing) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n return false;\n }\n if (command) {\n void Promise.resolve(\n extras.sendCommand(\n {\n ...command,\n message: {\n ...command.message,\n parts: [\n ...files,\n ...(texts.length\n ? [{ type: 'text' as const, text: texts.join('\\n\\n') }]\n : []),\n ],\n },\n },\n preparedMetadata === undefined ? undefined : { preparedMetadata },\n ),\n ).catch(() => undefined);\n composer.cancel();\n return true;\n }\n if (preparedMetadata && extras.sendPreparedEdit) {\n extras.sendPreparedEdit(sourceId, preparedMetadata);\n return true;\n }\n } catch (error) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n throw error;\n }\n }\n composer.send();\n return true;\n } finally {\n submitting.current = false;\n }\n }, [aui]);\n}\n"],"names":[],"mappings":";;;;AAqBO,SAAS,gCAAwD;AACtE,+BAAA;AACA,QAAM,MAAM,OAAA;AACZ,QAAM,QAAQ,OAAO,IAAI;AACzB,QAAM,aAAa,OAAO,KAAK;AAC/B,YAAU,MAAM;AACd,UAAM,UAAU;AAChB,WAAO,MAAM;AACX,YAAM,UAAU;AAAA,IAClB;AAAA,EACF,GAAG,CAAA,CAAE;AACL,SAAO,YAAY,YAAY;;AAC7B,QAAI,WAAW,QAAS,QAAO;AAC/B,U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,iBAAK,QAAQ;AAAA,cACX,OAAO;AAAA,gBACL;AAAA,kBACE,GAAG;AAAA,kBACH,SAAS;AAAA,oBACP,GAAG,QAAQ;AAAA,oBACX,OAAO;AAAA,sBACL,GAAG;AAAA,sBACH,GAAI,MAAM,SACN,CAAC,EAAE,MAAM,QAAiB,MAAM,MAAM,KAAK,MAAM,EAAA,CAAG,IACpD,CAAA;AAAA,oBAAC;AAAA,kBACP;AAAA,gBACF;AAAA,gBAEF,qBAAqB,SAAY,SAAY,EAAE,iBAAA;AAAA,cAAiB;AAAA,YAClE,EACA,MAAM,MAAM,MAAS;AACvB,qBAAS,OAAA;AACT,mBAAO;AAAA,UACT;AACA,cAAI,oBAAoB,OAAO,kBAAkB;AAC/C,mBAAO,iBAAiB,UAAU,gBAAgB;AAClD,mBAAO;AAAA,UACT;AAAA,QACF,SAAS,OAAO;AACd,cAAI,iBAAkB,cAAO,mCAAP,gCAAwC;AAC9D,gBAAM;AAAA,QACR;AAAA,MACF;AACA,eAAS,KAAA;AACT,aAAO;AAAA,IACT,UAAA;AACE,iBAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AACV;"}
1
+ {"version":3,"file":"use-deep-agent-edit-submit.js","sources":["../../../../agent-runtime/src/use-deep-agent-edit-submit.ts"],"sourcesContent":["import { useAui } from '@assistant-ui/store';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useRef } from 'react';\nimport { ChatEditUnreachableError } from './chat-outbox';\nimport { readDeepAgentStatewireExtras, resolveDeepAgentEditCommand } from './edit-command';\nimport { useDeepAgentChatOutboxContext } from './use-deep-agent-chat-outbox';\nimport { useHistoricalEditAttachments } from './use-historical-edit-attachments';\n\n/**\n * The submit handler of a message's edit composer on a deep-agent thread: the\n * edited text leaves as a `run/edit` anchored on the host's own parent of the\n * message (see `edit-command.ts`) — older pages stated first for a message at\n * or below the loaded window's edge — instead of the library's\n * converted-message anchor, which the host rejects `wrong-anchor` after a\n * chunked assistant turn and at the window edge.\n *\n * Read inside the message scope (`aui.message()`): the library's optimistic\n * fold shows the edited bubble and rewinds the visible history the moment the\n * command is dispatched, so the edit composer closes right away. Falls back\n * to the composer's own `send()` when the thread is not a statewire thread or\n * the host has not settled the message yet. Resolves `false` for an empty\n * draft, a duplicate submission, or an edit cancelled during preparation.\n *\n * While the thread's chat outbox (a host that keeps one) says Athena can't be\n * reached, it rejects with {@link ChatEditUnreachableError} and sends nothing:\n * an edit rewinds and re-runs the conversation, and statewire would replay a\n * journaled one the moment its connection returns, from a hidden window too.\n * The draft stays in the edit composer, which says why.\n */\nexport function useDeepAgentMessageEditSubmit(): () => Promise<boolean> {\n useHistoricalEditAttachments();\n const aui = useAui();\n const outbox = useDeepAgentChatOutboxContext();\n const outboxRef = useRef(outbox);\n outboxRef.current = outbox;\n const alive = useRef(true);\n const submitting = useRef(false);\n useEffect(() => {\n alive.current = true;\n return () => {\n alive.current = false;\n };\n }, []);\n return useCallback(async () => {\n if (submitting.current) return false;\n const composer = aui.message().composer();\n const draft = composer.getState();\n const text = draft.text.trim();\n if (!text && draft.attachments.length === 0) return false;\n // Read at the submit (an edit begun while Athena answered and sent after it went is refused\n // too) and again right before anything is sent: preparing an edit can page older history in.\n const refuseWhileUnreachable = (): void => {\n const reachability = outboxRef.current?.reachability;\n if (reachability && !reachability.get()) throw new ChatEditUnreachableError();\n };\n refuseWhileUnreachable();\n const files: StatewireThread.FilePart[] = [];\n const texts = text ? [text] : [];\n // beginEdit lifts original inline images/files into completed composer\n // attachments. The anchored command must carry those too: a text-only\n // reconstruction silently deleted them when editing a cross-device turn.\n for (const attachment of draft.attachments) {\n if (attachment.status.type !== 'complete')\n throw new Error('Wait for attachments to finish before sending your edit.');\n for (const part of attachment.content ?? []) {\n if (part.type === 'text') texts.push(part.text);\n else if (part.type === 'image')\n files.push({ type: 'file', mediaType: 'image/*', url: part.image });\n else if (part.type === 'file')\n files.push({\n type: 'file',\n mediaType: part.mimeType,\n url: part.data,\n ...(part.filename && { filename: part.filename }),\n });\n else throw new Error('This attachment cannot be edited here.');\n }\n }\n submitting.current = true;\n try {\n const sourceId = aui.message().getState().id;\n const readExtras = () =>\n alive.current ? readDeepAgentStatewireExtras(aui.thread().getState().extras) : null;\n const extras = readExtras();\n if (extras) {\n const preparedMetadata = extras.prepareMessageMetadata?.();\n try {\n const command = await resolveDeepAgentEditCommand({\n readExtras,\n sourceId,\n text,\n });\n if (!alive.current || !composer.getState().isEditing) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n return false;\n }\n // Athena can have gone while older history was paged in: the edit stays a draft (the\n // catch below lets its prepared metadata go).\n refuseWhileUnreachable();\n if (command) {\n void Promise.resolve(\n extras.sendCommand(\n {\n ...command,\n message: {\n ...command.message,\n parts: [\n ...files,\n ...(texts.length\n ? [{ type: 'text' as const, text: texts.join('\\n\\n') }]\n : []),\n ],\n },\n },\n preparedMetadata === undefined ? undefined : { preparedMetadata },\n ),\n ).catch(() => undefined);\n composer.cancel();\n return true;\n }\n if (preparedMetadata && extras.sendPreparedEdit) {\n extras.sendPreparedEdit(sourceId, preparedMetadata);\n return true;\n }\n } catch (error) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n throw error;\n }\n }\n refuseWhileUnreachable();\n composer.send();\n return true;\n } finally {\n submitting.current = false;\n }\n }, [aui]);\n}\n"],"names":["_a"],"mappings":";;;;;;AA6BO,SAAS,gCAAwD;AACtE,+BAAA;AACA,QAAM,MAAM,OAAA;AACZ,QAAM,SAAS,8BAAA;AACf,QAAM,YAAY,OAAO,MAAM;AAC/B,YAAU,UAAU;AACpB,QAAM,QAAQ,OAAO,IAAI;AACzB,QAAM,aAAa,OAAO,KAAK;AAC/B,YAAU,MAAM;AACd,UAAM,UAAU;AAChB,WAAO,MAAM;AACX,YAAM,UAAU;AAAA,IAClB;AAAA,EACF,GAAG,CAAA,CAAE;AACL,SAAO,YAAY,YAAY;;AAC7B,QAAI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