@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,417 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Metadata, RunView } from '@memberjunction/core';
3
+ import { UUIDsEqual } from '@memberjunction/global';
4
+ import * as i0 from "@angular/core";
5
+ /**
6
+ * MULTI-LEG channel-state merge: folds every leg's channel rows into one state set,
7
+ * NEWEST leg wins per channel name — but only a leg that actually SAVED state counts.
8
+ * A resumed session whose final leg never touched the whiteboard therefore still
9
+ * reviews with the board an EARLIER leg drew (previously only the primary/newest leg's
10
+ * rows were consulted, so that board silently vanished from review).
11
+ *
12
+ * @param legChannelStates Per-leg channel states, ordered OLDEST → NEWEST (the chain order).
13
+ * @returns One entry per channel name (case-insensitive), each from the newest leg that
14
+ * saved a non-empty state; channels no leg ever saved keep a null-state entry so the
15
+ * review still knows the channel existed.
16
+ */
17
+ export function MergeChainChannelStates(legChannelStates) {
18
+ const byName = new Map();
19
+ for (const leg of legChannelStates) {
20
+ for (const state of leg) {
21
+ const key = state.ChannelName.trim().toLowerCase();
22
+ if (key.length === 0) {
23
+ continue;
24
+ }
25
+ const existing = byName.get(key);
26
+ const hasState = typeof state.StateJson === 'string' && state.StateJson.trim().length > 0;
27
+ // Later legs are newer: a saved state always supersedes; a null/empty state only
28
+ // registers the channel's existence and never clobbers an earlier saved board.
29
+ if (!existing || hasState) {
30
+ byName.set(key, hasState ? state : (existing ?? state));
31
+ }
32
+ }
33
+ }
34
+ return [...byName.values()];
35
+ }
36
+ const SESSION_FIELDS = ['ID', 'AgentID', 'Agent', 'Status', 'ConversationID', 'Config', 'LastSessionID', 'LastActiveAt', 'ClosedAt', 'CloseReason', '__mj_CreatedAt'];
37
+ const DETAIL_FIELDS = ['ID', 'Role', 'Message', 'HiddenToUser', '__mj_CreatedAt'];
38
+ const RUN_FIELDS = ['ID', 'AgentID', 'Agent', 'Status', 'Success', 'Message', 'ErrorMessage', 'FinalStep', 'StartedAt', 'CompletedAt'];
39
+ const CHANNEL_FIELDS = ['ID', 'Channel', 'Config'];
40
+ const JUNCTION_FIELDS = ['ID', 'ConversationDetailID', 'ArtifactVersionID'];
41
+ const VERSION_FIELDS = ['ID', 'ArtifactID', 'Name', 'Artifact'];
42
+ /** Maximum number of chain legs the review loader walks (the reviewed session included). */
43
+ export const MAX_REVIEW_LEGS = 5;
44
+ /** Maximum total caption-detail rows loaded across the whole chain (oldest legs trimmed first). */
45
+ export const MAX_REVIEW_DETAILS = 500;
46
+ // ── Review → thread-item mapping (pure, unit-testable) ──────────────────────
47
+ /** Maps one delegated-run preview to the done delegation-card VM the thread/rail render. */
48
+ export function BuildReviewDelegationCard(run, fallbackAgentName) {
49
+ const startedAt = run.StartedAt?.getTime() ?? 0;
50
+ return {
51
+ CallID: run.RunID,
52
+ AgentName: run.AgentName || fallbackAgentName,
53
+ LatestMessage: run.Message ?? run.ErrorMessage ?? run.Status,
54
+ LatestStep: run.FinalStep ?? '',
55
+ Done: true,
56
+ Success: run.Success,
57
+ RunRef: shortRunRef(run.RunID),
58
+ RunID: run.RunID,
59
+ Result: run.Message ?? run.ErrorMessage ?? null,
60
+ StartedAt: startedAt,
61
+ FinishedAt: run.CompletedAt?.getTime() ?? startedAt
62
+ };
63
+ }
64
+ /**
65
+ * Builds the chronological thread (caption turns + done delegation cards, oldest first)
66
+ * for a reviewed session — the items `RealtimeSessionState.LoadHistoricalItems` takes.
67
+ *
68
+ * CHAIN-AWARE: when the review carries multiple {@link RealtimeSessionReview.Legs}, each
69
+ * leg's items render in leg order with a `divider` item between legs ("Session leg
70
+ * started · <time>", carrying the PREVIOUS leg's CloseReason as a chip). A single-leg
71
+ * review (or a legless legacy shape) renders the flat thread with no divider —
72
+ * byte-identical to the pre-chain behavior.
73
+ */
74
+ export function BuildReviewThreadItems(review) {
75
+ const legs = review.Legs ?? [];
76
+ if (legs.length <= 1) {
77
+ const only = legs[0];
78
+ return buildLegThreadItems(only?.Turns ?? review.Turns, only?.DelegatedRuns ?? review.DelegatedRuns, review.AgentName);
79
+ }
80
+ const items = [];
81
+ legs.forEach((leg, i) => {
82
+ if (i > 0) {
83
+ items.push({
84
+ Kind: 'divider',
85
+ Label: 'Session leg started',
86
+ At: leg.StartedAt,
87
+ Icon: 'fa-solid fa-arrows-rotate',
88
+ CloseReason: legs[i - 1].CloseReason ?? null
89
+ });
90
+ }
91
+ items.push(...buildLegThreadItems(leg.Turns, leg.DelegatedRuns, review.AgentName));
92
+ });
93
+ return items;
94
+ }
95
+ /**
96
+ * Builds ONE leg's chronological items (caption turns + done delegation cards, oldest
97
+ * first). Entries without a timestamp sort to the front, preserving their relative order.
98
+ */
99
+ function buildLegThreadItems(turns, runs, fallbackAgentName) {
100
+ const stamped = [];
101
+ for (const turn of turns) {
102
+ stamped.push({ At: turn.At?.getTime() ?? 0, Item: { Kind: 'caption', Role: turn.Role, Text: turn.Text } });
103
+ }
104
+ for (const run of runs) {
105
+ stamped.push({ At: run.StartedAt?.getTime() ?? 0, Item: { Kind: 'delegation', Card: BuildReviewDelegationCard(run, fallbackAgentName) } });
106
+ }
107
+ // Array.prototype.sort is stable — equal timestamps keep their build order.
108
+ stamped.sort((a, b) => a.At - b.At);
109
+ return stamped.map(s => s.Item);
110
+ }
111
+ /** Derives a short run reference (e.g. "#a3f1") from the run id — mirrors the live cards. */
112
+ function shortRunRef(runId) {
113
+ const compact = runId.replace(/[^a-z0-9]/gi, '');
114
+ return compact.length >= 4 ? `#${compact.slice(-4).toLowerCase()}` : `#${compact.toLowerCase()}`;
115
+ }
116
+ /**
117
+ * STATELESS loader for the call overlay's SESSION REVIEW mode: given a past
118
+ * `MJ: AI Agent Sessions` id, batch-loads the session row, its persisted caption turns
119
+ * (`MJ: Conversation Details` linked by `AgentSessionID`), its delegated agent runs
120
+ * (minus the co-agent observability run named in the session Config's `coAgentRunID`),
121
+ * and its saved channel states — and folds them into one {@link RealtimeSessionReview}.
122
+ *
123
+ * CHAIN-AWARE: when the reviewed session carries a `LastSessionID` (it RESUMED an earlier
124
+ * session), the loader walks the chain BACKWARDS — capped at {@link MAX_REVIEW_LEGS} legs
125
+ * and {@link MAX_REVIEW_DETAILS} caption rows total (oldest legs trimmed first), with a
126
+ * cycle guard so a corrupt A→B→A chain can never loop — and surfaces ALL legs
127
+ * chronologically on {@link RealtimeSessionReview.Legs}. Channel state stays the
128
+ * reviewed (latest) leg's only. The chain's conversation-history ARTIFACTS (junction
129
+ * rows on the session-stamped details) are collected onto
130
+ * {@link RealtimeSessionReview.Artifacts}.
131
+ *
132
+ * TOLERANT by design: any missing piece degrades to an empty collection; the loader
133
+ * returns `null` only when the reviewed session row itself can't be found.
134
+ */
135
+ export class RealtimeSessionReviewService {
136
+ /**
137
+ * Loads everything review mode renders for one past session (and its prior-leg chain).
138
+ *
139
+ * @param agentSessionId The `MJ: AI Agent Sessions.ID` to review.
140
+ * @param provider Optional metadata provider (multi-server apps); falls back to the global default.
141
+ * @returns The assembled review, or `null` when the session doesn't exist / can't be read.
142
+ */
143
+ async LoadSessionReview(agentSessionId, provider) {
144
+ const trimmed = agentSessionId?.trim() ?? '';
145
+ if (trimmed.length === 0) {
146
+ return null;
147
+ }
148
+ try {
149
+ const md = provider ?? Metadata.Provider;
150
+ const primary = await this.loadLegRows(trimmed, md, true);
151
+ if (!primary) {
152
+ return null;
153
+ }
154
+ const chain = await this.collectChainLegs(primary, md);
155
+ const artifacts = await this.loadChainArtifacts(chain, md);
156
+ return this.assembleReview(chain, artifacts);
157
+ }
158
+ catch (error) {
159
+ console.error('[RealtimeSessionReview] Failed to load session review:', error);
160
+ return null;
161
+ }
162
+ }
163
+ /**
164
+ * One batched RunViews pass for one chain leg: session row + caption turns + linked
165
+ * runs (+ channel rows for the PRIMARY leg only — channel state is latest-leg-only).
166
+ * Returns `null` when the session row can't be found.
167
+ */
168
+ async loadLegRows(agentSessionId, provider, includeChannels) {
169
+ const safeID = agentSessionId.replace(/'/g, "''");
170
+ const rv = RunView.FromMetadataProvider(provider);
171
+ const queries = [
172
+ { EntityName: 'MJ: AI Agent Sessions', ExtraFilter: `ID='${safeID}'`, Fields: SESSION_FIELDS, ResultType: 'simple' },
173
+ {
174
+ EntityName: 'MJ: Conversation Details', ExtraFilter: `AgentSessionID='${safeID}'`, Fields: DETAIL_FIELDS,
175
+ OrderBy: '__mj_CreatedAt ASC', MaxRows: MAX_REVIEW_DETAILS, ResultType: 'simple'
176
+ },
177
+ { EntityName: 'MJ: AI Agent Runs', ExtraFilter: `AgentSessionID='${safeID}'`, Fields: RUN_FIELDS, OrderBy: 'StartedAt ASC', ResultType: 'simple' }
178
+ ];
179
+ if (includeChannels) {
180
+ queries.push({ EntityName: 'MJ: AI Agent Session Channels', ExtraFilter: `AgentSessionID='${safeID}'`, Fields: CHANNEL_FIELDS, ResultType: 'simple' });
181
+ }
182
+ const [sessionResult, detailResult, runResult, channelResult] = await rv.RunViews(queries);
183
+ const sessions = (sessionResult?.Success ? sessionResult.Results : []);
184
+ const session = sessions[0] ?? null;
185
+ if (!session) {
186
+ return null;
187
+ }
188
+ return {
189
+ session,
190
+ details: (detailResult?.Success ? detailResult.Results : []),
191
+ runs: (runResult?.Success ? runResult.Results : []),
192
+ channels: (channelResult?.Success ? channelResult.Results : [])
193
+ };
194
+ }
195
+ /**
196
+ * Walks the `LastSessionID` chain BACKWARDS from the reviewed (primary) leg, collecting
197
+ * raw leg rows OLDEST-FIRST (primary last). Safety rails:
198
+ * - at most {@link MAX_REVIEW_LEGS} legs total;
199
+ * - at most {@link MAX_REVIEW_DETAILS} caption rows across the chain — an older leg
200
+ * whose details would overflow the budget is trimmed to its NEWEST rows and ends
201
+ * the walk;
202
+ * - a visited-set cycle guard (case-insensitive ids) so A→B→A can never loop;
203
+ * - a leg that fails to load simply ends the walk (the collected legs still render).
204
+ */
205
+ async collectChainLegs(primary, provider) {
206
+ const chain = [primary];
207
+ const visited = new Set([this.normalizeID(primary.session.ID)]);
208
+ let cursor = primary.session.LastSessionID ?? null;
209
+ let detailBudget = MAX_REVIEW_DETAILS - primary.details.length;
210
+ while (cursor && chain.length < MAX_REVIEW_LEGS && detailBudget > 0) {
211
+ const key = this.normalizeID(cursor);
212
+ if (visited.has(key)) {
213
+ console.warn(`[RealtimeSessionReview] Session chain cycle detected at ${cursor} — stopping the walk.`);
214
+ break;
215
+ }
216
+ visited.add(key);
217
+ const leg = await this.loadLegRows(cursor, provider, false);
218
+ if (!leg) {
219
+ break;
220
+ }
221
+ if (leg.details.length > detailBudget) {
222
+ // Keep this leg's NEWEST rows (details arrive oldest-first) and end the walk.
223
+ leg.details = leg.details.slice(leg.details.length - detailBudget);
224
+ detailBudget = 0;
225
+ }
226
+ else {
227
+ detailBudget -= leg.details.length;
228
+ }
229
+ chain.unshift(leg);
230
+ cursor = leg.session.LastSessionID ?? null;
231
+ }
232
+ return chain;
233
+ }
234
+ /**
235
+ * Collects the chain's conversation-history ARTIFACTS: `MJ: Conversation Detail
236
+ * Artifacts` junction rows (Direction `Output`) hanging off the chain's session-stamped
237
+ * details, resolved through `MJ: Artifact Versions` to `{ArtifactID, ArtifactVersionID,
238
+ * Name}` (version name, falling back to the artifact name). Order follows junction
239
+ * creation; duplicate versions are deduped. TOLERANT: any failure returns `[]`.
240
+ */
241
+ async loadChainArtifacts(chain, provider) {
242
+ const detailIDs = chain.flatMap(leg => leg.details.map(d => d.ID)).filter(id => typeof id === 'string' && id.length > 0);
243
+ if (detailIDs.length === 0) {
244
+ return [];
245
+ }
246
+ try {
247
+ const rv = RunView.FromMetadataProvider(provider);
248
+ const detailList = detailIDs.map(id => `'${id.replace(/'/g, "''")}'`).join(',');
249
+ const [junctionResult] = await rv.RunViews([{
250
+ EntityName: 'MJ: Conversation Detail Artifacts',
251
+ ExtraFilter: `ConversationDetailID IN (${detailList}) AND Direction='Output'`,
252
+ Fields: JUNCTION_FIELDS,
253
+ OrderBy: '__mj_CreatedAt ASC',
254
+ ResultType: 'simple'
255
+ }]);
256
+ const junctions = (junctionResult?.Success ? junctionResult.Results : []);
257
+ const versionIDs = this.uniqueVersionIDs(junctions);
258
+ if (versionIDs.length === 0) {
259
+ return [];
260
+ }
261
+ const versionList = versionIDs.map(id => `'${id.replace(/'/g, "''")}'`).join(',');
262
+ const [versionResult] = await rv.RunViews([{
263
+ EntityName: 'MJ: Artifact Versions',
264
+ ExtraFilter: `ID IN (${versionList})`,
265
+ Fields: VERSION_FIELDS,
266
+ ResultType: 'simple'
267
+ }]);
268
+ const versions = (versionResult?.Success ? versionResult.Results : []);
269
+ const byID = new Map(versions.map(v => [this.normalizeID(v.ID), v]));
270
+ const artifacts = [];
271
+ for (const versionID of versionIDs) {
272
+ const row = byID.get(this.normalizeID(versionID));
273
+ if (!row?.ArtifactID) {
274
+ continue; // junction points at an unreadable / deleted version — skip
275
+ }
276
+ artifacts.push({
277
+ ArtifactID: row.ArtifactID,
278
+ ArtifactVersionID: row.ID,
279
+ Name: row.Name?.trim() || row.Artifact?.trim() || 'Artifact'
280
+ });
281
+ }
282
+ return artifacts;
283
+ }
284
+ catch (error) {
285
+ console.warn('[RealtimeSessionReview] Artifact collection failed — review renders without artifact tabs.', error);
286
+ return [];
287
+ }
288
+ }
289
+ /** Unique, non-empty `ArtifactVersionID`s from junction rows, in arrival order (case-insensitive dedupe). */
290
+ uniqueVersionIDs(junctions) {
291
+ const seen = new Set();
292
+ const ids = [];
293
+ for (const j of junctions) {
294
+ const id = typeof j.ArtifactVersionID === 'string' ? j.ArtifactVersionID.trim() : '';
295
+ if (id.length === 0 || seen.has(this.normalizeID(id))) {
296
+ continue;
297
+ }
298
+ seen.add(this.normalizeID(id));
299
+ ids.push(id);
300
+ }
301
+ return ids;
302
+ }
303
+ /** Case-insensitive UUID key for Set/Map membership (SQL Server uppercase vs PostgreSQL lowercase). */
304
+ normalizeID(id) {
305
+ return (id ?? '').trim().toLowerCase();
306
+ }
307
+ /**
308
+ * Folds the chain's raw leg rows into the typed review. The PRIMARY (reviewed) leg —
309
+ * the chain's LAST entry — supplies identity/lifecycle/channel state; turns and runs
310
+ * are surfaced both per-leg (`Legs`) and flattened chronologically (`Turns` /
311
+ * `DelegatedRuns`). Each leg excludes ITS OWN config's co-agent observability run.
312
+ */
313
+ assembleReview(chain, artifacts) {
314
+ const primary = chain[chain.length - 1];
315
+ const session = primary.session;
316
+ const config = this.parseSessionConfig(session.Config);
317
+ const legs = chain.map(leg => this.mapLeg(leg));
318
+ return {
319
+ SessionID: session.ID,
320
+ AgentID: session.AgentID,
321
+ AgentName: session.Agent || 'the agent',
322
+ TargetAgentID: config.targetAgentID ?? session.AgentID,
323
+ ConversationID: session.ConversationID ?? null,
324
+ Status: session.Status,
325
+ CloseReason: session.CloseReason ?? null,
326
+ StartedAt: this.toDate(session.__mj_CreatedAt),
327
+ LastActiveAt: this.toDate(session.LastActiveAt),
328
+ ClosedAt: this.toDate(session.ClosedAt),
329
+ Turns: legs.flatMap(l => l.Turns),
330
+ DelegatedRuns: legs.flatMap(l => l.DelegatedRuns),
331
+ // Multi-leg: newest leg with a SAVED state wins per channel — a final leg that
332
+ // never touched the board no longer hides an earlier leg's drawing from review.
333
+ ChannelStates: MergeChainChannelStates(chain.map(leg => this.mapChannels(leg.channels))),
334
+ Legs: legs,
335
+ Artifacts: artifacts
336
+ };
337
+ }
338
+ /** Maps one leg's raw rows to the public leg shape (per-leg co-agent-run exclusion). */
339
+ mapLeg(leg) {
340
+ const config = this.parseSessionConfig(leg.session.Config);
341
+ return {
342
+ SessionID: leg.session.ID,
343
+ StartedAt: this.toDate(leg.session.__mj_CreatedAt),
344
+ ClosedAt: this.toDate(leg.session.ClosedAt),
345
+ CloseReason: leg.session.CloseReason ?? null,
346
+ Turns: this.mapTurns(leg.details),
347
+ DelegatedRuns: this.mapRuns(leg.runs, config.coAgentRunID ?? null)
348
+ };
349
+ }
350
+ /** Persisted detail rows → caption turns: visible `User`/`AI` rows with text (AI → Assistant). */
351
+ mapTurns(details) {
352
+ const turns = [];
353
+ for (const row of details) {
354
+ const text = row.Message?.trim() ?? '';
355
+ if (row.HiddenToUser || text.length === 0 || (row.Role !== 'User' && row.Role !== 'AI')) {
356
+ continue;
357
+ }
358
+ turns.push({
359
+ Role: row.Role === 'AI' ? 'Assistant' : 'User',
360
+ Text: text,
361
+ At: this.toDate(row.__mj_CreatedAt)
362
+ });
363
+ }
364
+ return turns;
365
+ }
366
+ /** Linked run rows → delegated-run previews, EXCLUDING the co-agent's observability run. */
367
+ mapRuns(runs, coAgentRunId) {
368
+ return runs
369
+ .filter(r => !coAgentRunId || !UUIDsEqual(r.ID, coAgentRunId))
370
+ .map(r => ({
371
+ RunID: r.ID,
372
+ AgentID: r.AgentID,
373
+ AgentName: r.Agent ?? null,
374
+ Status: r.Status ?? '',
375
+ Success: r.Success === true,
376
+ Message: r.Message ?? null,
377
+ ErrorMessage: r.ErrorMessage ?? null,
378
+ FinalStep: r.FinalStep ?? null,
379
+ StartedAt: this.toDate(r.StartedAt),
380
+ CompletedAt: this.toDate(r.CompletedAt)
381
+ }));
382
+ }
383
+ /** Session-channel rows → named channel states (rows without a channel name are skipped). */
384
+ mapChannels(channels) {
385
+ return channels
386
+ .filter(c => !!c.Channel)
387
+ .map(c => ({ ChannelName: c.Channel, StateJson: c.Config ?? null }));
388
+ }
389
+ /** Tolerant Config JSON parse — malformed/missing payloads degrade to `{}`. */
390
+ parseSessionConfig(raw) {
391
+ if (!raw) {
392
+ return {};
393
+ }
394
+ try {
395
+ const parsed = JSON.parse(raw);
396
+ return parsed && typeof parsed === 'object' ? parsed : {};
397
+ }
398
+ catch {
399
+ return {};
400
+ }
401
+ }
402
+ /** Tolerant date conversion — view rows arrive as ISO strings (or Dates from some providers). */
403
+ toDate(value) {
404
+ if (value == null) {
405
+ return null;
406
+ }
407
+ const date = value instanceof Date ? value : new Date(value);
408
+ return isNaN(date.getTime()) ? null : date;
409
+ }
410
+ static ɵfac = function RealtimeSessionReviewService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || RealtimeSessionReviewService)(); };
411
+ static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: RealtimeSessionReviewService, factory: RealtimeSessionReviewService.ɵfac, providedIn: 'root' });
412
+ }
413
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(RealtimeSessionReviewService, [{
414
+ type: Injectable,
415
+ args: [{ providedIn: 'root' }]
416
+ }], null, null); })();
417
+ //# sourceMappingURL=realtime-session-review.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime-session-review.service.js","sourceRoot":"","sources":["../../../src/lib/services/realtime-session-review.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAqB,QAAQ,EAAE,OAAO,EAAiB,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;;AAuDpD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CACrC,gBAAiF;IAEjF,MAAM,MAAM,GAAG,IAAI,GAAG,EAA6C,CAAC;IACpE,KAAK,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACnC,KAAK,MAAM,KAAK,IAAI,GAAG,EAAE,CAAC;YACxB,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YACnD,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACrB,SAAS;YACX,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;YAC1F,iFAAiF;YACjF,+EAA+E;YAC/E,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBAC1B,MAAM,CAAC,GAAG,CAAC,G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FAA6F;IACrF,WAAW,CAAC,QAAsB;QACxC,OAAO,QAAQ;aACZ,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;aACxB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,OAAiB,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,+EAA+E;IACvE,kBAAkB,CAAC,GAAkB;QAC3C,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAsB,CAAC;YACpD,OAAO,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,iGAAiG;IACzF,MAAM,CAAC,KAAuC;QACpD,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,CAAC;sHAjSU,4BAA4B;gEAA5B,4BAA4B,WAA5B,4BAA4B,mBADf,MAAM;;iFACnB,4BAA4B;cADxC,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable } from '@angular/core';\nimport { IMetadataProvider, Metadata, RunView, RunViewParams } from '@memberjunction/core';\nimport { UUIDsEqual } from '@memberjunction/global';\nimport { RealtimeDelegationCardVM, RealtimeThreadItem } from '../components/realtime/realtime-session-state';\nimport { ParsedDelegationArtifact } from './delegation-result-parser';\n\n/**\n * Why a reviewed session was closed, as stamped server-side by `SessionManager.CloseSession`\n * (mirrors `MJAIAgentSessionEntity.CloseReason`). `null` means the session is still open OR a\n * legacy row was closed before the column existed.\n */\nexport type RealtimeReviewCloseReason = 'Error' | 'Explicit' | 'Janitor' | 'Shutdown';\n\n/** One historical caption turn of a reviewed session (a persisted `MJ: Conversation Details` row). */\nexport interface RealtimeSessionReviewTurn {\n /** Who spoke the turn. Persisted `AI` rows map to `Assistant`. */\n Role: 'User' | 'Assistant';\n /** The transcript text. */\n Text: string;\n /** When the turn was persisted (`__mj_CreatedAt`), or null when unknown. */\n At: Date | null;\n}\n\n/**\n * A compact preview of one DELEGATED agent run the reviewed session spawned (an\n * `MJ: AI Agent Runs` row linked via `AgentSessionID`, EXCLUDING the co-agent's own\n * observability run). Carries just enough to render a done delegation card.\n */\nexport interface RealtimeSessionReviewRun {\n /** `MJ: AI Agent Runs.ID`. */\n RunID: string;\n /** The delegated agent's id. */\n AgentID: string;\n /** Denormalized agent display name from the run view, when available. */\n AgentName: string | null;\n /** Terminal (or last-known) run status (`Completed` | `Failed` | `Running` | …). */\n Status: string;\n /** Whether the run reported success. */\n Success: boolean;\n /** The run's user-facing result message, when one was recorded. */\n Message: string | null;\n /** The run's error message, when it failed. */\n ErrorMessage: string | null;\n /** The final step the run reported (`Success` | `Failed` | `Retry` | …), when known. */\n FinalStep: string | null;\n StartedAt: Date | null;\n CompletedAt: Date | null;\n}\n\n/** The persisted state of one interactive channel of the reviewed session. */\nexport interface RealtimeSessionReviewChannelState {\n /** Channel display name (e.g. `Whiteboard`), denormalized on the session-channel row. */\n ChannelName: string;\n /** The channel's serialized state of record (`AIAgentSessionChannel.Config`), or null when none was saved. */\n StateJson: string | null;\n}\n\n/**\n * MULTI-LEG channel-state merge: folds every leg's channel rows into one state set,\n * NEWEST leg wins per channel name — but only a leg that actually SAVED state counts.\n * A resumed session whose final leg never touched the whiteboard therefore still\n * reviews with the board an EARLIER leg drew (previously only the primary/newest leg's\n * rows were consulted, so that board silently vanished from review).\n *\n * @param legChannelStates Per-leg channel states, ordered OLDEST → NEWEST (the chain order).\n * @returns One entry per channel name (case-insensitive), each from the newest leg that\n * saved a non-empty state; channels no leg ever saved keep a null-state entry so the\n * review still knows the channel existed.\n */\nexport function MergeChainChannelStates(\n legChannelStates: ReadonlyArray<ReadonlyArray<RealtimeSessionReviewChannelState>>\n): RealtimeSessionReviewChannelState[] {\n const byName = new Map<string, RealtimeSessionReviewChannelState>();\n for (const leg of legChannelStates) {\n for (const state of leg) {\n const key = state.ChannelName.trim().toLowerCase();\n if (key.length === 0) {\n continue;\n }\n const existing = byName.get(key);\n const hasState = typeof state.StateJson === 'string' && state.StateJson.trim().length > 0;\n // Later legs are newer: a saved state always supersedes; a null/empty state only\n // registers the channel's existence and never clobbers an earlier saved board.\n if (!existing || hasState) {\n byName.set(key, hasState ? state : (existing ?? state));\n }\n }\n }\n return [...byName.values()];\n}\n\n/**\n * One LEG of a reviewed session chain: a single `MJ: AI Agent Sessions` row plus its own\n * caption turns and delegated-run previews. A session resumed via `lastSessionId` chains\n * legs together (newest leg's `LastSessionID` → prior leg); the review loader walks that\n * chain BACKWARDS (capped — see the loader docs) so review mode can render the FULL\n * conversation arc chronologically, with a divider between legs.\n */\nexport interface RealtimeSessionReviewLeg {\n /** `MJ: AI Agent Sessions.ID` of this leg. */\n SessionID: string;\n /** When this leg started (`__mj_CreatedAt`). */\n StartedAt: Date | null;\n /** When this leg closed (null while still open). */\n ClosedAt: Date | null;\n /** Why this leg closed (null while open / legacy rows). */\n CloseReason: RealtimeReviewCloseReason | null;\n /** This leg's chronological caption turns (oldest first). */\n Turns: RealtimeSessionReviewTurn[];\n /** This leg's delegated-run previews (oldest first, minus its co-agent observability run). */\n DelegatedRuns: RealtimeSessionReviewRun[];\n}\n\n/**\n * Everything the call overlay's SESSION REVIEW mode renders for one past realtime session:\n * the session identity/lifecycle row, the chronological caption turns, previews of the\n * delegated runs, and the saved per-channel states (e.g. the whiteboard board).\n */\nexport interface RealtimeSessionReview {\n /** `MJ: AI Agent Sessions.ID` of the reviewed session. */\n SessionID: string;\n /** The session's fronting agent id (`AIAgentSession.AgentID` — usually the Realtime Co-Agent). */\n AgentID: string;\n /** Display name shown in the review banner (target agent when resolvable, else the session agent). */\n AgentName: string;\n /**\n * The agent a RESUMED live session should front: the session Config's `targetAgentID`,\n * falling back to the session's own `AgentID` when the config doesn't carry one.\n */\n TargetAgentID: string;\n /** Conversation the session was bound to, when any. */\n ConversationID: string | null;\n Status: 'Active' | 'Closed' | 'Idle';\n CloseReason: RealtimeReviewCloseReason | null;\n /** When the session started (`__mj_CreatedAt`). */\n StartedAt: Date | null;\n LastActiveAt: Date | null;\n ClosedAt: Date | null;\n /** Chronological caption turns (oldest first) — ALL legs of the chain, flattened. */\n Turns: RealtimeSessionReviewTurn[];\n /** Delegated run previews (oldest first, all legs), minus each leg's co-agent observability run. */\n DelegatedRuns: RealtimeSessionReviewRun[];\n /**\n * Saved channel states, one per session-channel row that carried a name. Channel state\n * (e.g. the whiteboard board) is the LATEST leg's only — earlier legs' states were\n * superseded when the chain resumed.\n */\n ChannelStates: RealtimeSessionReviewChannelState[];\n /**\n * The session-chain LEGS, chronological (oldest first; the LAST leg is the reviewed\n * session itself). Single-session reviews carry exactly one leg. Drives the per-leg\n * dividers `BuildReviewThreadItems` renders.\n */\n Legs: RealtimeSessionReviewLeg[];\n /**\n * ARTIFACTS attached to the chain's conversation history: every `MJ: Conversation\n * Detail Artifacts` junction (Direction `Output`) hanging off the chain's\n * session-stamped `Conversation Details`, resolved to `{ArtifactID, ArtifactVersionID,\n * Name}`. Review mode registers each as an (unfocused) artifact tab on the surface\n * panel, and they carry into a resumed live session. Empty when none / on any\n * tolerated load failure.\n */\n Artifacts: ParsedDelegationArtifact[];\n}\n\n// ── Raw row shapes (ResultType: 'simple', narrowed Fields) ──────────────────\n\ninterface SessionRow {\n ID: string;\n AgentID: string;\n Agent: string | null;\n Status: 'Active' | 'Closed' | 'Idle';\n ConversationID: string | null;\n Config: string | null;\n LastSessionID: string | null;\n LastActiveAt: string | null;\n ClosedAt: string | null;\n CloseReason: RealtimeReviewCloseReason | null;\n __mj_CreatedAt: string | null;\n}\n\ninterface DetailRow {\n ID: string;\n Role: 'AI' | 'Error' | 'User';\n Message: string | null;\n HiddenToUser: boolean;\n __mj_CreatedAt: string | null;\n}\n\ninterface RunRow {\n ID: string;\n AgentID: string;\n Agent: string | null;\n Status: string;\n Success: boolean | null;\n Message: string | null;\n ErrorMessage: string | null;\n FinalStep: string | null;\n StartedAt: string | null;\n CompletedAt: string | null;\n}\n\ninterface ChannelRow {\n ID: string;\n Channel: string | null;\n Config: string | null;\n}\n\ninterface DetailArtifactJunctionRow {\n ID: string;\n ConversationDetailID: string;\n ArtifactVersionID: string | null;\n}\n\ninterface ArtifactVersionRow {\n ID: string;\n ArtifactID: string;\n /** Version display name (nullable on the row). */\n Name: string | null;\n /** Denormalized parent-artifact name from the version view. */\n Artifact: string | null;\n}\n\n/** The raw rows of ONE chain leg, before mapping to the public review shapes. */\ninterface LegRows {\n session: SessionRow;\n details: DetailRow[];\n runs: RunRow[];\n channels: ChannelRow[];\n}\n\n/** The Config-JSON keys the realtime voice stack persists on `AIAgentSession.Config`. */\ninterface SessionConfigJson {\n targetAgentID?: string;\n coAgentRunID?: string;\n}\n\nconst SESSION_FIELDS = ['ID', 'AgentID', 'Agent', 'Status', 'ConversationID', 'Config', 'LastSessionID', 'LastActiveAt', 'ClosedAt', 'CloseReason', '__mj_CreatedAt'];\nconst DETAIL_FIELDS = ['ID', 'Role', 'Message', 'HiddenToUser', '__mj_CreatedAt'];\nconst RUN_FIELDS = ['ID', 'AgentID', 'Agent', 'Status', 'Success', 'Message', 'ErrorMessage', 'FinalStep', 'StartedAt', 'CompletedAt'];\nconst CHANNEL_FIELDS = ['ID', 'Channel', 'Config'];\nconst JUNCTION_FIELDS = ['ID', 'ConversationDetailID', 'ArtifactVersionID'];\nconst VERSION_FIELDS = ['ID', 'ArtifactID', 'Name', 'Artifact'];\n\n/** Maximum number of chain legs the review loader walks (the reviewed session included). */\nexport const MAX_REVIEW_LEGS = 5;\n/** Maximum total caption-detail rows loaded across the whole chain (oldest legs trimmed first). */\nexport const MAX_REVIEW_DETAILS = 500;\n\n// ── Review → thread-item mapping (pure, unit-testable) ──────────────────────\n\n/** Maps one delegated-run preview to the done delegation-card VM the thread/rail render. */\nexport function BuildReviewDelegationCard(run: RealtimeSessionReviewRun, fallbackAgentName: string): RealtimeDelegationCardVM {\n const startedAt = run.StartedAt?.getTime() ?? 0;\n return {\n CallID: run.RunID,\n AgentName: run.AgentName || fallbackAgentName,\n LatestMessage: run.Message ?? run.ErrorMessage ?? run.Status,\n LatestStep: run.FinalStep ?? '',\n Done: true,\n Success: run.Success,\n RunRef: shortRunRef(run.RunID),\n RunID: run.RunID,\n Result: run.Message ?? run.ErrorMessage ?? null,\n StartedAt: startedAt,\n FinishedAt: run.CompletedAt?.getTime() ?? startedAt\n };\n}\n\n/**\n * Builds the chronological thread (caption turns + done delegation cards, oldest first)\n * for a reviewed session — the items `RealtimeSessionState.LoadHistoricalItems` takes.\n *\n * CHAIN-AWARE: when the review carries multiple {@link RealtimeSessionReview.Legs}, each\n * leg's items render in leg order with a `divider` item between legs (\"Session leg\n * started · <time>\", carrying the PREVIOUS leg's CloseReason as a chip). A single-leg\n * review (or a legless legacy shape) renders the flat thread with no divider —\n * byte-identical to the pre-chain behavior.\n */\nexport function BuildReviewThreadItems(review: RealtimeSessionReview): RealtimeThreadItem[] {\n const legs = review.Legs ?? [];\n if (legs.length <= 1) {\n const only = legs[0];\n return buildLegThreadItems(only?.Turns ?? review.Turns, only?.DelegatedRuns ?? review.DelegatedRuns, review.AgentName);\n }\n const items: RealtimeThreadItem[] = [];\n legs.forEach((leg, i) => {\n if (i > 0) {\n items.push({\n Kind: 'divider',\n Label: 'Session leg started',\n At: leg.StartedAt,\n Icon: 'fa-solid fa-arrows-rotate',\n CloseReason: legs[i - 1].CloseReason ?? null\n });\n }\n items.push(...buildLegThreadItems(leg.Turns, leg.DelegatedRuns, review.AgentName));\n });\n return items;\n}\n\n/**\n * Builds ONE leg's chronological items (caption turns + done delegation cards, oldest\n * first). Entries without a timestamp sort to the front, preserving their relative order.\n */\nfunction buildLegThreadItems(\n turns: RealtimeSessionReviewTurn[],\n runs: RealtimeSessionReviewRun[],\n fallbackAgentName: string\n): RealtimeThreadItem[] {\n const stamped: Array<{ At: number; Item: RealtimeThreadItem }> = [];\n for (const turn of turns) {\n stamped.push({ At: turn.At?.getTime() ?? 0, Item: { Kind: 'caption', Role: turn.Role, Text: turn.Text } });\n }\n for (const run of runs) {\n stamped.push({ At: run.StartedAt?.getTime() ?? 0, Item: { Kind: 'delegation', Card: BuildReviewDelegationCard(run, fallbackAgentName) } });\n }\n // Array.prototype.sort is stable — equal timestamps keep their build order.\n stamped.sort((a, b) => a.At - b.At);\n return stamped.map(s => s.Item);\n}\n\n/** Derives a short run reference (e.g. \"#a3f1\") from the run id — mirrors the live cards. */\nfunction shortRunRef(runId: string): string {\n const compact = runId.replace(/[^a-z0-9]/gi, '');\n return compact.length >= 4 ? `#${compact.slice(-4).toLowerCase()}` : `#${compact.toLowerCase()}`;\n}\n\n/**\n * STATELESS loader for the call overlay's SESSION REVIEW mode: given a past\n * `MJ: AI Agent Sessions` id, batch-loads the session row, its persisted caption turns\n * (`MJ: Conversation Details` linked by `AgentSessionID`), its delegated agent runs\n * (minus the co-agent observability run named in the session Config's `coAgentRunID`),\n * and its saved channel states — and folds them into one {@link RealtimeSessionReview}.\n *\n * CHAIN-AWARE: when the reviewed session carries a `LastSessionID` (it RESUMED an earlier\n * session), the loader walks the chain BACKWARDS — capped at {@link MAX_REVIEW_LEGS} legs\n * and {@link MAX_REVIEW_DETAILS} caption rows total (oldest legs trimmed first), with a\n * cycle guard so a corrupt A→B→A chain can never loop — and surfaces ALL legs\n * chronologically on {@link RealtimeSessionReview.Legs}. Channel state stays the\n * reviewed (latest) leg's only. The chain's conversation-history ARTIFACTS (junction\n * rows on the session-stamped details) are collected onto\n * {@link RealtimeSessionReview.Artifacts}.\n *\n * TOLERANT by design: any missing piece degrades to an empty collection; the loader\n * returns `null` only when the reviewed session row itself can't be found.\n */\n@Injectable({ providedIn: 'root' })\nexport class RealtimeSessionReviewService {\n /**\n * Loads everything review mode renders for one past session (and its prior-leg chain).\n *\n * @param agentSessionId The `MJ: AI Agent Sessions.ID` to review.\n * @param provider Optional metadata provider (multi-server apps); falls back to the global default.\n * @returns The assembled review, or `null` when the session doesn't exist / can't be read.\n */\n public async LoadSessionReview(agentSessionId: string, provider?: IMetadataProvider): Promise<RealtimeSessionReview | null> {\n const trimmed = agentSessionId?.trim() ?? '';\n if (trimmed.length === 0) {\n return null;\n }\n try {\n const md = provider ?? Metadata.Provider;\n const primary = await this.loadLegRows(trimmed, md, true);\n if (!primary) {\n return null;\n }\n const chain = await this.collectChainLegs(primary, md);\n const artifacts = await this.loadChainArtifacts(chain, md);\n return this.assembleReview(chain, artifacts);\n } catch (error) {\n console.error('[RealtimeSessionReview] Failed to load session review:', error);\n return null;\n }\n }\n\n /**\n * One batched RunViews pass for one chain leg: session row + caption turns + linked\n * runs (+ channel rows for the PRIMARY leg only — channel state is latest-leg-only).\n * Returns `null` when the session row can't be found.\n */\n private async loadLegRows(\n agentSessionId: string,\n provider: IMetadataProvider,\n includeChannels: boolean\n ): Promise<LegRows | null> {\n const safeID = agentSessionId.replace(/'/g, \"''\");\n const rv = RunView.FromMetadataProvider(provider);\n const queries: RunViewParams[] = [\n { EntityName: 'MJ: AI Agent Sessions', ExtraFilter: `ID='${safeID}'`, Fields: SESSION_FIELDS, ResultType: 'simple' as const },\n {\n EntityName: 'MJ: Conversation Details', ExtraFilter: `AgentSessionID='${safeID}'`, Fields: DETAIL_FIELDS,\n OrderBy: '__mj_CreatedAt ASC', MaxRows: MAX_REVIEW_DETAILS, ResultType: 'simple' as const\n },\n { EntityName: 'MJ: AI Agent Runs', ExtraFilter: `AgentSessionID='${safeID}'`, Fields: RUN_FIELDS, OrderBy: 'StartedAt ASC', ResultType: 'simple' as const }\n ];\n if (includeChannels) {\n queries.push({ EntityName: 'MJ: AI Agent Session Channels', ExtraFilter: `AgentSessionID='${safeID}'`, Fields: CHANNEL_FIELDS, ResultType: 'simple' as const });\n }\n const [sessionResult, detailResult, runResult, channelResult] = await rv.RunViews(queries);\n const sessions = (sessionResult?.Success ? sessionResult.Results : []) as SessionRow[];\n const session = sessions[0] ?? null;\n if (!session) {\n return null;\n }\n return {\n session,\n details: (detailResult?.Success ? detailResult.Results : []) as DetailRow[],\n runs: (runResult?.Success ? runResult.Results : []) as RunRow[],\n channels: (channelResult?.Success ? channelResult.Results : []) as ChannelRow[]\n };\n }\n\n /**\n * Walks the `LastSessionID` chain BACKWARDS from the reviewed (primary) leg, collecting\n * raw leg rows OLDEST-FIRST (primary last). Safety rails:\n * - at most {@link MAX_REVIEW_LEGS} legs total;\n * - at most {@link MAX_REVIEW_DETAILS} caption rows across the chain — an older leg\n * whose details would overflow the budget is trimmed to its NEWEST rows and ends\n * the walk;\n * - a visited-set cycle guard (case-insensitive ids) so A→B→A can never loop;\n * - a leg that fails to load simply ends the walk (the collected legs still render).\n */\n private async collectChainLegs(primary: LegRows, provider: IMetadataProvider): Promise<LegRows[]> {\n const chain: LegRows[] = [primary];\n const visited = new Set<string>([this.normalizeID(primary.session.ID)]);\n let cursor = primary.session.LastSessionID ?? null;\n let detailBudget = MAX_REVIEW_DETAILS - primary.details.length;\n\n while (cursor && chain.length < MAX_REVIEW_LEGS && detailBudget > 0) {\n const key = this.normalizeID(cursor);\n if (visited.has(key)) {\n console.warn(`[RealtimeSessionReview] Session chain cycle detected at ${cursor} — stopping the walk.`);\n break;\n }\n visited.add(key);\n const leg = await this.loadLegRows(cursor, provider, false);\n if (!leg) {\n break;\n }\n if (leg.details.length > detailBudget) {\n // Keep this leg's NEWEST rows (details arrive oldest-first) and end the walk.\n leg.details = leg.details.slice(leg.details.length - detailBudget);\n detailBudget = 0;\n } else {\n detailBudget -= leg.details.length;\n }\n chain.unshift(leg);\n cursor = leg.session.LastSessionID ?? null;\n }\n return chain;\n }\n\n /**\n * Collects the chain's conversation-history ARTIFACTS: `MJ: Conversation Detail\n * Artifacts` junction rows (Direction `Output`) hanging off the chain's session-stamped\n * details, resolved through `MJ: Artifact Versions` to `{ArtifactID, ArtifactVersionID,\n * Name}` (version name, falling back to the artifact name). Order follows junction\n * creation; duplicate versions are deduped. TOLERANT: any failure returns `[]`.\n */\n private async loadChainArtifacts(chain: LegRows[], provider: IMetadataProvider): Promise<ParsedDelegationArtifact[]> {\n const detailIDs = chain.flatMap(leg => leg.details.map(d => d.ID)).filter(id => typeof id === 'string' && id.length > 0);\n if (detailIDs.length === 0) {\n return [];\n }\n try {\n const rv = RunView.FromMetadataProvider(provider);\n const detailList = detailIDs.map(id => `'${id.replace(/'/g, \"''\")}'`).join(',');\n const [junctionResult] = await rv.RunViews([{\n EntityName: 'MJ: Conversation Detail Artifacts',\n ExtraFilter: `ConversationDetailID IN (${detailList}) AND Direction='Output'`,\n Fields: JUNCTION_FIELDS,\n OrderBy: '__mj_CreatedAt ASC',\n ResultType: 'simple'\n }]);\n const junctions = (junctionResult?.Success ? junctionResult.Results : []) as DetailArtifactJunctionRow[];\n const versionIDs = this.uniqueVersionIDs(junctions);\n if (versionIDs.length === 0) {\n return [];\n }\n\n const versionList = versionIDs.map(id => `'${id.replace(/'/g, \"''\")}'`).join(',');\n const [versionResult] = await rv.RunViews([{\n EntityName: 'MJ: Artifact Versions',\n ExtraFilter: `ID IN (${versionList})`,\n Fields: VERSION_FIELDS,\n ResultType: 'simple'\n }]);\n const versions = (versionResult?.Success ? versionResult.Results : []) as ArtifactVersionRow[];\n const byID = new Map<string, ArtifactVersionRow>(versions.map(v => [this.normalizeID(v.ID), v]));\n\n const artifacts: ParsedDelegationArtifact[] = [];\n for (const versionID of versionIDs) {\n const row = byID.get(this.normalizeID(versionID));\n if (!row?.ArtifactID) {\n continue; // junction points at an unreadable / deleted version — skip\n }\n artifacts.push({\n ArtifactID: row.ArtifactID,\n ArtifactVersionID: row.ID,\n Name: row.Name?.trim() || row.Artifact?.trim() || 'Artifact'\n });\n }\n return artifacts;\n } catch (error) {\n console.warn('[RealtimeSessionReview] Artifact collection failed — review renders without artifact tabs.', error);\n return [];\n }\n }\n\n /** Unique, non-empty `ArtifactVersionID`s from junction rows, in arrival order (case-insensitive dedupe). */\n private uniqueVersionIDs(junctions: DetailArtifactJunctionRow[]): string[] {\n const seen = new Set<string>();\n const ids: string[] = [];\n for (const j of junctions) {\n const id = typeof j.ArtifactVersionID === 'string' ? j.ArtifactVersionID.trim() : '';\n if (id.length === 0 || seen.has(this.normalizeID(id))) {\n continue;\n }\n seen.add(this.normalizeID(id));\n ids.push(id);\n }\n return ids;\n }\n\n /** Case-insensitive UUID key for Set/Map membership (SQL Server uppercase vs PostgreSQL lowercase). */\n private normalizeID(id: string): string {\n return (id ?? '').trim().toLowerCase();\n }\n\n /**\n * Folds the chain's raw leg rows into the typed review. The PRIMARY (reviewed) leg —\n * the chain's LAST entry — supplies identity/lifecycle/channel state; turns and runs\n * are surfaced both per-leg (`Legs`) and flattened chronologically (`Turns` /\n * `DelegatedRuns`). Each leg excludes ITS OWN config's co-agent observability run.\n */\n private assembleReview(chain: LegRows[], artifacts: ParsedDelegationArtifact[]): RealtimeSessionReview {\n const primary = chain[chain.length - 1];\n const session = primary.session;\n const config = this.parseSessionConfig(session.Config);\n const legs = chain.map(leg => this.mapLeg(leg));\n return {\n SessionID: session.ID,\n AgentID: session.AgentID,\n AgentName: session.Agent || 'the agent',\n TargetAgentID: config.targetAgentID ?? session.AgentID,\n ConversationID: session.ConversationID ?? null,\n Status: session.Status,\n CloseReason: session.CloseReason ?? null,\n StartedAt: this.toDate(session.__mj_CreatedAt),\n LastActiveAt: this.toDate(session.LastActiveAt),\n ClosedAt: this.toDate(session.ClosedAt),\n Turns: legs.flatMap(l => l.Turns),\n DelegatedRuns: legs.flatMap(l => l.DelegatedRuns),\n // Multi-leg: newest leg with a SAVED state wins per channel — a final leg that\n // never touched the board no longer hides an earlier leg's drawing from review.\n ChannelStates: MergeChainChannelStates(chain.map(leg => this.mapChannels(leg.channels))),\n Legs: legs,\n Artifacts: artifacts\n };\n }\n\n /** Maps one leg's raw rows to the public leg shape (per-leg co-agent-run exclusion). */\n private mapLeg(leg: LegRows): RealtimeSessionReviewLeg {\n const config = this.parseSessionConfig(leg.session.Config);\n return {\n SessionID: leg.session.ID,\n StartedAt: this.toDate(leg.session.__mj_CreatedAt),\n ClosedAt: this.toDate(leg.session.ClosedAt),\n CloseReason: leg.session.CloseReason ?? null,\n Turns: this.mapTurns(leg.details),\n DelegatedRuns: this.mapRuns(leg.runs, config.coAgentRunID ?? null)\n };\n }\n\n /** Persisted detail rows → caption turns: visible `User`/`AI` rows with text (AI → Assistant). */\n private mapTurns(details: DetailRow[]): RealtimeSessionReviewTurn[] {\n const turns: RealtimeSessionReviewTurn[] = [];\n for (const row of details) {\n const text = row.Message?.trim() ?? '';\n if (row.HiddenToUser || text.length === 0 || (row.Role !== 'User' && row.Role !== 'AI')) {\n continue;\n }\n turns.push({\n Role: row.Role === 'AI' ? 'Assistant' : 'User',\n Text: text,\n At: this.toDate(row.__mj_CreatedAt)\n });\n }\n return turns;\n }\n\n /** Linked run rows → delegated-run previews, EXCLUDING the co-agent's observability run. */\n private mapRuns(runs: RunRow[], coAgentRunId: string | null): RealtimeSessionReviewRun[] {\n return runs\n .filter(r => !coAgentRunId || !UUIDsEqual(r.ID, coAgentRunId))\n .map(r => ({\n RunID: r.ID,\n AgentID: r.AgentID,\n AgentName: r.Agent ?? null,\n Status: r.Status ?? '',\n Success: r.Success === true,\n Message: r.Message ?? null,\n ErrorMessage: r.ErrorMessage ?? null,\n FinalStep: r.FinalStep ?? null,\n StartedAt: this.toDate(r.StartedAt),\n CompletedAt: this.toDate(r.CompletedAt)\n }));\n }\n\n /** Session-channel rows → named channel states (rows without a channel name are skipped). */\n private mapChannels(channels: ChannelRow[]): RealtimeSessionReviewChannelState[] {\n return channels\n .filter(c => !!c.Channel)\n .map(c => ({ ChannelName: c.Channel as string, StateJson: c.Config ?? null }));\n }\n\n /** Tolerant Config JSON parse — malformed/missing payloads degrade to `{}`. */\n private parseSessionConfig(raw: string | null): SessionConfigJson {\n if (!raw) {\n return {};\n }\n try {\n const parsed = JSON.parse(raw) as SessionConfigJson;\n return parsed && typeof parsed === 'object' ? parsed : {};\n } catch {\n return {};\n }\n }\n\n /** Tolerant date conversion — view rows arrive as ISO strings (or Dates from some providers). */\n private toDate(value: string | Date | null | undefined): Date | null {\n if (value == null) {\n return null;\n }\n const date = value instanceof Date ? value : new Date(value);\n return isNaN(date.getTime()) ? null : date;\n }\n}\n"]}