@athenaintel/react 0.41.3 → 0.42.1

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 (439) hide show
  1. package/README.md +102 -9
  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 +88 -4
  82. package/dist/agent-runtime/src/messages.cjs.map +1 -1
  83. package/dist/agent-runtime/src/messages.d.ts +603 -0
  84. package/dist/agent-runtime/src/messages.js +88 -4
  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.d.ts +154 -0
  97. package/dist/agent-runtime/src/running-tool-placeholder.cjs +11 -0
  98. package/dist/agent-runtime/src/running-tool-placeholder.cjs.map +1 -0
  99. package/dist/agent-runtime/src/running-tool-placeholder.d.ts +25 -0
  100. package/dist/agent-runtime/src/running-tool-placeholder.js +11 -0
  101. package/dist/agent-runtime/src/running-tool-placeholder.js.map +1 -0
  102. package/dist/agent-runtime/src/runtime-messages.d.ts +104 -0
  103. package/dist/agent-runtime/src/screen-point.d.ts +151 -0
  104. package/dist/agent-runtime/src/sealed-idb.cjs +112 -0
  105. package/dist/agent-runtime/src/sealed-idb.cjs.map +1 -0
  106. package/dist/agent-runtime/src/sealed-idb.d.ts +106 -0
  107. package/dist/agent-runtime/src/sealed-idb.js +112 -0
  108. package/dist/agent-runtime/src/sealed-idb.js.map +1 -0
  109. package/dist/agent-runtime/src/send-recovery.d.ts +40 -0
  110. package/dist/agent-runtime/src/statewire-attach-observer.d.ts +194 -0
  111. package/dist/agent-runtime/src/statewire-diagnostics.d.ts +74 -0
  112. package/dist/agent-runtime/src/statewire-state.d.ts +29 -0
  113. package/dist/agent-runtime/src/statewire-suspended.cjs.map +1 -1
  114. package/dist/agent-runtime/src/statewire-suspended.d.ts +27 -0
  115. package/dist/agent-runtime/src/statewire-suspended.js.map +1 -1
  116. package/dist/agent-runtime/src/statewire-transport.d.ts +40 -0
  117. package/dist/agent-runtime/src/streaming-markdown.d.ts +46 -0
  118. package/dist/agent-runtime/src/subagent-transcripts.cjs +209 -0
  119. package/dist/agent-runtime/src/subagent-transcripts.cjs.map +1 -0
  120. package/dist/agent-runtime/src/subagent-transcripts.d.ts +71 -0
  121. package/dist/agent-runtime/src/subagent-transcripts.js +209 -0
  122. package/dist/agent-runtime/src/subagent-transcripts.js.map +1 -0
  123. package/dist/agent-runtime/src/subagents.cjs +253 -0
  124. package/dist/agent-runtime/src/subagents.cjs.map +1 -0
  125. package/dist/agent-runtime/src/subagents.d.ts +311 -0
  126. package/dist/agent-runtime/src/subagents.js +253 -0
  127. package/dist/agent-runtime/src/subagents.js.map +1 -0
  128. package/dist/agent-runtime/src/subscription-wake-event.d.ts +111 -0
  129. package/dist/agent-runtime/src/thread-extras.d.ts +43 -0
  130. package/dist/agent-runtime/src/thread-handoff.d.ts +364 -0
  131. package/dist/agent-runtime/src/thread-prewarm-controller.d.ts +76 -0
  132. package/dist/agent-runtime/src/thread-prewarm.d.ts +118 -0
  133. package/dist/agent-runtime/src/thread-snapshot-cache.d.ts +99 -0
  134. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs +46 -117
  135. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs.map +1 -1
  136. package/dist/agent-runtime/src/thread-snapshot-mirror.d.ts +101 -0
  137. package/dist/agent-runtime/src/thread-snapshot-mirror.js +17 -88
  138. package/dist/agent-runtime/src/thread-snapshot-mirror.js.map +1 -1
  139. package/dist/agent-runtime/src/thread-status.d.ts +53 -0
  140. package/dist/agent-runtime/src/tool-metadata.d.ts +146 -0
  141. package/dist/agent-runtime/src/tool-names.cjs +67 -0
  142. package/dist/agent-runtime/src/tool-names.cjs.map +1 -1
  143. package/dist/agent-runtime/src/tool-names.d.ts +60 -0
  144. package/dist/agent-runtime/src/tool-names.js +68 -1
  145. package/dist/agent-runtime/src/tool-names.js.map +1 -1
  146. package/dist/agent-runtime/src/tool-outputs.d.ts +35 -0
  147. package/dist/agent-runtime/src/tool-result.cjs +1 -0
  148. package/dist/agent-runtime/src/tool-result.cjs.map +1 -1
  149. package/dist/agent-runtime/src/tool-result.d.ts +126 -0
  150. package/dist/agent-runtime/src/tool-result.js +1 -0
  151. package/dist/agent-runtime/src/tool-result.js.map +1 -1
  152. package/dist/agent-runtime/src/types.d.ts +159 -0
  153. package/dist/agent-runtime/src/use-conversation-list.d.ts +76 -0
  154. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +136 -0
  155. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -0
  156. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +64 -0
  157. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +136 -0
  158. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -0
  159. package/dist/agent-runtime/src/use-deep-agent-config.d.ts +169 -0
  160. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs +13 -0
  161. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs.map +1 -1
  162. package/dist/agent-runtime/src/use-deep-agent-edit-submit.d.ts +22 -0
  163. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js +13 -0
  164. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js.map +1 -1
  165. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +20 -2
  166. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  167. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +168 -0
  168. package/dist/agent-runtime/src/use-deep-agent-runtime.js +20 -2
  169. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  170. package/dist/agent-runtime/src/use-deep-agent-thread.cjs +12 -4
  171. package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
  172. package/dist/agent-runtime/src/use-deep-agent-thread.d.ts +320 -0
  173. package/dist/agent-runtime/src/use-deep-agent-thread.js +12 -4
  174. package/dist/agent-runtime/src/use-deep-agent-thread.js.map +1 -1
  175. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +999 -0
  176. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -0
  177. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +409 -0
  178. package/dist/agent-runtime/src/use-deep-agent-voice.js +999 -0
  179. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -0
  180. package/dist/agent-runtime/src/use-deep-agent-window-sync.d.ts +102 -0
  181. package/dist/agent-runtime/src/use-historical-edit-attachments.d.ts +2 -0
  182. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +84 -0
  183. package/dist/agent-runtime/src/voice-presentation.d.ts +80 -0
  184. package/dist/agent-runtime/src/voice-turn-grouping.d.ts +28 -0
  185. package/dist/agent-runtime/src/voice-wire-types.d.ts +15 -0
  186. package/dist/agent-runtime/src/withdrawn-turns.d.ts +97 -0
  187. package/dist/chat/AthenaChat.cjs +72 -5
  188. package/dist/chat/AthenaChat.cjs.map +1 -1
  189. package/dist/chat/AthenaChat.js +73 -6
  190. package/dist/chat/AthenaChat.js.map +1 -1
  191. package/dist/chat/StatewireApprovalCard.d.ts +1 -1
  192. package/dist/chat/StatewireClientToolBridge.d.ts +1 -1
  193. package/dist/chat/StatewireQueuedMessages.cjs +11 -4
  194. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  195. package/dist/chat/StatewireQueuedMessages.d.ts +1 -1
  196. package/dist/chat/StatewireQueuedMessages.js +11 -4
  197. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  198. package/dist/chat/chat-outbox-rows.cjs +223 -0
  199. package/dist/chat/chat-outbox-rows.cjs.map +1 -0
  200. package/dist/chat/chat-outbox-rows.d.ts +29 -0
  201. package/dist/chat/chat-outbox-rows.js +223 -0
  202. package/dist/chat/chat-outbox-rows.js.map +1 -0
  203. package/dist/chat/statewire-approval.d.ts +1 -1
  204. package/dist/chat/statewire-client-tools.d.ts +1 -1
  205. package/dist/chat/super-grouping/SuperGroupingCard.cjs +3 -1
  206. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  207. package/dist/chat/super-grouping/SuperGroupingCard.d.ts +7 -1
  208. package/dist/chat/super-grouping/SuperGroupingCard.js +3 -1
  209. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  210. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +7 -2
  211. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  212. package/dist/chat/super-grouping/SuperGroupingTranscript.d.ts +2 -2
  213. package/dist/chat/super-grouping/SuperGroupingTranscript.js +7 -2
  214. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  215. package/dist/chat/super-grouping/activity-timeline.cjs +15 -8
  216. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  217. package/dist/chat/super-grouping/activity-timeline.d.ts +18 -8
  218. package/dist/chat/super-grouping/activity-timeline.js +15 -8
  219. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  220. package/dist/chat/use-statewire-approval-request.cjs +36 -0
  221. package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
  222. package/dist/chat/use-statewire-approval-request.d.ts +49 -1
  223. package/dist/chat/use-statewire-approval-request.js +39 -3
  224. package/dist/chat/use-statewire-approval-request.js.map +1 -1
  225. package/dist/chat-ui/composer/tiptap-composer.cjs +102 -3
  226. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  227. package/dist/chat-ui/composer/tiptap-composer.d.ts +32 -1
  228. package/dist/chat-ui/composer/tiptap-composer.js +103 -4
  229. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  230. package/dist/chat-ui/header/conversation-history-panel.d.ts +1 -1
  231. package/dist/chat-ui/index.d.ts +1 -1
  232. package/dist/chat-ui/messages/message-components.cjs +15 -0
  233. package/dist/chat-ui/messages/message-components.cjs.map +1 -1
  234. package/dist/chat-ui/messages/message-components.js +15 -0
  235. package/dist/chat-ui/messages/message-components.js.map +1 -1
  236. package/dist/chat-ui/messages/runtime-message.d.ts +1 -1
  237. package/dist/chat-ui/messages/statewire-continue-run.d.ts +1 -1
  238. package/dist/chat-ui/messages/user-edit-composer.cjs +15 -2
  239. package/dist/chat-ui/messages/user-edit-composer.cjs.map +1 -1
  240. package/dist/chat-ui/messages/user-edit-composer.d.ts +4 -2
  241. package/dist/chat-ui/messages/user-edit-composer.js +15 -2
  242. package/dist/chat-ui/messages/user-edit-composer.js.map +1 -1
  243. package/dist/chat-ui/messages/wake-marker.d.ts +1 -1
  244. package/dist/chat-ui/rich-text/chat-text-schema.cjs +1 -0
  245. package/dist/chat-ui/rich-text/chat-text-schema.cjs.map +1 -1
  246. package/dist/chat-ui/rich-text/chat-text-schema.d.ts +3 -0
  247. package/dist/chat-ui/rich-text/chat-text-schema.js +1 -0
  248. package/dist/chat-ui/rich-text/chat-text-schema.js.map +1 -1
  249. package/dist/chat-ui/statewire.cjs +1 -0
  250. package/dist/chat-ui/statewire.cjs.map +1 -1
  251. package/dist/chat-ui/statewire.d.ts +2 -2
  252. package/dist/chat-ui/statewire.js +2 -1
  253. package/dist/chat-ui/thread/statewire-history-edge.d.ts +1 -1
  254. package/dist/composer/AttachmentContext.cjs +8 -4
  255. package/dist/composer/AttachmentContext.cjs.map +1 -1
  256. package/dist/composer/AttachmentContext.d.ts +7 -0
  257. package/dist/composer/AttachmentContext.js +8 -4
  258. package/dist/composer/AttachmentContext.js.map +1 -1
  259. package/dist/composer/build-composed-message.cjs +34 -0
  260. package/dist/composer/build-composed-message.cjs.map +1 -1
  261. package/dist/composer/build-composed-message.d.ts +20 -0
  262. package/dist/composer/build-composed-message.js +35 -1
  263. package/dist/composer/build-composed-message.js.map +1 -1
  264. package/dist/composer/composer-handoff.cjs +39 -2
  265. package/dist/composer/composer-handoff.cjs.map +1 -1
  266. package/dist/composer/composer-handoff.d.ts +28 -3
  267. package/dist/composer/composer-handoff.js +39 -2
  268. package/dist/composer/composer-handoff.js.map +1 -1
  269. package/dist/composer/useAttachFiles.cjs +15 -2
  270. package/dist/composer/useAttachFiles.cjs.map +1 -1
  271. package/dist/composer/useAttachFiles.d.ts +11 -0
  272. package/dist/composer/useAttachFiles.js +15 -2
  273. package/dist/composer/useAttachFiles.js.map +1 -1
  274. package/dist/composer/useSendMessage.cjs.map +1 -1
  275. package/dist/composer/useSendMessage.d.ts +4 -3
  276. package/dist/composer/useSendMessage.js.map +1 -1
  277. package/dist/diagnostics/athena-diagnostics.cjs.map +1 -1
  278. package/dist/diagnostics/athena-diagnostics.d.ts +3 -1
  279. package/dist/diagnostics/athena-diagnostics.js.map +1 -1
  280. package/dist/index.cjs +13 -0
  281. package/dist/index.cjs.map +1 -1
  282. package/dist/index.d.ts +13 -6
  283. package/dist/index.js +14 -1
  284. package/dist/index.js.map +1 -1
  285. package/dist/offline/chat-outbox.cjs +57 -0
  286. package/dist/offline/chat-outbox.cjs.map +1 -0
  287. package/dist/offline/chat-outbox.d.ts +80 -0
  288. package/dist/offline/chat-outbox.js +57 -0
  289. package/dist/offline/chat-outbox.js.map +1 -0
  290. package/dist/offline/offline-history.d.ts +1 -1
  291. package/dist/provider/AthenaProvider.cjs +162 -8
  292. package/dist/provider/AthenaProvider.cjs.map +1 -1
  293. package/dist/provider/AthenaProvider.d.ts +15 -1
  294. package/dist/provider/AthenaProvider.js +163 -9
  295. package/dist/provider/AthenaProvider.js.map +1 -1
  296. package/dist/provider/statewire-window-context.d.ts +1 -1
  297. package/dist/react/package.json.cjs +1 -1
  298. package/dist/react/package.json.js +1 -1
  299. package/dist/references/src/anchors/file-line-range.d.ts +58 -0
  300. package/dist/references/src/anchors/format.d.ts +21 -0
  301. package/dist/references/src/anchors/message-anchors.d.ts +71 -0
  302. package/dist/references/src/anchors/parse.d.ts +8 -0
  303. package/dist/references/src/anchors/registry-contract.d.ts +24 -0
  304. package/dist/references/src/anchors/registry.d.ts +19 -0
  305. package/dist/references/src/anchors/schemas.d.ts +194 -0
  306. package/dist/references/src/anchors/serialize.d.ts +8 -0
  307. package/dist/references/src/anchors/time.d.ts +78 -0
  308. package/dist/references/src/anchors/types.d.ts +474 -0
  309. package/dist/references/src/asset-bounds.d.ts +27 -0
  310. package/dist/references/src/asset-links.d.ts +23 -0
  311. package/dist/references/src/asset-reference.d.ts +16 -0
  312. package/dist/references/src/formats/format-catalog.d.ts +79 -0
  313. package/dist/references/src/formats/markdown/parse-reference-markdown.d.ts +28 -0
  314. package/dist/references/src/formats/markdown/reference-display-name.d.ts +6 -0
  315. package/dist/references/src/formats/object/asset-object.d.ts +9 -0
  316. package/dist/references/src/formats/object/callable-object.d.ts +6 -0
  317. package/dist/references/src/formats/object/decode-reference-object-payload.d.ts +3 -0
  318. package/dist/references/src/formats/object/external-url-object.d.ts +9 -0
  319. package/dist/references/src/formats/object/group-object.d.ts +9 -0
  320. package/dist/references/src/formats/object/navigation-object.d.ts +9 -0
  321. package/dist/references/src/formats/object/parse-reference-object.d.ts +11 -0
  322. package/dist/references/src/formats/object/person-object.d.ts +9 -0
  323. package/dist/references/src/formats/uri/asset-mention-uri.d.ts +9 -0
  324. package/dist/references/src/formats/uri/asset-spaces-url.d.ts +9 -0
  325. package/dist/references/src/formats/uri/callable-mention-uris.d.ts +9 -0
  326. package/dist/references/src/formats/uri/detect-uri-wire.d.ts +9 -0
  327. package/dist/references/src/formats/uri/group-mention-uri.d.ts +12 -0
  328. package/dist/references/src/formats/uri/navigation-spaces-url.d.ts +14 -0
  329. package/dist/references/src/formats/uri/parse-reference-uri.d.ts +20 -0
  330. package/dist/references/src/formats/uri/person-mention-uri.d.ts +9 -0
  331. package/dist/references/src/formats/uri/template-placeholder.d.ts +12 -0
  332. package/dist/references/src/index.d.ts +47 -0
  333. package/dist/references/src/legacy/index.d.ts +14 -0
  334. package/dist/references/src/legacy/pre-reference-asset-url.d.ts +57 -0
  335. package/dist/references/src/legacy/pre-reference-citation-bridge.d.ts +22 -0
  336. package/dist/references/src/legacy/pre-reference-citation.d.ts +138 -0
  337. package/dist/references/src/legacy/pre-reference-external-url.d.ts +31 -0
  338. package/dist/references/src/legacy/pre-reference-format.d.ts +8 -0
  339. package/dist/references/src/legacy/pre-reference-mention.d.ts +27 -0
  340. package/dist/references/src/legacy/pre-reference-object.d.ts +8 -0
  341. package/dist/references/src/legacy/pre-reference-uri.d.ts +12 -0
  342. package/dist/references/src/legacy.d.ts +2 -0
  343. package/dist/references/src/mention-href-patterns.d.ts +19 -0
  344. package/dist/references/src/mention-node/index.d.ts +5 -0
  345. package/dist/references/src/mention-node/mention-node.d.ts +31 -0
  346. package/dist/references/src/mention-node/resolve-node-attrs.d.ts +27 -0
  347. package/dist/references/src/parse-reference.d.ts +23 -0
  348. package/dist/references/src/schemas.d.ts +463 -0
  349. package/dist/references/src/serialize-reference.d.ts +50 -0
  350. package/dist/references/src/sheet-name.d.ts +10 -0
  351. package/dist/references/src/tool-option-schemas.d.ts +597 -0
  352. package/dist/references/src/types.d.ts +125 -0
  353. package/dist/references/src/version-ref.d.ts +30 -0
  354. package/dist/runtime/statewire-lifecycle.d.ts +1 -1
  355. package/dist/runtime/statewire-model-lane.d.ts +1 -1
  356. package/dist/runtime/statewire-server-lane-context.d.ts +1 -1
  357. package/dist/runtime/statewire-session-key.cjs +7 -0
  358. package/dist/runtime/statewire-session-key.cjs.map +1 -1
  359. package/dist/runtime/statewire-session-key.d.ts +16 -0
  360. package/dist/runtime/statewire-session-key.js +8 -1
  361. package/dist/runtime/statewire-session-key.js.map +1 -1
  362. package/dist/runtime/statewire-session-lane.cjs +48 -0
  363. package/dist/runtime/statewire-session-lane.cjs.map +1 -0
  364. package/dist/runtime/statewire-session-lane.d.ts +29 -0
  365. package/dist/runtime/statewire-session-lane.js +48 -0
  366. package/dist/runtime/statewire-session-lane.js.map +1 -0
  367. package/dist/runtime/statewire-thread-config-lane.d.ts +1 -1
  368. package/dist/runtime/useAthenaStatewireRuntime.cjs +16 -5
  369. package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
  370. package/dist/runtime/useAthenaStatewireRuntime.d.ts +15 -1
  371. package/dist/runtime/useAthenaStatewireRuntime.js +17 -6
  372. package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
  373. package/dist/styles.css +1 -1
  374. package/dist/threads/api.d.ts +1 -1
  375. package/dist/threads/conversation-list-fetcher.d.ts +1 -1
  376. package/dist/threads/index-triggered-refresh.cjs +164 -0
  377. package/dist/threads/index-triggered-refresh.cjs.map +1 -0
  378. package/dist/threads/index-triggered-refresh.d.ts +70 -0
  379. package/dist/threads/index-triggered-refresh.js +164 -0
  380. package/dist/threads/index-triggered-refresh.js.map +1 -0
  381. package/dist/threads/offline-session-list.d.ts +1 -1
  382. package/dist/threads/pull-request-display.d.ts +1 -1
  383. package/dist/threads/session-list-model.d.ts +1 -1
  384. package/dist/threads/session-list-tab-share.cjs +150 -0
  385. package/dist/threads/session-list-tab-share.cjs.map +1 -0
  386. package/dist/threads/session-list-tab-share.d.ts +73 -0
  387. package/dist/threads/session-list-tab-share.js +150 -0
  388. package/dist/threads/session-list-tab-share.js.map +1 -0
  389. package/dist/threads/session-row-parts.d.ts +1 -1
  390. package/dist/threads/sessions-query.d.ts +1 -1
  391. package/dist/threads/statewire-thread-list.cjs +42 -16
  392. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  393. package/dist/threads/statewire-thread-list.d.ts +11 -2
  394. package/dist/threads/statewire-thread-list.js +43 -17
  395. package/dist/threads/statewire-thread-list.js.map +1 -1
  396. package/dist/threads/thread-prefetcher.d.ts +1 -1
  397. package/dist/threads/use-athena-session-attention.d.ts +1 -1
  398. package/dist/threads/use-athena-sessions.cjs +32 -22
  399. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  400. package/dist/threads/use-athena-sessions.js +33 -23
  401. package/dist/threads/use-athena-sessions.js.map +1 -1
  402. package/dist/threads/use-rest-conversation-history.d.ts +1 -1
  403. package/dist/threads/use-statewire-conversation-history.d.ts +5 -5
  404. package/dist/tiptap-markdown-table/src/markdown-table-serializer.d.ts +56 -0
  405. package/dist/tools/NestedPtcMessages.cjs +14 -9
  406. package/dist/tools/NestedPtcMessages.cjs.map +1 -1
  407. package/dist/tools/NestedPtcMessages.d.ts +9 -0
  408. package/dist/tools/NestedPtcMessages.js +6 -1
  409. package/dist/tools/NestedPtcMessages.js.map +1 -1
  410. package/dist/tools/index.d.ts +1 -1
  411. package/dist/tools/primitives.d.ts +1 -1
  412. package/dist/tools/subagent-task-tool-ui.cjs +494 -0
  413. package/dist/tools/subagent-task-tool-ui.cjs.map +1 -0
  414. package/dist/tools/subagent-task-tool-ui.d.ts +109 -0
  415. package/dist/tools/subagent-task-tool-ui.js +494 -0
  416. package/dist/tools/subagent-task-tool-ui.js.map +1 -0
  417. package/dist/tools/tool-fallback.d.ts +1 -1
  418. package/dist/tools/tool-icons.d.ts +1 -1
  419. package/dist/tools/tool-summary.d.ts +1 -1
  420. package/dist/tools/tool-uis.cjs +4 -0
  421. package/dist/tools/tool-uis.cjs.map +1 -1
  422. package/dist/tools/tool-uis.js +4 -0
  423. package/dist/tools/tool-uis.js.map +1 -1
  424. package/dist/voice/chat.cjs +6 -0
  425. package/dist/voice/chat.cjs.map +1 -0
  426. package/dist/voice/chat.d.ts +2 -0
  427. package/dist/voice/chat.js +6 -0
  428. package/dist/voice/chat.js.map +1 -0
  429. package/dist/voice/livekit-join.cjs +119 -0
  430. package/dist/voice/livekit-join.cjs.map +1 -0
  431. package/dist/voice/livekit-join.d.ts +8 -0
  432. package/dist/voice/livekit-join.js +119 -0
  433. package/dist/voice/livekit-join.js.map +1 -0
  434. package/dist/voice/livekit.cjs +32 -0
  435. package/dist/voice/livekit.cjs.map +1 -0
  436. package/dist/voice/livekit.d.ts +80 -0
  437. package/dist/voice/livekit.js +32 -0
  438. package/dist/voice/livekit.js.map +1 -0
  439. package/package.json +20 -10
@@ -0,0 +1,696 @@
1
+ const CHAT_OUTBOX_COUNTDOWN_MS = 5e3;
2
+ const CHAT_OUTBOX_ASK_AFTER_MS = 24 * 60 * 60 * 1e3;
3
+ const CHAT_OUTBOX_CLAIM_LEASE_MS = 3e4;
4
+ const CHAT_OUTBOX_ATTACHMENT_CHECK_TIMEOUT_MS = 15e3;
5
+ const CHAT_EDIT_UNREACHABLE_LABEL = "Can't edit while Athena can't be reached";
6
+ const CHAT_EDIT_KEPT_MESSAGE = "Can't reach Athena right now. Your edit stays here — submit it once Athena is back.";
7
+ class ChatEditUnreachableError extends Error {
8
+ constructor() {
9
+ super(CHAT_EDIT_KEPT_MESSAGE);
10
+ this.name = "ChatEditUnreachableError";
11
+ }
12
+ }
13
+ function chatOutboxFailureMessage(reason) {
14
+ switch (reason) {
15
+ case "refused":
16
+ return "This conversation can't be reached right now.";
17
+ case "prepare":
18
+ return "Couldn't prepare this message to send.";
19
+ case "attachment":
20
+ return "An attachment is no longer available to you.";
21
+ default:
22
+ return "Couldn't send this message.";
23
+ }
24
+ }
25
+ const AWAY_CAUSES = /* @__PURE__ */ new Set(["unmount", "stream-gone"]);
26
+ function chatOutboxCommandMessageId(params) {
27
+ var _a;
28
+ const first = params == null ? void 0 : params[0];
29
+ const id = (_a = first == null ? void 0 : first.message) == null ? void 0 : _a.id;
30
+ return typeof id === "string" ? id : null;
31
+ }
32
+ function failureOf(error) {
33
+ const failure = error == null ? void 0 : error.failure;
34
+ const fate = typeof (failure == null ? void 0 : failure.fate) === "string" ? failure.fate : void 0;
35
+ const cause = typeof (failure == null ? void 0 : failure.cause) === "string" ? failure.cause : void 0;
36
+ const message = error instanceof Error ? error.message : String(error);
37
+ return { fate, cause, message };
38
+ }
39
+ function defaultMessageId() {
40
+ var _a;
41
+ const host = globalThis;
42
+ if (typeof ((_a = host.crypto) == null ? void 0 : _a.randomUUID) === "function") return host.crypto.randomUUID();
43
+ const hex = Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
44
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-a${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
45
+ }
46
+ function sameChatOutboxRowState(a, b) {
47
+ if (a.kind !== b.kind) return false;
48
+ switch (a.kind) {
49
+ case "countdown":
50
+ return a.endsAt === b.endsAt;
51
+ case "failed":
52
+ return a.reason === b.reason && a.message === b.message;
53
+ default:
54
+ return true;
55
+ }
56
+ }
57
+ function sameChatOutboxEntry(a, b) {
58
+ return a === b || a.id === b.id && a.threadId === b.threadId && a.text === b.text && a.newChat === b.newChat && a.queuedAt === b.queuedAt && a.composerMarkdown === b.composerMarkdown;
59
+ }
60
+ function sameChatOutboxSnapshot(a, b) {
61
+ if (a === b) return true;
62
+ if (a.countdownEndsAt !== b.countdownEndsAt || a.durable !== b.durable || a.loaded !== b.loaded) return false;
63
+ if (a.rows.length !== b.rows.length || a.elsewhere.length !== b.elsewhere.length) return false;
64
+ for (let index = 0; index < a.rows.length; index += 1) {
65
+ const x = a.rows[index];
66
+ const y = b.rows[index];
67
+ if (!x || !y || x.entry !== y.entry || !sameChatOutboxRowState(x.state, y.state)) return false;
68
+ }
69
+ for (let index = 0; index < a.elsewhere.length; index += 1) {
70
+ const x = a.elsewhere[index];
71
+ const y = b.elsewhere[index];
72
+ if (!x || !y || x.threadId !== y.threadId || x.count !== y.count || x.newChat !== y.newChat || !sameChatOutboxEntry(x.first, y.first)) {
73
+ return false;
74
+ }
75
+ }
76
+ return true;
77
+ }
78
+ function createChatOutbox(options) {
79
+ const {
80
+ threadId,
81
+ isNewChat,
82
+ store,
83
+ reachability,
84
+ foreground,
85
+ thread,
86
+ restore,
87
+ openThread,
88
+ onEvent,
89
+ checkAttachments,
90
+ now = () => Date.now(),
91
+ countdownMs = CHAT_OUTBOX_COUNTDOWN_MS,
92
+ askAfterMs = CHAT_OUTBOX_ASK_AFTER_MS,
93
+ claimLeaseMs = CHAT_OUTBOX_CLAIM_LEASE_MS,
94
+ attachmentCheckTimeoutMs = CHAT_OUTBOX_ATTACHMENT_CHECK_TIMEOUT_MS,
95
+ newMessageId = defaultMessageId,
96
+ setTimer = (task, ms) => {
97
+ const timer = setTimeout(task, ms);
98
+ return () => clearTimeout(timer);
99
+ }
100
+ } = options;
101
+ const claimant = newMessageId();
102
+ let disposed = false;
103
+ let loaded = store === null;
104
+ let entries = [];
105
+ let elsewhere = [];
106
+ let claims = /* @__PURE__ */ new Map();
107
+ const persisted = /* @__PURE__ */ new Set();
108
+ const unsettled = /* @__PURE__ */ new Map();
109
+ let listingsStarted = 0;
110
+ const phases = /* @__PURE__ */ new Map();
111
+ const sendNow = /* @__PURE__ */ new Set();
112
+ const handedInRegain = /* @__PURE__ */ new Map();
113
+ let regain = 0;
114
+ let wasReachable = reachability.get();
115
+ let countdown = null;
116
+ let leaseTimer = null;
117
+ const checkTimers = /* @__PURE__ */ new Set();
118
+ const readyToGo = /* @__PURE__ */ new Map();
119
+ let releasing = false;
120
+ const asked = /* @__PURE__ */ new Set();
121
+ const listeners = /* @__PURE__ */ new Set();
122
+ let snapshot = {
123
+ rows: [],
124
+ countdownEndsAt: null,
125
+ durable: true,
126
+ loaded,
127
+ elsewhere
128
+ };
129
+ const emit = (event) => {
130
+ try {
131
+ onEvent == null ? void 0 : onEvent(event);
132
+ } catch {
133
+ }
134
+ };
135
+ const phaseOf = (id) => phases.get(id) ?? { kind: "idle" };
136
+ const isBusy = (phase) => phase.kind === "claiming" || phase.kind === "handed" || phase.kind === "awaiting-thread";
137
+ const claimedElsewhere = (id) => {
138
+ const claim = claims.get(id);
139
+ return claim !== void 0 && claim.by !== claimant && now() - claim.at < claimLeaseMs;
140
+ };
141
+ const settledFor = (id, listing) => {
142
+ if (!unsettled.has(id)) return true;
143
+ const settledAt = unsettled.get(id);
144
+ return settledAt !== void 0 && listing > settledAt;
145
+ };
146
+ const writePending = (id) => unsettled.has(id) && unsettled.get(id) === void 0;
147
+ const markUnsettled = (id, write) => {
148
+ unsettled.set(id, void 0);
149
+ const settle = () => {
150
+ if (!unsettled.has(id)) return;
151
+ unsettled.set(id, listingsStarted);
152
+ evaluate();
153
+ };
154
+ void write.then(settle, settle);
155
+ };
156
+ const rowState = (entry, line) => {
157
+ const phase = phaseOf(entry.id);
158
+ if (phase.kind === "failed") {
159
+ return { kind: "failed", reason: phase.reason, message: chatOutboxFailureMessage(phase.reason) };
160
+ }
161
+ if (isBusy(phase) || claimedElsewhere(entry.id)) return { kind: "sending" };
162
+ if (countdown !== null && line.run.some((candidate) => candidate.id === entry.id)) {
163
+ return { kind: "countdown", endsAt: countdown.endsAt };
164
+ }
165
+ if (line.askId === entry.id) return { kind: "ask" };
166
+ return { kind: "waiting" };
167
+ };
168
+ const computeLine = () => {
169
+ const run = [];
170
+ for (const entry of entries) {
171
+ const phase = phaseOf(entry.id);
172
+ if (phase.kind === "failed") continue;
173
+ if (isBusy(phase) || claimedElsewhere(entry.id)) continue;
174
+ if (handedInRegain.get(entry.id) === regain && !sendNow.has(entry.id)) continue;
175
+ if (!sendNow.has(entry.id) && now() - entry.queuedAt > askAfterMs) {
176
+ return { run, askId: run.length === 0 ? entry.id : null };
177
+ }
178
+ run.push(entry);
179
+ }
180
+ return { run, askId: null };
181
+ };
182
+ const gateOpen = () => reachability.get() && foreground.get();
183
+ const publish = () => {
184
+ const line = gateOpen() ? computeLine() : { run: [], askId: null };
185
+ const next = {
186
+ rows: entries.map((entry) => ({ entry, state: rowState(entry, line) })),
187
+ countdownEndsAt: (countdown == null ? void 0 : countdown.endsAt) ?? null,
188
+ durable: entries.every((entry) => persisted.has(entry.id)),
189
+ loaded,
190
+ elsewhere
191
+ };
192
+ if (sameChatOutboxSnapshot(snapshot, next)) return;
193
+ snapshot = next;
194
+ for (const listener of listeners) {
195
+ try {
196
+ listener();
197
+ } catch {
198
+ }
199
+ }
200
+ };
201
+ const stopCountdown = () => {
202
+ countdown == null ? void 0 : countdown.cancel();
203
+ countdown = null;
204
+ };
205
+ const dropEntry = (id) => {
206
+ entries = entries.filter((entry) => entry.id !== id);
207
+ unsettled.delete(id);
208
+ phases.delete(id);
209
+ readyToGo.delete(id);
210
+ sendNow.delete(id);
211
+ persisted.delete(id);
212
+ claims.delete(id);
213
+ asked.delete(id);
214
+ if (countdown == null ? void 0 : countdown.ids.includes(id)) stopCountdown();
215
+ };
216
+ const letGo = (id, event) => {
217
+ if (!entries.some((entry) => entry.id === id)) return;
218
+ dropEntry(id);
219
+ emit(event);
220
+ if (store) void store.remove(threadId, id).catch(() => void 0);
221
+ };
222
+ const fail = (id, reason) => {
223
+ phases.set(id, { kind: "failed", reason });
224
+ sendNow.delete(id);
225
+ emit({ type: "failed", threadId, messageId: id, message: chatOutboxFailureMessage(reason), reason });
226
+ if (store) {
227
+ void store.markFailed({ threadId, id, claimant, failure: { reason, at: now() } }).catch(() => void 0);
228
+ }
229
+ };
230
+ const releaseClaim = (id) => {
231
+ if (store) void store.release({ threadId, id, claimant }).catch(() => void 0);
232
+ };
233
+ const handOff = (entry, auto) => {
234
+ if (thread.heldIds().has(entry.id)) {
235
+ letGo(entry.id, { type: "adopted", threadId, messageId: entry.id });
236
+ return;
237
+ }
238
+ const readiness = thread.readiness();
239
+ if (readiness === "refused") {
240
+ fail(entry.id, "refused");
241
+ return;
242
+ }
243
+ if (readiness === "connecting") {
244
+ phases.set(entry.id, { kind: "awaiting-thread" });
245
+ return;
246
+ }
247
+ if (writePending(entry.id)) {
248
+ phases.set(entry.id, { kind: "awaiting-thread" });
249
+ return;
250
+ }
251
+ sendNow.delete(entry.id);
252
+ phases.set(entry.id, { kind: "claiming" });
253
+ const claim = store ? store.claim({ threadId, id: entry.id, claimant, now: now(), leaseMs: claimLeaseMs }) : Promise.resolve("claimed");
254
+ void claim.then(
255
+ (result) => {
256
+ if (disposed || phaseOf(entry.id).kind !== "claiming") return;
257
+ if (result === "gone") {
258
+ dropEntry(entry.id);
259
+ evaluate();
260
+ return;
261
+ }
262
+ if (result === "taken") {
263
+ phases.set(entry.id, { kind: "idle" });
264
+ claims.set(entry.id, { by: "elsewhere", at: now() });
265
+ evaluate();
266
+ return;
267
+ }
268
+ if (!stillGoes(entry)) return;
269
+ checkThenDispatch(entry, auto);
270
+ },
271
+ () => {
272
+ if (disposed || phaseOf(entry.id).kind !== "claiming") return;
273
+ fail(entry.id, "prepare");
274
+ evaluate();
275
+ }
276
+ );
277
+ };
278
+ const stillGoes = (entry) => {
279
+ if (thread.heldIds().has(entry.id)) {
280
+ letGo(entry.id, { type: "adopted", threadId, messageId: entry.id });
281
+ evaluate();
282
+ return false;
283
+ }
284
+ const ready = thread.readiness();
285
+ if (ready === "refused") {
286
+ fail(entry.id, "refused");
287
+ evaluate();
288
+ return false;
289
+ }
290
+ if (!gateOpen() || ready !== "ready") {
291
+ phases.set(entry.id, gateOpen() ? { kind: "awaiting-thread" } : { kind: "idle" });
292
+ releaseClaim(entry.id);
293
+ evaluate();
294
+ return false;
295
+ }
296
+ return true;
297
+ };
298
+ const checkThenDispatch = (entry, auto) => {
299
+ const attachments = entry.attachments ?? [];
300
+ if (attachments.length === 0 || !checkAttachments) {
301
+ readyToGo.set(entry.id, auto);
302
+ releaseReady();
303
+ return;
304
+ }
305
+ let answered = false;
306
+ let stopTimer = () => void 0;
307
+ const answer = (verdict) => {
308
+ if (answered) return;
309
+ answered = true;
310
+ stopTimer();
311
+ checkTimers.delete(stopTimer);
312
+ if (disposed || phaseOf(entry.id).kind !== "claiming") return;
313
+ if (!stillGoes(entry)) return;
314
+ if (verdict === "ok") {
315
+ readyToGo.set(entry.id, auto);
316
+ releaseReady();
317
+ return;
318
+ }
319
+ fail(entry.id, verdict === "refused" ? "attachment" : "error");
320
+ evaluate();
321
+ };
322
+ stopTimer = setTimer(() => answer("unknown"), attachmentCheckTimeoutMs);
323
+ checkTimers.add(stopTimer);
324
+ let checking;
325
+ try {
326
+ checking = checkAttachments(attachments);
327
+ } catch (error) {
328
+ checking = Promise.reject(error);
329
+ }
330
+ void checking.then(answer, () => answer("unknown"));
331
+ };
332
+ function releaseReady() {
333
+ if (releasing || disposed) return;
334
+ releasing = true;
335
+ try {
336
+ for (const entry of [...entries]) {
337
+ if (phaseOf(entry.id).kind !== "claiming") continue;
338
+ const auto = readyToGo.get(entry.id);
339
+ if (auto === void 0) return;
340
+ readyToGo.delete(entry.id);
341
+ if (stillGoes(entry)) dispatch(entry, auto);
342
+ }
343
+ } finally {
344
+ releasing = false;
345
+ }
346
+ }
347
+ const dispatch = (entry, auto) => {
348
+ handedInRegain.set(entry.id, regain);
349
+ phases.set(entry.id, { kind: "handed", journaled: false });
350
+ emit({ type: "handed", threadId, messageId: entry.id, auto, ageMs: now() - entry.queuedAt });
351
+ let sent;
352
+ try {
353
+ sent = thread.send(entry);
354
+ } catch (error) {
355
+ sent = Promise.reject(error);
356
+ }
357
+ void sent.then(
358
+ () => {
359
+ if (disposed) return;
360
+ letGo(entry.id, { type: "delivered", threadId, messageId: entry.id, status: "accepted" });
361
+ evaluate();
362
+ },
363
+ (error) => {
364
+ if (disposed) return;
365
+ const phase = phaseOf(entry.id);
366
+ if (phase.kind === "handed" && phase.journaled) return;
367
+ if (phase.kind !== "handed") return;
368
+ const failure = failureOf(error);
369
+ if (failure.cause !== void 0 && AWAY_CAUSES.has(failure.cause)) {
370
+ phases.set(entry.id, { kind: "idle" });
371
+ handedInRegain.delete(entry.id);
372
+ releaseClaim(entry.id);
373
+ evaluate();
374
+ return;
375
+ }
376
+ fail(entry.id, "error");
377
+ evaluate();
378
+ }
379
+ );
380
+ };
381
+ const startCountdown = (run) => {
382
+ stopCountdown();
383
+ const ids = run.map((entry) => entry.id);
384
+ const endsAt = now() + countdownMs;
385
+ const cancel = setTimer(() => {
386
+ if (disposed || (countdown == null ? void 0 : countdown.endsAt) !== endsAt) return;
387
+ countdown = null;
388
+ if (!gateOpen()) {
389
+ evaluate();
390
+ return;
391
+ }
392
+ for (const id of ids) {
393
+ const entry = entries.find((candidate) => candidate.id === id);
394
+ if (!entry) continue;
395
+ const phase = phaseOf(id);
396
+ if (phase.kind !== "idle" || claimedElsewhere(id)) continue;
397
+ handOff(entry, true);
398
+ }
399
+ evaluate();
400
+ }, countdownMs);
401
+ countdown = { endsAt, ids, cancel };
402
+ emit({ type: "countdown-started", threadId, count: ids.length });
403
+ };
404
+ const scheduleLeaseCheck = () => {
405
+ leaseTimer == null ? void 0 : leaseTimer();
406
+ leaseTimer = null;
407
+ let soonest = Number.POSITIVE_INFINITY;
408
+ for (const [id, claim] of claims) {
409
+ if (claim.by === claimant || !entries.some((entry) => entry.id === id)) continue;
410
+ const expires = claim.at + claimLeaseMs - now();
411
+ if (expires > 0) soonest = Math.min(soonest, expires);
412
+ }
413
+ if (Number.isFinite(soonest)) leaseTimer = setTimer(() => evaluate(), soonest + 1);
414
+ };
415
+ function evaluate() {
416
+ evaluateLine();
417
+ releaseReady();
418
+ }
419
+ function evaluateLine() {
420
+ if (disposed) return;
421
+ const reachable = reachability.get();
422
+ if (reachable && !wasReachable) regain += 1;
423
+ wasReachable = reachable;
424
+ if (loaded) {
425
+ const held = thread.heldIds();
426
+ for (const entry of [...entries]) {
427
+ const phase = phaseOf(entry.id);
428
+ if (phase.kind === "handed") {
429
+ if (held.has(entry.id)) phases.set(entry.id, { kind: "handed", journaled: true });
430
+ continue;
431
+ }
432
+ if (phase.kind === "claiming") continue;
433
+ if (held.has(entry.id)) letGo(entry.id, { type: "adopted", threadId, messageId: entry.id });
434
+ }
435
+ if (!gateOpen()) {
436
+ for (const entry of entries) {
437
+ if (phaseOf(entry.id).kind === "awaiting-thread") phases.set(entry.id, { kind: "idle" });
438
+ }
439
+ } else if (thread.readiness() !== "connecting") {
440
+ for (const entry of entries) {
441
+ if (phaseOf(entry.id).kind === "awaiting-thread") {
442
+ phases.set(entry.id, { kind: "idle" });
443
+ handOff(entry, true);
444
+ }
445
+ }
446
+ }
447
+ }
448
+ if (!loaded || !gateOpen()) {
449
+ stopCountdown();
450
+ publish();
451
+ return;
452
+ }
453
+ const line = computeLine();
454
+ if (line.askId !== null && !asked.has(line.askId)) {
455
+ asked.add(line.askId);
456
+ const entry = entries.find((candidate) => candidate.id === line.askId);
457
+ if (entry) emit({ type: "asked", threadId, messageId: entry.id, ageMs: now() - entry.queuedAt });
458
+ }
459
+ const immediate = [];
460
+ for (const entry of line.run) {
461
+ if (!sendNow.has(entry.id)) break;
462
+ immediate.push(entry);
463
+ }
464
+ for (const entry of immediate) handOff(entry, false);
465
+ const run = line.run.slice(immediate.length).filter((entry) => !sendNow.has(entry.id));
466
+ if (run.length === 0) {
467
+ stopCountdown();
468
+ } else if (countdown === null || countdown.ids.length !== run.length || run.some((entry, index) => (countdown == null ? void 0 : countdown.ids[index]) !== entry.id)) {
469
+ startCountdown(run);
470
+ }
471
+ scheduleLeaseCheck();
472
+ publish();
473
+ }
474
+ const applyRecords = (records, listing) => {
475
+ const mine = records.filter((record) => record.entry.threadId === threadId);
476
+ const stored = new Map(mine.map((record) => [record.entry.id, record]));
477
+ claims = new Map(
478
+ mine.flatMap((record) => record.claim ? [[record.entry.id, record.claim]] : [])
479
+ );
480
+ for (const record of mine) {
481
+ if (!settledFor(record.entry.id, listing)) continue;
482
+ if (record.memoryOnly) persisted.delete(record.entry.id);
483
+ else persisted.add(record.entry.id);
484
+ const phase = phaseOf(record.entry.id);
485
+ if (record.failure && phase.kind !== "failed" && !isBusy(phase)) {
486
+ phases.set(record.entry.id, { kind: "failed", reason: record.failure.reason });
487
+ }
488
+ }
489
+ const kept = entries.filter(
490
+ (entry) => stored.has(entry.id) || !settledFor(entry.id, listing) || isBusy(phaseOf(entry.id))
491
+ );
492
+ for (const entry of entries) {
493
+ if (kept.includes(entry)) continue;
494
+ if (countdown == null ? void 0 : countdown.ids.includes(entry.id)) stopCountdown();
495
+ phases.delete(entry.id);
496
+ persisted.delete(entry.id);
497
+ sendNow.delete(entry.id);
498
+ }
499
+ const known = new Set(kept.map((entry) => entry.id));
500
+ const added = mine.filter((record) => !known.has(record.entry.id)).map((record) => record.entry);
501
+ entries = [...kept, ...added].sort((a, b) => a.queuedAt - b.queuedAt);
502
+ for (const [id, settledAt] of unsettled) {
503
+ if (settledAt !== void 0 && listing > settledAt) unsettled.delete(id);
504
+ }
505
+ const byThread = /* @__PURE__ */ new Map();
506
+ for (const record of records) {
507
+ if (record.entry.threadId === threadId) continue;
508
+ const current = byThread.get(record.entry.threadId);
509
+ if (current) {
510
+ current.count += 1;
511
+ current.newChat && (current.newChat = record.entry.newChat);
512
+ } else {
513
+ byThread.set(record.entry.threadId, {
514
+ count: 1,
515
+ first: record.entry,
516
+ newChat: record.entry.newChat
517
+ });
518
+ }
519
+ }
520
+ elsewhere = [...byThread].map(([otherThreadId, other]) => ({ threadId: otherThreadId, ...other })).sort((a, b) => a.first.queuedAt - b.first.queuedAt);
521
+ };
522
+ let reading = null;
523
+ let readAgain = false;
524
+ const reload = () => {
525
+ if (!store || disposed) return;
526
+ if (reading) {
527
+ readAgain = true;
528
+ return;
529
+ }
530
+ listingsStarted += 1;
531
+ const listing = listingsStarted;
532
+ reading = store.listAll().then(
533
+ (records) => {
534
+ if (disposed) return;
535
+ applyRecords(records, listing);
536
+ loaded = true;
537
+ },
538
+ () => {
539
+ loaded = true;
540
+ }
541
+ ).finally(() => {
542
+ reading = null;
543
+ if (disposed) return;
544
+ evaluate();
545
+ if (readAgain) {
546
+ readAgain = false;
547
+ reload();
548
+ }
549
+ });
550
+ };
551
+ const unsubscribers = [
552
+ reachability.subscribe(evaluate),
553
+ foreground.subscribe(evaluate),
554
+ thread.subscribe(evaluate),
555
+ ...store ? [store.subscribe(reload)] : []
556
+ ];
557
+ reload();
558
+ publish();
559
+ return {
560
+ threadId,
561
+ reachability,
562
+ getSnapshot: () => snapshot,
563
+ subscribe(listener) {
564
+ listeners.add(listener);
565
+ return () => {
566
+ listeners.delete(listener);
567
+ };
568
+ },
569
+ shouldHold() {
570
+ if (!reachability.get()) return true;
571
+ if (!loaded) return true;
572
+ return entries.some((entry) => {
573
+ const phase = phaseOf(entry.id);
574
+ return phase.kind !== "failed" && !(phase.kind === "handed" && phase.journaled);
575
+ });
576
+ },
577
+ hold(input) {
578
+ const entry = {
579
+ id: newMessageId(),
580
+ threadId,
581
+ text: input.text,
582
+ queuedAt: now(),
583
+ newChat: typeof isNewChat === "function" ? isNewChat() : isNewChat,
584
+ ...input.composerMarkdown !== void 0 && { composerMarkdown: input.composerMarkdown },
585
+ ...input.composerHtml !== void 0 && { composerHtml: input.composerHtml },
586
+ ...input.metadata !== void 0 && { metadata: input.metadata },
587
+ ...input.files !== void 0 && input.files.length > 0 && { files: input.files },
588
+ ...input.attachments !== void 0 && input.attachments.length > 0 && { attachments: input.attachments }
589
+ };
590
+ if (!loaded && gateOpen()) sendNow.add(entry.id);
591
+ entries = [...entries, entry];
592
+ if (store) {
593
+ persisted.add(entry.id);
594
+ const write = store.put(entry);
595
+ markUnsettled(entry.id, write);
596
+ void write.then(
597
+ (kept) => {
598
+ if (!kept) persisted.delete(entry.id);
599
+ emit({ type: "held", threadId, messageId: entry.id, durable: kept });
600
+ publish();
601
+ },
602
+ () => {
603
+ persisted.delete(entry.id);
604
+ emit({ type: "held", threadId, messageId: entry.id, durable: false });
605
+ publish();
606
+ }
607
+ );
608
+ } else {
609
+ emit({ type: "held", threadId, messageId: entry.id, durable: false });
610
+ }
611
+ evaluate();
612
+ return entry;
613
+ },
614
+ cancel(id) {
615
+ const entry = entries.find((candidate) => candidate.id === id);
616
+ if (!entry || isBusy(phaseOf(id))) return;
617
+ dropEntry(id);
618
+ emit({ type: "cancelled", threadId, messageId: id });
619
+ if (store) void store.remove(threadId, id).catch(() => void 0);
620
+ try {
621
+ restore(entry);
622
+ } finally {
623
+ evaluate();
624
+ }
625
+ },
626
+ send(id) {
627
+ const entry = entries.find((candidate) => candidate.id === id);
628
+ if (!entry || isBusy(phaseOf(id))) return;
629
+ const wasFailed = phaseOf(id).kind === "failed";
630
+ phases.set(id, { kind: "idle" });
631
+ handedInRegain.delete(id);
632
+ sendNow.add(id);
633
+ if (wasFailed && store) {
634
+ const write = store.clearFailure({ threadId, id });
635
+ markUnsettled(id, write);
636
+ void write.catch(() => void 0);
637
+ }
638
+ evaluate();
639
+ },
640
+ discard(id) {
641
+ const entry = entries.find((candidate) => candidate.id === id);
642
+ if (!entry || isBusy(phaseOf(id))) return;
643
+ dropEntry(id);
644
+ emit({ type: "discarded", threadId, messageId: id });
645
+ if (store) void store.remove(threadId, id).catch(() => void 0);
646
+ evaluate();
647
+ },
648
+ observeCommand(update) {
649
+ if (disposed) return;
650
+ const id = chatOutboxCommandMessageId(update.params);
651
+ if (id === null) return;
652
+ const phase = phaseOf(id);
653
+ if (phase.kind === "handed") {
654
+ if (update.status === "queued") {
655
+ phases.set(id, { kind: "handed", journaled: true });
656
+ return;
657
+ }
658
+ letGo(id, { type: "delivered", threadId, messageId: id, status: update.status });
659
+ evaluate();
660
+ return;
661
+ }
662
+ if (entries.some((entry) => entry.id === id)) evaluate();
663
+ },
664
+ openThread: openThread ?? null,
665
+ dispose() {
666
+ if (disposed) return;
667
+ disposed = true;
668
+ stopCountdown();
669
+ leaseTimer == null ? void 0 : leaseTimer();
670
+ for (const stop of checkTimers) stop();
671
+ checkTimers.clear();
672
+ readyToGo.clear();
673
+ for (const unsubscribe of unsubscribers) unsubscribe();
674
+ listeners.clear();
675
+ if (store) {
676
+ for (const [id, phase] of phases) {
677
+ if (phase.kind === "claiming") releaseClaim(id);
678
+ }
679
+ }
680
+ }
681
+ };
682
+ }
683
+ export {
684
+ CHAT_EDIT_KEPT_MESSAGE,
685
+ CHAT_EDIT_UNREACHABLE_LABEL,
686
+ CHAT_OUTBOX_ASK_AFTER_MS,
687
+ CHAT_OUTBOX_ATTACHMENT_CHECK_TIMEOUT_MS,
688
+ CHAT_OUTBOX_CLAIM_LEASE_MS,
689
+ CHAT_OUTBOX_COUNTDOWN_MS,
690
+ ChatEditUnreachableError,
691
+ chatOutboxCommandMessageId,
692
+ chatOutboxFailureMessage,
693
+ createChatOutbox,
694
+ sameChatOutboxSnapshot
695
+ };
696
+ //# sourceMappingURL=chat-outbox.js.map