@athenaintel/react 0.41.3 → 0.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/README.md +102 -9
  2. package/dist/agent-runtime/src/asset-attachment.d.ts +98 -0
  3. package/dist/agent-runtime/src/athena-asset-drag.d.ts +32 -0
  4. package/dist/agent-runtime/src/auth-denial.d.ts +29 -0
  5. package/dist/agent-runtime/src/chat-outbox-attachments.cjs +41 -0
  6. package/dist/agent-runtime/src/chat-outbox-attachments.cjs.map +1 -0
  7. package/dist/agent-runtime/src/chat-outbox-attachments.d.ts +38 -0
  8. package/dist/agent-runtime/src/chat-outbox-attachments.js +41 -0
  9. package/dist/agent-runtime/src/chat-outbox-attachments.js.map +1 -0
  10. package/dist/agent-runtime/src/chat-outbox-signals.cjs +63 -0
  11. package/dist/agent-runtime/src/chat-outbox-signals.cjs.map +1 -0
  12. package/dist/agent-runtime/src/chat-outbox-signals.d.ts +12 -0
  13. package/dist/agent-runtime/src/chat-outbox-signals.js +63 -0
  14. package/dist/agent-runtime/src/chat-outbox-signals.js.map +1 -0
  15. package/dist/agent-runtime/src/chat-outbox-store.cjs +509 -0
  16. package/dist/agent-runtime/src/chat-outbox-store.cjs.map +1 -0
  17. package/dist/agent-runtime/src/chat-outbox-store.d.ts +203 -0
  18. package/dist/agent-runtime/src/chat-outbox-store.js +509 -0
  19. package/dist/agent-runtime/src/chat-outbox-store.js.map +1 -0
  20. package/dist/agent-runtime/src/chat-outbox-thread.cjs +136 -0
  21. package/dist/agent-runtime/src/chat-outbox-thread.cjs.map +1 -0
  22. package/dist/agent-runtime/src/chat-outbox-thread.d.ts +118 -0
  23. package/dist/agent-runtime/src/chat-outbox-thread.js +136 -0
  24. package/dist/agent-runtime/src/chat-outbox-thread.js.map +1 -0
  25. package/dist/agent-runtime/src/chat-outbox.cjs +696 -0
  26. package/dist/agent-runtime/src/chat-outbox.cjs.map +1 -0
  27. package/dist/agent-runtime/src/chat-outbox.d.ts +285 -0
  28. package/dist/agent-runtime/src/chat-outbox.js +696 -0
  29. package/dist/agent-runtime/src/chat-outbox.js.map +1 -0
  30. package/dist/agent-runtime/src/chat-socket-reachability.d.ts +45 -0
  31. package/dist/agent-runtime/src/client-tool-bridge.d.ts +152 -0
  32. package/dist/agent-runtime/src/client-tools.d.ts +133 -0
  33. package/dist/agent-runtime/src/composer-markdown.cjs +10 -0
  34. package/dist/agent-runtime/src/composer-markdown.cjs.map +1 -1
  35. package/dist/agent-runtime/src/composer-markdown.d.ts +108 -0
  36. package/dist/agent-runtime/src/composer-markdown.js +10 -0
  37. package/dist/agent-runtime/src/composer-markdown.js.map +1 -1
  38. package/dist/agent-runtime/src/config-mutations.d.ts +51 -0
  39. package/dist/agent-runtime/src/conversation-index.d.ts +110 -0
  40. package/dist/agent-runtime/src/conversation-list.d.ts +343 -0
  41. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs +3 -2
  42. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs.map +1 -1
  43. package/dist/agent-runtime/src/deep-agent-transport-recipe.d.ts +166 -0
  44. package/dist/agent-runtime/src/deep-agent-transport-recipe.js +3 -2
  45. package/dist/agent-runtime/src/deep-agent-transport-recipe.js.map +1 -1
  46. package/dist/agent-runtime/src/desktop-handoff.d.ts +139 -0
  47. package/dist/agent-runtime/src/durable-thread-snapshot-cache.d.ts +60 -0
  48. package/dist/agent-runtime/src/edit-command.d.ts +156 -0
  49. package/dist/agent-runtime/src/errors.d.ts +174 -0
  50. package/dist/agent-runtime/src/execute-output.d.ts +31 -0
  51. package/dist/agent-runtime/src/generated/runconfig-contract.cjs +16 -2
  52. package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  53. package/dist/agent-runtime/src/generated/runconfig-contract.d.ts +202 -0
  54. package/dist/agent-runtime/src/generated/runconfig-contract.js +16 -2
  55. package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  56. package/dist/agent-runtime/src/github-wake-event.d.ts +77 -0
  57. package/dist/agent-runtime/src/index.d.ts +74 -0
  58. package/dist/agent-runtime/src/interrupts.cjs +17 -0
  59. package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
  60. package/dist/agent-runtime/src/interrupts.d.ts +348 -0
  61. package/dist/agent-runtime/src/interrupts.js +17 -0
  62. package/dist/agent-runtime/src/interrupts.js.map +1 -1
  63. package/dist/agent-runtime/src/lane-follow.d.ts +121 -0
  64. package/dist/agent-runtime/src/lane-history.cjs +209 -0
  65. package/dist/agent-runtime/src/lane-history.cjs.map +1 -0
  66. package/dist/agent-runtime/src/lane-history.d.ts +175 -0
  67. package/dist/agent-runtime/src/lane-history.js +209 -0
  68. package/dist/agent-runtime/src/lane-history.js.map +1 -0
  69. package/dist/agent-runtime/src/lane-images.d.ts +184 -0
  70. package/dist/agent-runtime/src/message-author.d.ts +43 -0
  71. package/dist/agent-runtime/src/message-text.cjs +15 -0
  72. package/dist/agent-runtime/src/message-text.cjs.map +1 -0
  73. package/dist/agent-runtime/src/message-text.d.ts +47 -0
  74. package/dist/agent-runtime/src/message-text.js +15 -0
  75. package/dist/agent-runtime/src/message-text.js.map +1 -0
  76. package/dist/agent-runtime/src/message-window.cjs +15 -1
  77. package/dist/agent-runtime/src/message-window.cjs.map +1 -1
  78. package/dist/agent-runtime/src/message-window.d.ts +159 -0
  79. package/dist/agent-runtime/src/message-window.js +16 -2
  80. package/dist/agent-runtime/src/message-window.js.map +1 -1
  81. package/dist/agent-runtime/src/messages.cjs +88 -4
  82. package/dist/agent-runtime/src/messages.cjs.map +1 -1
  83. package/dist/agent-runtime/src/messages.d.ts +603 -0
  84. package/dist/agent-runtime/src/messages.js +88 -4
  85. package/dist/agent-runtime/src/messages.js.map +1 -1
  86. package/dist/agent-runtime/src/model-context.d.ts +22 -0
  87. package/dist/agent-runtime/src/offline-status.d.ts +157 -0
  88. package/dist/agent-runtime/src/optimistic-content.d.ts +21 -0
  89. package/dist/agent-runtime/src/protocol.cjs +12 -4
  90. package/dist/agent-runtime/src/protocol.cjs.map +1 -1
  91. package/dist/agent-runtime/src/protocol.d.ts +119 -0
  92. package/dist/agent-runtime/src/protocol.js +13 -5
  93. package/dist/agent-runtime/src/protocol.js.map +1 -1
  94. package/dist/agent-runtime/src/ptc-subcalls.d.ts +51 -0
  95. package/dist/agent-runtime/src/queue.d.ts +138 -0
  96. package/dist/agent-runtime/src/quota-safe-local-storage-session.d.ts +154 -0
  97. package/dist/agent-runtime/src/running-tool-placeholder.cjs +11 -0
  98. package/dist/agent-runtime/src/running-tool-placeholder.cjs.map +1 -0
  99. package/dist/agent-runtime/src/running-tool-placeholder.d.ts +25 -0
  100. package/dist/agent-runtime/src/running-tool-placeholder.js +11 -0
  101. package/dist/agent-runtime/src/running-tool-placeholder.js.map +1 -0
  102. package/dist/agent-runtime/src/runtime-messages.d.ts +104 -0
  103. package/dist/agent-runtime/src/screen-point.d.ts +151 -0
  104. package/dist/agent-runtime/src/sealed-idb.cjs +112 -0
  105. package/dist/agent-runtime/src/sealed-idb.cjs.map +1 -0
  106. package/dist/agent-runtime/src/sealed-idb.d.ts +106 -0
  107. package/dist/agent-runtime/src/sealed-idb.js +112 -0
  108. package/dist/agent-runtime/src/sealed-idb.js.map +1 -0
  109. package/dist/agent-runtime/src/send-recovery.d.ts +40 -0
  110. package/dist/agent-runtime/src/statewire-attach-observer.d.ts +194 -0
  111. package/dist/agent-runtime/src/statewire-diagnostics.d.ts +74 -0
  112. package/dist/agent-runtime/src/statewire-state.d.ts +29 -0
  113. package/dist/agent-runtime/src/statewire-suspended.cjs.map +1 -1
  114. package/dist/agent-runtime/src/statewire-suspended.d.ts +27 -0
  115. package/dist/agent-runtime/src/statewire-suspended.js.map +1 -1
  116. package/dist/agent-runtime/src/statewire-transport.d.ts +40 -0
  117. package/dist/agent-runtime/src/streaming-markdown.d.ts +46 -0
  118. package/dist/agent-runtime/src/subagent-transcripts.cjs +209 -0
  119. package/dist/agent-runtime/src/subagent-transcripts.cjs.map +1 -0
  120. package/dist/agent-runtime/src/subagent-transcripts.d.ts +71 -0
  121. package/dist/agent-runtime/src/subagent-transcripts.js +209 -0
  122. package/dist/agent-runtime/src/subagent-transcripts.js.map +1 -0
  123. package/dist/agent-runtime/src/subagents.cjs +253 -0
  124. package/dist/agent-runtime/src/subagents.cjs.map +1 -0
  125. package/dist/agent-runtime/src/subagents.d.ts +311 -0
  126. package/dist/agent-runtime/src/subagents.js +253 -0
  127. package/dist/agent-runtime/src/subagents.js.map +1 -0
  128. package/dist/agent-runtime/src/subscription-wake-event.d.ts +111 -0
  129. package/dist/agent-runtime/src/thread-extras.d.ts +43 -0
  130. package/dist/agent-runtime/src/thread-handoff.d.ts +364 -0
  131. package/dist/agent-runtime/src/thread-prewarm-controller.d.ts +76 -0
  132. package/dist/agent-runtime/src/thread-prewarm.d.ts +118 -0
  133. package/dist/agent-runtime/src/thread-snapshot-cache.d.ts +99 -0
  134. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs +46 -117
  135. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs.map +1 -1
  136. package/dist/agent-runtime/src/thread-snapshot-mirror.d.ts +101 -0
  137. package/dist/agent-runtime/src/thread-snapshot-mirror.js +17 -88
  138. package/dist/agent-runtime/src/thread-snapshot-mirror.js.map +1 -1
  139. package/dist/agent-runtime/src/thread-status.d.ts +53 -0
  140. package/dist/agent-runtime/src/tool-metadata.d.ts +146 -0
  141. package/dist/agent-runtime/src/tool-names.cjs +67 -0
  142. package/dist/agent-runtime/src/tool-names.cjs.map +1 -1
  143. package/dist/agent-runtime/src/tool-names.d.ts +60 -0
  144. package/dist/agent-runtime/src/tool-names.js +68 -1
  145. package/dist/agent-runtime/src/tool-names.js.map +1 -1
  146. package/dist/agent-runtime/src/tool-outputs.d.ts +35 -0
  147. package/dist/agent-runtime/src/tool-result.cjs +1 -0
  148. package/dist/agent-runtime/src/tool-result.cjs.map +1 -1
  149. package/dist/agent-runtime/src/tool-result.d.ts +126 -0
  150. package/dist/agent-runtime/src/tool-result.js +1 -0
  151. package/dist/agent-runtime/src/tool-result.js.map +1 -1
  152. package/dist/agent-runtime/src/types.d.ts +159 -0
  153. package/dist/agent-runtime/src/use-conversation-list.d.ts +76 -0
  154. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +136 -0
  155. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -0
  156. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +64 -0
  157. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +136 -0
  158. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -0
  159. package/dist/agent-runtime/src/use-deep-agent-config.d.ts +169 -0
  160. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs +13 -0
  161. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs.map +1 -1
  162. package/dist/agent-runtime/src/use-deep-agent-edit-submit.d.ts +22 -0
  163. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js +13 -0
  164. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js.map +1 -1
  165. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +20 -2
  166. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  167. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +168 -0
  168. package/dist/agent-runtime/src/use-deep-agent-runtime.js +20 -2
  169. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  170. package/dist/agent-runtime/src/use-deep-agent-thread.cjs +12 -4
  171. package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
  172. package/dist/agent-runtime/src/use-deep-agent-thread.d.ts +320 -0
  173. package/dist/agent-runtime/src/use-deep-agent-thread.js +12 -4
  174. package/dist/agent-runtime/src/use-deep-agent-thread.js.map +1 -1
  175. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +999 -0
  176. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -0
  177. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +409 -0
  178. package/dist/agent-runtime/src/use-deep-agent-voice.js +999 -0
  179. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -0
  180. package/dist/agent-runtime/src/use-deep-agent-window-sync.d.ts +102 -0
  181. package/dist/agent-runtime/src/use-historical-edit-attachments.d.ts +2 -0
  182. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +84 -0
  183. package/dist/agent-runtime/src/voice-presentation.d.ts +80 -0
  184. package/dist/agent-runtime/src/voice-turn-grouping.d.ts +28 -0
  185. package/dist/agent-runtime/src/voice-wire-types.d.ts +15 -0
  186. package/dist/agent-runtime/src/withdrawn-turns.d.ts +97 -0
  187. package/dist/chat/AthenaChat.cjs +72 -5
  188. package/dist/chat/AthenaChat.cjs.map +1 -1
  189. package/dist/chat/AthenaChat.js +73 -6
  190. package/dist/chat/AthenaChat.js.map +1 -1
  191. package/dist/chat/StatewireApprovalCard.d.ts +1 -1
  192. package/dist/chat/StatewireClientToolBridge.d.ts +1 -1
  193. package/dist/chat/StatewireQueuedMessages.cjs +11 -4
  194. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  195. package/dist/chat/StatewireQueuedMessages.d.ts +1 -1
  196. package/dist/chat/StatewireQueuedMessages.js +11 -4
  197. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  198. package/dist/chat/chat-outbox-rows.cjs +223 -0
  199. package/dist/chat/chat-outbox-rows.cjs.map +1 -0
  200. package/dist/chat/chat-outbox-rows.d.ts +29 -0
  201. package/dist/chat/chat-outbox-rows.js +223 -0
  202. package/dist/chat/chat-outbox-rows.js.map +1 -0
  203. package/dist/chat/statewire-approval.d.ts +1 -1
  204. package/dist/chat/statewire-client-tools.d.ts +1 -1
  205. package/dist/chat/super-grouping/SuperGroupingCard.cjs +3 -1
  206. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  207. package/dist/chat/super-grouping/SuperGroupingCard.d.ts +7 -1
  208. package/dist/chat/super-grouping/SuperGroupingCard.js +3 -1
  209. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  210. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +7 -2
  211. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  212. package/dist/chat/super-grouping/SuperGroupingTranscript.d.ts +2 -2
  213. package/dist/chat/super-grouping/SuperGroupingTranscript.js +7 -2
  214. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  215. package/dist/chat/super-grouping/activity-timeline.cjs +15 -8
  216. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  217. package/dist/chat/super-grouping/activity-timeline.d.ts +18 -8
  218. package/dist/chat/super-grouping/activity-timeline.js +15 -8
  219. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  220. package/dist/chat/use-statewire-approval-request.cjs +36 -0
  221. package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
  222. package/dist/chat/use-statewire-approval-request.d.ts +49 -1
  223. package/dist/chat/use-statewire-approval-request.js +39 -3
  224. package/dist/chat/use-statewire-approval-request.js.map +1 -1
  225. package/dist/chat-ui/composer/tiptap-composer.cjs +102 -3
  226. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  227. package/dist/chat-ui/composer/tiptap-composer.d.ts +32 -1
  228. package/dist/chat-ui/composer/tiptap-composer.js +103 -4
  229. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  230. package/dist/chat-ui/header/conversation-history-panel.d.ts +1 -1
  231. package/dist/chat-ui/index.d.ts +1 -1
  232. package/dist/chat-ui/messages/message-components.cjs +15 -0
  233. package/dist/chat-ui/messages/message-components.cjs.map +1 -1
  234. package/dist/chat-ui/messages/message-components.js +15 -0
  235. package/dist/chat-ui/messages/message-components.js.map +1 -1
  236. package/dist/chat-ui/messages/runtime-message.d.ts +1 -1
  237. package/dist/chat-ui/messages/statewire-continue-run.d.ts +1 -1
  238. package/dist/chat-ui/messages/user-edit-composer.cjs +15 -2
  239. package/dist/chat-ui/messages/user-edit-composer.cjs.map +1 -1
  240. package/dist/chat-ui/messages/user-edit-composer.d.ts +4 -2
  241. package/dist/chat-ui/messages/user-edit-composer.js +15 -2
  242. package/dist/chat-ui/messages/user-edit-composer.js.map +1 -1
  243. package/dist/chat-ui/messages/wake-marker.d.ts +1 -1
  244. package/dist/chat-ui/rich-text/chat-text-schema.cjs +1 -0
  245. package/dist/chat-ui/rich-text/chat-text-schema.cjs.map +1 -1
  246. package/dist/chat-ui/rich-text/chat-text-schema.d.ts +3 -0
  247. package/dist/chat-ui/rich-text/chat-text-schema.js +1 -0
  248. package/dist/chat-ui/rich-text/chat-text-schema.js.map +1 -1
  249. package/dist/chat-ui/statewire.cjs +1 -0
  250. package/dist/chat-ui/statewire.cjs.map +1 -1
  251. package/dist/chat-ui/statewire.d.ts +2 -2
  252. package/dist/chat-ui/statewire.js +2 -1
  253. package/dist/chat-ui/thread/statewire-history-edge.d.ts +1 -1
  254. package/dist/composer/AttachmentContext.cjs +8 -4
  255. package/dist/composer/AttachmentContext.cjs.map +1 -1
  256. package/dist/composer/AttachmentContext.d.ts +7 -0
  257. package/dist/composer/AttachmentContext.js +8 -4
  258. package/dist/composer/AttachmentContext.js.map +1 -1
  259. package/dist/composer/build-composed-message.cjs +34 -0
  260. package/dist/composer/build-composed-message.cjs.map +1 -1
  261. package/dist/composer/build-composed-message.d.ts +20 -0
  262. package/dist/composer/build-composed-message.js +35 -1
  263. package/dist/composer/build-composed-message.js.map +1 -1
  264. package/dist/composer/composer-handoff.cjs +39 -2
  265. package/dist/composer/composer-handoff.cjs.map +1 -1
  266. package/dist/composer/composer-handoff.d.ts +28 -3
  267. package/dist/composer/composer-handoff.js +39 -2
  268. package/dist/composer/composer-handoff.js.map +1 -1
  269. package/dist/composer/useAttachFiles.cjs +15 -2
  270. package/dist/composer/useAttachFiles.cjs.map +1 -1
  271. package/dist/composer/useAttachFiles.d.ts +11 -0
  272. package/dist/composer/useAttachFiles.js +15 -2
  273. package/dist/composer/useAttachFiles.js.map +1 -1
  274. package/dist/composer/useSendMessage.cjs.map +1 -1
  275. package/dist/composer/useSendMessage.d.ts +4 -3
  276. package/dist/composer/useSendMessage.js.map +1 -1
  277. package/dist/diagnostics/athena-diagnostics.cjs.map +1 -1
  278. package/dist/diagnostics/athena-diagnostics.d.ts +3 -1
  279. package/dist/diagnostics/athena-diagnostics.js.map +1 -1
  280. package/dist/index.cjs +13 -0
  281. package/dist/index.cjs.map +1 -1
  282. package/dist/index.d.ts +13 -6
  283. package/dist/index.js +14 -1
  284. package/dist/index.js.map +1 -1
  285. package/dist/offline/chat-outbox.cjs +57 -0
  286. package/dist/offline/chat-outbox.cjs.map +1 -0
  287. package/dist/offline/chat-outbox.d.ts +80 -0
  288. package/dist/offline/chat-outbox.js +57 -0
  289. package/dist/offline/chat-outbox.js.map +1 -0
  290. package/dist/offline/offline-history.d.ts +1 -1
  291. package/dist/provider/AthenaProvider.cjs +162 -8
  292. package/dist/provider/AthenaProvider.cjs.map +1 -1
  293. package/dist/provider/AthenaProvider.d.ts +15 -1
  294. package/dist/provider/AthenaProvider.js +163 -9
  295. package/dist/provider/AthenaProvider.js.map +1 -1
  296. package/dist/provider/statewire-window-context.d.ts +1 -1
  297. package/dist/react/package.json.cjs +1 -1
  298. package/dist/react/package.json.js +1 -1
  299. package/dist/references/src/anchors/file-line-range.d.ts +58 -0
  300. package/dist/references/src/anchors/format.d.ts +21 -0
  301. package/dist/references/src/anchors/message-anchors.d.ts +71 -0
  302. package/dist/references/src/anchors/parse.d.ts +8 -0
  303. package/dist/references/src/anchors/registry-contract.d.ts +24 -0
  304. package/dist/references/src/anchors/registry.d.ts +19 -0
  305. package/dist/references/src/anchors/schemas.d.ts +194 -0
  306. package/dist/references/src/anchors/serialize.d.ts +8 -0
  307. package/dist/references/src/anchors/time.d.ts +78 -0
  308. package/dist/references/src/anchors/types.d.ts +474 -0
  309. package/dist/references/src/asset-bounds.d.ts +27 -0
  310. package/dist/references/src/asset-links.d.ts +23 -0
  311. package/dist/references/src/asset-reference.d.ts +16 -0
  312. package/dist/references/src/formats/format-catalog.d.ts +79 -0
  313. package/dist/references/src/formats/markdown/parse-reference-markdown.d.ts +28 -0
  314. package/dist/references/src/formats/markdown/reference-display-name.d.ts +6 -0
  315. package/dist/references/src/formats/object/asset-object.d.ts +9 -0
  316. package/dist/references/src/formats/object/callable-object.d.ts +6 -0
  317. package/dist/references/src/formats/object/decode-reference-object-payload.d.ts +3 -0
  318. package/dist/references/src/formats/object/external-url-object.d.ts +9 -0
  319. package/dist/references/src/formats/object/group-object.d.ts +9 -0
  320. package/dist/references/src/formats/object/navigation-object.d.ts +9 -0
  321. package/dist/references/src/formats/object/parse-reference-object.d.ts +11 -0
  322. package/dist/references/src/formats/object/person-object.d.ts +9 -0
  323. package/dist/references/src/formats/uri/asset-mention-uri.d.ts +9 -0
  324. package/dist/references/src/formats/uri/asset-spaces-url.d.ts +9 -0
  325. package/dist/references/src/formats/uri/callable-mention-uris.d.ts +9 -0
  326. package/dist/references/src/formats/uri/detect-uri-wire.d.ts +9 -0
  327. package/dist/references/src/formats/uri/group-mention-uri.d.ts +12 -0
  328. package/dist/references/src/formats/uri/navigation-spaces-url.d.ts +14 -0
  329. package/dist/references/src/formats/uri/parse-reference-uri.d.ts +20 -0
  330. package/dist/references/src/formats/uri/person-mention-uri.d.ts +9 -0
  331. package/dist/references/src/formats/uri/template-placeholder.d.ts +12 -0
  332. package/dist/references/src/index.d.ts +47 -0
  333. package/dist/references/src/legacy/index.d.ts +14 -0
  334. package/dist/references/src/legacy/pre-reference-asset-url.d.ts +57 -0
  335. package/dist/references/src/legacy/pre-reference-citation-bridge.d.ts +22 -0
  336. package/dist/references/src/legacy/pre-reference-citation.d.ts +138 -0
  337. package/dist/references/src/legacy/pre-reference-external-url.d.ts +31 -0
  338. package/dist/references/src/legacy/pre-reference-format.d.ts +8 -0
  339. package/dist/references/src/legacy/pre-reference-mention.d.ts +27 -0
  340. package/dist/references/src/legacy/pre-reference-object.d.ts +8 -0
  341. package/dist/references/src/legacy/pre-reference-uri.d.ts +12 -0
  342. package/dist/references/src/legacy.d.ts +2 -0
  343. package/dist/references/src/mention-href-patterns.d.ts +19 -0
  344. package/dist/references/src/mention-node/index.d.ts +5 -0
  345. package/dist/references/src/mention-node/mention-node.d.ts +31 -0
  346. package/dist/references/src/mention-node/resolve-node-attrs.d.ts +27 -0
  347. package/dist/references/src/parse-reference.d.ts +23 -0
  348. package/dist/references/src/schemas.d.ts +463 -0
  349. package/dist/references/src/serialize-reference.d.ts +50 -0
  350. package/dist/references/src/sheet-name.d.ts +10 -0
  351. package/dist/references/src/tool-option-schemas.d.ts +597 -0
  352. package/dist/references/src/types.d.ts +125 -0
  353. package/dist/references/src/version-ref.d.ts +30 -0
  354. package/dist/runtime/statewire-lifecycle.d.ts +1 -1
  355. package/dist/runtime/statewire-model-lane.d.ts +1 -1
  356. package/dist/runtime/statewire-server-lane-context.d.ts +1 -1
  357. package/dist/runtime/statewire-session-key.cjs +7 -0
  358. package/dist/runtime/statewire-session-key.cjs.map +1 -1
  359. package/dist/runtime/statewire-session-key.d.ts +16 -0
  360. package/dist/runtime/statewire-session-key.js +8 -1
  361. package/dist/runtime/statewire-session-key.js.map +1 -1
  362. package/dist/runtime/statewire-session-lane.cjs +48 -0
  363. package/dist/runtime/statewire-session-lane.cjs.map +1 -0
  364. package/dist/runtime/statewire-session-lane.d.ts +29 -0
  365. package/dist/runtime/statewire-session-lane.js +48 -0
  366. package/dist/runtime/statewire-session-lane.js.map +1 -0
  367. package/dist/runtime/statewire-thread-config-lane.d.ts +1 -1
  368. package/dist/runtime/useAthenaStatewireRuntime.cjs +16 -5
  369. package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
  370. package/dist/runtime/useAthenaStatewireRuntime.d.ts +15 -1
  371. package/dist/runtime/useAthenaStatewireRuntime.js +17 -6
  372. package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
  373. package/dist/styles.css +1 -1
  374. package/dist/threads/api.d.ts +1 -1
  375. package/dist/threads/conversation-list-fetcher.d.ts +1 -1
  376. package/dist/threads/index-triggered-refresh.cjs +164 -0
  377. package/dist/threads/index-triggered-refresh.cjs.map +1 -0
  378. package/dist/threads/index-triggered-refresh.d.ts +70 -0
  379. package/dist/threads/index-triggered-refresh.js +164 -0
  380. package/dist/threads/index-triggered-refresh.js.map +1 -0
  381. package/dist/threads/offline-session-list.d.ts +1 -1
  382. package/dist/threads/pull-request-display.d.ts +1 -1
  383. package/dist/threads/session-list-model.d.ts +1 -1
  384. package/dist/threads/session-list-tab-share.cjs +150 -0
  385. package/dist/threads/session-list-tab-share.cjs.map +1 -0
  386. package/dist/threads/session-list-tab-share.d.ts +73 -0
  387. package/dist/threads/session-list-tab-share.js +150 -0
  388. package/dist/threads/session-list-tab-share.js.map +1 -0
  389. package/dist/threads/session-row-parts.d.ts +1 -1
  390. package/dist/threads/sessions-query.d.ts +1 -1
  391. package/dist/threads/statewire-thread-list.cjs +42 -16
  392. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  393. package/dist/threads/statewire-thread-list.d.ts +11 -2
  394. package/dist/threads/statewire-thread-list.js +43 -17
  395. package/dist/threads/statewire-thread-list.js.map +1 -1
  396. package/dist/threads/thread-prefetcher.d.ts +1 -1
  397. package/dist/threads/use-athena-session-attention.d.ts +1 -1
  398. package/dist/threads/use-athena-sessions.cjs +32 -22
  399. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  400. package/dist/threads/use-athena-sessions.js +33 -23
  401. package/dist/threads/use-athena-sessions.js.map +1 -1
  402. package/dist/threads/use-rest-conversation-history.d.ts +1 -1
  403. package/dist/threads/use-statewire-conversation-history.d.ts +5 -5
  404. package/dist/tiptap-markdown-table/src/markdown-table-serializer.d.ts +56 -0
  405. package/dist/tools/NestedPtcMessages.cjs +14 -9
  406. package/dist/tools/NestedPtcMessages.cjs.map +1 -1
  407. package/dist/tools/NestedPtcMessages.d.ts +9 -0
  408. package/dist/tools/NestedPtcMessages.js +6 -1
  409. package/dist/tools/NestedPtcMessages.js.map +1 -1
  410. package/dist/tools/index.d.ts +1 -1
  411. package/dist/tools/primitives.d.ts +1 -1
  412. package/dist/tools/subagent-task-tool-ui.cjs +494 -0
  413. package/dist/tools/subagent-task-tool-ui.cjs.map +1 -0
  414. package/dist/tools/subagent-task-tool-ui.d.ts +109 -0
  415. package/dist/tools/subagent-task-tool-ui.js +494 -0
  416. package/dist/tools/subagent-task-tool-ui.js.map +1 -0
  417. package/dist/tools/tool-fallback.d.ts +1 -1
  418. package/dist/tools/tool-icons.d.ts +1 -1
  419. package/dist/tools/tool-summary.d.ts +1 -1
  420. package/dist/tools/tool-uis.cjs +4 -0
  421. package/dist/tools/tool-uis.cjs.map +1 -1
  422. package/dist/tools/tool-uis.js +4 -0
  423. package/dist/tools/tool-uis.js.map +1 -1
  424. package/dist/voice/chat.cjs +6 -0
  425. package/dist/voice/chat.cjs.map +1 -0
  426. package/dist/voice/chat.d.ts +2 -0
  427. package/dist/voice/chat.js +6 -0
  428. package/dist/voice/chat.js.map +1 -0
  429. package/dist/voice/livekit-join.cjs +119 -0
  430. package/dist/voice/livekit-join.cjs.map +1 -0
  431. package/dist/voice/livekit-join.d.ts +8 -0
  432. package/dist/voice/livekit-join.js +119 -0
  433. package/dist/voice/livekit-join.js.map +1 -0
  434. package/dist/voice/livekit.cjs +32 -0
  435. package/dist/voice/livekit.cjs.map +1 -0
  436. package/dist/voice/livekit.d.ts +80 -0
  437. package/dist/voice/livekit.js +32 -0
  438. package/dist/voice/livekit.js.map +1 -0
  439. package/package.json +20 -10
@@ -1 +1 @@
1
- {"version":3,"file":"use-deep-agent-runtime.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-runtime.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport { isStatewireChannelTeardown } from './errors';\nimport { type DeepAgentModelContextHost, registerDeepAgentRunConfig } from './model-context';\nimport {\n isStorageQuotaError,\n QuotaSafeLocalStorageSession,\n readFailedSendStampsFromRecord,\n readPersistedFailedSendStamps,\n type SessionStorageDegradation,\n} from './quota-safe-local-storage-session';\nimport { createDeepAgentSendRecovery } from './send-recovery';\nimport type { StatewireTransportOptions } from './statewire-transport';\nimport { readStatewireFailedSendLane } from './thread-extras';\nimport { isConfigSyncUnavailableRejection } from './use-deep-agent-config';\nimport { useDeepAgentThread, type UseDeepAgentThreadOptions } from './use-deep-agent-thread';\n\n/** The thread element `useDeepAgentThread` produces — what the host's `useAui`\n * consumes (`useAui({ thread })`). */\nexport type DeepAgentThreadElement = ReturnType<typeof useDeepAgentThread>;\n\n/**\n * Durable command-lane persistence for the thread — where the lane identity and\n * the commands still awaiting a durable verdict live, so a reload resumes the\n * lane instead of minting a new client.\n *\n * - `local-storage`: browser hosts. Backed by {@link QuotaSafeLocalStorageSession}\n * (the upstream `LocalStorageSession` contract with Athena keys, legacy\n * metadata, and retention). A storage failure after mounting — the origin\n * out of quota after statewire's own sweep, a lockdown-mode write refusal —\n * degrades the session to memory-only persistence and is reported through\n * `onStorageDegraded` (default: one console warning); it never stops the\n * connection. Guarded by a shared availability probe: SSR, storage-blocked\n * iframes, and locked-down browsers keep the session process-local, exactly\n * as before the seam existed, while an origin that is merely full mounts the\n * session and lets it degrade. `key` scopes the stored lane — a thread id is\n * only meaningful against the backend (and, where relevant, principal) that\n * minted it, so include the sync-host URL.\n * - `session-store`: React Native hosts pass a hydrated library store backed\n * by AsyncStorage. Its synchronous `load()` is\n * also the send-recovery freshness gate's view of the persisted failed lane,\n * so a store that persists `failed` gets the same 24 h staleness rule as the\n * browser hosts.\n * - `false`: process-local session (a reload mints a new client).\n */\nexport type DeepAgentSessionPersistence =\n | {\n kind: 'local-storage';\n key: (threadId: string) => string;\n onStorageDegraded?: (degradation: SessionStorageDegradation) => void;\n }\n | { kind: 'session-store'; store: NonNullable<StatewireTransportOptions['sessionStore']> }\n | false;\n\n/** Structural view of the browser storage global — this package compiles\n * without the DOM lib (React Native honesty; see `globals.d.ts`). */\ntype StorageGlobals = {\n localStorage?: {\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n };\n navigator?: { locks?: unknown };\n};\n\n/**\n * Whether a localStorage-backed session can persist here. A write probe, not a\n * `typeof` check: storage-blocked iframes (SDK embeds under third-party-storage\n * blocking) throw from the `localStorage` accessor itself, and lockdown-mode\n * origins throw from `setItem` — each of those must mean \"stay process-local\",\n * never a crash at mount. An origin that is merely out of quota still reads\n * and takes locks, so it mounts the session: {@link QuotaSafeLocalStorageSession}\n * degrades that to memory-only persistence and recovers when room frees,\n * where staying process-local would give up cross-tab sharing for the whole\n * page load over a condition that clears.\n *\n * The Web Locks API is probed too: the session storage serializes the shared\n * record across tabs through `navigator.locks` and refuses to mount without it\n * (the same precondition as the vendor `LocalStorageSession`), so an origin\n * with localStorage but no Web Locks — older WebViews, Safari before 15.4 —\n * must also stay process-local instead of throwing at mount.\n */\nexport function canPersistDeepAgentSession(): boolean {\n try {\n const globals = globalThis as StorageGlobals;\n if (!globals.navigator?.locks) return false;\n const storage = globals.localStorage;\n if (!storage) return false;\n const probeKey = '__athena_statewire_session_probe__';\n try {\n storage.setItem(probeKey, probeKey);\n storage.removeItem(probeKey);\n } catch (error) {\n return isStorageQuotaError(error);\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** A host session store's current record, or `null` when the read throws —\n * the recovery gate must never take the runtime down over a storage fault. */\nfunction loadSessionRecord(\n store: NonNullable<StatewireTransportOptions['sessionStore']>\n): ReturnType<NonNullable<StatewireTransportOptions['sessionStore']>['load']> | null {\n try {\n return store.load();\n } catch {\n return null;\n }\n}\n\n/**\n * The shared tail of every surface's transport error policy: channel teardown\n * is lifecycle noise (logged at debug), as is `config_sync_unavailable` — only\n * `config/*` writes emit it, and the host's config sync already handles it\n * through its own command promise (regionally-pinned workspaces run on\n * local-only config); everything else is a real transport error. Hosts with their own error chain\n * (paywall, telemetry, send-failure stores) end it with this so the fallback\n * logging stays uniform per surface.\n */\nexport function logUnhandledStatewireError(surface: string, error: Error): void {\n if (isStatewireChannelTeardown(error)) {\n console.debug(`[${surface}] statewire channel teardown:`, error);\n return;\n }\n if (isConfigSyncUnavailableRejection(error)) {\n console.debug(`[${surface}] config sync unavailable (handled by config sync):`, error);\n return;\n }\n console.error(`[${surface}] statewire transport error:`, error);\n}\n\n/**\n * The imperative thread-state slice of an assistant-ui client — structural so\n * web and native `useAui` results both satisfy it. The send-recovery layer\n * reads the statewire thread extras through it (the sanctioned imperative\n * pattern: `aui.thread().getState()` inside callbacks/effects, never render).\n */\nexport interface DeepAgentThreadStateClientHost {\n thread: () => { getState: () => { extras?: unknown } };\n subscribe: (listener: () => void) => () => void;\n}\n\n/** Deep-agent runConfig registration on the ambient model context (see\n * {@link registerDeepAgentRunConfig}). */\nexport interface DeepAgentRunConfigRegistration {\n /**\n * Builds the `runConfig` that drives the run. The core pulls it when the\n * model context notifies (mount and each key change); the server reads that\n * synced value at command admission. The per-render ref makes each pull use\n * the latest closure but does not trigger a pull itself.\n */\n get: () => Record<string, unknown>;\n /**\n * Re-registers the provider and notifies model-context sync when this value\n * changes (reference equality). Include getter inputs that can change while\n * mounted; they reach the server only after a key change triggers a pull.\n */\n key?: unknown;\n}\n\nexport interface UseDeepAgentRuntimeOptions<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n> extends Omit<UseDeepAgentThreadOptions, 'storage' | 'sessionStore'> {\n /** Host surface tag for the shared fallback error logging (e.g.\n * `'AthenaDeepAgent'`, `'AthenaSDK'`, `'ChromeStatewire'`). */\n surface: string;\n /** Durable command-lane persistence; defaults to process-local. */\n session?: DeepAgentSessionPersistence;\n /**\n * Builds the host's assistant-ui client from the thread element — pass the\n * platform `useAui` (web hosts from `@assistant-ui/react`, React Native\n * hosts from `@assistant-ui/react-native`; this package imports neither).\n * Called unconditionally on every render, so it MUST be (or call) a hook\n * following the rules of hooks — define it at module scope with a `use*`\n * name: `const useHostClient = (thread: DeepAgentThreadElement) =>\n * useAui({ thread })`.\n */\n useClient: (thread: DeepAgentThreadElement) => TClient;\n /** Registers the deep-agent runConfig on the client's model context. Hosts\n * that register elsewhere (e.g. a bridge component mounted under the\n * provider) omit it. */\n runConfig?: DeepAgentRunConfigRegistration;\n}\n\n/**\n * The configurable deep-agent statewire runtime — the one hook every Athena\n * chat surface (Olympus, `@athenaintel/react` SDK, Chrome extension, Office\n * add-in, mobile) mounts its assistant-ui client through.\n *\n * Composes the pieces every surface previously wired by hand:\n * `useDeepAgentThread` (attach lifecycle, auth parking, lane projection,\n * connection/running observers), durable session persistence with the shared\n * availability guard, transport-level send recovery (failed sends the server\n * never judged auto-retry under their original message id — `send-recovery.ts`),\n * the platform client via `useClient`, and the\n * runConfig model-context registration on provider notifications. Everything\n * host-specific — auth headers, run-config building, error policy, adapters,\n * diagnostics recorders — stays an option, so per-surface behavior is\n * configuration, not a fork.\n */\nexport function useDeepAgentRuntime<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n>(options: UseDeepAgentRuntimeOptions<TClient>): TClient {\n const {\n surface,\n session = false,\n useClient,\n runConfig,\n onError,\n onStateChange,\n onCommandChange,\n ...threadOptions\n } = options;\n\n // Probed once per mount, like every browser host did individually: an origin\n // that cannot persist stays process-local for the mount's lifetime.\n const [canPersistLocalSession] = useState(canPersistDeepAgentSession);\n\n // Per-render refs so the transport never remounts on a new closure identity\n // and always reads the latest policy.\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n const surfaceRef = useRef(surface);\n surfaceRef.current = surface;\n const onStateChangeRef = useRef(onStateChange);\n onStateChangeRef.current = onStateChange;\n const onCommandChangeRef = useRef(onCommandChange);\n onCommandChangeRef.current = onCommandChange;\n const diagnosticsRef = useRef(threadOptions.diagnostics);\n diagnosticsRef.current = threadOptions.diagnostics;\n const clientRef = useRef<TClient | null>(null);\n\n // Where the persisted session record lives, for the recovery freshness gate\n // (read per sweep — undefined means \"no persistence, everything is fresh\").\n const failureStampsRef = useRef<(() => ReadonlyMap<string, number> | null) | undefined>(\n undefined\n );\n failureStampsRef.current =\n session === false\n ? undefined\n : session.kind === 'local-storage'\n ? canPersistLocalSession\n ? () => readPersistedFailedSendStamps(session.key(threadOptions.threadId))\n : undefined\n : () => readFailedSendStampsFromRecord(loadSessionRecord(session.store));\n\n // Send recovery, keyed by attach identity exactly like the thread's session\n // (a switch or re-attach gets fresh hydration gating and retry budgets). The\n // controller re-dispatches failed sends the server never judged; see\n // `send-recovery.ts` for the contract.\n const attachId =\n threadOptions.attachKey === undefined\n ? threadOptions.threadId\n : `${threadOptions.threadId}:${threadOptions.attachKey}`;\n // biome-ignore lint/correctness/useExhaustiveDependencies: keyed by attach identity on purpose; every other input is read through a per-render ref.\n const sendRecovery = useMemo(\n () =>\n createDeepAgentSendRecovery({\n lane: () => {\n const client = clientRef.current;\n if (!client) return null;\n return readStatewireFailedSendLane(client.thread().getState().extras);\n },\n failureStamps: () => failureStampsRef.current?.() ?? null,\n diagnostics: () => diagnosticsRef.current,\n }),\n [attachId]\n );\n useEffect(() => () => sendRecovery.dispose(), [sendRecovery]);\n const sendRecoveryRef = useRef(sendRecovery);\n sendRecoveryRef.current = sendRecovery;\n\n const thread = useDeepAgentThread({\n ...threadOptions,\n ...(session !== false &&\n session.kind === 'local-storage' &&\n canPersistLocalSession && {\n storage: {\n session: QuotaSafeLocalStorageSession({\n threadId: threadOptions.threadId,\n key: session.key,\n ...(session.onStorageDegraded === undefined\n ? {}\n : { onStorageDegraded: session.onStorageDegraded }),\n }),\n },\n }),\n ...(session !== false && session.kind === 'session-store' && { sessionStore: session.store }),\n onStateChange: (state, ctx) => {\n sendRecoveryRef.current.observeStateChange(state);\n onStateChangeRef.current?.(state, ctx);\n },\n onCommandChange: (update, ctx) => {\n sendRecoveryRef.current.observeCommand(update);\n onCommandChangeRef.current?.(update, ctx);\n },\n onError: (error) => {\n const handler = onErrorRef.current;\n if (handler) {\n handler(error);\n return;\n }\n logUnhandledStatewireError(surfaceRef.current, error);\n },\n });\n\n const client = useClient(thread);\n clientRef.current = client;\n\n // A locked shared journal can publish failed history after onCommandChange,\n // with no canonical state change to wake recovery. Observe the client that\n // owns the visible failed lane; the controller guards in-flight retries.\n useEffect(() => {\n const unsubscribe = client.subscribe(() => sendRecovery.observeFailedLaneChange());\n sendRecovery.observeFailedLaneChange();\n return unsubscribe;\n }, [client, sendRecovery]);\n\n // Commands travel bare, so the runConfig that drives the run rides the\n // ambient model context: `contextSync: 'command-send'` mirrors it to the\n // server, which reads `config.runConfig` at command admission. The core pulls\n // on model-context notifications; the per-render ref ensures each pull uses\n // the latest closure but does not trigger a pull itself.\n const getRunConfigRef = useRef(runConfig?.get);\n getRunConfigRef.current = runConfig?.get;\n const hasRunConfig = runConfig !== undefined;\n const runConfigKey = runConfig?.key;\n useEffect(() => {\n if (!hasRunConfig) return undefined;\n return registerDeepAgentRunConfig(client, () => getRunConfigRef.current?.() ?? {});\n }, [client, hasRunConfig, runConfigKey]);\n\n return client;\n}\n\n"],"names":["isStorageQuotaError","isStatewireChannelTeardown","isConfigSyncUnavailableRejection","useState","useRef","readPersistedFailedSendStamps","readFailedSendStampsFromRecord","sendRecovery","useMemo","createDeepAgentSendRecovery","client","readStatewireFailedSendLane","useEffect","useDeepAgentThread","QuotaSafeLocalStorageSession","registerDeepAgentRunConfig"],"mappings":";;;;;;;;;;AAgFO,SAAS,6BAAsC;;AACpD,MAAI;AACF,UAAM,UAAU;AAChB,QAAI,GAAC,aAAQ,cAAR,mBAAmB,OAAO,QAAO;AACtC,UAAM,UAAU,QAAQ;AACxB,QAAI,CAAC,QAAS,QAAO;AACrB,UAAM,WAAW;AACjB,QAAI;AACF,cAAQ,QAAQ,UAAU,QAAQ;AAClC,cAAQ,WAAW,QAAQ;AAAA,IAC7B,SAAS,OAAO;AACd,aAAOA,6BAAAA,oBAAoB,KAAK;AAAA,IAClC;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAIA,SAAS,kBACP,OACmF;AACnF,MAAI;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,SAAS;AACX,gBAAQ,KAAK;AACb;AAAA,MACF;AACA,iCAA2B,WAAW,SAAS,KAAK;AAAA,IACtD;AAAA,EAAA,CACD;AAED,QAAM,SAAS,UAAU,MAAM;AAC/B,YAAU,UAAU;AAKpBF,QAAAA,UAAU,MAAM;AACd,UAAM,cAAc,OAAO,UAAU,MAAML,eAAa,yBAAyB;AACjFA,mBAAa,wBAAA;AACb,WAAO;AAAA,EACT,GAAG,CAAC,QAAQA,cAAY,CAAC;AAOzB,QAAM,kBAAkBH,MAAAA,OAAO,uCAAW,GAAG;AAC7C,kBAAgB,UAAU,uCAAW;AACrC,QAAM,eAAe,cAAc;AACnC,QAAM,eAAe,uCAAW;AAChCQ,QAAAA,UAAU,MAAM;AACd,QAAI,CAAC,aAAc,QAAO;AAC1B,WAAOG,aAAAA,2BAA2B,QAAQ,MAAA;;AAAM,oCAAgB,YAAhB,6CAA+B,CAAA;AAAA,KAAE;AAAA,EACnF,GAAG,CAAC,QAAQ,cAAc,YAAY,CAAC;AAEvC,SAAO;AACT;;;;"}
1
+ {"version":3,"file":"use-deep-agent-runtime.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-runtime.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport { isStatewireChannelTeardown } from './errors';\nimport { type DeepAgentModelContextHost, registerDeepAgentRunConfig } from './model-context';\nimport {\n isStorageQuotaError,\n QuotaSafeLocalStorageSession,\n readFailedSendStampsFromRecord,\n readPersistedFailedSendStamps,\n type SessionStorageDegradation,\n} from './quota-safe-local-storage-session';\nimport { createDeepAgentSendRecovery } from './send-recovery';\nimport type { StatewireTransportOptions } from './statewire-transport';\nimport { readStatewireFailedSendLane } from './thread-extras';\nimport { isConfigSyncUnavailableRejection } from './use-deep-agent-config';\nimport { useDeepAgentThread, type UseDeepAgentThreadOptions } from './use-deep-agent-thread';\n\n/** The thread element `useDeepAgentThread` produces — what the host's `useAui`\n * consumes (`useAui({ thread })`). */\nexport type DeepAgentThreadElement = ReturnType<typeof useDeepAgentThread>;\n\n/**\n * Durable command-lane persistence for the thread — where the lane identity and\n * the commands still awaiting a durable verdict live, so a reload resumes the\n * lane instead of minting a new client.\n *\n * - `local-storage`: browser hosts. Backed by {@link QuotaSafeLocalStorageSession}\n * (the upstream `LocalStorageSession` contract with Athena keys, legacy\n * metadata, and retention). A storage failure after mounting — the origin\n * out of quota after statewire's own sweep, a lockdown-mode write refusal —\n * degrades the session to memory-only persistence and is reported through\n * `onStorageDegraded` (default: one console warning); it never stops the\n * connection. Guarded by a shared availability probe: SSR, storage-blocked\n * iframes, and locked-down browsers keep the session process-local, exactly\n * as before the seam existed, while an origin that is merely full mounts the\n * session and lets it degrade. `key` scopes the stored lane — a thread id is\n * only meaningful against the backend (and, where relevant, principal) that\n * minted it, so include the sync-host URL.\n * - `session-store`: React Native hosts pass a hydrated library store backed\n * by AsyncStorage. Its synchronous `load()` is\n * also the send-recovery freshness gate's view of the persisted failed lane,\n * so a store that persists `failed` gets the same 24 h staleness rule as the\n * browser hosts.\n * - `pending`: the principal the lane is scoped by is not known yet (the\n * host's signed-in user is still loading). See {@link DeepAgentPendingSession}.\n * - `false`: process-local session (a reload mints a new client).\n *\n * A `local-storage` `key` must name the same lane for the whole life of the\n * thread's mount. The statewire session that mounts on a lane keeps the client\n * id, lane clocks and journal it loaded there; moved to another key, it carries\n * them along, and the record it left keeps the same client id with a stale\n * clock and whatever it had journaled. Every later mount that loads that record\n * resends its journal and stamps early commands from its clock, at or below the\n * watermark the server keeps for the id, so the server absorbs each one as a\n * replay and answers `expired`. A host whose principal arrives after mount\n * passes `pending` until it does, never a stand-in key.\n */\nexport type DeepAgentSessionPersistence =\n | {\n kind: 'local-storage';\n key: (threadId: string) => string;\n onStorageDegraded?: (degradation: SessionStorageDegradation) => void;\n }\n | { kind: 'session-store'; store: NonNullable<StatewireTransportOptions['sessionStore']> }\n | DeepAgentPendingSession\n | false;\n\n/**\n * The durable lane's principal is not known yet. A lane belongs to one\n * principal and a mounted session cannot move to another lane (see\n * {@link DeepAgentSessionPersistence}), so nothing is mounted, nothing is\n * journaled and the transport stays parked — no dial — until the host passes\n * the real persistence. The park is an attach identity of its own: the attach\n * that follows makes every per-attach decision afresh (the remembered-snapshot\n * seed, the pooled hello, which the park leaves in the pool) and dials the real\n * lane once, as the thread's first attach. The park carries no connection\n * message, so it reads like a never-started chat rather than a paused one; a\n * host suspension, when one applies, wins.\n */\nexport type DeepAgentPendingSession = { kind: 'pending' };\n\n/**\n * The attach key a pending-lane park runs under. It differs from every key the\n * host passes, so the real attach after it is a new attach identity.\n */\nexport function pendingSessionAttachKey(attachKey: string | number | undefined): string {\n return `session-pending:${attachKey ?? ''}`;\n}\n\n/** Structural view of the browser storage global — this package compiles\n * without the DOM lib (React Native honesty; see `globals.d.ts`). */\ntype StorageGlobals = {\n localStorage?: {\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n };\n navigator?: { locks?: unknown };\n};\n\n/**\n * Whether a localStorage-backed session can persist here. A write probe, not a\n * `typeof` check: storage-blocked iframes (SDK embeds under third-party-storage\n * blocking) throw from the `localStorage` accessor itself, and lockdown-mode\n * origins throw from `setItem` — each of those must mean \"stay process-local\",\n * never a crash at mount. An origin that is merely out of quota still reads\n * and takes locks, so it mounts the session: {@link QuotaSafeLocalStorageSession}\n * degrades that to memory-only persistence and recovers when room frees,\n * where staying process-local would give up cross-tab sharing for the whole\n * page load over a condition that clears.\n *\n * The Web Locks API is probed too: the session storage serializes the shared\n * record across tabs through `navigator.locks` and refuses to mount without it\n * (the same precondition as the vendor `LocalStorageSession`), so an origin\n * with localStorage but no Web Locks — older WebViews, Safari before 15.4 —\n * must also stay process-local instead of throwing at mount.\n */\nexport function canPersistDeepAgentSession(): boolean {\n try {\n const globals = globalThis as StorageGlobals;\n if (!globals.navigator?.locks) return false;\n const storage = globals.localStorage;\n if (!storage) return false;\n const probeKey = '__athena_statewire_session_probe__';\n try {\n storage.setItem(probeKey, probeKey);\n storage.removeItem(probeKey);\n } catch (error) {\n return isStorageQuotaError(error);\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** A host session store's current record, or `null` when the read throws —\n * the recovery gate must never take the runtime down over a storage fault. */\nfunction loadSessionRecord(\n store: NonNullable<StatewireTransportOptions['sessionStore']>\n): ReturnType<NonNullable<StatewireTransportOptions['sessionStore']>['load']> | null {\n try {\n return store.load();\n } catch {\n return null;\n }\n}\n\n/**\n * The shared tail of every surface's transport error policy: channel teardown\n * is lifecycle noise (logged at debug), as is `config_sync_unavailable` — only\n * `config/*` writes emit it, and the host's config sync already handles it\n * through its own command promise (regionally-pinned workspaces run on\n * local-only config); everything else is a real transport error. Hosts with their own error chain\n * (paywall, telemetry, send-failure stores) end it with this so the fallback\n * logging stays uniform per surface.\n */\nexport function logUnhandledStatewireError(surface: string, error: Error): void {\n if (isStatewireChannelTeardown(error)) {\n console.debug(`[${surface}] statewire channel teardown:`, error);\n return;\n }\n if (isConfigSyncUnavailableRejection(error)) {\n console.debug(`[${surface}] config sync unavailable (handled by config sync):`, error);\n return;\n }\n console.error(`[${surface}] statewire transport error:`, error);\n}\n\n/**\n * The imperative thread-state slice of an assistant-ui client — structural so\n * web and native `useAui` results both satisfy it. The send-recovery layer\n * reads the statewire thread extras through it (the sanctioned imperative\n * pattern: `aui.thread().getState()` inside callbacks/effects, never render).\n */\nexport interface DeepAgentThreadStateClientHost {\n thread: () => { getState: () => { extras?: unknown } };\n subscribe: (listener: () => void) => () => void;\n}\n\n/** Deep-agent runConfig registration on the ambient model context (see\n * {@link registerDeepAgentRunConfig}). */\nexport interface DeepAgentRunConfigRegistration {\n /**\n * Builds the `runConfig` that drives the run. The core pulls it when the\n * model context notifies (mount and each key change); the server reads that\n * synced value at command admission. The per-render ref makes each pull use\n * the latest closure but does not trigger a pull itself.\n */\n get: () => Record<string, unknown>;\n /**\n * Re-registers the provider and notifies model-context sync when this value\n * changes (reference equality). Include getter inputs that can change while\n * mounted; they reach the server only after a key change triggers a pull.\n */\n key?: unknown;\n}\n\nexport interface UseDeepAgentRuntimeOptions<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n> extends Omit<UseDeepAgentThreadOptions, 'storage' | 'sessionStore'> {\n /** Host surface tag for the shared fallback error logging (e.g.\n * `'AthenaDeepAgent'`, `'AthenaSDK'`, `'ChromeStatewire'`). */\n surface: string;\n /** Durable command-lane persistence; defaults to process-local. */\n session?: DeepAgentSessionPersistence;\n /**\n * Builds the host's assistant-ui client from the thread element — pass the\n * platform `useAui` (web hosts from `@assistant-ui/react`, React Native\n * hosts from `@assistant-ui/react-native`; this package imports neither).\n * Called unconditionally on every render, so it MUST be (or call) a hook\n * following the rules of hooks — define it at module scope with a `use*`\n * name: `const useHostClient = (thread: DeepAgentThreadElement) =>\n * useAui({ thread })`.\n */\n useClient: (thread: DeepAgentThreadElement) => TClient;\n /** Registers the deep-agent runConfig on the client's model context. Hosts\n * that register elsewhere (e.g. a bridge component mounted under the\n * provider) omit it. */\n runConfig?: DeepAgentRunConfigRegistration;\n}\n\n/**\n * The configurable deep-agent statewire runtime — the one hook every Athena\n * chat surface (Olympus, `@athenaintel/react` SDK, Chrome extension, Office\n * add-in, mobile) mounts its assistant-ui client through.\n *\n * Composes the pieces every surface previously wired by hand:\n * `useDeepAgentThread` (attach lifecycle, auth parking, lane projection,\n * connection/running observers), durable session persistence with the shared\n * availability guard, transport-level send recovery (failed sends the server\n * never judged auto-retry under their original message id — `send-recovery.ts`),\n * the platform client via `useClient`, and the\n * runConfig model-context registration on provider notifications. Everything\n * host-specific — auth headers, run-config building, error policy, adapters,\n * diagnostics recorders — stays an option, so per-surface behavior is\n * configuration, not a fork.\n */\nexport function useDeepAgentRuntime<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n>(options: UseDeepAgentRuntimeOptions<TClient>): TClient {\n const {\n surface,\n session = false,\n useClient,\n runConfig,\n onError,\n onStateChange,\n onCommandChange,\n ...threadOptions\n } = options;\n\n // Probed once per mount, like every browser host did individually: an origin\n // that cannot persist stays process-local for the mount's lifetime.\n const [canPersistLocalSession] = useState(canPersistDeepAgentSession);\n\n // Per-render refs so the transport never remounts on a new closure identity\n // and always reads the latest policy.\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n const surfaceRef = useRef(surface);\n surfaceRef.current = surface;\n const onStateChangeRef = useRef(onStateChange);\n onStateChangeRef.current = onStateChange;\n const onCommandChangeRef = useRef(onCommandChange);\n onCommandChangeRef.current = onCommandChange;\n const diagnosticsRef = useRef(threadOptions.diagnostics);\n diagnosticsRef.current = threadOptions.diagnostics;\n const clientRef = useRef<TClient | null>(null);\n\n // Where the persisted session record lives, for the recovery freshness gate\n // (read per sweep — undefined means \"no persistence, everything is fresh\").\n const failureStampsRef = useRef<(() => ReadonlyMap<string, number> | null) | undefined>(\n undefined\n );\n failureStampsRef.current =\n session === false || session.kind === 'pending'\n ? undefined\n : session.kind === 'local-storage'\n ? canPersistLocalSession\n ? () => readPersistedFailedSendStamps(session.key(threadOptions.threadId))\n : undefined\n : () => readFailedSendStampsFromRecord(loadSessionRecord(session.store));\n\n // A pending lane parks the thread under an attach identity of its own (see\n // `DeepAgentPendingSession`), so the attach once the lane is known is new.\n const sessionPending = session !== false && session.kind === 'pending';\n const attachKey = sessionPending\n ? pendingSessionAttachKey(threadOptions.attachKey)\n : threadOptions.attachKey;\n\n // Send recovery, keyed by attach identity exactly like the thread's session\n // (a switch or re-attach gets fresh hydration gating and retry budgets). The\n // controller re-dispatches failed sends the server never judged; see\n // `send-recovery.ts` for the contract.\n const attachId =\n attachKey === undefined ? threadOptions.threadId : `${threadOptions.threadId}:${attachKey}`;\n // biome-ignore lint/correctness/useExhaustiveDependencies: keyed by attach identity on purpose; every other input is read through a per-render ref.\n const sendRecovery = useMemo(\n () =>\n createDeepAgentSendRecovery({\n lane: () => {\n const client = clientRef.current;\n if (!client) return null;\n return readStatewireFailedSendLane(client.thread().getState().extras);\n },\n failureStamps: () => failureStampsRef.current?.() ?? null,\n diagnostics: () => diagnosticsRef.current,\n }),\n [attachId]\n );\n useEffect(() => () => sendRecovery.dispose(), [sendRecovery]);\n const sendRecoveryRef = useRef(sendRecovery);\n sendRecoveryRef.current = sendRecovery;\n\n const thread = useDeepAgentThread({\n ...threadOptions,\n ...(attachKey !== undefined && { attachKey }),\n // Parked without a message (a host suspension, when one applies, wins):\n // nothing dials and nothing journals until the lane is known. What paints\n // the first frame is the real attach's to report, not the park's.\n ...(sessionPending && {\n suspended: threadOptions.suspended || {},\n onAttachSource: undefined,\n }),\n // A pooled dial for the thread is the real attach's to take: a park that\n // only waits for the lane neither takes nor discards it. A host suspension\n // still discards it, as it does without a pending lane.\n ...(sessionPending && !threadOptions.suspended && { prewarmPool: undefined }),\n ...(session !== false &&\n session.kind === 'local-storage' &&\n canPersistLocalSession && {\n storage: {\n session: QuotaSafeLocalStorageSession({\n threadId: threadOptions.threadId,\n key: session.key,\n ...(session.onStorageDegraded === undefined\n ? {}\n : { onStorageDegraded: session.onStorageDegraded }),\n }),\n },\n }),\n ...(session !== false && session.kind === 'session-store' && { sessionStore: session.store }),\n onStateChange: (state, ctx) => {\n sendRecoveryRef.current.observeStateChange(state);\n onStateChangeRef.current?.(state, ctx);\n },\n onCommandChange: (update, ctx) => {\n sendRecoveryRef.current.observeCommand(update);\n onCommandChangeRef.current?.(update, ctx);\n },\n onError: (error) => {\n const handler = onErrorRef.current;\n if (handler) {\n handler(error);\n return;\n }\n logUnhandledStatewireError(surfaceRef.current, error);\n },\n });\n\n const client = useClient(thread);\n clientRef.current = client;\n\n // A locked shared journal can publish failed history after onCommandChange,\n // with no canonical state change to wake recovery. Observe the client that\n // owns the visible failed lane; the controller guards in-flight retries.\n useEffect(() => {\n const unsubscribe = client.subscribe(() => sendRecovery.observeFailedLaneChange());\n sendRecovery.observeFailedLaneChange();\n return unsubscribe;\n }, [client, sendRecovery]);\n\n // Commands travel bare, so the runConfig that drives the run rides the\n // ambient model context: `contextSync: 'command-send'` mirrors it to the\n // server, which reads `config.runConfig` at command admission. The core pulls\n // on model-context notifications; the per-render ref ensures each pull uses\n // the latest closure but does not trigger a pull itself.\n const getRunConfigRef = useRef(runConfig?.get);\n getRunConfigRef.current = runConfig?.get;\n const hasRunConfig = runConfig !== undefined;\n const runConfigKey = runConfig?.key;\n useEffect(() => {\n if (!hasRunConfig) return undefined;\n return registerDeepAgentRunConfig(client, () => getRunConfigRef.current?.() ?? {});\n }, [client, hasRunConfig, runConfigKey]);\n\n return client;\n}\n\n"],"names":["isStorageQuotaError","isStatewireChannelTeardown","isConfigSyncUnavailableRejection","useState","useRef","readPersistedFailedSendStamps","readFailedSendStampsFromRecord","sendRecovery","useMemo","createDeepAgentSendRecovery","client","readStatewireFailedSendLane","useEffect","useDeepAgentThread","QuotaSafeLocalStorageSession","registerDeepAgentRunConfig"],"mappings":";;;;;;;;;;AAoFO,SAAS,wBAAwB,WAAgD;AACtF,SAAO,mBAAmB,aAAa,EAAE;AAC3C;AA6BO,SAAS,6BAAsC;;AACpD,MAAI;AACF,UAAM,UAAU;AAChB,QAAI,GAAC,aAAQ,cAAR,mBAAmB,OAAO,QAAO;AACtC,UAAM,UAAU,QAAQ;AACxB,QAAI,CAAC,QAAS,QAAO;AACrB,UAAM,WAAW;AACjB,QAAI;AACF,cAAQ,QAAQ,UAAU,QAAQ;AAClC,cAAQ,WAAW,QAAQ;AAAA,IAC7B,SAAS,OAAO;AACd,aAAOA,6BAAAA,oBAAoB,KAAK;AAAA,IAClC;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAIA,SAAS,kBACP,OACmF;AACnF,MAAI;AACF,WAAO,MAAM,KAAA;AAAA,EACf,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAWO,SAAS,2BAA2B,SAAiB,OAAoB;AAC9E,MAAIC,OAAAA,2BAA2B,KAAK,GAAG;AACrC,YAAQ,MAAM,IAAI,OAAO,iCAAiC,KAAK;AAC/D;AAAA,EACF;AACA,MAAIC,mBAAAA,iCAAi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C,+BAAmB,YAAnB,4CAA6B,QAAQ;AAAA,IACvC;AAAA,IACA,SAAS,CAAC,UAAU;AAClB,YAAM,UAAU,WAAW;AAC3B,UAAI,SAAS;AACX,gBAAQ,KAAK;AACb;AAAA,MACF;AACA,iCAA2B,WAAW,SAAS,KAAK;AAAA,IACtD;AAAA,EAAA,CACD;AAED,QAAM,SAAS,UAAU,MAAM;AAC/B,YAAU,UAAU;AAKpBF,QAAAA,UAAU,MAAM;AACd,UAAM,cAAc,OAAO,UAAU,MAAML,eAAa,yBAAyB;AACjFA,mBAAa,wBAAA;AACb,WAAO;AAAA,EACT,GAAG,CAAC,QAAQA,cAAY,CAAC;AAOzB,QAAM,kBAAkBH,MAAAA,OAAO,uCAAW,GAAG;AAC7C,kBAAgB,UAAU,uCAAW;AACrC,QAAM,eAAe,cAAc;AACnC,QAAM,eAAe,uCAAW;AAChCQ,QAAAA,UAAU,MAAM;AACd,QAAI,CAAC,aAAc,QAAO;AAC1B,WAAOG,aAAAA,2BAA2B,QAAQ,MAAA;;AAAM,oCAAgB,YAAhB,6CAA+B,CAAA;AAAA,KAAE;AAAA,EACnF,GAAG,CAAC,QAAQ,cAAc,YAAY,CAAC;AAEvC,SAAO;AACT;;;;;"}
@@ -0,0 +1,168 @@
1
+ import { type DeepAgentModelContextHost } from './model-context';
2
+ import { type SessionStorageDegradation } from './quota-safe-local-storage-session';
3
+ import type { StatewireTransportOptions } from './statewire-transport';
4
+ import { useDeepAgentThread, type UseDeepAgentThreadOptions } from './use-deep-agent-thread';
5
+ /** The thread element `useDeepAgentThread` produces — what the host's `useAui`
6
+ * consumes (`useAui({ thread })`). */
7
+ export type DeepAgentThreadElement = ReturnType<typeof useDeepAgentThread>;
8
+ /**
9
+ * Durable command-lane persistence for the thread — where the lane identity and
10
+ * the commands still awaiting a durable verdict live, so a reload resumes the
11
+ * lane instead of minting a new client.
12
+ *
13
+ * - `local-storage`: browser hosts. Backed by {@link QuotaSafeLocalStorageSession}
14
+ * (the upstream `LocalStorageSession` contract with Athena keys, legacy
15
+ * metadata, and retention). A storage failure after mounting — the origin
16
+ * out of quota after statewire's own sweep, a lockdown-mode write refusal —
17
+ * degrades the session to memory-only persistence and is reported through
18
+ * `onStorageDegraded` (default: one console warning); it never stops the
19
+ * connection. Guarded by a shared availability probe: SSR, storage-blocked
20
+ * iframes, and locked-down browsers keep the session process-local, exactly
21
+ * as before the seam existed, while an origin that is merely full mounts the
22
+ * session and lets it degrade. `key` scopes the stored lane — a thread id is
23
+ * only meaningful against the backend (and, where relevant, principal) that
24
+ * minted it, so include the sync-host URL.
25
+ * - `session-store`: React Native hosts pass a hydrated library store backed
26
+ * by AsyncStorage. Its synchronous `load()` is
27
+ * also the send-recovery freshness gate's view of the persisted failed lane,
28
+ * so a store that persists `failed` gets the same 24 h staleness rule as the
29
+ * browser hosts.
30
+ * - `pending`: the principal the lane is scoped by is not known yet (the
31
+ * host's signed-in user is still loading). See {@link DeepAgentPendingSession}.
32
+ * - `false`: process-local session (a reload mints a new client).
33
+ *
34
+ * A `local-storage` `key` must name the same lane for the whole life of the
35
+ * thread's mount. The statewire session that mounts on a lane keeps the client
36
+ * id, lane clocks and journal it loaded there; moved to another key, it carries
37
+ * them along, and the record it left keeps the same client id with a stale
38
+ * clock and whatever it had journaled. Every later mount that loads that record
39
+ * resends its journal and stamps early commands from its clock, at or below the
40
+ * watermark the server keeps for the id, so the server absorbs each one as a
41
+ * replay and answers `expired`. A host whose principal arrives after mount
42
+ * passes `pending` until it does, never a stand-in key.
43
+ */
44
+ export type DeepAgentSessionPersistence = {
45
+ kind: 'local-storage';
46
+ key: (threadId: string) => string;
47
+ onStorageDegraded?: (degradation: SessionStorageDegradation) => void;
48
+ } | {
49
+ kind: 'session-store';
50
+ store: NonNullable<StatewireTransportOptions['sessionStore']>;
51
+ } | DeepAgentPendingSession | false;
52
+ /**
53
+ * The durable lane's principal is not known yet. A lane belongs to one
54
+ * principal and a mounted session cannot move to another lane (see
55
+ * {@link DeepAgentSessionPersistence}), so nothing is mounted, nothing is
56
+ * journaled and the transport stays parked — no dial — until the host passes
57
+ * the real persistence. The park is an attach identity of its own: the attach
58
+ * that follows makes every per-attach decision afresh (the remembered-snapshot
59
+ * seed, the pooled hello, which the park leaves in the pool) and dials the real
60
+ * lane once, as the thread's first attach. The park carries no connection
61
+ * message, so it reads like a never-started chat rather than a paused one; a
62
+ * host suspension, when one applies, wins.
63
+ */
64
+ export type DeepAgentPendingSession = {
65
+ kind: 'pending';
66
+ };
67
+ /**
68
+ * The attach key a pending-lane park runs under. It differs from every key the
69
+ * host passes, so the real attach after it is a new attach identity.
70
+ */
71
+ export declare function pendingSessionAttachKey(attachKey: string | number | undefined): string;
72
+ /**
73
+ * Whether a localStorage-backed session can persist here. A write probe, not a
74
+ * `typeof` check: storage-blocked iframes (SDK embeds under third-party-storage
75
+ * blocking) throw from the `localStorage` accessor itself, and lockdown-mode
76
+ * origins throw from `setItem` — each of those must mean "stay process-local",
77
+ * never a crash at mount. An origin that is merely out of quota still reads
78
+ * and takes locks, so it mounts the session: {@link QuotaSafeLocalStorageSession}
79
+ * degrades that to memory-only persistence and recovers when room frees,
80
+ * where staying process-local would give up cross-tab sharing for the whole
81
+ * page load over a condition that clears.
82
+ *
83
+ * The Web Locks API is probed too: the session storage serializes the shared
84
+ * record across tabs through `navigator.locks` and refuses to mount without it
85
+ * (the same precondition as the vendor `LocalStorageSession`), so an origin
86
+ * with localStorage but no Web Locks — older WebViews, Safari before 15.4 —
87
+ * must also stay process-local instead of throwing at mount.
88
+ */
89
+ export declare function canPersistDeepAgentSession(): boolean;
90
+ /**
91
+ * The shared tail of every surface's transport error policy: channel teardown
92
+ * is lifecycle noise (logged at debug), as is `config_sync_unavailable` — only
93
+ * `config/*` writes emit it, and the host's config sync already handles it
94
+ * through its own command promise (regionally-pinned workspaces run on
95
+ * local-only config); everything else is a real transport error. Hosts with their own error chain
96
+ * (paywall, telemetry, send-failure stores) end it with this so the fallback
97
+ * logging stays uniform per surface.
98
+ */
99
+ export declare function logUnhandledStatewireError(surface: string, error: Error): void;
100
+ /**
101
+ * The imperative thread-state slice of an assistant-ui client — structural so
102
+ * web and native `useAui` results both satisfy it. The send-recovery layer
103
+ * reads the statewire thread extras through it (the sanctioned imperative
104
+ * pattern: `aui.thread().getState()` inside callbacks/effects, never render).
105
+ */
106
+ export interface DeepAgentThreadStateClientHost {
107
+ thread: () => {
108
+ getState: () => {
109
+ extras?: unknown;
110
+ };
111
+ };
112
+ subscribe: (listener: () => void) => () => void;
113
+ }
114
+ /** Deep-agent runConfig registration on the ambient model context (see
115
+ * {@link registerDeepAgentRunConfig}). */
116
+ export interface DeepAgentRunConfigRegistration {
117
+ /**
118
+ * Builds the `runConfig` that drives the run. The core pulls it when the
119
+ * model context notifies (mount and each key change); the server reads that
120
+ * synced value at command admission. The per-render ref makes each pull use
121
+ * the latest closure but does not trigger a pull itself.
122
+ */
123
+ get: () => Record<string, unknown>;
124
+ /**
125
+ * Re-registers the provider and notifies model-context sync when this value
126
+ * changes (reference equality). Include getter inputs that can change while
127
+ * mounted; they reach the server only after a key change triggers a pull.
128
+ */
129
+ key?: unknown;
130
+ }
131
+ export interface UseDeepAgentRuntimeOptions<TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost> extends Omit<UseDeepAgentThreadOptions, 'storage' | 'sessionStore'> {
132
+ /** Host surface tag for the shared fallback error logging (e.g.
133
+ * `'AthenaDeepAgent'`, `'AthenaSDK'`, `'ChromeStatewire'`). */
134
+ surface: string;
135
+ /** Durable command-lane persistence; defaults to process-local. */
136
+ session?: DeepAgentSessionPersistence;
137
+ /**
138
+ * Builds the host's assistant-ui client from the thread element — pass the
139
+ * platform `useAui` (web hosts from `@assistant-ui/react`, React Native
140
+ * hosts from `@assistant-ui/react-native`; this package imports neither).
141
+ * Called unconditionally on every render, so it MUST be (or call) a hook
142
+ * following the rules of hooks — define it at module scope with a `use*`
143
+ * name: `const useHostClient = (thread: DeepAgentThreadElement) =>
144
+ * useAui({ thread })`.
145
+ */
146
+ useClient: (thread: DeepAgentThreadElement) => TClient;
147
+ /** Registers the deep-agent runConfig on the client's model context. Hosts
148
+ * that register elsewhere (e.g. a bridge component mounted under the
149
+ * provider) omit it. */
150
+ runConfig?: DeepAgentRunConfigRegistration;
151
+ }
152
+ /**
153
+ * The configurable deep-agent statewire runtime — the one hook every Athena
154
+ * chat surface (Olympus, `@athenaintel/react` SDK, Chrome extension, Office
155
+ * add-in, mobile) mounts its assistant-ui client through.
156
+ *
157
+ * Composes the pieces every surface previously wired by hand:
158
+ * `useDeepAgentThread` (attach lifecycle, auth parking, lane projection,
159
+ * connection/running observers), durable session persistence with the shared
160
+ * availability guard, transport-level send recovery (failed sends the server
161
+ * never judged auto-retry under their original message id — `send-recovery.ts`),
162
+ * the platform client via `useClient`, and the
163
+ * runConfig model-context registration on provider notifications. Everything
164
+ * host-specific — auth headers, run-config building, error policy, adapters,
165
+ * diagnostics recorders — stays an option, so per-surface behavior is
166
+ * configuration, not a fork.
167
+ */
168
+ export declare function useDeepAgentRuntime<TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost>(options: UseDeepAgentRuntimeOptions<TClient>): TClient;
@@ -6,6 +6,9 @@ import { createDeepAgentSendRecovery } from "./send-recovery.js";
6
6
  import { readStatewireFailedSendLane } from "./thread-extras.js";
7
7
  import { isConfigSyncUnavailableRejection } from "./use-deep-agent-config.js";
8
8
  import { useDeepAgentThread } from "./use-deep-agent-thread.js";
9
+ function pendingSessionAttachKey(attachKey) {
10
+ return `session-pending:${attachKey ?? ""}`;
11
+ }
9
12
  function canPersistDeepAgentSession() {
10
13
  var _a;
11
14
  try {
@@ -69,8 +72,10 @@ function useDeepAgentRuntime(options) {
69
72
  const failureStampsRef = useRef(
70
73
  void 0
71
74
  );
72
- failureStampsRef.current = session === false ? void 0 : session.kind === "local-storage" ? canPersistLocalSession ? () => readPersistedFailedSendStamps(session.key(threadOptions.threadId)) : void 0 : () => readFailedSendStampsFromRecord(loadSessionRecord(session.store));
73
- const attachId = threadOptions.attachKey === void 0 ? threadOptions.threadId : `${threadOptions.threadId}:${threadOptions.attachKey}`;
75
+ failureStampsRef.current = session === false || session.kind === "pending" ? void 0 : session.kind === "local-storage" ? canPersistLocalSession ? () => readPersistedFailedSendStamps(session.key(threadOptions.threadId)) : void 0 : () => readFailedSendStampsFromRecord(loadSessionRecord(session.store));
76
+ const sessionPending = session !== false && session.kind === "pending";
77
+ const attachKey = sessionPending ? pendingSessionAttachKey(threadOptions.attachKey) : threadOptions.attachKey;
78
+ const attachId = attachKey === void 0 ? threadOptions.threadId : `${threadOptions.threadId}:${attachKey}`;
74
79
  const sendRecovery = useMemo(
75
80
  () => createDeepAgentSendRecovery({
76
81
  lane: () => {
@@ -91,6 +96,18 @@ function useDeepAgentRuntime(options) {
91
96
  sendRecoveryRef.current = sendRecovery;
92
97
  const thread = useDeepAgentThread({
93
98
  ...threadOptions,
99
+ ...attachKey !== void 0 && { attachKey },
100
+ // Parked without a message (a host suspension, when one applies, wins):
101
+ // nothing dials and nothing journals until the lane is known. What paints
102
+ // the first frame is the real attach's to report, not the park's.
103
+ ...sessionPending && {
104
+ suspended: threadOptions.suspended || {},
105
+ onAttachSource: void 0
106
+ },
107
+ // A pooled dial for the thread is the real attach's to take: a park that
108
+ // only waits for the lane neither takes nor discards it. A host suspension
109
+ // still discards it, as it does without a pending lane.
110
+ ...sessionPending && !threadOptions.suspended && { prewarmPool: void 0 },
94
111
  ...session !== false && session.kind === "local-storage" && canPersistLocalSession && {
95
112
  storage: {
96
113
  session: QuotaSafeLocalStorageSession({
@@ -143,6 +160,7 @@ function useDeepAgentRuntime(options) {
143
160
  export {
144
161
  canPersistDeepAgentSession,
145
162
  logUnhandledStatewireError,
163
+ pendingSessionAttachKey,
146
164
  useDeepAgentRuntime
147
165
  };
148
166
  //# sourceMappingURL=use-deep-agent-runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-deep-agent-runtime.js","sources":["../../../../agent-runtime/src/use-deep-agent-runtime.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport { isStatewireChannelTeardown } from './errors';\nimport { type DeepAgentModelContextHost, registerDeepAgentRunConfig } from './model-context';\nimport {\n isStorageQuotaError,\n QuotaSafeLocalStorageSession,\n readFailedSendStampsFromRecord,\n readPersistedFailedSendStamps,\n type SessionStorageDegradation,\n} from './quota-safe-local-storage-session';\nimport { createDeepAgentSendRecovery } from './send-recovery';\nimport type { StatewireTransportOptions } from './statewire-transport';\nimport { readStatewireFailedSendLane } from './thread-extras';\nimport { isConfigSyncUnavailableRejection } from './use-deep-agent-config';\nimport { useDeepAgentThread, type UseDeepAgentThreadOptions } from './use-deep-agent-thread';\n\n/** The thread element `useDeepAgentThread` produces — what the host's `useAui`\n * consumes (`useAui({ thread })`). */\nexport type DeepAgentThreadElement = ReturnType<typeof useDeepAgentThread>;\n\n/**\n * Durable command-lane persistence for the thread — where the lane identity and\n * the commands still awaiting a durable verdict live, so a reload resumes the\n * lane instead of minting a new client.\n *\n * - `local-storage`: browser hosts. Backed by {@link QuotaSafeLocalStorageSession}\n * (the upstream `LocalStorageSession` contract with Athena keys, legacy\n * metadata, and retention). A storage failure after mounting — the origin\n * out of quota after statewire's own sweep, a lockdown-mode write refusal —\n * degrades the session to memory-only persistence and is reported through\n * `onStorageDegraded` (default: one console warning); it never stops the\n * connection. Guarded by a shared availability probe: SSR, storage-blocked\n * iframes, and locked-down browsers keep the session process-local, exactly\n * as before the seam existed, while an origin that is merely full mounts the\n * session and lets it degrade. `key` scopes the stored lane — a thread id is\n * only meaningful against the backend (and, where relevant, principal) that\n * minted it, so include the sync-host URL.\n * - `session-store`: React Native hosts pass a hydrated library store backed\n * by AsyncStorage. Its synchronous `load()` is\n * also the send-recovery freshness gate's view of the persisted failed lane,\n * so a store that persists `failed` gets the same 24 h staleness rule as the\n * browser hosts.\n * - `false`: process-local session (a reload mints a new client).\n */\nexport type DeepAgentSessionPersistence =\n | {\n kind: 'local-storage';\n key: (threadId: string) => string;\n onStorageDegraded?: (degradation: SessionStorageDegradation) => void;\n }\n | { kind: 'session-store'; store: NonNullable<StatewireTransportOptions['sessionStore']> }\n | false;\n\n/** Structural view of the browser storage global — this package compiles\n * without the DOM lib (React Native honesty; see `globals.d.ts`). */\ntype StorageGlobals = {\n localStorage?: {\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n };\n navigator?: { locks?: unknown };\n};\n\n/**\n * Whether a localStorage-backed session can persist here. A write probe, not a\n * `typeof` check: storage-blocked iframes (SDK embeds under third-party-storage\n * blocking) throw from the `localStorage` accessor itself, and lockdown-mode\n * origins throw from `setItem` — each of those must mean \"stay process-local\",\n * never a crash at mount. An origin that is merely out of quota still reads\n * and takes locks, so it mounts the session: {@link QuotaSafeLocalStorageSession}\n * degrades that to memory-only persistence and recovers when room frees,\n * where staying process-local would give up cross-tab sharing for the whole\n * page load over a condition that clears.\n *\n * The Web Locks API is probed too: the session storage serializes the shared\n * record across tabs through `navigator.locks` and refuses to mount without it\n * (the same precondition as the vendor `LocalStorageSession`), so an origin\n * with localStorage but no Web Locks — older WebViews, Safari before 15.4 —\n * must also stay process-local instead of throwing at mount.\n */\nexport function canPersistDeepAgentSession(): boolean {\n try {\n const globals = globalThis as StorageGlobals;\n if (!globals.navigator?.locks) return false;\n const storage = globals.localStorage;\n if (!storage) return false;\n const probeKey = '__athena_statewire_session_probe__';\n try {\n storage.setItem(probeKey, probeKey);\n storage.removeItem(probeKey);\n } catch (error) {\n return isStorageQuotaError(error);\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** A host session store's current record, or `null` when the read throws —\n * the recovery gate must never take the runtime down over a storage fault. */\nfunction loadSessionRecord(\n store: NonNullable<StatewireTransportOptions['sessionStore']>\n): ReturnType<NonNullable<StatewireTransportOptions['sessionStore']>['load']> | null {\n try {\n return store.load();\n } catch {\n return null;\n }\n}\n\n/**\n * The shared tail of every surface's transport error policy: channel teardown\n * is lifecycle noise (logged at debug), as is `config_sync_unavailable` — only\n * `config/*` writes emit it, and the host's config sync already handles it\n * through its own command promise (regionally-pinned workspaces run on\n * local-only config); everything else is a real transport error. Hosts with their own error chain\n * (paywall, telemetry, send-failure stores) end it with this so the fallback\n * logging stays uniform per surface.\n */\nexport function logUnhandledStatewireError(surface: string, error: Error): void {\n if (isStatewireChannelTeardown(error)) {\n console.debug(`[${surface}] statewire channel teardown:`, error);\n return;\n }\n if (isConfigSyncUnavailableRejection(error)) {\n console.debug(`[${surface}] config sync unavailable (handled by config sync):`, error);\n return;\n }\n console.error(`[${surface}] statewire transport error:`, error);\n}\n\n/**\n * The imperative thread-state slice of an assistant-ui client — structural so\n * web and native `useAui` results both satisfy it. The send-recovery layer\n * reads the statewire thread extras through it (the sanctioned imperative\n * pattern: `aui.thread().getState()` inside callbacks/effects, never render).\n */\nexport interface DeepAgentThreadStateClientHost {\n thread: () => { getState: () => { extras?: unknown } };\n subscribe: (listener: () => void) => () => void;\n}\n\n/** Deep-agent runConfig registration on the ambient model context (see\n * {@link registerDeepAgentRunConfig}). */\nexport interface DeepAgentRunConfigRegistration {\n /**\n * Builds the `runConfig` that drives the run. The core pulls it when the\n * model context notifies (mount and each key change); the server reads that\n * synced value at command admission. The per-render ref makes each pull use\n * the latest closure but does not trigger a pull itself.\n */\n get: () => Record<string, unknown>;\n /**\n * Re-registers the provider and notifies model-context sync when this value\n * changes (reference equality). Include getter inputs that can change while\n * mounted; they reach the server only after a key change triggers a pull.\n */\n key?: unknown;\n}\n\nexport interface UseDeepAgentRuntimeOptions<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n> extends Omit<UseDeepAgentThreadOptions, 'storage' | 'sessionStore'> {\n /** Host surface tag for the shared fallback error logging (e.g.\n * `'AthenaDeepAgent'`, `'AthenaSDK'`, `'ChromeStatewire'`). */\n surface: string;\n /** Durable command-lane persistence; defaults to process-local. */\n session?: DeepAgentSessionPersistence;\n /**\n * Builds the host's assistant-ui client from the thread element — pass the\n * platform `useAui` (web hosts from `@assistant-ui/react`, React Native\n * hosts from `@assistant-ui/react-native`; this package imports neither).\n * Called unconditionally on every render, so it MUST be (or call) a hook\n * following the rules of hooks — define it at module scope with a `use*`\n * name: `const useHostClient = (thread: DeepAgentThreadElement) =>\n * useAui({ thread })`.\n */\n useClient: (thread: DeepAgentThreadElement) => TClient;\n /** Registers the deep-agent runConfig on the client's model context. Hosts\n * that register elsewhere (e.g. a bridge component mounted under the\n * provider) omit it. */\n runConfig?: DeepAgentRunConfigRegistration;\n}\n\n/**\n * The configurable deep-agent statewire runtime — the one hook every Athena\n * chat surface (Olympus, `@athenaintel/react` SDK, Chrome extension, Office\n * add-in, mobile) mounts its assistant-ui client through.\n *\n * Composes the pieces every surface previously wired by hand:\n * `useDeepAgentThread` (attach lifecycle, auth parking, lane projection,\n * connection/running observers), durable session persistence with the shared\n * availability guard, transport-level send recovery (failed sends the server\n * never judged auto-retry under their original message id — `send-recovery.ts`),\n * the platform client via `useClient`, and the\n * runConfig model-context registration on provider notifications. Everything\n * host-specific — auth headers, run-config building, error policy, adapters,\n * diagnostics recorders — stays an option, so per-surface behavior is\n * configuration, not a fork.\n */\nexport function useDeepAgentRuntime<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n>(options: UseDeepAgentRuntimeOptions<TClient>): TClient {\n const {\n surface,\n session = false,\n useClient,\n runConfig,\n onError,\n onStateChange,\n onCommandChange,\n ...threadOptions\n } = options;\n\n // Probed once per mount, like every browser host did individually: an origin\n // that cannot persist stays process-local for the mount's lifetime.\n const [canPersistLocalSession] = useState(canPersistDeepAgentSession);\n\n // Per-render refs so the transport never remounts on a new closure identity\n // and always reads the latest policy.\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n const surfaceRef = useRef(surface);\n surfaceRef.current = surface;\n const onStateChangeRef = useRef(onStateChange);\n onStateChangeRef.current = onStateChange;\n const onCommandChangeRef = useRef(onCommandChange);\n onCommandChangeRef.current = onCommandChange;\n const diagnosticsRef = useRef(threadOptions.diagnostics);\n diagnosticsRef.current = threadOptions.diagnostics;\n const clientRef = useRef<TClient | null>(null);\n\n // Where the persisted session record lives, for the recovery freshness gate\n // (read per sweep — undefined means \"no persistence, everything is fresh\").\n const failureStampsRef = useRef<(() => ReadonlyMap<string, number> | null) | undefined>(\n undefined\n );\n failureStampsRef.current =\n session === false\n ? undefined\n : session.kind === 'local-storage'\n ? canPersistLocalSession\n ? () => readPersistedFailedSendStamps(session.key(threadOptions.threadId))\n : undefined\n : () => readFailedSendStampsFromRecord(loadSessionRecord(session.store));\n\n // Send recovery, keyed by attach identity exactly like the thread's session\n // (a switch or re-attach gets fresh hydration gating and retry budgets). The\n // controller re-dispatches failed sends the server never judged; see\n // `send-recovery.ts` for the contract.\n const attachId =\n threadOptions.attachKey === undefined\n ? threadOptions.threadId\n : `${threadOptions.threadId}:${threadOptions.attachKey}`;\n // biome-ignore lint/correctness/useExhaustiveDependencies: keyed by attach identity on purpose; every other input is read through a per-render ref.\n const sendRecovery = useMemo(\n () =>\n createDeepAgentSendRecovery({\n lane: () => {\n const client = clientRef.current;\n if (!client) return null;\n return readStatewireFailedSendLane(client.thread().getState().extras);\n },\n failureStamps: () => failureStampsRef.current?.() ?? null,\n diagnostics: () => diagnosticsRef.current,\n }),\n [attachId]\n );\n useEffect(() => () => sendRecovery.dispose(), [sendRecovery]);\n const sendRecoveryRef = useRef(sendRecovery);\n sendRecoveryRef.current = sendRecovery;\n\n const thread = useDeepAgentThread({\n ...threadOptions,\n ...(session !== false &&\n session.kind === 'local-storage' &&\n canPersistLocalSession && {\n storage: {\n session: QuotaSafeLocalStorageSession({\n threadId: threadOptions.threadId,\n key: session.key,\n ...(session.onStorageDegraded === undefined\n ? {}\n : { onStorageDegraded: session.onStorageDegraded }),\n }),\n },\n }),\n ...(session !== false && session.kind === 'session-store' && { sessionStore: session.store }),\n onStateChange: (state, ctx) => {\n sendRecoveryRef.current.observeStateChange(state);\n onStateChangeRef.current?.(state, ctx);\n },\n onCommandChange: (update, ctx) => {\n sendRecoveryRef.current.observeCommand(update);\n onCommandChangeRef.current?.(update, ctx);\n },\n onError: (error) => {\n const handler = onErrorRef.current;\n if (handler) {\n handler(error);\n return;\n }\n logUnhandledStatewireError(surfaceRef.current, error);\n },\n });\n\n const client = useClient(thread);\n clientRef.current = client;\n\n // A locked shared journal can publish failed history after onCommandChange,\n // with no canonical state change to wake recovery. Observe the client that\n // owns the visible failed lane; the controller guards in-flight retries.\n useEffect(() => {\n const unsubscribe = client.subscribe(() => sendRecovery.observeFailedLaneChange());\n sendRecovery.observeFailedLaneChange();\n return unsubscribe;\n }, [client, sendRecovery]);\n\n // Commands travel bare, so the runConfig that drives the run rides the\n // ambient model context: `contextSync: 'command-send'` mirrors it to the\n // server, which reads `config.runConfig` at command admission. The core pulls\n // on model-context notifications; the per-render ref ensures each pull uses\n // the latest closure but does not trigger a pull itself.\n const getRunConfigRef = useRef(runConfig?.get);\n getRunConfigRef.current = runConfig?.get;\n const hasRunConfig = runConfig !== undefined;\n const runConfigKey = runConfig?.key;\n useEffect(() => {\n if (!hasRunConfig) return undefined;\n return registerDeepAgentRunConfig(client, () => getRunConfigRef.current?.() ?? {});\n }, [client, hasRunConfig, runConfigKey]);\n\n return client;\n}\n\n"],"names":["client"],"mappings":";;;;;;;;AAgFO,SAAS,6BAAsC;;AACpD,MAAI;AACF,UAAM,UAAU;AAChB,QAAI,GAAC,aAAQ,cAAR,mBAAmB,OAAO,QAAO;AACtC,UAAM,UAAU,QAAQ;AACxB,QAAI,CAAC,QAAS,QAAO;AACrB,UAAM,WAAW;AACjB,QAAI;AACF,cAAQ,QAAQ,UAAU,QAAQ;AAClC,cAAQ,WAAW,QAAQ;AAAA,IAC7B,SAAS,OAAO;AACd,aAAO,oBAAoB,KAAK;AAAA,IAClC;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAIA,SAAS,kBACP,OACmF;AACnF,MAAI;AACF,WAAO,MAAM,KAAA;AAAA,EACf,QAAQ;AACN,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,yBAAyB;AACjF,iBAAa,wBAAA;AACb,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,YAAY,CAAC;AAOzB,QAAM,kBAAkB,OAAO,uCAAW,GAAG;AAC7C,kBAAgB,UAAU,uCAAW;AACrC,QAAM,eAAe,cAAc;AACnC,QAAM,eAAe,uCAAW;AAChC,YAAU,MAAM;AACd,QAAI,CAAC,aAAc,QAAO;AAC1B,WAAO,2BAA2B,QAAQ,MAAA;;AAAM,oCAAgB,YAAhB,6CAA+B,CAAA;AAAA,KAAE;AAAA,EACnF,GAAG,CAAC,QAAQ,cAAc,YAAY,CAAC;AAEvC,SAAO;AACT;"}
1
+ {"version":3,"file":"use-deep-agent-runtime.js","sources":["../../../../agent-runtime/src/use-deep-agent-runtime.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport { isStatewireChannelTeardown } from './errors';\nimport { type DeepAgentModelContextHost, registerDeepAgentRunConfig } from './model-context';\nimport {\n isStorageQuotaError,\n QuotaSafeLocalStorageSession,\n readFailedSendStampsFromRecord,\n readPersistedFailedSendStamps,\n type SessionStorageDegradation,\n} from './quota-safe-local-storage-session';\nimport { createDeepAgentSendRecovery } from './send-recovery';\nimport type { StatewireTransportOptions } from './statewire-transport';\nimport { readStatewireFailedSendLane } from './thread-extras';\nimport { isConfigSyncUnavailableRejection } from './use-deep-agent-config';\nimport { useDeepAgentThread, type UseDeepAgentThreadOptions } from './use-deep-agent-thread';\n\n/** The thread element `useDeepAgentThread` produces — what the host's `useAui`\n * consumes (`useAui({ thread })`). */\nexport type DeepAgentThreadElement = ReturnType<typeof useDeepAgentThread>;\n\n/**\n * Durable command-lane persistence for the thread — where the lane identity and\n * the commands still awaiting a durable verdict live, so a reload resumes the\n * lane instead of minting a new client.\n *\n * - `local-storage`: browser hosts. Backed by {@link QuotaSafeLocalStorageSession}\n * (the upstream `LocalStorageSession` contract with Athena keys, legacy\n * metadata, and retention). A storage failure after mounting — the origin\n * out of quota after statewire's own sweep, a lockdown-mode write refusal —\n * degrades the session to memory-only persistence and is reported through\n * `onStorageDegraded` (default: one console warning); it never stops the\n * connection. Guarded by a shared availability probe: SSR, storage-blocked\n * iframes, and locked-down browsers keep the session process-local, exactly\n * as before the seam existed, while an origin that is merely full mounts the\n * session and lets it degrade. `key` scopes the stored lane — a thread id is\n * only meaningful against the backend (and, where relevant, principal) that\n * minted it, so include the sync-host URL.\n * - `session-store`: React Native hosts pass a hydrated library store backed\n * by AsyncStorage. Its synchronous `load()` is\n * also the send-recovery freshness gate's view of the persisted failed lane,\n * so a store that persists `failed` gets the same 24 h staleness rule as the\n * browser hosts.\n * - `pending`: the principal the lane is scoped by is not known yet (the\n * host's signed-in user is still loading). See {@link DeepAgentPendingSession}.\n * - `false`: process-local session (a reload mints a new client).\n *\n * A `local-storage` `key` must name the same lane for the whole life of the\n * thread's mount. The statewire session that mounts on a lane keeps the client\n * id, lane clocks and journal it loaded there; moved to another key, it carries\n * them along, and the record it left keeps the same client id with a stale\n * clock and whatever it had journaled. Every later mount that loads that record\n * resends its journal and stamps early commands from its clock, at or below the\n * watermark the server keeps for the id, so the server absorbs each one as a\n * replay and answers `expired`. A host whose principal arrives after mount\n * passes `pending` until it does, never a stand-in key.\n */\nexport type DeepAgentSessionPersistence =\n | {\n kind: 'local-storage';\n key: (threadId: string) => string;\n onStorageDegraded?: (degradation: SessionStorageDegradation) => void;\n }\n | { kind: 'session-store'; store: NonNullable<StatewireTransportOptions['sessionStore']> }\n | DeepAgentPendingSession\n | false;\n\n/**\n * The durable lane's principal is not known yet. A lane belongs to one\n * principal and a mounted session cannot move to another lane (see\n * {@link DeepAgentSessionPersistence}), so nothing is mounted, nothing is\n * journaled and the transport stays parked — no dial — until the host passes\n * the real persistence. The park is an attach identity of its own: the attach\n * that follows makes every per-attach decision afresh (the remembered-snapshot\n * seed, the pooled hello, which the park leaves in the pool) and dials the real\n * lane once, as the thread's first attach. The park carries no connection\n * message, so it reads like a never-started chat rather than a paused one; a\n * host suspension, when one applies, wins.\n */\nexport type DeepAgentPendingSession = { kind: 'pending' };\n\n/**\n * The attach key a pending-lane park runs under. It differs from every key the\n * host passes, so the real attach after it is a new attach identity.\n */\nexport function pendingSessionAttachKey(attachKey: string | number | undefined): string {\n return `session-pending:${attachKey ?? ''}`;\n}\n\n/** Structural view of the browser storage global — this package compiles\n * without the DOM lib (React Native honesty; see `globals.d.ts`). */\ntype StorageGlobals = {\n localStorage?: {\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n };\n navigator?: { locks?: unknown };\n};\n\n/**\n * Whether a localStorage-backed session can persist here. A write probe, not a\n * `typeof` check: storage-blocked iframes (SDK embeds under third-party-storage\n * blocking) throw from the `localStorage` accessor itself, and lockdown-mode\n * origins throw from `setItem` — each of those must mean \"stay process-local\",\n * never a crash at mount. An origin that is merely out of quota still reads\n * and takes locks, so it mounts the session: {@link QuotaSafeLocalStorageSession}\n * degrades that to memory-only persistence and recovers when room frees,\n * where staying process-local would give up cross-tab sharing for the whole\n * page load over a condition that clears.\n *\n * The Web Locks API is probed too: the session storage serializes the shared\n * record across tabs through `navigator.locks` and refuses to mount without it\n * (the same precondition as the vendor `LocalStorageSession`), so an origin\n * with localStorage but no Web Locks — older WebViews, Safari before 15.4 —\n * must also stay process-local instead of throwing at mount.\n */\nexport function canPersistDeepAgentSession(): boolean {\n try {\n const globals = globalThis as StorageGlobals;\n if (!globals.navigator?.locks) return false;\n const storage = globals.localStorage;\n if (!storage) return false;\n const probeKey = '__athena_statewire_session_probe__';\n try {\n storage.setItem(probeKey, probeKey);\n storage.removeItem(probeKey);\n } catch (error) {\n return isStorageQuotaError(error);\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** A host session store's current record, or `null` when the read throws —\n * the recovery gate must never take the runtime down over a storage fault. */\nfunction loadSessionRecord(\n store: NonNullable<StatewireTransportOptions['sessionStore']>\n): ReturnType<NonNullable<StatewireTransportOptions['sessionStore']>['load']> | null {\n try {\n return store.load();\n } catch {\n return null;\n }\n}\n\n/**\n * The shared tail of every surface's transport error policy: channel teardown\n * is lifecycle noise (logged at debug), as is `config_sync_unavailable` — only\n * `config/*` writes emit it, and the host's config sync already handles it\n * through its own command promise (regionally-pinned workspaces run on\n * local-only config); everything else is a real transport error. Hosts with their own error chain\n * (paywall, telemetry, send-failure stores) end it with this so the fallback\n * logging stays uniform per surface.\n */\nexport function logUnhandledStatewireError(surface: string, error: Error): void {\n if (isStatewireChannelTeardown(error)) {\n console.debug(`[${surface}] statewire channel teardown:`, error);\n return;\n }\n if (isConfigSyncUnavailableRejection(error)) {\n console.debug(`[${surface}] config sync unavailable (handled by config sync):`, error);\n return;\n }\n console.error(`[${surface}] statewire transport error:`, error);\n}\n\n/**\n * The imperative thread-state slice of an assistant-ui client — structural so\n * web and native `useAui` results both satisfy it. The send-recovery layer\n * reads the statewire thread extras through it (the sanctioned imperative\n * pattern: `aui.thread().getState()` inside callbacks/effects, never render).\n */\nexport interface DeepAgentThreadStateClientHost {\n thread: () => { getState: () => { extras?: unknown } };\n subscribe: (listener: () => void) => () => void;\n}\n\n/** Deep-agent runConfig registration on the ambient model context (see\n * {@link registerDeepAgentRunConfig}). */\nexport interface DeepAgentRunConfigRegistration {\n /**\n * Builds the `runConfig` that drives the run. The core pulls it when the\n * model context notifies (mount and each key change); the server reads that\n * synced value at command admission. The per-render ref makes each pull use\n * the latest closure but does not trigger a pull itself.\n */\n get: () => Record<string, unknown>;\n /**\n * Re-registers the provider and notifies model-context sync when this value\n * changes (reference equality). Include getter inputs that can change while\n * mounted; they reach the server only after a key change triggers a pull.\n */\n key?: unknown;\n}\n\nexport interface UseDeepAgentRuntimeOptions<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n> extends Omit<UseDeepAgentThreadOptions, 'storage' | 'sessionStore'> {\n /** Host surface tag for the shared fallback error logging (e.g.\n * `'AthenaDeepAgent'`, `'AthenaSDK'`, `'ChromeStatewire'`). */\n surface: string;\n /** Durable command-lane persistence; defaults to process-local. */\n session?: DeepAgentSessionPersistence;\n /**\n * Builds the host's assistant-ui client from the thread element — pass the\n * platform `useAui` (web hosts from `@assistant-ui/react`, React Native\n * hosts from `@assistant-ui/react-native`; this package imports neither).\n * Called unconditionally on every render, so it MUST be (or call) a hook\n * following the rules of hooks — define it at module scope with a `use*`\n * name: `const useHostClient = (thread: DeepAgentThreadElement) =>\n * useAui({ thread })`.\n */\n useClient: (thread: DeepAgentThreadElement) => TClient;\n /** Registers the deep-agent runConfig on the client's model context. Hosts\n * that register elsewhere (e.g. a bridge component mounted under the\n * provider) omit it. */\n runConfig?: DeepAgentRunConfigRegistration;\n}\n\n/**\n * The configurable deep-agent statewire runtime — the one hook every Athena\n * chat surface (Olympus, `@athenaintel/react` SDK, Chrome extension, Office\n * add-in, mobile) mounts its assistant-ui client through.\n *\n * Composes the pieces every surface previously wired by hand:\n * `useDeepAgentThread` (attach lifecycle, auth parking, lane projection,\n * connection/running observers), durable session persistence with the shared\n * availability guard, transport-level send recovery (failed sends the server\n * never judged auto-retry under their original message id — `send-recovery.ts`),\n * the platform client via `useClient`, and the\n * runConfig model-context registration on provider notifications. Everything\n * host-specific — auth headers, run-config building, error policy, adapters,\n * diagnostics recorders — stays an option, so per-surface behavior is\n * configuration, not a fork.\n */\nexport function useDeepAgentRuntime<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n>(options: UseDeepAgentRuntimeOptions<TClient>): TClient {\n const {\n surface,\n session = false,\n useClient,\n runConfig,\n onError,\n onStateChange,\n onCommandChange,\n ...threadOptions\n } = options;\n\n // Probed once per mount, like every browser host did individually: an origin\n // that cannot persist stays process-local for the mount's lifetime.\n const [canPersistLocalSession] = useState(canPersistDeepAgentSession);\n\n // Per-render refs so the transport never remounts on a new closure identity\n // and always reads the latest policy.\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n const surfaceRef = useRef(surface);\n surfaceRef.current = surface;\n const onStateChangeRef = useRef(onStateChange);\n onStateChangeRef.current = onStateChange;\n const onCommandChangeRef = useRef(onCommandChange);\n onCommandChangeRef.current = onCommandChange;\n const diagnosticsRef = useRef(threadOptions.diagnostics);\n diagnosticsRef.current = threadOptions.diagnostics;\n const clientRef = useRef<TClient | null>(null);\n\n // Where the persisted session record lives, for the recovery freshness gate\n // (read per sweep — undefined means \"no persistence, everything is fresh\").\n const failureStampsRef = useRef<(() => ReadonlyMap<string, number> | null) | undefined>(\n undefined\n );\n failureStampsRef.current =\n session === false || session.kind === 'pending'\n ? undefined\n : session.kind === 'local-storage'\n ? canPersistLocalSession\n ? () => readPersistedFailedSendStamps(session.key(threadOptions.threadId))\n : undefined\n : () => readFailedSendStampsFromRecord(loadSessionRecord(session.store));\n\n // A pending lane parks the thread under an attach identity of its own (see\n // `DeepAgentPendingSession`), so the attach once the lane is known is new.\n const sessionPending = session !== false && session.kind === 'pending';\n const attachKey = sessionPending\n ? pendingSessionAttachKey(threadOptions.attachKey)\n : threadOptions.attachKey;\n\n // Send recovery, keyed by attach identity exactly like the thread's session\n // (a switch or re-attach gets fresh hydration gating and retry budgets). The\n // controller re-dispatches failed sends the server never judged; see\n // `send-recovery.ts` for the contract.\n const attachId =\n attachKey === undefined ? threadOptions.threadId : `${threadOptions.threadId}:${attachKey}`;\n // biome-ignore lint/correctness/useExhaustiveDependencies: keyed by attach identity on purpose; every other input is read through a per-render ref.\n const sendRecovery = useMemo(\n () =>\n createDeepAgentSendRecovery({\n lane: () => {\n const client = clientRef.current;\n if (!client) return null;\n return readStatewireFailedSendLane(client.thread().getState().extras);\n },\n failureStamps: () => failureStampsRef.current?.() ?? null,\n diagnostics: () => diagnosticsRef.current,\n }),\n [attachId]\n );\n useEffect(() => () => sendRecovery.dispose(), [sendRecovery]);\n const sendRecoveryRef = useRef(sendRecovery);\n sendRecoveryRef.current = sendRecovery;\n\n const thread = useDeepAgentThread({\n ...threadOptions,\n ...(attachKey !== undefined && { attachKey }),\n // Parked without a message (a host suspension, when one applies, wins):\n // nothing dials and nothing journals until the lane is known. What paints\n // the first frame is the real attach's to report, not the park's.\n ...(sessionPending && {\n suspended: threadOptions.suspended || {},\n onAttachSource: undefined,\n }),\n // A pooled dial for the thread is the real attach's to take: a park that\n // only waits for the lane neither takes nor discards it. A host suspension\n // still discards it, as it does without a pending lane.\n ...(sessionPending && !threadOptions.suspended && { prewarmPool: undefined }),\n ...(session !== false &&\n session.kind === 'local-storage' &&\n canPersistLocalSession && {\n storage: {\n session: QuotaSafeLocalStorageSession({\n threadId: threadOptions.threadId,\n key: session.key,\n ...(session.onStorageDegraded === undefined\n ? {}\n : { onStorageDegraded: session.onStorageDegraded }),\n }),\n },\n }),\n ...(session !== false && session.kind === 'session-store' && { sessionStore: session.store }),\n onStateChange: (state, ctx) => {\n sendRecoveryRef.current.observeStateChange(state);\n onStateChangeRef.current?.(state, ctx);\n },\n onCommandChange: (update, ctx) => {\n sendRecoveryRef.current.observeCommand(update);\n onCommandChangeRef.current?.(update, ctx);\n },\n onError: (error) => {\n const handler = onErrorRef.current;\n if (handler) {\n handler(error);\n return;\n }\n logUnhandledStatewireError(surfaceRef.current, error);\n },\n });\n\n const client = useClient(thread);\n clientRef.current = client;\n\n // A locked shared journal can publish failed history after onCommandChange,\n // with no canonical state change to wake recovery. Observe the client that\n // owns the visible failed lane; the controller guards in-flight retries.\n useEffect(() => {\n const unsubscribe = client.subscribe(() => sendRecovery.observeFailedLaneChange());\n sendRecovery.observeFailedLaneChange();\n return unsubscribe;\n }, [client, sendRecovery]);\n\n // Commands travel bare, so the runConfig that drives the run rides the\n // ambient model context: `contextSync: 'command-send'` mirrors it to the\n // server, which reads `config.runConfig` at command admission. The core pulls\n // on model-context notifications; the per-render ref ensures each pull uses\n // the latest closure but does not trigger a pull itself.\n const getRunConfigRef = useRef(runConfig?.get);\n getRunConfigRef.current = runConfig?.get;\n const hasRunConfig = runConfig !== undefined;\n const runConfigKey = runConfig?.key;\n useEffect(() => {\n if (!hasRunConfig) return undefined;\n return registerDeepAgentRunConfig(client, () => getRunConfigRef.current?.() ?? {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,oCAAgB,YAAhB,6CAA+B,CAAA;AAAA,KAAE;AAAA,EACnF,GAAG,CAAC,QAAQ,cAAc,YAAY,CAAC;AAEvC,SAAO;AACT;"}
@@ -44,6 +44,9 @@ function useDeepAgentThread({
44
44
  diagnostics,
45
45
  snapshotCache,
46
46
  messageWindow: messageWindow$1,
47
+ laneHistory = false,
48
+ readMessageWindow = messageWindow.readDeepAgentMessageWindow,
49
+ createConversionCache = messages.createDeepAgentMessageConversionCache,
47
50
  toolOutputs,
48
51
  withdrawnTurns,
49
52
  prewarmPool,
@@ -85,6 +88,8 @@ function useDeepAgentThread({
85
88
  headersRef.current = headers;
86
89
  const messageWindowRef = react.useRef(messageWindow$1);
87
90
  messageWindowRef.current = messageWindow$1;
91
+ const laneHistoryRef = react.useRef(laneHistory);
92
+ laneHistoryRef.current = laneHistory;
88
93
  const interestRef = react.useRef({ attachId: "", stated: false });
89
94
  const lastMessagesRef = react.useRef(null);
90
95
  const [toolOutputsVersion, setToolOutputsVersion] = react.useState(0);
@@ -157,7 +162,9 @@ function useDeepAgentThread({
157
162
  (_a3 = onOutOfBandRunActiveRef.current) == null ? void 0 : _a3.call(onOutOfBandRunActiveRef, stateOutOfBandRunActive);
158
163
  });
159
164
  }
160
- const protocolStatus = protocol.projectDeepAgentProtocol(state);
165
+ const protocolStatus = protocol.projectDeepAgentProtocol(state, {
166
+ laneHistory: laneHistoryRef.current
167
+ });
161
168
  if (protocolStatus !== null) {
162
169
  const previous = ((_a2 = lastProtocolRef.current) == null ? void 0 : _a2.attachId) === attachIdRef.current ? lastProtocolRef.current.status : null;
163
170
  if (previous === null || previous.protocolVersion !== protocolStatus.protocolVersion) {
@@ -236,7 +243,7 @@ function useDeepAgentThread({
236
243
  }
237
244
  const conversionCacheRef = react.useRef(null);
238
245
  if (conversionCacheRef.current === null || conversionCacheRef.current.attachId !== attachId) {
239
- conversionCacheRef.current = { attachId, cache: messages.createDeepAgentMessageConversionCache() };
246
+ conversionCacheRef.current = { attachId, cache: createConversionCache() };
240
247
  }
241
248
  const conversionCache = conversionCacheRef.current.cache;
242
249
  const lastStateMessagesRef = react.useRef(
@@ -246,7 +253,7 @@ function useDeepAgentThread({
246
253
  (wireState, meta) => {
247
254
  var _a2, _b, _c, _d, _e, _f, _g;
248
255
  const values = statewireState.readDeepAgentStreamValues(wireState);
249
- const window = messageWindow.readDeepAgentMessageWindow(meta.mounted);
256
+ const window = readMessageWindow(meta.mounted);
250
257
  const held = ((_a2 = lastMessagesRef.current) == null ? void 0 : _a2.attachId) === attachId ? lastMessagesRef.current.messages : null;
251
258
  const messages2 = (window == null ? void 0 : window.messages) ?? values.messages ?? held ?? [];
252
259
  if (window !== null || messages2.length > 0) lastMessagesRef.current = { attachId, messages: messages2 };
@@ -337,7 +344,7 @@ function useDeepAgentThread({
337
344
  }
338
345
  return converter(state, ((_g = (_f = state.runs) == null ? void 0 : _f[0]) == null ? void 0 : _g.status) === "running", conversionCache);
339
346
  },
340
- [attachId, conversionCache, converter, materialize, threadId]
347
+ [attachId, conversionCache, converter, materialize, readMessageWindow, threadId]
341
348
  );
342
349
  return reactStatewire.StatewireThread({
343
350
  // The transport stamps this protocol on every command; the thread client
@@ -388,6 +395,7 @@ function useDeepAgentThread({
388
395
  isNew: preloadRef.current.preload,
389
396
  headers: (ctx) => headersRef.current(ctx),
390
397
  messageWindow: messageWindowRef.current,
398
+ laneHistory: laneHistoryRef.current,
391
399
  sessionStore,
392
400
  onAuthResolve: (ctx) => {
393
401
  var _a2;