@memberjunction/ng-conversations 5.40.1 → 5.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. package/README.md +57 -0
  2. package/dist/__tests__/channel-optional-surface.test.d.ts +2 -0
  3. package/dist/__tests__/channel-optional-surface.test.d.ts.map +1 -0
  4. package/dist/__tests__/channel-optional-surface.test.js +53 -0
  5. package/dist/__tests__/channel-optional-surface.test.js.map +1 -0
  6. package/dist/__tests__/chat-events.test.d.ts +14 -0
  7. package/dist/__tests__/chat-events.test.d.ts.map +1 -0
  8. package/dist/__tests__/chat-events.test.js +109 -0
  9. package/dist/__tests__/chat-events.test.js.map +1 -0
  10. package/dist/__tests__/conversation-naming.test.d.ts +2 -0
  11. package/dist/__tests__/conversation-naming.test.d.ts.map +1 -0
  12. package/dist/__tests__/conversation-naming.test.js +110 -0
  13. package/dist/__tests__/conversation-naming.test.js.map +1 -0
  14. package/dist/__tests__/delegation-result-parser.test.d.ts +2 -0
  15. package/dist/__tests__/delegation-result-parser.test.d.ts.map +1 -0
  16. package/dist/__tests__/delegation-result-parser.test.js +107 -0
  17. package/dist/__tests__/delegation-result-parser.test.js.map +1 -0
  18. package/dist/__tests__/event-wiring.test.d.ts +15 -0
  19. package/dist/__tests__/event-wiring.test.d.ts.map +1 -0
  20. package/dist/__tests__/event-wiring.test.js +100 -0
  21. package/dist/__tests__/event-wiring.test.js.map +1 -0
  22. package/dist/__tests__/narration-template.test.d.ts +2 -0
  23. package/dist/__tests__/narration-template.test.d.ts.map +1 -0
  24. package/dist/__tests__/narration-template.test.js +76 -0
  25. package/dist/__tests__/narration-template.test.js.map +1 -0
  26. package/dist/__tests__/realtime-agent-picker-models.test.d.ts +2 -0
  27. package/dist/__tests__/realtime-agent-picker-models.test.d.ts.map +1 -0
  28. package/dist/__tests__/realtime-agent-picker-models.test.js +49 -0
  29. package/dist/__tests__/realtime-agent-picker-models.test.js.map +1 -0
  30. package/dist/__tests__/realtime-audio-visuals.test.d.ts +2 -0
  31. package/dist/__tests__/realtime-audio-visuals.test.d.ts.map +1 -0
  32. package/dist/__tests__/realtime-audio-visuals.test.js +123 -0
  33. package/dist/__tests__/realtime-audio-visuals.test.js.map +1 -0
  34. package/dist/__tests__/realtime-delegation-card-cancel.test.d.ts +2 -0
  35. package/dist/__tests__/realtime-delegation-card-cancel.test.d.ts.map +1 -0
  36. package/dist/__tests__/realtime-delegation-card-cancel.test.js +48 -0
  37. package/dist/__tests__/realtime-delegation-card-cancel.test.js.map +1 -0
  38. package/dist/__tests__/realtime-disclosure.test.d.ts +2 -0
  39. package/dist/__tests__/realtime-disclosure.test.d.ts.map +1 -0
  40. package/dist/__tests__/realtime-disclosure.test.js +164 -0
  41. package/dist/__tests__/realtime-disclosure.test.js.map +1 -0
  42. package/dist/__tests__/realtime-pairing.test.d.ts +2 -0
  43. package/dist/__tests__/realtime-pairing.test.d.ts.map +1 -0
  44. package/dist/__tests__/realtime-pairing.test.js +207 -0
  45. package/dist/__tests__/realtime-pairing.test.js.map +1 -0
  46. package/dist/__tests__/realtime-review-lifecycle.test.d.ts +2 -0
  47. package/dist/__tests__/realtime-review-lifecycle.test.d.ts.map +1 -0
  48. package/dist/__tests__/realtime-review-lifecycle.test.js +154 -0
  49. package/dist/__tests__/realtime-review-lifecycle.test.js.map +1 -0
  50. package/dist/__tests__/realtime-session-cancel-usage.test.d.ts +2 -0
  51. package/dist/__tests__/realtime-session-cancel-usage.test.d.ts.map +1 -0
  52. package/dist/__tests__/realtime-session-cancel-usage.test.js +230 -0
  53. package/dist/__tests__/realtime-session-cancel-usage.test.js.map +1 -0
  54. package/dist/__tests__/realtime-session-channels.test.d.ts +2 -0
  55. package/dist/__tests__/realtime-session-channels.test.d.ts.map +1 -0
  56. package/dist/__tests__/realtime-session-channels.test.js +252 -0
  57. package/dist/__tests__/realtime-session-channels.test.js.map +1 -0
  58. package/dist/__tests__/realtime-session-client-tools.test.d.ts +2 -0
  59. package/dist/__tests__/realtime-session-client-tools.test.d.ts.map +1 -0
  60. package/dist/__tests__/realtime-session-client-tools.test.js +103 -0
  61. package/dist/__tests__/realtime-session-client-tools.test.js.map +1 -0
  62. package/dist/__tests__/realtime-session-minimized.test.d.ts +2 -0
  63. package/dist/__tests__/realtime-session-minimized.test.d.ts.map +1 -0
  64. package/dist/__tests__/realtime-session-minimized.test.js +32 -0
  65. package/dist/__tests__/realtime-session-minimized.test.js.map +1 -0
  66. package/dist/__tests__/realtime-session-mint.test.d.ts +2 -0
  67. package/dist/__tests__/realtime-session-mint.test.d.ts.map +1 -0
  68. package/dist/__tests__/realtime-session-mint.test.js +69 -0
  69. package/dist/__tests__/realtime-session-mint.test.js.map +1 -0
  70. package/dist/__tests__/realtime-session-policy.test.d.ts +2 -0
  71. package/dist/__tests__/realtime-session-policy.test.d.ts.map +1 -0
  72. package/dist/__tests__/realtime-session-policy.test.js +303 -0
  73. package/dist/__tests__/realtime-session-policy.test.js.map +1 -0
  74. package/dist/__tests__/realtime-session-review.service.test.d.ts +2 -0
  75. package/dist/__tests__/realtime-session-review.service.test.d.ts.map +1 -0
  76. package/dist/__tests__/realtime-session-review.service.test.js +743 -0
  77. package/dist/__tests__/realtime-session-review.service.test.js.map +1 -0
  78. package/dist/__tests__/realtime-session-state.test.d.ts +2 -0
  79. package/dist/__tests__/realtime-session-state.test.d.ts.map +1 -0
  80. package/dist/__tests__/realtime-session-state.test.js +83 -0
  81. package/dist/__tests__/realtime-session-state.test.js.map +1 -0
  82. package/dist/__tests__/realtime-session-timeline-card.test.d.ts +2 -0
  83. package/dist/__tests__/realtime-session-timeline-card.test.d.ts.map +1 -0
  84. package/dist/__tests__/realtime-session-timeline-card.test.js +106 -0
  85. package/dist/__tests__/realtime-session-timeline-card.test.js.map +1 -0
  86. package/dist/__tests__/realtime-session-timeline.test.d.ts +2 -0
  87. package/dist/__tests__/realtime-session-timeline.test.d.ts.map +1 -0
  88. package/dist/__tests__/realtime-session-timeline.test.js +142 -0
  89. package/dist/__tests__/realtime-session-timeline.test.js.map +1 -0
  90. package/dist/__tests__/realtime-sessions-adapter.test.d.ts +19 -0
  91. package/dist/__tests__/realtime-sessions-adapter.test.d.ts.map +1 -0
  92. package/dist/__tests__/realtime-sessions-adapter.test.js +188 -0
  93. package/dist/__tests__/realtime-sessions-adapter.test.js.map +1 -0
  94. package/dist/__tests__/realtime-surface-panel-prefs.test.d.ts +2 -0
  95. package/dist/__tests__/realtime-surface-panel-prefs.test.d.ts.map +1 -0
  96. package/dist/__tests__/realtime-surface-panel-prefs.test.js +100 -0
  97. package/dist/__tests__/realtime-surface-panel-prefs.test.js.map +1 -0
  98. package/dist/__tests__/realtime-surface-tabs-model.test.d.ts +2 -0
  99. package/dist/__tests__/realtime-surface-tabs-model.test.d.ts.map +1 -0
  100. package/dist/__tests__/realtime-surface-tabs-model.test.js +193 -0
  101. package/dist/__tests__/realtime-surface-tabs-model.test.js.map +1 -0
  102. package/dist/__tests__/remote-browser-audio-player.test.d.ts +2 -0
  103. package/dist/__tests__/remote-browser-audio-player.test.d.ts.map +1 -0
  104. package/dist/__tests__/remote-browser-audio-player.test.js +137 -0
  105. package/dist/__tests__/remote-browser-audio-player.test.js.map +1 -0
  106. package/dist/__tests__/remote-browser-channel.test.d.ts +2 -0
  107. package/dist/__tests__/remote-browser-channel.test.d.ts.map +1 -0
  108. package/dist/__tests__/remote-browser-channel.test.js +423 -0
  109. package/dist/__tests__/remote-browser-channel.test.js.map +1 -0
  110. package/dist/__tests__/slot-defaults.test.d.ts +24 -0
  111. package/dist/__tests__/slot-defaults.test.d.ts.map +1 -0
  112. package/dist/__tests__/slot-defaults.test.js +63 -0
  113. package/dist/__tests__/slot-defaults.test.js.map +1 -0
  114. package/dist/__tests__/user-authorization.test.d.ts +2 -0
  115. package/dist/__tests__/user-authorization.test.d.ts.map +1 -0
  116. package/dist/__tests__/user-authorization.test.js +97 -0
  117. package/dist/__tests__/user-authorization.test.js.map +1 -0
  118. package/dist/__tests__/voice-session-narration.test.d.ts +2 -0
  119. package/dist/__tests__/voice-session-narration.test.d.ts.map +1 -0
  120. package/dist/__tests__/voice-session-narration.test.js +609 -0
  121. package/dist/__tests__/voice-session-narration.test.js.map +1 -0
  122. package/dist/__tests__/whiteboard-artifact-viewer.test.d.ts +2 -0
  123. package/dist/__tests__/whiteboard-artifact-viewer.test.d.ts.map +1 -0
  124. package/dist/__tests__/whiteboard-artifact-viewer.test.js +101 -0
  125. package/dist/__tests__/whiteboard-artifact-viewer.test.js.map +1 -0
  126. package/dist/__tests__/whiteboard-channel.test.d.ts +2 -0
  127. package/dist/__tests__/whiteboard-channel.test.d.ts.map +1 -0
  128. package/dist/__tests__/whiteboard-channel.test.js +260 -0
  129. package/dist/__tests__/whiteboard-channel.test.js.map +1 -0
  130. package/dist/__tests__/whiteboard-restore-state.test.d.ts +2 -0
  131. package/dist/__tests__/whiteboard-restore-state.test.d.ts.map +1 -0
  132. package/dist/__tests__/whiteboard-restore-state.test.js +108 -0
  133. package/dist/__tests__/whiteboard-restore-state.test.js.map +1 -0
  134. package/dist/lib/components/conversation/conversation-chat-area.component.d.ts +205 -3
  135. package/dist/lib/components/conversation/conversation-chat-area.component.d.ts.map +1 -1
  136. package/dist/lib/components/conversation/conversation-chat-area.component.js +911 -342
  137. package/dist/lib/components/conversation/conversation-chat-area.component.js.map +1 -1
  138. package/dist/lib/components/mention/mention-dropdown.component.js +35 -17
  139. package/dist/lib/components/mention/mention-dropdown.component.js.map +1 -1
  140. package/dist/lib/components/mention/mention-editor.component.d.ts +4 -0
  141. package/dist/lib/components/mention/mention-editor.component.d.ts.map +1 -1
  142. package/dist/lib/components/mention/mention-editor.component.js +43 -19
  143. package/dist/lib/components/mention/mention-editor.component.js.map +1 -1
  144. package/dist/lib/components/message/message-input-box.component.d.ts +17 -1
  145. package/dist/lib/components/message/message-input-box.component.d.ts.map +1 -1
  146. package/dist/lib/components/message/message-input-box.component.js +73 -15
  147. package/dist/lib/components/message/message-input-box.component.js.map +1 -1
  148. package/dist/lib/components/message/message-input.component.d.ts +142 -6
  149. package/dist/lib/components/message/message-input.component.d.ts.map +1 -1
  150. package/dist/lib/components/message/message-input.component.js +328 -82
  151. package/dist/lib/components/message/message-input.component.js.map +1 -1
  152. package/dist/lib/components/message/message-item.component.d.ts +28 -3
  153. package/dist/lib/components/message/message-item.component.d.ts.map +1 -1
  154. package/dist/lib/components/message/message-item.component.js +180 -108
  155. package/dist/lib/components/message/message-item.component.js.map +1 -1
  156. package/dist/lib/components/message/message-list.component.d.ts +81 -2
  157. package/dist/lib/components/message/message-list.component.d.ts.map +1 -1
  158. package/dist/lib/components/message/message-list.component.js +252 -87
  159. package/dist/lib/components/message/message-list.component.js.map +1 -1
  160. package/dist/lib/components/realtime/channels/base-realtime-channel-client.d.ts +282 -0
  161. package/dist/lib/components/realtime/channels/base-realtime-channel-client.d.ts.map +1 -0
  162. package/dist/lib/components/realtime/channels/base-realtime-channel-client.js +158 -0
  163. package/dist/lib/components/realtime/channels/base-realtime-channel-client.js.map +1 -0
  164. package/dist/lib/components/realtime/channels/channel-onboarding-panel.component.d.ts +25 -0
  165. package/dist/lib/components/realtime/channels/channel-onboarding-panel.component.d.ts.map +1 -0
  166. package/dist/lib/components/realtime/channels/channel-onboarding-panel.component.js +140 -0
  167. package/dist/lib/components/realtime/channels/channel-onboarding-panel.component.js.map +1 -0
  168. package/dist/lib/components/realtime/channels/realtime-channel-pane.component.d.ts +35 -0
  169. package/dist/lib/components/realtime/channels/realtime-channel-pane.component.d.ts.map +1 -0
  170. package/dist/lib/components/realtime/channels/realtime-channel-pane.component.js +58 -0
  171. package/dist/lib/components/realtime/channels/realtime-channel-pane.component.js.map +1 -0
  172. package/dist/lib/components/realtime/realtime-activity-rail.component.d.ts +63 -0
  173. package/dist/lib/components/realtime/realtime-activity-rail.component.d.ts.map +1 -0
  174. package/dist/lib/components/realtime/realtime-activity-rail.component.js +260 -0
  175. package/dist/lib/components/realtime/realtime-activity-rail.component.js.map +1 -0
  176. package/dist/lib/components/realtime/realtime-agent-banner.component.d.ts +117 -0
  177. package/dist/lib/components/realtime/realtime-agent-banner.component.d.ts.map +1 -0
  178. package/dist/lib/components/realtime/realtime-agent-banner.component.js +504 -0
  179. package/dist/lib/components/realtime/realtime-agent-banner.component.js.map +1 -0
  180. package/dist/lib/components/realtime/realtime-agent-picker.component.d.ts +168 -0
  181. package/dist/lib/components/realtime/realtime-agent-picker.component.d.ts.map +1 -0
  182. package/dist/lib/components/realtime/realtime-agent-picker.component.js +556 -0
  183. package/dist/lib/components/realtime/realtime-agent-picker.component.js.map +1 -0
  184. package/dist/lib/components/realtime/realtime-audio-visuals.d.ts +97 -0
  185. package/dist/lib/components/realtime/realtime-audio-visuals.d.ts.map +1 -0
  186. package/dist/lib/components/realtime/realtime-audio-visuals.js +139 -0
  187. package/dist/lib/components/realtime/realtime-audio-visuals.js.map +1 -0
  188. package/dist/lib/components/realtime/realtime-channel-strip.component.d.ts +29 -0
  189. package/dist/lib/components/realtime/realtime-channel-strip.component.d.ts.map +1 -0
  190. package/dist/lib/components/realtime/realtime-channel-strip.component.js +69 -0
  191. package/dist/lib/components/realtime/realtime-channel-strip.component.js.map +1 -0
  192. package/dist/lib/components/realtime/realtime-composer.component.d.ts +65 -0
  193. package/dist/lib/components/realtime/realtime-composer.component.d.ts.map +1 -0
  194. package/dist/lib/components/realtime/realtime-composer.component.js +256 -0
  195. package/dist/lib/components/realtime/realtime-composer.component.js.map +1 -0
  196. package/dist/lib/components/realtime/realtime-delegation-card.component.d.ts +71 -0
  197. package/dist/lib/components/realtime/realtime-delegation-card.component.d.ts.map +1 -0
  198. package/dist/lib/components/realtime/realtime-delegation-card.component.js +324 -0
  199. package/dist/lib/components/realtime/realtime-delegation-card.component.js.map +1 -0
  200. package/dist/lib/components/realtime/realtime-disclosure.d.ts +135 -0
  201. package/dist/lib/components/realtime/realtime-disclosure.d.ts.map +1 -0
  202. package/dist/lib/components/realtime/realtime-disclosure.js +188 -0
  203. package/dist/lib/components/realtime/realtime-disclosure.js.map +1 -0
  204. package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts +491 -0
  205. package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts.map +1 -0
  206. package/dist/lib/components/realtime/realtime-session-overlay.component.js +1274 -0
  207. package/dist/lib/components/realtime/realtime-session-overlay.component.js.map +1 -0
  208. package/dist/lib/components/realtime/realtime-session-state.d.ts +191 -0
  209. package/dist/lib/components/realtime/realtime-session-state.d.ts.map +1 -0
  210. package/dist/lib/components/realtime/realtime-session-state.js +244 -0
  211. package/dist/lib/components/realtime/realtime-session-state.js.map +1 -0
  212. package/dist/lib/components/realtime/realtime-session-thread.component.d.ts +56 -0
  213. package/dist/lib/components/realtime/realtime-session-thread.component.d.ts.map +1 -0
  214. package/dist/lib/components/realtime/realtime-session-thread.component.js +246 -0
  215. package/dist/lib/components/realtime/realtime-session-thread.component.js.map +1 -0
  216. package/dist/lib/components/realtime/realtime-session-timeline-card.component.d.ts +51 -0
  217. package/dist/lib/components/realtime/realtime-session-timeline-card.component.d.ts.map +1 -0
  218. package/dist/lib/components/realtime/realtime-session-timeline-card.component.js +193 -0
  219. package/dist/lib/components/realtime/realtime-session-timeline-card.component.js.map +1 -0
  220. package/dist/lib/components/realtime/realtime-surface-panel-prefs.d.ts +77 -0
  221. package/dist/lib/components/realtime/realtime-surface-panel-prefs.d.ts.map +1 -0
  222. package/dist/lib/components/realtime/realtime-surface-panel-prefs.js +114 -0
  223. package/dist/lib/components/realtime/realtime-surface-panel-prefs.js.map +1 -0
  224. package/dist/lib/components/realtime/realtime-surface-tabs.component.d.ts +173 -0
  225. package/dist/lib/components/realtime/realtime-surface-tabs.component.d.ts.map +1 -0
  226. package/dist/lib/components/realtime/realtime-surface-tabs.component.js +496 -0
  227. package/dist/lib/components/realtime/realtime-surface-tabs.component.js.map +1 -0
  228. package/dist/lib/components/realtime/realtime-surface-tabs.model.d.ts +181 -0
  229. package/dist/lib/components/realtime/realtime-surface-tabs.model.d.ts.map +1 -0
  230. package/dist/lib/components/realtime/realtime-surface-tabs.model.js +223 -0
  231. package/dist/lib/components/realtime/realtime-surface-tabs.model.js.map +1 -0
  232. package/dist/lib/components/realtime/remote-browser/remote-browser-audio-player.d.ts +163 -0
  233. package/dist/lib/components/realtime/remote-browser/remote-browser-audio-player.d.ts.map +1 -0
  234. package/dist/lib/components/realtime/remote-browser/remote-browser-audio-player.js +309 -0
  235. package/dist/lib/components/realtime/remote-browser/remote-browser-audio-player.js.map +1 -0
  236. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.d.ts +168 -0
  237. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.d.ts.map +1 -0
  238. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js +524 -0
  239. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js.map +1 -0
  240. package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.d.ts +346 -0
  241. package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.d.ts.map +1 -0
  242. package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.js +851 -0
  243. package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.js.map +1 -0
  244. package/dist/lib/components/realtime/remote-browser/remote-browser-tools.d.ts +86 -0
  245. package/dist/lib/components/realtime/remote-browser/remote-browser-tools.d.ts.map +1 -0
  246. package/dist/lib/components/realtime/remote-browser/remote-browser-tools.js +210 -0
  247. package/dist/lib/components/realtime/remote-browser/remote-browser-tools.js.map +1 -0
  248. package/dist/lib/components/realtime/whiteboard/whiteboard-artifact-viewer.component.d.ts +48 -0
  249. package/dist/lib/components/realtime/whiteboard/whiteboard-artifact-viewer.component.d.ts.map +1 -0
  250. package/dist/lib/components/realtime/whiteboard/whiteboard-artifact-viewer.component.js +180 -0
  251. package/dist/lib/components/realtime/whiteboard/whiteboard-artifact-viewer.component.js.map +1 -0
  252. package/dist/lib/components/realtime/whiteboard/whiteboard-channel.d.ts +119 -0
  253. package/dist/lib/components/realtime/whiteboard/whiteboard-channel.d.ts.map +1 -0
  254. package/dist/lib/components/realtime/whiteboard/whiteboard-channel.js +274 -0
  255. package/dist/lib/components/realtime/whiteboard/whiteboard-channel.js.map +1 -0
  256. package/dist/lib/components/slots/mj-chat-agent-presence-default.component.d.ts +11 -0
  257. package/dist/lib/components/slots/mj-chat-agent-presence-default.component.d.ts.map +1 -0
  258. package/dist/lib/components/slots/mj-chat-agent-presence-default.component.js +98 -0
  259. package/dist/lib/components/slots/mj-chat-agent-presence-default.component.js.map +1 -0
  260. package/dist/lib/components/slots/mj-chat-demonstration-surface-default.component.d.ts +9 -0
  261. package/dist/lib/components/slots/mj-chat-demonstration-surface-default.component.d.ts.map +1 -0
  262. package/dist/lib/components/slots/mj-chat-demonstration-surface-default.component.js +35 -0
  263. package/dist/lib/components/slots/mj-chat-demonstration-surface-default.component.js.map +1 -0
  264. package/dist/lib/components/slots/mj-chat-empty-state-default.component.d.ts +28 -0
  265. package/dist/lib/components/slots/mj-chat-empty-state-default.component.d.ts.map +1 -0
  266. package/dist/lib/components/slots/mj-chat-empty-state-default.component.js +104 -0
  267. package/dist/lib/components/slots/mj-chat-empty-state-default.component.js.map +1 -0
  268. package/dist/lib/components/slots/mj-chat-header-default.component.d.ts +11 -0
  269. package/dist/lib/components/slots/mj-chat-header-default.component.d.ts.map +1 -0
  270. package/dist/lib/components/slots/mj-chat-header-default.component.js +103 -0
  271. package/dist/lib/components/slots/mj-chat-header-default.component.js.map +1 -0
  272. package/dist/lib/components/slots/mj-chat-message-bubble-default.component.d.ts +15 -0
  273. package/dist/lib/components/slots/mj-chat-message-bubble-default.component.d.ts.map +1 -0
  274. package/dist/lib/components/slots/mj-chat-message-bubble-default.component.js +73 -0
  275. package/dist/lib/components/slots/mj-chat-message-bubble-default.component.js.map +1 -0
  276. package/dist/lib/components/slots/mj-chat-message-extra-default.component.d.ts +9 -0
  277. package/dist/lib/components/slots/mj-chat-message-extra-default.component.d.ts.map +1 -0
  278. package/dist/lib/components/slots/mj-chat-message-extra-default.component.js +34 -0
  279. package/dist/lib/components/slots/mj-chat-message-extra-default.component.js.map +1 -0
  280. package/dist/lib/components/slots/slot-interfaces.d.ts +95 -0
  281. package/dist/lib/components/slots/slot-interfaces.d.ts.map +1 -0
  282. package/dist/lib/components/slots/slot-interfaces.js +18 -0
  283. package/dist/lib/components/slots/slot-interfaces.js.map +1 -0
  284. package/dist/lib/components/workspace/conversation-workspace.component.d.ts +11 -0
  285. package/dist/lib/components/workspace/conversation-workspace.component.d.ts.map +1 -1
  286. package/dist/lib/components/workspace/conversation-workspace.component.js +28 -4
  287. package/dist/lib/components/workspace/conversation-workspace.component.js.map +1 -1
  288. package/dist/lib/conversations.module.d.ts +12 -1
  289. package/dist/lib/conversations.module.d.ts.map +1 -1
  290. package/dist/lib/conversations.module.js +93 -5
  291. package/dist/lib/conversations.module.js.map +1 -1
  292. package/dist/lib/directives/chat-slot.directive.d.ts +44 -0
  293. package/dist/lib/directives/chat-slot.directive.d.ts.map +1 -0
  294. package/dist/lib/directives/chat-slot.directive.js +54 -0
  295. package/dist/lib/directives/chat-slot.directive.js.map +1 -0
  296. package/dist/lib/events/chat-events.d.ts +137 -0
  297. package/dist/lib/events/chat-events.d.ts.map +1 -0
  298. package/dist/lib/events/chat-events.js +189 -0
  299. package/dist/lib/events/chat-events.js.map +1 -0
  300. package/dist/lib/models/conversation-state.model.d.ts +2 -1
  301. package/dist/lib/models/conversation-state.model.d.ts.map +1 -1
  302. package/dist/lib/models/conversation-state.model.js.map +1 -1
  303. package/dist/lib/services/artifact-state.service.d.ts.map +1 -1
  304. package/dist/lib/services/artifact-state.service.js +23 -6
  305. package/dist/lib/services/artifact-state.service.js.map +1 -1
  306. package/dist/lib/services/conversation-agent.service.d.ts +60 -74
  307. package/dist/lib/services/conversation-agent.service.d.ts.map +1 -1
  308. package/dist/lib/services/conversation-agent.service.js +100 -313
  309. package/dist/lib/services/conversation-agent.service.js.map +1 -1
  310. package/dist/lib/services/conversation-bridge.service.d.ts +11 -70
  311. package/dist/lib/services/conversation-bridge.service.d.ts.map +1 -1
  312. package/dist/lib/services/conversation-bridge.service.js +51 -85
  313. package/dist/lib/services/conversation-bridge.service.js.map +1 -1
  314. package/dist/lib/services/conversation-naming.d.ts +63 -0
  315. package/dist/lib/services/conversation-naming.d.ts.map +1 -0
  316. package/dist/lib/services/conversation-naming.js +58 -0
  317. package/dist/lib/services/conversation-naming.js.map +1 -0
  318. package/dist/lib/services/conversation-streaming.service.d.ts +24 -154
  319. package/dist/lib/services/conversation-streaming.service.d.ts.map +1 -1
  320. package/dist/lib/services/conversation-streaming.service.js +39 -361
  321. package/dist/lib/services/conversation-streaming.service.js.map +1 -1
  322. package/dist/lib/services/conversations-runtime-bootstrap.service.d.ts +10 -0
  323. package/dist/lib/services/conversations-runtime-bootstrap.service.d.ts.map +1 -0
  324. package/dist/lib/services/conversations-runtime-bootstrap.service.js +104 -0
  325. package/dist/lib/services/conversations-runtime-bootstrap.service.js.map +1 -0
  326. package/dist/lib/services/delegation-result-parser.d.ts +45 -0
  327. package/dist/lib/services/delegation-result-parser.d.ts.map +1 -0
  328. package/dist/lib/services/delegation-result-parser.js +48 -0
  329. package/dist/lib/services/delegation-result-parser.js.map +1 -0
  330. package/dist/lib/services/mention-autocomplete.service.d.ts +19 -4
  331. package/dist/lib/services/mention-autocomplete.service.d.ts.map +1 -1
  332. package/dist/lib/services/mention-autocomplete.service.js +65 -4
  333. package/dist/lib/services/mention-autocomplete.service.js.map +1 -1
  334. package/dist/lib/services/mention-parser.service.d.ts +8 -53
  335. package/dist/lib/services/mention-parser.service.d.ts.map +1 -1
  336. package/dist/lib/services/mention-parser.service.js +32 -243
  337. package/dist/lib/services/mention-parser.service.js.map +1 -1
  338. package/dist/lib/services/narration-template.d.ts +42 -0
  339. package/dist/lib/services/narration-template.d.ts.map +1 -0
  340. package/dist/lib/services/narration-template.js +73 -0
  341. package/dist/lib/services/narration-template.js.map +1 -0
  342. package/dist/lib/services/realtime-pairing.d.ts +120 -0
  343. package/dist/lib/services/realtime-pairing.d.ts.map +1 -0
  344. package/dist/lib/services/realtime-pairing.js +150 -0
  345. package/dist/lib/services/realtime-pairing.js.map +1 -0
  346. package/dist/lib/services/realtime-session-review.service.d.ts +233 -0
  347. package/dist/lib/services/realtime-session-review.service.d.ts.map +1 -0
  348. package/dist/lib/services/realtime-session-review.service.js +417 -0
  349. package/dist/lib/services/realtime-session-review.service.js.map +1 -0
  350. package/dist/lib/services/realtime-session.service.d.ts +739 -0
  351. package/dist/lib/services/realtime-session.service.d.ts.map +1 -0
  352. package/dist/lib/services/realtime-session.service.js +1647 -0
  353. package/dist/lib/services/realtime-session.service.js.map +1 -0
  354. package/dist/lib/services/realtime-sessions-adapter.d.ts +54 -0
  355. package/dist/lib/services/realtime-sessions-adapter.d.ts.map +1 -0
  356. package/dist/lib/services/realtime-sessions-adapter.js +154 -0
  357. package/dist/lib/services/realtime-sessions-adapter.js.map +1 -0
  358. package/dist/lib/services/user-authorization.d.ts +67 -0
  359. package/dist/lib/services/user-authorization.d.ts.map +1 -0
  360. package/dist/lib/services/user-authorization.js +66 -0
  361. package/dist/lib/services/user-authorization.js.map +1 -0
  362. package/dist/lib/utils/realtime-session-timeline.d.ts +84 -0
  363. package/dist/lib/utils/realtime-session-timeline.d.ts.map +1 -0
  364. package/dist/lib/utils/realtime-session-timeline.js +94 -0
  365. package/dist/lib/utils/realtime-session-timeline.js.map +1 -0
  366. package/dist/public-api.d.ts +41 -0
  367. package/dist/public-api.d.ts.map +1 -1
  368. package/dist/public-api.js +50 -0
  369. package/dist/public-api.js.map +1 -1
  370. package/package.json +27 -24
  371. package/dist/__tests__/conversation-bridge.service.test.d.ts +0 -2
  372. package/dist/__tests__/conversation-bridge.service.test.d.ts.map +0 -1
  373. package/dist/__tests__/conversation-bridge.service.test.js +0 -98
  374. package/dist/__tests__/conversation-bridge.service.test.js.map +0 -1
  375. package/dist/__tests__/mention-parser.test.d.ts +0 -2
  376. package/dist/__tests__/mention-parser.test.d.ts.map +0 -1
  377. package/dist/__tests__/mention-parser.test.js +0 -154
  378. package/dist/__tests__/mention-parser.test.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime-session.service.js","sourceRoot":"","sources":["../../../src/lib/services/realtime-session.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAc,OAAO,EAAgB,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAqB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EAOtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAA4B,MAAM,4BAA4B,CAAC;AACjG,OAAO,EAAE,yBAAyB,EAA0B,MAAM,8DAA8D,CAAC;;AAEjI,iFAAiF;AACjF,wFAAwF;AACxF,uEAAuE;AACvE,qFAAqF;AACrF,sFAAsF;AACtF,sFAAsF;AACtF,uFAAuF;AACvF,wBAAwB,EAAE,CAAC;AAC3B,wBAAwB,EAAE,CAAC;AAC3B,4BAA4B,EAAE,CAAC;AAC/B,4BAA4B,EAAE,CAAC;AAC/B,qBAAqB,EAAE,CAAC;AA0LxB;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,OAAO,sBAAsB;IACjC,8EAA8E;IACtE,iBAAiB,GAAG,IAAI,eAAe,CAAuB,QAAQ,CAAC,CAAC;IACxE,UAAU,GAAG,IAAI,eAAe,CAAiB,EAAE,CAAC,CAAC;IACrD,QAAQ,GAAG,IAAI,eAAe,CAAU,KAAK,CAAC,CAAC;IAC/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AAE,MAAM,EAAE","sourcesContent":["import { Injectable } from '@angular/core';\nimport { BehaviorSubject, Observable, Subject, Subscription } from 'rxjs';\nimport { Metadata, IMetadataProvider } from '@memberjunction/core';\nimport { AIEngineBase } from '@memberjunction/ai-engine-base';\nimport { GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';\nimport { MJGlobal } from '@memberjunction/global';\nimport { ClientRealtimeSessionConfig, JSONObject, JSONValue, RealtimeToolDefinition } from '@memberjunction/ai';\nimport {\n BaseRealtimeClient,\n LoadAssemblyAIRealtimeClient,\n LoadElevenLabsRealtimeClient,\n LoadGeminiRealtimeClient,\n LoadOpenAIRealtimeClient,\n LoadxAIRealtimeClient,\n RealtimeAudioActivity,\n RealtimeClientError,\n RealtimeClientState,\n RealtimeClientToolCall,\n RealtimeClientTranscript,\n RealtimeClientUsage\n} from '@memberjunction/ai-realtime-client';\nimport { BuildNarrationInstructions } from './narration-template';\nimport { ParseDelegationResultJson, ParsedDelegationArtifact } from './delegation-result-parser';\nimport { BaseRealtimeChannelClient, RealtimeChannelContext } from '../components/realtime/channels/base-realtime-channel-client';\n\n// Tree-shaking prevention: the OpenAI client is resolved dynamically through the\n// ClassFactory (by the server-reported Provider key), so this static call is what keeps\n// its @RegisterClass side effect from being eliminated by the bundler.\n// NOTE: the interactive-channel plugins (resolved dynamically from the `MJ: AI Agent\n// Channels` registry by ClientPluginClass key) get the same treatment, but their Load\n// calls live in `conversations.module.ts` — plugins carry Angular surface COMPONENTS,\n// and this service stays component-free (it must stay importable in plain-node tests).\nLoadOpenAIRealtimeClient();\nLoadGeminiRealtimeClient();\nLoadElevenLabsRealtimeClient();\nLoadAssemblyAIRealtimeClient();\nLoadxAIRealtimeClient();\n\n/**\n * Connection / turn state for a real-time voice session, surfaced to the UI overlay.\n * - `connecting` — negotiating the session + provider handshake\n * - `listening` — connected, mic open, waiting for / hearing the user\n * - `speaking` — the agent is producing audio\n * - `thinking` — the agent delegated work (tool call) and is waiting on a result\n * - `error` — a fatal error occurred; the session is no longer usable\n * - `closed` — the session has been torn down\n */\nexport type VoiceConnectionState =\n | 'connecting'\n | 'listening'\n | 'speaking'\n | 'thinking'\n | 'error'\n | 'closed';\n\n/** A single caption line (one side of the conversation) shown in the live-captions list. */\nexport interface VoiceCaption {\n Role: 'User' | 'Assistant';\n Text: string;\n}\n\n/**\n * A delegated-run progress update surfaced to the UI, emitted on {@link RealtimeSessionService.DelegationProgress$}.\n * These originate server-side during an `invoke-target-agent` delegation (e.g. while Sage works) and let a\n * future overlay render a \"working\" card while the realtime model narrates the same progress aloud.\n */\nexport interface VoiceDelegationProgress {\n /** The `invoke-target-agent` call this progress belongs to. */\n CallID: string;\n /** The delegation phase: `prompt_execution` | `action_execution` | `subagent_execution` | `decision_processing`. */\n Step: string;\n /** Human-readable progress message. */\n Message: string;\n /** Optional completion percentage (0–100) when the server can estimate it. */\n Percentage?: number;\n}\n\n/**\n * The terminal result of a delegated tool call, emitted on {@link RealtimeSessionService.DelegationResult$}\n * when the delegation finishes so the overlay can flip the \"working\" card into a result card with real\n * content + provenance.\n */\nexport interface VoiceDelegationResult {\n /** The `invoke-target-agent` call this result belongs to. */\n CallID: string;\n /** Whether the delegated work succeeded. */\n Success: boolean;\n /** The result text — the agent's output, or an error message on failure. */\n Output: string;\n /**\n * ID of the delegated agent run (`MJ: AI Agent Runs`) when the server reported one\n * (`runId` in the tool ResultJson). Powers the overlay's gear-gated \"Open run\" dev link.\n */\n RunID?: string;\n /**\n * Artifacts the delegated run produced, when the server reported any (`artifacts` in the\n * tool ResultJson). The overlay's tabbed surface panel auto-opens one artifact tab per\n * entry and focuses the newest on arrival.\n */\n Artifacts?: ParsedDelegationArtifact[];\n}\n\n/**\n * Handler for a CLIENT-EXECUTED UI tool (e.g. the live whiteboard's `Whiteboard_*` surface),\n * registered via {@link RealtimeSessionService.RegisterClientToolHandler}. Receives the tool name +\n * raw arguments JSON from the realtime model and returns the result JSON string fed back as the\n * `tool_response`. May be sync or async; thrown errors are wrapped into a\n * `{ success: false, error }` payload by the service so the model can narrate the failure.\n */\nexport type RealtimeClientToolHandler = (toolName: string, argsJson: string) => string | Promise<string>;\n\n/**\n * A channel's request to enter / leave the FOCUS layout, emitted on\n * {@link RealtimeSessionService.ChannelFocus$} when a plugin calls its context's\n * `SetFocusMode`. The overlay shell subscribes: it collapses/restores the main call column\n * and remembers which channel holds focus (so the floating pill's \"exit\" can be routed\n * back via {@link BaseRealtimeChannelClient.RequestFocusExit}).\n */\nexport interface RealtimeChannelFocusEvent {\n /** The channel plugin requesting the layout change. */\n Channel: BaseRealtimeChannelClient;\n /** `true` to enter focus mode (surface owns the screen), `false` to leave it. */\n Focused: boolean;\n}\n\n/**\n * The narrow projection of an ACTIVE `MJ: AI Agent Channels` registry row the service\n * reads at session start from {@link AIEngineBase}'s cached `AgentChannels`.\n */\ninterface RealtimeChannelDefinitionRow {\n ID: string;\n Name: string;\n ClientPluginClass: string;\n}\n\n/**\n * One EPHEMERAL spoken narration of delegated-run progress, emitted on\n * {@link RealtimeSessionService.DelegationNarration$}. These are the interim \"here's what's\n * happening\" utterances the realtime model speaks while a delegation runs. By product\n * decision they are NOT captions and NOT persisted as ConversationDetails — they exist\n * only as a live note in the overlay, replaced by each newer narration.\n */\nexport interface VoiceDelegationNarration {\n /** The narration transcript text. */\n Text: string;\n}\n\n/**\n * Raw shape of the JSON `message` the server publishes on the push-status topic during a delegated run.\n * We filter on `resolver` + `type` before correlating by `agentSessionID`; normal agent runs publish\n * other shapes on the same topic and are ignored.\n */\ninterface RealtimeDelegationProgressPayload {\n resolver: string;\n type: string;\n agentSessionID: string;\n callID: string;\n step: string;\n message: string;\n percentage?: number;\n}\n\n/**\n * Raw shape of the JSON `message` the server publishes on the push-status topic for each live Remote\n * Browser screencast frame (mirrors {@link RealtimeDelegationProgressPayload}, distinguished by\n * `resolver` + `type`). Routed to the active Remote Browser channel plugin — never narrated.\n */\ninterface RemoteBrowserScreencastPayload {\n type: 'RemoteBrowserScreencastFrame';\n agentSessionID: string;\n dataBase64: string;\n width: number;\n height: number;\n seq: number;\n}\n\n/**\n * Raw shape of the JSON `message` the server publishes on the push-status topic for each live Remote\n * Browser tab-audio chunk (mirrors {@link RemoteBrowserScreencastPayload}, distinguished by `type`).\n * Routed to the active Remote Browser channel plugin's audio player — never narrated.\n */\ninterface RemoteBrowserAudioChunkPayload {\n type: 'RemoteBrowserAudioChunk';\n agentSessionID: string;\n dataBase64: string;\n codec: string;\n sampleRate: number;\n channels: number;\n seq: number;\n}\n\n/**\n * Result shape returned by the `StartRealtimeClientSession` server mutation.\n * The browser uses these values to open a client-direct realtime session.\n */\ninterface StartRealtimeClientSessionResult {\n AgentSessionId: string;\n ConversationId: string | null;\n Provider: string;\n Model: string;\n EphemeralToken: string;\n ExpiresAt: string;\n /** JSON.stringify of the provider session config (instructions + tools) to apply at connect. */\n SessionConfigJson: string;\n /** Display name of the realtime model the session uses (e.g. \"GPT Realtime 2\"). Null when unknown. */\n ModelName: string | null;\n /**\n * DB-driven progress-narration instruction template (contains a `{{ progressMessage }}`\n * placeholder). Null when the deployment hasn't synced the narration prompt — the client\n * falls back to its built-in wording.\n */\n NarrationInstructionsTemplate: string | null;\n /**\n * JSON map of the PRIOR session's saved channel states keyed by channel name (present only\n * when the start carried `lastSessionId` and the prior session — owned by the same user —\n * had saved states). Applied to the matching channel plugins via\n * {@link BaseRealtimeChannelClient.RestoreState} so e.g. the whiteboard resumes where the\n * last session left off.\n */\n PriorChannelStatesJson: string | null;\n}\n\n/**\n * Drives a **client-direct** real-time voice session: the browser mints an ephemeral\n * token from the MJ server, then connects DIRECTLY to the realtime provider. Audio\n * frames never transit the MJ server (low latency); only tool calls and final\n * transcripts are relayed back to MJ over GraphQL.\n *\n * This service is PROVIDER-AGNOSTIC policy/orchestration. All provider wire concerns\n * (transport, event translation, the response state machine, narration-kind tagging,\n * playback tracking) live in a {@link BaseRealtimeClient} driver resolved through the\n * MJ ClassFactory by the server-reported `Provider` key (e.g. `'openai'` →\n * `OpenAIRealtimeClient`). Future providers (Gemini Live, …) snap in by registering a\n * new driver — this service does not change.\n *\n * The Realtime Co-Agent (server-side) fronts the conversation's current agent — the server\n * bakes the companion instructions + tool set into `SessionConfigJson`, which the client\n * driver applies verbatim.\n *\n * Lifecycle: {@link StartVoiceSession} → live duplex → {@link EndVoiceSession}.\n */\n@Injectable({ providedIn: 'root' })\nexport class RealtimeSessionService {\n // ── Reactive UI state ──────────────────────────────────────────────────────\n private _connectionState$ = new BehaviorSubject<VoiceConnectionState>('closed');\n private _captions$ = new BehaviorSubject<VoiceCaption[]>([]);\n private _active$ = new BehaviorSubject<boolean>(false);\n private _delegationProgress$ = new Subject<VoiceDelegationProgress>();\n private _delegationResult$ = new Subject<VoiceDelegationResult>();\n private _delegationNarration$ = new Subject<VoiceDelegationNarration>();\n private _agentName$ = new BehaviorSubject<string>('Sage');\n private _modelName$ = new BehaviorSubject<string | null>(null);\n private _minimized$ = new BehaviorSubject<boolean>(false);\n private _activeChannels$ = new BehaviorSubject<BaseRealtimeChannelClient[]>([]);\n private _channelFocus$ = new Subject<RealtimeChannelFocusEvent>();\n // ─── Generic session-lifecycle events (consumed by RealtimeSessionsAdapter to\n // bridge into @memberjunction/conversations-runtime's framework-agnostic\n // SessionsObserver). Why not derive from Active$ + agentSessionId? Because\n // Active$ flips true before mintSession resolves and sets agentSessionId —\n // a naive Active$ subscription would emit session-started with sessionId === null.\n // Emitting explicitly avoids the race entirely. ───\n private _sessionStarted$ = new Subject<{ sessionId: string; channelNames: string[] }>();\n private _sessionEnded$ = new Subject<{ sessionId: string; reason: 'explicit' | 'error' }>();\n private _channelActivity$ = new Subject<BaseRealtimeChannelClient>();\n\n /** Current connection / turn state. */\n public readonly ConnectionState$: Observable<VoiceConnectionState> = this._connectionState$.asObservable();\n /** Live captions for both sides of the conversation. */\n public readonly Captions$: Observable<VoiceCaption[]> = this._captions$.asObservable();\n /** True while a session is open (mic button active, overlay shown). */\n public readonly Active$: Observable<boolean> = this._active$.asObservable();\n /**\n * Progress updates from a delegated agent run (e.g. Sage) while the realtime model waits on it.\n * The future overlay subscribes to render a \"working\" card; the model also narrates these aloud.\n */\n public readonly DelegationProgress$: Observable<VoiceDelegationProgress> = this._delegationProgress$.asObservable();\n /** Terminal result of a delegation, so the overlay can complete the working card with real content. */\n public readonly DelegationResult$: Observable<VoiceDelegationResult> = this._delegationResult$.asObservable();\n /**\n * EPHEMERAL spoken progress narrations (see {@link VoiceDelegationNarration}). These are\n * deliberately kept OUT of {@link Captions$} and never relayed/persisted — the overlay\n * renders them as a transient \"live note\" near the active working card.\n */\n public readonly DelegationNarration$: Observable<VoiceDelegationNarration> = this._delegationNarration$.asObservable();\n /** Display name of the agent the active session fronts (set at session start). */\n public readonly AgentName$: Observable<string> = this._agentName$.asObservable();\n /**\n * Display name of the realtime MODEL the active session runs on (server-reported at session\n * start, e.g. \"GPT Realtime 2\"). `null` before a session starts / when the server didn't report\n * one. The overlay banner shows it subtly next to the agent identity.\n */\n public readonly ModelName$: Observable<string | null> = this._modelName$.asObservable();\n\n /**\n * True while the active call overlay is MINIMIZED to the host's floating \"on call\" pill\n * (e.g. after a dev link navigated away). The mic and session stay fully live — this is\n * pure presentation state, reset to `false` at session start and teardown.\n */\n public readonly Minimized$: Observable<boolean> = this._minimized$.asObservable();\n\n /**\n * The session's ACTIVE interactive-channel plugins, resolved from the `MJ: AI Agent\n * Channels` registry at session start (one instance per session, per channel). Emits\n * `[]` before a session starts and after teardown. The overlay subscribes to register\n * one surface tab per plugin — it never knows any concrete channel type.\n */\n public readonly ActiveChannels$: Observable<BaseRealtimeChannelClient[]> = this._activeChannels$.asObservable();\n\n /**\n * Channel requests to enter / leave the FOCUS layout (see\n * {@link RealtimeChannelFocusEvent}). Fired when a plugin calls its host context's\n * `SetFocusMode` — e.g. the whiteboard's \"Focus board\" toggle.\n */\n public readonly ChannelFocus$: Observable<RealtimeChannelFocusEvent> = this._channelFocus$.asObservable();\n\n /**\n * Fired EXACTLY ONCE per session after both `agentSessionId` is set AND the\n * realtime client is connected. Carries the server-issued `sessionId` and the\n * `ChannelName` of each plugin resolved at session mint. Consumed by\n * `RealtimeSessionsAdapter` (in this package) to feed\n * `@memberjunction/conversations-runtime`'s `SessionsObserver`.\n *\n * **Why this exists separately from `Active$`:** `Active$` flips `true` BEFORE\n * `mintSession` resolves, so `agentSessionId` is still `null` at that moment.\n * Subscribers correlating `(Active$, agentSessionId)` would race; this event\n * removes the race.\n */\n public readonly SessionStarted$: Observable<{ sessionId: string; channelNames: string[] }> =\n this._sessionStarted$.asObservable();\n\n /**\n * Fired EXACTLY ONCE per session as teardown begins, with the prior\n * `agentSessionId` (so subscribers can correlate against `SessionStarted$`'s\n * sessionId) and the client-distinguishable reason — `'explicit'` when the\n * user called `EndVoiceSession`, `'error'` when teardown ran from a catch\n * block. Server-side close paths (janitor, shutdown) do NOT propagate here —\n * they happen out-of-process and have no client push channel today.\n */\n public readonly SessionEnded$: Observable<{ sessionId: string; reason: 'explicit' | 'error' }> =\n this._sessionEnded$.asObservable();\n\n /**\n * Fires with the channel PLUGIN every time the agent ACTS on that channel (a tool call\n * was routed to its local executor — e.g. the agent drew on the whiteboard). The overlay\n * uses the FIRST emission per channel to auto-reveal + focus the channel's surface tab,\n * so the user discovers the surface the moment the agent starts using it. Finer-grained\n * than {@link SessionStarted$}/{@link SessionEnded$} (per tool call, not per session).\n */\n public readonly ChannelActivity$: Observable<BaseRealtimeChannelClient> = this._channelActivity$.asObservable();\n\n /** Synchronous access to the session's active interactive-channel plugins. */\n public get ActiveChannels(): readonly BaseRealtimeChannelClient[] {\n return this._activeChannels$.value;\n }\n\n /** Synchronous access to the display name of the agent the active session fronts. */\n public get CurrentAgentName(): string {\n return this._agentName$.value;\n }\n\n /**\n * ID of the active server-side agent session (`MJ: AI Agent Sessions`), or `null` when no\n * session is open / the session hasn't been minted yet. Powers the overlay's gear-gated\n * \"Open session\" dev link.\n */\n /** Conversation id the SERVER created for this session (null when the host supplied one). */\n private createdConversationId: string | null = null;\n /** The session's conversation id (supplied or server-created). */\n private sessionConversationId: string | null = null;\n /** First final user utterance of the live session (the naming seed). */\n private firstUserTranscript: string | null = null;\n\n /**\n * When the active/last session CREATED its conversation (started without one), the new\n * conversation's id — the host uses it to refresh the cached list, conditionally select\n * it on close, and auto-name it. Null when the session joined an existing conversation.\n */\n public get SessionCreatedConversationId(): string | null {\n return this.createdConversationId;\n }\n\n /** The first final user utterance of the session (naming seed); null before the user speaks. */\n public get FirstUserTranscript(): string | null {\n return this.firstUserTranscript;\n }\n\n public get CurrentAgentSessionId(): string | null {\n return this.agentSessionId;\n }\n\n /** Synchronous access to the minimized presentation state. */\n public get IsMinimized(): boolean {\n return this._minimized$.value;\n }\n\n /**\n * Minimizes / restores the active call overlay (host renders the floating pill while\n * minimized). Presentation-only — the live audio session is untouched.\n */\n public SetMinimized(minimized: boolean): void {\n if (this._minimized$.value !== minimized) {\n this._minimized$.next(minimized);\n }\n }\n\n // ── Session internals ──────────────────────────────────────────────────────\n /** The provider-direct realtime client driving the live session (ClassFactory-resolved). */\n private client: BaseRealtimeClient | null = null;\n /** The mic capture stream — acquired here (permission UX) and handed to the client. */\n private localStream: MediaStream | null = null;\n private agentSessionId: string | null = null;\n /**\n * The DB-driven narration instruction template (server-resolved at session start, containing a\n * `{{ progressMessage }}` placeholder). `null` when the deployment hasn't synced the narration\n * prompt — {@link buildNarrationInstructions} then falls back to the built-in wording.\n */\n private narrationTemplate: string | null = null;\n\n // ── Delegated-run progress streaming ───────────────────────────────────────\n /** First spoken update fires no earlier than this long after delegated work starts. */\n private static readonly FirstNarrationDelayMs = 5000;\n /** Minimum gap between SUBSEQUENT spoken updates (the 7–10s band; floods aggregate). */\n private static readonly NarrationIntervalMs = 8000;\n /** Retry delay when the fire moment finds the model busy / audio still playing. */\n private static readonly NarrationBusyRetryMs = 1500;\n /** Max progress messages aggregated into one spoken digest. */\n private static readonly MaxDigestMessages = 4;\n /** Max prior spoken narrations chained into the instructions (anti-repetition). */\n private static readonly MaxPriorNarrations = 3;\n /**\n * Aggregation buffer: distinct progress messages since the last spoken update (oldest\n * first, capped at {@link RealtimeSessionService.MaxDigestMessages}). A flood of small\n * updates becomes ONE digest; the buffer is discarded when the result lands first.\n */\n private pendingNarrationMessages: string[] = [];\n /**\n * Tool calls currently executing on the server. Progress events ride PubSub and can\n * lag the (fast) mutation result — any progress for a call NOT in this set is stale\n * (already completed) and is dropped, so we never narrate \"starting up\" after the\n * answer was already spoken.\n */\n private inFlightCallIds = new Set<string>();\n /** Timer for the deferred narration; cancelled when the delegation result lands first. */\n private narrationTimer: ReturnType<typeof setTimeout> | null = null;\n /**\n * Call ids the USER explicitly cancelled via {@link CancelDelegation} /\n * {@link CancelInFlightDelegations}. Their cards were already flipped to the\n * \"Cancelled by user\" failed result, so when the original tool mutation later resolves\n * with the aborted run's outcome, {@link emitDelegationResult} skips the duplicate card\n * emission (the model still receives the tool result). Cleared at teardown.\n */\n private cancelledCallIds = new Set<string>();\n\n // ── Usage telemetry relay (B7) ─────────────────────────────────────────────\n /** Debounce window for relaying accumulated usage deltas to the server. */\n private static readonly UsageFlushDebounceMs = 10000;\n /** Accumulated input-token delta since the last flush. */\n private pendingUsageInput = 0;\n /** Accumulated output-token delta since the last flush. */\n private pendingUsageOutput = 0;\n /** Pending debounced usage flush; also force-flushed at teardown. */\n private usageFlushTimer: ReturnType<typeof setTimeout> | null = null;\n /** Active push-status subscription that feeds delegation progress; cleared on teardown. */\n private delegationProgressSub: Subscription | null = null;\n /** Timestamp (ms) of the last narration we triggered; 0 = never. */\n private lastDelegationNarrationAt = 0;\n /** When the current delegation burst began (first in-flight call); anchors the 5s first update. */\n private delegationBurstStartedAt = 0;\n /** Spoken updates so far in this burst (1-based numbering for the instructions). */\n private narrationCount = 0;\n /** What the model actually SAID for prior updates this burst — chained in so it never repeats itself. */\n private spokenNarrations: string[] = [];\n /** Tail message of the last digest, so an identical trailing progress event isn't re-buffered. */\n private lastNarratedTail = '';\n\n /**\n * Registry of CLIENT-EXECUTED UI tool handlers, keyed by tool-name prefix (e.g.\n * `'Whiteboard_'`). Tool calls whose name matches a registered prefix run LOCALLY through the\n * handler (never relayed to the server); everything else takes the standard server-relay path.\n * Cleared at teardown.\n */\n private clientToolHandlers = new Map<string, RealtimeClientToolHandler>();\n\n // ── Interactive channels (registry-resolved plugins) ───────────────────────\n /** Debounce window for persisting a channel's state of record after a change burst. */\n private static readonly ChannelSaveDebounceMs = 3000;\n /**\n * Pending DEBOUNCED channel-state saves, keyed by channel name. Each entry keeps the\n * LATEST serialized state plus the session id captured while the session was live —\n * the teardown flush runs as the live id is being torn down, so the capture guarantees\n * the final save still lands on the just-closed session.\n */\n private pendingChannelSaves = new Map<string, {\n Timer: ReturnType<typeof setTimeout>;\n StateJson: string;\n SessionID: string | null;\n }>();\n\n private _provider: IMetadataProvider | null = null;\n\n /**\n * Metadata provider used for the GraphQL relay mutations. Falls back to the\n * global default when unset (single-provider apps see no change).\n */\n public get Provider(): IMetadataProvider {\n return this._provider ?? Metadata.Provider;\n }\n public set Provider(value: IMetadataProvider | null) {\n this._provider = value;\n }\n\n /** True when a session is currently open. */\n public get IsActive(): boolean {\n return this._active$.value;\n }\n\n /**\n * Start a client-direct voice session fronting `targetAgentId`.\n *\n * @param targetAgentId The agent the Realtime Co-Agent voices on behalf of.\n * @param conversationId Optional existing conversation to bind + seed context from.\n * @param lastSessionId Optional prior session to chain to (resume / continuation).\n * @param agentName Optional display name of the target agent — resolved by the caller\n * (which knows the conversation's routing context) and surfaced on {@link AgentName$}\n * so ANY host (composer trigger, chat-area overlay) can render it without re-resolving.\n * @param preferredModelId Optional EXPLICIT realtime model choice (`MJ: AI Models.ID`). When\n * set, the server uses exactly that model and FAILS with a clear reason if it can't (no\n * silent fallback). Omit for the server's automatic (highest-PowerRank) selection.\n * @param clientTools Optional EXTRA client-executed UI tool declarations to expose to the\n * realtime model alongside the server's stable tool set and the interactive-channel\n * tools (which are aggregated automatically from the registry-resolved plugins — see\n * {@link ActiveChannels$}). The server only DECLARES these — execution stays in the\n * browser via handlers registered with {@link RegisterClientToolHandler}. This is an\n * extension point for hosts with bespoke (non-channel) UI tools; most callers omit it.\n * @param coAgentId Optional EXPLICIT co-agent choice (`MJ: AI Agents.ID` of an Active,\n * Realtime-type agent) — the highest-precedence step of the server's co-agent resolution\n * chain. When set, the server uses exactly that co-agent and FAILS with a clear reason if\n * it can't (no silent fallback). Omit to let server metadata drive the choice: the target\n * agent's `DefaultCoAgentID`, then the type-level `AIAgentCoAgent` default row, then the global Realtime Co-Agent.\n * @param configOverridesJson Optional JSON payload of SESSION CONFIG overrides (e.g.\n * `{\"realtime\":{\"modelPreference\":\"<modelId>\"}}`), forwarded verbatim on the mint\n * mutation. The server enforces the `Realtime: Advanced Session Controls`\n * authorization on any overrides — hosts only populate this from authorization-gated\n * pickers, and never synthesize overrides beyond what the user explicitly chose.\n * Omit/`null` for the server's defaults (today's behavior).\n */\n public async StartVoiceSession(\n targetAgentId: string,\n conversationId?: string | null,\n lastSessionId?: string | null,\n agentName?: string | null,\n preferredModelId?: string | null,\n clientTools?: RealtimeToolDefinition[] | null,\n coAgentId?: string | null,\n configOverridesJson?: string | null\n ): Promise<void> {\n if (this.IsActive) {\n return; // a session is already running — ignore duplicate starts\n }\n\n if (agentName) {\n this._agentName$.next(agentName);\n }\n this.resetState();\n this._active$.next(true);\n this._connectionState$.next('connecting');\n\n try {\n // Resolve + initialize the interactive-channel plugins FIRST: their client-executed\n // tool sets must be declared to the realtime model at session mint.\n const allClientTools = [...(clientTools ?? []), ...(await this.startChannels())];\n const session = await this.mintSession(targetAgentId, conversationId, lastSessionId, preferredModelId, allClientTools, coAgentId, configOverridesJson);\n this.agentSessionId = session.AgentSessionId;\n // A null input conversationId means the SERVER created a fresh conversation for\n // this session — track it so the host can fold it into the cached list, select\n // it on close, and auto-name it (via the shared naming helper).\n this.createdConversationId = !conversationId && session.ConversationId ? session.ConversationId : null;\n this.sessionConversationId = session.ConversationId ?? conversationId ?? null;\n this.firstUserTranscript = null;\n this.narrationTemplate = session.NarrationInstructionsTemplate ?? null;\n this._modelName$.next(session.ModelName ?? null);\n // Resume continuity: rehydrate channel plugins from the PRIOR session's saved states\n // (e.g. the whiteboard) BEFORE any surface binds — tolerant, never blocks the start.\n this.applyPriorChannelStates(session.PriorChannelStatesJson);\n\n const client = this.createRealtimeClient(session.Provider);\n this.client = client;\n this.wireClientHandlers(client);\n\n this.localStream = await navigator.mediaDevices.getUserMedia({ audio: true });\n await client.Connect(this.buildClientConfig(session), this.localStream);\n\n this.subscribeDelegationProgress();\n // State advances to 'listening' once the provider control channel opens\n // (driven by the client's OnStateChange events).\n\n // Surface a generic session-started event for the conversations runtime\n // SessionsObserver bridge. Emitting AFTER Connect() guarantees both that\n // agentSessionId is set (line ~468) AND the realtime client is connected,\n // so consumers can act on it without re-checking either condition.\n this._sessionStarted$.next({\n sessionId: this.agentSessionId,\n channelNames: this._activeChannels$.value.map(c => c.ChannelName),\n });\n } catch (error) {\n console.error('[RealtimeSession] Failed to start session:', error);\n this._connectionState$.next('error');\n await this.teardown(false);\n }\n }\n\n /**\n * End the active session: stop the mic, tear down the provider connection, and close\n * the server-side agent session. Safe to call when no session is active.\n */\n public async EndVoiceSession(): Promise<void> {\n if (!this.IsActive && !this.agentSessionId) {\n return;\n }\n await this.teardown(true);\n }\n\n /**\n * Inject a typed message into the live session as a user turn.\n *\n * Decomposed into two steps, each mirroring an existing voice path so the typed\n * turn behaves identically to a spoken one:\n * 1. {@link BaseRealtimeClient.SendText} injects the text as user input and triggers a\n * reply through the SAME collision-safe path tool results use — so it queues behind\n * any in-flight response (progress narration / prior turn) instead of colliding.\n * 2. Relay the turn through the same caption + transcript paths user speech uses\n * ({@link onUserTranscript}) so it shows in the live thread AND persists to MJ.\n *\n * No-op when no session is open / the control channel isn't ready, or when the text is empty.\n */\n public SendText(text: string): void {\n const trimmed = text?.trim() ?? '';\n if (trimmed.length === 0) {\n return;\n }\n const client = this.client;\n if (!client || !this.isSessionLive()) {\n return;\n }\n client.SendText(trimmed);\n // Relay as a user turn — same path spoken input uses (caption + persisted transcript).\n void this.onUserTranscript(trimmed);\n }\n\n /** Mute / unmute the local microphone track. Returns the new muted state. */\n public ToggleMute(): boolean {\n const tracks = this.localStream?.getAudioTracks() ?? [];\n if (tracks.length === 0) {\n return false;\n }\n const muted = tracks[0].enabled; // currently enabled → becomes muted\n this.client?.SetMuted(muted);\n return muted;\n }\n\n // ── Client-executed UI tools ───────────────────────────────────────────────\n\n /**\n * Registers a handler for CLIENT-EXECUTED UI tools whose names start with `toolNamePrefix`\n * (e.g. `'Whiteboard_'` → all `Whiteboard_*` calls). Matching tool calls execute LOCALLY via\n * the handler — they are never relayed to the server — and the handler's result JSON is sent\n * back to the model as the `tool_response`. Re-registering the same prefix replaces the\n * handler. The registry is cleared at session teardown.\n */\n public RegisterClientToolHandler(toolNamePrefix: string, handler: RealtimeClientToolHandler): void {\n this.clientToolHandlers.set(toolNamePrefix, handler);\n }\n\n /** Removes the handler registered for `toolNamePrefix` (no-op when none is registered). */\n public UnregisterClientToolHandler(toolNamePrefix: string): void {\n this.clientToolHandlers.delete(toolNamePrefix);\n }\n\n /**\n * Feeds a background context note into the live model (no spoken reply is requested) — the\n * perception channel interactive surfaces use (e.g. the whiteboard's coalesced scene deltas).\n * No-op when no session is live.\n */\n public SendContextNote(text: string): void {\n const trimmed = text?.trim() ?? '';\n if (trimmed.length === 0 || !this.client || !this.isSessionLive()) {\n return;\n }\n this.client.SendContextNote(trimmed);\n }\n\n /**\n * The active client's current audio activity (per-direction RMS levels + spectrum\n * bins), or `null` when no session is live or the driver attached no audio meters.\n * Sampled by the overlay's animation-frame loop to drive the audio-reactive orb/EQ —\n * a cheap analyser read, never provider traffic.\n */\n public GetAudioActivity(): RealtimeAudioActivity | null {\n return this.client?.GetAudioActivity() ?? null;\n }\n\n // ── Interactive channels (registry-driven plugins) ─────────────────────────\n\n /**\n * Resolves, instantiates and initializes the session's interactive-channel plugins from\n * the `MJ: AI Agent Channels` registry, publishes them on {@link ActiveChannels$}, and\n * returns their aggregated client-executed tool declarations for the session mint.\n * Tolerant by design: registry/resolution failures degrade to \"no channels\" — the voice\n * session itself always proceeds.\n */\n private async startChannels(): Promise<RealtimeToolDefinition[]> {\n const channels = await this.loadActiveChannels();\n for (const plugin of channels) {\n this.initializeChannel(plugin);\n }\n this._activeChannels$.next(channels);\n return channels.flatMap(plugin => plugin.GetToolDefinitions());\n }\n\n /**\n * Loads the ACTIVE channel definitions from the registry and resolves each row's\n * `ClientPluginClass` through the MJ ClassFactory into a per-session plugin instance —\n * the client-side mirror of how realtime-model drivers resolve from `BaseRealtimeModel`\n * / `BaseRealtimeClient`. Rows whose plugin class isn't registered are skipped (logged),\n * never fatal.\n */\n private async loadActiveChannels(): Promise<BaseRealtimeChannelClient[]> {\n const rows = await this.fetchChannelDefinitions();\n const channels: BaseRealtimeChannelClient[] = [];\n for (const row of rows) {\n const plugin = this.resolveChannelPlugin(row);\n if (plugin) {\n channels.push(plugin);\n }\n }\n return channels;\n }\n\n /**\n * Reads the ACTIVE `MJ: AI Agent Channels` rows from {@link AIEngineBase}'s cached\n * `AgentChannels` (provider-scoped engine instance, lazy `Config` — no RunView\n * round-trip; the engine's BaseEntity-event reactivity keeps the registry fresh).\n * Failures are logged and degrade to an empty list — channel availability must\n * never block the voice session.\n */\n private async fetchChannelDefinitions(): Promise<RealtimeChannelDefinitionRow[]> {\n try {\n const engine = AIEngineBase.GetProviderInstance<AIEngineBase>(this.Provider, AIEngineBase) as AIEngineBase;\n await engine.Config(false, undefined, this.Provider);\n return (engine.AgentChannels ?? [])\n .filter(c => c.IsActive)\n .map<RealtimeChannelDefinitionRow>(c => ({ ID: c.ID, Name: c.Name, ClientPluginClass: c.ClientPluginClass }));\n } catch (error) {\n console.warn('[RealtimeSession] Channel registry unavailable — starting with no channels:', error);\n return [];\n }\n }\n\n /**\n * Resolves one registry row's `ClientPluginClass` via the ClassFactory (registration\n * checked first, exactly like the realtime-client drivers) and instantiates a fresh\n * per-session plugin. Returns `null` (logged) when no plugin is registered for the key\n * — e.g. its Load function was never called or the package isn't included client-side.\n */\n private resolveChannelPlugin(row: RealtimeChannelDefinitionRow): BaseRealtimeChannelClient | null {\n const key = row.ClientPluginClass?.trim();\n if (!key) {\n console.warn(`[RealtimeSession] Channel '${row.Name}' has no ClientPluginClass — skipping.`);\n return null;\n }\n const registration = MJGlobal.Instance.ClassFactory.GetRegistration(BaseRealtimeChannelClient, key);\n if (!registration) {\n console.warn(`[RealtimeSession] No client plugin registered for channel '${row.Name}' (key '${key}') — skipping.`);\n return null;\n }\n const plugin = MJGlobal.Instance.ClassFactory.CreateInstance<BaseRealtimeChannelClient>(BaseRealtimeChannelClient, key);\n if (!plugin) {\n console.warn(`[RealtimeSession] Failed to instantiate client plugin for channel '${row.Name}' (key '${key}').`);\n return null;\n }\n return plugin;\n }\n\n /**\n * Wires one plugin into the session: hands it its host context and registers its\n * prefix-routed local tool executor (so `<ToolNamePrefix>*` calls run in the browser\n * through {@link BaseRealtimeChannelClient.ApplyAgentTool}, never the server relay).\n */\n private initializeChannel(plugin: BaseRealtimeChannelClient): void {\n plugin.Initialize(this.buildChannelContext(plugin));\n this.RegisterClientToolHandler(plugin.ToolNamePrefix, (toolName, argsJson) => {\n // The agent is ACTING on this channel — surface-discovery signal for the overlay\n // (first activity auto-reveals + focuses the channel tab) before the tool applies.\n this._channelActivity$.next(plugin);\n return plugin.ApplyAgentTool(toolName, argsJson);\n });\n }\n\n /** Builds the host-services context one channel plugin sees (its only line to the session). */\n private buildChannelContext(plugin: BaseRealtimeChannelClient): RealtimeChannelContext {\n // Capture the service in a local so the AgentSessionID getter reads the SERVICE's live\n // field (not the object literal's `this`) every time it's accessed.\n const service = this;\n return {\n AgentName: this.CurrentAgentName,\n SendContextNote: (text: string) => this.SendContextNote(text),\n RequestSpokenResponse: (instructions: string) => this.requestChannelSpokenResponse(instructions),\n RequestSave: (stateJson: string) => this.scheduleChannelSave(plugin.ChannelName, stateJson),\n SaveAsArtifact: (name: string, contentJson: string) => this.saveChannelArtifact(plugin.ChannelName, name, contentJson),\n SetFocusMode: (on: boolean) => this._channelFocus$.next({ Channel: plugin, Focused: on }),\n // Live session id + GraphQL escape hatch for SERVER-BACKED channels (e.g. Remote\n // Browser). `get` so a channel always reads the CURRENT id — it's null at Initialize\n // (the plugin is built before mintSession resolves) and set once the session is live.\n get AgentSessionID(): string | null {\n return service.agentSessionId;\n },\n ExecuteServerAction: <TResult>(query: string, variables: Record<string, JSONValue>) =>\n this.executeChannelServerAction<TResult>(query, variables)\n };\n }\n\n /**\n * Runs a channel-specific GraphQL operation through the live session's provider (the\n * {@link RealtimeChannelContext.ExecuteServerAction} implementation). Best-effort: any\n * transport/server error is logged and resolves to `null` so the calling channel can map\n * the failure to a model-readable result string without `try/catch`.\n */\n private async executeChannelServerAction<TResult>(query: string, variables: Record<string, JSONValue>): Promise<TResult | null> {\n try {\n const result = await this.gql().ExecuteGQL(query, variables);\n return (result as TResult) ?? null;\n } catch (error) {\n console.error('[RealtimeSession] Channel server action failed:', error);\n return null;\n }\n }\n\n /**\n * A channel asked the live model to SPEAK in reaction to channel input (e.g. a widget\n * submission) — routed through the client's spoken-update channel. No-op when the\n * session isn't live; empty instructions are dropped.\n */\n private requestChannelSpokenResponse(instructions: string): void {\n const trimmed = instructions?.trim() ?? '';\n if (trimmed.length === 0 || !this.client || !this.isSessionLive()) {\n return;\n }\n this.client.RequestSpokenUpdate(trimmed);\n }\n\n /**\n * Applies the PRIOR session's saved channel states (resume continuity): parses the\n * server-supplied map and offers each entry to the matching active plugin via\n * {@link BaseRealtimeChannelClient.RestoreState}. Fully tolerant — malformed payloads,\n * unknown channels, and plugin rejections are logged and skipped; the session start is\n * never affected.\n */\n private applyPriorChannelStates(statesJson: string | null | undefined): void {\n if (!statesJson) {\n return;\n }\n let states: Record<string, string>;\n try {\n const parsed: unknown = JSON.parse(statesJson);\n if (parsed === null || typeof parsed !== 'object') {\n return;\n }\n states = parsed as Record<string, string>;\n } catch {\n console.warn('[RealtimeSession] PriorChannelStatesJson was malformed — starting channels fresh');\n return;\n }\n for (const plugin of this._activeChannels$.value) {\n const state = states[plugin.ChannelName];\n if (typeof state === 'string' && state.length > 0) {\n try {\n const restored = plugin.RestoreState(state);\n if (!restored) {\n console.warn(`[RealtimeSession] Channel '${plugin.ChannelName}' declined its prior-session state — starting fresh`);\n }\n } catch (error) {\n console.warn(`[RealtimeSession] Channel '${plugin.ChannelName}' restore threw — starting fresh`, error);\n }\n }\n }\n }\n\n /**\n * Persists a channel's state as a first-class versioned artifact (`MJ: Artifacts`) via the\n * `SaveSessionChannelArtifact` mutation — the channel-context capability behind e.g. the\n * whiteboard's \"Save to artifacts\". Best-effort: returns the created Artifact ID, or null\n * on any failure (logged, never thrown). Uses the live session id, falling back to the\n * teardown-captured one so \"save my board\" works right after the call ends.\n */\n private async saveChannelArtifact(channelName: string, name: string, contentJson: string): Promise<string | null> {\n const sessionId = this.agentSessionId ?? this.lastKnownSessionIdForSaves();\n if (!sessionId || !name.trim() || !contentJson) {\n return null;\n }\n try {\n const result = await this.gql().ExecuteGQL(\n `mutation SaveSessionChannelArtifact($agentSessionId: String!, $channelName: String!, $name: String!, $contentJson: String!) {\n SaveSessionChannelArtifact(agentSessionId: $agentSessionId, channelName: $channelName, name: $name, contentJson: $contentJson) {\n Success\n ErrorMessage\n ArtifactID\n ArtifactVersionID\n }\n }`,\n { agentSessionId: sessionId, channelName, name: name.trim(), contentJson }\n ) as { SaveSessionChannelArtifact?: { Success: boolean; ErrorMessage?: string; ArtifactID?: string } };\n const payload = result?.SaveSessionChannelArtifact;\n if (!payload?.Success) {\n console.warn(`[RealtimeSession] Save-as-artifact failed for '${channelName}': ${payload?.ErrorMessage ?? 'unknown error'}`);\n return null;\n }\n return payload.ArtifactID ?? null;\n } catch (error) {\n console.warn(`[RealtimeSession] Save-as-artifact errored for '${channelName}':`, error);\n return null;\n }\n }\n\n /** Most recent session id captured by the save pipeline (post-teardown saves). */\n private lastKnownSessionIdForSaves(): string | null {\n for (const pending of this.pendingChannelSaves.values()) {\n if (pending.SessionID) {\n return pending.SessionID;\n }\n }\n return null;\n }\n\n /**\n * Schedules the DEBOUNCED state-of-record save for a channel: each request replaces the\n * pending payload (latest state wins) and re-arms the timer; the session id is captured\n * while live so the teardown flush can persist onto the just-closed session.\n */\n private scheduleChannelSave(channelName: string, stateJson: string): void {\n const pending = this.pendingChannelSaves.get(channelName);\n if (pending) {\n clearTimeout(pending.Timer);\n }\n this.pendingChannelSaves.set(channelName, {\n Timer: setTimeout(() => this.flushChannelSave(channelName), RealtimeSessionService.ChannelSaveDebounceMs),\n StateJson: stateJson,\n SessionID: this.agentSessionId ?? pending?.SessionID ?? null\n });\n }\n\n /** Fires one pending channel save (best-effort; {@link SaveChannelState} logs failures). */\n private flushChannelSave(channelName: string): void {\n const pending = this.pendingChannelSaves.get(channelName);\n if (!pending) {\n return;\n }\n this.pendingChannelSaves.delete(channelName);\n clearTimeout(pending.Timer);\n void this.SaveChannelState(channelName, pending.StateJson, pending.SessionID);\n }\n\n /** Final teardown flush: persist every channel's unsaved state immediately. */\n private flushAllChannelSaves(): void {\n for (const channelName of [...this.pendingChannelSaves.keys()]) {\n this.flushChannelSave(channelName);\n }\n }\n\n /** Disposes all channel plugins (errors contained per plugin) and clears the live set. */\n private disposeChannels(): void {\n for (const plugin of this._activeChannels$.value) {\n try {\n plugin.Dispose();\n } catch (error) {\n console.error(`[RealtimeSession] Channel '${plugin.ChannelName}' Dispose failed:`, error);\n }\n }\n if (this._activeChannels$.value.length > 0) {\n this._activeChannels$.next([]);\n }\n }\n\n // ── Realtime client resolution + wiring ────────────────────────────────────\n\n /**\n * Resolves the provider-direct realtime client for `provider` through the MJ\n * ClassFactory — the client-side mirror of how server drivers are resolved from\n * `BaseRealtimeModel`. Throws a clear error when no driver is registered for the\n * provider (e.g. its Load function was never called).\n */\n private createRealtimeClient(provider: string): BaseRealtimeClient {\n const registration = MJGlobal.Instance.ClassFactory.GetRegistration(BaseRealtimeClient, provider);\n if (!registration) {\n throw new Error(\n `No realtime client registered for provider '${provider}'. ` +\n `Ensure the provider's client driver package is imported and its Load function called.`\n );\n }\n const client = MJGlobal.Instance.ClassFactory.CreateInstance<BaseRealtimeClient>(BaseRealtimeClient, provider);\n if (!client) {\n throw new Error(`Failed to instantiate the realtime client for provider '${provider}'`);\n }\n return client;\n }\n\n /** Builds the client-direct session config the realtime client connects with. */\n private buildClientConfig(session: StartRealtimeClientSessionResult): ClientRealtimeSessionConfig {\n return {\n Provider: session.Provider,\n Model: session.Model,\n EphemeralToken: session.EphemeralToken,\n ExpiresAt: session.ExpiresAt,\n SessionConfig: this.parseSessionConfig(session.SessionConfigJson)\n };\n }\n\n /**\n * Parses the server-built session config JSON. On failure, logs and returns an empty\n * object — the client treats an empty config as \"nothing to apply\", so the session\n * still opens (mirroring the prior behavior of skipping the config update).\n */\n private parseSessionConfig(sessionConfigJson: string | null): JSONObject {\n if (!sessionConfigJson) {\n return {};\n }\n try {\n return JSON.parse(sessionConfigJson) as JSONObject;\n } catch (error) {\n console.error('[RealtimeSession] Failed to parse/apply SessionConfigJson:', error);\n return {};\n }\n }\n\n /** Subscribes this service's policy handlers to the realtime client's events. */\n private wireClientHandlers(client: BaseRealtimeClient): void {\n client.OnStateChange((state: RealtimeClientState) => this.onClientStateChange(state));\n client.OnTranscript((transcript: RealtimeClientTranscript) => {\n void this.onClientTranscript(transcript);\n });\n client.OnToolCall((call: RealtimeClientToolCall) => {\n void this.handleToolCall(call);\n });\n client.OnError((error: RealtimeClientError) => {\n console.error('[RealtimeSession] Provider error event:', error);\n });\n // Usage telemetry: accumulate the driver's per-response token DELTAS and relay them to\n // the server (onto the co-agent AIPromptRun) debounced + once at teardown. Providers\n // without usage events simply never emit — registering is always safe.\n client.OnUsage((usage: RealtimeClientUsage) => this.onUsageDelta(usage));\n // TRUE BARGE-IN (user input cut off active model output — the driver already stopped\n // the speech): the user took the floor, so any pending/queued progress narration is\n // stale — cancel it; the next progress event re-schedules at the session-global pace.\n // HOST POLICY (deliberate): barge-in does NOT abort in-flight delegated runs — the\n // narration design EXPECTS the user to keep talking while delegated work runs, so\n // killing the work on speech would cancel exactly the jobs the user asked for.\n // Explicit cancellation is a separate, intentional act: the overlay's per-card ✕\n // calls {@link CancelDelegation} (server cancel channel) instead.\n client.OnInterruption(() => {\n this.cancelPendingNarration();\n });\n }\n\n /** Maps a client state event onto the UI connection state. */\n private onClientStateChange(state: RealtimeClientState): void {\n const mapped = this.mapClientState(state);\n if (mapped) {\n this._connectionState$.next(mapped);\n }\n }\n\n /**\n * Translates {@link RealtimeClientState} into {@link VoiceConnectionState}. `'connected'`\n * is suppressed (the UI stays 'connecting' until the control channel opens → 'listening'),\n * and `'closed'` never overwrites a terminal 'error' the service itself recorded.\n */\n private mapClientState(state: RealtimeClientState): VoiceConnectionState | null {\n switch (state) {\n case 'connecting':\n return 'connecting';\n case 'connected':\n return null;\n case 'listening':\n return 'listening';\n case 'speaking':\n return 'speaking';\n case 'error':\n return 'error';\n case 'closed':\n return this._connectionState$.value === 'error' ? null : 'closed';\n }\n }\n\n /** True when the live control channel is usable (open and not torn down / failed). */\n private isSessionLive(): boolean {\n const state = this._connectionState$.value;\n return state === 'listening' || state === 'speaking' || state === 'thinking';\n }\n\n // ── Transcript policy ──────────────────────────────────────────────────────\n\n /**\n * Applies transcript policy to client transcript events. Interim deltas are ignored\n * (the client already drives the speaking state). Final NORMAL assistant turns become\n * captions + persisted transcripts; final NARRATION turns are EPHEMERAL by product\n * decision — emitted on {@link DelegationNarration$} only, never a caption, never\n * relayed/persisted. User turns ride the caption + relay path.\n */\n private async onClientTranscript(transcript: RealtimeClientTranscript): Promise<void> {\n if (!transcript.IsFinal) {\n return;\n }\n if (transcript.Role === 'Assistant') {\n if (transcript.Kind === 'narration') {\n this._delegationNarration$.next({ Text: transcript.Text });\n // Remember what was actually SAID so later updates build on it instead of repeating.\n this.spokenNarrations.push(transcript.Text);\n if (this.spokenNarrations.length > RealtimeSessionService.MaxPriorNarrations) {\n this.spokenNarrations.shift();\n }\n } else if (transcript.ReplacesPrevious) {\n // CORRECTION (e.g. ElevenLabs post-barge-in re-finalization): this final\n // SUPERSEDES the previous final assistant turn — replace the caption in place\n // and tell the server to update the persisted turn instead of appending.\n this.replaceLastCaption('Assistant', transcript.Text);\n await this.relayTranscript('assistant', transcript.Text, true);\n } else {\n this.appendCaption({ Role: 'Assistant', Text: transcript.Text });\n await this.relayTranscript('assistant', transcript.Text);\n }\n } else if (transcript.ReplacesPrevious) {\n // STREAMING user transcription: providers like Grok emit the growing utterance as repeated\n // events (each the full text so far), flagging all but the first ReplacesPrevious. Update the\n // in-place User caption + persisted turn instead of stacking a new bubble per increment — the\n // same correction semantics the assistant branch uses. (OpenAI sends one final → the else path.)\n this.replaceLastCaption('User', transcript.Text);\n await this.relayTranscript('user', transcript.Text, true);\n } else {\n await this.onUserTranscript(transcript.Text);\n }\n }\n\n /**\n * Replaces the LAST caption of `role` in place (correction semantics); falls back to a\n * plain append when no such caption exists yet (e.g. the superseded turn predates this\n * client's caption window).\n */\n private replaceLastCaption(role: 'User' | 'Assistant', text: string): void {\n const captions = this._captions$.value;\n for (let i = captions.length - 1; i >= 0; i--) {\n if (captions[i].Role === role) {\n const next = [...captions];\n next[i] = { Role: role, Text: text };\n this._captions$.next(next);\n return;\n }\n }\n this.appendCaption({ Role: role, Text: text });\n }\n\n /** Finalizes the user turn: push a caption + relay the final transcript. */\n private async onUserTranscript(transcript: string): Promise<void> {\n if (transcript.trim().length === 0) {\n return;\n }\n if (this.firstUserTranscript === null) {\n // First spoken user utterance — the naming seed for a session-created conversation.\n this.firstUserTranscript = transcript;\n }\n this.appendCaption({ Role: 'User', Text: transcript });\n await this.relayTranscript('user', transcript);\n }\n\n // ── Tool calling ───────────────────────────────────────────────────────────\n\n /**\n * Routes a provider tool call: names matching a registered client-tool prefix execute\n * LOCALLY (UI tools — see {@link RegisterClientToolHandler}); everything else executes on\n * the MJ server. Either way the result feeds back to the model via\n * {@link BaseRealtimeClient.SendToolResult} so it speaks the outcome.\n */\n private async handleToolCall(call: RealtimeClientToolCall): Promise<void> {\n const clientHandler = this.findClientToolHandler(call.ToolName);\n if (clientHandler) {\n // Local UI tool: no server relay, no 'thinking' turn-state / narration burst — these\n // are fast, in-browser surface mutations (e.g. drawing on the whiteboard).\n const resultJson = await this.executeClientTool(clientHandler, call);\n this.client?.SendToolResult(call.CallID, resultJson);\n // Observability: record the channel tool call on the co-agent's run (run-only — NOT a chat\n // turn). Without this the run shows speech but never the browser_/Whiteboard_ actions the\n // co-agent took. Fire-and-forget; never disturbs the live surface mutation.\n void this.relayToolTurn(call.ToolName, call.ArgumentsJson, resultJson);\n return;\n }\n this._connectionState$.next('thinking');\n if (this.inFlightCallIds.size === 0) {\n // A fresh delegation burst: anchor the first-update delay and clear the digest\n // buffer. Deliberately NOT reset: lastDelegationNarrationAt (the 8s spacing floor\n // is SESSION-global — sequential tool calls seconds apart must not re-arm the\n // faster first-update path, which read as \"no debounce\") and spokenNarrations\n // (so the story never repeats across closely-spaced calls).\n this.delegationBurstStartedAt = Date.now();\n this.narrationCount = 0;\n this.pendingNarrationMessages = [];\n this.lastNarratedTail = '';\n }\n this.inFlightCallIds.add(call.CallID);\n try {\n const resultJson = await this.executeSessionTool(call.CallID, call.ToolName, call.ArgumentsJson);\n this.emitDelegationResult(call.CallID, resultJson);\n this.client?.SendToolResult(call.CallID, resultJson);\n } catch (error) {\n console.error('[RealtimeSession] Tool execution failed:', error);\n // Feed the error back so the model can narrate it rather than going silent.\n // success:false matters: ParseDelegationResultJson treats anything else as\n // success, which would flip the overlay's working card to a SUCCESS card\n // carrying the error text (matches the server broker's failure shape).\n const errorJson = JSON.stringify({\n success: false,\n error: error instanceof Error ? error.message : String(error)\n });\n this.emitDelegationResult(call.CallID, errorJson);\n this.client?.SendToolResult(call.CallID, errorJson);\n }\n }\n\n /** Finds the registered client-tool handler whose prefix matches `toolName`, or `null`. */\n private findClientToolHandler(toolName: string): RealtimeClientToolHandler | null {\n for (const [prefix, handler] of this.clientToolHandlers) {\n if (toolName.startsWith(prefix)) {\n return handler;\n }\n }\n return null;\n }\n\n /**\n * Executes one client-tool call through its handler, wrapping any thrown error into a\n * `{ success: false, error }` JSON payload so the model can narrate the failure instead of\n * the call going silent.\n */\n private async executeClientTool(handler: RealtimeClientToolHandler, call: RealtimeClientToolCall): Promise<string> {\n try {\n return await handler(call.ToolName, call.ArgumentsJson);\n } catch (error) {\n console.error('[RealtimeSession] Client tool execution failed:', error);\n return JSON.stringify({\n success: false,\n error: error instanceof Error ? error.message : String(error)\n });\n }\n }\n\n /**\n * Emits a delegation result so the overlay's \"working\" card flips to a result card with real\n * content. Parses the broker's `{success, output, runId}` | `{success:false, error}` shape via\n * {@link ParseDelegationResultJson}; if it isn't JSON, surfaces the raw string. Only delegation\n * cards (created from progress events) react — non-delegation tool results have no card and are\n * harmlessly ignored downstream. The `runId` (the delegated `MJ: AI Agent Runs` record) rides\n * along as {@link VoiceDelegationResult.RunID} for the overlay's dev links, and any `artifacts`\n * ride along as {@link VoiceDelegationResult.Artifacts} for the surface panel's artifact tabs.\n */\n private emitDelegationResult(callId: string, resultJson: string): void {\n // The result will be spoken next — a deferred interim update is now pointless\n // (this is what keeps fast agents like Sage from narrating over their own answer),\n // and any progress still in the PubSub pipe for this call is stale.\n this.inFlightCallIds.delete(callId);\n this.cancelPendingNarration();\n if (this.cancelledCallIds.delete(callId)) {\n // The user explicitly cancelled this call: its card already flipped to the\n // \"Cancelled by user\" failed result, so the aborted run's late outcome must not\n // overwrite it. (The tool result still flows back to the model via the caller.)\n return;\n }\n const parsed = ParseDelegationResultJson(resultJson);\n this._delegationResult$.next({\n CallID: callId,\n Success: parsed.Success,\n Output: parsed.Output,\n RunID: parsed.RunID,\n Artifacts: parsed.Artifacts\n });\n }\n\n // ── Explicit delegation cancellation (server cancel channel) ───────────────\n\n /**\n * Cancels ONE in-flight delegated tool call — the overlay's per-card ✕ affordance.\n *\n * EXPLICIT USER INTENT ONLY (deliberate host policy): true barge-in never aborts\n * delegations — the narration design expects the user to talk while delegated work runs.\n * Calls the `CancelRealtimeSessionTool` mutation (ownership-gated server-side); when the\n * server reports it aborted the run, the card is flipped immediately to a FAILED\n * \"Cancelled by user\" result and the eventual late result from the aborted run is\n * suppressed (see {@link emitDelegationResult}).\n *\n * @returns `true` when the server aborted the in-flight run; `false` when there was\n * nothing to cancel (the work finished first — its real result is already racing in)\n * or the mutation failed (logged, never thrown).\n */\n public async CancelDelegation(callId: string): Promise<boolean> {\n if (!this.agentSessionId || !this.inFlightCallIds.has(callId)) {\n return false;\n }\n const aborted = await this.cancelSessionTool(callId);\n if (aborted <= 0) {\n return false; // finished first / nothing in flight server-side — let the real result land\n }\n this.surfaceUserCancellation(callId);\n return true;\n }\n\n /**\n * Cancels EVERY in-flight delegated tool call for the active session (callId-less form of\n * the `CancelRealtimeSessionTool` mutation). Exposed for host policies that need a\n * sweep-cancel (e.g. an explicit \"stop everything\" affordance) — NOT wired to barge-in,\n * by the same deliberate policy as {@link CancelDelegation}.\n *\n * @returns The number of in-flight runs the server aborted (0 when nothing was tracked\n * in flight client-side, nothing was in flight server-side, or the mutation failed).\n */\n public async CancelInFlightDelegations(): Promise<number> {\n if (!this.agentSessionId || this.inFlightCallIds.size === 0) {\n return 0;\n }\n const aborted = await this.cancelSessionTool(null);\n if (aborted <= 0) {\n return 0;\n }\n for (const callId of [...this.inFlightCallIds]) {\n this.surfaceUserCancellation(callId);\n }\n return aborted;\n }\n\n /** Flips a cancelled call's card to the failed \"Cancelled by user\" result and suppresses the late real result. */\n private surfaceUserCancellation(callId: string): void {\n this.inFlightCallIds.delete(callId);\n this.cancelledCallIds.add(callId);\n this.cancelPendingNarration();\n this._delegationResult$.next({\n CallID: callId,\n Success: false,\n Output: 'Cancelled by user'\n });\n }\n\n /**\n * Calls the `CancelRealtimeSessionTool` mutation and unwraps its structured\n * `{ AbortedCount, Success, ErrorMessage }` result. Returns the aborted count —\n * 0 on a structured failure or a thrown transport error (both logged, never thrown).\n */\n private async cancelSessionTool(callId: string | null): Promise<number> {\n try {\n const mutation = `\n mutation CancelRealtimeSessionTool($agentSessionId: String!, $callId: String) {\n CancelRealtimeSessionTool(agentSessionId: $agentSessionId, callId: $callId) {\n AbortedCount\n Success\n ErrorMessage\n }\n }\n `;\n const result = await this.gql().ExecuteGQL(mutation, { agentSessionId: this.agentSessionId, callId });\n const payload = result?.CancelRealtimeSessionTool as\n | { AbortedCount?: number; Success?: boolean; ErrorMessage?: string }\n | undefined;\n if (!payload?.Success) {\n console.warn(`[RealtimeSession] Cancel reported failure: ${payload?.ErrorMessage ?? 'unknown error'}`);\n return 0;\n }\n return typeof payload.AbortedCount === 'number' ? payload.AbortedCount : 0;\n } catch (error) {\n console.error('[RealtimeSession] Failed to cancel in-flight delegation(s):', error);\n return 0;\n }\n }\n\n // ── Session minting (GraphQL) ──────────────────────────────────────────────\n\n /** Calls the `StartRealtimeClientSession` mutation to obtain an ephemeral token + config. */\n private async mintSession(\n targetAgentId: string,\n conversationId?: string | null,\n lastSessionId?: string | null,\n preferredModelId?: string | null,\n clientTools?: RealtimeToolDefinition[] | null,\n coAgentId?: string | null,\n configOverridesJson?: string | null\n ): Promise<StartRealtimeClientSessionResult> {\n const mutation = `\n mutation StartRealtimeClientSession($targetAgentId: String!, $conversationId: String, $lastSessionId: String, $preferredModelId: String, $clientToolsJson: String, $coAgentId: String, $configOverridesJson: String) {\n StartRealtimeClientSession(targetAgentId: $targetAgentId, conversationId: $conversationId, lastSessionId: $lastSessionId, preferredModelId: $preferredModelId, clientToolsJson: $clientToolsJson, coAgentId: $coAgentId, configOverridesJson: $configOverridesJson) {\n AgentSessionId\n ConversationId\n Provider\n Model\n EphemeralToken\n ExpiresAt\n SessionConfigJson\n ModelName\n NarrationInstructionsTemplate\n PriorChannelStatesJson\n }\n }\n `;\n const variables = {\n targetAgentId,\n conversationId: conversationId ?? null,\n lastSessionId: lastSessionId ?? null,\n preferredModelId: preferredModelId ?? null,\n clientToolsJson: clientTools && clientTools.length > 0 ? JSON.stringify(clientTools) : null,\n coAgentId: coAgentId ?? null,\n configOverridesJson: configOverridesJson ?? null\n };\n const result = await this.gql().ExecuteGQL(mutation, variables);\n const payload = result?.StartRealtimeClientSession as StartRealtimeClientSessionResult | undefined;\n if (!payload?.EphemeralToken) {\n throw new Error('StartRealtimeClientSession returned no ephemeral token');\n }\n return payload;\n }\n\n /** Calls the `ExecuteRealtimeSessionTool` mutation; returns the ResultJson string. */\n private async executeSessionTool(callId: string, toolName: string, argsJson: string): Promise<string> {\n if (!this.agentSessionId) {\n throw new Error('No active agent session for tool execution');\n }\n const mutation = `\n mutation ExecuteRealtimeSessionTool($agentSessionId: String!, $callId: String!, $toolName: String!, $argsJson: String!) {\n ExecuteRealtimeSessionTool(agentSessionId: $agentSessionId, callId: $callId, toolName: $toolName, argsJson: $argsJson)\n }\n `;\n const result = await this.gql().ExecuteGQL(mutation, {\n agentSessionId: this.agentSessionId,\n callId,\n toolName,\n argsJson\n });\n return (result?.ExecuteRealtimeSessionTool as string) ?? '{}';\n }\n\n /**\n * Persists an interactive channel's state of record (e.g. the whiteboard's serialized scene)\n * onto the session's `MJ: AI Agent Session Channels` row via `SaveSessionChannelState`.\n *\n * @param channelName The channel definition name (e.g. `'Whiteboard'`).\n * @param stateJson The serialized channel state.\n * @param agentSessionId Optional EXPLICIT session id. The debounced channel-save pipeline\n * captures the id while the session is live and passes it here, so the final teardown\n * flush still lands on the just-closed session. Falls back to the active session's id;\n * returns `false` when neither is available.\n * @returns Whether the server persisted the state. Failures are logged, never thrown — channel\n * persistence is best-effort and must not disturb the live call.\n */\n public async SaveChannelState(channelName: string, stateJson: string, agentSessionId?: string | null): Promise<boolean> {\n const sessionId = agentSessionId ?? this.agentSessionId;\n if (!sessionId) {\n return false;\n }\n try {\n const mutation = `\n mutation SaveSessionChannelState($agentSessionId: String!, $channelName: String!, $stateJson: String!) {\n SaveSessionChannelState(agentSessionId: $agentSessionId, channelName: $channelName, stateJson: $stateJson)\n }\n `;\n const result = await this.gql().ExecuteGQL(mutation, { agentSessionId: sessionId, channelName, stateJson });\n return (result?.SaveSessionChannelState as boolean) ?? false;\n } catch (error) {\n console.error('[RealtimeSession] Failed to save channel state:', error);\n return false;\n }\n }\n\n // ── Transcript relay (GraphQL) ─────────────────────────────────────────────\n\n /**\n * Relays a final transcript turn to MJ via `RelayRealtimeTranscript`.\n * @param replacesPrevious CORRECTION semantics: the server updates the session's most\n * recent persisted turn of this role IN PLACE instead of appending (e.g. ElevenLabs'\n * post-barge-in `agent_response_correction`).\n */\n private async relayTranscript(role: 'user' | 'assistant', text: string, replacesPrevious: boolean = false): Promise<void> {\n if (!this.agentSessionId) {\n return;\n }\n try {\n const mutation = `\n mutation RelayRealtimeTranscript($agentSessionId: String!, $role: String!, $text: String!, $replacesPrevious: Boolean) {\n RelayRealtimeTranscript(agentSessionId: $agentSessionId, role: $role, text: $text, replacesPrevious: $replacesPrevious)\n }\n `;\n await this.gql().ExecuteGQL(mutation, {\n agentSessionId: this.agentSessionId,\n role,\n text,\n replacesPrevious\n });\n } catch (error) {\n console.error('[RealtimeSession] Failed to relay transcript:', error);\n }\n }\n\n /**\n * Relays a co-agent CHANNEL tool-call turn (browser_ / Whiteboard_ etc.) to the session's run for\n * observability via `RelayRealtimeToolTurn` — so the co-agent's AIPromptRun shows what it DID, not\n * just what it said. Run-only by design: deliberately NOT a `ConversationDetail` turn, so the chat\n * thread stays speech-only. Best-effort — a failed relay never disturbs the live call.\n */\n private async relayToolTurn(toolName: string, argsJson: string, resultJson: string): Promise<void> {\n if (!this.agentSessionId) {\n return;\n }\n try {\n const mutation = `\n mutation RelayRealtimeToolTurn($agentSessionId: String!, $toolName: String!, $argsJson: String, $resultJson: String) {\n RelayRealtimeToolTurn(agentSessionId: $agentSessionId, toolName: $toolName, argsJson: $argsJson, resultJson: $resultJson)\n }\n `;\n await this.gql().ExecuteGQL(mutation, {\n agentSessionId: this.agentSessionId,\n toolName,\n argsJson,\n resultJson\n });\n } catch (error) {\n console.error('[RealtimeSession] Failed to relay tool turn:', error);\n }\n }\n\n // ── Usage telemetry relay (B7) ─────────────────────────────────────────────\n\n /**\n * Accumulates one usage DELTA from the realtime client (per-response token counts —\n * the `OnUsage` contract shape) and schedules the debounced relay. Negative / non-finite\n * values are clamped to 0; an all-zero delta is dropped without arming the timer.\n */\n private onUsageDelta(usage: RealtimeClientUsage): void {\n const input = this.clampUsageDelta(usage.InputTokens);\n const output = this.clampUsageDelta(usage.OutputTokens);\n if (input === 0 && output === 0) {\n return;\n }\n this.pendingUsageInput += input;\n this.pendingUsageOutput += output;\n if (!this.usageFlushTimer) {\n this.usageFlushTimer = setTimeout(() => {\n this.usageFlushTimer = null;\n void this.flushPendingUsage();\n }, RealtimeSessionService.UsageFlushDebounceMs);\n }\n }\n\n /** Clamps a driver-reported token delta: undefined / negative / non-finite become 0. */\n private clampUsageDelta(value: number | undefined): number {\n return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;\n }\n\n /**\n * Relays the accumulated usage deltas to the server via `RelayRealtimeUsage` (which\n * accumulates them onto the co-agent `AIPromptRun`). Best-effort: a failed relay\n * re-accumulates the captured deltas so the next debounce / teardown flush retries —\n * usage telemetry must never disturb the live call.\n *\n * @param agentSessionId Optional EXPLICIT session id (the teardown flush runs while the\n * live id is still set, but accepts it as a parameter for symmetry with channel saves).\n */\n private async flushPendingUsage(agentSessionId?: string | null): Promise<void> {\n const sessionId = agentSessionId ?? this.agentSessionId;\n const input = this.pendingUsageInput;\n const output = this.pendingUsageOutput;\n if (!sessionId || (input === 0 && output === 0)) {\n return;\n }\n this.pendingUsageInput = 0;\n this.pendingUsageOutput = 0;\n try {\n const mutation = `\n mutation RelayRealtimeUsage($agentSessionId: String!, $inputTokens: Int!, $outputTokens: Int!) {\n RelayRealtimeUsage(agentSessionId: $agentSessionId, inputTokens: $inputTokens, outputTokens: $outputTokens)\n }\n `;\n await this.gql().ExecuteGQL(mutation, { agentSessionId: sessionId, inputTokens: input, outputTokens: output });\n } catch (error) {\n console.error('[RealtimeSession] Failed to relay usage telemetry:', error);\n // Re-accumulate so a later debounce / the teardown flush retries the same deltas.\n this.pendingUsageInput += input;\n this.pendingUsageOutput += output;\n }\n }\n\n /** Cancels the pending debounced usage flush and zeroes the accumulators (teardown tail). */\n private resetUsageRelay(): void {\n if (this.usageFlushTimer) {\n clearTimeout(this.usageFlushTimer);\n this.usageFlushTimer = null;\n }\n this.pendingUsageInput = 0;\n this.pendingUsageOutput = 0;\n }\n\n // ── Delegated-run progress streaming ───────────────────────────────────────\n\n /**\n * Subscribes to the server's push-status topic (scoped by the GraphQL transport\n * sessionId) to receive delegated-run progress for the active voice session.\n * Each matching event is surfaced on {@link DelegationProgress$} and narrated.\n */\n private subscribeDelegationProgress(): void {\n if (this.delegationProgressSub) {\n return; // already subscribed for this session\n }\n const transportSessionId = this.gql().sessionId;\n this.lastDelegationNarrationAt = 0;\n this.delegationProgressSub = this.gql()\n .PushStatusUpdates(transportSessionId)\n .subscribe({\n next: (raw: string) => this.onDelegationStatusMessage(raw),\n error: (err: unknown) => console.error('[RealtimeSession] Delegation progress stream error:', err)\n });\n }\n\n /**\n * Parses one push-status message and routes it: a Remote Browser screencast frame goes to the active\n * Remote Browser channel's canvas; a delegation-progress event is dispatched + narrated. Other shapes\n * (normal agent-run streams) are ignored. Screencast frames are checked FIRST and short-circuit, so the\n * delegation path is untouched.\n */\n private onDelegationStatusMessage(raw: string): void {\n const frame = this.parseScreencastFrame(raw);\n if (frame) {\n this.routeScreencastFrame(frame);\n return;\n }\n const audio = this.parseAudioChunk(raw);\n if (audio) {\n this.routeAudioChunk(audio);\n return;\n }\n const progress = this.parseProgress(raw);\n if (progress) {\n this.dispatchProgress(progress);\n }\n }\n\n /**\n * Parses a push-status message and returns it only when it's a Remote Browser screencast frame for the\n * active session — otherwise `null` (ignored, so delegation progress falls through). Matched by\n * `resolver` + `type`, then scoped to THIS session by `agentSessionID`.\n */\n private parseScreencastFrame(raw: string): RemoteBrowserScreencastPayload | null {\n let payload: { resolver?: string } & Partial<RemoteBrowserScreencastPayload>;\n try {\n payload = JSON.parse(raw);\n } catch {\n return null;\n }\n const matches =\n payload?.resolver === 'RemoteBrowserActionResolver' &&\n payload?.type === 'RemoteBrowserScreencastFrame' &&\n payload?.agentSessionID === this.agentSessionId &&\n typeof payload?.dataBase64 === 'string';\n return matches ? (payload as RemoteBrowserScreencastPayload) : null;\n }\n\n /**\n * Forwards a screencast frame to the active Remote Browser channel plugin so it paints the frame on its\n * surface canvas. The plugin is found among the session's active channels by its `ChannelName`; located\n * via a structural guard so the service stays decoupled from the concrete channel class.\n */\n private routeScreencastFrame(frame: RemoteBrowserScreencastPayload): void {\n for (const channel of this._activeChannels$.value) {\n if (channel.ChannelName === 'Remote Browser' && this.hasOnScreencastFrame(channel)) {\n channel.OnScreencastFrame(frame.dataBase64);\n return;\n }\n }\n }\n\n /** Structural guard: true when the channel exposes an `OnScreencastFrame(dataBase64)` method. */\n private hasOnScreencastFrame(\n channel: BaseRealtimeChannelClient,\n ): channel is BaseRealtimeChannelClient & { OnScreencastFrame(dataBase64: string): void } {\n return typeof (channel as { OnScreencastFrame?: unknown }).OnScreencastFrame === 'function';\n }\n\n /**\n * Parses a push-status message and returns it only when it's a Remote Browser audio chunk for the active\n * session — otherwise `null` (ignored). Matched by `resolver` + `type`, then scoped to THIS session by\n * `agentSessionID`.\n */\n private parseAudioChunk(raw: string): RemoteBrowserAudioChunkPayload | null {\n let payload: { resolver?: string } & Partial<RemoteBrowserAudioChunkPayload>;\n try {\n payload = JSON.parse(raw);\n } catch {\n return null;\n }\n const matches =\n payload?.resolver === 'RemoteBrowserActionResolver' &&\n payload?.type === 'RemoteBrowserAudioChunk' &&\n payload?.agentSessionID === this.agentSessionId &&\n typeof payload?.dataBase64 === 'string';\n return matches ? (payload as RemoteBrowserAudioChunkPayload) : null;\n }\n\n /**\n * Forwards an audio chunk to the active Remote Browser channel plugin so it plays the chunk through its\n * client-side audio player. The plugin is found among the session's active channels by its `ChannelName`;\n * located via a structural guard so the service stays decoupled from the concrete channel class.\n */\n private routeAudioChunk(chunk: RemoteBrowserAudioChunkPayload): void {\n for (const channel of this._activeChannels$.value) {\n if (channel.ChannelName === 'Remote Browser' && this.hasOnAudioChunk(channel)) {\n channel.OnAudioChunk({\n dataBase64: chunk.dataBase64,\n codec: chunk.codec,\n sampleRate: chunk.sampleRate,\n channels: chunk.channels,\n seq: chunk.seq,\n });\n return;\n }\n }\n }\n\n /** Structural guard: true when the channel exposes an `OnAudioChunk(chunk)` method. */\n private hasOnAudioChunk(\n channel: BaseRealtimeChannelClient,\n ): channel is BaseRealtimeChannelClient & { OnAudioChunk(chunk: { dataBase64: string; codec: string; sampleRate: number; channels: number; seq: number }): void } {\n return typeof (channel as { OnAudioChunk?: unknown }).OnAudioChunk === 'function';\n }\n\n /**\n * Parses a push-status message and returns it only when it's a delegation\n * progress event for the active voice session — otherwise `null` (ignored).\n */\n private parseProgress(raw: string): VoiceDelegationProgress | null {\n let payload: RealtimeDelegationProgressPayload;\n try {\n payload = JSON.parse(raw) as RealtimeDelegationProgressPayload;\n } catch {\n return null; // non-JSON or unrelated frame\n }\n const matches =\n payload?.resolver === 'RealtimeClientSessionResolver' &&\n payload?.type === 'RealtimeDelegationProgress' &&\n payload?.agentSessionID === this.agentSessionId;\n if (!matches) {\n return null;\n }\n return {\n CallID: payload.callID,\n Step: payload.step,\n Message: payload.message,\n Percentage: payload.percentage\n };\n }\n\n /** Emits the progress to the UI observable and feeds it to the realtime model. */\n private dispatchProgress(progress: VoiceDelegationProgress): void {\n // Drop stale progress: PubSub delivery can lag the mutation result, so events for a\n // call that already completed (or was never seen) must not update cards or narrate.\n if (!this.inFlightCallIds.has(progress.CallID)) {\n return;\n }\n this._delegationProgress$.next(progress);\n this.narrateProgress(progress);\n }\n\n /**\n * Injects the progress into the model's context as a background note every time,\n * then (throttled) asks the model to briefly voice a reassuring update so the\n * background work doesn't sit in silence — without chattering or interrupting.\n */\n private narrateProgress(progress: VoiceDelegationProgress): void {\n const client = this.client;\n if (!client) {\n return;\n }\n client.SendContextNote(`[delegated-agent progress] ${progress.Message}`);\n // Floods of small updates AGGREGATE: each distinct message joins the digest buffer,\n // and ONE spoken update fires per window (first at ~5s into the burst, then every\n // ~8s). The buffer is discarded if the final result lands first.\n this.bufferNarrationMessage(progress.Message);\n if (this.pendingNarrationMessages.length > 0 && !this.narrationTimer) {\n this.narrationTimer = setTimeout(() => this.fireDeferredNarration(), this.nextNarrationDelayMs());\n }\n }\n\n /** Adds a progress message to the digest buffer (deduped, capped, oldest-first). */\n private bufferNarrationMessage(message: string): void {\n if (message === this.lastNarratedTail || this.pendingNarrationMessages.includes(message)) {\n return;\n }\n this.pendingNarrationMessages.push(message);\n if (this.pendingNarrationMessages.length > RealtimeSessionService.MaxDigestMessages) {\n this.pendingNarrationMessages.shift();\n }\n }\n\n /**\n * ms until the next spoken update is allowed. Two constraints, BOTH enforced:\n * - first update of a burst: no earlier than ~5s after the burst started;\n * - ~8s since the last spoken update, SESSION-global — so sequential tool calls\n * that reset the burst can never narrate faster than the interval.\n */\n private nextNarrationDelayMs(): number {\n const now = Date.now();\n const firstAnchor = this.narrationCount === 0\n ? this.delegationBurstStartedAt + RealtimeSessionService.FirstNarrationDelayMs\n : 0;\n const spacingFloor = this.lastDelegationNarrationAt > 0\n ? this.lastDelegationNarrationAt + RealtimeSessionService.NarrationIntervalMs\n : 0;\n return Math.max(250, Math.max(firstAnchor, spacingFloor) - now);\n }\n\n /**\n * Speaks the aggregated progress digest — unless the work already finished (buffer\n * cancelled) or the model is busy / audio is still playing, in which case it retries\n * shortly with the buffer intact (work is still running, so the update stays relevant).\n */\n private fireDeferredNarration(): void {\n this.narrationTimer = null;\n const client = this.client;\n if (this.pendingNarrationMessages.length === 0 || !client || this.inFlightCallIds.size === 0) {\n this.pendingNarrationMessages = [];\n return;\n }\n if (client.IsBusy || client.IsAudioPlaying) {\n this.narrationTimer = setTimeout(() => this.fireDeferredNarration(), RealtimeSessionService.NarrationBusyRetryMs);\n return;\n }\n const digest = this.pendingNarrationMessages.join(' → ');\n this.lastNarratedTail = this.pendingNarrationMessages[this.pendingNarrationMessages.length - 1];\n this.pendingNarrationMessages = [];\n this.narrationCount++;\n this.lastDelegationNarrationAt = Date.now();\n client.RequestSpokenUpdate(this.buildNarrationInstructions(digest));\n }\n\n /** Cancels any deferred narration — the result is about to be spoken, so it's moot. */\n private cancelPendingNarration(): void {\n if (this.narrationTimer) {\n clearTimeout(this.narrationTimer);\n this.narrationTimer = null;\n }\n this.pendingNarrationMessages = [];\n }\n\n /**\n * Builds the one-off instructions for a short spoken update that conveys THIS specific\n * progress message naturally — strictly first person, since the co-agent owns the work.\n * The wording is DB-driven: the server-resolved `Realtime Co-Agent - Progress Narration`\n * template (substituting `{{ progressMessage }}`) when present, otherwise the built-in\n * fallback so deployments that haven't synced the prompt behave exactly as before.\n * The client tags the resulting turn as narration, keeping it EPHEMERAL — surfaced on\n * {@link DelegationNarration$} instead of becoming a caption / persisted ConversationDetail.\n */\n private buildNarrationInstructions(digest: string): string {\n return BuildNarrationInstructions(this.narrationTemplate, digest, {\n PriorNarrations: this.spokenNarrations.slice(-RealtimeSessionService.MaxPriorNarrations),\n UpdateNumber: this.narrationCount\n });\n }\n\n /** Tears down the delegation progress subscription and resets the narration throttle. */\n private teardownDelegationProgress(): void {\n if (this.delegationProgressSub) {\n this.delegationProgressSub.unsubscribe();\n this.delegationProgressSub = null;\n }\n this.cancelPendingNarration();\n this.inFlightCallIds.clear();\n this.cancelledCallIds.clear();\n this.lastDelegationNarrationAt = 0;\n this.delegationBurstStartedAt = 0;\n this.narrationCount = 0;\n this.spokenNarrations = [];\n this.lastNarratedTail = '';\n }\n\n // ── Teardown ───────────────────────────────────────────────────────────────\n\n /**\n * Tears down all client resources and (optionally) closes the server session.\n * @param closeServerSession when true, calls `CloseAgentSession` on the server.\n */\n private async teardown(closeServerSession: boolean): Promise<void> {\n this.teardownDelegationProgress();\n\n // Channels first: flush any unsaved channel state WHILE the live session id is still\n // set (the captured per-save id covers the race anyway), then dispose the plugins.\n this.flushAllChannelSaves();\n this.disposeChannels();\n\n // Defensive: stop the mic even when Connect never ran (the client also stops the\n // tracks it was handed — track.stop() is idempotent).\n this.localStream?.getTracks().forEach(t => t.stop());\n this.localStream = null;\n\n if (this.client) {\n await this.client.Disconnect();\n this.client = null;\n }\n\n // Final usage flush WHILE the live session id is still set (the relay mutation also\n // accepts a Closed session, so ordering vs. CloseAgentSession is belt-and-braces).\n if (this.usageFlushTimer) {\n clearTimeout(this.usageFlushTimer);\n this.usageFlushTimer = null;\n }\n await this.flushPendingUsage(this.agentSessionId);\n this.resetUsageRelay();\n\n if (closeServerSession && this.agentSessionId) {\n await this.closeServerSession(this.agentSessionId);\n }\n\n // Capture the session id BEFORE we null it so the lifecycle emit carries it.\n // Skip emitting when there was no live session (defensive — teardown is safe\n // to call without an active session).\n const closedSessionId = this.agentSessionId;\n this.agentSessionId = null;\n this.narrationTemplate = null;\n this.clientToolHandlers.clear();\n this._modelName$.next(null);\n this.SetMinimized(false);\n this._active$.next(false);\n if (this._connectionState$.value !== 'error') {\n this._connectionState$.next('closed');\n }\n\n // Surface generic session-ended for the conversations runtime bridge.\n // `closeServerSession=true` means the user explicitly called EndVoiceSession;\n // `false` means teardown ran from a catch block (start path error path).\n if (closedSessionId) {\n this._sessionEnded$.next({\n sessionId: closedSessionId,\n reason: closeServerSession ? 'explicit' : 'error',\n });\n }\n }\n\n /** Calls the `CloseAgentSession` mutation (provisioned in P4b). */\n private async closeServerSession(agentSessionId: string): Promise<void> {\n try {\n const mutation = `\n mutation CloseAgentSession($agentSessionId: String!) {\n CloseAgentSession(agentSessionId: $agentSessionId)\n }\n `;\n await this.gql().ExecuteGQL(mutation, { agentSessionId });\n } catch (error) {\n console.error('[RealtimeSession] Failed to close server session:', error);\n }\n }\n\n // ── Helpers ────────────────────────────────────────────────────────────────\n\n /** Pushes a caption onto the live list (immutable update for change detection). */\n private appendCaption(caption: VoiceCaption): void {\n this._captions$.next([...this._captions$.value, caption]);\n }\n\n /** Resets reactive + internal state at the start of a session. */\n private resetState(): void {\n this._captions$.next([]);\n this.SetMinimized(false);\n }\n\n /** The GraphQL provider used for relay mutations. */\n private gql(): GraphQLDataProvider {\n return this.Provider as GraphQLDataProvider;\n }\n}\n"]}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @fileoverview Angular host's bridge from {@link RealtimeSessionService} to
3
+ * `@memberjunction/conversations-runtime`'s framework-agnostic
4
+ * `SessionsObserver`.
5
+ *
6
+ * **Role.** Implements `ISessionsAdapter` (defined in conversations-runtime) by
7
+ * subscribing to the voice service's three lifecycle observables —
8
+ * `SessionStarted$`, `ActiveChannels$` (diffed for channel open/close),
9
+ * `SessionEnded$` — and emitting a single discriminated-union stream the
10
+ * runtime re-broadcasts as `ConversationsRuntime.Instance.Sessions.SessionLifecycle$`.
11
+ *
12
+ * **Why not subscribe to `RealtimeSessionService` from the runtime directly?**
13
+ * The runtime is pure TypeScript and must remain Angular-free so non-Angular
14
+ * consumers (React, Vue, Node workers) can use it. This adapter is the
15
+ * Angular-specific code that bridges Angular DI's voice service into the
16
+ * framework-agnostic adapter contract.
17
+ *
18
+ * **Multi-source-ready.** Today this is a 1:1 bridge for `RealtimeSessionService`.
19
+ * A future Angular host that also has a video-session service would either
20
+ * extend this adapter with `merge(voice.SessionLifecycle$, video.SessionLifecycle$)`
21
+ * or register a sibling adapter — the runtime contract doesn't change.
22
+ *
23
+ * @module @memberjunction/ng-conversations
24
+ */
25
+ import { Observable } from 'rxjs';
26
+ import type { ISessionsAdapter, SessionLifecycleEvent } from '@memberjunction/conversations-runtime';
27
+ import { RealtimeSessionService } from './realtime-session.service';
28
+ /**
29
+ * Bridges `RealtimeSessionService`'s native lifecycle observables to the generic
30
+ * `SessionLifecycleEvent` shape the runtime expects.
31
+ *
32
+ * **Lifecycle.** Construct once at host bootstrap (see
33
+ * `ConversationsRuntimeBootstrap`), pass to
34
+ * `ConversationsRuntime.Instance.UseSessionsAdapter(...)`, and the runtime owns
35
+ * subscription/teardown via `SessionsObserver`. The adapter itself holds the
36
+ * subscriptions to the voice service and exposes them merged into one stream.
37
+ *
38
+ * Call {@link Dispose} when tearing down the host (typically only in tests —
39
+ * production hosts run for the lifetime of the page).
40
+ */
41
+ export declare class RealtimeSessionsAdapter implements ISessionsAdapter {
42
+ private readonly voice;
43
+ readonly SessionLifecycle$: Observable<SessionLifecycleEvent>;
44
+ private readonly _events$;
45
+ private readonly _subs;
46
+ constructor(voice: RealtimeSessionService);
47
+ /**
48
+ * Tear down all subscriptions to the voice service and complete the
49
+ * lifecycle stream. Safe to call multiple times.
50
+ */
51
+ Dispose(): void;
52
+ private wireUp;
53
+ }
54
+ //# sourceMappingURL=realtime-sessions-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime-sessions-adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/services/realtime-sessions-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,UAAU,EAA8C,MAAM,MAAM,CAAC;AAC9E,OAAO,KAAK,EACR,gBAAgB,EAChB,qBAAqB,EACxB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE;;;;;;;;;;;;GAYG;AACH,qBAAa,uBAAwB,YAAW,gBAAgB;IAMhD,OAAO,CAAC,QAAQ,CAAC,KAAK;IALlC,SAAgB,iBAAiB,EAAE,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAErE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;IACjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsB;gBAEf,KAAK,EAAE,sBAAsB;IAK1D;;;OAGG;IACI,OAAO,IAAI,IAAI;IAQtB,OAAO,CAAC,MAAM;CAsGjB"}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * @fileoverview Angular host's bridge from {@link RealtimeSessionService} to
3
+ * `@memberjunction/conversations-runtime`'s framework-agnostic
4
+ * `SessionsObserver`.
5
+ *
6
+ * **Role.** Implements `ISessionsAdapter` (defined in conversations-runtime) by
7
+ * subscribing to the voice service's three lifecycle observables —
8
+ * `SessionStarted$`, `ActiveChannels$` (diffed for channel open/close),
9
+ * `SessionEnded$` — and emitting a single discriminated-union stream the
10
+ * runtime re-broadcasts as `ConversationsRuntime.Instance.Sessions.SessionLifecycle$`.
11
+ *
12
+ * **Why not subscribe to `RealtimeSessionService` from the runtime directly?**
13
+ * The runtime is pure TypeScript and must remain Angular-free so non-Angular
14
+ * consumers (React, Vue, Node workers) can use it. This adapter is the
15
+ * Angular-specific code that bridges Angular DI's voice service into the
16
+ * framework-agnostic adapter contract.
17
+ *
18
+ * **Multi-source-ready.** Today this is a 1:1 bridge for `RealtimeSessionService`.
19
+ * A future Angular host that also has a video-session service would either
20
+ * extend this adapter with `merge(voice.SessionLifecycle$, video.SessionLifecycle$)`
21
+ * or register a sibling adapter — the runtime contract doesn't change.
22
+ *
23
+ * @module @memberjunction/ng-conversations
24
+ */
25
+ import { Subject, pairwise, startWith } from 'rxjs';
26
+ /**
27
+ * Bridges `RealtimeSessionService`'s native lifecycle observables to the generic
28
+ * `SessionLifecycleEvent` shape the runtime expects.
29
+ *
30
+ * **Lifecycle.** Construct once at host bootstrap (see
31
+ * `ConversationsRuntimeBootstrap`), pass to
32
+ * `ConversationsRuntime.Instance.UseSessionsAdapter(...)`, and the runtime owns
33
+ * subscription/teardown via `SessionsObserver`. The adapter itself holds the
34
+ * subscriptions to the voice service and exposes them merged into one stream.
35
+ *
36
+ * Call {@link Dispose} when tearing down the host (typically only in tests —
37
+ * production hosts run for the lifetime of the page).
38
+ */
39
+ export class RealtimeSessionsAdapter {
40
+ voice;
41
+ SessionLifecycle$;
42
+ _events$ = new Subject();
43
+ _subs = [];
44
+ constructor(voice) {
45
+ this.voice = voice;
46
+ this.SessionLifecycle$ = this._events$.asObservable();
47
+ this.wireUp();
48
+ }
49
+ /**
50
+ * Tear down all subscriptions to the voice service and complete the
51
+ * lifecycle stream. Safe to call multiple times.
52
+ */
53
+ Dispose() {
54
+ for (const sub of this._subs) {
55
+ sub.unsubscribe();
56
+ }
57
+ this._subs.length = 0;
58
+ this._events$.complete();
59
+ }
60
+ wireUp() {
61
+ // session-started — bridge RealtimeSessionService.SessionStarted$ verbatim.
62
+ // That service emits ONLY after both agentSessionId is set AND the
63
+ // realtime client is connected, so we don't need any correlation here.
64
+ //
65
+ // We ALSO synthesize session-channel:open events for each initial
66
+ // channel listed in channelNames. Reason: RealtimeSessionService's
67
+ // StartVoiceSession calls startChannels() (which emits to
68
+ // ActiveChannels$) BEFORE mintSession() resolves and sets
69
+ // agentSessionId. By the time our ActiveChannels$ diff handler runs for
70
+ // that first emission, CurrentAgentSessionId is still null and the
71
+ // event is skipped (correctly — we can't attribute it to a session
72
+ // yet). The result without this synthesis would be asymmetric — initial
73
+ // channels never get an open event, even though they get a close event
74
+ // during teardown. Emitting opens from SessionStarted$ closes the gap.
75
+ this._subs.push(this.voice.SessionStarted$.subscribe((started) => {
76
+ this._events$.next({
77
+ kind: 'session-started',
78
+ sessionId: started.sessionId,
79
+ channelKinds: started.channelNames,
80
+ });
81
+ for (const channelName of started.channelNames) {
82
+ this._events$.next({
83
+ kind: 'session-channel',
84
+ sessionId: started.sessionId,
85
+ channelKind: channelName,
86
+ state: 'open',
87
+ });
88
+ }
89
+ }));
90
+ // session-channel (mid-session additions + removals) — diff
91
+ // ActiveChannels$ to surface DYNAMIC channel changes during a live
92
+ // session. The service emits the FULL channel array each time (or []
93
+ // on teardown); we compare consecutive emissions to figure out which
94
+ // channels were added vs removed.
95
+ //
96
+ // INITIAL channel-open events at session start are intentionally NOT
97
+ // produced by this diff path — they're synthesized from SessionStarted$
98
+ // above (see the timing rationale there). Channel CLOSES at teardown
99
+ // DO flow through this path because agentSessionId is still set when
100
+ // disposeChannels() emits [] to ActiveChannels$ (teardown nulls it
101
+ // afterwards).
102
+ //
103
+ // `startWith([])` seeds pairwise so it can emit on the first real value
104
+ // — needed so the initial-emission case still goes through the diff
105
+ // logic (where the null-sessionId guard catches it).
106
+ this._subs.push(this.voice.ActiveChannels$
107
+ .pipe(startWith([]), pairwise())
108
+ .subscribe(([prev, curr]) => {
109
+ const sessionId = this.voice.CurrentAgentSessionId;
110
+ // No active session id means we can't meaningfully attribute the
111
+ // channel event. Two cases land here:
112
+ // 1. Initial emission during startChannels() — sessionId not set yet;
113
+ // initial opens are handled by SessionStarted$ above.
114
+ // 2. The brief post-teardown window after agentSessionId is nulled.
115
+ if (!sessionId) {
116
+ return;
117
+ }
118
+ const prevNames = new Set(prev.map(c => c.ChannelName));
119
+ const currNames = new Set(curr.map(c => c.ChannelName));
120
+ for (const name of currNames) {
121
+ if (!prevNames.has(name)) {
122
+ this._events$.next({
123
+ kind: 'session-channel',
124
+ sessionId,
125
+ channelKind: name,
126
+ state: 'open',
127
+ });
128
+ }
129
+ }
130
+ for (const name of prevNames) {
131
+ if (!currNames.has(name)) {
132
+ this._events$.next({
133
+ kind: 'session-channel',
134
+ sessionId,
135
+ channelKind: name,
136
+ state: 'closed',
137
+ });
138
+ }
139
+ }
140
+ }));
141
+ // session-ended — bridge RealtimeSessionService.SessionEnded$ verbatim
142
+ // (the service narrows the reason union to what's actually
143
+ // distinguishable client-side; the runtime widens to include 'unknown'
144
+ // for adapters that can't tell, which we don't need here).
145
+ this._subs.push(this.voice.SessionEnded$.subscribe((ended) => {
146
+ this._events$.next({
147
+ kind: 'session-ended',
148
+ sessionId: ended.sessionId,
149
+ reason: ended.reason,
150
+ });
151
+ }));
152
+ }
153
+ }
154
+ //# sourceMappingURL=realtime-sessions-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime-sessions-adapter.js","sourceRoot":"","sources":["../../../src/lib/services/realtime-sessions-adapter.ts"],"names":[],"m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vB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;wBACf,IAAI,EAAE,iBAAiB;wBACvB,SAAS;wBACT,WAAW,EAAE,IAAI;wBACjB,KAAK,EAAE,MAAM;qBAChB,CAAC,CAAC;gBACP,CAAC;YACL,CAAC;YACD,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;gBAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;wBACf,IAAI,EAAE,iBAAiB;wBACvB,SAAS;wBACT,WAAW,EAAE,IAAI;wBACjB,KAAK,EAAE,QAAQ;qBAClB,CAAC,CAAC;gBACP,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CACT,CAAC;QAEF,uEAAuE;QACvE,2DAA2D;QAC3D,uEAAuE;QACvE,2DAA2D;QAC3D,IAAI,CAAC,KAAK,CAAC,IAAI,CACX,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YACzC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACf,IAAI,EAAE,eAAe;gBACrB,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;aACvB,CAAC,CAAC;QACP,CAAC,CAAC,CACL,CAAC;IACN,CAAC;CACJ","sourcesContent":["/**\n * @fileoverview Angular host's bridge from {@link RealtimeSessionService} to\n * `@memberjunction/conversations-runtime`'s framework-agnostic\n * `SessionsObserver`.\n *\n * **Role.** Implements `ISessionsAdapter` (defined in conversations-runtime) by\n * subscribing to the voice service's three lifecycle observables —\n * `SessionStarted$`, `ActiveChannels$` (diffed for channel open/close),\n * `SessionEnded$` — and emitting a single discriminated-union stream the\n * runtime re-broadcasts as `ConversationsRuntime.Instance.Sessions.SessionLifecycle$`.\n *\n * **Why not subscribe to `RealtimeSessionService` from the runtime directly?**\n * The runtime is pure TypeScript and must remain Angular-free so non-Angular\n * consumers (React, Vue, Node workers) can use it. This adapter is the\n * Angular-specific code that bridges Angular DI's voice service into the\n * framework-agnostic adapter contract.\n *\n * **Multi-source-ready.** Today this is a 1:1 bridge for `RealtimeSessionService`.\n * A future Angular host that also has a video-session service would either\n * extend this adapter with `merge(voice.SessionLifecycle$, video.SessionLifecycle$)`\n * or register a sibling adapter — the runtime contract doesn't change.\n *\n * @module @memberjunction/ng-conversations\n */\n\nimport { Observable, Subject, Subscription, pairwise, startWith } from 'rxjs';\nimport type {\n ISessionsAdapter,\n SessionLifecycleEvent,\n} from '@memberjunction/conversations-runtime';\nimport { RealtimeSessionService } from './realtime-session.service';\n\n/**\n * Bridges `RealtimeSessionService`'s native lifecycle observables to the generic\n * `SessionLifecycleEvent` shape the runtime expects.\n *\n * **Lifecycle.** Construct once at host bootstrap (see\n * `ConversationsRuntimeBootstrap`), pass to\n * `ConversationsRuntime.Instance.UseSessionsAdapter(...)`, and the runtime owns\n * subscription/teardown via `SessionsObserver`. The adapter itself holds the\n * subscriptions to the voice service and exposes them merged into one stream.\n *\n * Call {@link Dispose} when tearing down the host (typically only in tests —\n * production hosts run for the lifetime of the page).\n */\nexport class RealtimeSessionsAdapter implements ISessionsAdapter {\n public readonly SessionLifecycle$: Observable<SessionLifecycleEvent>;\n\n private readonly _events$ = new Subject<SessionLifecycleEvent>();\n private readonly _subs: Subscription[] = [];\n\n constructor(private readonly voice: RealtimeSessionService) {\n this.SessionLifecycle$ = this._events$.asObservable();\n this.wireUp();\n }\n\n /**\n * Tear down all subscriptions to the voice service and complete the\n * lifecycle stream. Safe to call multiple times.\n */\n public Dispose(): void {\n for (const sub of this._subs) {\n sub.unsubscribe();\n }\n this._subs.length = 0;\n this._events$.complete();\n }\n\n private wireUp(): void {\n // session-started — bridge RealtimeSessionService.SessionStarted$ verbatim.\n // That service emits ONLY after both agentSessionId is set AND the\n // realtime client is connected, so we don't need any correlation here.\n //\n // We ALSO synthesize session-channel:open events for each initial\n // channel listed in channelNames. Reason: RealtimeSessionService's\n // StartVoiceSession calls startChannels() (which emits to\n // ActiveChannels$) BEFORE mintSession() resolves and sets\n // agentSessionId. By the time our ActiveChannels$ diff handler runs for\n // that first emission, CurrentAgentSessionId is still null and the\n // event is skipped (correctly — we can't attribute it to a session\n // yet). The result without this synthesis would be asymmetric — initial\n // channels never get an open event, even though they get a close event\n // during teardown. Emitting opens from SessionStarted$ closes the gap.\n this._subs.push(\n this.voice.SessionStarted$.subscribe((started) => {\n this._events$.next({\n kind: 'session-started',\n sessionId: started.sessionId,\n channelKinds: started.channelNames,\n });\n for (const channelName of started.channelNames) {\n this._events$.next({\n kind: 'session-channel',\n sessionId: started.sessionId,\n channelKind: channelName,\n state: 'open',\n });\n }\n })\n );\n\n // session-channel (mid-session additions + removals) — diff\n // ActiveChannels$ to surface DYNAMIC channel changes during a live\n // session. The service emits the FULL channel array each time (or []\n // on teardown); we compare consecutive emissions to figure out which\n // channels were added vs removed.\n //\n // INITIAL channel-open events at session start are intentionally NOT\n // produced by this diff path — they're synthesized from SessionStarted$\n // above (see the timing rationale there). Channel CLOSES at teardown\n // DO flow through this path because agentSessionId is still set when\n // disposeChannels() emits [] to ActiveChannels$ (teardown nulls it\n // afterwards).\n //\n // `startWith([])` seeds pairwise so it can emit on the first real value\n // — needed so the initial-emission case still goes through the diff\n // logic (where the null-sessionId guard catches it).\n this._subs.push(\n this.voice.ActiveChannels$\n .pipe(startWith([] as ReturnType<() => readonly { ChannelName: string }[]>), pairwise())\n .subscribe(([prev, curr]) => {\n const sessionId = this.voice.CurrentAgentSessionId;\n // No active session id means we can't meaningfully attribute the\n // channel event. Two cases land here:\n // 1. Initial emission during startChannels() — sessionId not set yet;\n // initial opens are handled by SessionStarted$ above.\n // 2. The brief post-teardown window after agentSessionId is nulled.\n if (!sessionId) {\n return;\n }\n const prevNames = new Set(prev.map(c => c.ChannelName));\n const currNames = new Set(curr.map(c => c.ChannelName));\n\n for (const name of currNames) {\n if (!prevNames.has(name)) {\n this._events$.next({\n kind: 'session-channel',\n sessionId,\n channelKind: name,\n state: 'open',\n });\n }\n }\n for (const name of prevNames) {\n if (!currNames.has(name)) {\n this._events$.next({\n kind: 'session-channel',\n sessionId,\n channelKind: name,\n state: 'closed',\n });\n }\n }\n })\n );\n\n // session-ended — bridge RealtimeSessionService.SessionEnded$ verbatim\n // (the service narrows the reason union to what's actually\n // distinguishable client-side; the runtime widens to include 'unknown'\n // for adapters that can't tell, which we don't need here).\n this._subs.push(\n this.voice.SessionEnded$.subscribe((ended) => {\n this._events$.next({\n kind: 'session-ended',\n sessionId: ended.sessionId,\n reason: ended.reason,\n });\n })\n );\n }\n}\n"]}