@athenaintel/react 0.57.2 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (852) hide show
  1. package/README.md +795 -12
  2. package/dist/agent-runtime/src/addressed-agents.cjs +16 -0
  3. package/dist/agent-runtime/src/addressed-agents.cjs.map +1 -0
  4. package/dist/agent-runtime/src/addressed-agents.d.ts +30 -0
  5. package/dist/agent-runtime/src/addressed-agents.js +16 -0
  6. package/dist/agent-runtime/src/addressed-agents.js.map +1 -0
  7. package/dist/agent-runtime/src/answer-label.cjs +4 -3
  8. package/dist/agent-runtime/src/answer-label.cjs.map +1 -1
  9. package/dist/agent-runtime/src/answer-label.d.ts +13 -6
  10. package/dist/agent-runtime/src/answer-label.js +4 -3
  11. package/dist/agent-runtime/src/answer-label.js.map +1 -1
  12. package/dist/agent-runtime/src/chat-outbox-attachments.cjs.map +1 -1
  13. package/dist/agent-runtime/src/chat-outbox-attachments.d.ts +1 -1
  14. package/dist/agent-runtime/src/chat-outbox-attachments.js.map +1 -1
  15. package/dist/agent-runtime/src/chat-outbox-entry.cjs +101 -0
  16. package/dist/agent-runtime/src/chat-outbox-entry.cjs.map +1 -0
  17. package/dist/agent-runtime/src/chat-outbox-entry.d.ts +99 -0
  18. package/dist/agent-runtime/src/chat-outbox-entry.js +101 -0
  19. package/dist/agent-runtime/src/chat-outbox-entry.js.map +1 -0
  20. package/dist/agent-runtime/src/chat-outbox-legacy.cjs +252 -0
  21. package/dist/agent-runtime/src/chat-outbox-legacy.cjs.map +1 -0
  22. package/dist/agent-runtime/src/chat-outbox-legacy.d.ts +96 -0
  23. package/dist/agent-runtime/src/chat-outbox-legacy.js +252 -0
  24. package/dist/agent-runtime/src/chat-outbox-legacy.js.map +1 -0
  25. package/dist/agent-runtime/src/chat-outbox-policy.cjs +30 -0
  26. package/dist/agent-runtime/src/chat-outbox-policy.cjs.map +1 -0
  27. package/dist/agent-runtime/src/chat-outbox-policy.d.ts +42 -0
  28. package/dist/agent-runtime/src/chat-outbox-policy.js +30 -0
  29. package/dist/agent-runtime/src/chat-outbox-policy.js.map +1 -0
  30. package/dist/agent-runtime/src/chat-outbox-storage.cjs +306 -0
  31. package/dist/agent-runtime/src/chat-outbox-storage.cjs.map +1 -0
  32. package/dist/agent-runtime/src/chat-outbox-storage.d.ts +194 -0
  33. package/dist/agent-runtime/src/chat-outbox-storage.js +306 -0
  34. package/dist/agent-runtime/src/chat-outbox-storage.js.map +1 -0
  35. package/dist/agent-runtime/src/chat-outbox-thread.cjs +21 -94
  36. package/dist/agent-runtime/src/chat-outbox-thread.cjs.map +1 -1
  37. package/dist/agent-runtime/src/chat-outbox-thread.d.ts +22 -18
  38. package/dist/agent-runtime/src/chat-outbox-thread.js +21 -94
  39. package/dist/agent-runtime/src/chat-outbox-thread.js.map +1 -1
  40. package/dist/agent-runtime/src/chat-outbox.cjs +492 -547
  41. package/dist/agent-runtime/src/chat-outbox.cjs.map +1 -1
  42. package/dist/agent-runtime/src/chat-outbox.d.ts +110 -142
  43. package/dist/agent-runtime/src/chat-outbox.js +492 -547
  44. package/dist/agent-runtime/src/chat-outbox.js.map +1 -1
  45. package/dist/agent-runtime/src/composer-markdown.cjs +0 -16
  46. package/dist/agent-runtime/src/composer-markdown.cjs.map +1 -1
  47. package/dist/agent-runtime/src/composer-markdown.d.ts +1 -1
  48. package/dist/agent-runtime/src/composer-markdown.js +1 -17
  49. package/dist/agent-runtime/src/composer-markdown.js.map +1 -1
  50. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs +3 -1
  51. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs.map +1 -1
  52. package/dist/agent-runtime/src/deep-agent-transport-recipe.d.ts +8 -1
  53. package/dist/agent-runtime/src/deep-agent-transport-recipe.js +3 -1
  54. package/dist/agent-runtime/src/deep-agent-transport-recipe.js.map +1 -1
  55. package/dist/agent-runtime/src/dictation-preferences.d.ts +356 -0
  56. package/dist/agent-runtime/src/dictation-record.d.ts +279 -0
  57. package/dist/agent-runtime/src/dictation-session.d.ts +106 -7
  58. package/dist/agent-runtime/src/dictation-snippets.d.ts +9 -0
  59. package/dist/agent-runtime/src/dictation-transfer.d.ts +142 -0
  60. package/dist/agent-runtime/src/edit-command.cjs.map +1 -1
  61. package/dist/agent-runtime/src/edit-command.d.ts +1 -1
  62. package/dist/agent-runtime/src/edit-command.js.map +1 -1
  63. package/dist/agent-runtime/src/errors.cjs +1 -0
  64. package/dist/agent-runtime/src/errors.cjs.map +1 -1
  65. package/dist/agent-runtime/src/errors.js +1 -0
  66. package/dist/agent-runtime/src/errors.js.map +1 -1
  67. package/dist/agent-runtime/src/generated/runconfig-contract.cjs +24 -0
  68. package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  69. package/dist/agent-runtime/src/generated/runconfig-contract.d.ts +3 -3
  70. package/dist/agent-runtime/src/generated/runconfig-contract.js +24 -0
  71. package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  72. package/dist/agent-runtime/src/index.d.ts +14 -8
  73. package/dist/agent-runtime/src/lane-follow.cjs +289 -0
  74. package/dist/agent-runtime/src/lane-follow.cjs.map +1 -0
  75. package/dist/agent-runtime/src/lane-follow.js +289 -0
  76. package/dist/agent-runtime/src/lane-follow.js.map +1 -0
  77. package/dist/agent-runtime/src/lane-images.cjs +387 -0
  78. package/dist/agent-runtime/src/lane-images.cjs.map +1 -0
  79. package/dist/agent-runtime/src/lane-images.js +387 -0
  80. package/dist/agent-runtime/src/lane-images.js.map +1 -0
  81. package/dist/agent-runtime/src/message-window.js +1 -1
  82. package/dist/agent-runtime/src/messages.cjs +19 -1
  83. package/dist/agent-runtime/src/messages.cjs.map +1 -1
  84. package/dist/agent-runtime/src/messages.d.ts +8 -0
  85. package/dist/agent-runtime/src/messages.js +21 -3
  86. package/dist/agent-runtime/src/messages.js.map +1 -1
  87. package/dist/agent-runtime/src/named-agents.cjs +301 -0
  88. package/dist/agent-runtime/src/named-agents.cjs.map +1 -0
  89. package/dist/agent-runtime/src/named-agents.d.ts +246 -0
  90. package/dist/agent-runtime/src/named-agents.js +301 -0
  91. package/dist/agent-runtime/src/named-agents.js.map +1 -0
  92. package/dist/agent-runtime/src/offline-status.cjs.map +1 -1
  93. package/dist/agent-runtime/src/offline-status.d.ts +93 -2
  94. package/dist/agent-runtime/src/offline-status.js.map +1 -1
  95. package/dist/agent-runtime/src/ptc-subcalls.cjs +41 -0
  96. package/dist/agent-runtime/src/ptc-subcalls.cjs.map +1 -0
  97. package/dist/agent-runtime/src/ptc-subcalls.js +41 -0
  98. package/dist/agent-runtime/src/ptc-subcalls.js.map +1 -0
  99. package/dist/agent-runtime/src/queue.cjs +2 -2
  100. package/dist/agent-runtime/src/queue.cjs.map +1 -1
  101. package/dist/agent-runtime/src/queue.d.ts +20 -25
  102. package/dist/agent-runtime/src/queue.js +2 -2
  103. package/dist/agent-runtime/src/queue.js.map +1 -1
  104. package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs +314 -84
  105. package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs.map +1 -1
  106. package/dist/agent-runtime/src/quota-safe-local-storage-session.d.ts +137 -40
  107. package/dist/agent-runtime/src/quota-safe-local-storage-session.js +318 -88
  108. package/dist/agent-runtime/src/quota-safe-local-storage-session.js.map +1 -1
  109. package/dist/agent-runtime/src/run-send.cjs +54 -0
  110. package/dist/agent-runtime/src/run-send.cjs.map +1 -0
  111. package/dist/agent-runtime/src/run-send.d.ts +51 -0
  112. package/dist/agent-runtime/src/run-send.js +54 -0
  113. package/dist/agent-runtime/src/run-send.js.map +1 -0
  114. package/dist/agent-runtime/src/running-tool-placeholder.cjs +6 -0
  115. package/dist/agent-runtime/src/running-tool-placeholder.cjs.map +1 -1
  116. package/dist/agent-runtime/src/running-tool-placeholder.js +6 -0
  117. package/dist/agent-runtime/src/running-tool-placeholder.js.map +1 -1
  118. package/dist/agent-runtime/src/runtime.d.ts +9 -5
  119. package/dist/agent-runtime/src/sealed-idb.cjs +64 -0
  120. package/dist/agent-runtime/src/sealed-idb.cjs.map +1 -1
  121. package/dist/agent-runtime/src/sealed-idb.d.ts +16 -0
  122. package/dist/agent-runtime/src/sealed-idb.js +64 -0
  123. package/dist/agent-runtime/src/sealed-idb.js.map +1 -1
  124. package/dist/agent-runtime/src/send-recovery.cjs +90 -118
  125. package/dist/agent-runtime/src/send-recovery.cjs.map +1 -1
  126. package/dist/agent-runtime/src/send-recovery.d.ts +25 -29
  127. package/dist/agent-runtime/src/send-recovery.js +90 -118
  128. package/dist/agent-runtime/src/send-recovery.js.map +1 -1
  129. package/dist/agent-runtime/src/statewire-diagnostics.d.ts +4 -1
  130. package/dist/agent-runtime/src/statewire-held-sends.cjs +191 -0
  131. package/dist/agent-runtime/src/statewire-held-sends.cjs.map +1 -0
  132. package/dist/agent-runtime/src/statewire-held-sends.d.ts +119 -0
  133. package/dist/agent-runtime/src/statewire-held-sends.js +191 -0
  134. package/dist/agent-runtime/src/statewire-held-sends.js.map +1 -0
  135. package/dist/agent-runtime/src/statewire-state.cjs +4 -0
  136. package/dist/agent-runtime/src/statewire-state.cjs.map +1 -1
  137. package/dist/agent-runtime/src/statewire-state.js +4 -0
  138. package/dist/agent-runtime/src/statewire-state.js.map +1 -1
  139. package/dist/agent-runtime/src/statewire-transport.cjs +8 -2
  140. package/dist/agent-runtime/src/statewire-transport.cjs.map +1 -1
  141. package/dist/agent-runtime/src/statewire-transport.d.ts +14 -5
  142. package/dist/agent-runtime/src/statewire-transport.js +8 -2
  143. package/dist/agent-runtime/src/statewire-transport.js.map +1 -1
  144. package/dist/agent-runtime/src/subagent-transcripts.cjs +1 -23
  145. package/dist/agent-runtime/src/subagent-transcripts.cjs.map +1 -1
  146. package/dist/agent-runtime/src/subagent-transcripts.js +3 -25
  147. package/dist/agent-runtime/src/subagent-transcripts.js.map +1 -1
  148. package/dist/agent-runtime/src/subagents.cjs +22 -29
  149. package/dist/agent-runtime/src/subagents.cjs.map +1 -1
  150. package/dist/agent-runtime/src/subagents.js +23 -30
  151. package/dist/agent-runtime/src/subagents.js.map +1 -1
  152. package/dist/agent-runtime/src/thread-extras.cjs +27 -19
  153. package/dist/agent-runtime/src/thread-extras.cjs.map +1 -1
  154. package/dist/agent-runtime/src/thread-extras.d.ts +19 -6
  155. package/dist/agent-runtime/src/thread-extras.js +27 -19
  156. package/dist/agent-runtime/src/thread-extras.js.map +1 -1
  157. package/dist/agent-runtime/src/thread-handoff-flow-machine.d.ts +8 -8
  158. package/dist/agent-runtime/src/tool-metadata.cjs +19 -0
  159. package/dist/agent-runtime/src/tool-metadata.cjs.map +1 -1
  160. package/dist/agent-runtime/src/tool-metadata.js +19 -0
  161. package/dist/agent-runtime/src/tool-metadata.js.map +1 -1
  162. package/dist/agent-runtime/src/tool-names.cjs +21 -0
  163. package/dist/agent-runtime/src/tool-names.cjs.map +1 -1
  164. package/dist/agent-runtime/src/tool-names.d.ts +8 -0
  165. package/dist/agent-runtime/src/tool-names.js +21 -0
  166. package/dist/agent-runtime/src/tool-names.js.map +1 -1
  167. package/dist/agent-runtime/src/typed-interrupt-kinds.cjs +247 -0
  168. package/dist/agent-runtime/src/typed-interrupt-kinds.cjs.map +1 -0
  169. package/dist/agent-runtime/src/typed-interrupt-kinds.d.ts +173 -0
  170. package/dist/agent-runtime/src/typed-interrupt-kinds.js +247 -0
  171. package/dist/agent-runtime/src/typed-interrupt-kinds.js.map +1 -0
  172. package/dist/agent-runtime/src/typed-interrupts.cjs +48 -0
  173. package/dist/agent-runtime/src/typed-interrupts.cjs.map +1 -0
  174. package/dist/agent-runtime/src/typed-interrupts.d.ts +75 -0
  175. package/dist/agent-runtime/src/typed-interrupts.js +48 -0
  176. package/dist/agent-runtime/src/typed-interrupts.js.map +1 -0
  177. package/dist/agent-runtime/src/types.d.ts +1 -1
  178. package/dist/agent-runtime/src/use-conversation-list.cjs +1 -0
  179. package/dist/agent-runtime/src/use-conversation-list.cjs.map +1 -1
  180. package/dist/agent-runtime/src/use-conversation-list.d.ts +7 -0
  181. package/dist/agent-runtime/src/use-conversation-list.js +1 -0
  182. package/dist/agent-runtime/src/use-conversation-list.js.map +1 -1
  183. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +46 -29
  184. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -1
  185. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +14 -22
  186. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +46 -29
  187. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -1
  188. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +78 -14
  189. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  190. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +34 -7
  191. package/dist/agent-runtime/src/use-deep-agent-runtime.js +79 -15
  192. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  193. package/dist/agent-runtime/src/use-deep-agent-thread.cjs +16 -1
  194. package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
  195. package/dist/agent-runtime/src/use-deep-agent-thread.d.ts +7 -2
  196. package/dist/agent-runtime/src/use-deep-agent-thread.js +16 -1
  197. package/dist/agent-runtime/src/use-deep-agent-thread.js.map +1 -1
  198. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +30 -4
  199. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -1
  200. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +22 -4
  201. package/dist/agent-runtime/src/use-deep-agent-voice.js +30 -4
  202. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -1
  203. package/dist/agent-runtime/src/withdrawn-turns.d.ts +5 -4
  204. package/dist/agent-runtime/src/word-device-fit.d.ts +174 -0
  205. package/dist/agent-runtime/src/work-in.d.ts +127 -0
  206. package/dist/assets/AthenaAssetEmbed.cjs.map +1 -1
  207. package/dist/assets/AthenaAssetEmbed.d.ts +6 -1
  208. package/dist/assets/AthenaAssetEmbed.js.map +1 -1
  209. package/dist/assets/asset-panel-store.cjs +13 -5
  210. package/dist/assets/asset-panel-store.cjs.map +1 -1
  211. package/dist/assets/asset-panel-store.d.ts +33 -2
  212. package/dist/assets/asset-panel-store.js +13 -5
  213. package/dist/assets/asset-panel-store.js.map +1 -1
  214. package/dist/auth/AthenaCredentialSourceContext.cjs +11 -0
  215. package/dist/auth/AthenaCredentialSourceContext.cjs.map +1 -1
  216. package/dist/auth/AthenaCredentialSourceContext.d.ts +6 -0
  217. package/dist/auth/AthenaCredentialSourceContext.js +11 -0
  218. package/dist/auth/AthenaCredentialSourceContext.js.map +1 -1
  219. package/dist/auth/account-identity.cjs +13 -2
  220. package/dist/auth/account-identity.cjs.map +1 -1
  221. package/dist/auth/account-identity.d.ts +9 -0
  222. package/dist/auth/account-identity.js +13 -2
  223. package/dist/auth/account-identity.js.map +1 -1
  224. package/dist/auth/credential-source.cjs +20 -4
  225. package/dist/auth/credential-source.cjs.map +1 -1
  226. package/dist/auth/credential-source.d.ts +9 -0
  227. package/dist/auth/credential-source.js +20 -4
  228. package/dist/auth/credential-source.js.map +1 -1
  229. package/dist/catalog/chat-pickers.cjs +31 -0
  230. package/dist/catalog/chat-pickers.cjs.map +1 -1
  231. package/dist/catalog/chat-pickers.d.ts +17 -0
  232. package/dist/catalog/chat-pickers.js +33 -2
  233. package/dist/catalog/chat-pickers.js.map +1 -1
  234. package/dist/catalog/runtime-catalog.cjs +63 -3
  235. package/dist/catalog/runtime-catalog.cjs.map +1 -1
  236. package/dist/catalog/runtime-catalog.d.ts +63 -3
  237. package/dist/catalog/runtime-catalog.js +64 -4
  238. package/dist/catalog/runtime-catalog.js.map +1 -1
  239. package/dist/chat/AthenaChat.cjs +301 -98
  240. package/dist/chat/AthenaChat.cjs.map +1 -1
  241. package/dist/chat/AthenaChat.d.ts +80 -4
  242. package/dist/chat/AthenaChat.js +302 -99
  243. package/dist/chat/AthenaChat.js.map +1 -1
  244. package/dist/chat/StatewireApprovalCard.cjs +35 -5
  245. package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
  246. package/dist/chat/StatewireApprovalCard.d.ts +55 -2
  247. package/dist/chat/StatewireApprovalCard.js +37 -7
  248. package/dist/chat/StatewireApprovalCard.js.map +1 -1
  249. package/dist/chat/StatewireQueuedMessages.cjs +17 -2
  250. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  251. package/dist/chat/StatewireQueuedMessages.d.ts +8 -45
  252. package/dist/chat/StatewireQueuedMessages.js +18 -3
  253. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  254. package/dist/chat/chat-agent-mentions.cjs +70 -0
  255. package/dist/chat/chat-agent-mentions.cjs.map +1 -0
  256. package/dist/chat/chat-agent-mentions.d.ts +13 -0
  257. package/dist/chat/chat-agent-mentions.js +70 -0
  258. package/dist/chat/chat-agent-mentions.js.map +1 -0
  259. package/dist/chat/composer-actions.cjs +12 -0
  260. package/dist/chat/composer-actions.cjs.map +1 -0
  261. package/dist/chat/composer-actions.d.ts +22 -0
  262. package/dist/chat/composer-actions.js +12 -0
  263. package/dist/chat/composer-actions.js.map +1 -0
  264. package/dist/chat/follow-up-suggestions.cjs +185 -0
  265. package/dist/chat/follow-up-suggestions.cjs.map +1 -0
  266. package/dist/chat/follow-up-suggestions.d.ts +64 -0
  267. package/dist/chat/follow-up-suggestions.js +185 -0
  268. package/dist/chat/follow-up-suggestions.js.map +1 -0
  269. package/dist/chat/super-grouping/ToolTimeline.cjs +4 -3
  270. package/dist/chat/super-grouping/ToolTimeline.cjs.map +1 -1
  271. package/dist/chat/super-grouping/ToolTimeline.d.ts +7 -3
  272. package/dist/chat/super-grouping/ToolTimeline.js +4 -3
  273. package/dist/chat/super-grouping/ToolTimeline.js.map +1 -1
  274. package/dist/chat/turn-changes.cjs +284 -0
  275. package/dist/chat/turn-changes.cjs.map +1 -0
  276. package/dist/chat/turn-changes.d.ts +130 -0
  277. package/dist/chat/turn-changes.js +284 -0
  278. package/dist/chat/turn-changes.js.map +1 -0
  279. package/dist/chat/typed-interrupts/StatewireTypedInterruptCard.cjs +31 -0
  280. package/dist/chat/typed-interrupts/StatewireTypedInterruptCard.cjs.map +1 -0
  281. package/dist/chat/typed-interrupts/StatewireTypedInterruptCard.d.ts +31 -0
  282. package/dist/chat/typed-interrupts/StatewireTypedInterruptCard.js +31 -0
  283. package/dist/chat/typed-interrupts/StatewireTypedInterruptCard.js.map +1 -0
  284. package/dist/chat/typed-interrupts/approval-cards.cjs +250 -0
  285. package/dist/chat/typed-interrupts/approval-cards.cjs.map +1 -0
  286. package/dist/chat/typed-interrupts/approval-cards.d.ts +22 -0
  287. package/dist/chat/typed-interrupts/approval-cards.js +250 -0
  288. package/dist/chat/typed-interrupts/approval-cards.js.map +1 -0
  289. package/dist/chat/typed-interrupts/form-cards.cjs +289 -0
  290. package/dist/chat/typed-interrupts/form-cards.cjs.map +1 -0
  291. package/dist/chat/typed-interrupts/form-cards.d.ts +6 -0
  292. package/dist/chat/typed-interrupts/form-cards.js +289 -0
  293. package/dist/chat/typed-interrupts/form-cards.js.map +1 -0
  294. package/dist/chat/typed-interrupts/interrupt-card-shell.cjs +182 -0
  295. package/dist/chat/typed-interrupts/interrupt-card-shell.cjs.map +1 -0
  296. package/dist/chat/typed-interrupts/interrupt-card-shell.d.ts +47 -0
  297. package/dist/chat/typed-interrupts/interrupt-card-shell.js +182 -0
  298. package/dist/chat/typed-interrupts/interrupt-card-shell.js.map +1 -0
  299. package/dist/chat/typed-interrupts/json-schema-form.cjs +388 -0
  300. package/dist/chat/typed-interrupts/json-schema-form.cjs.map +1 -0
  301. package/dist/chat/typed-interrupts/json-schema-form.d.ts +33 -0
  302. package/dist/chat/typed-interrupts/json-schema-form.js +388 -0
  303. package/dist/chat/typed-interrupts/json-schema-form.js.map +1 -0
  304. package/dist/chat/typed-interrupts/questionnaire-card.cjs +449 -0
  305. package/dist/chat/typed-interrupts/questionnaire-card.cjs.map +1 -0
  306. package/dist/chat/typed-interrupts/questionnaire-card.d.ts +20 -0
  307. package/dist/chat/typed-interrupts/questionnaire-card.js +449 -0
  308. package/dist/chat/typed-interrupts/questionnaire-card.js.map +1 -0
  309. package/dist/chat/typed-interrupts/request-file-card.cjs +159 -0
  310. package/dist/chat/typed-interrupts/request-file-card.cjs.map +1 -0
  311. package/dist/chat/typed-interrupts/request-file-card.d.ts +2 -0
  312. package/dist/chat/typed-interrupts/request-file-card.js +159 -0
  313. package/dist/chat/typed-interrupts/request-file-card.js.map +1 -0
  314. package/dist/chat/typed-interrupts/toolkit-selection-card.cjs +189 -0
  315. package/dist/chat/typed-interrupts/toolkit-selection-card.cjs.map +1 -0
  316. package/dist/chat/typed-interrupts/toolkit-selection-card.d.ts +23 -0
  317. package/dist/chat/typed-interrupts/toolkit-selection-card.js +189 -0
  318. package/dist/chat/typed-interrupts/toolkit-selection-card.js.map +1 -0
  319. package/dist/chat/typed-interrupts/typed-interrupt-body.cjs +26 -0
  320. package/dist/chat/typed-interrupts/typed-interrupt-body.cjs.map +1 -0
  321. package/dist/chat/typed-interrupts/typed-interrupt-body.d.ts +3 -0
  322. package/dist/chat/typed-interrupts/typed-interrupt-body.js +26 -0
  323. package/dist/chat/typed-interrupts/typed-interrupt-body.js.map +1 -0
  324. package/dist/chat/typed-interrupts/typed-interrupt-graphql.cjs +105 -0
  325. package/dist/chat/typed-interrupts/typed-interrupt-graphql.cjs.map +1 -0
  326. package/dist/chat/typed-interrupts/typed-interrupt-graphql.d.ts +29 -0
  327. package/dist/chat/typed-interrupts/typed-interrupt-graphql.js +105 -0
  328. package/dist/chat/typed-interrupts/typed-interrupt-graphql.js.map +1 -0
  329. package/dist/chat/typed-interrupts/typed-interrupt-notice.cjs +70 -0
  330. package/dist/chat/typed-interrupts/typed-interrupt-notice.cjs.map +1 -0
  331. package/dist/chat/typed-interrupts/typed-interrupt-notice.d.ts +45 -0
  332. package/dist/chat/typed-interrupts/typed-interrupt-notice.js +70 -0
  333. package/dist/chat/typed-interrupts/typed-interrupt-notice.js.map +1 -0
  334. package/dist/chat/typed-interrupts/typed-interrupt-panel.cjs +76 -0
  335. package/dist/chat/typed-interrupts/typed-interrupt-panel.cjs.map +1 -0
  336. package/dist/chat/typed-interrupts/typed-interrupt-panel.d.ts +11 -0
  337. package/dist/chat/typed-interrupts/typed-interrupt-panel.js +76 -0
  338. package/dist/chat/typed-interrupts/typed-interrupt-panel.js.map +1 -0
  339. package/dist/chat/typed-interrupts/typed-interrupt-types.d.ts +46 -0
  340. package/dist/chat/typed-interrupts/use-interrupt-draft.cjs +106 -0
  341. package/dist/chat/typed-interrupts/use-interrupt-draft.cjs.map +1 -0
  342. package/dist/chat/typed-interrupts/use-interrupt-draft.d.ts +29 -0
  343. package/dist/chat/typed-interrupts/use-interrupt-draft.js +106 -0
  344. package/dist/chat/typed-interrupts/use-interrupt-draft.js.map +1 -0
  345. package/dist/chat/typed-interrupts/use-statewire-typed-interrupt.cjs +231 -0
  346. package/dist/chat/typed-interrupts/use-statewire-typed-interrupt.cjs.map +1 -0
  347. package/dist/chat/typed-interrupts/use-statewire-typed-interrupt.d.ts +66 -0
  348. package/dist/chat/typed-interrupts/use-statewire-typed-interrupt.js +231 -0
  349. package/dist/chat/typed-interrupts/use-statewire-typed-interrupt.js.map +1 -0
  350. package/dist/chat-ui/composer/composer-named-agents.cjs +13 -0
  351. package/dist/chat-ui/composer/composer-named-agents.cjs.map +1 -0
  352. package/dist/chat-ui/composer/composer-named-agents.d.ts +20 -0
  353. package/dist/chat-ui/composer/composer-named-agents.js +13 -0
  354. package/dist/chat-ui/composer/composer-named-agents.js.map +1 -0
  355. package/dist/chat-ui/composer/slash-command-menu.cjs +143 -0
  356. package/dist/chat-ui/composer/slash-command-menu.cjs.map +1 -0
  357. package/dist/chat-ui/composer/slash-command-menu.d.ts +19 -0
  358. package/dist/chat-ui/composer/slash-command-menu.js +143 -0
  359. package/dist/chat-ui/composer/slash-command-menu.js.map +1 -0
  360. package/dist/chat-ui/composer/slash-commands-extension.cjs +51 -0
  361. package/dist/chat-ui/composer/slash-commands-extension.cjs.map +1 -0
  362. package/dist/chat-ui/composer/slash-commands-extension.d.ts +39 -0
  363. package/dist/chat-ui/composer/slash-commands-extension.js +51 -0
  364. package/dist/chat-ui/composer/slash-commands-extension.js.map +1 -0
  365. package/dist/chat-ui/composer/slash-commands.cjs +74 -0
  366. package/dist/chat-ui/composer/slash-commands.cjs.map +1 -0
  367. package/dist/chat-ui/composer/slash-commands.d.ts +82 -0
  368. package/dist/chat-ui/composer/slash-commands.js +74 -0
  369. package/dist/chat-ui/composer/slash-commands.js.map +1 -0
  370. package/dist/chat-ui/composer/tiptap-composer.cjs +135 -9
  371. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  372. package/dist/chat-ui/composer/tiptap-composer.d.ts +61 -2
  373. package/dist/chat-ui/composer/tiptap-composer.js +135 -9
  374. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  375. package/dist/chat-ui/index.cjs +5 -0
  376. package/dist/chat-ui/index.cjs.map +1 -1
  377. package/dist/chat-ui/index.d.ts +4 -2
  378. package/dist/chat-ui/index.js +5 -0
  379. package/dist/chat-ui/index.js.map +1 -1
  380. package/dist/chat-ui/mentions/mention-chip.cjs +10 -4
  381. package/dist/chat-ui/mentions/mention-chip.cjs.map +1 -1
  382. package/dist/chat-ui/mentions/mention-chip.js +11 -5
  383. package/dist/chat-ui/mentions/mention-chip.js.map +1 -1
  384. package/dist/chat-ui/mentions/mention-extension.cjs +8 -1
  385. package/dist/chat-ui/mentions/mention-extension.cjs.map +1 -1
  386. package/dist/chat-ui/mentions/mention-extension.js +8 -1
  387. package/dist/chat-ui/mentions/mention-extension.js.map +1 -1
  388. package/dist/chat-ui/mentions/suggestions/components/get-scope-name.cjs +1 -0
  389. package/dist/chat-ui/mentions/suggestions/components/get-scope-name.cjs.map +1 -1
  390. package/dist/chat-ui/mentions/suggestions/components/get-scope-name.js +1 -0
  391. package/dist/chat-ui/mentions/suggestions/components/get-scope-name.js.map +1 -1
  392. package/dist/chat-ui/mentions/suggestions/components/mention-icon.cjs +20 -2
  393. package/dist/chat-ui/mentions/suggestions/components/mention-icon.cjs.map +1 -1
  394. package/dist/chat-ui/mentions/suggestions/components/mention-icon.d.ts +10 -1
  395. package/dist/chat-ui/mentions/suggestions/components/mention-icon.js +22 -4
  396. package/dist/chat-ui/mentions/suggestions/components/mention-icon.js.map +1 -1
  397. package/dist/chat-ui/mentions/suggestions/components/menu-item.cjs +1 -1
  398. package/dist/chat-ui/mentions/suggestions/components/menu-item.cjs.map +1 -1
  399. package/dist/chat-ui/mentions/suggestions/components/menu-item.js +1 -1
  400. package/dist/chat-ui/mentions/suggestions/components/menu-item.js.map +1 -1
  401. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs +45 -0
  402. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs.map +1 -1
  403. package/dist/chat-ui/mentions/suggestions/data/api-client.d.ts +48 -0
  404. package/dist/chat-ui/mentions/suggestions/data/api-client.js +45 -0
  405. package/dist/chat-ui/mentions/suggestions/data/api-client.js.map +1 -1
  406. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icon-names.generated.cjs +89 -0
  407. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icon-names.generated.cjs.map +1 -0
  408. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icon-names.generated.d.ts +8 -0
  409. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icon-names.generated.js +89 -0
  410. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icon-names.generated.js.map +1 -0
  411. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.cjs +140 -116
  412. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.cjs.map +1 -1
  413. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.d.ts +46 -12
  414. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.js +141 -117
  415. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.js.map +1 -1
  416. package/dist/chat-ui/mentions/suggestions/data/sources/index.cjs +272 -25
  417. package/dist/chat-ui/mentions/suggestions/data/sources/index.cjs.map +1 -1
  418. package/dist/chat-ui/mentions/suggestions/data/sources/index.d.ts +88 -10
  419. package/dist/chat-ui/mentions/suggestions/data/sources/index.js +274 -27
  420. package/dist/chat-ui/mentions/suggestions/data/sources/index.js.map +1 -1
  421. package/dist/chat-ui/mentions/suggestions/data/types.cjs.map +1 -1
  422. package/dist/chat-ui/mentions/suggestions/data/types.d.ts +27 -1
  423. package/dist/chat-ui/mentions/suggestions/data/types.js.map +1 -1
  424. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.cjs +56 -5
  425. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.cjs.map +1 -1
  426. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.d.ts +26 -6
  427. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.js +57 -6
  428. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.js.map +1 -1
  429. package/dist/chat-ui/mentions/suggestions/mention-suggestions.extension.cjs +34 -17
  430. package/dist/chat-ui/mentions/suggestions/mention-suggestions.extension.cjs.map +1 -1
  431. package/dist/chat-ui/mentions/suggestions/mention-suggestions.extension.d.ts +19 -1
  432. package/dist/chat-ui/mentions/suggestions/mention-suggestions.extension.js +35 -18
  433. package/dist/chat-ui/mentions/suggestions/mention-suggestions.extension.js.map +1 -1
  434. package/dist/chat-ui/mentions/use-asset-icon-app-url.cjs +12 -0
  435. package/dist/chat-ui/mentions/use-asset-icon-app-url.cjs.map +1 -0
  436. package/dist/chat-ui/mentions/use-asset-icon-app-url.d.ts +8 -0
  437. package/dist/chat-ui/mentions/use-asset-icon-app-url.js +12 -0
  438. package/dist/chat-ui/mentions/use-asset-icon-app-url.js.map +1 -0
  439. package/dist/chat-ui/statewire.d.ts +1 -1
  440. package/dist/chat-ui/thread/statewire-history-edge.cjs +15 -0
  441. package/dist/chat-ui/thread/statewire-history-edge.cjs.map +1 -1
  442. package/dist/chat-ui/thread/statewire-history-edge.d.ts +4 -1
  443. package/dist/chat-ui/thread/statewire-history-edge.js +15 -0
  444. package/dist/chat-ui/thread/statewire-history-edge.js.map +1 -1
  445. package/dist/collab/client.cjs +41 -6
  446. package/dist/collab/client.cjs.map +1 -1
  447. package/dist/collab/client.d.ts +38 -7
  448. package/dist/collab/client.js +41 -6
  449. package/dist/collab/client.js.map +1 -1
  450. package/dist/composer/ComposerAttachedReferences.cjs +119 -0
  451. package/dist/composer/ComposerAttachedReferences.cjs.map +1 -0
  452. package/dist/composer/ComposerAttachedReferences.d.ts +26 -0
  453. package/dist/composer/ComposerAttachedReferences.js +119 -0
  454. package/dist/composer/ComposerAttachedReferences.js.map +1 -0
  455. package/dist/composer/ComposerNamedAgents.cjs +63 -0
  456. package/dist/composer/ComposerNamedAgents.cjs.map +1 -0
  457. package/dist/composer/ComposerNamedAgents.d.ts +16 -0
  458. package/dist/composer/ComposerNamedAgents.js +63 -0
  459. package/dist/composer/ComposerNamedAgents.js.map +1 -0
  460. package/dist/composer/attached-references.cjs +159 -0
  461. package/dist/composer/attached-references.cjs.map +1 -0
  462. package/dist/composer/attached-references.d.ts +86 -0
  463. package/dist/composer/attached-references.js +159 -0
  464. package/dist/composer/attached-references.js.map +1 -0
  465. package/dist/composer/build-composed-message.cjs +14 -7
  466. package/dist/composer/build-composed-message.cjs.map +1 -1
  467. package/dist/composer/build-composed-message.d.ts +6 -1
  468. package/dist/composer/build-composed-message.js +14 -7
  469. package/dist/composer/build-composed-message.js.map +1 -1
  470. package/dist/composer/composer-handoff.cjs +6 -2
  471. package/dist/composer/composer-handoff.cjs.map +1 -1
  472. package/dist/composer/composer-handoff.d.ts +7 -1
  473. package/dist/composer/composer-handoff.js +6 -2
  474. package/dist/composer/composer-handoff.js.map +1 -1
  475. package/dist/composer/folder-upload.cjs +149 -0
  476. package/dist/composer/folder-upload.cjs.map +1 -0
  477. package/dist/composer/folder-upload.d.ts +79 -0
  478. package/dist/composer/folder-upload.js +149 -0
  479. package/dist/composer/folder-upload.js.map +1 -0
  480. package/dist/composer/index.d.ts +1 -1
  481. package/dist/composer/staged-message-metadata.cjs +12 -0
  482. package/dist/composer/staged-message-metadata.cjs.map +1 -0
  483. package/dist/composer/staged-message-metadata.d.ts +15 -0
  484. package/dist/composer/staged-message-metadata.js +12 -0
  485. package/dist/composer/staged-message-metadata.js.map +1 -0
  486. package/dist/composer/useAttachToChat.cjs +35 -0
  487. package/dist/composer/useAttachToChat.cjs.map +1 -0
  488. package/dist/composer/useAttachToChat.d.ts +54 -0
  489. package/dist/composer/useAttachToChat.js +35 -0
  490. package/dist/composer/useAttachToChat.js.map +1 -0
  491. package/dist/composer/useAttachedReferencesComposerProps.cjs +19 -0
  492. package/dist/composer/useAttachedReferencesComposerProps.cjs.map +1 -0
  493. package/dist/composer/useAttachedReferencesComposerProps.d.ts +12 -0
  494. package/dist/composer/useAttachedReferencesComposerProps.js +19 -0
  495. package/dist/composer/useAttachedReferencesComposerProps.js.map +1 -0
  496. package/dist/composer/useFileUpload.cjs +95 -7
  497. package/dist/composer/useFileUpload.cjs.map +1 -1
  498. package/dist/composer/useFileUpload.d.ts +21 -2
  499. package/dist/composer/useFileUpload.js +95 -7
  500. package/dist/composer/useFileUpload.js.map +1 -1
  501. package/dist/data/athena-api-error.cjs +125 -0
  502. package/dist/data/athena-api-error.cjs.map +1 -0
  503. package/dist/data/athena-api-error.d.ts +96 -0
  504. package/dist/data/athena-api-error.js +125 -0
  505. package/dist/data/athena-api-error.js.map +1 -0
  506. package/dist/data/athena-data-client.cjs +106 -0
  507. package/dist/data/athena-data-client.cjs.map +1 -0
  508. package/dist/data/athena-data-client.d.ts +74 -0
  509. package/dist/data/athena-data-client.js +106 -0
  510. package/dist/data/athena-data-client.js.map +1 -0
  511. package/dist/data/athena-member.cjs +93 -0
  512. package/dist/data/athena-member.cjs.map +1 -0
  513. package/dist/data/athena-member.d.ts +125 -0
  514. package/dist/data/athena-member.js +93 -0
  515. package/dist/data/athena-member.js.map +1 -0
  516. package/dist/data/athena-request.cjs +460 -0
  517. package/dist/data/athena-request.cjs.map +1 -0
  518. package/dist/data/athena-request.d.ts +120 -0
  519. package/dist/data/athena-request.js +460 -0
  520. package/dist/data/athena-request.js.map +1 -0
  521. package/dist/data/use-athena-fetch.cjs +14 -0
  522. package/dist/data/use-athena-fetch.cjs.map +1 -0
  523. package/dist/data/use-athena-fetch.d.ts +19 -0
  524. package/dist/data/use-athena-fetch.js +14 -0
  525. package/dist/data/use-athena-fetch.js.map +1 -0
  526. package/dist/data/use-athena-graphql.cjs +66 -0
  527. package/dist/data/use-athena-graphql.cjs.map +1 -0
  528. package/dist/data/use-athena-graphql.d.ts +56 -0
  529. package/dist/data/use-athena-graphql.js +66 -0
  530. package/dist/data/use-athena-graphql.js.map +1 -0
  531. package/dist/data/use-athena-rest.cjs +33 -0
  532. package/dist/data/use-athena-rest.cjs.map +1 -0
  533. package/dist/data/use-athena-rest.d.ts +21 -0
  534. package/dist/data/use-athena-rest.js +33 -0
  535. package/dist/data/use-athena-rest.js.map +1 -0
  536. package/dist/data/use-semantic-query.cjs +44 -0
  537. package/dist/data/use-semantic-query.cjs.map +1 -0
  538. package/dist/data/use-semantic-query.d.ts +92 -0
  539. package/dist/data/use-semantic-query.js +44 -0
  540. package/dist/data/use-semantic-query.js.map +1 -0
  541. package/dist/diagnostics/athena-diagnostics.cjs.map +1 -1
  542. package/dist/diagnostics/athena-diagnostics.d.ts +5 -1
  543. package/dist/diagnostics/athena-diagnostics.js.map +1 -1
  544. package/dist/diagnostics/errors.cjs +7 -0
  545. package/dist/diagnostics/errors.cjs.map +1 -1
  546. package/dist/diagnostics/errors.d.ts +7 -0
  547. package/dist/diagnostics/errors.js +7 -0
  548. package/dist/diagnostics/errors.js.map +1 -1
  549. package/dist/index.cjs +155 -11
  550. package/dist/index.cjs.map +1 -1
  551. package/dist/index.d.ts +72 -13
  552. package/dist/index.js +148 -4
  553. package/dist/index.js.map +1 -1
  554. package/dist/keryx-http/src/initial-sync.cjs +64 -16
  555. package/dist/keryx-http/src/initial-sync.cjs.map +1 -1
  556. package/dist/keryx-http/src/initial-sync.d.ts +31 -1
  557. package/dist/keryx-http/src/initial-sync.js +64 -16
  558. package/dist/keryx-http/src/initial-sync.js.map +1 -1
  559. package/dist/keryx-http/src/own-awareness.cjs +20 -0
  560. package/dist/keryx-http/src/own-awareness.cjs.map +1 -0
  561. package/dist/keryx-http/src/own-awareness.d.ts +50 -0
  562. package/dist/keryx-http/src/own-awareness.js +20 -0
  563. package/dist/keryx-http/src/own-awareness.js.map +1 -0
  564. package/dist/keryx-http/src/update-attributions.cjs +26 -1
  565. package/dist/keryx-http/src/update-attributions.cjs.map +1 -1
  566. package/dist/keryx-http/src/update-attributions.d.ts +10 -1
  567. package/dist/keryx-http/src/update-attributions.js +26 -1
  568. package/dist/keryx-http/src/update-attributions.js.map +1 -1
  569. package/dist/offline/chat-outbox.cjs +262 -26
  570. package/dist/offline/chat-outbox.cjs.map +1 -1
  571. package/dist/offline/chat-outbox.d.ts +90 -12
  572. package/dist/offline/chat-outbox.js +263 -27
  573. package/dist/offline/chat-outbox.js.map +1 -1
  574. package/dist/provider/AthenaProvider.cjs +60 -22
  575. package/dist/provider/AthenaProvider.cjs.map +1 -1
  576. package/dist/provider/AthenaProvider.d.ts +24 -8
  577. package/dist/provider/AthenaProvider.js +61 -23
  578. package/dist/provider/AthenaProvider.js.map +1 -1
  579. package/dist/react/package.json.cjs +1 -1
  580. package/dist/react/package.json.js +1 -1
  581. package/dist/references/src/anchors/parse.cjs +11 -1
  582. package/dist/references/src/anchors/parse.cjs.map +1 -1
  583. package/dist/references/src/anchors/parse.js +11 -1
  584. package/dist/references/src/anchors/parse.js.map +1 -1
  585. package/dist/references/src/anchors/schemas.d.ts +1 -0
  586. package/dist/references/src/anchors/serialize.cjs +1 -0
  587. package/dist/references/src/anchors/serialize.cjs.map +1 -1
  588. package/dist/references/src/anchors/serialize.js +1 -0
  589. package/dist/references/src/anchors/serialize.js.map +1 -1
  590. package/dist/references/src/anchors/types.cjs +5 -0
  591. package/dist/references/src/anchors/types.cjs.map +1 -1
  592. package/dist/references/src/anchors/types.d.ts +9 -0
  593. package/dist/references/src/anchors/types.js +5 -0
  594. package/dist/references/src/anchors/types.js.map +1 -1
  595. package/dist/references/src/attachable.cjs +149 -0
  596. package/dist/references/src/attachable.cjs.map +1 -0
  597. package/dist/references/src/attachable.d.ts +87 -0
  598. package/dist/references/src/attachable.js +149 -0
  599. package/dist/references/src/attachable.js.map +1 -0
  600. package/dist/references/src/schemas.d.ts +2 -0
  601. package/dist/runtime/StatewirePlanModeLaneSync.cjs +93 -0
  602. package/dist/runtime/StatewirePlanModeLaneSync.cjs.map +1 -0
  603. package/dist/runtime/StatewirePlanModeLaneSync.d.ts +34 -0
  604. package/dist/runtime/StatewirePlanModeLaneSync.js +93 -0
  605. package/dist/runtime/StatewirePlanModeLaneSync.js.map +1 -0
  606. package/dist/runtime/StatewireThreadConfigLaneSync.cjs +2 -0
  607. package/dist/runtime/StatewireThreadConfigLaneSync.cjs.map +1 -1
  608. package/dist/runtime/StatewireThreadConfigLaneSync.d.ts +4 -0
  609. package/dist/runtime/StatewireThreadConfigLaneSync.js +2 -0
  610. package/dist/runtime/StatewireThreadConfigLaneSync.js.map +1 -1
  611. package/dist/runtime/statewire-plan-mode.cjs +71 -0
  612. package/dist/runtime/statewire-plan-mode.cjs.map +1 -0
  613. package/dist/runtime/statewire-plan-mode.d.ts +88 -0
  614. package/dist/runtime/statewire-plan-mode.js +71 -0
  615. package/dist/runtime/statewire-plan-mode.js.map +1 -0
  616. package/dist/runtime/statewire-run-config.cjs +3 -1
  617. package/dist/runtime/statewire-run-config.cjs.map +1 -1
  618. package/dist/runtime/statewire-run-config.d.ts +7 -0
  619. package/dist/runtime/statewire-run-config.js +3 -1
  620. package/dist/runtime/statewire-run-config.js.map +1 -1
  621. package/dist/runtime/statewire-session-key.cjs +11 -5
  622. package/dist/runtime/statewire-session-key.cjs.map +1 -1
  623. package/dist/runtime/statewire-session-key.d.ts +22 -10
  624. package/dist/runtime/statewire-session-key.js +11 -5
  625. package/dist/runtime/statewire-session-key.js.map +1 -1
  626. package/dist/runtime/useAthenaStatewireRuntime.cjs +64 -9
  627. package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
  628. package/dist/runtime/useAthenaStatewireRuntime.d.ts +26 -10
  629. package/dist/runtime/useAthenaStatewireRuntime.js +66 -11
  630. package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
  631. package/dist/search/useAthenaAssets.cjs +394 -0
  632. package/dist/search/useAthenaAssets.cjs.map +1 -0
  633. package/dist/search/useAthenaAssets.d.ts +186 -0
  634. package/dist/search/useAthenaAssets.js +394 -0
  635. package/dist/search/useAthenaAssets.js.map +1 -0
  636. package/dist/sheet-range/index.cjs +4 -0
  637. package/dist/sheet-range/index.cjs.map +1 -1
  638. package/dist/sheet-range/index.d.ts +4 -2
  639. package/dist/sheet-range/index.js +4 -0
  640. package/dist/sheet-range/index.js.map +1 -1
  641. package/dist/sheet-range/query-range.cjs +102 -0
  642. package/dist/sheet-range/query-range.cjs.map +1 -0
  643. package/dist/sheet-range/query-range.d.ts +46 -0
  644. package/dist/sheet-range/query-range.js +102 -0
  645. package/dist/sheet-range/query-range.js.map +1 -0
  646. package/dist/styles.css +1 -1
  647. package/dist/subagents/index.cjs +49 -0
  648. package/dist/subagents/index.cjs.map +1 -0
  649. package/dist/subagents/index.d.ts +16 -0
  650. package/dist/subagents/index.js +49 -0
  651. package/dist/subagents/index.js.map +1 -0
  652. package/dist/subagents/lane-follow.cjs +19 -0
  653. package/dist/subagents/lane-follow.cjs.map +1 -0
  654. package/dist/subagents/lane-follow.d.ts +9 -0
  655. package/dist/subagents/lane-follow.js +19 -0
  656. package/dist/subagents/lane-follow.js.map +1 -0
  657. package/dist/subagents/lane-model.cjs +178 -0
  658. package/dist/subagents/lane-model.cjs.map +1 -0
  659. package/dist/subagents/lane-model.d.ts +140 -0
  660. package/dist/subagents/lane-model.js +178 -0
  661. package/dist/subagents/lane-model.js.map +1 -0
  662. package/dist/subagents/lane-parts.cjs +517 -0
  663. package/dist/subagents/lane-parts.cjs.map +1 -0
  664. package/dist/subagents/lane-parts.d.ts +130 -0
  665. package/dist/subagents/lane-parts.js +517 -0
  666. package/dist/subagents/lane-parts.js.map +1 -0
  667. package/dist/subagents/subagent-lane-group.cjs +215 -0
  668. package/dist/subagents/subagent-lane-group.cjs.map +1 -0
  669. package/dist/subagents/subagent-lane-group.d.ts +67 -0
  670. package/dist/subagents/subagent-lane-group.js +215 -0
  671. package/dist/subagents/subagent-lane-group.js.map +1 -0
  672. package/dist/subagents/subagent-transcript-drawer.cjs +431 -0
  673. package/dist/subagents/subagent-transcript-drawer.cjs.map +1 -0
  674. package/dist/subagents/subagent-transcript-drawer.d.ts +78 -0
  675. package/dist/subagents/subagent-transcript-drawer.js +431 -0
  676. package/dist/subagents/subagent-transcript-drawer.js.map +1 -0
  677. package/dist/subagents/task-subagent-group.cjs +115 -0
  678. package/dist/subagents/task-subagent-group.cjs.map +1 -0
  679. package/dist/subagents/task-subagent-group.d.ts +36 -0
  680. package/dist/subagents/task-subagent-group.js +115 -0
  681. package/dist/subagents/task-subagent-group.js.map +1 -0
  682. package/dist/subagents/use-omitted-images-in-view.cjs +68 -0
  683. package/dist/subagents/use-omitted-images-in-view.cjs.map +1 -0
  684. package/dist/subagents/use-omitted-images-in-view.d.ts +21 -0
  685. package/dist/subagents/use-omitted-images-in-view.js +68 -0
  686. package/dist/subagents/use-omitted-images-in-view.js.map +1 -0
  687. package/dist/threads/Inbox.cjs +2 -2
  688. package/dist/threads/Inbox.cjs.map +1 -1
  689. package/dist/threads/SessionList.cjs +6 -6
  690. package/dist/threads/SessionList.cjs.map +1 -1
  691. package/dist/threads/SessionsPage.cjs +13 -7
  692. package/dist/threads/SessionsPage.cjs.map +1 -1
  693. package/dist/threads/SessionsPage.d.ts +10 -1
  694. package/dist/threads/SessionsPage.js +9 -3
  695. package/dist/threads/SessionsPage.js.map +1 -1
  696. package/dist/threads/session-list-model.cjs.map +1 -1
  697. package/dist/threads/session-list-model.d.ts +2 -1
  698. package/dist/threads/session-list-model.js.map +1 -1
  699. package/dist/threads/session-row-parts.cjs +3 -3
  700. package/dist/threads/session-row-parts.cjs.map +1 -1
  701. package/dist/threads/sessions-page-model.cjs +13 -5
  702. package/dist/threads/sessions-page-model.cjs.map +1 -1
  703. package/dist/threads/sessions-page-model.d.ts +7 -0
  704. package/dist/threads/sessions-page-model.js +11 -3
  705. package/dist/threads/sessions-page-model.js.map +1 -1
  706. package/dist/threads/sessions-page-storage.cjs +8 -8
  707. package/dist/threads/sessions-page-storage.cjs.map +1 -1
  708. package/dist/threads/sessions-page-storage.d.ts +5 -1
  709. package/dist/threads/sessions-page-storage.js +8 -8
  710. package/dist/threads/sessions-page-storage.js.map +1 -1
  711. package/dist/threads/statewire-thread-list.cjs +14 -2
  712. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  713. package/dist/threads/statewire-thread-list.d.ts +11 -2
  714. package/dist/threads/statewire-thread-list.js +14 -2
  715. package/dist/threads/statewire-thread-list.js.map +1 -1
  716. package/dist/threads/use-athena-sessions.cjs +1 -0
  717. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  718. package/dist/threads/use-athena-sessions.d.ts +7 -0
  719. package/dist/threads/use-athena-sessions.js +1 -0
  720. package/dist/threads/use-athena-sessions.js.map +1 -1
  721. package/dist/threads/use-athena-thread-agent.cjs +31 -0
  722. package/dist/threads/use-athena-thread-agent.cjs.map +1 -0
  723. package/dist/threads/use-athena-thread-agent.d.ts +38 -0
  724. package/dist/threads/use-athena-thread-agent.js +31 -0
  725. package/dist/threads/use-athena-thread-agent.js.map +1 -0
  726. package/dist/threads/use-athena-thread-plan-mode.cjs +18 -0
  727. package/dist/threads/use-athena-thread-plan-mode.cjs.map +1 -0
  728. package/dist/threads/use-athena-thread-plan-mode.d.ts +18 -0
  729. package/dist/threads/use-athena-thread-plan-mode.js +18 -0
  730. package/dist/threads/use-athena-thread-plan-mode.js.map +1 -0
  731. package/dist/threads/use-rest-conversation-history.d.ts +1 -0
  732. package/dist/tools/agent-creations.cjs +97 -0
  733. package/dist/tools/agent-creations.cjs.map +1 -0
  734. package/dist/tools/agent-creations.d.ts +38 -0
  735. package/dist/tools/agent-creations.js +97 -0
  736. package/dist/tools/agent-creations.js.map +1 -0
  737. package/dist/tools/agent-highlights.cjs +100 -0
  738. package/dist/tools/agent-highlights.cjs.map +1 -0
  739. package/dist/tools/agent-highlights.d.ts +57 -0
  740. package/dist/tools/agent-highlights.js +100 -0
  741. package/dist/tools/agent-highlights.js.map +1 -0
  742. package/dist/tools/append-document-tool-ui.cjs +1 -0
  743. package/dist/tools/append-document-tool-ui.cjs.map +1 -1
  744. package/dist/tools/append-document-tool-ui.d.ts +7 -0
  745. package/dist/tools/append-document-tool-ui.js +2 -1
  746. package/dist/tools/append-document-tool-ui.js.map +1 -1
  747. package/dist/tools/auto-open-tools.cjs +144 -71
  748. package/dist/tools/auto-open-tools.cjs.map +1 -1
  749. package/dist/tools/auto-open-tools.d.ts +131 -1
  750. package/dist/tools/auto-open-tools.js +145 -72
  751. package/dist/tools/auto-open-tools.js.map +1 -1
  752. package/dist/tools/browser-tool-uis.cjs +594 -0
  753. package/dist/tools/browser-tool-uis.cjs.map +1 -0
  754. package/dist/tools/browser-tool-uis.d.ts +8 -0
  755. package/dist/tools/browser-tool-uis.js +594 -0
  756. package/dist/tools/browser-tool-uis.js.map +1 -0
  757. package/dist/tools/computer-asset-tool-uis.cjs +313 -0
  758. package/dist/tools/computer-asset-tool-uis.cjs.map +1 -0
  759. package/dist/tools/computer-asset-tool-uis.d.ts +5 -0
  760. package/dist/tools/computer-asset-tool-uis.js +313 -0
  761. package/dist/tools/computer-asset-tool-uis.js.map +1 -0
  762. package/dist/tools/document-edit-tool-uis.cjs +218 -0
  763. package/dist/tools/document-edit-tool-uis.cjs.map +1 -0
  764. package/dist/tools/document-edit-tool-uis.d.ts +40 -0
  765. package/dist/tools/document-edit-tool-uis.js +218 -0
  766. package/dist/tools/document-edit-tool-uis.js.map +1 -0
  767. package/dist/tools/drive-tool-uis.cjs +429 -0
  768. package/dist/tools/drive-tool-uis.cjs.map +1 -0
  769. package/dist/tools/drive-tool-uis.d.ts +121 -0
  770. package/dist/tools/drive-tool-uis.js +429 -0
  771. package/dist/tools/drive-tool-uis.js.map +1 -0
  772. package/dist/tools/email-calendar-tool-uis.cjs +789 -0
  773. package/dist/tools/email-calendar-tool-uis.cjs.map +1 -0
  774. package/dist/tools/email-calendar-tool-uis.d.ts +129 -0
  775. package/dist/tools/email-calendar-tool-uis.js +789 -0
  776. package/dist/tools/email-calendar-tool-uis.js.map +1 -0
  777. package/dist/tools/ontology-tool-uis.cjs +83 -0
  778. package/dist/tools/ontology-tool-uis.cjs.map +1 -0
  779. package/dist/tools/ontology-tool-uis.d.ts +9 -0
  780. package/dist/tools/ontology-tool-uis.js +83 -0
  781. package/dist/tools/ontology-tool-uis.js.map +1 -0
  782. package/dist/tools/orchestration-tool-uis.cjs +586 -0
  783. package/dist/tools/orchestration-tool-uis.cjs.map +1 -0
  784. package/dist/tools/orchestration-tool-uis.d.ts +141 -0
  785. package/dist/tools/orchestration-tool-uis.js +586 -0
  786. package/dist/tools/orchestration-tool-uis.js.map +1 -0
  787. package/dist/tools/presentation-edit-tool-uis.cjs +516 -0
  788. package/dist/tools/presentation-edit-tool-uis.cjs.map +1 -0
  789. package/dist/tools/presentation-edit-tool-uis.d.ts +73 -0
  790. package/dist/tools/presentation-edit-tool-uis.js +516 -0
  791. package/dist/tools/presentation-edit-tool-uis.js.map +1 -0
  792. package/dist/tools/project-tool-uis.cjs +213 -0
  793. package/dist/tools/project-tool-uis.cjs.map +1 -0
  794. package/dist/tools/project-tool-uis.d.ts +14 -0
  795. package/dist/tools/project-tool-uis.js +213 -0
  796. package/dist/tools/project-tool-uis.js.map +1 -0
  797. package/dist/tools/sandbox-tool-uis.cjs +491 -0
  798. package/dist/tools/sandbox-tool-uis.cjs.map +1 -0
  799. package/dist/tools/sandbox-tool-uis.d.ts +116 -0
  800. package/dist/tools/sandbox-tool-uis.js +491 -0
  801. package/dist/tools/sandbox-tool-uis.js.map +1 -0
  802. package/dist/tools/sheet-query-tool-ui.cjs +138 -0
  803. package/dist/tools/sheet-query-tool-ui.cjs.map +1 -0
  804. package/dist/tools/sheet-query-tool-ui.d.ts +15 -0
  805. package/dist/tools/sheet-query-tool-ui.js +138 -0
  806. package/dist/tools/sheet-query-tool-ui.js.map +1 -0
  807. package/dist/tools/studio-screenshot-tool-uis.cjs +262 -0
  808. package/dist/tools/studio-screenshot-tool-uis.cjs.map +1 -0
  809. package/dist/tools/studio-screenshot-tool-uis.d.ts +52 -0
  810. package/dist/tools/studio-screenshot-tool-uis.js +262 -0
  811. package/dist/tools/studio-screenshot-tool-uis.js.map +1 -0
  812. package/dist/tools/subagent-task-tool-ui.cjs +24 -475
  813. package/dist/tools/subagent-task-tool-ui.cjs.map +1 -1
  814. package/dist/tools/subagent-task-tool-ui.d.ts +19 -103
  815. package/dist/tools/subagent-task-tool-ui.js +28 -479
  816. package/dist/tools/subagent-task-tool-ui.js.map +1 -1
  817. package/dist/tools/tool-summary.cjs +36 -0
  818. package/dist/tools/tool-summary.cjs.map +1 -1
  819. package/dist/tools/tool-summary.js +36 -0
  820. package/dist/tools/tool-summary.js.map +1 -1
  821. package/dist/tools/tool-uis.cjs +181 -53
  822. package/dist/tools/tool-uis.cjs.map +1 -1
  823. package/dist/tools/tool-uis.d.ts +40 -0
  824. package/dist/tools/tool-uis.js +183 -55
  825. package/dist/tools/tool-uis.js.map +1 -1
  826. package/dist/typed-interrupts/index.cjs +15 -0
  827. package/dist/typed-interrupts/index.cjs.map +1 -0
  828. package/dist/typed-interrupts/index.d.ts +20 -0
  829. package/dist/typed-interrupts/index.js +15 -0
  830. package/dist/typed-interrupts/index.js.map +1 -0
  831. package/dist/version.cjs +4 -0
  832. package/dist/version.cjs.map +1 -1
  833. package/dist/version.d.ts +9 -0
  834. package/dist/version.js +4 -0
  835. package/dist/version.js.map +1 -1
  836. package/dist/workbench/live-desktop-api.cjs +2 -1
  837. package/dist/workbench/live-desktop-api.cjs.map +1 -1
  838. package/dist/workbench/live-desktop-api.js +2 -1
  839. package/dist/workbench/live-desktop-api.js.map +1 -1
  840. package/dist/workbench/session-workbench-panes.cjs +6 -6
  841. package/dist/workbench/session-workbench-panes.cjs.map +1 -1
  842. package/dist/workbench/session-workspace-api.cjs +7 -2
  843. package/dist/workbench/session-workspace-api.cjs.map +1 -1
  844. package/dist/workbench/session-workspace-api.d.ts +10 -0
  845. package/dist/workbench/session-workspace-api.js +7 -2
  846. package/dist/workbench/session-workspace-api.js.map +1 -1
  847. package/package.json +28 -6
  848. package/dist/agent-runtime/src/chat-outbox-store.cjs +0 -510
  849. package/dist/agent-runtime/src/chat-outbox-store.cjs.map +0 -1
  850. package/dist/agent-runtime/src/chat-outbox-store.d.ts +0 -210
  851. package/dist/agent-runtime/src/chat-outbox-store.js +0 -510
  852. package/dist/agent-runtime/src/chat-outbox-store.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"chat-outbox.cjs","sources":["../../../../agent-runtime/src/chat-outbox.ts"],"sourcesContent":["import type { ChatOutboxAttachmentCheck, ChatOutboxAttachmentVerdict } from \"./chat-outbox-attachments\";\nimport type {\n ChatOutboxAttachment,\n ChatOutboxClaim,\n ChatOutboxEntry,\n ChatOutboxFailureReason,\n ChatOutboxFile,\n ChatOutboxRecord,\n ChatOutboxStore,\n} from \"./chat-outbox-store\";\n\n/**\n * The chat outbox: a message typed while Athena can't be reached waits on this device and is sent\n * once Athena answers again, while the app is in front, after a few seconds the person can cancel\n * (decision 5 of the offline plan, `docs/plans/2026-10-27-offline-everywhere-plan.md`).\n *\n * - **Held before the conversation's journal, never inside it.** A send made while Athena can't be\n * reached does not reach statewire at all: statewire would replay it the moment its connection\n * returns (from a hidden tab too) and has no way to take a journaled statement back. The message\n * waits here instead, and reaches statewire only when this controller hands it over, under the\n * id minted when it was typed.\n * - **Sent in front, with a countdown.** Once Athena is reachable and the app is in front (a visible\n * tab, an active app, a focused desktop window), the waiting messages count down\n * ({@link CHAT_OUTBOX_COUNTDOWN_MS}) with a Cancel that gives the text back to the composer; then\n * each is handed over once. Going to the background or losing Athena stops the countdown; it\n * starts over, in full, when both are back.\n * - **A day is the limit for sending on its own.** A message that waited more than\n * {@link CHAT_OUTBOX_ASK_AFTER_MS} asks first (Send / Edit / Discard); the messages behind it wait\n * for the answer, so nothing is sent out of order.\n * - **Once per message, never a loop.** A message is handed over at most once per return of Athena.\n * A hand-off that fails before the conversation took it (anything but the conversation going\n * away) stays as \"Couldn't send\" with Retry and Discard, kept with the message so no window and\n * no later mount sends it again on its own. Once the conversation's journal took it, statewire\n * owns it: it delivers it exactly once, and a refusal lands in the conversation's own failed\n * lane (Retry / Discard there).\n * - **One sender per message.** A hand-off claims the message in the store first, atomically\n * across windows ({@link CHAT_OUTBOX_CLAIM_LEASE_MS}), so two windows on the same conversation\n * never hand the same message twice (a second hand-off of an id whose run is in flight would be\n * read as an edit of that turn). The gate is checked again once the claim is written: a tab\n * hidden (or an Athena lost) meanwhile lets the claim go, and the message waits again.\n * - **Nothing overtakes.** Until the conversation's kept messages are read, a new send waits too\n * (it goes at once if nothing older turns up), and a message the person told to go now still\n * goes after the older ones in line.\n * - **Kept until it is safe to let go.** The waiting record is removed only once statewire has the\n * statement durably (`posted`, `applied` or settled), or once the conversation shows the message\n * (a journal adopted from an earlier page, or the message already on the transcript).\n * - **Its attachments go with it, still valid.** A message keeps the files that had finished\n * uploading before Athena went out of reach (references to files already in Athena; one picked\n * while it can't be reached is never attached). Once the message is claimed they are asked about\n * ({@link ChatOutboxOptions.checkAttachments}): one Athena refuses (deleted, or no longer shared\n * with the person) keeps the message as \"Couldn't send\" with Retry, Edit and Discard, and a check\n * Athena could not answer keeps it the same way as a send error. Nothing goes unchecked, and the\n * text is never lost.\n * - **Its own send settings, never another's.** A message keeps the per-send settings it was typed\n * with ({@link ChatOutboxEntry.sendContext}), and the host stages them as it is handed over (its\n * `handed` event carries them). Every send of a conversation rides one ambient context, so a host\n * with settings that can differ between messages gives the outbox a send gate\n * ({@link ChatOutboxOptions.sendGate}): only messages whose settings are the same are handed over\n * together, and a message whose settings differ from a send the conversation has not taken yet\n * waits, in line, until it has.\n */\n\n/** How long the countdown before a waiting message is sent lasts. */\nexport const CHAT_OUTBOX_COUNTDOWN_MS = 5_000;\n/** A message that waited longer than this asks before it is sent. */\nexport const CHAT_OUTBOX_ASK_AFTER_MS = 24 * 60 * 60 * 1000;\n/** How long a window's claim on a message holds against another window's hand-off. */\nexport const CHAT_OUTBOX_CLAIM_LEASE_MS = 30_000;\n/** How long the check of a message's attachments may take before it counts as unanswered. */\nexport const CHAT_OUTBOX_ATTACHMENT_CHECK_TIMEOUT_MS = 15_000;\n\n/**\n * Why a sent message's Edit is not offered while Athena can't be reached (its tooltip, or the hint\n * under it where there are no tooltips). An edit rewinds the conversation and re-runs it: a\n * journaled one would replay the moment the connection returns, from a hidden window too, so an\n * edit never waits the way a new message does.\n */\nexport const CHAT_EDIT_UNREACHABLE_LABEL = \"Can't edit while Athena can't be reached\";\n\n/** What an edit submitted while Athena can't be reached says: the edit stays where it was typed. */\nexport const CHAT_EDIT_KEPT_MESSAGE =\n \"Can't reach Athena right now. Your edit stays here — submit it once Athena is back.\";\n\n/** An edit submitted while Athena can't be reached: refused, never queued (its message says so). */\nexport class ChatEditUnreachableError extends Error {\n constructor() {\n super(CHAT_EDIT_KEPT_MESSAGE);\n this.name = \"ChatEditUnreachableError\";\n }\n}\n\n/** A boolean the host reports and notifies on: Athena's reachability, the app being in front. */\nexport interface ChatOutboxSignal {\n get(): boolean;\n subscribe(listener: () => void): () => void;\n}\n\n/**\n * Whether a hand-off reaches the conversation now: `ready` (attached, a never-started chat that\n * dials on its first send, or an idle channel that reattaches on demand — in each case what the\n * conversation shows is the server's, so a message missing from it never reached it),\n * `connecting` (reattaching: what it shows may be a remembered snapshot), `refused` (the host\n * refused the conversation: stopped, or parked on an authorization denial).\n */\nexport type ChatOutboxThreadReadiness = \"ready\" | \"connecting\" | \"refused\";\n\n/** The conversation the outbox hands messages to (`chat-outbox-thread.ts` adapts a statewire thread). */\nexport interface ChatOutboxThreadPort {\n readiness(): ChatOutboxThreadReadiness;\n /**\n * Message ids the conversation shows anywhere: its transcript, its queue and steer lanes, the\n * run being dispatched, its failed lane — this page's journal included (statewire folds a\n * journaled send into them, one adopted from an earlier page too).\n */\n heldIds(): ReadonlySet<string>;\n /** Hand the message to the conversation under its own id; settles with the server's verdict. */\n send(entry: ChatOutboxEntry): Promise<unknown>;\n subscribe(listener: () => void): () => void;\n}\n\nexport type ChatOutboxRowState =\n /** Not sent yet: Athena can't be reached, or the app is not in front. */\n | { kind: \"waiting\" }\n /** Athena is back: the message is sent when the countdown ends, unless cancelled. */\n | { kind: \"countdown\"; endsAt: number }\n /** It waited more than a day: Send, Edit or Discard. */\n | { kind: \"ask\" }\n /** Being handed to the conversation (by this window or another). */\n | { kind: \"sending\" }\n /** The hand-off failed for a reason other than Athena being unreachable. */\n | { kind: \"failed\"; reason: ChatOutboxFailureReason; message: string };\n\nexport interface ChatOutboxRow {\n entry: ChatOutboxEntry;\n state: ChatOutboxRowState;\n}\n\n/** Another conversation of the same person with messages waiting (the tray offers to open it). */\nexport interface ChatOutboxElsewhere {\n threadId: string;\n /** How many messages wait there. */\n count: number;\n /** The oldest of them: its text names the conversation. */\n first: ChatOutboxEntry;\n /**\n * Every message waiting there was typed into a chat that had never started, so it opens as the\n * new chat it still is (one typed after the chat started says it has a session now).\n */\n newChat: boolean;\n}\n\nexport interface ChatOutboxSnapshot {\n rows: readonly ChatOutboxRow[];\n /** When the running countdown ends (epoch ms), or `null`. */\n countdownEndsAt: number | null;\n /** Whether every waiting message is kept on this device (false: only while the page stays open). */\n durable: boolean;\n /** Whether the thread's kept messages have been read. */\n loaded: boolean;\n /** The person's other conversations with messages waiting, oldest first. */\n elsewhere: readonly ChatOutboxElsewhere[];\n}\n\n/** What a failed row says. */\nexport function chatOutboxFailureMessage(reason: ChatOutboxFailureReason): string {\n switch (reason) {\n case \"refused\":\n return \"This conversation can't be reached right now.\";\n case \"prepare\":\n return \"Couldn't prepare this message to send.\";\n case \"attachment\":\n return \"An attachment is no longer available to you.\";\n default:\n return \"Couldn't send this message.\";\n }\n}\n\nexport interface ChatOutboxInput {\n text: string;\n composerMarkdown?: string;\n /** The draft as an HTML composer holds it (the phone's), given back exactly on Cancel. */\n composerHtml?: string;\n metadata?: Record<string, unknown>;\n /** The per-send settings the host stages when the message goes ({@link ChatOutboxEntry.sendContext}). */\n sendContext?: Record<string, unknown>;\n files?: ChatOutboxFile[];\n /** Files already in Athena the message carries, asked about before it goes. */\n attachments?: ChatOutboxAttachment[];\n}\n\nexport type ChatOutboxEvent =\n | { type: \"held\"; threadId: string; messageId: string; durable: boolean }\n | { type: \"countdown-started\"; threadId: string; count: number }\n | { type: \"asked\"; threadId: string; messageId: string; ageMs: number }\n | {\n type: \"handed\";\n threadId: string;\n messageId: string;\n auto: boolean;\n ageMs: number;\n /** The message's own send settings, raised just before the hand-off so the host stages them. */\n sendContext?: Record<string, unknown>;\n }\n | { type: \"delivered\"; threadId: string; messageId: string; status: string }\n | { type: \"adopted\"; threadId: string; messageId: string }\n | { type: \"failed\"; threadId: string; messageId: string; message: string; reason: ChatOutboxFailureReason }\n | { type: \"cancelled\"; threadId: string; messageId: string }\n | { type: \"discarded\"; threadId: string; messageId: string };\n\n/**\n * A host's say over which waiting messages go together, and when (Olympus: the agents a message\n * names ride the conversation's one ambient context, so a message naming other agents than a send\n * still on its way waits for it). Without one, every message goes as soon as it may.\n */\nexport interface ChatOutboxSendGate {\n /** Consecutive messages with the same key may be handed over together; a different one waits. */\n keyOf(entry: ChatOutboxEntry): string;\n /** Whether the message may be handed over now. */\n mayHandOff(entry: ChatOutboxEntry): boolean;\n /** Called whenever {@link mayHandOff} may have changed. */\n subscribe(listener: () => void): () => void;\n}\n\n/** The command-lifecycle update statewire reports (`onCommandChange`), structurally. */\nexport interface ChatOutboxCommandUpdate {\n status: \"queued\" | \"posted\" | \"applied\" | \"settled\";\n params?: readonly unknown[];\n failure?: { fate: string; cause?: string } | undefined;\n}\n\nexport interface ChatOutbox {\n readonly threadId: string;\n getSnapshot(): ChatOutboxSnapshot;\n subscribe(listener: () => void): () => void;\n /**\n * Whether Athena can be reached, as this outbox reads it (the host's model; in the SDK the\n * conversation's own channel too). An edit of a sent message waits on it as a send does: while it\n * says no, the Edit action is not offered and a submitted edit is refused\n * ({@link CHAT_EDIT_UNREACHABLE_LABEL}, {@link ChatEditUnreachableError}).\n */\n readonly reachability: ChatOutboxSignal;\n /**\n * Whether a send made now must wait here: Athena can't be reached, or earlier messages of this\n * conversation are still waiting (a later message never overtakes them).\n */\n shouldHold(): boolean;\n /** Keep a message typed now; it waits until it can be sent. */\n hold(input: ChatOutboxInput): ChatOutboxEntry;\n /** Cancel (or the ask's Edit): the message leaves the outbox and its text goes back to the composer. */\n cancel(id: string): void;\n /** The ask's Send, a failed row's Retry: hand it over now (one attempt; waits if Athena is out of reach). */\n send(id: string): void;\n discard(id: string): void;\n /** Feed statewire's command lifecycle (`onCommandChange`). */\n observeCommand(update: ChatOutboxCommandUpdate): void;\n /** Open another conversation the tray lists as holding waiting messages (`null`: the host cannot). */\n readonly openThread: ((target: { threadId: string; newChat: boolean }) => void) | null;\n dispose(): void;\n}\n\nexport interface ChatOutboxOptions {\n threadId: string;\n /**\n * The conversation has never started (a new chat): what waits reopens with it. Read when a\n * message is held, so a chat that started since stamps its later messages as started.\n */\n isNewChat: boolean | (() => boolean);\n /** Where waiting messages are kept for this person; `null` keeps them in memory only. */\n store: ChatOutboxStore | null;\n reachability: ChatOutboxSignal;\n foreground: ChatOutboxSignal;\n thread: ChatOutboxThreadPort;\n /** Give a cancelled message's text back to the composer. */\n restore: (entry: ChatOutboxEntry) => void;\n /**\n * Open another of the person's conversations that holds waiting messages (the tray's Open);\n * omitted where the host cannot switch conversations (an embedded chat).\n */\n openThread?: (target: { threadId: string; newChat: boolean }) => void;\n onEvent?: (event: ChatOutboxEvent) => void;\n /**\n * Asks Athena whether a waiting message's attachments can still be opened, right before it goes\n * (`createChatOutboxAttachmentCheck`). `refused` keeps the message as \"Couldn't send\" (Retry,\n * Edit, Discard); `unknown` too, as a send error. Omitted: attachments go unchecked.\n */\n checkAttachments?: ChatOutboxAttachmentCheck;\n /**\n * Which waiting messages go together, and when (a message whose send settings differ from a send\n * the conversation has not taken yet waits for it). Omitted: every message goes once it may.\n */\n sendGate?: ChatOutboxSendGate;\n now?: () => number;\n countdownMs?: number;\n askAfterMs?: number;\n claimLeaseMs?: number;\n /** How long the attachment check may take before it counts as unanswered. */\n attachmentCheckTimeoutMs?: number;\n newMessageId?: () => string;\n /** Timer seam (tests): schedule `task` after `ms`, returning what cancels it. */\n setTimer?: (task: () => void, ms: number) => () => void;\n}\n\ntype Phase =\n /** Waiting in line. */\n | { kind: \"idle\" }\n /**\n * The countdown ended (or the person said Send) while the conversation was reattaching, or\n * while the message's own write was still landing: it goes as soon as both are done.\n */\n | { kind: \"awaiting-thread\" }\n /** Claiming it in the store before the hand-off. */\n | { kind: \"claiming\" }\n /** Handed to the conversation; `journaled` once statewire's journal took it. */\n | { kind: \"handed\"; journaled: boolean }\n | { kind: \"failed\"; reason: ChatOutboxFailureReason };\n\n/** Fates statewire settles a send with when the conversation went away under it (not a failure). */\nconst AWAY_CAUSES: ReadonlySet<string> = new Set([\"unmount\", \"stream-gone\"]);\n\n/** The message id a run send carries, off a command update's params. */\nexport function chatOutboxCommandMessageId(params: readonly unknown[] | undefined): string | null {\n const first = params?.[0] as { message?: { id?: unknown } } | undefined;\n const id = first?.message?.id;\n return typeof id === \"string\" ? id : null;\n}\n\nfunction failureOf(error: unknown): { fate?: string; cause?: string; message: string } {\n const failure = (error as { failure?: { fate?: unknown; cause?: unknown } } | null)?.failure;\n const fate = typeof failure?.fate === \"string\" ? failure.fate : undefined;\n const cause = typeof failure?.cause === \"string\" ? failure.cause : undefined;\n const message = error instanceof Error ? error.message : String(error);\n return { fate, cause, message };\n}\n\nfunction defaultMessageId(): string {\n const host = globalThis as { crypto?: { randomUUID?: () => string } };\n if (typeof host.crypto?.randomUUID === \"function\") return host.crypto.randomUUID();\n // Hosts without randomUUID (none Athena ships today): a random v4-shaped id.\n const hex = Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join(\"\");\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-a${hex.slice(17, 20)}-${hex.slice(20, 32)}`;\n}\n\nfunction sameChatOutboxRowState(a: ChatOutboxRowState, b: ChatOutboxRowState): boolean {\n if (a.kind !== b.kind) return false;\n switch (a.kind) {\n case \"countdown\":\n return a.endsAt === (b as typeof a).endsAt;\n case \"failed\":\n return a.reason === (b as typeof a).reason && a.message === (b as typeof a).message;\n default:\n return true;\n }\n}\n\n/** Whether two listings of a message show the same thing (another chat's preview is re-read per listing). */\nfunction sameChatOutboxEntry(a: ChatOutboxEntry, b: ChatOutboxEntry): boolean {\n return (\n a === b ||\n (a.id === b.id &&\n a.threadId === b.threadId &&\n a.text === b.text &&\n a.newChat === b.newChat &&\n a.queuedAt === b.queuedAt &&\n a.composerMarkdown === b.composerMarkdown)\n );\n}\n\n/** Whether two snapshots show the same thing (the rows' entries by identity: a listing keeps them). */\nexport function sameChatOutboxSnapshot(a: ChatOutboxSnapshot, b: ChatOutboxSnapshot): boolean {\n if (a === b) return true;\n if (a.countdownEndsAt !== b.countdownEndsAt || a.durable !== b.durable || a.loaded !== b.loaded) return false;\n if (a.rows.length !== b.rows.length || a.elsewhere.length !== b.elsewhere.length) return false;\n for (let index = 0; index < a.rows.length; index += 1) {\n const x = a.rows[index];\n const y = b.rows[index];\n if (!x || !y || x.entry !== y.entry || !sameChatOutboxRowState(x.state, y.state)) return false;\n }\n for (let index = 0; index < a.elsewhere.length; index += 1) {\n const x = a.elsewhere[index];\n const y = b.elsewhere[index];\n if (\n !x ||\n !y ||\n x.threadId !== y.threadId ||\n x.count !== y.count ||\n x.newChat !== y.newChat ||\n !sameChatOutboxEntry(x.first, y.first)\n ) {\n return false;\n }\n }\n return true;\n}\n\nexport function createChatOutbox(options: ChatOutboxOptions): ChatOutbox {\n const {\n threadId,\n isNewChat,\n store,\n reachability,\n foreground,\n thread,\n restore,\n openThread,\n onEvent,\n checkAttachments,\n sendGate,\n now = () => Date.now(),\n countdownMs = CHAT_OUTBOX_COUNTDOWN_MS,\n askAfterMs = CHAT_OUTBOX_ASK_AFTER_MS,\n claimLeaseMs = CHAT_OUTBOX_CLAIM_LEASE_MS,\n attachmentCheckTimeoutMs = CHAT_OUTBOX_ATTACHMENT_CHECK_TIMEOUT_MS,\n newMessageId = defaultMessageId,\n setTimer = (task, ms) => {\n const timer = setTimeout(task, ms);\n return () => clearTimeout(timer);\n },\n } = options;\n\n /** This controller's name on the claims it takes. */\n const claimant = newMessageId();\n let disposed = false;\n let loaded = store === null;\n /** The thread's waiting messages, oldest first. */\n let entries: ChatOutboxEntry[] = [];\n /** The person's other conversations with messages waiting. */\n let elsewhere: readonly ChatOutboxElsewhere[] = [];\n /** Claims as the store last reported them (another window's hand-off in progress). */\n let claims = new Map<string, ChatOutboxClaim>();\n /** Messages kept on the device (absent: in the store's memory only, or no store at all). */\n const persisted = new Set<string>();\n /**\n * Messages this window wrote to the store (the message itself, or Retry's cleared failure) that\n * a listing may not show yet: how many listings had started when the write settled, or\n * `undefined` while it is pending. A listing that started before then is not believed about\n * them (it would drop a message just kept, or bring back a failure just cleared).\n */\n const unsettled = new Map<string, number | undefined>();\n let listingsStarted = 0;\n const phases = new Map<string, Phase>();\n /** Messages the person told to go now (the ask's Send, Retry): they skip the countdown. */\n const sendNow = new Set<string>();\n /** The return of Athena each message was last handed over in (one hand-off per return). */\n const handedInRegain = new Map<string, number>();\n let regain = 0;\n let wasReachable = reachability.get();\n let countdown: { endsAt: number; ids: readonly string[]; cancel: () => void } | null = null;\n let leaseTimer: (() => void) | null = null;\n /** The running attachment checks' time limits (stopped on dispose). */\n const checkTimers = new Set<() => void>();\n /**\n * Claimed messages ready to be handed over (their attachments checked, or none), each with\n * whether it goes on its own: they go in line, behind any older one still being claimed or\n * asked about ({@link releaseReady}).\n */\n const readyToGo = new Map<string, boolean>();\n let releasing = false;\n const asked = new Set<string>();\n const listeners = new Set<() => void>();\n let snapshot: ChatOutboxSnapshot = {\n rows: [],\n countdownEndsAt: null,\n durable: true,\n loaded,\n elsewhere,\n };\n\n const emit = (event: ChatOutboxEvent): void => {\n try {\n onEvent?.(event);\n } catch {\n // Telemetry never reaches the send path.\n }\n };\n\n const phaseOf = (id: string): Phase => phases.get(id) ?? { kind: \"idle\" };\n const isBusy = (phase: Phase): boolean =>\n phase.kind === \"claiming\" || phase.kind === \"handed\" || phase.kind === \"awaiting-thread\";\n /** Another window holds a live claim on it. */\n const claimedElsewhere = (id: string): boolean => {\n const claim = claims.get(id);\n return claim !== undefined && claim.by !== claimant && now() - claim.at < claimLeaseMs;\n };\n /** Whether a listing that started as listing number `listing` may speak for the message. */\n const settledFor = (id: string, listing: number): boolean => {\n if (!unsettled.has(id)) return true;\n const settledAt = unsettled.get(id);\n return settledAt !== undefined && listing > settledAt;\n };\n /** Whether this window's write of the message has not landed yet. */\n const writePending = (id: string): boolean => unsettled.has(id) && unsettled.get(id) === undefined;\n const markUnsettled = (id: string, write: Promise<unknown>): void => {\n unsettled.set(id, undefined);\n const settle = () => {\n if (!unsettled.has(id)) return;\n unsettled.set(id, listingsStarted);\n // A hand-off deferred for this write goes now.\n evaluate();\n };\n void write.then(settle, settle);\n };\n\n interface Line {\n /** The messages that would go next, in order, before any that must ask. */\n run: ChatOutboxEntry[];\n /** The head of the line when it waited more than a day. */\n askId: string | null;\n }\n\n const rowState = (entry: ChatOutboxEntry, line: Line): ChatOutboxRowState => {\n const phase = phaseOf(entry.id);\n if (phase.kind === \"failed\") {\n return { kind: \"failed\", reason: phase.reason, message: chatOutboxFailureMessage(phase.reason) };\n }\n if (isBusy(phase) || claimedElsewhere(entry.id)) return { kind: \"sending\" };\n // In line behind (or in) the running countdown: it goes when the countdown ends.\n if (countdown !== null && line.run.some((candidate) => candidate.id === entry.id)) {\n return { kind: \"countdown\", endsAt: countdown.endsAt };\n }\n if (line.askId === entry.id) return { kind: \"ask\" };\n return { kind: \"waiting\" };\n };\n\n /** Messages with the same key may be handed over together (the host's send gate decides). */\n const keyOf = (entry: ChatOutboxEntry): string => sendGate?.keyOf(entry) ?? \"\";\n /** Whether the host lets the message be handed over now. */\n const mayHandOff = (entry: ChatOutboxEntry): boolean => sendGate?.mayHandOff(entry) ?? true;\n\n /** The waiting messages in line to be sent, given that the gate is open. */\n const computeLine = (): Line => {\n const run: ChatOutboxEntry[] = [];\n /** The send key of the line's head: a message with another key waits behind it. */\n let lineKey: string | null = null;\n for (const entry of entries) {\n const phase = phaseOf(entry.id);\n // A failed message is out of line until the person decides; one being handed (here or in\n // another window) is ahead of everything behind it.\n if (phase.kind === \"failed\") continue;\n const key = keyOf(entry);\n if (lineKey === null) lineKey = key;\n else if (key !== lineKey) break;\n if (isBusy(phase) || claimedElsewhere(entry.id)) continue;\n if (handedInRegain.get(entry.id) === regain && !sendNow.has(entry.id)) continue;\n if (!sendNow.has(entry.id) && now() - entry.queuedAt > askAfterMs) {\n return { run, askId: run.length === 0 ? entry.id : null };\n }\n run.push(entry);\n }\n // The line waits while the host holds its head (a send naming other settings is on its way).\n const head = run[0];\n if (head !== undefined && !mayHandOff(head)) return { run: [], askId: null };\n return { run, askId: null };\n };\n\n const gateOpen = (): boolean => reachability.get() && foreground.get();\n\n /**\n * Re-read the snapshot; listeners hear from it only when something they would show changed.\n * The outbox re-evaluates on every notification of the thread it serves, and a host renders on\n * every snapshot it is handed (`useChatOutboxSnapshot`): a fresh object for an unchanged state\n * would send that host round again (render -> thread notification -> publish -> render).\n */\n const publish = (): void => {\n const line = gateOpen() ? computeLine() : { run: [], askId: null };\n const next: ChatOutboxSnapshot = {\n rows: entries.map((entry) => ({ entry, state: rowState(entry, line) })),\n countdownEndsAt: countdown?.endsAt ?? null,\n durable: entries.every((entry) => persisted.has(entry.id)),\n loaded,\n elsewhere,\n };\n if (sameChatOutboxSnapshot(snapshot, next)) return;\n snapshot = next;\n for (const listener of listeners) {\n try {\n listener();\n } catch {\n // A listener's fault never reaches the outbox.\n }\n }\n };\n\n const stopCountdown = (): void => {\n countdown?.cancel();\n countdown = null;\n };\n\n const dropEntry = (id: string): void => {\n entries = entries.filter((entry) => entry.id !== id);\n unsettled.delete(id);\n phases.delete(id);\n readyToGo.delete(id);\n sendNow.delete(id);\n persisted.delete(id);\n claims.delete(id);\n asked.delete(id);\n if (countdown?.ids.includes(id)) stopCountdown();\n };\n\n /** The conversation has the message now (its journal or its transcript): let the record go. */\n const letGo = (id: string, event: ChatOutboxEvent): void => {\n if (!entries.some((entry) => entry.id === id)) return;\n dropEntry(id);\n emit(event);\n if (store) void store.remove(threadId, id).catch(() => undefined);\n };\n\n /** \"Couldn't send\": kept with the message, so nothing sends it again until the person retries. */\n const fail = (id: string, reason: ChatOutboxFailureReason): void => {\n phases.set(id, { kind: \"failed\", reason });\n sendNow.delete(id);\n emit({ type: \"failed\", threadId, messageId: id, message: chatOutboxFailureMessage(reason), reason });\n if (store) {\n void store\n .markFailed({ threadId, id, claimant, failure: { reason, at: now() } })\n .catch(() => undefined);\n }\n };\n\n /** Let this window's claim go: the hand-off did not start. */\n const releaseClaim = (id: string): void => {\n if (store) void store.release({ threadId, id, claimant }).catch(() => undefined);\n };\n\n /** Statewire's journal took it, or it ended without reaching it. */\n const handOff = (entry: ChatOutboxEntry, auto: boolean): void => {\n // The conversation may have taken it since the last evaluation (an attach that just landed\n // shows a message an earlier page already delivered): never hand an id it holds.\n if (thread.heldIds().has(entry.id)) {\n letGo(entry.id, { type: \"adopted\", threadId, messageId: entry.id });\n return;\n }\n const readiness = thread.readiness();\n if (readiness === \"refused\") {\n fail(entry.id, \"refused\");\n return;\n }\n if (readiness === \"connecting\") {\n phases.set(entry.id, { kind: \"awaiting-thread\" });\n return;\n }\n // Its write (the message itself, or Retry's cleared failure) has not landed: claiming now\n // could find no record yet. It goes once the write settles (which evaluates again).\n if (writePending(entry.id)) {\n phases.set(entry.id, { kind: \"awaiting-thread\" });\n return;\n }\n sendNow.delete(entry.id);\n phases.set(entry.id, { kind: \"claiming\" });\n const claim: Promise<\"claimed\" | \"taken\" | \"gone\"> = store\n ? store.claim({ threadId, id: entry.id, claimant, now: now(), leaseMs: claimLeaseMs })\n : Promise.resolve(\"claimed\");\n void claim.then(\n (result) => {\n if (disposed || phaseOf(entry.id).kind !== \"claiming\") return;\n if (result === \"gone\") {\n // Cancelled, discarded or handed by another window meanwhile.\n dropEntry(entry.id);\n evaluate();\n return;\n }\n if (result === \"taken\") {\n phases.set(entry.id, { kind: \"idle\" });\n claims.set(entry.id, { by: \"elsewhere\", at: now() });\n evaluate();\n return;\n }\n // The claim took a moment to write: look again before anything reaches statewire.\n if (!stillGoes(entry)) return;\n checkThenDispatch(entry, auto);\n },\n () => {\n if (disposed || phaseOf(entry.id).kind !== \"claiming\") return;\n fail(entry.id, \"prepare\");\n evaluate();\n },\n );\n };\n\n /**\n * Whether a claimed hand-off goes on, looked at again once what it waited on landed (its claim,\n * its attachments' check): the conversation may show the message by now, or refuse it; the app\n * may have gone to the background or Athena out of reach (never sent from the background), or\n * the conversation be reattaching, and then the claim goes and the message waits again.\n */\n const stillGoes = (entry: ChatOutboxEntry): boolean => {\n if (thread.heldIds().has(entry.id)) {\n letGo(entry.id, { type: \"adopted\", threadId, messageId: entry.id });\n evaluate();\n return false;\n }\n const ready = thread.readiness();\n if (ready === \"refused\") {\n fail(entry.id, \"refused\");\n evaluate();\n return false;\n }\n if (!gateOpen() || ready !== \"ready\") {\n phases.set(entry.id, gateOpen() ? { kind: \"awaiting-thread\" } : { kind: \"idle\" });\n releaseClaim(entry.id);\n evaluate();\n return false;\n }\n return true;\n };\n\n /**\n * A claimed message's attachments are asked about before it is handed over: the claim holds\n * meanwhile (the row says Sending…, and no other window hands it), bounded by\n * `attachmentCheckTimeoutMs`. Only `ok` hands it over; a refusal, or a check Athena could not\n * answer, keeps it as \"Couldn't send\" until the person retries, edits or discards it.\n */\n const checkThenDispatch = (entry: ChatOutboxEntry, auto: boolean): void => {\n const attachments = entry.attachments ?? [];\n if (attachments.length === 0 || !checkAttachments) {\n readyToGo.set(entry.id, auto);\n releaseReady();\n return;\n }\n let answered = false;\n let stopTimer: () => void = () => undefined;\n const answer = (verdict: ChatOutboxAttachmentVerdict): void => {\n if (answered) return;\n answered = true;\n stopTimer();\n checkTimers.delete(stopTimer);\n if (disposed || phaseOf(entry.id).kind !== \"claiming\") return;\n if (!stillGoes(entry)) return;\n if (verdict === \"ok\") {\n readyToGo.set(entry.id, auto);\n releaseReady();\n return;\n }\n fail(entry.id, verdict === \"refused\" ? \"attachment\" : \"error\");\n evaluate();\n };\n stopTimer = setTimer(() => answer(\"unknown\"), attachmentCheckTimeoutMs);\n checkTimers.add(stopTimer);\n let checking: Promise<ChatOutboxAttachmentVerdict>;\n try {\n checking = checkAttachments(attachments);\n } catch (error) {\n checking = Promise.reject(error);\n }\n void checking.then(answer, () => answer(\"unknown\"));\n };\n\n /**\n * Hands the ready messages over in line: oldest first, and none while an older one is still\n * being claimed or asked about (a check takes a moment, and a later message must not reach the\n * conversation before it). One whose gate closed meanwhile waits again, and one that failed or\n * left lets the line move. Re-entered from `evaluate`, it runs once at a time.\n */\n function releaseReady(): void {\n if (releasing || disposed) return;\n releasing = true;\n let heldBack = false;\n try {\n for (const entry of [...entries]) {\n if (phaseOf(entry.id).kind !== \"claiming\") continue;\n const auto = readyToGo.get(entry.id);\n if (auto === undefined) return;\n // The host holds it (a send with other settings went out since the line was counted down,\n // and the conversation has not taken it yet): it and everything behind it wait again.\n if (!mayHandOff(entry)) {\n holdBackFrom(entry);\n heldBack = true;\n return;\n }\n readyToGo.delete(entry.id);\n if (stillGoes(entry)) dispatch(entry, auto);\n }\n } finally {\n releasing = false;\n if (heldBack) evaluateLine();\n }\n }\n\n /**\n * `first` and every claimed message behind it go back in line unclaimed: they are counted down\n * and claimed again once the host lets the line go, so no other window waits on a claim of ours.\n */\n function holdBackFrom(first: ChatOutboxEntry): void {\n let behind = false;\n for (const entry of entries) {\n if (entry.id === first.id) behind = true;\n if (!behind || phaseOf(entry.id).kind !== \"claiming\") continue;\n readyToGo.delete(entry.id);\n phases.set(entry.id, { kind: \"idle\" });\n releaseClaim(entry.id);\n }\n }\n\n const dispatch = (entry: ChatOutboxEntry, auto: boolean): void => {\n handedInRegain.set(entry.id, regain);\n phases.set(entry.id, { kind: \"handed\", journaled: false });\n // Raised before the hand-off: the host stages the message's own send settings, which the\n // statement rides out with.\n emit({\n type: \"handed\",\n threadId,\n messageId: entry.id,\n auto,\n ageMs: now() - entry.queuedAt,\n ...(entry.sendContext !== undefined && { sendContext: entry.sendContext }),\n });\n let sent: Promise<unknown>;\n try {\n sent = thread.send(entry);\n } catch (error) {\n sent = Promise.reject(error);\n }\n void sent.then(\n () => {\n if (disposed) return;\n letGo(entry.id, { type: \"delivered\", threadId, messageId: entry.id, status: \"accepted\" });\n evaluate();\n },\n (error: unknown) => {\n if (disposed) return;\n const phase = phaseOf(entry.id);\n // Statewire's journal took it: its own record decides what happens next (an exactly-once\n // replay, or its failed lane), and the settle update lets this record go.\n if (phase.kind === \"handed\" && phase.journaled) return;\n if (phase.kind !== \"handed\") return;\n const failure = failureOf(error);\n if (failure.cause !== undefined && AWAY_CAUSES.has(failure.cause)) {\n // The conversation went away before its journal took the message: it waits again.\n phases.set(entry.id, { kind: \"idle\" });\n handedInRegain.delete(entry.id);\n releaseClaim(entry.id);\n evaluate();\n return;\n }\n fail(entry.id, \"error\");\n evaluate();\n },\n );\n };\n\n const startCountdown = (run: readonly ChatOutboxEntry[]): void => {\n stopCountdown();\n const ids = run.map((entry) => entry.id);\n const endsAt = now() + countdownMs;\n const cancel = setTimer(() => {\n if (disposed || countdown?.endsAt !== endsAt) return;\n countdown = null;\n if (!gateOpen()) {\n evaluate();\n return;\n }\n for (const id of ids) {\n const entry = entries.find((candidate) => candidate.id === id);\n if (!entry) continue;\n const phase = phaseOf(id);\n if (phase.kind !== \"idle\" || claimedElsewhere(id)) continue;\n // A send with other settings left meanwhile: the line waits for the conversation to take it.\n if (!mayHandOff(entry)) break;\n handOff(entry, true);\n }\n evaluate();\n }, countdownMs);\n countdown = { endsAt, ids, cancel };\n emit({ type: \"countdown-started\", threadId, count: ids.length });\n };\n\n const scheduleLeaseCheck = (): void => {\n leaseTimer?.();\n leaseTimer = null;\n let soonest = Number.POSITIVE_INFINITY;\n for (const [id, claim] of claims) {\n if (claim.by === claimant || !entries.some((entry) => entry.id === id)) continue;\n const expires = claim.at + claimLeaseMs - now();\n if (expires > 0) soonest = Math.min(soonest, expires);\n }\n if (Number.isFinite(soonest)) leaseTimer = setTimer(() => evaluate(), soonest + 1);\n };\n\n /** Re-derive everything from the inputs, then let the ready messages go in line. */\n function evaluate(): void {\n evaluateLine();\n releaseReady();\n }\n\n /** What the conversation holds, the gate, the line. */\n function evaluateLine(): void {\n if (disposed) return;\n const reachable = reachability.get();\n if (reachable && !wasReachable) regain += 1;\n wasReachable = reachable;\n\n if (loaded) {\n const held = thread.heldIds();\n for (const entry of [...entries]) {\n const phase = phaseOf(entry.id);\n if (phase.kind === \"handed\") {\n // This window's hand-off: the conversation folding it in means statewire's journal\n // took it; the record goes at `posted` (persisted before the wire) or a settle.\n if (held.has(entry.id)) phases.set(entry.id, { kind: \"handed\", journaled: true });\n continue;\n }\n if (phase.kind === \"claiming\") continue;\n // Not handed by this window, yet the conversation shows it: a journal adopted from an\n // earlier page (read back from storage, so durable), or the message already landed.\n if (held.has(entry.id)) letGo(entry.id, { type: \"adopted\", threadId, messageId: entry.id });\n }\n if (!gateOpen()) {\n // Gone to the background or out of reach before the conversation came back: those whose\n // countdown had ended go back in line, so returning starts the countdown over.\n for (const entry of entries) {\n if (phaseOf(entry.id).kind === \"awaiting-thread\") phases.set(entry.id, { kind: \"idle\" });\n }\n } else if (thread.readiness() !== \"connecting\") {\n // The conversation is back: the messages whose countdown already ended go now, in line, up\n // to one the host holds (it, and those behind it, are counted down again once it lets go).\n let held = false;\n let handedKey: string | null = null;\n for (const entry of entries) {\n if (phaseOf(entry.id).kind !== \"awaiting-thread\") continue;\n phases.set(entry.id, { kind: \"idle\" });\n const key = keyOf(entry);\n held ||= (handedKey !== null && key !== handedKey) || !mayHandOff(entry);\n if (held) continue;\n handedKey = key;\n handOff(entry, true);\n }\n }\n }\n\n if (!loaded || !gateOpen()) {\n stopCountdown();\n publish();\n return;\n }\n\n const line = computeLine();\n if (line.askId !== null && !asked.has(line.askId)) {\n asked.add(line.askId);\n const entry = entries.find((candidate) => candidate.id === line.askId);\n if (entry) emit({ type: \"asked\", threadId, messageId: entry.id, ageMs: now() - entry.queuedAt });\n }\n // Messages the person told to go now leave without a countdown, but never ahead of older\n // ones still in line: those count down first, and these follow them.\n const immediate: ChatOutboxEntry[] = [];\n for (const entry of line.run) {\n if (!sendNow.has(entry.id)) break;\n immediate.push(entry);\n }\n for (const entry of immediate) handOff(entry, false);\n const run = line.run.slice(immediate.length).filter((entry) => !sendNow.has(entry.id));\n if (run.length === 0) {\n stopCountdown();\n } else if (\n countdown === null ||\n countdown.ids.length !== run.length ||\n run.some((entry, index) => countdown?.ids[index] !== entry.id)\n ) {\n // A new countdown for a new line (a message added or cancelled starts it over).\n startCountdown(run);\n }\n scheduleLeaseCheck();\n publish();\n }\n\n const applyRecords = (records: readonly ChatOutboxRecord[], listing: number): void => {\n const mine = records.filter((record) => record.entry.threadId === threadId);\n const stored = new Map(mine.map((record) => [record.entry.id, record]));\n claims = new Map(\n mine.flatMap((record) => (record.claim ? [[record.entry.id, record.claim] as const] : [])),\n );\n for (const record of mine) {\n if (!settledFor(record.entry.id, listing)) continue;\n if (record.memoryOnly) persisted.delete(record.entry.id);\n else persisted.add(record.entry.id);\n // A hand-off that failed (in this window or another, now or before) stays failed until the\n // person retries it; this window's own failure is never cleared by a listing.\n const phase = phaseOf(record.entry.id);\n if (record.failure && phase.kind !== \"failed\" && !isBusy(phase)) {\n phases.set(record.entry.id, { kind: \"failed\", reason: record.failure.reason });\n }\n }\n // Messages the store no longer holds (sent, cancelled or discarded in another window) leave\n // this one too, unless this window is handing them or wrote them after the listing started.\n const kept = entries.filter(\n (entry) =>\n stored.has(entry.id) || !settledFor(entry.id, listing) || isBusy(phaseOf(entry.id)),\n );\n for (const entry of entries) {\n if (kept.includes(entry)) continue;\n if (countdown?.ids.includes(entry.id)) stopCountdown();\n phases.delete(entry.id);\n persisted.delete(entry.id);\n sendNow.delete(entry.id);\n }\n const known = new Set(kept.map((entry) => entry.id));\n const added = mine.filter((record) => !known.has(record.entry.id)).map((record) => record.entry);\n entries = [...kept, ...added].sort((a, b) => a.queuedAt - b.queuedAt);\n // Writes this listing has seen (it started after they settled) need no guard any more.\n for (const [id, settledAt] of unsettled) {\n if (settledAt !== undefined && listing > settledAt) unsettled.delete(id);\n }\n\n const byThread = new Map<string, { count: number; first: ChatOutboxEntry; newChat: boolean }>();\n for (const record of records) {\n if (record.entry.threadId === threadId) continue;\n const current = byThread.get(record.entry.threadId);\n if (current) {\n current.count += 1;\n current.newChat &&= record.entry.newChat;\n } else {\n byThread.set(record.entry.threadId, {\n count: 1,\n first: record.entry,\n newChat: record.entry.newChat,\n });\n }\n }\n elsewhere = [...byThread]\n .map(([otherThreadId, other]) => ({ threadId: otherThreadId, ...other }))\n .sort((a, b) => a.first.queuedAt - b.first.queuedAt);\n };\n\n let reading: Promise<void> | null = null;\n let readAgain = false;\n const reload = (): void => {\n if (!store || disposed) return;\n if (reading) {\n readAgain = true;\n return;\n }\n listingsStarted += 1;\n const listing = listingsStarted;\n reading = store\n .listAll()\n .then(\n (records) => {\n if (disposed) return;\n applyRecords(records, listing);\n loaded = true;\n },\n () => {\n loaded = true;\n },\n )\n .finally(() => {\n reading = null;\n if (disposed) return;\n evaluate();\n if (readAgain) {\n readAgain = false;\n reload();\n }\n });\n };\n\n const unsubscribers = [\n reachability.subscribe(evaluate),\n foreground.subscribe(evaluate),\n thread.subscribe(evaluate),\n ...(sendGate ? [sendGate.subscribe(evaluate)] : []),\n ...(store ? [store.subscribe(reload)] : []),\n ];\n reload();\n publish();\n\n return {\n threadId,\n reachability,\n getSnapshot: () => snapshot,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n shouldHold() {\n if (!reachability.get()) return true;\n // Until the conversation's kept messages are read, a new send could overtake one of them.\n if (!loaded) return true;\n // A message statewire's journal already took is ordered ahead of a new send by its seq;\n // one still waiting (or being claimed, or waiting for the conversation) is not.\n return entries.some((entry) => {\n const phase = phaseOf(entry.id);\n return phase.kind !== \"failed\" && !(phase.kind === \"handed\" && phase.journaled);\n });\n },\n hold(input) {\n const entry: ChatOutboxEntry = {\n id: newMessageId(),\n threadId,\n text: input.text,\n queuedAt: now(),\n newChat: typeof isNewChat === \"function\" ? isNewChat() : isNewChat,\n ...(input.composerMarkdown !== undefined && { composerMarkdown: input.composerMarkdown }),\n ...(input.composerHtml !== undefined && { composerHtml: input.composerHtml }),\n ...(input.metadata !== undefined && { metadata: input.metadata }),\n ...(input.sendContext !== undefined && { sendContext: input.sendContext }),\n ...(input.files !== undefined && input.files.length > 0 && { files: input.files }),\n ...(input.attachments !== undefined &&\n input.attachments.length > 0 && { attachments: input.attachments }),\n };\n // Sent from in front while Athena answers, held only until the kept messages are read: it\n // goes at once when nothing older is waiting, after them otherwise.\n if (!loaded && gateOpen()) sendNow.add(entry.id);\n entries = [...entries, entry];\n if (store) {\n // Counted as kept from the start: a page closed before the write settles is the same\n // risk a draft has, and the row must not flash \"only while this page is open\".\n persisted.add(entry.id);\n const write = store.put(entry);\n markUnsettled(entry.id, write);\n void write.then(\n (kept) => {\n if (!kept) persisted.delete(entry.id);\n emit({ type: \"held\", threadId, messageId: entry.id, durable: kept });\n publish();\n },\n () => {\n persisted.delete(entry.id);\n emit({ type: \"held\", threadId, messageId: entry.id, durable: false });\n publish();\n },\n );\n } else {\n emit({ type: \"held\", threadId, messageId: entry.id, durable: false });\n }\n evaluate();\n return entry;\n },\n cancel(id) {\n const entry = entries.find((candidate) => candidate.id === id);\n if (!entry || isBusy(phaseOf(id))) return;\n dropEntry(id);\n emit({ type: \"cancelled\", threadId, messageId: id });\n if (store) void store.remove(threadId, id).catch(() => undefined);\n try {\n restore(entry);\n } finally {\n evaluate();\n }\n },\n send(id) {\n const entry = entries.find((candidate) => candidate.id === id);\n if (!entry || isBusy(phaseOf(id))) return;\n const wasFailed = phaseOf(id).kind === \"failed\";\n phases.set(id, { kind: \"idle\" });\n handedInRegain.delete(id);\n sendNow.add(id);\n if (wasFailed && store) {\n const write = store.clearFailure({ threadId, id });\n markUnsettled(id, write);\n void write.catch(() => undefined);\n }\n evaluate();\n },\n discard(id) {\n const entry = entries.find((candidate) => candidate.id === id);\n if (!entry || isBusy(phaseOf(id))) return;\n dropEntry(id);\n emit({ type: \"discarded\", threadId, messageId: id });\n if (store) void store.remove(threadId, id).catch(() => undefined);\n evaluate();\n },\n observeCommand(update) {\n if (disposed) return;\n const id = chatOutboxCommandMessageId(update.params);\n if (id === null) return;\n const phase = phaseOf(id);\n if (phase.kind === \"handed\") {\n if (update.status === \"queued\") {\n phases.set(id, { kind: \"handed\", journaled: true });\n return;\n }\n // Persisted before the wire (`posted`), admitted (`applied`), or settled: statewire owns\n // the message now (its exactly-once replay, or its failed lane).\n letGo(id, { type: \"delivered\", threadId, messageId: id, status: update.status });\n evaluate();\n return;\n }\n // A statement for a waiting message this window did not hand: a journal adopted from an\n // earlier page. The conversation folds it in, and the next evaluation lets the record go.\n if (entries.some((entry) => entry.id === id)) evaluate();\n },\n openThread: openThread ?? null,\n dispose() {\n if (disposed) return;\n disposed = true;\n stopCountdown();\n leaseTimer?.();\n for (const stop of checkTimers) stop();\n checkTimers.clear();\n readyToGo.clear();\n for (const unsubscribe of unsubscribers) unsubscribe();\n listeners.clear();\n // A claim taken for a hand-off that never started is released, so another window (or the\n // next mount) need not wait out the lease. One whose hand-off started stays until its lease\n // ends: statewire may still journal the statement, and the conversation then shows it.\n if (store) {\n for (const [id, phase] of phases) {\n if (phase.kind === \"claiming\") releaseClaim(id);\n }\n }\n },\n };\n}\n"],"names":["held"],"mappings":";;AA+DO,MAAM,2BAA2B;AAEjC,MAAM,2BAA2B,KAAK,KAAK,KAAK;AAEhD,MAAM,6BAA6B;AAEnC,MAAM,0CAA0C;AAQhD,MAAM,8BAA8B;AAGpC,MAAM,yBACX;AAGK,MAAM,iCAAiC,MAAM;AAAA,EAClD,cAAc;AACZ,UAAM,sBAAsB;AAC5B,SAAK,OAAO;AAAA,EACd;AACF;AA2EO,SAAS,yBAAyB,QAAyC;AAChF,UAAQ,QAAA;AAAA,IACN,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAAA;AAEb;AA8IA,MAAM,cAAmC,oBAAI,IAAI,CAAC,WAAW,aAAa,CAAC;AAGpE,SAAS,2BAA2B,QAAuD;;AAChG,QAAM,QAAQ,iCAAS;AACvB,QAAM,MAAK,oCAAO,YAAP,mBAAgB;AAC3B,SAAO,OAAO,OAAO,WAAW,KAAK;AACvC;AAEA,SAAS,UAAU,OAAoE;AACrF,QAAM,UAAW,+BAAoE;AACrF,QAAM,OAAO,QAAO,mCAAS,UAAS,WAAW,QAAQ,OAAO;AAChE,QAAM,QAAQ,QAAO,mCAAS,WAAU,WAAW,QAAQ,QAAQ;AACnE,QAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,SAAO,EAAE,MAAM,OAAO,QAAA;AACxB;AAEA,SAAS,mBAA2B;;AAClC,QAAM,OAAO;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IAAI;AACV,YAAM,QAAQ,QAAQ,KAAK,CAAC,cAAc,UAAU,OAAO,EAAE;AAC7D,UAAI,CAAC,SAAS,OAAO,QAAQ,EAAE,CAAC,EAAG;AACnC,gBAAU,EAAE;AACZ,WAAK,EAAE,MAAM,aAAa,UAAU,WAAW,IAAI;AACnD,UAAI,YAAY,MAAM,OAAO,UAAU,EAAE,EAAE,MAAM,MAAM,MAAS;AAChE,eAAA;AAAA,IACF;AAAA,IACA,eAAe,QAAQ;AACrB,UAAI,SAAU;AACd,YAAM,KAAK,2BAA2B,OAAO,MAAM;AACnD,UAAI,OAAO,KAAM;AACjB,YAAM,QAAQ,QAAQ,EAAE;AACxB,UAAI,MAAM,SAAS,UAAU;AAC3B,YAAI,OAAO,WAAW,UAAU;AAC9B,iBAAO,IAAI,IAAI,EAAE,MAAM,UAAU,WAAW,MAAM;AAClD;AAAA,QACF;AAGA,cAAM,IAAI,EAAE,MAAM,aAAa,UAAU,WAAW,IAAI,QAAQ,OAAO,OAAA,CAAQ;AAC/E,iBAAA;AACA;AAAA,MACF;AAGA,UAAI,QAAQ,KAAK,CAAC,UAAU,MAAM,OAAO,EAAE,EAAG,UAAA;AAAA,IAChD;AAAA,IACA,YAAY,cAAc;AAAA,IAC1B,UAAU;AACR,UAAI,SAAU;AACd,iBAAW;AACX,oBAAA;AACA;AACA,iBAAW,QAAQ,YAAa,MAAA;AAChC,kBAAY,MAAA;AACZ,gBAAU,MAAA;AACV,iBAAW,eAAe,cAAe,aAAA;AACzC,gBAAU,MAAA;AAIV,UAAI,OAAO;AACT,mBAAW,CAAC,IAAI,KAAK,KAAK,QAAQ;AAChC,cAAI,MAAM,SAAS,WAAY,cAAa,EAAE;AAAA,QAChD;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAEJ;;;;;;;;;;;;"}
1
+ {"version":3,"file":"chat-outbox.cjs","sources":["../../../../agent-runtime/src/chat-outbox.ts"],"sourcesContent":["import type { StatewireClient } from \"statewire\";\nimport { withAddressedAgents } from \"./addressed-agents\";\nimport type { ChatOutboxAttachmentCheck, ChatOutboxAttachmentVerdict } from \"./chat-outbox-attachments\";\nimport {\n CHAT_OUTBOX_LOCAL_META_KIND,\n type ChatOutboxAttachment,\n type ChatOutboxEntry,\n type ChatOutboxFile,\n type ChatOutboxLocalMeta,\n chatOutboxEntryOf,\n readChatOutboxLocalMeta,\n withoutTransientLocalMeta,\n} from \"./chat-outbox-entry\";\nimport { type LegacyChatOutboxReader, migrateLegacyChatOutbox } from \"./chat-outbox-legacy\";\nimport type { ChatOutboxDirectory } from \"./chat-outbox-storage\";\nimport { chatOutboxWireAnchorId } from \"./chat-outbox-thread\";\nimport { reanchorRunSend } from \"./statewire-held-sends\";\nimport { DEEP_AGENT_STATEWIRE_PROTOCOL } from \"./statewire-transport\";\n\nexport type { ChatOutboxAttachment, ChatOutboxEntry, ChatOutboxFile } from \"./chat-outbox-entry\";\n\n/**\n * The chat outbox: a message typed while Athena can't be reached waits on this device and is sent\n * once Athena answers again, while the app is in front, after a few seconds the person can cancel.\n *\n * It is a view over the thread's statewire outbox (statewire 0.24), which keeps every waiting\n * message in the thread's session record, orders it, and stamps each entry exactly once across tabs:\n *\n * - **Held, never queued, while Athena can't be reached.** {@link ChatOutbox.hold} puts the message\n * in the outbox held (`insert({ held: true, localMeta })`): no flush stamps it, in any tab, until\n * it is released.\n * - **Sent in front, after a countdown.** Once Athena is reachable and the app is in front, the\n * waiting messages count down ({@link CHAT_OUTBOX_COUNTDOWN_MS}, kept as `localMeta.countdownEndsAt`\n * so every tab shows the same one) with a Cancel that gives the text back to the composer; then\n * the visible tab releases each, re-anchored against the thread as it is then. A tab that comes\n * to the front starts a countdown it did not see begin over, in full. A hidden tab never\n * releases, and a hidden tab's flush holds what was queued before it mounted\n * (`createChatOutboxFlushPolicy`).\n * - **A day is the limit for sending on its own.** A message that waited more than\n * {@link CHAT_OUTBOX_ASK_AFTER_MS} asks first (Send / Edit / Discard).\n * - **Nothing overtakes.** Messages never pass a held one (`athenaCanOvertake`), so the messages\n * behind one that asks or failed wait for it, and a send typed while messages wait is held too.\n * - **Failures come back held.** A send the server refused (or that could not be delivered and is\n * not re-sent on its own) comes back held with `localMeta.error` (send recovery,\n * `statewire-held-sends.ts`), shown as \"Couldn't send\" with Retry, Edit and Discard.\n * - **Attachments are asked about before they go** ({@link ChatOutboxOptions.checkAttachments}).\n */\n\n/** How long the countdown before a waiting message is sent lasts. */\nexport const CHAT_OUTBOX_COUNTDOWN_MS = 5_000;\n/** A message that waited longer than this asks before it is sent. */\nexport const CHAT_OUTBOX_ASK_AFTER_MS = 24 * 60 * 60 * 1000;\n/** How long the check of a message's attachments may take before it counts as unanswered. */\nexport const CHAT_OUTBOX_ATTACHMENT_CHECK_TIMEOUT_MS = 15_000;\n\n/** The failure code a held message carries when Athena refused one of its attachments. */\nexport const CHAT_OUTBOX_ATTACHMENT_REFUSED_CODE = \"attachment-unavailable\";\n/** The failure code a held message carries when its attachments' check went unanswered. */\nexport const CHAT_OUTBOX_ATTACHMENT_UNKNOWN_CODE = \"attachment-check-failed\";\n\n/**\n * Why a sent message's Edit is not offered while Athena can't be reached. An edit rewinds the\n * conversation and re-runs it, so an edit never waits the way a new message does.\n */\nexport const CHAT_EDIT_UNREACHABLE_LABEL = \"Can't edit while Athena can't be reached\";\n\n/** What an edit submitted while Athena can't be reached says: the edit stays where it was typed. */\nexport const CHAT_EDIT_KEPT_MESSAGE =\n \"Can't reach Athena right now. Your edit stays here — submit it once Athena is back.\";\n\n/** An edit submitted while Athena can't be reached: refused, never queued (its message says so). */\nexport class ChatEditUnreachableError extends Error {\n constructor() {\n super(CHAT_EDIT_KEPT_MESSAGE);\n this.name = \"ChatEditUnreachableError\";\n }\n}\n\n/** A boolean the host reports and notifies on: Athena's reachability, the app being in front. */\nexport interface ChatOutboxSignal {\n get(): boolean;\n subscribe(listener: () => void): () => void;\n}\n\n/** The statewire outbox verbs the chat outbox uses (`StatewireClient.Outbox`, structurally). */\nexport interface ChatOutboxStatewireOutbox {\n readonly entries: readonly StatewireClient.OutboxEntry[];\n insert(entry: StatewireClient.OutboxInsert): string;\n update(id: string, fn: (entry: StatewireClient.OutboxEntry) => StatewireClient.OutboxPatch): void;\n remove(id: string): void;\n}\n\n/** The thread as the chat outbox reads it when it builds and re-anchors a send. */\nexport interface ChatOutboxThreadView {\n /** The raw wire messages of the loaded window (`extras.state.messages`), when replicated. */\n wireMessages: readonly unknown[] | null;\n /** The live run's id, or `null` between runs. */\n runId: string | null;\n /** Message ids on the transcript: a waiting message already there was delivered. */\n messageIds: ReadonlySet<string>;\n}\n\n/** The conversation the outbox lives in (`chat-outbox-thread.ts` adapts a statewire thread). */\nexport interface ChatOutboxThreadPort {\n /** The thread's statewire outbox; `null` while there is none (no session, not mounted yet). */\n outbox(): ChatOutboxStatewireOutbox | null;\n view(): ChatOutboxThreadView;\n subscribe(listener: () => void): () => void;\n /**\n * Dials a thread that is not attached and would not dial by itself (a chat that never started,\n * an idle channel), so a released message goes. statewire 0.24.1+ does this for outbox entries\n * itself; 0.24.0 dialed only for sends the page made.\n */\n wake?(): void;\n}\n\n/** Why a waiting message could not be sent. */\nexport type ChatOutboxFailureReason =\n /** The send failed (the server refused it, or it could not be delivered). */\n | \"error\"\n /** Athena refused one of its attachments: gone, or no longer the person's to open. */\n | \"attachment\";\n\nexport type ChatOutboxRowState =\n /** Not sent yet: Athena can't be reached, the app is not in front, or one ahead of it waits. */\n | { kind: \"waiting\" }\n /** Athena is back: the message is sent when the countdown ends, unless cancelled. */\n | { kind: \"countdown\"; endsAt: number }\n /** It waited more than a day: Send, Edit or Discard. */\n | { kind: \"ask\" }\n /** Being sent (its attachments are being checked). */\n | { kind: \"sending\" }\n /** It could not be sent: Retry, Edit or Discard. */\n | { kind: \"failed\"; reason: ChatOutboxFailureReason; message: string };\n\nexport interface ChatOutboxRow {\n entry: ChatOutboxEntry;\n state: ChatOutboxRowState;\n}\n\n/** Another conversation of the same person with messages waiting (the tray offers to open it). */\nexport interface ChatOutboxElsewhere {\n threadId: string;\n count: number;\n /** The oldest of them: its text names the conversation. */\n first: ChatOutboxEntry;\n /** Every message waiting there was typed into a chat that had never started. */\n newChat: boolean;\n}\n\nexport interface ChatOutboxSnapshot {\n rows: readonly ChatOutboxRow[];\n /** When the running countdown ends (epoch ms), or `null`. */\n countdownEndsAt: number | null;\n /** Whether every waiting message is kept on this device (false: only while the page stays open). */\n durable: boolean;\n /** Whether the thread's outbox is available (its session hydrated). */\n loaded: boolean;\n /** The person's other conversations with messages waiting, oldest first. */\n elsewhere: readonly ChatOutboxElsewhere[];\n}\n\n/** What a failed row says. */\nexport function chatOutboxFailureMessage(reason: ChatOutboxFailureReason): string {\n return reason === \"attachment\" ? \"An attachment is no longer available to you.\" : \"Couldn't send this message.\";\n}\n\nexport interface ChatOutboxInput {\n text: string;\n composerMarkdown?: string;\n /** The draft as an HTML composer holds it (the phone's), given back exactly on Cancel. */\n composerHtml?: string;\n metadata?: Record<string, unknown>;\n /** The agents the message names (`message.metadata.addressedAgents`); omitted, it names none of its own. */\n addressedAgents?: readonly string[];\n files?: ChatOutboxFile[];\n /** Files already in Athena the message carries, asked about before it goes. */\n attachments?: ChatOutboxAttachment[];\n}\n\nexport type ChatOutboxEvent =\n | { type: \"held\"; threadId: string; messageId: string; durable: boolean }\n | { type: \"countdown-started\"; threadId: string; count: number }\n | { type: \"asked\"; threadId: string; messageId: string; ageMs: number }\n | { type: \"handed\"; threadId: string; messageId: string; auto: boolean; ageMs: number }\n | { type: \"adopted\"; threadId: string; messageId: string }\n | { type: \"failed\"; threadId: string; messageId: string; message: string; reason: ChatOutboxFailureReason }\n | { type: \"cancelled\"; threadId: string; messageId: string }\n | { type: \"discarded\"; threadId: string; messageId: string }\n | { type: \"migrated\"; threadId: string; inserted: number; removed: number; kept: number };\n\nexport interface ChatOutbox {\n readonly threadId: string;\n getSnapshot(): ChatOutboxSnapshot;\n subscribe(listener: () => void): () => void;\n /**\n * Whether Athena can be reached, as this outbox reads it. An edit of a sent message waits on it:\n * while it says no, Edit is not offered and a submitted edit is refused\n * ({@link CHAT_EDIT_UNREACHABLE_LABEL}, {@link ChatEditUnreachableError}).\n */\n readonly reachability: ChatOutboxSignal;\n /**\n * Whether a send made now must wait here: Athena can't be reached, or messages of this\n * conversation are still waiting (a later message never overtakes them). `false` where the\n * thread keeps no outbox (no session): the send goes as it always did.\n */\n shouldHold(): boolean;\n /** Keep a message typed now; it waits until it can be sent. */\n hold(input: ChatOutboxInput): ChatOutboxEntry;\n /** Cancel (or the ask's Edit): the message leaves the outbox and its text goes back to the composer. */\n cancel(id: string): void;\n /** The ask's Send, a failed row's Retry: send it now. */\n send(id: string): void;\n /** A failed or asking row's Edit in place: the message is sent with the new text (same id). */\n edit(id: string, input: ChatOutboxInput): void;\n discard(id: string): void;\n /** Open another conversation the tray lists as holding waiting messages (`null`: the host cannot). */\n readonly openThread: ((target: { threadId: string; newChat: boolean }) => void) | null;\n dispose(): void;\n}\n\nexport interface ChatOutboxLegacyOptions {\n reader: LegacyChatOutboxReader;\n /**\n * Resolves `true` once the entry carrying `messageId` is stored on the device (read back through\n * `listChatOutboxes`). Omitted: an entry counts as kept once the outbox reports it `durable`.\n */\n isKept?: (threadId: string, messageId: string) => Promise<boolean>;\n}\n\nexport interface ChatOutboxOptions {\n threadId: string;\n /** The conversation has never started (a new chat); read when a message is held. */\n isNewChat: boolean | (() => boolean);\n reachability: ChatOutboxSignal;\n foreground: ChatOutboxSignal;\n thread: ChatOutboxThreadPort;\n /** Give a cancelled message's text back to the composer. */\n restore: (entry: ChatOutboxEntry) => void;\n /** Open another of the person's conversations holding waiting messages (the tray's Open). */\n openThread?: (target: { threadId: string; newChat: boolean }) => void;\n onEvent?: (event: ChatOutboxEvent) => void;\n /** Asks Athena whether a waiting message's attachments can still be opened, right before it goes. */\n checkAttachments?: ChatOutboxAttachmentCheck;\n /** Every thread's waiting messages (`createChatOutboxDirectory`): the tray's \"elsewhere\". */\n directory?: ChatOutboxDirectory;\n /** The previous store: this thread's records are moved into its outbox once it is available. */\n legacy?: ChatOutboxLegacyOptions;\n now?: () => number;\n countdownMs?: number;\n askAfterMs?: number;\n attachmentCheckTimeoutMs?: number;\n newMessageId?: () => string;\n /** Timer seam (tests): schedule `task` after `ms`, returning what cancels it. */\n setTimer?: (task: () => void, ms: number) => () => void;\n}\n\n/** How often, and how far apart, a migration looks again for its entries' writes to land. */\nconst MIGRATION_CONFIRM_ATTEMPTS = 20;\nconst MIGRATION_CONFIRM_DELAY_MS = 250;\n\nfunction randomId(): string {\n const host = globalThis as { crypto?: { randomUUID?: () => string } };\n if (typeof host.crypto?.randomUUID === \"function\") return host.crypto.randomUUID();\n const hex = Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join(\"\");\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-a${hex.slice(17, 20)}-${hex.slice(20, 32)}`;\n}\n\ntype RunParams = Record<string, unknown> & { runId?: unknown; runAnchorMessageId?: unknown };\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * A held run send's params re-anchored against the thread as it is now, keeping its method (so the\n * re-anchor and the release are one atomic `update`): a send into the live run keeps its statement,\n * any other goes into the live run, or starts one at the host's tail. An edit re-asserts its\n * source's parent. `null`: keep the params as they are.\n */\nexport function reanchorHeldSendParams(\n command: { method: string; params: readonly unknown[] },\n view: Pick<ChatOutboxThreadView, \"wireMessages\" | \"runId\">,\n): unknown[] | null {\n const params = command.params[0] as RunParams | undefined;\n if (!isRecord(params)) return null;\n const rest = command.params.slice(1);\n if (command.method === \"run/edit\") {\n const next = reanchorRunSend(command, { wireMessages: view.wireMessages, runId: view.runId });\n return next?.method === \"run/edit\" ? next.params : null;\n }\n if (command.method !== \"run/send\") return null;\n if (view.runId !== null && params.runId === view.runId) return null;\n const { runAnchorMessageId: _anchor, ...unanchored } = params;\n if (view.runId !== null) return [{ ...unanchored, runId: view.runId }, ...rest];\n const wire = view.wireMessages ?? [];\n return [\n { ...unanchored, runId: randomId(), runAnchorMessageId: wire.length > 0 ? chatOutboxWireAnchorId(wire) : null },\n ...rest,\n ];\n}\n\nfunction failureReason(error: StatewireClient.SendFailure): ChatOutboxFailureReason {\n return \"code\" in error && error.code === CHAT_OUTBOX_ATTACHMENT_REFUSED_CODE ? \"attachment\" : \"error\";\n}\n\nfunction sameEntry(a: ChatOutboxEntry, b: ChatOutboxEntry): boolean {\n return (\n a.id === b.id &&\n a.outboxId === b.outboxId &&\n a.threadId === b.threadId &&\n a.text === b.text &&\n a.queuedAt === b.queuedAt &&\n a.newChat === b.newChat &&\n a.durable === b.durable &&\n a.composerMarkdown === b.composerMarkdown &&\n a.composerHtml === b.composerHtml &&\n sameJson(a.metadata, b.metadata) &&\n sameJson(a.files, b.files) &&\n sameJson(a.attachments, b.attachments)\n );\n}\n\n/** Whether two JSON values (an entry's metadata, files or attachments) are equal. */\nfunction sameJson(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n if (Array.isArray(a) || Array.isArray(b)) {\n return (\n Array.isArray(a) &&\n Array.isArray(b) &&\n a.length === b.length &&\n a.every((item, index) => sameJson(item, b[index]))\n );\n }\n const ka = Object.keys(a);\n const kb = Object.keys(b);\n return (\n ka.length === kb.length &&\n ka.every((key) => Object.hasOwn(b, key) && sameJson(Reflect.get(a, key), Reflect.get(b, key)))\n );\n}\n\nfunction sameState(a: ChatOutboxRowState, b: ChatOutboxRowState): boolean {\n if (a.kind !== b.kind) return false;\n if (a.kind === \"countdown\") return a.endsAt === (b as typeof a).endsAt;\n if (a.kind === \"failed\") return a.reason === (b as typeof a).reason && a.message === (b as typeof a).message;\n return true;\n}\n\n/** Whether two snapshots show the same thing (rows' entries by identity: a listing keeps them). */\nexport function sameChatOutboxSnapshot(a: ChatOutboxSnapshot, b: ChatOutboxSnapshot): boolean {\n if (a === b) return true;\n if (a.countdownEndsAt !== b.countdownEndsAt || a.durable !== b.durable || a.loaded !== b.loaded) return false;\n if (a.rows.length !== b.rows.length || a.elsewhere.length !== b.elsewhere.length) return false;\n for (let index = 0; index < a.rows.length; index += 1) {\n const x = a.rows[index];\n const y = b.rows[index];\n if (!x || !y || x.entry !== y.entry || !sameState(x.state, y.state)) return false;\n }\n for (let index = 0; index < a.elsewhere.length; index += 1) {\n const x = a.elsewhere[index];\n const y = b.elsewhere[index];\n if (!x || !y || x.threadId !== y.threadId || x.count !== y.count || x.newChat !== y.newChat || x.first !== y.first) {\n return false;\n }\n }\n return true;\n}\n\ninterface HeldRow {\n stored: StatewireClient.OutboxEntry;\n entry: ChatOutboxEntry;\n meta: ChatOutboxLocalMeta;\n}\n\nexport function createChatOutbox(options: ChatOutboxOptions): ChatOutbox {\n const {\n threadId,\n isNewChat,\n reachability,\n foreground,\n thread,\n restore,\n openThread,\n onEvent,\n checkAttachments,\n directory,\n legacy,\n now = () => Date.now(),\n countdownMs = CHAT_OUTBOX_COUNTDOWN_MS,\n askAfterMs = CHAT_OUTBOX_ASK_AFTER_MS,\n attachmentCheckTimeoutMs = CHAT_OUTBOX_ATTACHMENT_CHECK_TIMEOUT_MS,\n newMessageId = randomId,\n setTimer = (task, ms) => {\n const timer = setTimeout(task, ms);\n return () => clearTimeout(timer);\n },\n } = options;\n\n let disposed = false;\n /** Since when this tab's gate (reachable and in front) has been open; `null` while it is shut. */\n let openSince: number | null = null;\n /** Messages held before the session could take them, inserted in order once it can. */\n let pending: { entry: ChatOutboxEntry; insert: StatewireClient.OutboxInsert }[] = [];\n /**\n * Messages inserted that the outbox does not list yet (on shared storage the insert lands under\n * the storage lock), by message id; they show as waiting until it does.\n */\n const landing = new Map<string, ChatOutboxEntry>();\n /** Landing messages cancelled or discarded before they showed: removed once they do. */\n const dropOnLanding = new Set<string>();\n /** Outbox ids whose countdown this tab asked to start (the write has not come back yet). */\n const countdownRequested = new Set<string>();\n /** Outbox ids this tab released (they leave the rows once the outbox says so). */\n const released = new Set<string>();\n /** Message id -> legacy record id of in-memory messages released and not yet shown delivered. */\n const legacyAwaitingDelivery = new Map<string, string>();\n /** Outbox ids whose attachments are being checked. */\n const checking = new Set<string>();\n /**\n * Outbox ids this tab marked failed whose write has not come back yet: they stop the line as a\n * failed row does, so a stale view never counts the message down and checks it again.\n */\n const failing = new Set<string>();\n const asked = new Set<string>();\n const checkTimers = new Set<() => void>();\n let timer: { at: number; cancel: () => void } | null = null;\n let migration: \"idle\" | \"running\" | \"done\" = legacy ? \"idle\" : \"done\";\n let migrationAttempts = 0;\n const entryCache = new Map<string, ChatOutboxEntry>();\n const listeners = new Set<() => void>();\n let rows: HeldRow[] = [];\n let snapshot: ChatOutboxSnapshot = { rows: [], countdownEndsAt: null, durable: true, loaded: false, elsewhere: [] };\n\n const emit = (event: ChatOutboxEvent): void => {\n try {\n onEvent?.(event);\n } catch {\n // Telemetry never reaches the send path.\n }\n };\n\n const gateOpen = (): boolean => reachability.get() && foreground.get() && thread.outbox() !== null;\n\n const stable = (entry: ChatOutboxEntry): ChatOutboxEntry => {\n const key = entry.outboxId ?? `pending:${entry.id}`;\n const cached = entryCache.get(key);\n if (cached && sameEntry(cached, entry)) return cached;\n entryCache.set(key, entry);\n return entry;\n };\n\n /** The held message entries of the thread's outbox, in queue order. */\n const readRows = (outbox: ChatOutboxStatewireOutbox | null): HeldRow[] => {\n if (!outbox) return [];\n const result: HeldRow[] = [];\n for (const stored of outbox.entries) {\n if (stored.state !== \"held\") continue;\n const entry = chatOutboxEntryOf(stored, threadId);\n if (!entry) continue;\n result.push({ stored, entry: stable(entry), meta: readChatOutboxLocalMeta(stored.localMeta) });\n }\n return result;\n };\n\n const isAsk = (row: HeldRow): boolean => now() - row.entry.queuedAt > askAfterMs;\n\n /** The line: rows that count down now (the gate is open), up to one that asks or failed. */\n const lineOf = (current: readonly HeldRow[]): HeldRow[] => {\n const line: HeldRow[] = [];\n for (const row of current) {\n if (row.meta.error || failing.has(row.stored.id) || isAsk(row)) break;\n if (checking.has(row.stored.id) || released.has(row.stored.id)) continue;\n line.push(row);\n }\n return line;\n };\n\n const countdownCurrent = (meta: ChatOutboxLocalMeta, since: number): boolean =>\n meta.countdownEndsAt !== undefined && meta.countdownFrom !== undefined && meta.countdownFrom >= since;\n\n const lineEndsAt = (line: readonly HeldRow[]): number | null => {\n if (openSince === null || line.length === 0) return null;\n let endsAt = 0;\n for (const row of line) {\n if (!countdownCurrent(row.meta, openSince)) return null;\n endsAt = Math.max(endsAt, row.meta.countdownEndsAt ?? 0);\n }\n return endsAt;\n };\n\n const rowState = (row: HeldRow, line: readonly HeldRow[], endsAt: number | null, blocked: boolean): ChatOutboxRowState => {\n if (row.meta.error) {\n const reason = failureReason(row.meta.error);\n return { kind: \"failed\", reason, message: chatOutboxFailureMessage(reason) };\n }\n if (checking.has(row.stored.id) || released.has(row.stored.id)) return { kind: \"sending\" };\n if (blocked) return { kind: \"waiting\" };\n if (isAsk(row)) return { kind: \"ask\" };\n if (endsAt !== null && line.includes(row)) return { kind: \"countdown\", endsAt };\n return { kind: \"waiting\" };\n };\n\n const publish = (current: readonly HeldRow[], line: readonly HeldRow[], endsAt: number | null): void => {\n const outbox = thread.outbox();\n const built: ChatOutboxRow[] = [];\n let blocked = false;\n for (const row of current) {\n const state = rowState(row, line, endsAt, blocked);\n built.push({ entry: row.entry, state });\n if (state.kind === \"failed\" || state.kind === \"ask\") blocked = true;\n }\n for (const entry of landing.values()) built.push({ entry, state: { kind: \"waiting\" } });\n for (const waiting of pending) built.push({ entry: waiting.entry, state: { kind: \"waiting\" } });\n const elsewhere: ChatOutboxElsewhere[] = [];\n for (const other of directory?.getSnapshot().threads ?? []) {\n const first = other.entries[0];\n if (other.threadId === threadId || !first) continue;\n elsewhere.push({\n threadId: other.threadId,\n count: other.entries.length,\n first,\n newChat: other.entries.every((entry) => entry.newChat),\n });\n }\n const next: ChatOutboxSnapshot = {\n rows: built,\n countdownEndsAt: endsAt,\n durable: built.every((row) => row.entry.durable),\n loaded: outbox !== null,\n elsewhere,\n };\n if (elsewhere.length === snapshot.elsewhere.length) {\n // Directory listings rebuild their entries: keep the previous objects when nothing changed.\n next.elsewhere = elsewhere.map((item, index) => {\n const previous = snapshot.elsewhere[index];\n return previous &&\n previous.threadId === item.threadId &&\n previous.count === item.count &&\n previous.newChat === item.newChat &&\n sameEntry(previous.first, item.first)\n ? previous\n : item;\n });\n }\n if (sameChatOutboxSnapshot(snapshot, next)) return;\n snapshot = next;\n for (const listener of listeners) {\n try {\n listener();\n } catch {\n // A listener's fault never reaches the outbox.\n }\n }\n };\n\n /** Release a held entry: re-anchored, its countdown and failure cleared, in one locked update. */\n const releaseNow = (row: HeldRow, auto: boolean): void => {\n const outbox = thread.outbox();\n if (!outbox) return;\n const view = thread.view();\n released.add(row.stored.id);\n emit({ type: \"handed\", threadId, messageId: row.entry.id, auto, ageMs: now() - row.entry.queuedAt });\n try {\n outbox.update(row.stored.id, (current) => {\n if (current.state !== \"held\") return {};\n const params = reanchorHeldSendParams(current.command, view);\n return {\n held: false,\n localMeta: withoutTransientLocalMeta(current.localMeta),\n ...(params !== null && { command: { params } }),\n };\n });\n } catch {\n // Released, sent or removed by another tab meanwhile: it leaves the rows once the outbox says so.\n }\n thread.wake?.();\n // A message kept only in page memory leaves the legacy store once the transcript shows it\n // delivered: until then that record is its only copy that outlives the page.\n if (legacy && row.meta.legacyId !== undefined && !row.entry.durable) {\n legacyAwaitingDelivery.set(row.entry.id, row.meta.legacyId);\n }\n };\n\n const markFailed = (row: HeldRow, code: string): void => {\n const outbox = thread.outbox();\n checking.delete(row.stored.id);\n if (!outbox) return;\n failing.add(row.stored.id);\n const error: StatewireClient.SendFailure = { fate: \"rejected\", cause: \"server\", code };\n try {\n outbox.update(row.stored.id, (current) => {\n if (current.state !== \"held\") return {};\n const base = withoutTransientLocalMeta(current.localMeta);\n return { localMeta: { ...(isRecord(base) ? base : {}), error } };\n });\n } catch {\n // Gone meanwhile.\n }\n const reason = failureReason(error);\n emit({ type: \"failed\", threadId, messageId: row.entry.id, message: chatOutboxFailureMessage(reason), reason });\n };\n\n /** Check the row's attachments (when it carries any), then release it. */\n const release = (row: HeldRow, auto: boolean): void => {\n const attachments = row.entry.attachments ?? [];\n if (attachments.length === 0 || !checkAttachments) {\n releaseNow(row, auto);\n return;\n }\n if (checking.has(row.stored.id)) return;\n checking.add(row.stored.id);\n let answered = false;\n let stopTimer: () => void = () => undefined;\n const answer = (verdict: ChatOutboxAttachmentVerdict): void => {\n if (answered) return;\n answered = true;\n stopTimer();\n checkTimers.delete(stopTimer);\n if (disposed || !checking.has(row.stored.id)) return;\n if (verdict === \"ok\") {\n checking.delete(row.stored.id);\n // An automatic send goes only while the gate is still open; the person's own Send goes.\n if (!auto || gateOpen()) releaseNow(row, auto);\n evaluate();\n return;\n }\n markFailed(row, verdict === \"refused\" ? CHAT_OUTBOX_ATTACHMENT_REFUSED_CODE : CHAT_OUTBOX_ATTACHMENT_UNKNOWN_CODE);\n evaluate();\n };\n stopTimer = setTimer(() => answer(\"unknown\"), attachmentCheckTimeoutMs);\n checkTimers.add(stopTimer);\n let checked: Promise<ChatOutboxAttachmentVerdict>;\n try {\n checked = checkAttachments(attachments);\n } catch (error) {\n checked = Promise.reject(error);\n }\n void checked.then(answer, () => answer(\"unknown\"));\n };\n\n const startMigration = (outbox: ChatOutboxStatewireOutbox): void => {\n if (!legacy || migration !== \"idle\") return;\n migration = \"running\";\n const isKept =\n legacy.isKept === undefined\n ? async (messageId: string) =>\n thread\n .outbox()\n ?.entries.some((entry) => entry.durable && chatOutboxEntryOf(entry, threadId)?.id === messageId) ?? false\n : (messageId: string) => legacy.isKept!(threadId, messageId);\n void migrateLegacyChatOutbox({\n threadId,\n reader: legacy.reader,\n outbox,\n isKept,\n messageIdsShown: () => thread.view().messageIds,\n }).then(\n (result) => {\n migration = \"done\";\n if (result.inserted + result.removed + result.kept > 0) emit({ type: \"migrated\", threadId, ...result });\n directory?.refresh();\n // A record waits for its entry's write to land on the device: look again shortly, a\n // bounded number of times. A session kept in page memory never lands; its records go as\n // their messages do.\n const inMemory = thread.outbox()?.entries.some((entry) => !entry.durable) ?? false;\n if (result.kept > 0 && !inMemory && migrationAttempts < MIGRATION_CONFIRM_ATTEMPTS && !disposed) {\n migrationAttempts += 1;\n const stop = setTimer(() => {\n checkTimers.delete(stop);\n migration = \"idle\";\n evaluate();\n }, MIGRATION_CONFIRM_DELAY_MS);\n checkTimers.add(stop);\n }\n },\n () => {\n migration = \"idle\";\n },\n );\n };\n\n function evaluate(): void {\n if (disposed) return;\n const outbox = thread.outbox();\n\n // Messages held before the session hydrated go in, in order.\n if (outbox && pending.length > 0) {\n const waiting = pending;\n pending = [];\n for (let index = 0; index < waiting.length; index += 1) {\n const item = waiting[index]!;\n try {\n outbox.insert(item.insert);\n landing.set(item.entry.id, item.entry);\n emit({ type: \"held\", threadId, messageId: item.entry.id, durable: true });\n } catch {\n pending = waiting.slice(index);\n break;\n }\n }\n }\n if (outbox) startMigration(outbox);\n\n if (legacy && legacyAwaitingDelivery.size > 0) {\n const delivered = thread.view().messageIds;\n for (const [messageId, legacyId] of legacyAwaitingDelivery) {\n if (!delivered.has(messageId)) continue;\n legacyAwaitingDelivery.delete(messageId);\n void legacy.reader.remove(threadId, legacyId).catch(() => undefined);\n }\n }\n\n let current = readRows(outbox);\n const dropped = new Set<string>();\n for (const row of current) {\n landing.delete(row.entry.id);\n if (!dropOnLanding.delete(row.entry.id) || !outbox) continue;\n dropped.add(row.stored.id);\n try {\n outbox.remove(row.stored.id);\n } catch {\n // Gone meanwhile.\n }\n }\n current = current.filter((row) => !dropped.has(row.stored.id));\n // A waiting message the transcript already shows was delivered (a migrated record whose send\n // had landed): it leaves the outbox.\n const shown = current.length > 0 ? thread.view().messageIds : new Set<string>();\n for (const row of current) {\n if (!shown.has(row.entry.id) || !outbox) continue;\n try {\n outbox.remove(row.stored.id);\n } catch {\n // Gone meanwhile.\n }\n emit({ type: \"adopted\", threadId, messageId: row.entry.id });\n }\n current = current.filter((row) => !shown.has(row.entry.id));\n const heldIds = new Set(current.map((row) => row.stored.id));\n for (const id of released) if (!heldIds.has(id)) released.delete(id);\n for (const id of checking) if (!heldIds.has(id)) checking.delete(id);\n for (const row of current) if (row.meta.error) failing.delete(row.stored.id);\n for (const id of failing) if (!heldIds.has(id)) failing.delete(id);\n for (const key of entryCache.keys()) if (!key.startsWith(\"pending:\") && !heldIds.has(key)) entryCache.delete(key);\n rows = current;\n\n const open = gateOpen();\n if (open && openSince === null) openSince = now();\n if (!open) openSince = null;\n\n let line: HeldRow[] = [];\n let endsAt: number | null = null;\n if (open && openSince !== null) {\n line = lineOf(current);\n const head = current.find(\n (row) =>\n !row.meta.error && !failing.has(row.stored.id) && !checking.has(row.stored.id) && !released.has(row.stored.id),\n );\n if (head && isAsk(head) && !asked.has(head.stored.id)) {\n asked.add(head.stored.id);\n emit({ type: \"asked\", threadId, messageId: head.entry.id, ageMs: now() - head.entry.queuedAt });\n }\n const since = openSince;\n const starting = line.filter((row) => !countdownCurrent(row.meta, since));\n for (const row of line) if (countdownCurrent(row.meta, since)) countdownRequested.delete(row.stored.id);\n const toRequest = starting.filter((row) => !countdownRequested.has(row.stored.id));\n if (toRequest.length > 0 && outbox) {\n const from = now();\n for (const row of toRequest) {\n countdownRequested.add(row.stored.id);\n try {\n outbox.update(row.stored.id, (stored) => {\n const meta = readChatOutboxLocalMeta(stored.localMeta);\n if (stored.state !== \"held\" || countdownCurrent(meta, since)) return {};\n const base = isRecord(stored.localMeta) ? stored.localMeta : {};\n return { localMeta: { ...base, countdownFrom: from, countdownEndsAt: from + countdownMs } };\n });\n } catch {\n countdownRequested.delete(row.stored.id);\n }\n }\n emit({ type: \"countdown-started\", threadId, count: line.length });\n }\n endsAt = lineEndsAt(line);\n }\n\n if (endsAt !== null && endsAt <= now()) {\n timer?.cancel();\n timer = null;\n for (const row of line) release(row, true);\n queueMicrotask(evaluate);\n publish(current, [], null);\n return;\n }\n if (endsAt === null) {\n timer?.cancel();\n timer = null;\n } else if (timer?.at !== endsAt) {\n timer?.cancel();\n const at = endsAt;\n timer = {\n at,\n cancel: setTimer(\n () => {\n if (timer?.at === at) timer = null;\n evaluate();\n },\n Math.max(0, at - now()),\n ),\n };\n }\n publish(current, line, endsAt);\n }\n\n const findRow = (id: string): HeldRow | undefined => rows.find((row) => row.entry.id === id);\n\n const forgetLegacy = (row: HeldRow): void => {\n legacyAwaitingDelivery.delete(row.entry.id);\n if (legacy && row.meta.legacyId !== undefined) {\n void legacy.reader.remove(threadId, row.meta.legacyId).catch(() => undefined);\n }\n };\n\n const buildInsert = (id: string, input: ChatOutboxInput): { entry: ChatOutboxEntry; insert: StatewireClient.OutboxInsert } => {\n const queuedAt = now();\n const newChat = typeof isNewChat === \"function\" ? isNewChat() : isNewChat;\n const files = input.files ?? [];\n const metadata = withAddressedAgents(input.metadata, input.addressedAgents);\n const parts = [\n ...files.map((file) => ({\n type: \"file\" as const,\n mediaType: file.mediaType,\n url: file.url,\n ...(file.filename !== undefined && { filename: file.filename }),\n })),\n ...(input.text.length > 0 ? [{ type: \"text\" as const, text: input.text }] : []),\n ];\n const view = thread.view();\n const params: RunParams = {\n type: \"run/send\",\n behavior: \"auto\",\n runId: view.runId ?? randomId(),\n message: { id, role: \"user\", parts, ...(metadata !== undefined && { metadata }) },\n ...(view.runId === null && {\n runAnchorMessageId:\n view.wireMessages && view.wireMessages.length > 0 ? chatOutboxWireAnchorId(view.wireMessages) : null,\n }),\n };\n const attachments = input.attachments && input.attachments.length > 0 ? input.attachments : undefined;\n const localMeta: ChatOutboxLocalMeta = {\n kind: CHAT_OUTBOX_LOCAL_META_KIND,\n threadId,\n queuedAt,\n newChat,\n ...(input.composerMarkdown !== undefined && { composerMarkdown: input.composerMarkdown }),\n ...(input.composerHtml !== undefined && { composerHtml: input.composerHtml }),\n ...(attachments && { attachments }),\n };\n const entry: ChatOutboxEntry = {\n id,\n threadId,\n text: input.text,\n queuedAt,\n newChat,\n durable: false,\n ...(input.composerMarkdown !== undefined && { composerMarkdown: input.composerMarkdown }),\n ...(input.composerHtml !== undefined && { composerHtml: input.composerHtml }),\n ...(metadata !== undefined && { metadata }),\n ...(files.length > 0 && { files }),\n ...(attachments && { attachments }),\n };\n return {\n entry,\n insert: {\n protocol: DEEP_AGENT_STATEWIRE_PROTOCOL,\n command: { method: \"run/send\", params: [params] },\n held: true,\n localMeta,\n },\n };\n };\n\n const unsubscribers = [\n reachability.subscribe(evaluate),\n foreground.subscribe(evaluate),\n thread.subscribe(evaluate),\n ...(directory ? [directory.subscribe(evaluate)] : []),\n ];\n evaluate();\n\n return {\n threadId,\n reachability,\n getSnapshot: () => snapshot,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n shouldHold() {\n if (thread.outbox() === null && pending.length === 0) return false;\n if (!reachability.get()) return true;\n return pending.length > 0 || landing.size > 0 || readRows(thread.outbox()).length > 0;\n },\n hold(input) {\n const built = buildInsert(newMessageId(), input);\n const outbox = thread.outbox();\n let inserted = false;\n if (outbox && pending.length === 0) {\n try {\n outbox.insert(built.insert);\n landing.set(built.entry.id, built.entry);\n inserted = true;\n } catch {\n inserted = false;\n }\n }\n if (!inserted) pending = [...pending, built];\n else emit({ type: \"held\", threadId, messageId: built.entry.id, durable: true });\n evaluate();\n const row = findRow(built.entry.id);\n return row?.entry ?? built.entry;\n },\n cancel(id) {\n const row = findRow(id);\n if (!row) {\n const waiting = pending.find((item) => item.entry.id === id)?.entry ?? landing.get(id);\n if (!waiting) return;\n pending = pending.filter((item) => item.entry !== waiting);\n if (landing.delete(id)) dropOnLanding.add(id);\n emit({ type: \"cancelled\", threadId, messageId: id });\n try {\n restore(waiting);\n } finally {\n evaluate();\n }\n return;\n }\n try {\n thread.outbox()?.remove(row.stored.id);\n } catch {\n return;\n }\n forgetLegacy(row);\n emit({ type: \"cancelled\", threadId, messageId: id });\n try {\n restore(row.entry);\n } finally {\n evaluate();\n }\n },\n send(id) {\n const row = findRow(id);\n if (!row || released.has(row.stored.id)) return;\n failing.delete(row.stored.id);\n release(row, false);\n evaluate();\n },\n edit(id, input) {\n const row = findRow(id);\n const outbox = thread.outbox();\n if (!row || !outbox) return;\n const rebuilt = buildInsert(id, input);\n const message = (rebuilt.insert.command.params[0] as RunParams).message;\n try {\n outbox.update(row.stored.id, (current) => {\n if (current.state !== \"held\") return {};\n const params = current.command.params[0];\n const stripped = withoutTransientLocalMeta(current.localMeta);\n const base = isRecord(stripped) ? stripped : {};\n const { composerMarkdown: _md, composerHtml: _html, attachments: _attachments, ...kept } = base;\n return {\n localMeta: { ...kept, ...(rebuilt.insert.localMeta as object), queuedAt: row.entry.queuedAt },\n command: { params: [{ ...(isRecord(params) ? params : {}), message }, ...current.command.params.slice(1)] },\n };\n });\n } catch {\n return;\n }\n evaluate();\n failing.delete(row.stored.id);\n const edited = findRow(id);\n if (edited) release(edited, false);\n evaluate();\n },\n discard(id) {\n const row = findRow(id);\n if (!row) {\n if (!pending.some((item) => item.entry.id === id) && !landing.has(id)) return;\n pending = pending.filter((item) => item.entry.id !== id);\n if (landing.delete(id)) dropOnLanding.add(id);\n } else {\n try {\n thread.outbox()?.remove(row.stored.id);\n } catch {\n return;\n }\n forgetLegacy(row);\n }\n emit({ type: \"discarded\", threadId, messageId: id });\n evaluate();\n },\n openThread: openThread ?? null,\n dispose() {\n if (disposed) return;\n disposed = true;\n timer?.cancel();\n timer = null;\n for (const stop of checkTimers) stop();\n checkTimers.clear();\n for (const unsubscribe of unsubscribers) unsubscribe();\n listeners.clear();\n },\n };\n}\n"],"names":["reanchorRunSend","chatOutboxWireAnchorId","timer","chatOutboxEntryOf","readChatOutboxLocalMeta","withoutTransientLocalMeta","migrateLegacyChatOutbox","withAddressedAgents","CHAT_OUTBOX_LOCAL_META_KIND","DEEP_AGENT_STATEWIRE_PROTOCOL"],"mappings":";;;;;;;;AAiDO,MAAM,2BAA2B;AAEjC,MAAM,2BAA2B,KAAK,KAAK,KAAK;AAEhD,MA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