@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
@@ -1 +1 @@
1
- {"version":3,"file":"build-composed-message.cjs","sources":["../../src/composer/build-composed-message.ts"],"sourcesContent":["import type { UploadedAsset } from './useFileUpload';\nimport type { QuoteData } from './QuoteContext';\nimport { buildAttachmentMarkdownWithAppUrl } from './AttachmentContext';\nimport {\n type ComposerSend,\n escapeCharacterReferences,\n} from '../chat-ui/composer/composer-message';\n\n/**\n * Assembles a composed message from attachments, a quote, and user text.\n * Used by both the TipTap Enter-key submit and the send-button click handler\n * to avoid duplicating the message-assembly logic.\n *\n * Returns an empty string if all inputs are empty.\n */\nexport function buildComposedMessage(opts: {\n attachments?: UploadedAsset[];\n quote?: QuoteData | null;\n userText?: string;\n appUrl?: string;\n}): string {\n const parts: string[] = [];\n\n if (opts.attachments && opts.attachments.length > 0) {\n const attachmentMd = buildAttachmentMarkdownWithAppUrl({\n attachments: opts.attachments,\n appUrl: opts.appUrl,\n });\n if (attachmentMd) parts.push(attachmentMd);\n }\n\n if (opts.quote) {\n const quotedLines = opts.quote.text.split('\\n').map((l) => `> ${l}`).join('\\n');\n const sourceLabel = opts.quote.sourceTitle\n ? `From \"${opts.quote.sourceTitle}\"`\n : opts.quote.sourceRole === 'assistant'\n ? 'Quoting assistant'\n : 'Quoting';\n parts.push(`${sourceLabel}:\\n${quotedLines}`);\n }\n\n const trimmed = opts.userText?.trim();\n if (trimmed) parts.push(trimmed);\n\n return parts.join('\\n\\n');\n}\n\n/**\n * The composed message a send delivers and the draft it came from: the same\n * attachments and quote around the editor's text as typed in one, and around\n * the editor's draft in the other (`ComposerSend`). `null` when there is\n * nothing to send.\n *\n * The quote and the attachment titles are text the person did not type in\n * the editor, and the message carries them as they are. The draft writes an\n * `&` in them that starts a character reference as `&amp;`, as the composer's\n * draft does for typed text, so it reads back as the message and stays a draft\n * of the message's own text (`isComposerMarkdownOfText`, which agora applies\n * too): a quoted `&lt;` would otherwise read as `<` in the draft and the\n * message would lose its composer markdown.\n */\nexport function buildComposedSend({\n attachments,\n quote,\n send,\n appUrl,\n}: {\n attachments?: UploadedAsset[];\n quote?: QuoteData | null;\n send: ComposerSend;\n appUrl?: string;\n}): ComposerSend | null {\n const text = buildComposedMessage({ attachments, quote, userText: send.text, appUrl });\n if (!text) return null;\n const draftMarkdown = buildComposedMessage({\n attachments: attachments?.map((attachment) => ({\n ...attachment,\n title: escapeCharacterReferences(attachment.title),\n })),\n quote: quote && {\n ...quote,\n text: escapeCharacterReferences(quote.text),\n ...(quote.sourceTitle !== undefined && {\n sourceTitle: escapeCharacterReferences(quote.sourceTitle),\n }),\n },\n userText: send.draftMarkdown,\n appUrl,\n });\n return { text, draftMarkdown };\n}\n"],"names":["buildAttachmentMarkdownWithAppUrl","escapeCharacterReferences"],"mappings":";;;;AAeO,SAAS,qBAAqB,MAK1B;;AACT,QAAM,QAAkB,CAAA;AAExB,MAAI,KAAK,eAAe,KAAK,YAAY,SAAS,GAAG;AACnD,UAAM,eAAeA,kBAAAA,kCAAkC;AAAA,MACrD,aAAa,KAAK;AAAA,MAClB,QAAQ,KAAK;AAAA,IAAA,CACd;AACD,QAAI,aAAc,OAAM,KAAK,YAAY;AAAA,EAC3C;AAEA,MAAI,KAAK,OAAO;AACd,UAAM,cAAc,KAAK,MAAM,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,EAAE,KAAK,IAAI;AAC9E,UAAM,cAAc,KAAK,MAAM,cAC3B,SAAS,KAAK,MAAM,WAAW,MAC/B,KAAK,MAAM,eAAe,cACxB,sBACA;AACN,UAAM,KAAK,GAAG,WAAW;AAAA,EAAM,WAAW,EAAE;AAAA,EAC9C;AAEA,QAAM,WAAU,UAAK,aAAL,mBAAe;AAC/B,MAAI,QAAS,OAAM,KAAK,OAAO;AAE/B,SAAO,MAAM,KAAK,MAAM;AAC1B;AAgBO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKwB;AACtB,QAAM,OAAO,qBAAqB,EAAE,aAAa,OAAO,UAAU,KAAK,MAAM,QAAQ;AACrF,MAAI,CAAC,KAAM,QAAO;AAClB,QAAM,gBAAgB,qBAAqB;AAAA,IACzC,aAAa,2CAAa,IAAI,CAAC,gBAAgB;AAAA,MAC7C,GAAG;AAAA,MACH,OAAOC,gBAAAA,0BAA0B,WAAW,KAAK;AAAA,IAAA;AAAA,IAEnD,OAAO,SAAS;AAAA,MACd,GAAG;AAAA,MACH,MAAMA,gBAAAA,0BAA0B,MAAM,IAAI;AAAA,MAC1C,GAAI,MAAM,gBAAgB,UAAa;AAAA,QACrC,aAAaA,gBAAAA,0BAA0B,MAAM,WAAW;AAAA,MAAA;AAAA,IAC1D;AAAA,IAEF,UAAU,KAAK;AAAA,IACf;AAAA,EAAA,CACD;AACD,SAAO,EAAE,MAAM,cAAA;AACjB;;;"}
1
+ {"version":3,"file":"build-composed-message.cjs","sources":["../../src/composer/build-composed-message.ts"],"sourcesContent":["import {\n type ChatOutbox,\n type ChatOutboxAttachment,\n type ChatOutboxEntry,\n withDeepAgentComposerMarkdown,\n} from '@athenaintel/agent-runtime';\nimport type { UploadedAsset } from './useFileUpload';\nimport type { QuoteData } from './QuoteContext';\nimport { buildAttachmentMarkdownWithAppUrl } from './AttachmentContext';\nimport {\n type ComposerSend,\n escapeCharacterReferences,\n} from '../chat-ui/composer/composer-message';\n\n/**\n * Assembles a composed message from attachments, a quote, and user text.\n * Used by both the TipTap Enter-key submit and the send-button click handler\n * to avoid duplicating the message-assembly logic.\n *\n * Returns an empty string if all inputs are empty.\n */\nexport function buildComposedMessage(opts: {\n attachments?: UploadedAsset[];\n quote?: QuoteData | null;\n userText?: string;\n appUrl?: string;\n}): string {\n const parts: string[] = [];\n\n if (opts.attachments && opts.attachments.length > 0) {\n const attachmentMd = buildAttachmentMarkdownWithAppUrl({\n attachments: opts.attachments,\n appUrl: opts.appUrl,\n });\n if (attachmentMd) parts.push(attachmentMd);\n }\n\n if (opts.quote) {\n const quotedLines = opts.quote.text.split('\\n').map((l) => `> ${l}`).join('\\n');\n const sourceLabel = opts.quote.sourceTitle\n ? `From \"${opts.quote.sourceTitle}\"`\n : opts.quote.sourceRole === 'assistant'\n ? 'Quoting assistant'\n : 'Quoting';\n parts.push(`${sourceLabel}:\\n${quotedLines}`);\n }\n\n const trimmed = opts.userText?.trim();\n if (trimmed) parts.push(trimmed);\n\n return parts.join('\\n\\n');\n}\n\n/**\n * The composed message a send delivers and the draft it came from: the same\n * attachments and quote around the editor's text as typed in one, and around\n * the editor's draft in the other (`ComposerSend`). `null` when there is\n * nothing to send.\n *\n * The quote and the attachment titles are text the person did not type in\n * the editor, and the message carries them as they are. The draft writes an\n * `&` in them that starts a character reference as `&amp;`, as the composer's\n * draft does for typed text, so it reads back as the message and stays a draft\n * of the message's own text (`isComposerMarkdownOfText`, which agora applies\n * too): a quoted `&lt;` would otherwise read as `<` in the draft and the\n * message would lose its composer markdown.\n */\nexport function buildComposedSend({\n attachments,\n quote,\n send,\n appUrl,\n}: {\n attachments?: UploadedAsset[];\n quote?: QuoteData | null;\n send: ComposerSend;\n appUrl?: string;\n}): ComposerSend | null {\n const text = buildComposedMessage({ attachments, quote, userText: send.text, appUrl });\n if (!text) return null;\n const draftMarkdown = buildComposedMessage({\n attachments: attachments?.map((attachment) => ({\n ...attachment,\n title: escapeCharacterReferences(attachment.title),\n })),\n quote: quote && {\n ...quote,\n text: escapeCharacterReferences(quote.text),\n ...(quote.sourceTitle !== undefined && {\n sourceTitle: escapeCharacterReferences(quote.sourceTitle),\n }),\n },\n userText: send.draftMarkdown,\n appUrl,\n });\n return { text, draftMarkdown };\n}\n\n/**\n * Holds a composed message in the chat outbox while sends are on hold (Athena can't be reached, or\n * earlier messages still wait): the uploaded attachments and the quote around the editor's text,\n * exactly as {@link buildComposedSend} would send them, so it goes with them once Athena is back.\n * The attachments are files already in Athena (an upload that finished before the drop); they are\n * named on the held message so the outbox asks Athena, right before it goes, that each can still\n * be opened. Cancel or Edit gives back the composed draft: the attachments as mentions in the\n * editor, the quote as quoted lines, nothing lost. `carried` are files already in Athena the\n * editor's own draft carries (mentions a held message gave back), named with the pills. `null`\n * when there is nothing to hold.\n */\nexport function holdComposedSend({\n outbox,\n attachments,\n carried = [],\n quote,\n send,\n appUrl,\n}: {\n outbox: ChatOutbox;\n attachments?: UploadedAsset[];\n carried?: readonly ChatOutboxAttachment[];\n quote?: QuoteData | null;\n send: ComposerSend;\n appUrl?: string;\n}): ChatOutboxEntry | null {\n const composed = buildComposedSend({ attachments, quote, send, appUrl });\n if (!composed) return null;\n const named = new Map<string, ChatOutboxAttachment>();\n for (const attachment of attachments ?? []) {\n named.set(attachment.id, {\n assetId: attachment.id,\n title: attachment.title,\n ...(attachment.mediaType && { mediaType: attachment.mediaType }),\n });\n }\n for (const attachment of carried) {\n if (!named.has(attachment.assetId)) named.set(attachment.assetId, attachment);\n }\n return outbox.hold({\n text: composed.text,\n composerMarkdown: composed.draftMarkdown,\n metadata: withDeepAgentComposerMarkdown({\n metadata: undefined,\n text: composed.text,\n markdown: composed.draftMarkdown,\n }),\n attachments: [...named.values()],\n });\n}\n"],"names":["buildAttachmentMarkdownWithAppUrl","escapeCharacterReferences","withDeepAgentComposerMarkdown"],"mappings":";;;;;AAqBO,SAAS,qBAAqB,MAK1B;;AACT,QAAM,QAAkB,CAAA;AAExB,MAAI,KAAK,eAAe,KAAK,YAAY,SAAS,GAAG;AACnD,UAAM,eAAeA,kBAAAA,kCAAkC;AAAA,MACrD,aAAa,KAAK;AAAA,MAClB,QAAQ,KAAK;AAAA,IAAA,CACd;AACD,QAAI,aAAc,OAAM,KAAK,YAAY;AAAA,EAC3C;AAEA,MAAI,KAAK,OAAO;AACd,UAAM,cA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Ac,eAAe,IAAI;AAC1C,UAAM,IAAI,WAAW,IAAI;AAAA,MACvB,SAAS,WAAW;AAAA,MACpB,OAAO,WAAW;AAAA,MAClB,GAAI,WAAW,aAAa,EAAE,WAAW,WAAW,UAAA;AAAA,IAAU,CAC/D;AAAA,EACH;AACA,aAAW,cAAc,SAAS;AAChC,QAAI,CAAC,MAAM,IAAI,WAAW,OAAO,EAAG,OAAM,IAAI,WAAW,SAAS,UAAU;AAAA,EAC9E;AACA,SAAO,OAAO,KAAK;AAAA,IACjB,MAAM,SAAS;AAAA,IACf,kBAAkB,SAAS;AAAA,IAC3B,UAAUC,iBAAAA,8BAA8B;AAAA,MACtC,UAAU;AAAA,MACV,MAAM,SAAS;AAAA,MACf,UAAU,SAAS;AAAA,IAAA,CACpB;AAAA,IACD,aAAa,CAAC,GAAG,MAAM,QAAQ;AAAA,EAAA,CAChC;AACH;;;;"}
@@ -1,3 +1,4 @@
1
+ import { type ChatOutbox, type ChatOutboxAttachment, type ChatOutboxEntry } from '../agent-runtime/src/index';
1
2
  import type { UploadedAsset } from './useFileUpload';
2
3
  import type { QuoteData } from './QuoteContext';
3
4
  import { type ComposerSend } from '../chat-ui/composer/composer-message';
@@ -34,3 +35,22 @@ export declare function buildComposedSend({ attachments, quote, send, appUrl, }:
34
35
  send: ComposerSend;
35
36
  appUrl?: string;
36
37
  }): ComposerSend | null;
38
+ /**
39
+ * Holds a composed message in the chat outbox while sends are on hold (Athena can't be reached, or
40
+ * earlier messages still wait): the uploaded attachments and the quote around the editor's text,
41
+ * exactly as {@link buildComposedSend} would send them, so it goes with them once Athena is back.
42
+ * The attachments are files already in Athena (an upload that finished before the drop); they are
43
+ * named on the held message so the outbox asks Athena, right before it goes, that each can still
44
+ * be opened. Cancel or Edit gives back the composed draft: the attachments as mentions in the
45
+ * editor, the quote as quoted lines, nothing lost. `carried` are files already in Athena the
46
+ * editor's own draft carries (mentions a held message gave back), named with the pills. `null`
47
+ * when there is nothing to hold.
48
+ */
49
+ export declare function holdComposedSend({ outbox, attachments, carried, quote, send, appUrl, }: {
50
+ outbox: ChatOutbox;
51
+ attachments?: UploadedAsset[];
52
+ carried?: readonly ChatOutboxAttachment[];
53
+ quote?: QuoteData | null;
54
+ send: ComposerSend;
55
+ appUrl?: string;
56
+ }): ChatOutboxEntry | null;
@@ -1,5 +1,6 @@
1
1
  import { buildAttachmentMarkdownWithAppUrl } from "./AttachmentContext.js";
2
2
  import { escapeCharacterReferences } from "../chat-ui/composer/composer-message.js";
3
+ import { withDeepAgentComposerMarkdown } from "../agent-runtime/src/composer-markdown.js";
3
4
  function buildComposedMessage(opts) {
4
5
  var _a;
5
6
  const parts = [];
@@ -45,8 +46,41 @@ function buildComposedSend({
45
46
  });
46
47
  return { text, draftMarkdown };
47
48
  }
49
+ function holdComposedSend({
50
+ outbox,
51
+ attachments,
52
+ carried = [],
53
+ quote,
54
+ send,
55
+ appUrl
56
+ }) {
57
+ const composed = buildComposedSend({ attachments, quote, send, appUrl });
58
+ if (!composed) return null;
59
+ const named = /* @__PURE__ */ new Map();
60
+ for (const attachment of attachments ?? []) {
61
+ named.set(attachment.id, {
62
+ assetId: attachment.id,
63
+ title: attachment.title,
64
+ ...attachment.mediaType && { mediaType: attachment.mediaType }
65
+ });
66
+ }
67
+ for (const attachment of carried) {
68
+ if (!named.has(attachment.assetId)) named.set(attachment.assetId, attachment);
69
+ }
70
+ return outbox.hold({
71
+ text: composed.text,
72
+ composerMarkdown: composed.draftMarkdown,
73
+ metadata: withDeepAgentComposerMarkdown({
74
+ metadata: void 0,
75
+ text: composed.text,
76
+ markdown: composed.draftMarkdown
77
+ }),
78
+ attachments: [...named.values()]
79
+ });
80
+ }
48
81
  export {
49
82
  buildComposedMessage,
50
- buildComposedSend
83
+ buildComposedSend,
84
+ holdComposedSend
51
85
  };
52
86
  //# sourceMappingURL=build-composed-message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-composed-message.js","sources":["../../src/composer/build-composed-message.ts"],"sourcesContent":["import type { UploadedAsset } from './useFileUpload';\nimport type { QuoteData } from './QuoteContext';\nimport { buildAttachmentMarkdownWithAppUrl } from './AttachmentContext';\nimport {\n type ComposerSend,\n escapeCharacterReferences,\n} from '../chat-ui/composer/composer-message';\n\n/**\n * Assembles a composed message from attachments, a quote, and user text.\n * Used by both the TipTap Enter-key submit and the send-button click handler\n * to avoid duplicating the message-assembly logic.\n *\n * Returns an empty string if all inputs are empty.\n */\nexport function buildComposedMessage(opts: {\n attachments?: UploadedAsset[];\n quote?: QuoteData | null;\n userText?: string;\n appUrl?: string;\n}): string {\n const parts: string[] = [];\n\n if (opts.attachments && opts.attachments.length > 0) {\n const attachmentMd = buildAttachmentMarkdownWithAppUrl({\n attachments: opts.attachments,\n appUrl: opts.appUrl,\n });\n if (attachmentMd) parts.push(attachmentMd);\n }\n\n if (opts.quote) {\n const quotedLines = opts.quote.text.split('\\n').map((l) => `> ${l}`).join('\\n');\n const sourceLabel = opts.quote.sourceTitle\n ? `From \"${opts.quote.sourceTitle}\"`\n : opts.quote.sourceRole === 'assistant'\n ? 'Quoting assistant'\n : 'Quoting';\n parts.push(`${sourceLabel}:\\n${quotedLines}`);\n }\n\n const trimmed = opts.userText?.trim();\n if (trimmed) parts.push(trimmed);\n\n return parts.join('\\n\\n');\n}\n\n/**\n * The composed message a send delivers and the draft it came from: the same\n * attachments and quote around the editor's text as typed in one, and around\n * the editor's draft in the other (`ComposerSend`). `null` when there is\n * nothing to send.\n *\n * The quote and the attachment titles are text the person did not type in\n * the editor, and the message carries them as they are. The draft writes an\n * `&` in them that starts a character reference as `&amp;`, as the composer's\n * draft does for typed text, so it reads back as the message and stays a draft\n * of the message's own text (`isComposerMarkdownOfText`, which agora applies\n * too): a quoted `&lt;` would otherwise read as `<` in the draft and the\n * message would lose its composer markdown.\n */\nexport function buildComposedSend({\n attachments,\n quote,\n send,\n appUrl,\n}: {\n attachments?: UploadedAsset[];\n quote?: QuoteData | null;\n send: ComposerSend;\n appUrl?: string;\n}): ComposerSend | null {\n const text = buildComposedMessage({ attachments, quote, userText: send.text, appUrl });\n if (!text) return null;\n const draftMarkdown = buildComposedMessage({\n attachments: attachments?.map((attachment) => ({\n ...attachment,\n title: escapeCharacterReferences(attachment.title),\n })),\n quote: quote && {\n ...quote,\n text: escapeCharacterReferences(quote.text),\n ...(quote.sourceTitle !== undefined && {\n sourceTitle: escapeCharacterReferences(quote.sourceTitle),\n }),\n },\n userText: send.draftMarkdown,\n appUrl,\n });\n return { text, draftMarkdown };\n}\n"],"names":[],"mappings":";;AAeO,SAAS,qBAAqB,MAK1B;;AACT,QAAM,QAAkB,CAAA;AAExB,MAAI,KAAK,eAAe,KAAK,YAAY,SAAS,GAAG;AACnD,UAAM,eAAe,kCAAkC;AAAA,MACrD,aAAa,KAAK;AAAA,MAClB,QAAQ,KAAK;AAAA,IAAA,CACd;AACD,QAAI,aAAc,OAAM,KAAK,YAAY;AAAA,EAC3C;AAEA,MAAI,KAAK,OAAO;AACd,UAAM,cAAc,KAAK,MAAM,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,EAAE,KAAK,IAAI;AAC9E,UAAM,cAAc,KAAK,MAAM,cAC3B,SAAS,KAAK,MAAM,WAAW,MAC/B,KAAK,MAAM,eAAe,cACxB,sBACA;AACN,UAAM,KAAK,GAAG,WAAW;AAAA,EAAM,WAAW,EAAE;AAAA,EAC9C;AAEA,QAAM,WAAU,UAAK,aAAL,mBAAe;AAC/B,MAAI,QAAS,OAAM,KAAK,OAAO;AAE/B,SAAO,MAAM,KAAK,MAAM;AAC1B;AAgBO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKwB;AACtB,QAAM,OAAO,qBAAqB,EAAE,aAAa,OAAO,UAAU,KAAK,MAAM,QAAQ;AACrF,MAAI,CAAC,KAAM,QAAO;AAClB,QAAM,gBAAgB,qBAAqB;AAAA,IACzC,aAAa,2CAAa,IAAI,CAAC,gBAAgB;AAAA,MAC7C,GAAG;AAAA,MACH,OAAO,0BAA0B,WAAW,KAAK;AAAA,IAAA;AAAA,IAEnD,OAAO,SAAS;AAAA,MACd,GAAG;AAAA,MACH,MAAM,0BAA0B,MAAM,IAAI;AAAA,MAC1C,GAAI,MAAM,gBAAgB,UAAa;AAAA,QACrC,aAAa,0BAA0B,MAAM,WAAW;AAAA,MAAA;AAAA,IAC1D;AAAA,IAEF,UAAU,KAAK;AAAA,IACf;AAAA,EAAA,CACD;AACD,SAAO,EAAE,MAAM,cAAA;AACjB;"}
1
+ {"version":3,"file":"build-composed-message.js","sources":["../../src/composer/build-composed-message.ts"],"sourcesContent":["import {\n type ChatOutbox,\n type ChatOutboxAttachment,\n type ChatOutboxEntry,\n withDeepAgentComposerMarkdown,\n} from '@athenaintel/agent-runtime';\nimport type { UploadedAsset } from './useFileUpload';\nimport type { QuoteData } from './QuoteContext';\nimport { buildAttachmentMarkdownWithAppUrl } from './AttachmentContext';\nimport {\n type ComposerSend,\n escapeCharacterReferences,\n} from '../chat-ui/composer/composer-message';\n\n/**\n * Assembles a composed message from attachments, a quote, and user text.\n * Used by both the TipTap Enter-key submit and the send-button click handler\n * to avoid duplicating the message-assembly logic.\n *\n * Returns an empty string if all inputs are empty.\n */\nexport function buildComposedMessage(opts: {\n attachments?: UploadedAsset[];\n quote?: QuoteData | null;\n userText?: string;\n appUrl?: string;\n}): string {\n const parts: string[] = [];\n\n if (opts.attachments && opts.attachments.length > 0) {\n const attachmentMd = buildAttachmentMarkdownWithAppUrl({\n attachments: opts.attachments,\n appUrl: opts.appUrl,\n });\n if (attachmentMd) parts.push(attachmentMd);\n }\n\n if (opts.quote) {\n const quotedLines = opts.quote.text.split('\\n').map((l) => `> ${l}`).join('\\n');\n const sourceLabel = opts.quote.sourceTitle\n ? `From \"${opts.quote.sourceTitle}\"`\n : opts.quote.sourceRole === 'assistant'\n ? 'Quoting assistant'\n : 'Quoting';\n parts.push(`${sourceLabel}:\\n${quotedLines}`);\n }\n\n const trimmed = opts.userText?.trim();\n if (trimmed) parts.push(trimmed);\n\n return parts.join('\\n\\n');\n}\n\n/**\n * The composed message a send delivers and the draft it came from: the same\n * attachments and quote around the editor's text as typed in one, and around\n * the editor's draft in the other (`ComposerSend`). `null` when there is\n * nothing to send.\n *\n * The quote and the attachment titles are text the person did not type in\n * the editor, and the message carries them as they are. The draft writes an\n * `&` in them that starts a character reference as `&amp;`, as the composer's\n * draft does for typed text, so it reads back as the message and stays a draft\n * of the message's own text (`isComposerMarkdownOfText`, which agora applies\n * too): a quoted `&lt;` would otherwise read as `<` in the draft and the\n * message would lose its composer markdown.\n */\nexport function buildComposedSend({\n attachments,\n quote,\n send,\n appUrl,\n}: {\n attachments?: UploadedAsset[];\n quote?: QuoteData | null;\n send: ComposerSend;\n appUrl?: string;\n}): ComposerSend | null {\n const text = buildComposedMessage({ attachments, quote, userText: send.text, appUrl });\n if (!text) return null;\n const draftMarkdown = buildComposedMessage({\n attachments: attachments?.map((attachment) => ({\n ...attachment,\n title: escapeCharacterReferences(attachment.title),\n })),\n quote: quote && {\n ...quote,\n text: escapeCharacterReferences(quote.text),\n ...(quote.sourceTitle !== undefined && {\n sourceTitle: escapeCharacterReferences(quote.sourceTitle),\n }),\n },\n userText: send.draftMarkdown,\n appUrl,\n });\n return { text, draftMarkdown };\n}\n\n/**\n * Holds a composed message in the chat outbox while sends are on hold (Athena can't be reached, or\n * earlier messages still wait): the uploaded attachments and the quote around the editor's text,\n * exactly as {@link buildComposedSend} would send them, so it goes with them once Athena is back.\n * The attachments are files already in Athena (an upload that finished before the drop); they are\n * named on the held message so the outbox asks Athena, right before it goes, that each can still\n * be opened. Cancel or Edit gives back the composed draft: the attachments as mentions in the\n * editor, the quote as quoted lines, nothing lost. `carried` are files already in Athena the\n * editor's own draft carries (mentions a held message gave back), named with the pills. `null`\n * when there is nothing to hold.\n */\nexport function holdComposedSend({\n outbox,\n attachments,\n carried = [],\n quote,\n send,\n appUrl,\n}: {\n outbox: ChatOutbox;\n attachments?: UploadedAsset[];\n carried?: readonly ChatOutboxAttachment[];\n quote?: QuoteData | null;\n send: ComposerSend;\n appUrl?: string;\n}): ChatOutboxEntry | null {\n const composed = buildComposedSend({ attachments, quote, send, appUrl });\n if (!composed) return null;\n const named = new Map<string, ChatOutboxAttachment>();\n for (const attachment of attachments ?? []) {\n named.set(attachment.id, {\n assetId: attachment.id,\n title: attachment.title,\n ...(attachment.mediaType && { mediaType: attachment.mediaType }),\n });\n }\n for (const attachment of carried) {\n if (!named.has(attachment.assetId)) named.set(attachment.assetId, attachment);\n }\n return outbox.hold({\n text: composed.text,\n composerMarkdown: composed.draftMarkdown,\n metadata: withDeepAgentComposerMarkdown({\n metadata: undefined,\n text: composed.text,\n markdown: composed.draftMarkdown,\n }),\n attachments: [...named.values()],\n });\n}\n"],"names":[],"mappings":";;;AAqBO,SAAS,qBAAqB,MAK1B;;AACT,QAAM,QAAkB,CAAA;AAExB,MAAI,KAAK,eAAe,KAAK,YAAY,SAAS,GAAG;AACnD,UAAM,eAAe,kCAAkC;AAAA,MACrD,aAAa,KAAK;AAAA,MAClB,QAAQ,KAAK;AAAA,IAAA,CACd;AACD,QAAI,aAAc,OAAM,KAAK,YAAY;AAAA,EAC3C;AAEA,MAAI,KAAK,OAAO;AACd,UAAM,cAAc,KAAK,MAAM,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,EAAE,KAAK,IAAI;AAC9E,UAAM,cAAc,KAAK,MAAM,cAC3B,SAAS,KAAK,MAAM,WAAW,MAC/B,KAAK,MAAM,eAAe,cACxB,sBACA;AACN,UAAM,KAAK,GAAG,WAAW;AAAA,EAAM,WAAW,EAAE;AAAA,EAC9C;AAEA,QAAM,WAAU,UAAK,aAAL,mBAAe;AAC/B,MAAI,QAAS,OAAM,KAAK,OAAO;AAE/B,SAAO,MAAM,KAAK,MAAM;AAC1B;AAgBO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;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AAAA,IAAA,CACpB;AAAA,IACD,aAAa,CAAC,GAAG,MAAM,QAAQ;AAAA,EAAA,CAChC;AACH;"}
@@ -4,9 +4,41 @@ const react$1 = require("react");
4
4
  const react = require("@assistant-ui/react");
5
5
  const athenaDiagnostics = require("../diagnostics/athena-diagnostics.cjs");
6
6
  const errors = require("../diagnostics/errors.cjs");
7
+ const statewireSessionLane = require("../runtime/statewire-session-lane.cjs");
7
8
  const statewireThreadList = require("../threads/statewire-thread-list.cjs");
8
9
  function createComposerHandoffStore() {
9
- return { pending: [], focusOnNextMirror: false, focusEnd: null, focusOnMount: false };
10
+ return {
11
+ pending: [],
12
+ focusOnNextMirror: false,
13
+ focusEnd: null,
14
+ focusOnMount: false,
15
+ restoredAttachments: /* @__PURE__ */ new Map()
16
+ };
17
+ }
18
+ function rememberRestoredAttachments({
19
+ store,
20
+ threadId,
21
+ attachments
22
+ }) {
23
+ if (attachments.length === 0) return;
24
+ store.restoredAttachments ?? (store.restoredAttachments = /* @__PURE__ */ new Map());
25
+ const kept = store.restoredAttachments.get(threadId) ?? [];
26
+ const known = new Set(kept.map((attachment) => attachment.assetId));
27
+ store.restoredAttachments.set(threadId, [
28
+ ...kept,
29
+ ...attachments.filter((attachment) => !known.has(attachment.assetId))
30
+ ]);
31
+ }
32
+ function takeRestoredAttachments({
33
+ store,
34
+ threadId,
35
+ assetIdsInDraft
36
+ }) {
37
+ var _a, _b;
38
+ const kept = (_a = store == null ? void 0 : store.restoredAttachments) == null ? void 0 : _a.get(threadId);
39
+ if (!kept) return [];
40
+ (_b = store == null ? void 0 : store.restoredAttachments) == null ? void 0 : _b.delete(threadId);
41
+ return kept.filter((attachment) => assetIdsInDraft.has(attachment.assetId));
10
42
  }
11
43
  const ComposerHandoffContext = react$1.createContext(null);
12
44
  function useComposerHandoffStore() {
@@ -28,7 +60,8 @@ function useComposerReady() {
28
60
  var _a;
29
61
  return ((_a = s.optional.thread) == null ? void 0 : _a.isLoading) ?? false;
30
62
  });
31
- return !((list == null ? void 0 : list.isLoading) ?? false) && !threadLoading;
63
+ const lanePending = statewireSessionLane.useStatewireSessionLanePending();
64
+ return !((list == null ? void 0 : list.isLoading) ?? false) && !threadLoading && !lanePending;
32
65
  }
33
66
  function mergeComposerDraft({
34
67
  current,
@@ -114,6 +147,8 @@ function clearComposerHandoff({
114
147
  store,
115
148
  reason
116
149
  }) {
150
+ var _a;
151
+ (_a = store.restoredAttachments) == null ? void 0 : _a.clear();
117
152
  const writes = store.pending;
118
153
  if (writes.length === 0) return;
119
154
  store.pending = [];
@@ -127,6 +162,8 @@ exports.drainComposerHandoff = drainComposerHandoff;
127
162
  exports.focusComposer = focusComposer;
128
163
  exports.mergeComposerDraft = mergeComposerDraft;
129
164
  exports.queueComposerWrite = queueComposerWrite;
165
+ exports.rememberRestoredAttachments = rememberRestoredAttachments;
166
+ exports.takeRestoredAttachments = takeRestoredAttachments;
130
167
  exports.useComposerHandoffStore = useComposerHandoffStore;
131
168
  exports.useComposerReady = useComposerReady;
132
169
  exports.useFocusComposer = useFocusComposer;
@@ -1 +1 @@
1
- {"version":3,"file":"composer-handoff.cjs","sources":["../../src/composer/composer-handoff.ts"],"sourcesContent":["/**\n * Composer handoff: writes to the chat composer from host UI that lives\n * outside `<AthenaChat>` (a sidebar, an agenda card, a workflow button).\n *\n * Two problems it solves for `useAppendToComposer` / `useSendMessage`:\n *\n * 1. A write before the chat is ready is lost. While the thread list is still\n * resolving the active thread, or the thread's history is still loading,\n * the composer the hooks write to belongs to a mount that is about to be\n * replaced (thread-list mode keys the statewire subtree by thread), and\n * the draft goes with it. The store below lives ABOVE that mount, so a\n * write made too early waits here and the ready mount drains it.\n * 2. A prefilled draft should put the caret after the text so the user can\n * keep typing or dictating. The Tiptap editor mirrors runtime text on a\n * later tick; the `focusOnNextMirror` flag asks it to focus at the end\n * right after that mirror lands, instead of the host guessing a delay.\n *\n * Every queued write is bound to the statewire thread it was made for and\n * drains only into that thread's mount; a thread switch, an identity change\n * or a provider unmount drops what waits with a `composer_write_dropped`\n * error, never into another user's or another thread's composer.\n */\nimport { createContext, useCallback, useContext } from 'react';\nimport { useAuiState } from '@assistant-ui/react';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport { AthenaSdkError } from '../diagnostics/errors';\nimport { useAthenaStatewireThreadList } from '../threads/statewire-thread-list';\n\n/** The slice of the assistant-ui client the handoff writes to. */\nexport interface ComposerTarget {\n composer: {\n getState: () => { text: string };\n setText: (text: string) => void;\n send: (options?: { steer?: boolean }) => unknown;\n };\n}\n\nexport interface ComposerWrite {\n text: string;\n /** Replace the draft instead of appending on a new line. */\n replace: boolean;\n /** Submit right after writing. */\n send: boolean;\n /** Put the caret at the end of the draft once the editor shows it. */\n focus: boolean;\n /** The statewire thread the write was made for; it drains only into that thread's mount. */\n threadId: string | null;\n /** Settled once the write has been applied (and, for `send`, with the send's outcome). */\n resolve?: (outcome: Promise<void> | void) => void;\n /** Settled with `composer_write_dropped` when the write can no longer land. */\n reject?: (error: AthenaSdkError) => void;\n}\n\nexport interface ComposerHandoffStore {\n /** Writes waiting for a ready composer, oldest first. Adjacent plain appends fold together. */\n pending: ComposerWrite[];\n /** Set by a `focus` write; the editor consumes it after mirroring the draft. */\n focusOnNextMirror: boolean;\n /** Registered by the mounted editor: place the caret at the end of the draft. */\n focusEnd: (() => void) | null;\n /** Set by `useFocusComposer` before the editor mounted; the editor consumes it when it does. */\n focusOnMount: boolean;\n}\n\nexport function createComposerHandoffStore(): ComposerHandoffStore {\n return { pending: [], focusOnNextMirror: false, focusEnd: null, focusOnMount: false };\n}\n\nexport const ComposerHandoffContext = createContext<ComposerHandoffStore | null>(null);\n\n/** The provider's handoff store, or null outside `AthenaProvider`. */\nexport function useComposerHandoffStore(): ComposerHandoffStore | null {\n return useContext(ComposerHandoffContext);\n}\n\n/**\n * Puts the caret at the end of the composer's draft and leaves the draft as it is; asked before the\n * editor has mounted, it focuses the editor as it mounts. For a host that shows the chat again and\n * wants typing to land in it (a launcher window a shortcut brings back).\n */\nexport function useFocusComposer(): () => void {\n const store = useComposerHandoffStore();\n return useCallback(() => {\n if (store) focusComposer({ store });\n }, [store]);\n}\n\n/** The caret to the end of the draft now, or, with no editor mounted yet, as one mounts. */\nexport function focusComposer({ store }: { store: ComposerHandoffStore }): void {\n if (store.focusEnd) store.focusEnd();\n else store.focusOnMount = true;\n}\n\n/**\n * Whether a composer write lands now: in thread-list mode the list has\n * resolved which thread is active, and that thread's history has loaded.\n * Until then the composer the hooks write to is the one of a mount that is\n * about to be replaced, and the draft goes with it.\n *\n * Deliberately not the socket status: a never-started chat sits in\n * `standby` until its first send and must still take a prefill.\n */\nexport function useComposerReady(): boolean {\n const list = useAthenaStatewireThreadList();\n const threadLoading = useAuiState((s) => s.optional.thread?.isLoading ?? false);\n return !(list?.isLoading ?? false) && !threadLoading;\n}\n\n/** The draft after `write`: `replace` (or an empty draft) takes the text as is. */\nexport function mergeComposerDraft({\n current,\n write,\n}: {\n current: string;\n write: Pick<ComposerWrite, 'text' | 'replace'>;\n}): string {\n if (write.replace || !current) return write.text;\n return `${current}\\n${write.text}`;\n}\n\n/**\n * Write into the live composer. Returns the send's outcome for a `send`\n * write so callers can await it.\n */\nexport function applyComposerWrite({\n target,\n store,\n write,\n}: {\n target: ComposerTarget;\n store: ComposerHandoffStore | null;\n write: ComposerWrite;\n}): Promise<void> | void {\n const current = target.composer.getState().text ?? '';\n const next = mergeComposerDraft({ current, write });\n target.composer.setText(next);\n if (write.focus && store) {\n // An unchanged draft never re-mirrors, so focus at once; otherwise the\n // editor focuses itself right after it has shown the new text.\n if (next === current) store.focusEnd?.();\n else store.focusOnNextMirror = true;\n }\n athenaDiagnostics.emit('composer.handoff', {\n level: 'debug',\n data: { phase: 'applied', send: write.send, focus: write.focus, chars: next.length },\n });\n if (write.send) {\n return Promise.resolve(target.composer.send({ steer: false })).then(() => undefined);\n }\n return undefined;\n}\n\n/**\n * Hold a write until the composer is ready. Writes keep their order; a plain\n * append folds into a directly preceding plain append for the same thread\n * (one draft, not two), while a replace or a send is kept as its own step so\n * no message is lost and every send settles on its own.\n */\nexport function queueComposerWrite({\n store,\n write,\n}: {\n store: ComposerHandoffStore;\n write: ComposerWrite;\n}): void {\n const last = store.pending[store.pending.length - 1];\n const foldable =\n last !== undefined &&\n !last.send &&\n !write.send &&\n !write.replace &&\n last.threadId === write.threadId &&\n last.resolve === undefined &&\n write.resolve === undefined;\n if (foldable) {\n last.text = mergeComposerDraft({ current: last.text, write });\n last.focus = last.focus || write.focus;\n } else {\n store.pending.push(write);\n }\n athenaDiagnostics.emit('composer.handoff', {\n level: 'debug',\n data: { phase: 'deferred', send: write.send, focus: write.focus, queued: store.pending.length },\n });\n}\n\nfunction dropWrite({ write, reason }: { write: ComposerWrite; reason: string }): void {\n const error = new AthenaSdkError({\n code: 'composer_write_dropped',\n message: `A composer ${write.send ? 'send' : 'draft'} queued before the chat was ready was dropped: ${reason}.`,\n hint: 'Make the write again from the chat that is active now.',\n context: { threadId: write.threadId, send: write.send },\n });\n athenaDiagnostics.emit('composer.handoff', {\n level: 'warn',\n error,\n data: { phase: 'dropped', send: write.send, reason, threadId: write.threadId },\n });\n write.reject?.(error);\n}\n\n/**\n * Deliver the pending writes, in order, into a now-ready composer. A write\n * made for another thread is dropped (rejected), never applied here.\n */\nexport function drainComposerHandoff({\n store,\n target,\n threadId,\n}: {\n store: ComposerHandoffStore;\n target: ComposerTarget;\n /** The statewire thread of the mount that is draining. */\n threadId: string | null;\n}): void {\n const writes = store.pending;\n if (writes.length === 0) return;\n store.pending = [];\n for (const write of writes) {\n if (write.threadId !== null && threadId !== null && write.threadId !== threadId) {\n dropWrite({ write, reason: `it was made for thread ${write.threadId}, thread ${threadId} is active` });\n continue;\n }\n const outcome = applyComposerWrite({ target, store, write });\n write.resolve?.(outcome);\n }\n}\n\n/** Drop every pending write (identity changed, provider unmounted). */\nexport function clearComposerHandoff({\n store,\n reason,\n}: {\n store: ComposerHandoffStore;\n reason: string;\n}): void {\n const writes = store.pending;\n if (writes.length === 0) return;\n store.pending = [];\n for (const write of writes) dropWrite({ write, reason });\n}\n"],"names":["createContext","useContext","useCallback","useAthenaStatewireThreadList","useAuiState","athenaDiagnostics","AthenaSdkError"],"mappings":";;;;;;;AAgEO,SAAS,6BAAmD;AACjE,SAAO,EAAE,SAAS,CAAA,GAAI,mBAAmB,OAAO,UAAU,MAAM,cAAc,MAAA;AAChF;AAEO,MAAM,yBAAyBA,QAAAA,cAA2C,IAAI;AAG9E,SAAS,0BAAuD;AACrE,SAAOC,QAAAA,WAAW,sBAAsB;AAC1C;AAOO,SAAS,mBAA+B;AAC7C,QAAM,QAAQ,wBAAA;AACd,SAAOC,QAAAA,YAAY,MAAM;AACvB,QAAI,MAAO,eAAc,EAAE,OAAO;AAAA,EACpC,GAAG,CAAC,KAAK,CAAC;AACZ;AAGO,SAAS,cAAc,EAAE,SAAgD;AAC9E,MAAI,MAAM,SAAU,OAAM,SAAA;AAAA,aACf,eAAe;AAC5B;AAWO,SAAS,mBAA4B;AAC1C,QAAM,OAAOC,oBAAAA,6BAAA;AACb,QAAM,gBAAgBC,MAAAA,YAAY,CAAC,MAAA;;AAAM,oBAAE,SAAS,WAAX,mBAAmB,cAAa;AAAA,GAAK;AAC9E,SAAO,GAAE,6BAAM,cAAa,UAAU,CAAC;AACzC;AAGO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AACF,GAGW;AACT,MAAI,MAAM,WAAW,CAAC,gBAAgB,MAAM;AAC5C,SAAO,GAAG,OAAO;AAAA,EAAK,MAAM,IAAI;AAClC;AAMO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF,GAIyB;;AACvB,QAAM,UAAU,OAAO,SAAS,SAAA,EAAW,QAAQ;AACnD,QAAM,OAAO,mBAAmB,EAAE,SAAS,OAAO;AAClD,SAAO,SAAS,QAAQ,IAAI;AAC5B,MAAI,MAAM,SAAS,OAAO;AAGxB,QAAI,SAAS,QAAS,aAAM,aAAN;AAAA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AO;AAAA,IACP;AAAA,IACA,MAAM,EAAE,OAAO,WAAW,MAAM,MAAM,MAAM,QAAQ,UAAU,MAAM,SAAA;AAAA,EAAS,CAC9E;AACD,cAAM,WAAN,+BAAe;AACjB;AAMO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAKS;;AACP,QAAM,SAAS,MAAM;AACrB,MAAI,OAAO,WAAW,EAAG;AACzB,QAAM,UAAU,CAAA;AAChB,aAAW,SAAS,QAAQ;AAC1B,QAAI,MAAM,aAAa,QAAQ,aAAa,QAAQ,MAAM,aAAa,UAAU;AAC/E,gBAAU,EAAE,OAAO,QAAQ,0BAA0B,MAAM,QAAQ,YAAY,QAAQ,aAAA,CAAc;AACrG;AAAA,IACF;AACA,UAAM,UAAU,mBAAmB,EAAE,QAAQ,OAAO,OAAO;AAC3D,gBAAM,YAAN,+BAAgB;AAAA,EAClB;AACF;AAGO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AACF,GAGS;AACP,QAAM,SAAS,MAAM;AACrB,MAAI,OAAO,WAAW,EAAG;AACzB,QAAM,UAAU,CAAA;AAChB,aAAW,SAAS,OAAQ,WAAU,EAAE,OAAO,QAAQ;AACzD;;;;;;;;;;;;"}
1
+ {"version":3,"file":"composer-handoff.cjs","sources":["../../src/composer/composer-handoff.ts"],"sourcesContent":["/**\n * Composer handoff: writes to the chat composer from host UI that lives\n * outside `<AthenaChat>` (a sidebar, an agenda card, a workflow button).\n *\n * Two problems it solves for `useAppendToComposer` / `useSendMessage`:\n *\n * 1. A write before the chat is ready is lost. While the thread list is still\n * resolving the active thread, or the thread's history is still loading,\n * the composer the hooks write to belongs to a mount that is about to be\n * replaced (thread-list mode keys the statewire subtree by thread), and\n * the draft goes with it. The store below lives ABOVE that mount, so a\n * write made too early waits here and the ready mount drains it.\n * 2. A prefilled draft should put the caret after the text so the user can\n * keep typing or dictating. The Tiptap editor mirrors runtime text on a\n * later tick; the `focusOnNextMirror` flag asks it to focus at the end\n * right after that mirror lands, instead of the host guessing a delay.\n *\n * Every queued write is bound to the statewire thread it was made for and\n * drains only into that thread's mount; a thread switch, an identity change\n * or a provider unmount drops what waits with a `composer_write_dropped`\n * error, never into another user's or another thread's composer.\n */\nimport { createContext, useCallback, useContext } from 'react';\nimport { useAuiState } from '@assistant-ui/react';\nimport type { ChatOutboxAttachment } from '@athenaintel/agent-runtime';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport { AthenaSdkError } from '../diagnostics/errors';\nimport { useStatewireSessionLanePending } from '../runtime/statewire-session-lane';\nimport { useAthenaStatewireThreadList } from '../threads/statewire-thread-list';\n\n/** The slice of the assistant-ui client the handoff writes to. */\nexport interface ComposerTarget {\n composer: {\n getState: () => { text: string };\n setText: (text: string) => void;\n send: (options?: { steer?: boolean }) => unknown;\n };\n}\n\nexport interface ComposerWrite {\n text: string;\n /** Replace the draft instead of appending on a new line. */\n replace: boolean;\n /** Submit right after writing. */\n send: boolean;\n /** Put the caret at the end of the draft once the editor shows it. */\n focus: boolean;\n /** The statewire thread the write was made for; it drains only into that thread's mount. */\n threadId: string | null;\n /** Settled once the write has been applied (and, for `send`, with the send's outcome). */\n resolve?: (outcome: Promise<void> | void) => void;\n /** Settled with `composer_write_dropped` when the write can no longer land. */\n reject?: (error: AthenaSdkError) => void;\n}\n\nexport interface ComposerHandoffStore {\n /** Writes waiting for a ready composer, oldest first. Adjacent plain appends fold together. */\n pending: ComposerWrite[];\n /** Set by a `focus` write; the editor consumes it after mirroring the draft. */\n focusOnNextMirror: boolean;\n /** Registered by the mounted editor: place the caret at the end of the draft. */\n focusEnd: (() => void) | null;\n /** Set by `useFocusComposer` before the editor mounted; the editor consumes it when it does. */\n focusOnMount: boolean;\n /**\n * Per thread, the attachments of messages the chat outbox gave back to the composer (Cancel, or\n * Edit on one that couldn't be sent): files already in Athena, back in the draft as mentions. A\n * message held again from that draft names those still in it, so the outbox asks Athena about\n * them again before it goes ({@link rememberRestoredAttachments}, {@link takeRestoredAttachments}).\n */\n restoredAttachments?: Map<string, ChatOutboxAttachment[]>;\n}\n\nexport function createComposerHandoffStore(): ComposerHandoffStore {\n return {\n pending: [],\n focusOnNextMirror: false,\n focusEnd: null,\n focusOnMount: false,\n restoredAttachments: new Map(),\n };\n}\n\n/** A held message given back to `threadId`'s composer: remember the attachments it carried. */\nexport function rememberRestoredAttachments({\n store,\n threadId,\n attachments,\n}: {\n store: ComposerHandoffStore;\n threadId: string;\n attachments: readonly ChatOutboxAttachment[];\n}): void {\n if (attachments.length === 0) return;\n store.restoredAttachments ??= new Map();\n const kept = store.restoredAttachments.get(threadId) ?? [];\n const known = new Set(kept.map((attachment) => attachment.assetId));\n store.restoredAttachments.set(threadId, [\n ...kept,\n ...attachments.filter((attachment) => !known.has(attachment.assetId)),\n ]);\n}\n\n/**\n * The remembered attachments of `threadId`'s draft whose mentions it still holds, for the message\n * leaving it now; the composer forgets them all (sent, held again, or removed from the draft).\n */\nexport function takeRestoredAttachments({\n store,\n threadId,\n assetIdsInDraft,\n}: {\n store: ComposerHandoffStore | null;\n threadId: string;\n assetIdsInDraft: ReadonlySet<string>;\n}): ChatOutboxAttachment[] {\n const kept = store?.restoredAttachments?.get(threadId);\n if (!kept) return [];\n store?.restoredAttachments?.delete(threadId);\n return kept.filter((attachment) => assetIdsInDraft.has(attachment.assetId));\n}\n\nexport const ComposerHandoffContext = createContext<ComposerHandoffStore | null>(null);\n\n/** The provider's handoff store, or null outside `AthenaProvider`. */\nexport function useComposerHandoffStore(): ComposerHandoffStore | null {\n return useContext(ComposerHandoffContext);\n}\n\n/**\n * Puts the caret at the end of the composer's draft and leaves the draft as it is; asked before the\n * editor has mounted, it focuses the editor as it mounts. For a host that shows the chat again and\n * wants typing to land in it (a launcher window a shortcut brings back).\n */\nexport function useFocusComposer(): () => void {\n const store = useComposerHandoffStore();\n return useCallback(() => {\n if (store) focusComposer({ store });\n }, [store]);\n}\n\n/** The caret to the end of the draft now, or, with no editor mounted yet, as one mounts. */\nexport function focusComposer({ store }: { store: ComposerHandoffStore }): void {\n if (store.focusEnd) store.focusEnd();\n else store.focusOnMount = true;\n}\n\n/**\n * Whether a composer write lands now: in thread-list mode the list has\n * resolved which thread is active, that thread's history has loaded, and the\n * chat's session lane is known (the sign-in provider above has resolved who is\n * signed in; see `StatewireSessionLane`). Until then the composer the hooks\n * write to is the one of a mount that is about to be replaced, and the draft\n * goes with it, or a send would go into a parked lane that refuses it unsent.\n *\n * Deliberately not the socket status: a never-started chat sits in\n * `standby` until its first send and must still take a prefill.\n */\nexport function useComposerReady(): boolean {\n const list = useAthenaStatewireThreadList();\n const threadLoading = useAuiState((s) => s.optional.thread?.isLoading ?? false);\n const lanePending = useStatewireSessionLanePending();\n return !(list?.isLoading ?? false) && !threadLoading && !lanePending;\n}\n\n/** The draft after `write`: `replace` (or an empty draft) takes the text as is. */\nexport function mergeComposerDraft({\n current,\n write,\n}: {\n current: string;\n write: Pick<ComposerWrite, 'text' | 'replace'>;\n}): string {\n if (write.replace || !current) return write.text;\n return `${current}\\n${write.text}`;\n}\n\n/**\n * Write into the live composer. Returns the send's outcome for a `send`\n * write so callers can await it.\n */\nexport function applyComposerWrite({\n target,\n store,\n write,\n}: {\n target: ComposerTarget;\n store: ComposerHandoffStore | null;\n write: ComposerWrite;\n}): Promise<void> | void {\n const current = target.composer.getState().text ?? '';\n const next = mergeComposerDraft({ current, write });\n target.composer.setText(next);\n if (write.focus && store) {\n // An unchanged draft never re-mirrors, so focus at once; otherwise the\n // editor focuses itself right after it has shown the new text.\n if (next === current) store.focusEnd?.();\n else store.focusOnNextMirror = true;\n }\n athenaDiagnostics.emit('composer.handoff', {\n level: 'debug',\n data: { phase: 'applied', send: write.send, focus: write.focus, chars: next.length },\n });\n if (write.send) {\n return Promise.resolve(target.composer.send({ steer: false })).then(() => undefined);\n }\n return undefined;\n}\n\n/**\n * Hold a write until the composer is ready. Writes keep their order; a plain\n * append folds into a directly preceding plain append for the same thread\n * (one draft, not two), while a replace or a send is kept as its own step so\n * no message is lost and every send settles on its own.\n */\nexport function queueComposerWrite({\n store,\n write,\n}: {\n store: ComposerHandoffStore;\n write: ComposerWrite;\n}): void {\n const last = store.pending[store.pending.length - 1];\n const foldable =\n last !== undefined &&\n !last.send &&\n !write.send &&\n !write.replace &&\n last.threadId === write.threadId &&\n last.resolve === undefined &&\n write.resolve === undefined;\n if (foldable) {\n last.text = mergeComposerDraft({ current: last.text, write });\n last.focus = last.focus || write.focus;\n } else {\n store.pending.push(write);\n }\n athenaDiagnostics.emit('composer.handoff', {\n level: 'debug',\n data: { phase: 'deferred', send: write.send, focus: write.focus, queued: store.pending.length },\n });\n}\n\nfunction dropWrite({ write, reason }: { write: ComposerWrite; reason: string }): void {\n const error = new AthenaSdkError({\n code: 'composer_write_dropped',\n message: `A composer ${write.send ? 'send' : 'draft'} queued before the chat was ready was dropped: ${reason}.`,\n hint: 'Make the write again from the chat that is active now.',\n context: { threadId: write.threadId, send: write.send },\n });\n athenaDiagnostics.emit('composer.handoff', {\n level: 'warn',\n error,\n data: { phase: 'dropped', send: write.send, reason, threadId: write.threadId },\n });\n write.reject?.(error);\n}\n\n/**\n * Deliver the pending writes, in order, into a now-ready composer. A write\n * made for another thread is dropped (rejected), never applied here.\n */\nexport function drainComposerHandoff({\n store,\n target,\n threadId,\n}: {\n store: ComposerHandoffStore;\n target: ComposerTarget;\n /** The statewire thread of the mount that is draining. */\n threadId: string | null;\n}): void {\n const writes = store.pending;\n if (writes.length === 0) return;\n store.pending = [];\n for (const write of writes) {\n if (write.threadId !== null && threadId !== null && write.threadId !== threadId) {\n dropWrite({ write, reason: `it was made for thread ${write.threadId}, thread ${threadId} is active` });\n continue;\n }\n const outcome = applyComposerWrite({ target, store, write });\n write.resolve?.(outcome);\n }\n}\n\n/** Drop every pending write (identity changed, provider unmounted). */\nexport function clearComposerHandoff({\n store,\n reason,\n}: {\n store: ComposerHandoffStore;\n reason: string;\n}): void {\n // Another identity, or no provider: the attachments given back belong to drafts that are gone.\n store.restoredAttachments?.clear();\n const writes = store.pending;\n if (writes.length === 0) return;\n store.pending = [];\n for (const write of writes) dropWrite({ write, reason });\n}\n"],"names":["createContext","useContext","useCallback","useAthenaStatewireThreadList","useAuiState","useStatewireSessionLanePending","athenaDiagnostics","AthenaSdkError"],"mappings":";;;;;;;;AAyEO,SAAS,6BAAmD;AACjE,SAAO;AAAA,IACL,SAAS,CAAA;AAAA,IACT,mBAAmB;AAAA,IACnB,UAAU;AAAA,IACV,cAAc;AAAA,IACd,yCAAyB,IAAA;AAAA,EAAI;AAEjC;AAGO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AACF,GAIS;AACP,MAAI,YAAY,WAAW,EAAG;AAC9B,QAAM,wBAAN,MAAM,0CAA4B,IAAA;AAClC,QAAM,OAAO,MAAM,oBAAoB,IAAI,QAAQ,KAAK,CAAA;AACxD,QAAM,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC,eAAe,WAAW,OAAO,CAAC;AAClE,QAAM,oBAAoB,IAAI,UAAU;AAAA,IACtC,GAAG;AAAA,IACH,GAAG,YAAY,OAAO,CAAC,eAAe,CAAC,MAAM,IAAI,WAAW,OAAO,CAAC;AAAA,EAAA,CACrE;AACH;AAMO,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACF,GAI2B;;AACzB,QAAM,QAAO,oCAAO,wBAAP,mBAA4B,IAAI;AAC7C,MAAI,CAAC,KAAM,QAAO,CAAA;AAClB,uCAAO,wBAAP,mBAA4B,OAAO;AACnC,SAAO,KAAK,OAAO,CAAC,eAAe,gBAAgB,IAAI,WAAW,OAAO,CAAC;AAC5E;AAEO,MAAM,yBAAyBA,QAAAA,cAA2C,IAAI;AAG9E,SAAS,0BAAuD;AACrE,SAAOC,QAAAA,WAAW,sBAAsB;AAC1C;AAOO,SAAS,mBAA+B;AAC7C,QAAM,QAAQ,wBAAA;AACd,SAAOC,QAAAA,YAAY,MAAM;AACvB,QAAI,MAA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AAQ,0BAA0B,MAAM,QAAQ,YAAY,QAAQ,aAAA,CAAc;AACrG;AAAA,IACF;AACA,UAAM,UAAU,mBAAmB,EAAE,QAAQ,OAAO,OAAO;AAC3D,gBAAM,YAAN,+BAAgB;AAAA,EAClB;AACF;AAGO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AACF,GAGS;;AAEP,cAAM,wBAAN,mBAA2B;AAC3B,QAAM,SAAS,MAAM;AACrB,MAAI,OAAO,WAAW,EAAG;AACzB,QAAM,UAAU,CAAA;AAChB,aAAW,SAAS,OAAQ,WAAU,EAAE,OAAO,QAAQ;AACzD;;;;;;;;;;;;;;"}
@@ -1,3 +1,4 @@
1
+ import type { ChatOutboxAttachment } from '../agent-runtime/src/index';
1
2
  import { AthenaSdkError } from '../diagnostics/errors';
2
3
  /** The slice of the assistant-ui client the handoff writes to. */
3
4
  export interface ComposerTarget {
@@ -35,8 +36,30 @@ export interface ComposerHandoffStore {
35
36
  focusEnd: (() => void) | null;
36
37
  /** Set by `useFocusComposer` before the editor mounted; the editor consumes it when it does. */
37
38
  focusOnMount: boolean;
39
+ /**
40
+ * Per thread, the attachments of messages the chat outbox gave back to the composer (Cancel, or
41
+ * Edit on one that couldn't be sent): files already in Athena, back in the draft as mentions. A
42
+ * message held again from that draft names those still in it, so the outbox asks Athena about
43
+ * them again before it goes ({@link rememberRestoredAttachments}, {@link takeRestoredAttachments}).
44
+ */
45
+ restoredAttachments?: Map<string, ChatOutboxAttachment[]>;
38
46
  }
39
47
  export declare function createComposerHandoffStore(): ComposerHandoffStore;
48
+ /** A held message given back to `threadId`'s composer: remember the attachments it carried. */
49
+ export declare function rememberRestoredAttachments({ store, threadId, attachments, }: {
50
+ store: ComposerHandoffStore;
51
+ threadId: string;
52
+ attachments: readonly ChatOutboxAttachment[];
53
+ }): void;
54
+ /**
55
+ * The remembered attachments of `threadId`'s draft whose mentions it still holds, for the message
56
+ * leaving it now; the composer forgets them all (sent, held again, or removed from the draft).
57
+ */
58
+ export declare function takeRestoredAttachments({ store, threadId, assetIdsInDraft, }: {
59
+ store: ComposerHandoffStore | null;
60
+ threadId: string;
61
+ assetIdsInDraft: ReadonlySet<string>;
62
+ }): ChatOutboxAttachment[];
40
63
  export declare const ComposerHandoffContext: import("react").Context<ComposerHandoffStore | null>;
41
64
  /** The provider's handoff store, or null outside `AthenaProvider`. */
42
65
  export declare function useComposerHandoffStore(): ComposerHandoffStore | null;
@@ -52,9 +75,11 @@ export declare function focusComposer({ store }: {
52
75
  }): void;
53
76
  /**
54
77
  * Whether a composer write lands now: in thread-list mode the list has
55
- * resolved which thread is active, and that thread's history has loaded.
56
- * Until then the composer the hooks write to is the one of a mount that is
57
- * about to be replaced, and the draft goes with it.
78
+ * resolved which thread is active, that thread's history has loaded, and the
79
+ * chat's session lane is known (the sign-in provider above has resolved who is
80
+ * signed in; see `StatewireSessionLane`). Until then the composer the hooks
81
+ * write to is the one of a mount that is about to be replaced, and the draft
82
+ * goes with it, or a send would go into a parked lane that refuses it unsent.
58
83
  *
59
84
  * Deliberately not the socket status: a never-started chat sits in
60
85
  * `standby` until its first send and must still take a prefill.
@@ -2,9 +2,41 @@ import { useCallback, createContext, useContext } from "react";
2
2
  import { useAuiState } from "@assistant-ui/react";
3
3
  import { athenaDiagnostics } from "../diagnostics/athena-diagnostics.js";
4
4
  import { AthenaSdkError } from "../diagnostics/errors.js";
5
+ import { useStatewireSessionLanePending } from "../runtime/statewire-session-lane.js";
5
6
  import { useAthenaStatewireThreadList } from "../threads/statewire-thread-list.js";
6
7
  function createComposerHandoffStore() {
7
- return { pending: [], focusOnNextMirror: false, focusEnd: null, focusOnMount: false };
8
+ return {
9
+ pending: [],
10
+ focusOnNextMirror: false,
11
+ focusEnd: null,
12
+ focusOnMount: false,
13
+ restoredAttachments: /* @__PURE__ */ new Map()
14
+ };
15
+ }
16
+ function rememberRestoredAttachments({
17
+ store,
18
+ threadId,
19
+ attachments
20
+ }) {
21
+ if (attachments.length === 0) return;
22
+ store.restoredAttachments ?? (store.restoredAttachments = /* @__PURE__ */ new Map());
23
+ const kept = store.restoredAttachments.get(threadId) ?? [];
24
+ const known = new Set(kept.map((attachment) => attachment.assetId));
25
+ store.restoredAttachments.set(threadId, [
26
+ ...kept,
27
+ ...attachments.filter((attachment) => !known.has(attachment.assetId))
28
+ ]);
29
+ }
30
+ function takeRestoredAttachments({
31
+ store,
32
+ threadId,
33
+ assetIdsInDraft
34
+ }) {
35
+ var _a, _b;
36
+ const kept = (_a = store == null ? void 0 : store.restoredAttachments) == null ? void 0 : _a.get(threadId);
37
+ if (!kept) return [];
38
+ (_b = store == null ? void 0 : store.restoredAttachments) == null ? void 0 : _b.delete(threadId);
39
+ return kept.filter((attachment) => assetIdsInDraft.has(attachment.assetId));
8
40
  }
9
41
  const ComposerHandoffContext = createContext(null);
10
42
  function useComposerHandoffStore() {
@@ -26,7 +58,8 @@ function useComposerReady() {
26
58
  var _a;
27
59
  return ((_a = s.optional.thread) == null ? void 0 : _a.isLoading) ?? false;
28
60
  });
29
- return !((list == null ? void 0 : list.isLoading) ?? false) && !threadLoading;
61
+ const lanePending = useStatewireSessionLanePending();
62
+ return !((list == null ? void 0 : list.isLoading) ?? false) && !threadLoading && !lanePending;
30
63
  }
31
64
  function mergeComposerDraft({
32
65
  current,
@@ -112,6 +145,8 @@ function clearComposerHandoff({
112
145
  store,
113
146
  reason
114
147
  }) {
148
+ var _a;
149
+ (_a = store.restoredAttachments) == null ? void 0 : _a.clear();
115
150
  const writes = store.pending;
116
151
  if (writes.length === 0) return;
117
152
  store.pending = [];
@@ -126,6 +161,8 @@ export {
126
161
  focusComposer,
127
162
  mergeComposerDraft,
128
163
  queueComposerWrite,
164
+ rememberRestoredAttachments,
165
+ takeRestoredAttachments,
129
166
  useComposerHandoffStore,
130
167
  useComposerReady,
131
168
  useFocusComposer
@@ -1 +1 @@
1
- {"version":3,"file":"composer-handoff.js","sources":["../../src/composer/composer-handoff.ts"],"sourcesContent":["/**\n * Composer handoff: writes to the chat composer from host UI that lives\n * outside `<AthenaChat>` (a sidebar, an agenda card, a workflow button).\n *\n * Two problems it solves for `useAppendToComposer` / `useSendMessage`:\n *\n * 1. A write before the chat is ready is lost. While the thread list is still\n * resolving the active thread, or the thread's history is still loading,\n * the composer the hooks write to belongs to a mount that is about to be\n * replaced (thread-list mode keys the statewire subtree by thread), and\n * the draft goes with it. The store below lives ABOVE that mount, so a\n * write made too early waits here and the ready mount drains it.\n * 2. A prefilled draft should put the caret after the text so the user can\n * keep typing or dictating. The Tiptap editor mirrors runtime text on a\n * later tick; the `focusOnNextMirror` flag asks it to focus at the end\n * right after that mirror lands, instead of the host guessing a delay.\n *\n * Every queued write is bound to the statewire thread it was made for and\n * drains only into that thread's mount; a thread switch, an identity change\n * or a provider unmount drops what waits with a `composer_write_dropped`\n * error, never into another user's or another thread's composer.\n */\nimport { createContext, useCallback, useContext } from 'react';\nimport { useAuiState } from '@assistant-ui/react';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport { AthenaSdkError } from '../diagnostics/errors';\nimport { useAthenaStatewireThreadList } from '../threads/statewire-thread-list';\n\n/** The slice of the assistant-ui client the handoff writes to. */\nexport interface ComposerTarget {\n composer: {\n getState: () => { text: string };\n setText: (text: string) => void;\n send: (options?: { steer?: boolean }) => unknown;\n };\n}\n\nexport interface ComposerWrite {\n text: string;\n /** Replace the draft instead of appending on a new line. */\n replace: boolean;\n /** Submit right after writing. */\n send: boolean;\n /** Put the caret at the end of the draft once the editor shows it. */\n focus: boolean;\n /** The statewire thread the write was made for; it drains only into that thread's mount. */\n threadId: string | null;\n /** Settled once the write has been applied (and, for `send`, with the send's outcome). */\n resolve?: (outcome: Promise<void> | void) => void;\n /** Settled with `composer_write_dropped` when the write can no longer land. */\n reject?: (error: AthenaSdkError) => void;\n}\n\nexport interface ComposerHandoffStore {\n /** Writes waiting for a ready composer, oldest first. Adjacent plain appends fold together. */\n pending: ComposerWrite[];\n /** Set by a `focus` write; the editor consumes it after mirroring the draft. */\n focusOnNextMirror: boolean;\n /** Registered by the mounted editor: place the caret at the end of the draft. */\n focusEnd: (() => void) | null;\n /** Set by `useFocusComposer` before the editor mounted; the editor consumes it when it does. */\n focusOnMount: boolean;\n}\n\nexport function createComposerHandoffStore(): ComposerHandoffStore {\n return { pending: [], focusOnNextMirror: false, focusEnd: null, focusOnMount: false };\n}\n\nexport const ComposerHandoffContext = createContext<ComposerHandoffStore | null>(null);\n\n/** The provider's handoff store, or null outside `AthenaProvider`. */\nexport function useComposerHandoffStore(): ComposerHandoffStore | null {\n return useContext(ComposerHandoffContext);\n}\n\n/**\n * Puts the caret at the end of the composer's draft and leaves the draft as it is; asked before the\n * editor has mounted, it focuses the editor as it mounts. For a host that shows the chat again and\n * wants typing to land in it (a launcher window a shortcut brings back).\n */\nexport function useFocusComposer(): () => void {\n const store = useComposerHandoffStore();\n return useCallback(() => {\n if (store) focusComposer({ store });\n }, [store]);\n}\n\n/** The caret to the end of the draft now, or, with no editor mounted yet, as one mounts. */\nexport function focusComposer({ store }: { store: ComposerHandoffStore }): void {\n if (store.focusEnd) store.focusEnd();\n else store.focusOnMount = true;\n}\n\n/**\n * Whether a composer write lands now: in thread-list mode the list has\n * resolved which thread is active, and that thread's history has loaded.\n * Until then the composer the hooks write to is the one of a mount that is\n * about to be replaced, and the draft goes with it.\n *\n * Deliberately not the socket status: a never-started chat sits in\n * `standby` until its first send and must still take a prefill.\n */\nexport function useComposerReady(): boolean {\n const list = useAthenaStatewireThreadList();\n const threadLoading = useAuiState((s) => s.optional.thread?.isLoading ?? false);\n return !(list?.isLoading ?? false) && !threadLoading;\n}\n\n/** The draft after `write`: `replace` (or an empty draft) takes the text as is. */\nexport function mergeComposerDraft({\n current,\n write,\n}: {\n current: string;\n write: Pick<ComposerWrite, 'text' | 'replace'>;\n}): string {\n if (write.replace || !current) return write.text;\n return `${current}\\n${write.text}`;\n}\n\n/**\n * Write into the live composer. Returns the send's outcome for a `send`\n * write so callers can await it.\n */\nexport function applyComposerWrite({\n target,\n store,\n write,\n}: {\n target: ComposerTarget;\n store: ComposerHandoffStore | null;\n write: ComposerWrite;\n}): Promise<void> | void {\n const current = target.composer.getState().text ?? '';\n const next = mergeComposerDraft({ current, write });\n target.composer.setText(next);\n if (write.focus && store) {\n // An unchanged draft never re-mirrors, so focus at once; otherwise the\n // editor focuses itself right after it has shown the new text.\n if (next === current) store.focusEnd?.();\n else store.focusOnNextMirror = true;\n }\n athenaDiagnostics.emit('composer.handoff', {\n level: 'debug',\n data: { phase: 'applied', send: write.send, focus: write.focus, chars: next.length },\n });\n if (write.send) {\n return Promise.resolve(target.composer.send({ steer: false })).then(() => undefined);\n }\n return undefined;\n}\n\n/**\n * Hold a write until the composer is ready. Writes keep their order; a plain\n * append folds into a directly preceding plain append for the same thread\n * (one draft, not two), while a replace or a send is kept as its own step so\n * no message is lost and every send settles on its own.\n */\nexport function queueComposerWrite({\n store,\n write,\n}: {\n store: ComposerHandoffStore;\n write: ComposerWrite;\n}): void {\n const last = store.pending[store.pending.length - 1];\n const foldable =\n last !== undefined &&\n !last.send &&\n !write.send &&\n !write.replace &&\n last.threadId === write.threadId &&\n last.resolve === undefined &&\n write.resolve === undefined;\n if (foldable) {\n last.text = mergeComposerDraft({ current: last.text, write });\n last.focus = last.focus || write.focus;\n } else {\n store.pending.push(write);\n }\n athenaDiagnostics.emit('composer.handoff', {\n level: 'debug',\n data: { phase: 'deferred', send: write.send, focus: write.focus, queued: store.pending.length },\n });\n}\n\nfunction dropWrite({ write, reason }: { write: ComposerWrite; reason: string }): void {\n const error = new AthenaSdkError({\n code: 'composer_write_dropped',\n message: `A composer ${write.send ? 'send' : 'draft'} queued before the chat was ready was dropped: ${reason}.`,\n hint: 'Make the write again from the chat that is active now.',\n context: { threadId: write.threadId, send: write.send },\n });\n athenaDiagnostics.emit('composer.handoff', {\n level: 'warn',\n error,\n data: { phase: 'dropped', send: write.send, reason, threadId: write.threadId },\n });\n write.reject?.(error);\n}\n\n/**\n * Deliver the pending writes, in order, into a now-ready composer. A write\n * made for another thread is dropped (rejected), never applied here.\n */\nexport function drainComposerHandoff({\n store,\n target,\n threadId,\n}: {\n store: ComposerHandoffStore;\n target: ComposerTarget;\n /** The statewire thread of the mount that is draining. */\n threadId: string | null;\n}): void {\n const writes = store.pending;\n if (writes.length === 0) return;\n store.pending = [];\n for (const write of writes) {\n if (write.threadId !== null && threadId !== null && write.threadId !== threadId) {\n dropWrite({ write, reason: `it was made for thread ${write.threadId}, thread ${threadId} is active` });\n continue;\n }\n const outcome = applyComposerWrite({ target, store, write });\n write.resolve?.(outcome);\n }\n}\n\n/** Drop every pending write (identity changed, provider unmounted). */\nexport function clearComposerHandoff({\n store,\n reason,\n}: {\n store: ComposerHandoffStore;\n reason: string;\n}): void {\n const writes = store.pending;\n if (writes.length === 0) return;\n store.pending = [];\n for (const write of writes) dropWrite({ write, reason });\n}\n"],"names":[],"mappings":";;;;;AAgEO,SAAS,6BAAmD;AACjE,SAAO,EAAE,SAAS,CAAA,GAAI,mBAAmB,OAAO,UAAU,MAAM,cAAc,MAAA;AAChF;AAEO,MAAM,yBAAyB,cAA2C,IAAI;AAG9E,SAAS,0BAAuD;AACrE,SAAO,WAAW,sBAAsB;AAC1C;AAOO,SAAS,mBAA+B;AAC7C,QAAM,QAAQ,wBAAA;AACd,SAAO,YAAY,MAAM;AACvB,QAAI,MAAO,eAAc,EAAE,OAAO;AAAA,EACpC,GAAG,CAAC,KAAK,CAAC;AACZ;AAGO,SAAS,cAAc,EAAE,SAAgD;AAC9E,MAAI,MAAM,SAAU,OAAM,SAAA;AAAA,aACf,eAAe;AAC5B;AAWO,SAAS,mBAA4B;AAC1C,QAAM,OAAO,6BAAA;AACb,QAAM,gBAAgB,YAAY,CAAC,MAAA;;AAAM,oBAAE,SAAS,WAAX,mBAAmB,cAAa;AAAA,GAAK;AAC9E,SAAO,GAAE,6BAAM,cAAa,UAAU,CAAC;AACzC;AAGO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AACF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,QAAQ,MAAM,QAAQ,OAAA;AAAA,EAAO,CAC/F;AACH;AAEA,SAAS,UAAU,EAAE,OAAO,UAA0D;;AACpF,QAAM,QAAQ,IAAI,eAAe;AAAA,IAC/B,MAAM;AAAA,IACN,SAAS,cAAc,MAAM,OAAO,SAAS,OAAO,kDAAkD,MAAM;AAAA,IAC5G,MAAM;AAAA,IACN,SAAS,EAAE,UAAU,MAAM,UAAU,MAAM,MAAM,KAAA;AAAA,EAAK,CACvD;AACD,oBAAkB,KAAK,oBAAoB;AAAA,IACzC,OAAO;AAAA,IACP;AAAA,IACA,MAAM,EAAE,OAAO,WAAW,MAAM,MAAM,MAAM,QAAQ,UAAU,MAAM,SAAA;AAAA,EAAS,CAC9E;AACD,cAAM,WAAN,+BAAe;AACjB;AAMO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAKS;;AACP,QAAM,SAAS,MAAM;AACrB,MAAI,OAAO,WAAW,EAAG;AACzB,QAAM,UAAU,CAAA;AAChB,aAAW,SAAS,QAAQ;AAC1B,QAAI,MAAM,aAAa,QAAQ,aAAa,QAAQ,MAAM,aAAa,UAAU;AAC/E,gBAAU,EAAE,OAAO,QAAQ,0BAA0B,MAAM,QAAQ,YAAY,QAAQ,aAAA,CAAc;AACrG;AAAA,IACF;AACA,UAAM,UAAU,mBAAmB,EAAE,QAAQ,OAAO,OAAO;AAC3D,gBAAM,YAAN,+BAAgB;AAAA,EAClB;AACF;AAGO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AACF,GAGS;AACP,QAAM,SAAS,MAAM;AACrB,MAAI,OAAO,WAAW,EAAG;AACzB,QAAM,UAAU,CAAA;AAChB,aAAW,SAAS,OAAQ,WAAU,EAAE,OAAO,QAAQ;AACzD;"}
1
+ {"version":3,"file":"composer-handoff.js","sources":["../../src/composer/composer-handoff.ts"],"sourcesContent":["/**\n * Composer handoff: writes to the chat composer from host UI that lives\n * outside `<AthenaChat>` (a sidebar, an agenda card, a workflow button).\n *\n * Two problems it solves for `useAppendToComposer` / `useSendMessage`:\n *\n * 1. A write before the chat is ready is lost. While the thread list is still\n * resolving the active thread, or the thread's history is still loading,\n * the composer the hooks write to belongs to a mount that is about to be\n * replaced (thread-list mode keys the statewire subtree by thread), and\n * the draft goes with it. The store below lives ABOVE that mount, so a\n * write made too early waits here and the ready mount drains it.\n * 2. A prefilled draft should put the caret after the text so the user can\n * keep typing or dictating. The Tiptap editor mirrors runtime text on a\n * later tick; the `focusOnNextMirror` flag asks it to focus at the end\n * right after that mirror lands, instead of the host guessing a delay.\n *\n * Every queued write is bound to the statewire thread it was made for and\n * drains only into that thread's mount; a thread switch, an identity change\n * or a provider unmount drops what waits with a `composer_write_dropped`\n * error, never into another user's or another thread's composer.\n */\nimport { createContext, useCallback, useContext } from 'react';\nimport { useAuiState } from '@assistant-ui/react';\nimport type { ChatOutboxAttachment } from '@athenaintel/agent-runtime';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport { AthenaSdkError } from '../diagnostics/errors';\nimport { useStatewireSessionLanePending } from '../runtime/statewire-session-lane';\nimport { useAthenaStatewireThreadList } from '../threads/statewire-thread-list';\n\n/** The slice of the assistant-ui client the handoff writes to. */\nexport interface ComposerTarget {\n composer: {\n getState: () => { text: string };\n setText: (text: string) => void;\n send: (options?: { steer?: boolean }) => unknown;\n };\n}\n\nexport interface ComposerWrite {\n text: string;\n /** Replace the draft instead of appending on a new line. */\n replace: boolean;\n /** Submit right after writing. */\n send: boolean;\n /** Put the caret at the end of the draft once the editor shows it. */\n focus: boolean;\n /** The statewire thread the write was made for; it drains only into that thread's mount. */\n threadId: string | null;\n /** Settled once the write has been applied (and, for `send`, with the send's outcome). */\n resolve?: (outcome: Promise<void> | void) => void;\n /** Settled with `composer_write_dropped` when the write can no longer land. */\n reject?: (error: AthenaSdkError) => void;\n}\n\nexport interface ComposerHandoffStore {\n /** Writes waiting for a ready composer, oldest first. Adjacent plain appends fold together. */\n pending: ComposerWrite[];\n /** Set by a `focus` write; the editor consumes it after mirroring the draft. */\n focusOnNextMirror: boolean;\n /** Registered by the mounted editor: place the caret at the end of the draft. */\n focusEnd: (() => void) | null;\n /** Set by `useFocusComposer` before the editor mounted; the editor consumes it when it does. */\n focusOnMount: boolean;\n /**\n * Per thread, the attachments of messages the chat outbox gave back to the composer (Cancel, or\n * Edit on one that couldn't be sent): files already in Athena, back in the draft as mentions. A\n * message held again from that draft names those still in it, so the outbox asks Athena about\n * them again before it goes ({@link rememberRestoredAttachments}, {@link takeRestoredAttachments}).\n */\n restoredAttachments?: Map<string, ChatOutboxAttachment[]>;\n}\n\nexport function createComposerHandoffStore(): ComposerHandoffStore {\n return {\n pending: [],\n focusOnNextMirror: false,\n focusEnd: null,\n focusOnMount: false,\n restoredAttachments: new Map(),\n };\n}\n\n/** A held message given back to `threadId`'s composer: remember the attachments it carried. */\nexport function rememberRestoredAttachments({\n store,\n threadId,\n attachments,\n}: {\n store: ComposerHandoffStore;\n threadId: string;\n attachments: readonly ChatOutboxAttachment[];\n}): void {\n if (attachments.length === 0) return;\n store.restoredAttachments ??= new Map();\n const kept = store.restoredAttachments.get(threadId) ?? [];\n const known = new Set(kept.map((attachment) => attachment.assetId));\n store.restoredAttachments.set(threadId, [\n ...kept,\n ...attachments.filter((attachment) => !known.has(attachment.assetId)),\n ]);\n}\n\n/**\n * The remembered attachments of `threadId`'s draft whose mentions it still holds, for the message\n * leaving it now; the composer forgets them all (sent, held again, or removed from the draft).\n */\nexport function takeRestoredAttachments({\n store,\n threadId,\n assetIdsInDraft,\n}: {\n store: ComposerHandoffStore | null;\n threadId: string;\n assetIdsInDraft: ReadonlySet<string>;\n}): ChatOutboxAttachment[] {\n const kept = store?.restoredAttachments?.get(threadId);\n if (!kept) return [];\n store?.restoredAttachments?.delete(threadId);\n return kept.filter((attachment) => assetIdsInDraft.has(attachment.assetId));\n}\n\nexport const ComposerHandoffContext = createContext<ComposerHandoffStore | null>(null);\n\n/** The provider's handoff store, or null outside `AthenaProvider`. */\nexport function useComposerHandoffStore(): ComposerHandoffStore | null {\n return useContext(ComposerHandoffContext);\n}\n\n/**\n * Puts the caret at the end of the composer's draft and leaves the draft as it is; asked before the\n * editor has mounted, it focuses the editor as it mounts. For a host that shows the chat again and\n * wants typing to land in it (a launcher window a shortcut brings back).\n */\nexport function useFocusComposer(): () => void {\n const store = useComposerHandoffStore();\n return useCallback(() => {\n if (store) focusComposer({ store });\n }, [store]);\n}\n\n/** The caret to the end of the draft now, or, with no editor mounted yet, as one mounts. */\nexport function focusComposer({ store }: { store: ComposerHandoffStore }): void {\n if (store.focusEnd) store.focusEnd();\n else store.focusOnMount = true;\n}\n\n/**\n * Whether a composer write lands now: in thread-list mode the list has\n * resolved which thread is active, that thread's history has loaded, and the\n * chat's session lane is known (the sign-in provider above has resolved who is\n * signed in; see `StatewireSessionLane`). Until then the composer the hooks\n * write to is the one of a mount that is about to be replaced, and the draft\n * goes with it, or a send would go into a parked lane that refuses it unsent.\n *\n * Deliberately not the socket status: a never-started chat sits in\n * `standby` until its first send and must still take a prefill.\n */\nexport function useComposerReady(): boolean {\n const list = useAthenaStatewireThreadList();\n const threadLoading = useAuiState((s) => s.optional.thread?.isLoading ?? false);\n const lanePending = useStatewireSessionLanePending();\n return !(list?.isLoading ?? false) && !threadLoading && !lanePending;\n}\n\n/** The draft after `write`: `replace` (or an empty draft) takes the text as is. */\nexport function mergeComposerDraft({\n current,\n write,\n}: {\n current: string;\n write: Pick<ComposerWrite, 'text' | 'replace'>;\n}): string {\n if (write.replace || !current) return write.text;\n return `${current}\\n${write.text}`;\n}\n\n/**\n * Write into the live composer. Returns the send's outcome for a `send`\n * write so callers can await it.\n */\nexport function applyComposerWrite({\n target,\n store,\n write,\n}: {\n target: ComposerTarget;\n store: ComposerHandoffStore | null;\n write: ComposerWrite;\n}): Promise<void> | void {\n const current = target.composer.getState().text ?? '';\n const next = mergeComposerDraft({ current, write });\n target.composer.setText(next);\n if (write.focus && store) {\n // An unchanged draft never re-mirrors, so focus at once; otherwise the\n // editor focuses itself right after it has shown the new text.\n if (next === current) store.focusEnd?.();\n else store.focusOnNextMirror = true;\n }\n athenaDiagnostics.emit('composer.handoff', {\n level: 'debug',\n data: { phase: 'applied', send: write.send, focus: write.focus, chars: next.length },\n });\n if (write.send) {\n return Promise.resolve(target.composer.send({ steer: false })).then(() => undefined);\n }\n return undefined;\n}\n\n/**\n * Hold a write until the composer is ready. Writes keep their order; a plain\n * append folds into a directly preceding plain append for the same thread\n * (one draft, not two), while a replace or a send is kept as its own step so\n * no message is lost and every send settles on its own.\n */\nexport function queueComposerWrite({\n store,\n write,\n}: {\n store: ComposerHandoffStore;\n write: ComposerWrite;\n}): void {\n const last = store.pending[store.pending.length - 1];\n const foldable =\n last !== undefined &&\n !last.send &&\n !write.send &&\n !write.replace &&\n last.threadId === write.threadId &&\n last.resolve === undefined &&\n write.resolve === undefined;\n if (foldable) {\n last.text = mergeComposerDraft({ current: last.text, write });\n last.focus = last.focus || write.focus;\n } else {\n store.pending.push(write);\n }\n athenaDiagnostics.emit('composer.handoff', {\n level: 'debug',\n data: { phase: 'deferred', send: write.send, focus: write.focus, queued: store.pending.length },\n });\n}\n\nfunction dropWrite({ write, reason }: { write: ComposerWrite; reason: string }): void {\n const error = new AthenaSdkError({\n code: 'composer_write_dropped',\n message: `A composer ${write.send ? 'send' : 'draft'} queued before the chat was ready was dropped: ${reason}.`,\n hint: 'Make the write again from the chat that is active now.',\n context: { threadId: write.threadId, send: write.send },\n });\n athenaDiagnostics.emit('composer.handoff', {\n level: 'warn',\n error,\n data: { phase: 'dropped', send: write.send, reason, threadId: write.threadId },\n });\n write.reject?.(error);\n}\n\n/**\n * Deliver the pending writes, in order, into a now-ready composer. A write\n * made for another thread is dropped (rejected), never applied here.\n */\nexport function drainComposerHandoff({\n store,\n target,\n threadId,\n}: {\n store: ComposerHandoffStore;\n target: ComposerTarget;\n /** The statewire thread of the mount that is draining. */\n threadId: string | null;\n}): void {\n const writes = store.pending;\n if (writes.length === 0) return;\n store.pending = [];\n for (const write of writes) {\n if (write.threadId !== null && threadId !== null && write.threadId !== threadId) {\n dropWrite({ write, reason: `it was made for thread ${write.threadId}, thread ${threadId} is active` });\n continue;\n }\n const outcome = applyComposerWrite({ target, store, write });\n write.resolve?.(outcome);\n }\n}\n\n/** Drop every pending write (identity changed, provider unmounted). */\nexport function clearComposerHandoff({\n store,\n reason,\n}: {\n store: ComposerHandoffStore;\n reason: string;\n}): void {\n // Another identity, or no provider: the attachments given back belong to drafts that are gone.\n store.restoredAttachments?.clear();\n const writes = store.pending;\n if (writes.length === 0) return;\n store.pending = [];\n for (const write of writes) dropWrite({ write, reason });\n}\n"],"names":[],"mappings":";;;;;;AAyEO,SAAS,6BAAmD;AACjE,SAAO;AAAA,IACL,SAAS,CAAA;AAAA,IACT,mBAAmB;AAAA,IACnB,UAAU;AAAA,IACV,cAAc;AAAA,IACd,yCAAyB,IAAA;AAAA,EAAI;AAEjC;AAGO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AACF,GAIS;AACP,MAAI,YAAY,WAAW,EAAG;AAC9B,QAAM,wBAAN,MAAM,0CAA4B,IAAA;AAClC,QAAM,OAAO,MAAM,oBAAoB,IAAI,QAAQ,KAAK,CAAA;AACxD,QAAM,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC,eAAe,WAAW,OAAO,CAAC;AAClE,QAAM,oBAAoB,IAAI,UAAU;AAAA,IACtC,GAAG;AAAA,IACH,GAAG,YAAY,OAAO,CAAC,eAAe,CAAC,MAAM,IAAI,WAAW,OAAO,CAAC;AAAA,EAAA,CACrE;AACH;AAMO,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACF,GAI2B;;AACzB,QAAM,QAAO,oCAAO,wBAAP,mBAA4B,IAAI;AAC7C,MAAI,CAAC,KAAM,QAAO,CAAA;AAClB,uCAAO,wBAAP,mBAA4B,OAAO;AACnC,SAAO,KAAK,OAAO,CAAC,eA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,OAAO,WAAW,EAAG;AACzB,QAAM,UAAU,CAAA;AAChB,aAAW,SAAS,QAAQ;AAC1B,QAAI,MAAM,aAAa,QAAQ,aAAa,QAAQ,MAAM,aAAa,UAAU;AAC/E,gBAAU,EAAE,OAAO,QAAQ,0BAA0B,MAAM,QAAQ,YAAY,QAAQ,aAAA,CAAc;AACrG;AAAA,IACF;AACA,UAAM,UAAU,mBAAmB,EAAE,QAAQ,OAAO,OAAO;AAC3D,gBAAM,YAAN,+BAAgB;AAAA,EAClB;AACF;AAGO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AACF,GAGS;;AAEP,cAAM,wBAAN,mBAA2B;AAC3B,QAAM,SAAS,MAAM;AACrB,MAAI,OAAO,WAAW,EAAG;AACzB,QAAM,UAAU,CAAA;AAChB,aAAW,SAAS,OAAQ,WAAU,EAAE,OAAO,QAAQ;AACzD;"}
@@ -4,6 +4,8 @@ const react = require("react");
4
4
  const athenaDiagnostics = require("../diagnostics/athena-diagnostics.cjs");
5
5
  const AttachmentContext = require("./AttachmentContext.cjs");
6
6
  const useFileUpload = require("./useFileUpload.cjs");
7
+ const useDeepAgentChatOutbox = require("../agent-runtime/src/use-deep-agent-chat-outbox.cjs");
8
+ const OFFLINE_FILE_ATTACH_MESSAGE = "Files can't be attached while Athena can't be reached. Messages you send now go out when it's back — attach the file then.";
7
9
  const ATTACH_FAILURE_MESSAGE = {
8
10
  paperclip: "Failed to attach the selected files",
9
11
  drop: "Failed to attach the dropped files",
@@ -11,10 +13,20 @@ const ATTACH_FAILURE_MESSAGE = {
11
13
  };
12
14
  function useAttachFiles() {
13
15
  const { upload, isUploading, error, clearError } = useFileUpload.useFileUpload();
14
- const { addAttachments, setIsUploading } = AttachmentContext.useAttachments();
16
+ const { addAttachments, setIsUploading, setNotice } = AttachmentContext.useAttachments();
17
+ const outbox = useDeepAgentChatOutbox.useDeepAgentChatOutboxContext();
15
18
  const attachFiles = react.useCallback(
16
19
  async (files, source) => {
17
20
  if (files.length === 0) return [];
21
+ if (outbox && !outbox.reachability.get()) {
22
+ setNotice(OFFLINE_FILE_ATTACH_MESSAGE);
23
+ athenaDiagnostics.athenaDiagnostics.emit("composer.attachment.refused_offline", {
24
+ level: "info",
25
+ data: { source, count: files.length }
26
+ });
27
+ return [];
28
+ }
29
+ setNotice(null);
18
30
  setIsUploading(true);
19
31
  try {
20
32
  const assets = await upload([...files]);
@@ -32,9 +44,10 @@ function useAttachFiles() {
32
44
  setIsUploading(false);
33
45
  }
34
46
  },
35
- [addAttachments, setIsUploading, upload]
47
+ [addAttachments, outbox, setIsUploading, setNotice, upload]
36
48
  );
37
49
  return { attachFiles, isUploading, error, clearError };
38
50
  }
51
+ exports.OFFLINE_FILE_ATTACH_MESSAGE = OFFLINE_FILE_ATTACH_MESSAGE;
39
52
  exports.useAttachFiles = useAttachFiles;
40
53
  //# sourceMappingURL=useAttachFiles.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAttachFiles.cjs","sources":["../../src/composer/useAttachFiles.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport { useAttachments } from './AttachmentContext';\nimport { useFileUpload, type UploadedAsset } from './useFileUpload';\n\n/** Which intake the files came through — carried on the diagnostics event. */\nexport type AttachFilesSource = 'paperclip' | 'drop' | 'paste';\n\nconst ATTACH_FAILURE_MESSAGE: Record<AttachFilesSource, string> = {\n paperclip: 'Failed to attach the selected files',\n drop: 'Failed to attach the dropped files',\n paste: 'Failed to attach the pasted images',\n};\n\nexport interface UseAttachFilesReturn {\n /**\n * Upload files as Athena assets and add them to the attachment pills.\n * Resolves to the assets attached; a failed upload resolves to `[]` after\n * recording `composer.attachment.error` on the diagnostics bus (and in\n * `error`).\n */\n attachFiles: (files: readonly File[], source: AttachFilesSource) => Promise<UploadedAsset[]>;\n /** This intake's own upload in flight. */\n isUploading: boolean;\n /** Last failure of this intake, for its own affordance. */\n error: string | null;\n clearError: () => void;\n}\n\n/**\n * The one intake path for the attachment pills: the paperclip, the drop zone\n * and the composer's paste all upload through here, so a failure reaches the\n * diagnostics bus the same way and the shared `isUploading` flag — which\n * parks every submit path — is set for exactly the upload's duration.\n */\nexport function useAttachFiles(): UseAttachFilesReturn {\n const { upload, isUploading, error, clearError } = useFileUpload();\n const { addAttachments, setIsUploading } = useAttachments();\n\n const attachFiles = useCallback(\n async (files: readonly File[], source: AttachFilesSource): Promise<UploadedAsset[]> => {\n if (files.length === 0) return [];\n setIsUploading(true);\n try {\n const assets = await upload([...files]);\n if (assets.length > 0) addAttachments(assets);\n return assets;\n } catch (error) {\n athenaDiagnostics.error(\n 'composer.attachment.error',\n error,\n { code: 'attachment_failed', message: ATTACH_FAILURE_MESSAGE[source] },\n { source, count: files.length },\n );\n return [];\n } finally {\n setIsUploading(false);\n }\n },\n [addAttachments, setIsUploading, upload],\n );\n\n return { attachFiles, isUploading, error, clearError };\n}\n"],"names":["useFileUpload","useAttachments","useCallback","error","athenaDiagnostics"],"mappings":";;;;;;AAQA,MAAM,yBAA4D;AAAA,EAChE,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AACT;AAuBO,SAAS,iBAAuC;AACrD,QAAM,EAAE,QAAQ,aAAa,OAAO,WAAA,IAAeA,cAAAA,cAAA;AACnD,QAAM,EAAE,gBAAgB,eAAA,IAAmBC,iCAAA;AAE3C,QAAM,cAAcC,MAAAA;AAAAA,IAClB,OAAO,OAAwB,WAAwD;AACrF,UAAI,MAAM,WAAW,EAAG,QAAO,CAAA;AAC/B,qBAAe,IAAI;AACnB,UAAI;AACF,cAAM,SAAS,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC;AACtC,YAAI,OAAO,SAAS,EAAG,gBAAe,MAAM;AAC5C,eAAO;AAAA,MACT,SAASC,QAAO;AACdC,0BAAAA,kBAAkB;AAAA,UAChB;AAAA,UACAD;AAAAA,UACA,EAAE,MAAM,qBAAqB,SAAS,uBAAuB,MAAM,EAAA;AAAA,UACnE,EAAE,QAAQ,OAAO,MAAM,OAAA;AAAA,QAAO;AAEhC,eAAO,CAAA;AAAA,MACT,UAAA;AACE,uBAAe,KAAK;AAAA,MACtB;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB,gBAAgB,MAAM;AAAA,EAAA;AAGzC,SAAO,EAAE,aAAa,aAAa,OAAO,WAAA;AAC5C;;"}
1
+ {"version":3,"file":"useAttachFiles.cjs","sources":["../../src/composer/useAttachFiles.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useDeepAgentChatOutboxContext } from '@athenaintel/agent-runtime';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport { useAttachments } from './AttachmentContext';\nimport { useFileUpload, type UploadedAsset } from './useFileUpload';\n\n/**\n * What the composer says when a file is picked, pasted or dropped while Athena can't be reached\n * (the same words as Olympus's): the upload cannot happen, and a message sent now waits in the chat\n * outbox with only the files that were already uploaded.\n */\nexport const OFFLINE_FILE_ATTACH_MESSAGE =\n \"Files can't be attached while Athena can't be reached. Messages you send now go out when it's back — attach the file then.\";\n\n/** Which intake the files came through — carried on the diagnostics event. */\nexport type AttachFilesSource = 'paperclip' | 'drop' | 'paste';\n\nconst ATTACH_FAILURE_MESSAGE: Record<AttachFilesSource, string> = {\n paperclip: 'Failed to attach the selected files',\n drop: 'Failed to attach the dropped files',\n paste: 'Failed to attach the pasted images',\n};\n\nexport interface UseAttachFilesReturn {\n /**\n * Upload files as Athena assets and add them to the attachment pills.\n * Resolves to the assets attached; a failed upload resolves to `[]` after\n * recording `composer.attachment.error` on the diagnostics bus (and in\n * `error`).\n */\n attachFiles: (files: readonly File[], source: AttachFilesSource) => Promise<UploadedAsset[]>;\n /** This intake's own upload in flight. */\n isUploading: boolean;\n /** Last failure of this intake, for its own affordance. */\n error: string | null;\n clearError: () => void;\n}\n\n/**\n * The one intake path for the attachment pills: the paperclip, the drop zone\n * and the composer's paste all upload through here, so a failure reaches the\n * diagnostics bus the same way and the shared `isUploading` flag — which\n * parks every submit path — is set for exactly the upload's duration.\n *\n * While the chat's outbox (a host's `chatOutbox`) says Athena can't be\n * reached, a file is not attached: its upload could only fail, and a message\n * that waits to be sent carries only files already uploaded. The composer\n * says so (`notice`, {@link OFFLINE_FILE_ATTACH_MESSAGE}).\n */\nexport function useAttachFiles(): UseAttachFilesReturn {\n const { upload, isUploading, error, clearError } = useFileUpload();\n const { addAttachments, setIsUploading, setNotice } = useAttachments();\n const outbox = useDeepAgentChatOutboxContext();\n\n const attachFiles = useCallback(\n async (files: readonly File[], source: AttachFilesSource): Promise<UploadedAsset[]> => {\n if (files.length === 0) return [];\n if (outbox && !outbox.reachability.get()) {\n setNotice(OFFLINE_FILE_ATTACH_MESSAGE);\n athenaDiagnostics.emit('composer.attachment.refused_offline', {\n level: 'info',\n data: { source, count: files.length },\n });\n return [];\n }\n setNotice(null);\n setIsUploading(true);\n try {\n const assets = await upload([...files]);\n if (assets.length > 0) addAttachments(assets);\n return assets;\n } catch (error) {\n athenaDiagnostics.error(\n 'composer.attachment.error',\n error,\n { code: 'attachment_failed', message: ATTACH_FAILURE_MESSAGE[source] },\n { source, count: files.length },\n );\n return [];\n } finally {\n setIsUploading(false);\n }\n },\n [addAttachments, outbox, setIsUploading, setNotice, upload],\n );\n\n return { attachFiles, isUploading, error, clearError };\n}\n"],"names":["useFileUpload","useAttachments","useDeepAgentChatOutboxContext","useCallback","athenaDiagnostics","error"],"mappings":";;;;;;;AAWO,MAAM,8BACX;AAKF,MAAM,yBAA4D;AAAA,EAChE,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AACT;AA4BO,SAAS,iBAAuC;AACrD,QAAM,EAAE,QAAQ,aAAa,OAAO,WAAA,IAAeA,cAAAA,cAAA;AACnD,QAAM,EAAE,gBAAgB,gBAAgB,UAAA,IAAcC,kBAAAA,eAAA;AACtD,QAAM,SAASC,uBAAAA,8BAAA;AAEf,QAAM,cAAcC,MAAAA;AAAAA,IAClB,OAAO,OAAwB,WAAwD;AACrF,UAAI,MAAM,WAAW,EAAG,QAAO,CAAA;AAC/B,UAAI,UAAU,CAAC,OAAO,aAAa,OAAO;AACxC,kBAAU,2BAA2B;AACrCC,0BAAAA,kBAAkB,KAAK,uCAAuC;AAAA,UAC5D,OAAO;AAAA,UACP,MAAM,EAAE,QAAQ,OAAO,MAAM,OAAA;AAAA,QAAO,CACrC;AACD,eAAO,CAAA;AAAA,MACT;AACA,gBAAU,IAAI;AACd,qBAAe,IAAI;AACnB,UAAI;AACF,cAAM,SAAS,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC;AACtC,YAAI,OAAO,SAAS,EAAG,gBAAe,MAAM;AAC5C,eAAO;AAAA,MACT,SAASC,QAAO;AACdD,0BAAAA,kBAAkB;AAAA,UAChB;AAAA,UACAC;AAAAA,UACA,EAAE,MAAM,qBAAqB,SAAS,uBAAuB,MAAM,EAAA;AAAA,UACnE,EAAE,QAAQ,OAAO,MAAM,OAAA;AAAA,QAAO;AAEhC,eAAO,CAAA;AAAA,MACT,UAAA;AACE,uBAAe,KAAK;AAAA,MACtB;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB,QAAQ,gBAAgB,WAAW,MAAM;AAAA,EAAA;AAG5D,SAAO,EAAE,aAAa,aAAa,OAAO,WAAA;AAC5C;;;"}
@@ -1,4 +1,10 @@
1
1
  import { type UploadedAsset } from './useFileUpload';
2
+ /**
3
+ * What the composer says when a file is picked, pasted or dropped while Athena can't be reached
4
+ * (the same words as Olympus's): the upload cannot happen, and a message sent now waits in the chat
5
+ * outbox with only the files that were already uploaded.
6
+ */
7
+ export declare const OFFLINE_FILE_ATTACH_MESSAGE = "Files can't be attached while Athena can't be reached. Messages you send now go out when it's back \u2014 attach the file then.";
2
8
  /** Which intake the files came through — carried on the diagnostics event. */
3
9
  export type AttachFilesSource = 'paperclip' | 'drop' | 'paste';
4
10
  export interface UseAttachFilesReturn {
@@ -20,5 +26,10 @@ export interface UseAttachFilesReturn {
20
26
  * and the composer's paste all upload through here, so a failure reaches the
21
27
  * diagnostics bus the same way and the shared `isUploading` flag — which
22
28
  * parks every submit path — is set for exactly the upload's duration.
29
+ *
30
+ * While the chat's outbox (a host's `chatOutbox`) says Athena can't be
31
+ * reached, a file is not attached: its upload could only fail, and a message
32
+ * that waits to be sent carries only files already uploaded. The composer
33
+ * says so (`notice`, {@link OFFLINE_FILE_ATTACH_MESSAGE}).
23
34
  */
24
35
  export declare function useAttachFiles(): UseAttachFilesReturn;
@@ -2,6 +2,8 @@ import { useCallback } from "react";
2
2
  import { athenaDiagnostics } from "../diagnostics/athena-diagnostics.js";
3
3
  import { useAttachments } from "./AttachmentContext.js";
4
4
  import { useFileUpload } from "./useFileUpload.js";
5
+ import { useDeepAgentChatOutboxContext } from "../agent-runtime/src/use-deep-agent-chat-outbox.js";
6
+ const OFFLINE_FILE_ATTACH_MESSAGE = "Files can't be attached while Athena can't be reached. Messages you send now go out when it's back — attach the file then.";
5
7
  const ATTACH_FAILURE_MESSAGE = {
6
8
  paperclip: "Failed to attach the selected files",
7
9
  drop: "Failed to attach the dropped files",
@@ -9,10 +11,20 @@ const ATTACH_FAILURE_MESSAGE = {
9
11
  };
10
12
  function useAttachFiles() {
11
13
  const { upload, isUploading, error, clearError } = useFileUpload();
12
- const { addAttachments, setIsUploading } = useAttachments();
14
+ const { addAttachments, setIsUploading, setNotice } = useAttachments();
15
+ const outbox = useDeepAgentChatOutboxContext();
13
16
  const attachFiles = useCallback(
14
17
  async (files, source) => {
15
18
  if (files.length === 0) return [];
19
+ if (outbox && !outbox.reachability.get()) {
20
+ setNotice(OFFLINE_FILE_ATTACH_MESSAGE);
21
+ athenaDiagnostics.emit("composer.attachment.refused_offline", {
22
+ level: "info",
23
+ data: { source, count: files.length }
24
+ });
25
+ return [];
26
+ }
27
+ setNotice(null);
16
28
  setIsUploading(true);
17
29
  try {
18
30
  const assets = await upload([...files]);
@@ -30,11 +42,12 @@ function useAttachFiles() {
30
42
  setIsUploading(false);
31
43
  }
32
44
  },
33
- [addAttachments, setIsUploading, upload]
45
+ [addAttachments, outbox, setIsUploading, setNotice, upload]
34
46
  );
35
47
  return { attachFiles, isUploading, error, clearError };
36
48
  }
37
49
  export {
50
+ OFFLINE_FILE_ATTACH_MESSAGE,
38
51
  useAttachFiles
39
52
  };
40
53
  //# sourceMappingURL=useAttachFiles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAttachFiles.js","sources":["../../src/composer/useAttachFiles.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport { useAttachments } from './AttachmentContext';\nimport { useFileUpload, type UploadedAsset } from './useFileUpload';\n\n/** Which intake the files came through — carried on the diagnostics event. */\nexport type AttachFilesSource = 'paperclip' | 'drop' | 'paste';\n\nconst ATTACH_FAILURE_MESSAGE: Record<AttachFilesSource, string> = {\n paperclip: 'Failed to attach the selected files',\n drop: 'Failed to attach the dropped files',\n paste: 'Failed to attach the pasted images',\n};\n\nexport interface UseAttachFilesReturn {\n /**\n * Upload files as Athena assets and add them to the attachment pills.\n * Resolves to the assets attached; a failed upload resolves to `[]` after\n * recording `composer.attachment.error` on the diagnostics bus (and in\n * `error`).\n */\n attachFiles: (files: readonly File[], source: AttachFilesSource) => Promise<UploadedAsset[]>;\n /** This intake's own upload in flight. */\n isUploading: boolean;\n /** Last failure of this intake, for its own affordance. */\n error: string | null;\n clearError: () => void;\n}\n\n/**\n * The one intake path for the attachment pills: the paperclip, the drop zone\n * and the composer's paste all upload through here, so a failure reaches the\n * diagnostics bus the same way and the shared `isUploading` flag — which\n * parks every submit path — is set for exactly the upload's duration.\n */\nexport function useAttachFiles(): UseAttachFilesReturn {\n const { upload, isUploading, error, clearError } = useFileUpload();\n const { addAttachments, setIsUploading } = useAttachments();\n\n const attachFiles = useCallback(\n async (files: readonly File[], source: AttachFilesSource): Promise<UploadedAsset[]> => {\n if (files.length === 0) return [];\n setIsUploading(true);\n try {\n const assets = await upload([...files]);\n if (assets.length > 0) addAttachments(assets);\n return assets;\n } catch (error) {\n athenaDiagnostics.error(\n 'composer.attachment.error',\n error,\n { code: 'attachment_failed', message: ATTACH_FAILURE_MESSAGE[source] },\n { source, count: files.length },\n );\n return [];\n } finally {\n setIsUploading(false);\n }\n },\n [addAttachments, setIsUploading, upload],\n );\n\n return { attachFiles, isUploading, error, clearError };\n}\n"],"names":["error"],"mappings":";;;;AAQA,MAAM,yBAA4D;AAAA,EAChE,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AACT;AAuBO,SAAS,iBAAuC;AACrD,QAAM,EAAE,QAAQ,aAAa,OAAO,WAAA,IAAe,cAAA;AACnD,QAAM,EAAE,gBAAgB,eAAA,IAAmB,eAAA;AAE3C,QAAM,cAAc;AAAA,IAClB,OAAO,OAAwB,WAAwD;AACrF,UAAI,MAAM,WAAW,EAAG,QAAO,CAAA;AAC/B,qBAAe,IAAI;AACnB,UAAI;AACF,cAAM,SAAS,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC;AACtC,YAAI,OAAO,SAAS,EAAG,gBAAe,MAAM;AAC5C,eAAO;AAAA,MACT,SAASA,QAAO;AACd,0BAAkB;AAAA,UAChB;AAAA,UACAA;AAAAA,UACA,EAAE,MAAM,qBAAqB,SAAS,uBAAuB,MAAM,EAAA;AAAA,UACnE,EAAE,QAAQ,OAAO,MAAM,OAAA;AAAA,QAAO;AAEhC,eAAO,CAAA;AAAA,MACT,UAAA;AACE,uBAAe,KAAK;AAAA,MACtB;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB,gBAAgB,MAAM;AAAA,EAAA;AAGzC,SAAO,EAAE,aAAa,aAAa,OAAO,WAAA;AAC5C;"}
1
+ {"version":3,"file":"useAttachFiles.js","sources":["../../src/composer/useAttachFiles.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useDeepAgentChatOutboxContext } from '@athenaintel/agent-runtime';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport { useAttachments } from './AttachmentContext';\nimport { useFileUpload, type UploadedAsset } from './useFileUpload';\n\n/**\n * What the composer says when a file is picked, pasted or dropped while Athena can't be reached\n * (the same words as Olympus's): the upload cannot happen, and a message sent now waits in the chat\n * outbox with only the files that were already uploaded.\n */\nexport const OFFLINE_FILE_ATTACH_MESSAGE =\n \"Files can't be attached while Athena can't be reached. Messages you send now go out when it's back — attach the file then.\";\n\n/** Which intake the files came through — carried on the diagnostics event. */\nexport type AttachFilesSource = 'paperclip' | 'drop' | 'paste';\n\nconst ATTACH_FAILURE_MESSAGE: Record<AttachFilesSource, string> = {\n paperclip: 'Failed to attach the selected files',\n drop: 'Failed to attach the dropped files',\n paste: 'Failed to attach the pasted images',\n};\n\nexport interface UseAttachFilesReturn {\n /**\n * Upload files as Athena assets and add them to the attachment pills.\n * Resolves to the assets attached; a failed upload resolves to `[]` after\n * recording `composer.attachment.error` on the diagnostics bus (and in\n * `error`).\n */\n attachFiles: (files: readonly File[], source: AttachFilesSource) => Promise<UploadedAsset[]>;\n /** This intake's own upload in flight. */\n isUploading: boolean;\n /** Last failure of this intake, for its own affordance. */\n error: string | null;\n clearError: () => void;\n}\n\n/**\n * The one intake path for the attachment pills: the paperclip, the drop zone\n * and the composer's paste all upload through here, so a failure reaches the\n * diagnostics bus the same way and the shared `isUploading` flag — which\n * parks every submit path — is set for exactly the upload's duration.\n *\n * While the chat's outbox (a host's `chatOutbox`) says Athena can't be\n * reached, a file is not attached: its upload could only fail, and a message\n * that waits to be sent carries only files already uploaded. The composer\n * says so (`notice`, {@link OFFLINE_FILE_ATTACH_MESSAGE}).\n */\nexport function useAttachFiles(): UseAttachFilesReturn {\n const { upload, isUploading, error, clearError } = useFileUpload();\n const { addAttachments, setIsUploading, setNotice } = useAttachments();\n const outbox = useDeepAgentChatOutboxContext();\n\n const attachFiles = useCallback(\n async (files: readonly File[], source: AttachFilesSource): Promise<UploadedAsset[]> => {\n if (files.length === 0) return [];\n if (outbox && !outbox.reachability.get()) {\n setNotice(OFFLINE_FILE_ATTACH_MESSAGE);\n athenaDiagnostics.emit('composer.attachment.refused_offline', {\n level: 'info',\n data: { source, count: files.length },\n });\n return [];\n }\n setNotice(null);\n setIsUploading(true);\n try {\n const assets = await upload([...files]);\n if (assets.length > 0) addAttachments(assets);\n return assets;\n } catch (error) {\n athenaDiagnostics.error(\n 'composer.attachment.error',\n error,\n { code: 'attachment_failed', message: ATTACH_FAILURE_MESSAGE[source] },\n { source, count: files.length },\n );\n return [];\n } finally {\n setIsUploading(false);\n }\n },\n [addAttachments, outbox, setIsUploading, setNotice, upload],\n );\n\n return { attachFiles, isUploading, error, clearError };\n}\n"],"names":["error"],"mappings":";;;;;AAWO,MAAM,8BACX;AAKF,MAAM,yBAA4D;AAAA,EAChE,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AACT;AA4BO,SAAS,iBAAuC;AACrD,QAAM,EAAE,QAAQ,aAAa,OAAO,WAAA,IAAe,cAAA;AACnD,QAAM,EAAE,gBAAgB,gBAAgB,UAAA,IAAc,eAAA;AACtD,QAAM,SAAS,8BAAA;AAEf,QAAM,cAAc;AAAA,IAClB,OAAO,OAAwB,WAAwD;AACrF,UAAI,MAAM,WAAW,EAAG,QAAO,CAAA;AAC/B,UAAI,UAAU,CAAC,OAAO,aAAa,OAAO;AACxC,kBAAU,2BAA2B;AACrC,0BAAkB,KAAK,uCAAuC;AAAA,UAC5D,OAAO;AAAA,UACP,MAAM,EAAE,QAAQ,OAAO,MAAM,OAAA;AAAA,QAAO,CACrC;AACD,eAAO,CAAA;AAAA,MACT;AACA,gBAAU,IAAI;AACd,qBAAe,IAAI;AACnB,UAAI;AACF,cAAM,SAAS,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC;AACtC,YAAI,OAAO,SAAS,EAAG,gBAAe,MAAM;AAC5C,eAAO;AAAA,MACT,SAASA,QAAO;AACd,0BAAkB;AAAA,UAChB;AAAA,UACAA;AAAAA,UACA,EAAE,MAAM,qBAAqB,SAAS,uBAAuB,MAAM,EAAA;AAAA,UACnE,EAAE,QAAQ,OAAO,MAAM,OAAA;AAAA,QAAO;AAEhC,eAAO,CAAA;AAAA,MACT,UAAA;AACE,uBAAe,KAAK;AAAA,MACtB;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB,QAAQ,gBAAgB,WAAW,MAAM;AAAA,EAAA;AAG5D,SAAO,EAAE,aAAa,aAAa,OAAO,WAAA;AAC5C;"}