@athenaintel/react 0.41.2 → 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 (451) hide show
  1. package/README.md +108 -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.cjs +158 -0
  48. package/dist/agent-runtime/src/durable-thread-snapshot-cache.cjs.map +1 -0
  49. package/dist/agent-runtime/src/durable-thread-snapshot-cache.d.ts +60 -0
  50. package/dist/agent-runtime/src/durable-thread-snapshot-cache.js +158 -0
  51. package/dist/agent-runtime/src/durable-thread-snapshot-cache.js.map +1 -0
  52. package/dist/agent-runtime/src/edit-command.d.ts +156 -0
  53. package/dist/agent-runtime/src/errors.d.ts +174 -0
  54. package/dist/agent-runtime/src/execute-output.d.ts +31 -0
  55. package/dist/agent-runtime/src/generated/runconfig-contract.cjs +16 -2
  56. package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  57. package/dist/agent-runtime/src/generated/runconfig-contract.d.ts +202 -0
  58. package/dist/agent-runtime/src/generated/runconfig-contract.js +16 -2
  59. package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  60. package/dist/agent-runtime/src/github-wake-event.d.ts +77 -0
  61. package/dist/agent-runtime/src/index.d.ts +74 -0
  62. package/dist/agent-runtime/src/interrupts.cjs +17 -0
  63. package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
  64. package/dist/agent-runtime/src/interrupts.d.ts +348 -0
  65. package/dist/agent-runtime/src/interrupts.js +17 -0
  66. package/dist/agent-runtime/src/interrupts.js.map +1 -1
  67. package/dist/agent-runtime/src/lane-follow.d.ts +121 -0
  68. package/dist/agent-runtime/src/lane-history.cjs +209 -0
  69. package/dist/agent-runtime/src/lane-history.cjs.map +1 -0
  70. package/dist/agent-runtime/src/lane-history.d.ts +175 -0
  71. package/dist/agent-runtime/src/lane-history.js +209 -0
  72. package/dist/agent-runtime/src/lane-history.js.map +1 -0
  73. package/dist/agent-runtime/src/lane-images.d.ts +184 -0
  74. package/dist/agent-runtime/src/message-author.d.ts +43 -0
  75. package/dist/agent-runtime/src/message-text.cjs +15 -0
  76. package/dist/agent-runtime/src/message-text.cjs.map +1 -0
  77. package/dist/agent-runtime/src/message-text.d.ts +47 -0
  78. package/dist/agent-runtime/src/message-text.js +15 -0
  79. package/dist/agent-runtime/src/message-text.js.map +1 -0
  80. package/dist/agent-runtime/src/message-window.cjs +15 -1
  81. package/dist/agent-runtime/src/message-window.cjs.map +1 -1
  82. package/dist/agent-runtime/src/message-window.d.ts +159 -0
  83. package/dist/agent-runtime/src/message-window.js +16 -2
  84. package/dist/agent-runtime/src/message-window.js.map +1 -1
  85. package/dist/agent-runtime/src/messages.cjs +88 -4
  86. package/dist/agent-runtime/src/messages.cjs.map +1 -1
  87. package/dist/agent-runtime/src/messages.d.ts +603 -0
  88. package/dist/agent-runtime/src/messages.js +88 -4
  89. package/dist/agent-runtime/src/messages.js.map +1 -1
  90. package/dist/agent-runtime/src/model-context.d.ts +22 -0
  91. package/dist/agent-runtime/src/offline-status.d.ts +157 -0
  92. package/dist/agent-runtime/src/optimistic-content.d.ts +21 -0
  93. package/dist/agent-runtime/src/protocol.cjs +12 -4
  94. package/dist/agent-runtime/src/protocol.cjs.map +1 -1
  95. package/dist/agent-runtime/src/protocol.d.ts +119 -0
  96. package/dist/agent-runtime/src/protocol.js +13 -5
  97. package/dist/agent-runtime/src/protocol.js.map +1 -1
  98. package/dist/agent-runtime/src/ptc-subcalls.d.ts +51 -0
  99. package/dist/agent-runtime/src/queue.d.ts +138 -0
  100. package/dist/agent-runtime/src/quota-safe-local-storage-session.d.ts +154 -0
  101. package/dist/agent-runtime/src/running-tool-placeholder.cjs +11 -0
  102. package/dist/agent-runtime/src/running-tool-placeholder.cjs.map +1 -0
  103. package/dist/agent-runtime/src/running-tool-placeholder.d.ts +25 -0
  104. package/dist/agent-runtime/src/running-tool-placeholder.js +11 -0
  105. package/dist/agent-runtime/src/running-tool-placeholder.js.map +1 -0
  106. package/dist/agent-runtime/src/runtime-messages.d.ts +104 -0
  107. package/dist/agent-runtime/src/screen-point.d.ts +151 -0
  108. package/dist/agent-runtime/src/sealed-idb.cjs +112 -0
  109. package/dist/agent-runtime/src/sealed-idb.cjs.map +1 -0
  110. package/dist/agent-runtime/src/sealed-idb.d.ts +106 -0
  111. package/dist/agent-runtime/src/sealed-idb.js +112 -0
  112. package/dist/agent-runtime/src/sealed-idb.js.map +1 -0
  113. package/dist/agent-runtime/src/send-recovery.d.ts +40 -0
  114. package/dist/agent-runtime/src/statewire-attach-observer.d.ts +194 -0
  115. package/dist/agent-runtime/src/statewire-diagnostics.d.ts +74 -0
  116. package/dist/agent-runtime/src/statewire-state.d.ts +29 -0
  117. package/dist/agent-runtime/src/statewire-suspended.cjs.map +1 -1
  118. package/dist/agent-runtime/src/statewire-suspended.d.ts +27 -0
  119. package/dist/agent-runtime/src/statewire-suspended.js.map +1 -1
  120. package/dist/agent-runtime/src/statewire-transport.d.ts +40 -0
  121. package/dist/agent-runtime/src/streaming-markdown.d.ts +46 -0
  122. package/dist/agent-runtime/src/subagent-transcripts.cjs +209 -0
  123. package/dist/agent-runtime/src/subagent-transcripts.cjs.map +1 -0
  124. package/dist/agent-runtime/src/subagent-transcripts.d.ts +71 -0
  125. package/dist/agent-runtime/src/subagent-transcripts.js +209 -0
  126. package/dist/agent-runtime/src/subagent-transcripts.js.map +1 -0
  127. package/dist/agent-runtime/src/subagents.cjs +253 -0
  128. package/dist/agent-runtime/src/subagents.cjs.map +1 -0
  129. package/dist/agent-runtime/src/subagents.d.ts +311 -0
  130. package/dist/agent-runtime/src/subagents.js +253 -0
  131. package/dist/agent-runtime/src/subagents.js.map +1 -0
  132. package/dist/agent-runtime/src/subscription-wake-event.d.ts +111 -0
  133. package/dist/agent-runtime/src/thread-extras.d.ts +43 -0
  134. package/dist/agent-runtime/src/thread-handoff.d.ts +364 -0
  135. package/dist/agent-runtime/src/thread-prewarm-controller.d.ts +76 -0
  136. package/dist/agent-runtime/src/thread-prewarm.d.ts +118 -0
  137. package/dist/agent-runtime/src/thread-snapshot-cache.d.ts +99 -0
  138. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs +329 -0
  139. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs.map +1 -0
  140. package/dist/agent-runtime/src/thread-snapshot-mirror.d.ts +101 -0
  141. package/dist/agent-runtime/src/thread-snapshot-mirror.js +329 -0
  142. package/dist/agent-runtime/src/thread-snapshot-mirror.js.map +1 -0
  143. package/dist/agent-runtime/src/thread-status.d.ts +53 -0
  144. package/dist/agent-runtime/src/tool-metadata.d.ts +146 -0
  145. package/dist/agent-runtime/src/tool-names.cjs +67 -0
  146. package/dist/agent-runtime/src/tool-names.cjs.map +1 -1
  147. package/dist/agent-runtime/src/tool-names.d.ts +60 -0
  148. package/dist/agent-runtime/src/tool-names.js +68 -1
  149. package/dist/agent-runtime/src/tool-names.js.map +1 -1
  150. package/dist/agent-runtime/src/tool-outputs.d.ts +35 -0
  151. package/dist/agent-runtime/src/tool-result.cjs +1 -0
  152. package/dist/agent-runtime/src/tool-result.cjs.map +1 -1
  153. package/dist/agent-runtime/src/tool-result.d.ts +126 -0
  154. package/dist/agent-runtime/src/tool-result.js +1 -0
  155. package/dist/agent-runtime/src/tool-result.js.map +1 -1
  156. package/dist/agent-runtime/src/types.d.ts +159 -0
  157. package/dist/agent-runtime/src/use-conversation-list.d.ts +76 -0
  158. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +136 -0
  159. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -0
  160. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +64 -0
  161. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +136 -0
  162. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -0
  163. package/dist/agent-runtime/src/use-deep-agent-config.d.ts +169 -0
  164. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs +13 -0
  165. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs.map +1 -1
  166. package/dist/agent-runtime/src/use-deep-agent-edit-submit.d.ts +22 -0
  167. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js +13 -0
  168. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js.map +1 -1
  169. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +20 -2
  170. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  171. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +168 -0
  172. package/dist/agent-runtime/src/use-deep-agent-runtime.js +20 -2
  173. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  174. package/dist/agent-runtime/src/use-deep-agent-thread.cjs +12 -4
  175. package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
  176. package/dist/agent-runtime/src/use-deep-agent-thread.d.ts +320 -0
  177. package/dist/agent-runtime/src/use-deep-agent-thread.js +12 -4
  178. package/dist/agent-runtime/src/use-deep-agent-thread.js.map +1 -1
  179. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +999 -0
  180. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -0
  181. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +409 -0
  182. package/dist/agent-runtime/src/use-deep-agent-voice.js +999 -0
  183. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -0
  184. package/dist/agent-runtime/src/use-deep-agent-window-sync.d.ts +102 -0
  185. package/dist/agent-runtime/src/use-historical-edit-attachments.d.ts +2 -0
  186. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +84 -0
  187. package/dist/agent-runtime/src/voice-presentation.d.ts +80 -0
  188. package/dist/agent-runtime/src/voice-turn-grouping.d.ts +28 -0
  189. package/dist/agent-runtime/src/voice-wire-types.d.ts +15 -0
  190. package/dist/agent-runtime/src/withdrawn-turns.d.ts +97 -0
  191. package/dist/chat/AthenaChat.cjs +77 -6
  192. package/dist/chat/AthenaChat.cjs.map +1 -1
  193. package/dist/chat/AthenaChat.js +78 -7
  194. package/dist/chat/AthenaChat.js.map +1 -1
  195. package/dist/chat/StatewireApprovalCard.d.ts +1 -1
  196. package/dist/chat/StatewireClientToolBridge.d.ts +1 -1
  197. package/dist/chat/StatewireQueuedMessages.cjs +11 -4
  198. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  199. package/dist/chat/StatewireQueuedMessages.d.ts +1 -1
  200. package/dist/chat/StatewireQueuedMessages.js +11 -4
  201. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  202. package/dist/chat/chat-outbox-rows.cjs +223 -0
  203. package/dist/chat/chat-outbox-rows.cjs.map +1 -0
  204. package/dist/chat/chat-outbox-rows.d.ts +29 -0
  205. package/dist/chat/chat-outbox-rows.js +223 -0
  206. package/dist/chat/chat-outbox-rows.js.map +1 -0
  207. package/dist/chat/statewire-approval.d.ts +1 -1
  208. package/dist/chat/statewire-client-tools.d.ts +1 -1
  209. package/dist/chat/super-grouping/SuperGroupingCard.cjs +3 -1
  210. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  211. package/dist/chat/super-grouping/SuperGroupingCard.d.ts +7 -1
  212. package/dist/chat/super-grouping/SuperGroupingCard.js +3 -1
  213. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  214. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +7 -2
  215. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  216. package/dist/chat/super-grouping/SuperGroupingTranscript.d.ts +2 -2
  217. package/dist/chat/super-grouping/SuperGroupingTranscript.js +7 -2
  218. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  219. package/dist/chat/super-grouping/activity-timeline.cjs +19 -11
  220. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  221. package/dist/chat/super-grouping/activity-timeline.d.ts +25 -9
  222. package/dist/chat/super-grouping/activity-timeline.js +19 -11
  223. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  224. package/dist/chat/use-statewire-approval-request.cjs +36 -0
  225. package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
  226. package/dist/chat/use-statewire-approval-request.d.ts +49 -1
  227. package/dist/chat/use-statewire-approval-request.js +39 -3
  228. package/dist/chat/use-statewire-approval-request.js.map +1 -1
  229. package/dist/chat-ui/composer/tiptap-composer.cjs +102 -3
  230. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  231. package/dist/chat-ui/composer/tiptap-composer.d.ts +32 -1
  232. package/dist/chat-ui/composer/tiptap-composer.js +103 -4
  233. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  234. package/dist/chat-ui/header/conversation-history-panel.d.ts +1 -1
  235. package/dist/chat-ui/index.d.ts +1 -1
  236. package/dist/chat-ui/messages/message-components.cjs +15 -0
  237. package/dist/chat-ui/messages/message-components.cjs.map +1 -1
  238. package/dist/chat-ui/messages/message-components.js +15 -0
  239. package/dist/chat-ui/messages/message-components.js.map +1 -1
  240. package/dist/chat-ui/messages/runtime-message.d.ts +1 -1
  241. package/dist/chat-ui/messages/statewire-continue-run.d.ts +1 -1
  242. package/dist/chat-ui/messages/user-edit-composer.cjs +15 -2
  243. package/dist/chat-ui/messages/user-edit-composer.cjs.map +1 -1
  244. package/dist/chat-ui/messages/user-edit-composer.d.ts +4 -2
  245. package/dist/chat-ui/messages/user-edit-composer.js +15 -2
  246. package/dist/chat-ui/messages/user-edit-composer.js.map +1 -1
  247. package/dist/chat-ui/messages/wake-marker.d.ts +1 -1
  248. package/dist/chat-ui/rich-text/chat-text-schema.cjs +1 -0
  249. package/dist/chat-ui/rich-text/chat-text-schema.cjs.map +1 -1
  250. package/dist/chat-ui/rich-text/chat-text-schema.d.ts +3 -0
  251. package/dist/chat-ui/rich-text/chat-text-schema.js +1 -0
  252. package/dist/chat-ui/rich-text/chat-text-schema.js.map +1 -1
  253. package/dist/chat-ui/statewire.cjs +1 -0
  254. package/dist/chat-ui/statewire.cjs.map +1 -1
  255. package/dist/chat-ui/statewire.d.ts +2 -2
  256. package/dist/chat-ui/statewire.js +2 -1
  257. package/dist/chat-ui/thread/statewire-history-edge.d.ts +1 -1
  258. package/dist/composer/AttachmentContext.cjs +8 -4
  259. package/dist/composer/AttachmentContext.cjs.map +1 -1
  260. package/dist/composer/AttachmentContext.d.ts +7 -0
  261. package/dist/composer/AttachmentContext.js +8 -4
  262. package/dist/composer/AttachmentContext.js.map +1 -1
  263. package/dist/composer/build-composed-message.cjs +34 -0
  264. package/dist/composer/build-composed-message.cjs.map +1 -1
  265. package/dist/composer/build-composed-message.d.ts +20 -0
  266. package/dist/composer/build-composed-message.js +35 -1
  267. package/dist/composer/build-composed-message.js.map +1 -1
  268. package/dist/composer/composer-handoff.cjs +39 -2
  269. package/dist/composer/composer-handoff.cjs.map +1 -1
  270. package/dist/composer/composer-handoff.d.ts +28 -3
  271. package/dist/composer/composer-handoff.js +39 -2
  272. package/dist/composer/composer-handoff.js.map +1 -1
  273. package/dist/composer/useAttachFiles.cjs +15 -2
  274. package/dist/composer/useAttachFiles.cjs.map +1 -1
  275. package/dist/composer/useAttachFiles.d.ts +11 -0
  276. package/dist/composer/useAttachFiles.js +15 -2
  277. package/dist/composer/useAttachFiles.js.map +1 -1
  278. package/dist/composer/useSendMessage.cjs.map +1 -1
  279. package/dist/composer/useSendMessage.d.ts +4 -3
  280. package/dist/composer/useSendMessage.js.map +1 -1
  281. package/dist/diagnostics/athena-diagnostics.cjs.map +1 -1
  282. package/dist/diagnostics/athena-diagnostics.d.ts +3 -1
  283. package/dist/diagnostics/athena-diagnostics.js.map +1 -1
  284. package/dist/index.cjs +18 -0
  285. package/dist/index.cjs.map +1 -1
  286. package/dist/index.d.ts +15 -6
  287. package/dist/index.js +19 -1
  288. package/dist/index.js.map +1 -1
  289. package/dist/offline/chat-outbox.cjs +57 -0
  290. package/dist/offline/chat-outbox.cjs.map +1 -0
  291. package/dist/offline/chat-outbox.d.ts +80 -0
  292. package/dist/offline/chat-outbox.js +57 -0
  293. package/dist/offline/chat-outbox.js.map +1 -0
  294. package/dist/offline/offline-history.cjs +77 -0
  295. package/dist/offline/offline-history.cjs.map +1 -0
  296. package/dist/offline/offline-history.d.ts +60 -0
  297. package/dist/offline/offline-history.js +77 -0
  298. package/dist/offline/offline-history.js.map +1 -0
  299. package/dist/provider/AthenaProvider.cjs +206 -9
  300. package/dist/provider/AthenaProvider.cjs.map +1 -1
  301. package/dist/provider/AthenaProvider.d.ts +22 -1
  302. package/dist/provider/AthenaProvider.js +207 -10
  303. package/dist/provider/AthenaProvider.js.map +1 -1
  304. package/dist/provider/statewire-window-context.d.ts +1 -1
  305. package/dist/react/package.json.cjs +1 -1
  306. package/dist/react/package.json.js +1 -1
  307. package/dist/references/src/anchors/file-line-range.d.ts +58 -0
  308. package/dist/references/src/anchors/format.d.ts +21 -0
  309. package/dist/references/src/anchors/message-anchors.d.ts +71 -0
  310. package/dist/references/src/anchors/parse.d.ts +8 -0
  311. package/dist/references/src/anchors/registry-contract.d.ts +24 -0
  312. package/dist/references/src/anchors/registry.d.ts +19 -0
  313. package/dist/references/src/anchors/schemas.d.ts +194 -0
  314. package/dist/references/src/anchors/serialize.d.ts +8 -0
  315. package/dist/references/src/anchors/time.d.ts +78 -0
  316. package/dist/references/src/anchors/types.d.ts +474 -0
  317. package/dist/references/src/asset-bounds.d.ts +27 -0
  318. package/dist/references/src/asset-links.d.ts +23 -0
  319. package/dist/references/src/asset-reference.d.ts +16 -0
  320. package/dist/references/src/formats/format-catalog.d.ts +79 -0
  321. package/dist/references/src/formats/markdown/parse-reference-markdown.d.ts +28 -0
  322. package/dist/references/src/formats/markdown/reference-display-name.d.ts +6 -0
  323. package/dist/references/src/formats/object/asset-object.d.ts +9 -0
  324. package/dist/references/src/formats/object/callable-object.d.ts +6 -0
  325. package/dist/references/src/formats/object/decode-reference-object-payload.d.ts +3 -0
  326. package/dist/references/src/formats/object/external-url-object.d.ts +9 -0
  327. package/dist/references/src/formats/object/group-object.d.ts +9 -0
  328. package/dist/references/src/formats/object/navigation-object.d.ts +9 -0
  329. package/dist/references/src/formats/object/parse-reference-object.d.ts +11 -0
  330. package/dist/references/src/formats/object/person-object.d.ts +9 -0
  331. package/dist/references/src/formats/uri/asset-mention-uri.d.ts +9 -0
  332. package/dist/references/src/formats/uri/asset-spaces-url.d.ts +9 -0
  333. package/dist/references/src/formats/uri/callable-mention-uris.d.ts +9 -0
  334. package/dist/references/src/formats/uri/detect-uri-wire.d.ts +9 -0
  335. package/dist/references/src/formats/uri/group-mention-uri.d.ts +12 -0
  336. package/dist/references/src/formats/uri/navigation-spaces-url.d.ts +14 -0
  337. package/dist/references/src/formats/uri/parse-reference-uri.d.ts +20 -0
  338. package/dist/references/src/formats/uri/person-mention-uri.d.ts +9 -0
  339. package/dist/references/src/formats/uri/template-placeholder.d.ts +12 -0
  340. package/dist/references/src/index.d.ts +47 -0
  341. package/dist/references/src/legacy/index.d.ts +14 -0
  342. package/dist/references/src/legacy/pre-reference-asset-url.d.ts +57 -0
  343. package/dist/references/src/legacy/pre-reference-citation-bridge.d.ts +22 -0
  344. package/dist/references/src/legacy/pre-reference-citation.d.ts +138 -0
  345. package/dist/references/src/legacy/pre-reference-external-url.d.ts +31 -0
  346. package/dist/references/src/legacy/pre-reference-format.d.ts +8 -0
  347. package/dist/references/src/legacy/pre-reference-mention.d.ts +27 -0
  348. package/dist/references/src/legacy/pre-reference-object.d.ts +8 -0
  349. package/dist/references/src/legacy/pre-reference-uri.d.ts +12 -0
  350. package/dist/references/src/legacy.d.ts +2 -0
  351. package/dist/references/src/mention-href-patterns.d.ts +19 -0
  352. package/dist/references/src/mention-node/index.d.ts +5 -0
  353. package/dist/references/src/mention-node/mention-node.d.ts +31 -0
  354. package/dist/references/src/mention-node/resolve-node-attrs.d.ts +27 -0
  355. package/dist/references/src/parse-reference.d.ts +23 -0
  356. package/dist/references/src/schemas.d.ts +463 -0
  357. package/dist/references/src/serialize-reference.d.ts +50 -0
  358. package/dist/references/src/sheet-name.d.ts +10 -0
  359. package/dist/references/src/tool-option-schemas.d.ts +597 -0
  360. package/dist/references/src/types.d.ts +125 -0
  361. package/dist/references/src/version-ref.d.ts +30 -0
  362. package/dist/runtime/statewire-lifecycle.d.ts +1 -1
  363. package/dist/runtime/statewire-model-lane.d.ts +1 -1
  364. package/dist/runtime/statewire-server-lane-context.d.ts +1 -1
  365. package/dist/runtime/statewire-session-key.cjs +7 -0
  366. package/dist/runtime/statewire-session-key.cjs.map +1 -1
  367. package/dist/runtime/statewire-session-key.d.ts +16 -0
  368. package/dist/runtime/statewire-session-key.js +8 -1
  369. package/dist/runtime/statewire-session-key.js.map +1 -1
  370. package/dist/runtime/statewire-session-lane.cjs +48 -0
  371. package/dist/runtime/statewire-session-lane.cjs.map +1 -0
  372. package/dist/runtime/statewire-session-lane.d.ts +29 -0
  373. package/dist/runtime/statewire-session-lane.js +48 -0
  374. package/dist/runtime/statewire-session-lane.js.map +1 -0
  375. package/dist/runtime/statewire-thread-config-lane.d.ts +1 -1
  376. package/dist/runtime/useAthenaStatewireRuntime.cjs +16 -5
  377. package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
  378. package/dist/runtime/useAthenaStatewireRuntime.d.ts +15 -1
  379. package/dist/runtime/useAthenaStatewireRuntime.js +17 -6
  380. package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
  381. package/dist/styles.css +1 -1
  382. package/dist/threads/api.d.ts +1 -1
  383. package/dist/threads/conversation-list-fetcher.d.ts +1 -1
  384. package/dist/threads/index-triggered-refresh.cjs +164 -0
  385. package/dist/threads/index-triggered-refresh.cjs.map +1 -0
  386. package/dist/threads/index-triggered-refresh.d.ts +70 -0
  387. package/dist/threads/index-triggered-refresh.js +164 -0
  388. package/dist/threads/index-triggered-refresh.js.map +1 -0
  389. package/dist/threads/offline-session-list.cjs +75 -0
  390. package/dist/threads/offline-session-list.cjs.map +1 -0
  391. package/dist/threads/offline-session-list.d.ts +27 -0
  392. package/dist/threads/offline-session-list.js +75 -0
  393. package/dist/threads/offline-session-list.js.map +1 -0
  394. package/dist/threads/pull-request-display.d.ts +1 -1
  395. package/dist/threads/session-list-model.d.ts +1 -1
  396. package/dist/threads/session-list-tab-share.cjs +150 -0
  397. package/dist/threads/session-list-tab-share.cjs.map +1 -0
  398. package/dist/threads/session-list-tab-share.d.ts +73 -0
  399. package/dist/threads/session-list-tab-share.js +150 -0
  400. package/dist/threads/session-list-tab-share.js.map +1 -0
  401. package/dist/threads/session-row-parts.d.ts +1 -1
  402. package/dist/threads/sessions-query.d.ts +1 -1
  403. package/dist/threads/statewire-thread-list.cjs +105 -20
  404. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  405. package/dist/threads/statewire-thread-list.d.ts +31 -3
  406. package/dist/threads/statewire-thread-list.js +107 -22
  407. package/dist/threads/statewire-thread-list.js.map +1 -1
  408. package/dist/threads/thread-prefetcher.d.ts +1 -1
  409. package/dist/threads/use-athena-session-attention.d.ts +1 -1
  410. package/dist/threads/use-athena-sessions.cjs +32 -22
  411. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  412. package/dist/threads/use-athena-sessions.js +33 -23
  413. package/dist/threads/use-athena-sessions.js.map +1 -1
  414. package/dist/threads/use-rest-conversation-history.d.ts +1 -1
  415. package/dist/threads/use-statewire-conversation-history.d.ts +5 -5
  416. package/dist/tiptap-markdown-table/src/markdown-table-serializer.d.ts +56 -0
  417. package/dist/tools/NestedPtcMessages.cjs +14 -9
  418. package/dist/tools/NestedPtcMessages.cjs.map +1 -1
  419. package/dist/tools/NestedPtcMessages.d.ts +9 -0
  420. package/dist/tools/NestedPtcMessages.js +6 -1
  421. package/dist/tools/NestedPtcMessages.js.map +1 -1
  422. package/dist/tools/index.d.ts +1 -1
  423. package/dist/tools/primitives.d.ts +1 -1
  424. package/dist/tools/subagent-task-tool-ui.cjs +494 -0
  425. package/dist/tools/subagent-task-tool-ui.cjs.map +1 -0
  426. package/dist/tools/subagent-task-tool-ui.d.ts +109 -0
  427. package/dist/tools/subagent-task-tool-ui.js +494 -0
  428. package/dist/tools/subagent-task-tool-ui.js.map +1 -0
  429. package/dist/tools/tool-fallback.d.ts +1 -1
  430. package/dist/tools/tool-icons.d.ts +1 -1
  431. package/dist/tools/tool-summary.d.ts +1 -1
  432. package/dist/tools/tool-uis.cjs +4 -0
  433. package/dist/tools/tool-uis.cjs.map +1 -1
  434. package/dist/tools/tool-uis.js +4 -0
  435. package/dist/tools/tool-uis.js.map +1 -1
  436. package/dist/voice/chat.cjs +6 -0
  437. package/dist/voice/chat.cjs.map +1 -0
  438. package/dist/voice/chat.d.ts +2 -0
  439. package/dist/voice/chat.js +6 -0
  440. package/dist/voice/chat.js.map +1 -0
  441. package/dist/voice/livekit-join.cjs +119 -0
  442. package/dist/voice/livekit-join.cjs.map +1 -0
  443. package/dist/voice/livekit-join.d.ts +8 -0
  444. package/dist/voice/livekit-join.js +119 -0
  445. package/dist/voice/livekit-join.js.map +1 -0
  446. package/dist/voice/livekit.cjs +32 -0
  447. package/dist/voice/livekit.cjs.map +1 -0
  448. package/dist/voice/livekit.d.ts +80 -0
  449. package/dist/voice/livekit.js +32 -0
  450. package/dist/voice/livekit.js.map +1 -0
  451. package/package.json +20 -10
@@ -0,0 +1,999 @@
1
+ import { useStatewireSendCommand, useStatewireState } from "@assistant-ui/react-statewire";
2
+ import { useRef, useCallback, useState, useEffect, useMemo } from "react";
3
+ import { statewireRejectionPayload } from "./errors.js";
4
+ import { readDeepAgentStreamValues, isDeepAgentStateHydrated } from "./statewire-state.js";
5
+ const readSendFailure = (error) => {
6
+ const failure = error == null ? void 0 : error.failure;
7
+ if (failure === null || typeof failure !== "object") return null;
8
+ return typeof failure.fate === "string" ? failure : null;
9
+ };
10
+ const errorMessage = (error) => error instanceof Error ? error.message : String(error);
11
+ class VoiceAnswerTimeoutError extends Error {
12
+ constructor() {
13
+ super("The voice session did not answer in time");
14
+ this.name = "VoiceAnswerTimeoutError";
15
+ }
16
+ }
17
+ const classifyVoiceStartError = (error) => {
18
+ if (error instanceof VoiceAnswerTimeoutError) {
19
+ return { kind: "answer_timeout", message: error.message };
20
+ }
21
+ const failure = readSendFailure(error);
22
+ if (failure === null) return { kind: "unknown", message: errorMessage(error) };
23
+ if (failure.fate === "rejected") {
24
+ const payload = failure.payload;
25
+ const detail = payload == null ? void 0 : payload.detail;
26
+ const reason = typeof (payload == null ? void 0 : payload.reason) === "string" ? payload.reason : void 0;
27
+ const detailCode = typeof (detail == null ? void 0 : detail.code) === "string" ? detail.code : void 0;
28
+ const detailMessage = typeof (detail == null ? void 0 : detail.message) === "string" ? detail.message : void 0;
29
+ const code = reason ?? detailCode ?? failure.code;
30
+ const status = typeof (payload == null ? void 0 : payload.status) === "number" ? payload.status : void 0;
31
+ return {
32
+ kind: "server_rejected",
33
+ message: failure.message ?? detailMessage ?? errorMessage(error),
34
+ ...code !== void 0 && { code },
35
+ ...status !== void 0 && { status }
36
+ };
37
+ }
38
+ return {
39
+ kind: "command_failed",
40
+ message: failure.message ?? errorMessage(error),
41
+ fate: failure.fate,
42
+ ...failure.cause !== void 0 && failure.cause !== "server" && { reason: failure.cause }
43
+ };
44
+ };
45
+ class VoiceNoAnswerError extends Error {
46
+ constructor(message) {
47
+ super(message);
48
+ this.name = "VoiceNoAnswerError";
49
+ }
50
+ }
51
+ const parseVoiceLiveKitAnswer = (answer) => {
52
+ if (!answer.startsWith(VOICE_LIVEKIT_ANSWER_PREFIX)) {
53
+ throw new VoiceNoAnswerError("voice/start returned no voice room");
54
+ }
55
+ let parsed;
56
+ try {
57
+ parsed = JSON.parse(answer.slice(VOICE_LIVEKIT_ANSWER_PREFIX.length));
58
+ } catch {
59
+ throw new VoiceNoAnswerError("voice/start returned a malformed voice room");
60
+ }
61
+ const record = parsed ?? null;
62
+ const serverUrl = record == null ? void 0 : record.serverUrl;
63
+ const token = record == null ? void 0 : record.token;
64
+ const roomName = record == null ? void 0 : record.roomName;
65
+ if (typeof serverUrl !== "string" || serverUrl === "" || typeof token !== "string" || token === "" || typeof roomName !== "string" || roomName === "") {
66
+ throw new VoiceNoAnswerError("voice/start returned an incomplete voice room");
67
+ }
68
+ return { serverUrl, token, roomName };
69
+ };
70
+ const classifyStartFailure = (error, stage) => {
71
+ const message = errorMessage(error);
72
+ switch (stage) {
73
+ case "preflight":
74
+ return { kind: "unsupported", stage, message };
75
+ case "audio-session":
76
+ return { kind: "audio_session", stage, message };
77
+ case "capture":
78
+ return {
79
+ kind: isMicrophoneDenied(error) ? "microphone_denied" : "capture_failed",
80
+ stage,
81
+ message
82
+ };
83
+ case "offer":
84
+ return { kind: "offer_failed", stage, message };
85
+ case "negotiate":
86
+ return { ...classifyVoiceStartError(error), stage };
87
+ case "answer":
88
+ return {
89
+ kind: error instanceof VoiceNoAnswerError ? "no_answer" : "answer_failed",
90
+ stage,
91
+ message
92
+ };
93
+ case "relay":
94
+ return { kind: "relay_failed", stage, message };
95
+ case "room":
96
+ return {
97
+ kind: isMicrophoneDenied(error) ? "microphone_denied" : "room_failed",
98
+ stage,
99
+ message
100
+ };
101
+ default:
102
+ return { kind: "unknown", stage, message };
103
+ }
104
+ };
105
+ const isMicrophoneDenied = (error) => {
106
+ const name = error == null ? void 0 : error.name;
107
+ if (name === "SecurityError" || name === "NotAllowedError" || name === "PermissionDeniedError") {
108
+ return true;
109
+ }
110
+ return /permission|denied|not allowed/i.test(errorMessage(error));
111
+ };
112
+ const describeVoiceFailure = (failure) => {
113
+ switch (failure.kind) {
114
+ case "microphone_denied":
115
+ return "Microphone access is blocked. Allow the microphone for Athena and try again.";
116
+ case "unsupported":
117
+ return "Voice mode is not available in this environment.";
118
+ case "audio_session":
119
+ return `The audio session could not start: ${failure.message}`;
120
+ case "answer_timeout":
121
+ return "The voice session did not answer in time. Check your connection and try again.";
122
+ case "room_failed":
123
+ return "The voice room could not be joined. Check your connection and try again.";
124
+ case "media_lost":
125
+ return "The voice connection was lost. Start voice again to continue.";
126
+ case "server_rejected":
127
+ if (failure.code === "voice-active") {
128
+ return "A voice session is already live on another device or tab. End it there first.";
129
+ }
130
+ if (failure.code === "voice-not-enabled") {
131
+ return "Voice mode is not enabled for this workspace.";
132
+ }
133
+ return failure.message;
134
+ default:
135
+ return failure.message;
136
+ }
137
+ };
138
+ const VOICE_WEBSOCKET_OFFER = "athena-voice-transport:websocket/v1";
139
+ const VOICE_RELAY_ANSWER_PREFIX = "athena-voice-relay:";
140
+ const VOICE_RELAY_SAMPLE_RATE = 24e3;
141
+ const VOICE_LIVEKIT_OFFER = "athena-voice-transport:livekit/v1";
142
+ const VOICE_LIVEKIT_ANSWER_PREFIX = "athena-voice-livekit:";
143
+ const VOICE_MODEL_PROVIDERS = /* @__PURE__ */ new Set(["openai_live", "google"]);
144
+ const parseVoiceModelOptions = (value) => {
145
+ if (!Array.isArray(value)) return null;
146
+ const options = [];
147
+ for (const entry of value) {
148
+ if (entry === null || typeof entry !== "object") continue;
149
+ const { id, label, provider, enabled, description } = entry;
150
+ if (typeof id !== "string" || id === "" || typeof label !== "string" || typeof provider !== "string" || !VOICE_MODEL_PROVIDERS.has(provider) || typeof enabled !== "boolean" || typeof description !== "string") {
151
+ continue;
152
+ }
153
+ options.push({
154
+ id,
155
+ label,
156
+ provider,
157
+ enabled,
158
+ description
159
+ });
160
+ }
161
+ return options;
162
+ };
163
+ const sameVoiceModelOptions = (a, b) => a.length === b.length && a.every((option, index) => {
164
+ const other = b[index];
165
+ return other !== void 0 && option.id === other.id && option.label === other.label && option.provider === other.provider && option.enabled === other.enabled && option.description === other.description;
166
+ });
167
+ function releaseCaptureStream(stream) {
168
+ if (!stream) return;
169
+ releaseSafely(() => {
170
+ for (const track of stream.getTracks()) releaseSafely(() => track.stop());
171
+ });
172
+ releaseSafely(() => {
173
+ var _a;
174
+ return (_a = stream.release) == null ? void 0 : _a.call(stream);
175
+ });
176
+ }
177
+ function releaseSafely(release) {
178
+ try {
179
+ void Promise.resolve(release()).catch(() => void 0);
180
+ } catch {
181
+ }
182
+ }
183
+ const voiceGlobals = globalThis;
184
+ const ANSWER_TIMEOUT_MS = 45e3;
185
+ const ICE_TIMEOUT_MS = 1e4;
186
+ const RELAY_OPEN_TIMEOUT_MS = 1e4;
187
+ const RELAY_CAPTURE_FRAME_SAMPLES = 1024;
188
+ const RELAY_PLAYBACK_LEAD_SECONDS = 0.02;
189
+ const MEDIA_DISCONNECT_GRACE_MS = 5e3;
190
+ const END_BEFORE_RESTART_TIMEOUT_MS = 3e3;
191
+ const mintVoiceTextId = () => `voicetext_${Date.now().toString(36)}${Math.random().toString(36).slice(2, 12)}`;
192
+ const REQUEST_LABELS = {
193
+ "session.commentary.append": "a result for the voice conversation",
194
+ "session.thinking.append": "a context update",
195
+ "session.input_audio.mute": "the mute request",
196
+ "session.input_audio.unmute": "the unmute request",
197
+ "response.item.create": "a tool result"
198
+ };
199
+ const describeVoiceWireError = (error) => {
200
+ const subject = error.requestType ? REQUEST_LABELS[error.requestType] ?? `a ${error.requestType} event` : "a session event";
201
+ return `The voice service rejected ${subject}: ${error.message}`;
202
+ };
203
+ const voiceRelayUrl = (relayUrl, ticket) => `${relayUrl.replace(/^http/, "ws").replace(/\/+$/, "")}/api/voice/relay?ticket=${encodeURIComponent(ticket)}`;
204
+ const pcm16FromFloat32 = (samples) => {
205
+ const pcm = new Int16Array(samples.length);
206
+ for (let index = 0; index < samples.length; index += 1) {
207
+ const clamped = Math.max(-1, Math.min(1, samples[index] ?? 0));
208
+ pcm[index] = clamped < 0 ? Math.round(clamped * 32768) : Math.round(clamped * 32767);
209
+ }
210
+ return pcm;
211
+ };
212
+ const float32FromPcm16 = (pcm) => {
213
+ const samples = new Float32Array(pcm.length);
214
+ for (let index = 0; index < pcm.length; index += 1) {
215
+ samples[index] = (pcm[index] ?? 0) / 32768;
216
+ }
217
+ return samples;
218
+ };
219
+ const isRecoveredCommandAuthRejection = (error) => {
220
+ const payload = statewireRejectionPayload(error);
221
+ if ((payload == null ? void 0 : payload.status) !== 503) return false;
222
+ const detail = payload.detail;
223
+ return (detail == null ? void 0 : detail.code) === "command_auth_context_expired" && detail.retryable === true;
224
+ };
225
+ const waitForIce = (pc, timeoutMs) => new Promise((resolve) => {
226
+ if (pc.iceGatheringState === "complete") {
227
+ resolve("complete");
228
+ return;
229
+ }
230
+ const timeout = setTimeout(() => {
231
+ pc.removeEventListener("icegatheringstatechange", check);
232
+ resolve("timeout");
233
+ }, timeoutMs);
234
+ const check = () => {
235
+ if (pc.iceGatheringState !== "complete") return;
236
+ clearTimeout(timeout);
237
+ pc.removeEventListener("icegatheringstatechange", check);
238
+ resolve("complete");
239
+ };
240
+ pc.addEventListener("icegatheringstatechange", check);
241
+ });
242
+ const waitForRelayOpen = (ws, timeoutMs) => new Promise((resolve, reject) => {
243
+ const timeout = setTimeout(
244
+ () => reject(new Error("The voice relay did not open in time")),
245
+ timeoutMs
246
+ );
247
+ ws.addEventListener("open", () => {
248
+ clearTimeout(timeout);
249
+ resolve();
250
+ });
251
+ ws.addEventListener("error", () => {
252
+ clearTimeout(timeout);
253
+ reject(new Error("The voice relay connection failed"));
254
+ });
255
+ ws.addEventListener("close", () => {
256
+ clearTimeout(timeout);
257
+ reject(new Error("The voice relay closed before it opened"));
258
+ });
259
+ });
260
+ const useDeepAgentVoice = (options = {}) => {
261
+ const wireSendCommand = useStatewireSendCommand();
262
+ const sendCommandRef = useRef(wireSendCommand);
263
+ sendCommandRef.current = wireSendCommand;
264
+ const sendCommand = useCallback(
265
+ async (command) => sendCommandRef.current(command),
266
+ []
267
+ );
268
+ const voice = useStatewireState(
269
+ // The raw wire state is non-object until the attach snapshot hydrates it.
270
+ (s) => readDeepAgentStreamValues(s).voice ?? null
271
+ );
272
+ const [phase, setPhase] = useState("idle");
273
+ const [failure, setFailure] = useState(null);
274
+ const error = (failure == null ? void 0 : failure.message) ?? null;
275
+ const [micMuted, setMicMutedState] = useState(false);
276
+ const micMutedRef = useRef(false);
277
+ const micChangeRef = useRef(0);
278
+ const [liveSince, setLiveSince] = useState(null);
279
+ const [handoffTask, setHandoffTask] = useState(null);
280
+ const lastActiveTaskRef = useRef(null);
281
+ const pcRef = useRef(null);
282
+ const releasePeerListenersRef = useRef(null);
283
+ const streamRef = useRef(null);
284
+ const wsRef = useRef(null);
285
+ const audioContextRef = useRef(null);
286
+ const audioNodesRef = useRef([]);
287
+ const playheadRef = useRef(0);
288
+ const livekitRef = useRef(null);
289
+ const livekitAbortRef = useRef(null);
290
+ const attemptRef = useRef(0);
291
+ const startingRef = useRef(false);
292
+ const startPromiseRef = useRef(null);
293
+ const autoRestartedRef = useRef(false);
294
+ const onRemoteStreamRef = useRef(options.onRemoteStream);
295
+ onRemoteStreamRef.current = options.onRemoteStream;
296
+ const audioSessionRef = useRef(options.audioSession);
297
+ audioSessionRef.current = options.audioSession;
298
+ const transportRef = useRef(options.transport ?? "webrtc");
299
+ transportRef.current = options.transport ?? "webrtc";
300
+ const relayUrlRef = useRef(options.relayUrl);
301
+ relayUrlRef.current = options.relayUrl;
302
+ const livekitAdapterRef = useRef(options.livekit);
303
+ livekitAdapterRef.current = options.livekit;
304
+ const modelRef = useRef(options.model);
305
+ modelRef.current = options.model;
306
+ const onDiagnosticRef = useRef(options.onDiagnostic);
307
+ onDiagnosticRef.current = options.onDiagnostic;
308
+ const timeoutsRef = useRef(options.timeouts);
309
+ timeoutsRef.current = options.timeouts;
310
+ const phaseRef = useRef("idle");
311
+ phaseRef.current = phase;
312
+ const attemptStartedAtRef = useRef(0);
313
+ const activeAudioSessionRef = useRef(null);
314
+ const startingAudioSessionRef = useRef(null);
315
+ const audioSessionIdleRef = useRef(Promise.resolve());
316
+ const report = useCallback(
317
+ (event, attempt, data) => {
318
+ const observer = onDiagnosticRef.current;
319
+ if (!observer) return;
320
+ const at = Date.now();
321
+ try {
322
+ observer({
323
+ event,
324
+ attempt,
325
+ at,
326
+ sinceStartMs: Math.max(0, at - attemptStartedAtRef.current),
327
+ ...data !== void 0 && { data }
328
+ });
329
+ } catch {
330
+ }
331
+ },
332
+ []
333
+ );
334
+ const releaseAudioSession = useCallback(() => {
335
+ const session = activeAudioSessionRef.current;
336
+ if (!session) return;
337
+ activeAudioSessionRef.current = null;
338
+ audioSessionIdleRef.current = audioSessionIdleRef.current.then(() => session.stop()).catch(() => void 0);
339
+ }, []);
340
+ const teardown = useCallback(() => {
341
+ attemptRef.current += 1;
342
+ const livekitAbort = livekitAbortRef.current;
343
+ livekitAbortRef.current = null;
344
+ releaseSafely(() => livekitAbort == null ? void 0 : livekitAbort.abort());
345
+ releaseSafely(() => {
346
+ var _a, _b;
347
+ return (_b = (_a = startingAudioSessionRef.current) == null ? void 0 : _a.cancelStart) == null ? void 0 : _b.call(_a);
348
+ });
349
+ releaseAudioSession();
350
+ const releasePeerListeners = releasePeerListenersRef.current;
351
+ releasePeerListenersRef.current = null;
352
+ releaseSafely(() => releasePeerListeners == null ? void 0 : releasePeerListeners());
353
+ const pc = pcRef.current;
354
+ pcRef.current = null;
355
+ releaseSafely(() => pc == null ? void 0 : pc.close());
356
+ const ws = wsRef.current;
357
+ wsRef.current = null;
358
+ releaseSafely(() => {
359
+ if (ws && ws.readyState < 2) ws.close(1e3, "client end");
360
+ });
361
+ const nodes = audioNodesRef.current;
362
+ audioNodesRef.current = [];
363
+ for (const node of nodes) releaseSafely(() => node.disconnect());
364
+ const audio = audioContextRef.current;
365
+ audioContextRef.current = null;
366
+ releaseSafely(() => audio == null ? void 0 : audio.close());
367
+ playheadRef.current = 0;
368
+ const livekit = livekitRef.current;
369
+ livekitRef.current = null;
370
+ releaseSafely(() => livekit == null ? void 0 : livekit.disconnect());
371
+ const stream = streamRef.current;
372
+ streamRef.current = null;
373
+ releaseCaptureStream(stream);
374
+ setLiveSince(null);
375
+ releaseSafely(() => {
376
+ var _a;
377
+ return (_a = onRemoteStreamRef.current) == null ? void 0 : _a.call(onRemoteStreamRef, null);
378
+ });
379
+ }, [releaseAudioSession]);
380
+ const fail = useCallback(
381
+ (nextFailure) => {
382
+ report("error", attemptRef.current, {
383
+ kind: nextFailure.kind,
384
+ stage: nextFailure.stage,
385
+ message: nextFailure.message,
386
+ code: nextFailure.code ?? null,
387
+ status: nextFailure.status ?? null,
388
+ fate: nextFailure.fate ?? null,
389
+ reason: nextFailure.reason ?? null
390
+ });
391
+ teardown();
392
+ setFailure(nextFailure);
393
+ setPhase("error");
394
+ },
395
+ [report, teardown]
396
+ );
397
+ const handleMediaLossRef = useRef(
398
+ async () => void 0
399
+ );
400
+ const watchConnection = useCallback((pc, attempt) => {
401
+ let disconnectTimer = null;
402
+ const clearDisconnectTimer = () => {
403
+ if (disconnectTimer === null) return;
404
+ clearTimeout(disconnectTimer);
405
+ disconnectTimer = null;
406
+ };
407
+ const onChange = () => {
408
+ if (attemptRef.current !== attempt) {
409
+ clearDisconnectTimer();
410
+ return;
411
+ }
412
+ const state = pc.connectionState ?? pc.iceConnectionState;
413
+ report("media-state", attempt, {
414
+ connectionState: pc.connectionState ?? null,
415
+ iceConnectionState: pc.iceConnectionState ?? null
416
+ });
417
+ if (state === "failed" || state === "closed") {
418
+ clearDisconnectTimer();
419
+ void handleMediaLossRef.current(attempt, state);
420
+ return;
421
+ }
422
+ if (state === "disconnected") {
423
+ if (disconnectTimer !== null) return;
424
+ disconnectTimer = setTimeout(() => {
425
+ disconnectTimer = null;
426
+ if (attemptRef.current !== attempt) return;
427
+ void handleMediaLossRef.current(attempt, "disconnected");
428
+ }, MEDIA_DISCONNECT_GRACE_MS);
429
+ return;
430
+ }
431
+ clearDisconnectTimer();
432
+ };
433
+ pc.addEventListener("connectionstatechange", onChange);
434
+ pc.addEventListener("iceconnectionstatechange", onChange);
435
+ return () => {
436
+ clearDisconnectTimer();
437
+ releaseSafely(() => pc.removeEventListener("connectionstatechange", onChange));
438
+ releaseSafely(() => pc.removeEventListener("iceconnectionstatechange", onChange));
439
+ };
440
+ }, [report]);
441
+ const playRelayChunk = useCallback((audio, data) => {
442
+ const pcm = new Int16Array(data);
443
+ if (pcm.length === 0) return;
444
+ const samples = float32FromPcm16(pcm);
445
+ const buffer = audio.createBuffer(1, samples.length, VOICE_RELAY_SAMPLE_RATE);
446
+ buffer.copyToChannel(samples, 0);
447
+ const node = audio.createBufferSource();
448
+ node.buffer = buffer;
449
+ node.connect(audio.destination);
450
+ const startAt = Math.max(audio.currentTime + RELAY_PLAYBACK_LEAD_SECONDS, playheadRef.current);
451
+ node.start(startAt);
452
+ playheadRef.current = startAt + buffer.duration;
453
+ }, []);
454
+ const runStartSession = useCallback(async () => {
455
+ var _a, _b, _c;
456
+ const attempt = attemptRef.current += 1;
457
+ startingRef.current = true;
458
+ attemptStartedAtRef.current = Date.now();
459
+ setFailure(null);
460
+ setPhase("connecting");
461
+ let stage = "preflight";
462
+ const timeouts = timeoutsRef.current;
463
+ const iceGatheringMs = (timeouts == null ? void 0 : timeouts.iceGatheringMs) ?? ICE_TIMEOUT_MS;
464
+ const answerMs = (timeouts == null ? void 0 : timeouts.answerMs) ?? ANSWER_TIMEOUT_MS;
465
+ const relayOpenMs = (timeouts == null ? void 0 : timeouts.relayOpenMs) ?? RELAY_OPEN_TIMEOUT_MS;
466
+ const stale = () => {
467
+ report("stale-attempt", attempt, { stage });
468
+ releaseAudioSession();
469
+ };
470
+ report("start-requested", attempt, { transport: transportRef.current });
471
+ try {
472
+ const transport = transportRef.current;
473
+ const mediaDevices = (_a = voiceGlobals.navigator) == null ? void 0 : _a.mediaDevices;
474
+ const PeerConnection = voiceGlobals.RTCPeerConnection;
475
+ const WebSocketCtor = voiceGlobals.WebSocket;
476
+ const AudioContextCtor = voiceGlobals.AudioContext;
477
+ const livekitAdapter = livekitAdapterRef.current;
478
+ if (transport === "livekit" && !livekitAdapter)
479
+ throw new Error("Voice is unavailable in this environment");
480
+ if (transport !== "livekit" && !mediaDevices)
481
+ throw new Error("Microphone capture is unavailable in this environment");
482
+ if (transport === "webrtc" && !PeerConnection)
483
+ throw new Error("WebRTC is unavailable in this environment");
484
+ if (transport === "websocket" && (!WebSocketCtor || !AudioContextCtor))
485
+ throw new Error("WebSocket audio is unavailable in this environment");
486
+ const relayUrl = relayUrlRef.current;
487
+ if (transport === "websocket" && !relayUrl)
488
+ throw new Error("The websocket voice transport needs a relay URL");
489
+ const audioSession = audioSessionRef.current;
490
+ if (audioSession) {
491
+ stage = "audio-session";
492
+ await audioSessionIdleRef.current;
493
+ if (attemptRef.current !== attempt) {
494
+ report("stale-attempt", attempt, { stage });
495
+ return;
496
+ }
497
+ startingAudioSessionRef.current = audioSession;
498
+ try {
499
+ await audioSession.start();
500
+ } finally {
501
+ startingAudioSessionRef.current = null;
502
+ }
503
+ activeAudioSessionRef.current = audioSession;
504
+ if (attemptRef.current !== attempt) {
505
+ stale();
506
+ return;
507
+ }
508
+ report("audio-session-ready", attempt);
509
+ }
510
+ const modelOption = modelRef.current;
511
+ const requestedModel = typeof modelOption === "function" ? modelOption() : modelOption;
512
+ const model2 = typeof requestedModel === "string" && requestedModel !== "" ? requestedModel : void 0;
513
+ const sendVoiceStart = (offer2) => sendCommand({
514
+ type: "voice/start",
515
+ offer: offer2,
516
+ ...model2 !== void 0 && { model: model2 }
517
+ });
518
+ const negotiateStart = async (offer2) => {
519
+ stage = "negotiate";
520
+ const negotiationStartedAt = Date.now();
521
+ const commandPromise = sendVoiceStart(offer2).catch((commandError) => {
522
+ if (!isRecoveredCommandAuthRejection(commandError)) throw commandError;
523
+ return sendVoiceStart(offer2);
524
+ });
525
+ void commandPromise.then(() => {
526
+ if (attemptRef.current !== attempt)
527
+ void sendCommand({ type: "voice/end" }).catch(() => void 0);
528
+ }).catch(() => void 0);
529
+ let answerTimer = null;
530
+ let result;
531
+ try {
532
+ result = await Promise.race([
533
+ commandPromise,
534
+ new Promise((_, reject) => {
535
+ answerTimer = setTimeout(() => reject(new VoiceAnswerTimeoutError()), answerMs);
536
+ })
537
+ ]);
538
+ } finally {
539
+ if (answerTimer !== null) clearTimeout(answerTimer);
540
+ }
541
+ report("answer-received", attempt, {
542
+ negotiationMs: Date.now() - negotiationStartedAt
543
+ });
544
+ stage = "answer";
545
+ const answer2 = result == null ? void 0 : result.answer;
546
+ if (typeof answer2 !== "string" || answer2 === "")
547
+ throw new VoiceNoAnswerError("voice/start returned no answer");
548
+ return answer2;
549
+ };
550
+ if (transport === "livekit") {
551
+ if (!livekitAdapter) return;
552
+ const answer2 = await negotiateStart(VOICE_LIVEKIT_OFFER);
553
+ if (attemptRef.current !== attempt) {
554
+ stale();
555
+ return;
556
+ }
557
+ try {
558
+ const room = parseVoiceLiveKitAnswer(answer2);
559
+ stage = "room";
560
+ let joined = false;
561
+ let disconnectedWhileJoining = false;
562
+ const controller = new AbortController();
563
+ livekitAbortRef.current = controller;
564
+ const session = await livekitAdapter.connect(room, {
565
+ micMuted: micMutedRef.current,
566
+ signal: controller.signal,
567
+ onDisconnected: (reason) => {
568
+ if (attemptRef.current !== attempt) return;
569
+ if (!joined) {
570
+ disconnectedWhileJoining = true;
571
+ return;
572
+ }
573
+ void handleMediaLossRef.current(attempt, reason);
574
+ }
575
+ });
576
+ if (attemptRef.current !== attempt) {
577
+ releaseSafely(() => session.disconnect());
578
+ stale();
579
+ return;
580
+ }
581
+ if (disconnectedWhileJoining) {
582
+ releaseSafely(() => session.disconnect());
583
+ throw new Error("The voice room disconnected while joining");
584
+ }
585
+ joined = true;
586
+ livekitRef.current = session;
587
+ report("room-joined", attempt, { roomName: room.roomName });
588
+ } catch (roomError) {
589
+ if (attemptRef.current === attempt)
590
+ void sendCommand({ type: "voice/end" }).catch(() => void 0);
591
+ throw roomError;
592
+ }
593
+ report("live", attempt, { transport, ...model2 !== void 0 && { model: model2 } });
594
+ if (micMutedRef.current) {
595
+ void sendCommand({ type: "voice/set-mic", paused: true }).catch(() => void 0);
596
+ }
597
+ setPhase("live");
598
+ setLiveSince(Date.now());
599
+ return;
600
+ }
601
+ if (!mediaDevices) return;
602
+ stage = "capture";
603
+ const stream = await mediaDevices.getUserMedia({ audio: true });
604
+ if (attemptRef.current !== attempt) {
605
+ releaseCaptureStream(stream);
606
+ stale();
607
+ return;
608
+ }
609
+ streamRef.current = stream;
610
+ for (const track of stream.getTracks()) track.enabled = !micMutedRef.current;
611
+ report("microphone-captured", attempt, {
612
+ tracks: stream.getTracks().length
613
+ });
614
+ if (transport === "websocket") {
615
+ if (!WebSocketCtor || !AudioContextCtor || !relayUrl) return;
616
+ const answer2 = await negotiateStart(VOICE_WEBSOCKET_OFFER);
617
+ if (attemptRef.current !== attempt) {
618
+ stale();
619
+ return;
620
+ }
621
+ if (!answer2.startsWith(VOICE_RELAY_ANSWER_PREFIX))
622
+ throw new VoiceNoAnswerError("voice/start returned no relay ticket");
623
+ stage = "relay";
624
+ const ticket = answer2.slice(VOICE_RELAY_ANSWER_PREFIX.length);
625
+ const ws = new WebSocketCtor(voiceRelayUrl(relayUrl, ticket));
626
+ ws.binaryType = "arraybuffer";
627
+ wsRef.current = ws;
628
+ await waitForRelayOpen(ws, relayOpenMs);
629
+ if (attemptRef.current !== attempt) {
630
+ stale();
631
+ return;
632
+ }
633
+ const audio = new AudioContextCtor({
634
+ sampleRate: VOICE_RELAY_SAMPLE_RATE
635
+ });
636
+ audioContextRef.current = audio;
637
+ await ((_b = audio.resume) == null ? void 0 : _b.call(audio));
638
+ if (attemptRef.current !== attempt) {
639
+ stale();
640
+ return;
641
+ }
642
+ const source = audio.createMediaStreamSource(stream);
643
+ const processor = audio.createScriptProcessor(RELAY_CAPTURE_FRAME_SAMPLES, 1, 1);
644
+ const sink = audio.createGain();
645
+ sink.gain.value = 0;
646
+ processor.onaudioprocess = (event) => {
647
+ if (attemptRef.current !== attempt || ws.readyState !== 1) return;
648
+ ws.send(pcm16FromFloat32(event.inputBuffer.getChannelData(0)).buffer);
649
+ };
650
+ source.connect(processor);
651
+ processor.connect(sink);
652
+ sink.connect(audio.destination);
653
+ audioNodesRef.current = [source, processor, sink];
654
+ playheadRef.current = 0;
655
+ ws.addEventListener("message", (event) => {
656
+ if (attemptRef.current !== attempt) return;
657
+ if (event.data instanceof ArrayBuffer) playRelayChunk(audio, event.data);
658
+ });
659
+ ws.addEventListener("close", () => {
660
+ if (attemptRef.current !== attempt) return;
661
+ void handleMediaLossRef.current(attempt, "relay-closed");
662
+ });
663
+ ws.addEventListener("error", () => {
664
+ if (attemptRef.current !== attempt) return;
665
+ void handleMediaLossRef.current(attempt, "relay-error");
666
+ });
667
+ report("live", attempt, { transport });
668
+ if (micMutedRef.current) {
669
+ void sendCommand({ type: "voice/set-mic", paused: true }).catch(() => void 0);
670
+ }
671
+ setPhase("live");
672
+ setLiveSince(Date.now());
673
+ return;
674
+ }
675
+ if (!PeerConnection) return;
676
+ stage = "offer";
677
+ const pc = new PeerConnection();
678
+ pcRef.current = pc;
679
+ for (const track of stream.getTracks()) pc.addTrack(track, stream);
680
+ const onTrack = async (trackEvent) => {
681
+ var _a2;
682
+ if (attemptRef.current !== attempt) return;
683
+ try {
684
+ const remote = trackEvent.streams[0] ?? (voiceGlobals.MediaStream ? new voiceGlobals.MediaStream([trackEvent.track]) : null);
685
+ if (!remote) return;
686
+ await ((_a2 = onRemoteStreamRef.current) == null ? void 0 : _a2.call(onRemoteStreamRef, remote));
687
+ } catch (playError) {
688
+ if (attemptRef.current !== attempt) return;
689
+ void sendCommand({ type: "voice/end" }).catch(() => void 0);
690
+ fail({
691
+ kind: "playback_failed",
692
+ stage: "playback",
693
+ message: `Audio playback: ${errorMessage(playError)}`
694
+ });
695
+ }
696
+ };
697
+ pc.addEventListener("track", onTrack);
698
+ const unwatchConnection = watchConnection(pc, attempt);
699
+ releasePeerListenersRef.current = () => {
700
+ unwatchConnection();
701
+ releaseSafely(() => pc.removeEventListener("track", onTrack));
702
+ };
703
+ const offer = await pc.createOffer();
704
+ await pc.setLocalDescription(offer);
705
+ const iceStartedAt = Date.now();
706
+ const iceOutcome = await waitForIce(pc, iceGatheringMs);
707
+ if (attemptRef.current !== attempt) {
708
+ stale();
709
+ return;
710
+ }
711
+ if (iceOutcome === "timeout") {
712
+ report("ice-gathering-timeout", attempt, {
713
+ waitedMs: Date.now() - iceStartedAt,
714
+ iceGatheringState: pc.iceGatheringState
715
+ });
716
+ }
717
+ const sdp = (_c = pc.localDescription) == null ? void 0 : _c.sdp;
718
+ if (!sdp) throw new Error("failed to create a local SDP offer");
719
+ report("offer-ready", attempt, {
720
+ iceGatheringMs: Date.now() - iceStartedAt,
721
+ iceGathering: iceOutcome,
722
+ sdpBytes: sdp.length
723
+ });
724
+ const answer = await negotiateStart(sdp);
725
+ if (attemptRef.current !== attempt) {
726
+ stale();
727
+ return;
728
+ }
729
+ await pc.setRemoteDescription({ type: "answer", sdp: answer });
730
+ if (attemptRef.current !== attempt) {
731
+ stale();
732
+ return;
733
+ }
734
+ report("live", attempt, { transport });
735
+ if (micMutedRef.current) {
736
+ void sendCommand({ type: "voice/set-mic", paused: true }).catch(() => void 0);
737
+ }
738
+ setPhase("live");
739
+ setLiveSince(Date.now());
740
+ } catch (startError) {
741
+ if (attemptRef.current !== attempt) {
742
+ stale();
743
+ return;
744
+ }
745
+ fail(classifyStartFailure(startError, stage));
746
+ } finally {
747
+ startingRef.current = false;
748
+ }
749
+ }, [fail, playRelayChunk, releaseAudioSession, report, sendCommand, watchConnection]);
750
+ const startSession = useCallback(async () => {
751
+ if (pcRef.current || wsRef.current || livekitRef.current || startingRef.current) return;
752
+ const run = runStartSession();
753
+ startPromiseRef.current = run;
754
+ try {
755
+ await run;
756
+ } finally {
757
+ if (startPromiseRef.current === run) startPromiseRef.current = null;
758
+ }
759
+ }, [runStartSession]);
760
+ const startRef = useRef(startSession);
761
+ startRef.current = startSession;
762
+ const handleMediaLoss = useCallback(
763
+ async (attempt, reason) => {
764
+ if (attemptRef.current !== attempt) return;
765
+ report("media-loss", attempt, {
766
+ reason,
767
+ restartBudgetLeft: !autoRestartedRef.current
768
+ });
769
+ if (lastActiveTaskRef.current) setHandoffTask(lastActiveTaskRef.current);
770
+ const ending = sendCommand({ type: "voice/end" }).catch(() => void 0);
771
+ teardown();
772
+ const recovery = attemptRef.current;
773
+ setPhase("idle");
774
+ let endTimer;
775
+ try {
776
+ await Promise.race([
777
+ ending,
778
+ new Promise((resolve) => {
779
+ endTimer = setTimeout(resolve, END_BEFORE_RESTART_TIMEOUT_MS);
780
+ })
781
+ ]);
782
+ } finally {
783
+ clearTimeout(endTimer);
784
+ }
785
+ const inflight = startPromiseRef.current;
786
+ if (inflight) await inflight.catch(() => void 0);
787
+ if (attemptRef.current !== recovery) return;
788
+ if (!autoRestartedRef.current) {
789
+ autoRestartedRef.current = true;
790
+ report("auto-restart", recovery, { trigger: "media-loss", reason });
791
+ await startRef.current();
792
+ return;
793
+ }
794
+ if (startingRef.current || pcRef.current || wsRef.current || livekitRef.current) return;
795
+ const lost = {
796
+ kind: "media_lost",
797
+ stage: "media",
798
+ message: `The voice connection was lost (${reason})`,
799
+ reason
800
+ };
801
+ report("error", recovery, {
802
+ kind: lost.kind,
803
+ stage: lost.stage,
804
+ message: lost.message,
805
+ reason
806
+ });
807
+ setFailure(lost);
808
+ setPhase("error");
809
+ },
810
+ [report, sendCommand, teardown]
811
+ );
812
+ handleMediaLossRef.current = handleMediaLoss;
813
+ const start = useCallback(async () => {
814
+ if (pcRef.current || wsRef.current || livekitRef.current || startingRef.current) return;
815
+ micMutedRef.current = false;
816
+ setMicMutedState(false);
817
+ autoRestartedRef.current = false;
818
+ setHandoffTask(null);
819
+ await startSession();
820
+ }, [startSession]);
821
+ const end = useCallback(() => {
822
+ if (phase === "connecting" || phase === "live") {
823
+ report("end", attemptRef.current, { source: "user", phase });
824
+ void sendCommand({ type: "voice/end" }).catch(() => void 0);
825
+ if (lastActiveTaskRef.current) setHandoffTask(lastActiveTaskRef.current);
826
+ }
827
+ teardown();
828
+ micMutedRef.current = false;
829
+ setMicMutedState(false);
830
+ setPhase("idle");
831
+ }, [phase, report, sendCommand, teardown]);
832
+ const setMicMuted = useCallback(
833
+ (muted) => {
834
+ if (phase !== "live") return;
835
+ const attempt = attemptRef.current;
836
+ const change = ++micChangeRef.current;
837
+ const applyLocal = (value) => {
838
+ var _a;
839
+ micMutedRef.current = value;
840
+ setMicMutedState(value);
841
+ for (const track of ((_a = streamRef.current) == null ? void 0 : _a.getTracks()) ?? []) track.enabled = !value;
842
+ const room = livekitRef.current;
843
+ if (room) releaseSafely(() => room.setMicrophoneEnabled(!value));
844
+ };
845
+ applyLocal(muted);
846
+ void sendCommand({ type: "voice/set-mic", paused: muted }).catch(() => {
847
+ if (!muted && attemptRef.current === attempt && micChangeRef.current === change) {
848
+ applyLocal(true);
849
+ }
850
+ });
851
+ },
852
+ [phase, sendCommand]
853
+ );
854
+ const sessionGone = useStatewireState(
855
+ (s) => isDeepAgentStateHydrated(s) && (readDeepAgentStreamValues(s).voice ?? null) === null
856
+ );
857
+ useEffect(() => {
858
+ var _a;
859
+ if (phase !== "live" || !sessionGone) return;
860
+ report("server-ended", attemptRef.current, {
861
+ restartBudgetLeft: !autoRestartedRef.current
862
+ });
863
+ if (lastActiveTaskRef.current) setHandoffTask(lastActiveTaskRef.current);
864
+ teardown();
865
+ setPhase("idle");
866
+ if (!autoRestartedRef.current) {
867
+ autoRestartedRef.current = true;
868
+ report("auto-restart", attemptRef.current, { trigger: "server-ended" });
869
+ void ((_a = startRef.current) == null ? void 0 : _a.call(startRef));
870
+ }
871
+ }, [phase, report, sessionGone, teardown]);
872
+ useEffect(
873
+ () => () => {
874
+ const phaseAtUnmount = phaseRef.current;
875
+ if (phaseAtUnmount === "connecting" || phaseAtUnmount === "live") {
876
+ report("end", attemptRef.current, {
877
+ source: "unmount",
878
+ phase: phaseAtUnmount
879
+ });
880
+ void sendCommand({ type: "voice/end" }).catch(() => void 0);
881
+ }
882
+ teardown();
883
+ },
884
+ [report, sendCommand, teardown]
885
+ );
886
+ const activeTask = (voice == null ? void 0 : voice.activeTask) ?? null;
887
+ useEffect(() => {
888
+ if (phase === "live") lastActiveTaskRef.current = activeTask;
889
+ else if (phase === "idle" || phase === "error") lastActiveTaskRef.current = null;
890
+ }, [phase, activeTask]);
891
+ const handoffRunActive = useStatewireState((s) => {
892
+ if (!isDeepAgentStateHydrated(s)) return true;
893
+ const status = readDeepAgentStreamValues(s).status;
894
+ return status === "running" || status === "stopping" || status === "input-required";
895
+ });
896
+ useEffect(() => {
897
+ if (handoffTask !== null && !handoffRunActive) setHandoffTask(null);
898
+ }, [handoffTask, handoffRunActive]);
899
+ const wireError = useStatewireState(
900
+ (s) => isDeepAgentStateHydrated(s) ? readDeepAgentStreamValues(s).voiceLastError ?? null : null
901
+ );
902
+ const notice = phase === "live" && wireError ? describeVoiceWireError(wireError) : null;
903
+ const model = useStatewireState((s) => {
904
+ if (!isDeepAgentStateHydrated(s)) return null;
905
+ const value = readDeepAgentStreamValues(s).voiceModel;
906
+ return typeof value === "string" && value !== "" ? value : null;
907
+ });
908
+ const wireModelOptions = useStatewireState(
909
+ (s) => isDeepAgentStateHydrated(s) ? readDeepAgentStreamValues(s).voiceModelOptions ?? null : null
910
+ );
911
+ const modelOptionsRef = useRef(null);
912
+ const modelOptions = useMemo(() => {
913
+ const next = parseVoiceModelOptions(wireModelOptions);
914
+ const previous = modelOptionsRef.current;
915
+ if (previous !== null && next !== null && sameVoiceModelOptions(previous, next)) return previous;
916
+ modelOptionsRef.current = next;
917
+ return next;
918
+ }, [wireModelOptions]);
919
+ const syncProfile = useCallback(() => {
920
+ if (phase !== "connecting" && phase !== "live") return;
921
+ void sendCommand({ type: "voice/profile-sync" }).catch(() => void 0);
922
+ }, [phase, sendCommand]);
923
+ const sendContext = useCallback(
924
+ (text) => {
925
+ const trimmed = text.trim();
926
+ if (phase !== "live" || !trimmed) return;
927
+ void sendCommand({ type: "voice/context", text: trimmed }).catch(() => void 0);
928
+ },
929
+ [phase, sendCommand]
930
+ );
931
+ const sendUserText = useCallback(
932
+ async (text) => {
933
+ if (phase !== "live" || !text.trim()) return false;
934
+ const messageId = mintVoiceTextId();
935
+ try {
936
+ await sendCommand({ type: "voice/user-text", text, messageId });
937
+ return true;
938
+ } catch {
939
+ return false;
940
+ }
941
+ },
942
+ [phase, sendCommand]
943
+ );
944
+ return useMemo(
945
+ () => ({
946
+ phase,
947
+ error,
948
+ failure,
949
+ start,
950
+ end,
951
+ activeTask,
952
+ liveSince,
953
+ micMuted,
954
+ setMicMuted,
955
+ sendUserText,
956
+ handoffTask,
957
+ syncProfile,
958
+ notice,
959
+ sendContext,
960
+ model,
961
+ modelOptions
962
+ }),
963
+ [
964
+ phase,
965
+ error,
966
+ failure,
967
+ start,
968
+ end,
969
+ activeTask,
970
+ liveSince,
971
+ micMuted,
972
+ setMicMuted,
973
+ sendUserText,
974
+ handoffTask,
975
+ syncProfile,
976
+ notice,
977
+ sendContext,
978
+ model,
979
+ modelOptions
980
+ ]
981
+ );
982
+ };
983
+ export {
984
+ VOICE_LIVEKIT_ANSWER_PREFIX,
985
+ VOICE_LIVEKIT_OFFER,
986
+ VOICE_RELAY_ANSWER_PREFIX,
987
+ VOICE_RELAY_SAMPLE_RATE,
988
+ VOICE_WEBSOCKET_OFFER,
989
+ classifyVoiceStartError,
990
+ describeVoiceFailure,
991
+ describeVoiceWireError,
992
+ float32FromPcm16,
993
+ parseVoiceLiveKitAnswer,
994
+ parseVoiceModelOptions,
995
+ pcm16FromFloat32,
996
+ useDeepAgentVoice,
997
+ voiceRelayUrl
998
+ };
999
+ //# sourceMappingURL=use-deep-agent-voice.js.map