@athenaintel/react 0.41.3 → 0.42.1

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