@athenaintel/react 0.48.0 → 0.52.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 (255) hide show
  1. package/README.md +68 -10
  2. package/dist/agent-runtime/src/call-recap.cjs +319 -0
  3. package/dist/agent-runtime/src/call-recap.cjs.map +1 -0
  4. package/dist/agent-runtime/src/call-recap.d.ts +142 -0
  5. package/dist/agent-runtime/src/call-recap.js +319 -0
  6. package/dist/agent-runtime/src/call-recap.js.map +1 -0
  7. package/dist/agent-runtime/src/chat-outbox-store.cjs +1 -0
  8. package/dist/agent-runtime/src/chat-outbox-store.cjs.map +1 -1
  9. package/dist/agent-runtime/src/chat-outbox-store.d.ts +7 -0
  10. package/dist/agent-runtime/src/chat-outbox-store.js +1 -0
  11. package/dist/agent-runtime/src/chat-outbox-store.js.map +1 -1
  12. package/dist/agent-runtime/src/chat-outbox.cjs +46 -5
  13. package/dist/agent-runtime/src/chat-outbox.cjs.map +1 -1
  14. package/dist/agent-runtime/src/chat-outbox.d.ts +29 -0
  15. package/dist/agent-runtime/src/chat-outbox.js +46 -5
  16. package/dist/agent-runtime/src/chat-outbox.js.map +1 -1
  17. package/dist/agent-runtime/src/conversation-index.cjs.map +1 -1
  18. package/dist/agent-runtime/src/conversation-index.d.ts +7 -0
  19. package/dist/agent-runtime/src/conversation-index.js.map +1 -1
  20. package/dist/agent-runtime/src/conversation-list.cjs +2 -1
  21. package/dist/agent-runtime/src/conversation-list.cjs.map +1 -1
  22. package/dist/agent-runtime/src/conversation-list.d.ts +19 -3
  23. package/dist/agent-runtime/src/conversation-list.js +2 -1
  24. package/dist/agent-runtime/src/conversation-list.js.map +1 -1
  25. package/dist/agent-runtime/src/desktop-handoff.d.ts +10 -0
  26. package/dist/agent-runtime/src/edit-command.cjs +21 -0
  27. package/dist/agent-runtime/src/edit-command.cjs.map +1 -1
  28. package/dist/agent-runtime/src/edit-command.d.ts +8 -0
  29. package/dist/agent-runtime/src/edit-command.js +21 -0
  30. package/dist/agent-runtime/src/edit-command.js.map +1 -1
  31. package/dist/agent-runtime/src/handoff-arrival.cjs +19 -0
  32. package/dist/agent-runtime/src/handoff-arrival.cjs.map +1 -1
  33. package/dist/agent-runtime/src/handoff-arrival.d.ts +18 -3
  34. package/dist/agent-runtime/src/handoff-arrival.js +20 -1
  35. package/dist/agent-runtime/src/handoff-arrival.js.map +1 -1
  36. package/dist/agent-runtime/src/handoff-cursor-id.cjs +6 -0
  37. package/dist/agent-runtime/src/handoff-cursor-id.cjs.map +1 -0
  38. package/dist/agent-runtime/src/handoff-cursor-id.d.ts +12 -0
  39. package/dist/agent-runtime/src/handoff-cursor-id.js +6 -0
  40. package/dist/agent-runtime/src/handoff-cursor-id.js.map +1 -0
  41. package/dist/agent-runtime/src/handoff-cursor.cjs +88 -0
  42. package/dist/agent-runtime/src/handoff-cursor.cjs.map +1 -0
  43. package/dist/agent-runtime/src/handoff-cursor.d.ts +120 -0
  44. package/dist/agent-runtime/src/handoff-cursor.js +88 -0
  45. package/dist/agent-runtime/src/handoff-cursor.js.map +1 -0
  46. package/dist/agent-runtime/src/index.d.ts +9 -7
  47. package/dist/agent-runtime/src/interrupts.cjs +28 -1
  48. package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
  49. package/dist/agent-runtime/src/interrupts.d.ts +21 -1
  50. package/dist/agent-runtime/src/interrupts.js +28 -1
  51. package/dist/agent-runtime/src/interrupts.js.map +1 -1
  52. package/dist/agent-runtime/src/model-context.cjs +3 -2
  53. package/dist/agent-runtime/src/model-context.cjs.map +1 -1
  54. package/dist/agent-runtime/src/model-context.d.ts +6 -1
  55. package/dist/agent-runtime/src/model-context.js +3 -2
  56. package/dist/agent-runtime/src/model-context.js.map +1 -1
  57. package/dist/agent-runtime/src/runtime.d.ts +3 -2
  58. package/dist/agent-runtime/src/send-recovery.cjs +37 -3
  59. package/dist/agent-runtime/src/send-recovery.cjs.map +1 -1
  60. package/dist/agent-runtime/src/send-recovery.d.ts +19 -0
  61. package/dist/agent-runtime/src/send-recovery.js +37 -3
  62. package/dist/agent-runtime/src/send-recovery.js.map +1 -1
  63. package/dist/agent-runtime/src/thread-handoff-flow-machine.d.ts +14 -8
  64. package/dist/agent-runtime/src/thread-handoff-protocol.d.ts +227 -5
  65. package/dist/agent-runtime/src/thread-handoff.d.ts +1 -1
  66. package/dist/agent-runtime/src/use-conversation-list.cjs +3 -2
  67. package/dist/agent-runtime/src/use-conversation-list.cjs.map +1 -1
  68. package/dist/agent-runtime/src/use-conversation-list.d.ts +6 -0
  69. package/dist/agent-runtime/src/use-conversation-list.js +3 -2
  70. package/dist/agent-runtime/src/use-conversation-list.js.map +1 -1
  71. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +21 -1
  72. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -1
  73. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +8 -2
  74. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +21 -1
  75. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -1
  76. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +24 -6
  77. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  78. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +17 -0
  79. package/dist/agent-runtime/src/use-deep-agent-runtime.js +24 -6
  80. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  81. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +44 -9
  82. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -1
  83. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +34 -1
  84. package/dist/agent-runtime/src/use-deep-agent-voice.js +44 -9
  85. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -1
  86. package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs +8 -3
  87. package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs.map +1 -1
  88. package/dist/agent-runtime/src/use-deep-agent-window-sync.d.ts +7 -0
  89. package/dist/agent-runtime/src/use-deep-agent-window-sync.js +9 -4
  90. package/dist/agent-runtime/src/use-deep-agent-window-sync.js.map +1 -1
  91. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +13 -2
  92. package/dist/agent-runtime/src/voice-earcon.cjs +139 -0
  93. package/dist/agent-runtime/src/voice-earcon.cjs.map +1 -0
  94. package/dist/agent-runtime/src/voice-earcon.d.ts +38 -0
  95. package/dist/agent-runtime/src/voice-earcon.js +139 -0
  96. package/dist/agent-runtime/src/voice-earcon.js.map +1 -0
  97. package/dist/agent-runtime/src/voice-media.cjs.map +1 -1
  98. package/dist/agent-runtime/src/voice-media.d.ts +14 -0
  99. package/dist/agent-runtime/src/voice-media.js.map +1 -1
  100. package/dist/agent-runtime/src/voice-presentation.cjs +2 -0
  101. package/dist/agent-runtime/src/voice-presentation.cjs.map +1 -1
  102. package/dist/agent-runtime/src/voice-presentation.js +2 -0
  103. package/dist/agent-runtime/src/voice-presentation.js.map +1 -1
  104. package/dist/assets/AthenaAssetEmbed.cjs.map +1 -1
  105. package/dist/assets/AthenaAssetEmbed.d.ts +11 -5
  106. package/dist/assets/AthenaAssetEmbed.js.map +1 -1
  107. package/dist/assets/use-asset-embed.cjs.map +1 -1
  108. package/dist/assets/use-asset-embed.d.ts +12 -5
  109. package/dist/assets/use-asset-embed.js.map +1 -1
  110. package/dist/chat/AthenaChat.cjs +27 -12
  111. package/dist/chat/AthenaChat.cjs.map +1 -1
  112. package/dist/chat/AthenaChat.d.ts +13 -0
  113. package/dist/chat/AthenaChat.js +27 -12
  114. package/dist/chat/AthenaChat.js.map +1 -1
  115. package/dist/chat/AthenaPlanStrip.cjs +97 -0
  116. package/dist/chat/AthenaPlanStrip.cjs.map +1 -0
  117. package/dist/chat/AthenaPlanStrip.d.ts +15 -0
  118. package/dist/chat/AthenaPlanStrip.js +97 -0
  119. package/dist/chat/AthenaPlanStrip.js.map +1 -0
  120. package/dist/chat/StatewireApprovalCard.cjs +41 -6
  121. package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
  122. package/dist/chat/StatewireApprovalCard.d.ts +18 -1
  123. package/dist/chat/StatewireApprovalCard.js +42 -7
  124. package/dist/chat/StatewireApprovalCard.js.map +1 -1
  125. package/dist/chat/StatewireQueuedMessages.cjs +56 -6
  126. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  127. package/dist/chat/StatewireQueuedMessages.d.ts +14 -0
  128. package/dist/chat/StatewireQueuedMessages.js +58 -8
  129. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  130. package/dist/chat/WaitingOnYouBanner.cjs +6 -2
  131. package/dist/chat/WaitingOnYouBanner.cjs.map +1 -1
  132. package/dist/chat/WaitingOnYouBanner.js +7 -3
  133. package/dist/chat/WaitingOnYouBanner.js.map +1 -1
  134. package/dist/chat/chat-voice-controls.cjs +3 -1
  135. package/dist/chat/chat-voice-controls.cjs.map +1 -1
  136. package/dist/chat/chat-voice-controls.d.ts +6 -1
  137. package/dist/chat/chat-voice-controls.js +3 -1
  138. package/dist/chat/chat-voice-controls.js.map +1 -1
  139. package/dist/chat/super-grouping/SuperGroupingCard.cjs +4 -2
  140. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  141. package/dist/chat/super-grouping/SuperGroupingCard.js +4 -2
  142. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  143. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +4 -2
  144. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  145. package/dist/chat/super-grouping/SuperGroupingTranscript.js +4 -2
  146. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  147. package/dist/chat/super-grouping/activity-timeline.cjs +6 -4
  148. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  149. package/dist/chat/super-grouping/activity-timeline.d.ts +9 -1
  150. package/dist/chat/super-grouping/activity-timeline.js +6 -4
  151. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  152. package/dist/chat/super-grouping/index.d.ts +1 -1
  153. package/dist/chat/super-grouping/use-earlier-steps-unloaded.cjs +17 -0
  154. package/dist/chat/super-grouping/use-earlier-steps-unloaded.cjs.map +1 -0
  155. package/dist/chat/super-grouping/use-earlier-steps-unloaded.d.ts +8 -0
  156. package/dist/chat/super-grouping/use-earlier-steps-unloaded.js +17 -0
  157. package/dist/chat/super-grouping/use-earlier-steps-unloaded.js.map +1 -0
  158. package/dist/chat-ui/index.cjs +11 -0
  159. package/dist/chat-ui/index.cjs.map +1 -1
  160. package/dist/chat-ui/index.d.ts +3 -1
  161. package/dist/chat-ui/index.js +12 -1
  162. package/dist/chat-ui/index.js.map +1 -1
  163. package/dist/chat-ui/messages/from-the-call-card.cjs +124 -0
  164. package/dist/chat-ui/messages/from-the-call-card.cjs.map +1 -0
  165. package/dist/chat-ui/messages/from-the-call-card.d.ts +17 -0
  166. package/dist/chat-ui/messages/from-the-call-card.js +124 -0
  167. package/dist/chat-ui/messages/from-the-call-card.js.map +1 -0
  168. package/dist/chat-ui/rich-text/chat-link.cjs +1 -0
  169. package/dist/chat-ui/rich-text/chat-link.cjs.map +1 -1
  170. package/dist/chat-ui/rich-text/chat-link.d.ts +4 -0
  171. package/dist/chat-ui/rich-text/chat-link.js +4 -3
  172. package/dist/chat-ui/rich-text/chat-link.js.map +1 -1
  173. package/dist/chat-ui/rich-text/chat-message-body.cjs +1 -0
  174. package/dist/chat-ui/rich-text/chat-message-body.cjs.map +1 -1
  175. package/dist/chat-ui/rich-text/chat-message-body.d.ts +12 -0
  176. package/dist/chat-ui/rich-text/chat-message-body.js +2 -1
  177. package/dist/chat-ui/rich-text/chat-message-body.js.map +1 -1
  178. package/dist/chat-ui/thread/chat-thread-shell.cjs +4 -0
  179. package/dist/chat-ui/thread/chat-thread-shell.cjs.map +1 -1
  180. package/dist/chat-ui/thread/chat-thread-shell.d.ts +4 -0
  181. package/dist/chat-ui/thread/chat-thread-shell.js +4 -0
  182. package/dist/chat-ui/thread/chat-thread-shell.js.map +1 -1
  183. package/dist/chat-ui/thread/handoff-cursor.cjs +216 -0
  184. package/dist/chat-ui/thread/handoff-cursor.cjs.map +1 -0
  185. package/dist/chat-ui/thread/handoff-cursor.d.ts +57 -0
  186. package/dist/chat-ui/thread/handoff-cursor.js +216 -0
  187. package/dist/chat-ui/thread/handoff-cursor.js.map +1 -0
  188. package/dist/chat-ui/thread/statewire-history-edge.cjs +2 -0
  189. package/dist/chat-ui/thread/statewire-history-edge.cjs.map +1 -1
  190. package/dist/chat-ui/thread/statewire-history-edge.d.ts +2 -0
  191. package/dist/chat-ui/thread/statewire-history-edge.js +3 -1
  192. package/dist/chat-ui/thread/statewire-history-edge.js.map +1 -1
  193. package/dist/collab/client.cjs +15 -3
  194. package/dist/collab/client.cjs.map +1 -1
  195. package/dist/collab/client.d.ts +4 -2
  196. package/dist/collab/client.js +16 -4
  197. package/dist/collab/client.js.map +1 -1
  198. package/dist/composer/index.d.ts +1 -1
  199. package/dist/composer/useReadComposerDraft.cjs +26 -7
  200. package/dist/composer/useReadComposerDraft.cjs.map +1 -1
  201. package/dist/composer/useReadComposerDraft.d.ts +23 -1
  202. package/dist/composer/useReadComposerDraft.js +27 -8
  203. package/dist/composer/useReadComposerDraft.js.map +1 -1
  204. package/dist/index.cjs +5 -0
  205. package/dist/index.cjs.map +1 -1
  206. package/dist/index.d.ts +5 -2
  207. package/dist/index.js +6 -1
  208. package/dist/index.js.map +1 -1
  209. package/dist/keryx-http/src/unconfirmed-update-attributions.cjs +207 -0
  210. package/dist/keryx-http/src/unconfirmed-update-attributions.cjs.map +1 -0
  211. package/dist/keryx-http/src/unconfirmed-update-attributions.d.ts +141 -0
  212. package/dist/keryx-http/src/unconfirmed-update-attributions.js +207 -0
  213. package/dist/keryx-http/src/unconfirmed-update-attributions.js.map +1 -0
  214. package/dist/keryx-http/src/update-attributions.cjs +34 -4
  215. package/dist/keryx-http/src/update-attributions.cjs.map +1 -1
  216. package/dist/keryx-http/src/update-attributions.d.ts +36 -4
  217. package/dist/keryx-http/src/update-attributions.js +35 -5
  218. package/dist/keryx-http/src/update-attributions.js.map +1 -1
  219. package/dist/provider/AthenaProvider.cjs +4 -0
  220. package/dist/provider/AthenaProvider.cjs.map +1 -1
  221. package/dist/provider/AthenaProvider.d.ts +11 -1
  222. package/dist/provider/AthenaProvider.js +4 -0
  223. package/dist/provider/AthenaProvider.js.map +1 -1
  224. package/dist/react/package.json.cjs +1 -1
  225. package/dist/react/package.json.js +1 -1
  226. package/dist/styles.css +1 -1
  227. package/dist/threads/api.cjs.map +1 -1
  228. package/dist/threads/api.d.ts +15 -0
  229. package/dist/threads/api.js.map +1 -1
  230. package/dist/threads/conversation-list-fetcher.cjs +13 -5
  231. package/dist/threads/conversation-list-fetcher.cjs.map +1 -1
  232. package/dist/threads/conversation-list-fetcher.d.ts +4 -1
  233. package/dist/threads/conversation-list-fetcher.js +13 -5
  234. package/dist/threads/conversation-list-fetcher.js.map +1 -1
  235. package/dist/threads/statewire-thread-list.cjs +28 -6
  236. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  237. package/dist/threads/statewire-thread-list.d.ts +20 -8
  238. package/dist/threads/statewire-thread-list.js +28 -6
  239. package/dist/threads/statewire-thread-list.js.map +1 -1
  240. package/dist/threads/use-athena-sessions.cjs +27 -5
  241. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  242. package/dist/threads/use-athena-sessions.d.ts +10 -5
  243. package/dist/threads/use-athena-sessions.js +28 -6
  244. package/dist/threads/use-athena-sessions.js.map +1 -1
  245. package/dist/threads/use-rest-conversation-history.d.ts +1 -0
  246. package/dist/tools/write-todos-tool-ui.cjs +8 -0
  247. package/dist/tools/write-todos-tool-ui.cjs.map +1 -1
  248. package/dist/tools/write-todos-tool-ui.d.ts +2 -0
  249. package/dist/tools/write-todos-tool-ui.js +8 -0
  250. package/dist/tools/write-todos-tool-ui.js.map +1 -1
  251. package/dist/workbench/session-workbench-panes.cjs +1 -8
  252. package/dist/workbench/session-workbench-panes.cjs.map +1 -1
  253. package/dist/workbench/session-workbench-panes.js +2 -9
  254. package/dist/workbench/session-workbench-panes.js.map +1 -1
  255. package/package.json +2 -2
@@ -1,5 +1,7 @@
1
+ import type { VoiceMediaEvent } from './voice-media';
1
2
  import type { DeepAgentVoiceOwnerWireState, DeepAgentVoiceSurface, DeepAgentVoiceWireError } from './voice-wire-types';
2
3
  export type { DeepAgentVoiceOwnerWireState, DeepAgentVoiceSurface, DeepAgentVoiceTransferWireState, } from './voice-wire-types';
4
+ export { playVoiceMoveEarcon, VOICE_MOVE_EARCON_MS, VOICE_MOVE_EARCON_PEAK, VOICE_MOVE_EARCON_SAMPLE_RATE, voiceMoveEarconDataUri, voiceMoveEarconSamples, voiceMoveEarconWav, } from './voice-earcon';
3
5
  declare module '@assistant-ui/core' {
4
6
  namespace Assistant {
5
7
  interface Commands {
@@ -180,7 +182,13 @@ export interface DeepAgentVoiceFailure {
180
182
  */
181
183
  export type DeepAgentVoiceDiagnosticEvent = 'start-requested' | 'audio-session-ready' | 'microphone-captured' | 'offer-ready' | 'ice-gathering-timeout' | 'answer-received' | 'room-joined' | 'live' | 'media-state' | 'media-loss' | 'auto-restart' | 'server-ended' | 'end' | 'error' | 'stale-attempt'
182
184
  /** The live call moved to another of the person's devices; this client let go of it. */
183
- | 'moved';
185
+ | 'moved'
186
+ /**
187
+ * The platform's room reported something about the call's media (the
188
+ * adapter's `onEvent`): `data.type` names it — a reconnect, the agent
189
+ * leaving, connection quality, an audio-quality sample or summary.
190
+ */
191
+ | 'media-event';
184
192
  export interface DeepAgentVoiceDiagnostic {
185
193
  event: DeepAgentVoiceDiagnosticEvent;
186
194
  attempt: number;
@@ -277,6 +285,11 @@ export interface DeepAgentVoiceLiveKitAdapter {
277
285
  /** Abort a pending join and release media when this attempt ends. */
278
286
  signal?: AbortSignal;
279
287
  onDisconnected: (reason: string) => void;
288
+ /**
289
+ * Media telemetry while the room lasts (reconnects, the agent leaving,
290
+ * audio quality); reported as `media-event` diagnostics. Optional.
291
+ */
292
+ onEvent?: (event: VoiceMediaEvent) => void;
280
293
  }): Promise<DeepAgentVoiceLiveKitSession>;
281
294
  }
282
295
  /** One realtime model the host offers for voice sessions (`state.voiceModelOptions`). */
@@ -355,6 +368,13 @@ export declare const voiceRelayUrl: (relayUrl: string, ticket: string) => string
355
368
  export declare const pcm16FromFloat32: (samples: Float32Array) => Int16Array;
356
369
  /** PCM16 → Float32 samples in [-1, 1] for Web Audio playback. */
357
370
  export declare const float32FromPcm16: (pcm: Int16Array) => Float32Array;
371
+ /** A call this device held or took moving between the person's own devices; see `onCallMoved`. */
372
+ export interface DeepAgentVoiceCallMove {
373
+ /** `here`: this device now holds the call. `away`: the call left this device. */
374
+ direction: 'here' | 'away';
375
+ /** The other device: where the call came from (`here`) or went (`away`). */
376
+ surface: DeepAgentVoiceSurface;
377
+ }
358
378
  export interface UseDeepAgentVoiceOptions {
359
379
  /**
360
380
  * Remote-audio sink: called with the remote stream when the session answers
@@ -405,6 +425,19 @@ export interface UseDeepAgentVoiceOptions {
405
425
  * fresh closure never restarts anything. Must not throw.
406
426
  */
407
427
  onDiagnostic?: (entry: DeepAgentVoiceDiagnostic) => void;
428
+ /**
429
+ * Called when this device's call moves between the person's own devices:
430
+ * `here` once {@link UseDeepAgentVoiceReturn.transferHere} took the call
431
+ * (it is live here), `away` when the host moved it to another device
432
+ * (alongside `movedTo`). Hosts play the move earcon from it
433
+ * ({@link playVoiceMoveEarcon} on the web). For `away` it runs before the
434
+ * hook lets go of the call's platform audio session, which it then releases
435
+ * at once (`audioSession.stop`): a host that plays the cue inside that
436
+ * session holds the session's stop itself, in its shared session queue, so
437
+ * a chat started meanwhile waits rather than finds the session taken. Read
438
+ * through a per-render ref; a throw or a rejected promise is ignored.
439
+ */
440
+ onCallMoved?: (move: DeepAgentVoiceCallMove) => void | Promise<void>;
408
441
  /** Per-surface overrides of the negotiation deadlines (ms). */
409
442
  timeouts?: {
410
443
  /** How long to wait for ICE gathering to complete before sending the offer with the candidates so far. */
@@ -419,6 +419,8 @@ const useDeepAgentVoice = (options = {}) => {
419
419
  modelRef.current = options.model;
420
420
  const onDiagnosticRef = useRef(options.onDiagnostic);
421
421
  onDiagnosticRef.current = options.onDiagnostic;
422
+ const onCallMovedRef = useRef(options.onCallMoved);
423
+ onCallMovedRef.current = options.onCallMoved;
422
424
  const timeoutsRef = useRef(options.timeouts);
423
425
  timeoutsRef.current = options.timeouts;
424
426
  const phaseRef = useRef("idle");
@@ -495,7 +497,15 @@ const useDeepAgentVoice = (options = {}) => {
495
497
  activeAudioSessionRef.current = null;
496
498
  audioSessionIdleRef.current = audioSessionIdleRef.current.then(() => session.stop()).catch(() => void 0);
497
499
  }, []);
498
- const teardown = useCallback(() => {
500
+ const notifyCallMoved = useCallback((move) => {
501
+ const observer = onCallMovedRef.current;
502
+ if (!observer) return;
503
+ try {
504
+ void Promise.resolve(observer(move)).catch(() => void 0);
505
+ } catch {
506
+ }
507
+ }, []);
508
+ const teardown = useCallback((options2) => {
499
509
  attemptRef.current += 1;
500
510
  const livekitAbort = livekitAbortRef.current;
501
511
  livekitAbortRef.current = null;
@@ -504,7 +514,7 @@ const useDeepAgentVoice = (options = {}) => {
504
514
  var _a, _b;
505
515
  return (_b = (_a = startingAudioSessionRef.current) == null ? void 0 : _a.cancelStart) == null ? void 0 : _b.call(_a);
506
516
  });
507
- releaseAudioSession();
517
+ if ((options2 == null ? void 0 : options2.keepAudioSession) !== true) releaseAudioSession();
508
518
  const releasePeerListeners = releasePeerListenersRef.current;
509
519
  releasePeerListenersRef.current = null;
510
520
  releaseSafely(() => releasePeerListeners == null ? void 0 : releasePeerListeners());
@@ -556,6 +566,7 @@ const useDeepAgentVoice = (options = {}) => {
556
566
  var _a;
557
567
  const surface = ((_a = voiceOwnerRef.current) == null ? void 0 : _a.surface) ?? "web";
558
568
  report("moved", attemptRef.current, { toSurface: surface });
569
+ notifyCallMoved({ direction: "away", surface });
559
570
  teardown();
560
571
  ownClientIdRef.current = null;
561
572
  micMutedRef.current = false;
@@ -564,7 +575,7 @@ const useDeepAgentVoice = (options = {}) => {
564
575
  setFailure(null);
565
576
  setPhase("idle");
566
577
  setMovedTo({ surface });
567
- }, [report, teardown]);
578
+ }, [notifyCallMoved, report, teardown]);
568
579
  const ownerMovedAway = useCallback(() => {
569
580
  const own = ownClientIdRef.current;
570
581
  const current = wireOwnerIdRef.current;
@@ -575,11 +586,17 @@ const useDeepAgentVoice = (options = {}) => {
575
586
  attempt,
576
587
  audioSession
577
588
  }) => {
589
+ const held = activeAudioSessionRef.current;
590
+ if (held !== null && held !== audioSession) releaseAudioSession();
578
591
  await audioSessionIdleRef.current;
579
592
  if (attemptRef.current !== attempt) {
580
593
  report("stale-attempt", attempt, { stage: "audio-session" });
581
594
  return false;
582
595
  }
596
+ if (activeAudioSessionRef.current === audioSession) {
597
+ report("audio-session-ready", attempt, { reused: true });
598
+ return true;
599
+ }
583
600
  startingAudioSessionRef.current = audioSession;
584
601
  try {
585
602
  await audioSession.start();
@@ -618,6 +635,11 @@ const useDeepAgentVoice = (options = {}) => {
618
635
  return;
619
636
  }
620
637
  onDisconnectedAfterJoin(reason);
638
+ },
639
+ // Telemetry about this attempt's room stays this attempt's even after
640
+ // it ended: the room's closing summary arrives after teardown.
641
+ onEvent: (event) => {
642
+ report("media-event", attempt, { ...event.data, type: event.type });
621
643
  }
622
644
  });
623
645
  if (attemptRef.current !== attempt) {
@@ -995,13 +1017,14 @@ const useDeepAgentVoice = (options = {}) => {
995
1017
  handleMovedAway();
996
1018
  return;
997
1019
  }
1020
+ const restarting = !autoRestartedRef.current;
998
1021
  report("media-loss", attempt, {
999
1022
  reason,
1000
- restartBudgetLeft: !autoRestartedRef.current
1023
+ restartBudgetLeft: restarting
1001
1024
  });
1002
1025
  if (lastActiveTaskRef.current) setHandoffTask(lastActiveTaskRef.current);
1003
1026
  const ending = sendCommand({ type: "voice/end", attemptId: callAttemptIdRef.current }).catch(() => void 0);
1004
- teardown();
1027
+ teardown({ keepAudioSession: restarting });
1005
1028
  const recovery = attemptRef.current;
1006
1029
  setPhase("idle");
1007
1030
  let endTimer;
@@ -1057,6 +1080,8 @@ const useDeepAgentVoice = (options = {}) => {
1057
1080
  await startSession((options2 == null ? void 0 : options2.opening) === "recap" ? { opening: "recap" } : {});
1058
1081
  }, [startSession]);
1059
1082
  const runTransferHere = useCallback(async () => {
1083
+ var _a;
1084
+ const fromSurface = ((_a = liveElsewhereRef.current) == null ? void 0 : _a.surface) ?? "web";
1060
1085
  const attempt = attemptRef.current += 1;
1061
1086
  const attemptId = mintVoiceId({ kind: "attempt" });
1062
1087
  callAttemptIdRef.current = attemptId;
@@ -1183,6 +1208,7 @@ const useDeepAgentVoice = (options = {}) => {
1183
1208
  report("live", attempt, { transport: "livekit", transfer: true });
1184
1209
  setPhase("live");
1185
1210
  setLiveSince(Date.now());
1211
+ notifyCallMoved({ direction: "here", surface: fromSurface });
1186
1212
  } catch (transferError) {
1187
1213
  if (attemptRef.current !== attempt) {
1188
1214
  stale();
@@ -1197,7 +1223,15 @@ const useDeepAgentVoice = (options = {}) => {
1197
1223
  } finally {
1198
1224
  startingRef.current = false;
1199
1225
  }
1200
- }, [acquireAudioSession, fail, joinVoiceRoom, releaseAudioSession, report, sendCommand]);
1226
+ }, [
1227
+ acquireAudioSession,
1228
+ fail,
1229
+ joinVoiceRoom,
1230
+ notifyCallMoved,
1231
+ releaseAudioSession,
1232
+ report,
1233
+ sendCommand
1234
+ ]);
1201
1235
  const transferHere = useCallback(async () => {
1202
1236
  if (pcRef.current || wsRef.current || livekitRef.current || startingRef.current) return;
1203
1237
  if (liveElsewhereRef.current === null) return;
@@ -1285,13 +1319,14 @@ const useDeepAgentVoice = (options = {}) => {
1285
1319
  useEffect(() => {
1286
1320
  var _a;
1287
1321
  if (phase !== "live" || !sessionGone) return;
1322
+ const restarting = !autoRestartedRef.current;
1288
1323
  report("server-ended", attemptRef.current, {
1289
- restartBudgetLeft: !autoRestartedRef.current
1324
+ restartBudgetLeft: restarting
1290
1325
  });
1291
1326
  if (lastActiveTaskRef.current) setHandoffTask(lastActiveTaskRef.current);
1292
- teardown();
1327
+ teardown({ keepAudioSession: restarting });
1293
1328
  setPhase("idle");
1294
- if (!autoRestartedRef.current) {
1329
+ if (restarting) {
1295
1330
  autoRestartedRef.current = true;
1296
1331
  report("auto-restart", attemptRef.current, { trigger: "server-ended" });
1297
1332
  void ((_a = startRef.current) == null ? void 0 : _a.call(startRef));