@memberjunction/ng-conversations 6.2.0-edge.3 → 6.2.0-edge.5

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 (318) hide show
  1. package/README.md +33 -7
  2. package/dist/lib/components/collection/collection-view.component.d.ts.map +1 -1
  3. package/dist/lib/components/collection/collection-view.component.js +1 -0
  4. package/dist/lib/components/collection/collection-view.component.js.map +1 -1
  5. package/dist/lib/components/composer/ai-composer.component.d.ts +14 -2
  6. package/dist/lib/components/composer/ai-composer.component.d.ts.map +1 -1
  7. package/dist/lib/components/composer/ai-composer.component.js +35 -4
  8. package/dist/lib/components/composer/ai-composer.component.js.map +1 -1
  9. package/dist/lib/components/conversation/conversation-agent-picker.component.d.ts +1 -1
  10. package/dist/lib/components/conversation/conversation-agent-picker.component.js +3 -3
  11. package/dist/lib/components/conversation/conversation-agent-picker.component.js.map +1 -1
  12. package/dist/lib/components/conversation/conversation-chat-area.component.d.ts +651 -53
  13. package/dist/lib/components/conversation/conversation-chat-area.component.d.ts.map +1 -1
  14. package/dist/lib/components/conversation/conversation-chat-area.component.js +3002 -661
  15. package/dist/lib/components/conversation/conversation-chat-area.component.js.map +1 -1
  16. package/dist/lib/components/conversation/forks-popover.component.d.ts +37 -0
  17. package/dist/lib/components/conversation/forks-popover.component.d.ts.map +1 -0
  18. package/dist/lib/components/conversation/forks-popover.component.js +164 -0
  19. package/dist/lib/components/conversation/forks-popover.component.js.map +1 -0
  20. package/dist/lib/components/export/export-modal.component.d.ts +7 -2
  21. package/dist/lib/components/export/export-modal.component.d.ts.map +1 -1
  22. package/dist/lib/components/export/export-modal.component.js +16 -3
  23. package/dist/lib/components/export/export-modal.component.js.map +1 -1
  24. package/dist/lib/components/message/conversation-message-rating.component.d.ts.map +1 -1
  25. package/dist/lib/components/message/conversation-message-rating.component.js +11 -9
  26. package/dist/lib/components/message/conversation-message-rating.component.js.map +1 -1
  27. package/dist/lib/components/message/message-input.component.d.ts +96 -11
  28. package/dist/lib/components/message/message-input.component.d.ts.map +1 -1
  29. package/dist/lib/components/message/message-input.component.js +253 -112
  30. package/dist/lib/components/message/message-input.component.js.map +1 -1
  31. package/dist/lib/components/message/message-item.component.d.ts +304 -16
  32. package/dist/lib/components/message/message-item.component.d.ts.map +1 -1
  33. package/dist/lib/components/message/message-item.component.js +2029 -363
  34. package/dist/lib/components/message/message-item.component.js.map +1 -1
  35. package/dist/lib/components/message/message-list.component.d.ts +101 -22
  36. package/dist/lib/components/message/message-list.component.d.ts.map +1 -1
  37. package/dist/lib/components/message/message-list.component.js +326 -55
  38. package/dist/lib/components/message/message-list.component.js.map +1 -1
  39. package/dist/lib/components/realtime/avatar/realtime-avatar-channel.d.ts +34 -0
  40. package/dist/lib/components/realtime/avatar/realtime-avatar-channel.d.ts.map +1 -0
  41. package/dist/lib/components/realtime/avatar/realtime-avatar-channel.js +75 -0
  42. package/dist/lib/components/realtime/avatar/realtime-avatar-channel.js.map +1 -0
  43. package/dist/lib/components/realtime/avatar/realtime-avatar-surface.component.d.ts +80 -0
  44. package/dist/lib/components/realtime/avatar/realtime-avatar-surface.component.d.ts.map +1 -0
  45. package/dist/lib/components/realtime/avatar/realtime-avatar-surface.component.js +202 -0
  46. package/dist/lib/components/realtime/avatar/realtime-avatar-surface.component.js.map +1 -0
  47. package/dist/lib/components/realtime/capture/realtime-camera-check-card.component.d.ts +45 -0
  48. package/dist/lib/components/realtime/capture/realtime-camera-check-card.component.d.ts.map +1 -0
  49. package/dist/lib/components/realtime/capture/realtime-camera-check-card.component.js +123 -0
  50. package/dist/lib/components/realtime/capture/realtime-camera-check-card.component.js.map +1 -0
  51. package/dist/lib/components/realtime/capture/realtime-capture-channel.d.ts +90 -0
  52. package/dist/lib/components/realtime/capture/realtime-capture-channel.d.ts.map +1 -0
  53. package/dist/lib/components/realtime/capture/realtime-capture-channel.js +223 -0
  54. package/dist/lib/components/realtime/capture/realtime-capture-channel.js.map +1 -0
  55. package/dist/lib/components/realtime/capture/realtime-capture-model.d.ts +98 -0
  56. package/dist/lib/components/realtime/capture/realtime-capture-model.d.ts.map +1 -0
  57. package/dist/lib/components/realtime/capture/realtime-capture-model.js +161 -0
  58. package/dist/lib/components/realtime/capture/realtime-capture-model.js.map +1 -0
  59. package/dist/lib/components/realtime/capture/realtime-capture-surface.component.d.ts +48 -0
  60. package/dist/lib/components/realtime/capture/realtime-capture-surface.component.d.ts.map +1 -0
  61. package/dist/lib/components/realtime/capture/realtime-capture-surface.component.js +205 -0
  62. package/dist/lib/components/realtime/capture/realtime-capture-surface.component.js.map +1 -0
  63. package/dist/lib/components/realtime/channels/client-context-channel.d.ts +19 -2
  64. package/dist/lib/components/realtime/channels/client-context-channel.d.ts.map +1 -1
  65. package/dist/lib/components/realtime/channels/client-context-channel.js +83 -9
  66. package/dist/lib/components/realtime/channels/client-context-channel.js.map +1 -1
  67. package/dist/lib/components/realtime/channels/realtime-channel-pane.component.d.ts +30 -9
  68. package/dist/lib/components/realtime/channels/realtime-channel-pane.component.d.ts.map +1 -1
  69. package/dist/lib/components/realtime/channels/realtime-channel-pane.component.js +78 -14
  70. package/dist/lib/components/realtime/channels/realtime-channel-pane.component.js.map +1 -1
  71. package/dist/lib/components/realtime/identity-verification/identity-verification-channel.d.ts +71 -0
  72. package/dist/lib/components/realtime/identity-verification/identity-verification-channel.d.ts.map +1 -0
  73. package/dist/lib/components/realtime/identity-verification/identity-verification-channel.js +259 -0
  74. package/dist/lib/components/realtime/identity-verification/identity-verification-channel.js.map +1 -0
  75. package/dist/lib/components/realtime/identity-verification/identity-verification-model.d.ts +129 -0
  76. package/dist/lib/components/realtime/identity-verification/identity-verification-model.d.ts.map +1 -0
  77. package/dist/lib/components/realtime/identity-verification/identity-verification-model.js +373 -0
  78. package/dist/lib/components/realtime/identity-verification/identity-verification-model.js.map +1 -0
  79. package/dist/lib/components/realtime/identity-verification/identity-verification-surface.component.d.ts +77 -0
  80. package/dist/lib/components/realtime/identity-verification/identity-verification-surface.component.d.ts.map +1 -0
  81. package/dist/lib/components/realtime/identity-verification/identity-verification-surface.component.js +420 -0
  82. package/dist/lib/components/realtime/identity-verification/identity-verification-surface.component.js.map +1 -0
  83. package/dist/lib/components/realtime/interactive-component/component-contract.d.ts +83 -0
  84. package/dist/lib/components/realtime/interactive-component/component-contract.d.ts.map +1 -0
  85. package/dist/lib/components/realtime/interactive-component/component-contract.js +292 -0
  86. package/dist/lib/components/realtime/interactive-component/component-contract.js.map +1 -0
  87. package/dist/lib/components/realtime/interactive-component/component-data-state.d.ts +39 -0
  88. package/dist/lib/components/realtime/interactive-component/component-data-state.d.ts.map +1 -0
  89. package/dist/lib/components/realtime/interactive-component/component-data-state.js +152 -0
  90. package/dist/lib/components/realtime/interactive-component/component-data-state.js.map +1 -0
  91. package/dist/lib/components/realtime/interactive-component/component-instance-engine.d.ts +109 -0
  92. package/dist/lib/components/realtime/interactive-component/component-instance-engine.d.ts.map +1 -0
  93. package/dist/lib/components/realtime/interactive-component/component-instance-engine.js +146 -0
  94. package/dist/lib/components/realtime/interactive-component/component-instance-engine.js.map +1 -0
  95. package/dist/lib/components/realtime/interactive-component/component-spec-content.d.ts +19 -0
  96. package/dist/lib/components/realtime/interactive-component/component-spec-content.d.ts.map +1 -0
  97. package/dist/lib/components/realtime/interactive-component/component-spec-content.js +39 -0
  98. package/dist/lib/components/realtime/interactive-component/component-spec-content.js.map +1 -0
  99. package/dist/lib/components/realtime/interactive-component/interactive-component-channel.d.ts +183 -0
  100. package/dist/lib/components/realtime/interactive-component/interactive-component-channel.d.ts.map +1 -0
  101. package/dist/lib/components/realtime/interactive-component/interactive-component-channel.js +761 -0
  102. package/dist/lib/components/realtime/interactive-component/interactive-component-channel.js.map +1 -0
  103. package/dist/lib/components/realtime/interactive-component/interactive-component-config.d.ts +25 -0
  104. package/dist/lib/components/realtime/interactive-component/interactive-component-config.d.ts.map +1 -0
  105. package/dist/lib/components/realtime/interactive-component/interactive-component-config.js +57 -0
  106. package/dist/lib/components/realtime/interactive-component/interactive-component-config.js.map +1 -0
  107. package/dist/lib/components/realtime/interactive-component/interactive-component-host.component.d.ts +40 -0
  108. package/dist/lib/components/realtime/interactive-component/interactive-component-host.component.d.ts.map +1 -0
  109. package/dist/lib/components/realtime/interactive-component/interactive-component-host.component.js +97 -0
  110. package/dist/lib/components/realtime/interactive-component/interactive-component-host.component.js.map +1 -0
  111. package/dist/lib/components/realtime/interactive-component/interactive-component-types.d.ts +144 -0
  112. package/dist/lib/components/realtime/interactive-component/interactive-component-types.d.ts.map +1 -0
  113. package/dist/lib/components/realtime/interactive-component/interactive-component-types.js +57 -0
  114. package/dist/lib/components/realtime/interactive-component/interactive-component-types.js.map +1 -0
  115. package/dist/lib/components/realtime/interactive-component/react-component-handle.d.ts +36 -0
  116. package/dist/lib/components/realtime/interactive-component/react-component-handle.d.ts.map +1 -0
  117. package/dist/lib/components/realtime/interactive-component/react-component-handle.js +55 -0
  118. package/dist/lib/components/realtime/interactive-component/react-component-handle.js.map +1 -0
  119. package/dist/lib/components/realtime/interactive-component/realtime-interactive-component-surface.component.d.ts +55 -0
  120. package/dist/lib/components/realtime/interactive-component/realtime-interactive-component-surface.component.d.ts.map +1 -0
  121. package/dist/lib/components/realtime/interactive-component/realtime-interactive-component-surface.component.js +210 -0
  122. package/dist/lib/components/realtime/interactive-component/realtime-interactive-component-surface.component.js.map +1 -0
  123. package/dist/lib/components/realtime/interactive-component/run-view-component-artifact-source.d.ts +32 -0
  124. package/dist/lib/components/realtime/interactive-component/run-view-component-artifact-source.d.ts.map +1 -0
  125. package/dist/lib/components/realtime/interactive-component/run-view-component-artifact-source.js +90 -0
  126. package/dist/lib/components/realtime/interactive-component/run-view-component-artifact-source.js.map +1 -0
  127. package/dist/lib/components/realtime/media/media-channel.d.ts +7 -0
  128. package/dist/lib/components/realtime/media/media-channel.d.ts.map +1 -1
  129. package/dist/lib/components/realtime/media/media-channel.js +28 -1
  130. package/dist/lib/components/realtime/media/media-channel.js.map +1 -1
  131. package/dist/lib/components/realtime/realtime-agent-banner.component.d.ts +8 -1
  132. package/dist/lib/components/realtime/realtime-agent-banner.component.d.ts.map +1 -1
  133. package/dist/lib/components/realtime/realtime-agent-banner.component.js +89 -71
  134. package/dist/lib/components/realtime/realtime-agent-banner.component.js.map +1 -1
  135. package/dist/lib/components/realtime/realtime-agent-orb.component.d.ts +21 -0
  136. package/dist/lib/components/realtime/realtime-agent-orb.component.d.ts.map +1 -0
  137. package/dist/lib/components/realtime/realtime-agent-orb.component.js +49 -0
  138. package/dist/lib/components/realtime/realtime-agent-orb.component.js.map +1 -0
  139. package/dist/lib/components/realtime/realtime-agent-picker.component.d.ts +44 -11
  140. package/dist/lib/components/realtime/realtime-agent-picker.component.d.ts.map +1 -1
  141. package/dist/lib/components/realtime/realtime-agent-picker.component.js +162 -50
  142. package/dist/lib/components/realtime/realtime-agent-picker.component.js.map +1 -1
  143. package/dist/lib/components/realtime/realtime-audio-visuals.d.ts +8 -2
  144. package/dist/lib/components/realtime/realtime-audio-visuals.d.ts.map +1 -1
  145. package/dist/lib/components/realtime/realtime-audio-visuals.js +14 -18
  146. package/dist/lib/components/realtime/realtime-audio-visuals.js.map +1 -1
  147. package/dist/lib/components/realtime/realtime-composer.component.d.ts +42 -2
  148. package/dist/lib/components/realtime/realtime-composer.component.d.ts.map +1 -1
  149. package/dist/lib/components/realtime/realtime-composer.component.js +137 -102
  150. package/dist/lib/components/realtime/realtime-composer.component.js.map +1 -1
  151. package/dist/lib/components/realtime/realtime-perception-chip.component.d.ts +71 -0
  152. package/dist/lib/components/realtime/realtime-perception-chip.component.d.ts.map +1 -0
  153. package/dist/lib/components/realtime/realtime-perception-chip.component.js +221 -0
  154. package/dist/lib/components/realtime/realtime-perception-chip.component.js.map +1 -0
  155. package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts +264 -22
  156. package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts.map +1 -1
  157. package/dist/lib/components/realtime/realtime-session-overlay.component.js +851 -135
  158. package/dist/lib/components/realtime/realtime-session-overlay.component.js.map +1 -1
  159. package/dist/lib/components/realtime/realtime-surface-placement-prefs.d.ts +14 -0
  160. package/dist/lib/components/realtime/realtime-surface-placement-prefs.d.ts.map +1 -0
  161. package/dist/lib/components/realtime/realtime-surface-placement-prefs.js +14 -0
  162. package/dist/lib/components/realtime/realtime-surface-placement-prefs.js.map +1 -0
  163. package/dist/lib/components/realtime/realtime-surface-stage.model.d.ts +74 -0
  164. package/dist/lib/components/realtime/realtime-surface-stage.model.d.ts.map +1 -0
  165. package/dist/lib/components/realtime/realtime-surface-stage.model.js +171 -0
  166. package/dist/lib/components/realtime/realtime-surface-stage.model.js.map +1 -0
  167. package/dist/lib/components/realtime/realtime-surface-tabs.component.d.ts +71 -13
  168. package/dist/lib/components/realtime/realtime-surface-tabs.component.d.ts.map +1 -1
  169. package/dist/lib/components/realtime/realtime-surface-tabs.component.js +232 -73
  170. package/dist/lib/components/realtime/realtime-surface-tabs.component.js.map +1 -1
  171. package/dist/lib/components/realtime/realtime-surface-tabs.model.d.ts +5 -0
  172. package/dist/lib/components/realtime/realtime-surface-tabs.model.d.ts.map +1 -1
  173. package/dist/lib/components/realtime/realtime-surface-tabs.model.js +8 -0
  174. package/dist/lib/components/realtime/realtime-surface-tabs.model.js.map +1 -1
  175. package/dist/lib/components/realtime/realtime-ui-config.d.ts +12 -2
  176. package/dist/lib/components/realtime/realtime-ui-config.d.ts.map +1 -1
  177. package/dist/lib/components/realtime/realtime-ui-config.js +5 -1
  178. package/dist/lib/components/realtime/realtime-ui-config.js.map +1 -1
  179. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.d.ts +10 -1
  180. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.d.ts.map +1 -1
  181. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js +42 -2
  182. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js.map +1 -1
  183. package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.d.ts +20 -3
  184. package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.d.ts.map +1 -1
  185. package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.js +44 -10
  186. package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.js.map +1 -1
  187. package/dist/lib/components/realtime/whiteboard/whiteboard-channel.d.ts +28 -44
  188. package/dist/lib/components/realtime/whiteboard/whiteboard-channel.d.ts.map +1 -1
  189. package/dist/lib/components/realtime/whiteboard/whiteboard-channel.js +76 -162
  190. package/dist/lib/components/realtime/whiteboard/whiteboard-channel.js.map +1 -1
  191. package/dist/lib/components/search/search-panel.component.d.ts +2 -0
  192. package/dist/lib/components/search/search-panel.component.d.ts.map +1 -1
  193. package/dist/lib/components/search/search-panel.component.js +25 -12
  194. package/dist/lib/components/search/search-panel.component.js.map +1 -1
  195. package/dist/lib/components/sidebar/routines-section.component.js +1 -1
  196. package/dist/lib/components/sidebar/routines-section.component.js.map +1 -1
  197. package/dist/lib/components/task/tasks-full-view.component.d.ts +152 -31
  198. package/dist/lib/components/task/tasks-full-view.component.d.ts.map +1 -1
  199. package/dist/lib/components/task/tasks-full-view.component.js +2227 -214
  200. package/dist/lib/components/task/tasks-full-view.component.js.map +1 -1
  201. package/dist/lib/components/tasks/tasks-dropdown.component.js +4 -4
  202. package/dist/lib/components/tasks/tasks-dropdown.component.js.map +1 -1
  203. package/dist/lib/components/workspace/conversation-workspace.component.d.ts +33 -32
  204. package/dist/lib/components/workspace/conversation-workspace.component.d.ts.map +1 -1
  205. package/dist/lib/components/workspace/conversation-workspace.component.js +72 -88
  206. package/dist/lib/components/workspace/conversation-workspace.component.js.map +1 -1
  207. package/dist/lib/conversations.module.d.ts +30 -29
  208. package/dist/lib/conversations.module.d.ts.map +1 -1
  209. package/dist/lib/conversations.module.js +27 -5
  210. package/dist/lib/conversations.module.js.map +1 -1
  211. package/dist/lib/events/chat-events.d.ts +25 -0
  212. package/dist/lib/events/chat-events.d.ts.map +1 -1
  213. package/dist/lib/events/chat-events.js +36 -0
  214. package/dist/lib/events/chat-events.js.map +1 -1
  215. package/dist/lib/models/agent-turn.model.d.ts +5 -0
  216. package/dist/lib/models/agent-turn.model.d.ts.map +1 -1
  217. package/dist/lib/models/agent-turn.model.js.map +1 -1
  218. package/dist/lib/services/agent-state.service.d.ts +34 -8
  219. package/dist/lib/services/agent-state.service.d.ts.map +1 -1
  220. package/dist/lib/services/agent-state.service.js +90 -37
  221. package/dist/lib/services/agent-state.service.js.map +1 -1
  222. package/dist/lib/services/artifact-state.service.d.ts +0 -9
  223. package/dist/lib/services/artifact-state.service.d.ts.map +1 -1
  224. package/dist/lib/services/artifact-state.service.js +1 -32
  225. package/dist/lib/services/artifact-state.service.js.map +1 -1
  226. package/dist/lib/services/browser-realtime-media-host.d.ts +19 -7
  227. package/dist/lib/services/browser-realtime-media-host.d.ts.map +1 -1
  228. package/dist/lib/services/browser-realtime-media-host.js +21 -72
  229. package/dist/lib/services/browser-realtime-media-host.js.map +1 -1
  230. package/dist/lib/services/conversation-agent.service.d.ts +48 -16
  231. package/dist/lib/services/conversation-agent.service.d.ts.map +1 -1
  232. package/dist/lib/services/conversation-agent.service.js +110 -35
  233. package/dist/lib/services/conversation-agent.service.js.map +1 -1
  234. package/dist/lib/services/conversation-detail-window.store.d.ts +22 -4
  235. package/dist/lib/services/conversation-detail-window.store.d.ts.map +1 -1
  236. package/dist/lib/services/conversation-detail-window.store.js +50 -9
  237. package/dist/lib/services/conversation-detail-window.store.js.map +1 -1
  238. package/dist/lib/services/conversation-naming.d.ts +72 -22
  239. package/dist/lib/services/conversation-naming.d.ts.map +1 -1
  240. package/dist/lib/services/conversation-naming.js +93 -12
  241. package/dist/lib/services/conversation-naming.js.map +1 -1
  242. package/dist/lib/services/conversation-tasks-filter.d.ts +15 -0
  243. package/dist/lib/services/conversation-tasks-filter.d.ts.map +1 -0
  244. package/dist/lib/services/conversation-tasks-filter.js +69 -0
  245. package/dist/lib/services/conversation-tasks-filter.js.map +1 -0
  246. package/dist/lib/services/data-cache.service.d.ts +13 -5
  247. package/dist/lib/services/data-cache.service.d.ts.map +1 -1
  248. package/dist/lib/services/data-cache.service.js +39 -19
  249. package/dist/lib/services/data-cache.service.js.map +1 -1
  250. package/dist/lib/services/export.service.d.ts +26 -9
  251. package/dist/lib/services/export.service.d.ts.map +1 -1
  252. package/dist/lib/services/export.service.js +61 -18
  253. package/dist/lib/services/export.service.js.map +1 -1
  254. package/dist/lib/services/realtime-audio-recorder.d.ts +115 -79
  255. package/dist/lib/services/realtime-audio-recorder.d.ts.map +1 -1
  256. package/dist/lib/services/realtime-audio-recorder.js +273 -186
  257. package/dist/lib/services/realtime-audio-recorder.js.map +1 -1
  258. package/dist/lib/services/realtime-pairing.d.ts +10 -5
  259. package/dist/lib/services/realtime-pairing.d.ts.map +1 -1
  260. package/dist/lib/services/realtime-pairing.js +15 -6
  261. package/dist/lib/services/realtime-pairing.js.map +1 -1
  262. package/dist/lib/services/realtime-session.service.d.ts +31 -2
  263. package/dist/lib/services/realtime-session.service.d.ts.map +1 -1
  264. package/dist/lib/services/realtime-session.service.js +34 -2
  265. package/dist/lib/services/realtime-session.service.js.map +1 -1
  266. package/dist/lib/services/recording/libopus-wasm-binary.d.ts +3 -0
  267. package/dist/lib/services/recording/libopus-wasm-binary.d.ts.map +1 -0
  268. package/dist/lib/services/recording/libopus-wasm-binary.js +489 -0
  269. package/dist/lib/services/recording/libopus-wasm-binary.js.map +1 -0
  270. package/dist/lib/services/recording/libopus-worker-source.d.ts +48 -0
  271. package/dist/lib/services/recording/libopus-worker-source.d.ts.map +1 -0
  272. package/dist/lib/services/recording/libopus-worker-source.js +170 -0
  273. package/dist/lib/services/recording/libopus-worker-source.js.map +1 -0
  274. package/dist/lib/services/recording/linear-resampler.d.ts +45 -0
  275. package/dist/lib/services/recording/linear-resampler.d.ts.map +1 -0
  276. package/dist/lib/services/recording/linear-resampler.js +85 -0
  277. package/dist/lib/services/recording/linear-resampler.js.map +1 -0
  278. package/dist/lib/services/recording/opus-packet-encoder.d.ts +50 -0
  279. package/dist/lib/services/recording/opus-packet-encoder.d.ts.map +1 -0
  280. package/dist/lib/services/recording/opus-packet-encoder.js +41 -0
  281. package/dist/lib/services/recording/opus-packet-encoder.js.map +1 -0
  282. package/dist/lib/services/recording/wasm-opus-encoder.d.ts +86 -0
  283. package/dist/lib/services/recording/wasm-opus-encoder.d.ts.map +1 -0
  284. package/dist/lib/services/recording/wasm-opus-encoder.js +232 -0
  285. package/dist/lib/services/recording/wasm-opus-encoder.js.map +1 -0
  286. package/dist/lib/services/recording/webcodecs-opus-encoder.d.ts +39 -0
  287. package/dist/lib/services/recording/webcodecs-opus-encoder.d.ts.map +1 -0
  288. package/dist/lib/services/recording/webcodecs-opus-encoder.js +101 -0
  289. package/dist/lib/services/recording/webcodecs-opus-encoder.js.map +1 -0
  290. package/dist/lib/services/search.service.d.ts +7 -2
  291. package/dist/lib/services/search.service.d.ts.map +1 -1
  292. package/dist/lib/services/search.service.js +16 -20
  293. package/dist/lib/services/search.service.js.map +1 -1
  294. package/dist/lib/utils/conversation-branching.d.ts +4 -0
  295. package/dist/lib/utils/conversation-branching.d.ts.map +1 -0
  296. package/dist/lib/utils/conversation-branching.js +5 -0
  297. package/dist/lib/utils/conversation-branching.js.map +1 -0
  298. package/dist/lib/utils/conversation-forks.d.ts +315 -0
  299. package/dist/lib/utils/conversation-forks.d.ts.map +1 -0
  300. package/dist/lib/utils/conversation-forks.js +456 -0
  301. package/dist/lib/utils/conversation-forks.js.map +1 -0
  302. package/dist/lib/utils/distinct-artifacts.d.ts +9 -3
  303. package/dist/lib/utils/distinct-artifacts.d.ts.map +1 -1
  304. package/dist/lib/utils/distinct-artifacts.js +24 -5
  305. package/dist/lib/utils/distinct-artifacts.js.map +1 -1
  306. package/dist/public-api.d.ts +23 -1
  307. package/dist/public-api.d.ts.map +1 -1
  308. package/dist/public-api.js +30 -1
  309. package/dist/public-api.js.map +1 -1
  310. package/package.json +37 -33
  311. package/dist/lib/components/thread/thread-panel.component.d.ts +0 -126
  312. package/dist/lib/components/thread/thread-panel.component.d.ts.map +0 -1
  313. package/dist/lib/components/thread/thread-panel.component.js +0 -440
  314. package/dist/lib/components/thread/thread-panel.component.js.map +0 -1
  315. package/dist/lib/services/realtime-pcm-wav.d.ts +0 -79
  316. package/dist/lib/services/realtime-pcm-wav.d.ts.map +0 -1
  317. package/dist/lib/services/realtime-pcm-wav.js +0 -213
  318. package/dist/lib/services/realtime-pcm-wav.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"agent-turn.model.js","sourceRoot":"","sources":["../../../src/lib/models/agent-turn.model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG","sourcesContent":["/**\n * @fileoverview The host-facing contract for an agent turn in `mj-conversation-chat-area`.\n *\n * An agent turn is what may follow a person's saved message. The chat area picks one agent by a\n * fixed order of routes, announces the turn with `BeforeAgentTurn` (which a host can cancel or\n * redirect), and then runs it: on MJ's own path, or on the host's server through an\n * {@link AgentTurnHandler}. These types are what a host reads and writes along the way.\n *\n * @module @memberjunction/ng-conversations\n */\n\nimport type { ExecuteAgentResult } from '@memberjunction/ai-core-plus';\n\n/**\n * When a message starts an agent turn.\n *\n * - `Always` (the default): every message does, as it always has.\n * - `MentionOnly`: only a message that tags an agent does. Any other message is posted with no\n * turn at all: no reply row, no placeholder and no turn events.\n */\nexport type AgentReplyMode = 'Always' | 'MentionOnly';\n\n/**\n * How the turn's agent was chosen. MJ tries the routes in this order and takes the first that\n * applies; under `MentionOnly`, only `Mention` applies.\n *\n * - `Mention`: the message tags the agent.\n * - `Continuity`: the last agent that answered in the conversation, other than the\n * conversation manager.\n * - `DecisionRouted`: another agent in the conversation, which a confident routing decision chose\n * in continuity's place. Only with the chat's `EnableDecisionRouting` on.\n * - `ConversationDefault`: the agent pinned on the conversation (`Conversation.DefaultAgentID`).\n * - `HostDefault`: the host's `DefaultAgentId` input.\n * - `ConversationManager`: MJ's conversation manager agent (Sage unless configured otherwise),\n * which may delegate to another agent.\n * - `Redirect`: a `BeforeAgentTurn` listener sent the turn to a different agent.\n */\nexport type AgentTurnRoute =\n | 'Mention'\n | 'Continuity'\n | 'DecisionRouted'\n | 'ConversationDefault'\n | 'HostDefault'\n | 'ConversationManager'\n | 'Redirect';\n\n/** The agent a turn resolved to, and the route that chose it. */\nexport interface AgentTurnTarget {\n /** The agent that takes the turn. */\n AgentId: string;\n /** How the agent was chosen. */\n Route: AgentTurnRoute;\n}\n\n/** What `BeforeAgentTurn` tells its listeners about the turn it announces. */\nexport interface AgentTurnInfo extends AgentTurnTarget {\n /** The agent's name, when MJ knows it. */\n AgentName: string | null;\n /** The person's saved message that the turn answers. */\n UserMessageId: string | null;\n}\n\n/**\n * Everything the chat area knows about a turn it hands to an {@link AgentTurnHandler}.\n * No reply row exists yet when the handler is called.\n */\nexport interface AgentTurnRequest {\n /** The conversation the message was posted in. */\n ConversationId: string;\n /** The person's saved message (`MJ: Conversation Details`, Role `User`). */\n UserMessageId: string;\n /** The message text, with mentions in their stored JSON form. */\n MessageText: string;\n /** The agent the turn resolved to, after any redirect. */\n AgentId: string;\n /** The agent's name, when MJ knows it. */\n AgentName: string | null;\n /** How the agent was chosen. */\n Route: AgentTurnRoute;\n /** The chat area's `ApplicationId` input. */\n ApplicationId: string | null;\n /** The chat area's `AppContext` input. */\n AppContext: Record<string, unknown> | null;\n /** The chat area's `AgentHistoryFrom` input: the first moment of the conversation the turn may read. */\n AgentHistoryFrom: Date | null;\n /**\n * The agent configuration preset (`MJ: AI Agent Configurations.ID`) the person chose: the one\n * on the mention for a `Mention` turn, otherwise the header mode picker's selection.\n */\n ConfigurationPresetId: string | null;\n /** Skills the person asked for with `/skill` in this message. */\n RequestedSkillIDs: string[];\n /** Whether Plan Mode is on for the conversation. */\n PlanMode: boolean;\n /**\n * The artifact version (`MJ: Artifact Versions.ID`) the message modifies, when the chat's\n * routing decision (`EnableDecisionRouting`) confidently named one this agent produced. MJ's\n * own path continues from that version instead of the agent's latest output. Null otherwise.\n */\n TargetArtifactVersionId: string | null;\n}\n\n/** What an {@link AgentTurnHandler} reports back to the chat area. */\nexport interface AgentTurnResult {\n /** False when the turn failed. The chat area shows {@link ErrorMessage} and writes nothing. */\n Success: boolean;\n /** Why the turn failed, shown to the person. */\n ErrorMessage?: string;\n /**\n * The rows the host wrote for the turn, oldest first: the agent's reply and any status rows.\n * The chat area loads and shows them. A row still `In-Progress` is followed like any other\n * in-progress reply. The host reports that row's live status through `AgentRunStatusPublisher`\n * (`@memberjunction/server`) on the caller's session: significant-step progress, streamed text,\n * the partial result, and the completion. The completion's `conversationDetailId` is the reply row.\n */\n ReplyDetailIds?: string[];\n /** The agent run, when the host has one. Carried on `AfterAgentTurn`. */\n AgentRunId?: string;\n /** The agent's result, when the host has one. `AfterAgentTurn` fires only when it's present. */\n Result?: ExecuteAgentResult;\n}\n\n/**\n * Runs an agent turn on the host's server instead of MJ's own path. The chat area calls it once\n * per turn, after `BeforeAgentTurn` and before any reply row exists, and shows the rows it reports.\n */\nexport type AgentTurnHandler = (request: AgentTurnRequest) => Promise<AgentTurnResult>;\n"]}
1
+ {"version":3,"file":"agent-turn.model.js","sourceRoot":"","sources":["../../../src/lib/models/agent-turn.model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG","sourcesContent":["/**\n * @fileoverview The host-facing contract for an agent turn in `mj-conversation-chat-area`.\n *\n * An agent turn is what may follow a person's saved message. The chat area picks one agent by a\n * fixed order of routes, announces the turn with `BeforeAgentTurn` (which a host can cancel or\n * redirect), and then runs it: on MJ's own path, or on the host's server through an\n * {@link AgentTurnHandler}. These types are what a host reads and writes along the way.\n *\n * @module @memberjunction/ng-conversations\n */\n\nimport type { ExecuteAgentResult } from '@memberjunction/ai-core-plus';\n\n/**\n * When a message starts an agent turn.\n *\n * - `Always` (the default): every message does, as it always has.\n * - `MentionOnly`: only a message that tags an agent does. Any other message is posted with no\n * turn at all: no reply row, no placeholder and no turn events.\n */\nexport type AgentReplyMode = 'Always' | 'MentionOnly';\n\n/**\n * How the turn's agent was chosen. MJ tries the routes in this order and takes the first that\n * applies; under `MentionOnly`, only `Mention` applies.\n *\n * - `Mention`: the message tags the agent.\n * - `Continuity`: the last agent that answered in the conversation, other than the\n * conversation manager.\n * - `DecisionRouted`: another agent in the conversation, which a confident routing decision chose\n * in continuity's place. Only with the chat's `EnableDecisionRouting` on.\n * - `ConversationDefault`: the agent pinned on the conversation (`Conversation.DefaultAgentID`).\n * - `HostDefault`: the host's `DefaultAgentId` input.\n * - `ConversationManager`: MJ's conversation manager agent (Sage unless configured otherwise),\n * which may delegate to another agent.\n * - `Redirect`: a `BeforeAgentTurn` listener sent the turn to a different agent.\n */\nexport type AgentTurnRoute =\n | 'Mention'\n | 'Continuity'\n | 'DecisionRouted'\n | 'ConversationDefault'\n | 'HostDefault'\n | 'ConversationManager'\n | 'Redirect';\n\n/** The agent a turn resolved to, and the route that chose it. */\nexport interface AgentTurnTarget {\n /** The agent that takes the turn. */\n AgentId: string;\n /** How the agent was chosen. */\n Route: AgentTurnRoute;\n}\n\n/** What `BeforeAgentTurn` tells its listeners about the turn it announces. */\nexport interface AgentTurnInfo extends AgentTurnTarget {\n /** The agent's name, when MJ knows it. */\n AgentName: string | null;\n /** The person's saved message that the turn answers. */\n UserMessageId: string | null;\n}\n\n/**\n * Everything the chat area knows about a turn it hands to an {@link AgentTurnHandler}.\n * No reply row exists yet when the handler is called.\n */\nexport interface AgentTurnRequest {\n /** The conversation the message was posted in. */\n ConversationId: string;\n /**\n * The fork the turn's rows go to; null is Main. A handler that writes conversation rows sets this\n * BranchID on them.\n */\n BranchID: string | null;\n /** The person's saved message (`MJ: Conversation Details`, Role `User`). */\n UserMessageId: string;\n /** The message text, with mentions in their stored JSON form. */\n MessageText: string;\n /** The agent the turn resolved to, after any redirect. */\n AgentId: string;\n /** The agent's name, when MJ knows it. */\n AgentName: string | null;\n /** How the agent was chosen. */\n Route: AgentTurnRoute;\n /** The chat area's `ApplicationId` input. */\n ApplicationId: string | null;\n /** The chat area's `AppContext` input. */\n AppContext: Record<string, unknown> | null;\n /** The chat area's `AgentHistoryFrom` input: the first moment of the conversation the turn may read. */\n AgentHistoryFrom: Date | null;\n /**\n * The agent configuration preset (`MJ: AI Agent Configurations.ID`) the person chose: the one\n * on the mention for a `Mention` turn, otherwise the header mode picker's selection.\n */\n ConfigurationPresetId: string | null;\n /** Skills the person asked for with `/skill` in this message. */\n RequestedSkillIDs: string[];\n /** Whether Plan Mode is on for the conversation. */\n PlanMode: boolean;\n /**\n * The artifact version (`MJ: Artifact Versions.ID`) the message modifies, when the chat's\n * routing decision (`EnableDecisionRouting`) confidently named one this agent produced. MJ's\n * own path continues from that version instead of the agent's latest output. Null otherwise.\n */\n TargetArtifactVersionId: string | null;\n}\n\n/** What an {@link AgentTurnHandler} reports back to the chat area. */\nexport interface AgentTurnResult {\n /** False when the turn failed. The chat area shows {@link ErrorMessage} and writes nothing. */\n Success: boolean;\n /** Why the turn failed, shown to the person. */\n ErrorMessage?: string;\n /**\n * The rows the host wrote for the turn, oldest first: the agent's reply and any status rows.\n * The chat area loads and shows them. A row still `In-Progress` is followed like any other\n * in-progress reply. The host reports that row's live status through `AgentRunStatusPublisher`\n * (`@memberjunction/server`) on the caller's session: significant-step progress, streamed text,\n * the partial result, and the completion. The completion's `conversationDetailId` is the reply row.\n */\n ReplyDetailIds?: string[];\n /** The agent run, when the host has one. Carried on `AfterAgentTurn`. */\n AgentRunId?: string;\n /** The agent's result, when the host has one. `AfterAgentTurn` fires only when it's present. */\n Result?: ExecuteAgentResult;\n}\n\n/**\n * Runs an agent turn on the host's server instead of MJ's own path. The chat area calls it once\n * per turn, after `BeforeAgentTurn` and before any reply row exists, and shows the rows it reports.\n */\nexport type AgentTurnHandler = (request: AgentTurnRequest) => Promise<AgentTurnResult>;\n"]}
@@ -1,7 +1,7 @@
1
1
  import { OnDestroy } from '@angular/core';
2
2
  import { Observable } from 'rxjs';
3
3
  import { UserInfo, IMetadataProvider } from '@memberjunction/core';
4
- import { MJAIAgentRunEntity } from '@memberjunction/core-entities';
4
+ import { MJAIAgentRunEntity, type ConversationScope } from '@memberjunction/core-entities';
5
5
  import * as i0 from "@angular/core";
6
6
  export type AgentStatus = 'acknowledging' | 'working' | 'completing' | 'completed' | 'error';
7
7
  export interface AgentWithStatus {
@@ -17,6 +17,9 @@ export declare class AgentStateService implements OnDestroy {
17
17
  private _activeAgents$;
18
18
  private pollSubscription?;
19
19
  private currentUser?;
20
+ /** The conversation and scope polling was started with, so a restart (SetPollInterval) keeps them. */
21
+ private pollConversationId?;
22
+ private pollScope;
20
23
  private pollInterval;
21
24
  private pollCycleCount;
22
25
  /** Minimum poll cycles before allowing auto-stop. Prevents premature shutdown
@@ -37,10 +40,11 @@ export declare class AgentStateService implements OnDestroy {
37
40
  * Starts polling for active agents
38
41
  * @param currentUser The current user context
39
42
  * @param conversationId Optional conversation ID to filter by
43
+ * @param scope The conversation scope whose runs are read; the trunk of `conversationId` when null
40
44
  */
41
- StartPolling(currentUser: UserInfo, conversationId?: string): void;
45
+ StartPolling(currentUser: UserInfo, conversationId?: string, scope?: ConversationScope | null): void;
42
46
  /** @deprecated Use {@link StartPolling}. */
43
- startPolling(currentUser: UserInfo, conversationId?: string): void;
47
+ startPolling(currentUser: UserInfo, conversationId?: string, scope?: ConversationScope | null): void;
44
48
  /**
45
49
  * Stops polling for active agents
46
50
  */
@@ -64,12 +68,15 @@ export declare class AgentStateService implements OnDestroy {
64
68
  /**
65
69
  * Manually refreshes active agents
66
70
  * @param conversationId Optional conversation ID to filter by
71
+ * @param scope The conversation scope whose runs are read; the trunk of `conversationId` when null
67
72
  */
68
- Refresh(conversationId?: string): Promise<void>;
73
+ Refresh(conversationId?: string, scope?: ConversationScope | null): Promise<void>;
69
74
  /** @deprecated Use {@link Refresh}. */
70
- refresh(conversationId?: string): Promise<void>;
75
+ refresh(conversationId?: string, scope?: ConversationScope | null): Promise<void>;
71
76
  /**
72
- * Loads active agents from the database
77
+ * Loads the running and paused agent runs from the database. With a conversation, only runs
78
+ * whose conversation detail is in `scope` (the trunk of `conversationId` when null), plus the
79
+ * conversation's runs that have no conversation detail, which belong to every path.
73
80
  */
74
81
  private loadActiveAgents;
75
82
  /**
@@ -85,10 +92,29 @@ export declare class AgentStateService implements OnDestroy {
85
92
  */
86
93
  private extractConfidence;
87
94
  /**
88
- * Cancels an agent run
89
- * @param agentRunId The agent run ID to cancel
95
+ * Stops an agent run that is still in flight.
96
+ *
97
+ * The run's row is the control channel: this marks it `Cancelled` with reason `User Request`,
98
+ * and the server process that owns the run notices within a few seconds (the agent-run
99
+ * watchdog's cancellation poll), aborts the in-flight step through the run's cancellation
100
+ * token, and finalizes the run — keeping the payload as it stood — and its reply as stopped.
101
+ * No request reaches the running process directly, so this works whichever replica owns it.
102
+ *
103
+ * The row is loaded fresh rather than taken from the polled active-agent list, which refreshes
104
+ * every 30 seconds and may not hold a run that started a moment ago.
105
+ *
106
+ * @returns true when the row was marked; false when the run was not found, had already
107
+ * finished (nothing to stop), or the save was refused.
90
108
  */
91
109
  CancelAgent(agentRunId: string): Promise<boolean>;
110
+ /**
111
+ * Stops the in-flight run behind an agent's reply message, for callers that know the
112
+ * conversation detail but not yet the run (the run row is created a moment after the reply
113
+ * placeholder). Finds the newest Running or Paused run for that detail and stops it.
114
+ *
115
+ * @returns true when a run was found and marked; false otherwise.
116
+ */
117
+ CancelAgentForDetail(conversationDetailId: string): Promise<boolean>;
92
118
  /** @deprecated Use {@link CancelAgent}. */
93
119
  cancelAgent(agentRunId: string): Promise<boolean>;
94
120
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"agent-state.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/agent-state.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAmB,UAAU,EAA0B,MAAM,MAAM,CAAC;AAE3E,OAAO,EAAwB,QAAQ,EAAY,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEnG,OAAO,EAAE,kB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E,MAAM,GAAG,UAAU,CAAC,eAAe,EAAE,CAAC;IAIvE;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIzD,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIzD;;;;OAIG;IACG,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,iBAAiB,GAAG,IAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7F,uCAAuC;IACjC,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,iBAAiB,GAAG,IAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7F;;;;OAIG;YACW,gBAAgB;IAkD9B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAW/B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAoC5B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;;;;;;;;;;;;;OAcG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BvD;;;;;;OAMG;IACG,oBAAoB,CAAC,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAyB1E,2CAA2C;IACrC,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvD;;;OAGG;IACH,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAS3C,+CAA+C;IAC/C,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;yCA7VhC,iBAAiB;6CAAjB,iBAAiB;CAgW7B"}
@@ -2,7 +2,8 @@ import { Injectable } from '@angular/core';
2
2
  import { BehaviorSubject, interval } from 'rxjs';
3
3
  import { map, shareReplay, switchMap } from 'rxjs/operators';
4
4
  import { LogStatusEx, RunView, Metadata } from '@memberjunction/core';
5
- import { UUIDsEqual } from '@memberjunction/global';
5
+ import { EscapeSQLString, UUIDsEqual } from '@memberjunction/global';
6
+ import { ConversationEngine } from '@memberjunction/core-entities';
6
7
  import * as i0 from "@angular/core";
7
8
  /**
8
9
  * Manages agent state and provides real-time updates for active agents
@@ -12,6 +13,9 @@ export class AgentStateService {
12
13
  _activeAgents$ = new BehaviorSubject([]);
13
14
  pollSubscription;
14
15
  currentUser;
16
+ /** The conversation and scope polling was started with, so a restart (SetPollInterval) keeps them. */
17
+ pollConversationId;
18
+ pollScope = null;
15
19
  pollInterval = 30000; // Poll every 30 seconds (reduced from 3s to minimize DB load)
16
20
  pollCycleCount = 0;
17
21
  /** Minimum poll cycles before allowing auto-stop. Prevents premature shutdown
@@ -41,21 +45,24 @@ export class AgentStateService {
41
45
  * Starts polling for active agents
42
46
  * @param currentUser The current user context
43
47
  * @param conversationId Optional conversation ID to filter by
48
+ * @param scope The conversation scope whose runs are read; the trunk of `conversationId` when null
44
49
  */
45
- StartPolling(currentUser, conversationId) {
50
+ StartPolling(currentUser, conversationId, scope = null) {
46
51
  this.currentUser = currentUser;
47
52
  this.StopPolling();
53
+ this.pollConversationId = conversationId;
54
+ this.pollScope = scope;
48
55
  this.pollCycleCount = 0;
49
56
  // Initial load
50
- this.loadActiveAgents(conversationId);
57
+ this.loadActiveAgents(conversationId, scope);
51
58
  // Start polling
52
59
  this.pollSubscription = interval(this.pollInterval)
53
- .pipe(switchMap(() => this.loadActiveAgents(conversationId)))
60
+ .pipe(switchMap(() => this.loadActiveAgents(conversationId, scope)))
54
61
  .subscribe();
55
62
  }
56
63
  /** @deprecated Use {@link StartPolling}. */
57
- startPolling(currentUser, conversationId) {
58
- return this.StartPolling(currentUser, conversationId);
64
+ startPolling(currentUser, conversationId, scope = null) {
65
+ return this.StartPolling(currentUser, conversationId, scope);
59
66
  }
60
67
  /**
61
68
  * Stops polling for active agents
@@ -98,18 +105,21 @@ export class AgentStateService {
98
105
  /**
99
106
  * Manually refreshes active agents
100
107
  * @param conversationId Optional conversation ID to filter by
108
+ * @param scope The conversation scope whose runs are read; the trunk of `conversationId` when null
101
109
  */
102
- async Refresh(conversationId) {
103
- await this.loadActiveAgents(conversationId);
110
+ async Refresh(conversationId, scope = null) {
111
+ await this.loadActiveAgents(conversationId, scope);
104
112
  }
105
113
  /** @deprecated Use {@link Refresh}. */
106
- async refresh(conversationId) {
107
- return this.Refresh(conversationId);
114
+ async refresh(conversationId, scope = null) {
115
+ return this.Refresh(conversationId, scope);
108
116
  }
109
117
  /**
110
- * Loads active agents from the database
118
+ * Loads the running and paused agent runs from the database. With a conversation, only runs
119
+ * whose conversation detail is in `scope` (the trunk of `conversationId` when null), plus the
120
+ * conversation's runs that have no conversation detail, which belong to every path.
111
121
  */
112
- async loadActiveAgents(conversationId) {
122
+ async loadActiveAgents(conversationId, scope = null) {
113
123
  if (!this.currentUser) {
114
124
  return;
115
125
  }
@@ -121,7 +131,8 @@ export class AgentStateService {
121
131
  // Valid statuses: Running, Completed, Paused, Failed, Cancelled
122
132
  let filter = `Status IN ('Running', 'Paused')`;
123
133
  if (conversationId) {
124
- filter += ` AND ConversationID='${conversationId}'`;
134
+ const inScope = ConversationEngine.ScopeSubquery(scope ?? ConversationEngine.TrunkScope(conversationId));
135
+ filter += ` AND (${inScope} OR ([ConversationID]='${EscapeSQLString(conversationId)}' AND [ConversationDetailID] IS NULL))`;
125
136
  }
126
137
  LogStatusEx({ message: `[${timestamp}] 🤖 AgentStateService - Executing RunView for AI Agent Runs`, verboseOnly: true });
127
138
  const result = await rv.RunView({
@@ -182,9 +193,8 @@ export class AgentStateService {
182
193
  if (seconds < 5) {
183
194
  return 'acknowledging';
184
195
  }
185
- // Check if nearing completion (has results or output)
186
- if (run.Result || run.Status === 'Completed') {
187
- // If there's output, likely completing
196
+ // A run that is no longer Running has reached its final block
197
+ if (run.Status !== 'Running') {
188
198
  return 'completing';
189
199
  }
190
200
  // Otherwise, working
@@ -197,13 +207,14 @@ export class AgentStateService {
197
207
  * Extracts confidence score from agent run if available
198
208
  */
199
209
  extractConfidence(run) {
200
- // Try to parse confidence from Result or other fields
210
+ // Try to parse confidence from the run payload (FinalPayload, or Result on older rows)
201
211
  // This is a placeholder - adjust based on actual data structure
202
212
  try {
203
- if (run.Result) {
204
- const result = typeof run.Result === 'string' ? JSON.parse(run.Result) : run.Result;
205
- if (result.confidence != null) {
206
- return parseFloat(result.confidence);
213
+ const payload = run.FinalPayload ?? run.Result;
214
+ if (payload) {
215
+ const result = JSON.parse(payload);
216
+ if (result?.confidence != null) {
217
+ return parseFloat(String(result.confidence));
207
218
  }
208
219
  }
209
220
  }
@@ -213,30 +224,72 @@ export class AgentStateService {
213
224
  return null;
214
225
  }
215
226
  /**
216
- * Cancels an agent run
217
- * @param agentRunId The agent run ID to cancel
227
+ * Stops an agent run that is still in flight.
228
+ *
229
+ * The run's row is the control channel: this marks it `Cancelled` with reason `User Request`,
230
+ * and the server process that owns the run notices within a few seconds (the agent-run
231
+ * watchdog's cancellation poll), aborts the in-flight step through the run's cancellation
232
+ * token, and finalizes the run — keeping the payload as it stood — and its reply as stopped.
233
+ * No request reaches the running process directly, so this works whichever replica owns it.
234
+ *
235
+ * The row is loaded fresh rather than taken from the polled active-agent list, which refreshes
236
+ * every 30 seconds and may not hold a run that started a moment ago.
237
+ *
238
+ * @returns true when the row was marked; false when the run was not found, had already
239
+ * finished (nothing to stop), or the save was refused.
218
240
  */
219
241
  async CancelAgent(agentRunId) {
220
- if (!this.currentUser) {
221
- return false;
222
- }
223
242
  try {
224
- const agent = this.GetAgent(agentRunId);
225
- if (!agent) {
243
+ const run = await this.Provider.GetEntityObject('MJ: AI Agent Runs', this.currentUser);
244
+ if (!await run.Load(agentRunId)) {
226
245
  return false;
227
246
  }
228
- agent.run.Status = 'Cancelled';
229
- const saved = await agent.run.Save();
230
- if (saved) {
231
- // Refresh the active agents list
232
- await this.Refresh();
233
- return true;
247
+ if (run.Status !== 'Running' && run.Status !== 'Paused') {
248
+ return false;
249
+ }
250
+ run.Status = 'Cancelled';
251
+ run.CancellationReason = 'User Request';
252
+ const saved = await run.Save();
253
+ if (!saved) {
254
+ console.error(`Failed to stop agent run ${agentRunId}: ${run.LatestResult?.CompleteMessage ?? 'unknown error'}`);
255
+ return false;
234
256
  }
257
+ await this.Refresh();
258
+ return true;
235
259
  }
236
260
  catch (error) {
237
261
  console.error('Failed to cancel agent:', error);
262
+ return false;
263
+ }
264
+ }
265
+ /**
266
+ * Stops the in-flight run behind an agent's reply message, for callers that know the
267
+ * conversation detail but not yet the run (the run row is created a moment after the reply
268
+ * placeholder). Finds the newest Running or Paused run for that detail and stops it.
269
+ *
270
+ * @returns true when a run was found and marked; false otherwise.
271
+ */
272
+ async CancelAgentForDetail(conversationDetailId) {
273
+ try {
274
+ const rv = RunView.FromMetadataProvider(this.Provider);
275
+ const result = await rv.RunView({
276
+ EntityName: 'MJ: AI Agent Runs',
277
+ ExtraFilter: `ConversationDetailID='${conversationDetailId}' AND Status IN ('Running', 'Paused')`,
278
+ OrderBy: 'StartedAt DESC',
279
+ MaxRows: 1,
280
+ Fields: ['ID'],
281
+ ResultType: 'simple'
282
+ }, this.currentUser);
283
+ const runId = result.Success ? result.Results?.[0]?.ID : undefined;
284
+ if (!runId) {
285
+ return false;
286
+ }
287
+ return await this.CancelAgent(runId);
288
+ }
289
+ catch (error) {
290
+ console.error('Failed to find the agent run to cancel:', error);
291
+ return false;
238
292
  }
239
- return false;
240
293
  }
241
294
  /** @deprecated Use {@link CancelAgent}. */
242
295
  async cancelAgent(agentRunId) {
@@ -248,9 +301,9 @@ export class AgentStateService {
248
301
  */
249
302
  SetPollInterval(milliseconds) {
250
303
  this.pollInterval = milliseconds;
251
- // Restart polling if currently active
304
+ // Restart polling if currently active, on the same conversation and scope
252
305
  if (this.pollSubscription && this.currentUser) {
253
- this.StartPolling(this.currentUser);
306
+ this.StartPolling(this.currentUser, this.pollConversationId, this.pollScope);
254
307
  }
255
308
  }
256
309
  /** @deprecated Use {@link SetPollInterval}. */
@@ -1 +1 @@
1
- {"version":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C,YAAoB;QAClC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,sCAAsC;QACtC,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC9C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,eAAe,CAAC,YAAoB;QAClC,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;2GA1SU,iBAAiB;gEAAjB,iBAAiB,WAAjB,iBAAiB,mBAFhB,MAAM;;iFAEP,iBAAiB;cAH7B,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB","sourcesContent":["import { Injectable, OnDestroy } from '@angular/core';\nimport { BehaviorSubject, Observable, interval, Subscription } from 'rxjs';\nimport { map, shareReplay, switchMap } from 'rxjs/operators';\nimport { LogStatusEx, RunView, UserInfo, Metadata, IMetadataProvider } from '@memberjunction/core';\nimport { UUIDsEqual } from '@memberjunction/global';\nimport { MJAIAgentRunEntity } from '@memberjunction/core-entities';\n\nexport type AgentStatus = 'acknowledging' | 'working' | 'completing' | 'completed' | 'error';\n\nexport interface AgentWithStatus {\n run: MJAIAgentRunEntity;\n status: AgentStatus;\n confidence: number | null;\n}\n\n/**\n * Manages agent state and provides real-time updates for active agents\n * Polls for agent status changes and provides reactive streams\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class AgentStateService implements OnDestroy {\n private _activeAgents$ = new BehaviorSubject<AgentWithStatus[]>([]);\n private pollSubscription?: Subscription;\n private currentUser?: UserInfo;\n private pollInterval: number = 30000; // Poll every 30 seconds (reduced from 3s to minimize DB load)\n private pollCycleCount = 0;\n /** Minimum poll cycles before allowing auto-stop. Prevents premature shutdown\n * when fire-and-forget ACK returns before the server creates the agent run record. */\n private readonly minimumPollCycles = 3;\n\n // Public observable streams\n public readonly ActiveAgents$ = this._activeAgents$.asObservable();\n\n /** @deprecated Use {@link ActiveAgents$}. */\n public get activeAgents$() {\n return this.ActiveAgents$;\n }\n\n private _provider: IMetadataProvider | null = null;\n\n constructor() {}\n\n /**\n * Set the metadata provider this service should use. When unset, falls back to Metadata.Provider.\n */\n public set Provider(value: IMetadataProvider | null) {\n this._provider = value;\n }\n\n public get Provider(): IMetadataProvider {\n return this._provider ?? Metadata.Provider;\n }\n\n ngOnDestroy(): void {\n this.StopPolling();\n }\n\n /**\n * Starts polling for active agents\n * @param currentUser The current user context\n * @param conversationId Optional conversation ID to filter by\n */\n StartPolling(currentUser: UserInfo, conversationId?: string): void {\n this.currentUser = currentUser;\n this.StopPolling();\n this.pollCycleCount = 0;\n\n // Initial load\n this.loadActiveAgents(conversationId);\n\n // Start polling\n this.pollSubscription = interval(this.pollInterval)\n .pipe(switchMap(() => this.loadActiveAgents(conversationId)))\n .subscribe();\n }\n\n /** @deprecated Use {@link StartPolling}. */\n startPolling(currentUser: UserInfo, conversationId?: string): void {\n return this.StartPolling(currentUser, conversationId);\n }\n\n /**\n * Stops polling for active agents\n */\n StopPolling(): void {\n if (this.pollSubscription) {\n this.pollSubscription.unsubscribe();\n this.pollSubscription = undefined;\n }\n }\n\n /** @deprecated Use {@link StopPolling}. */\n stopPolling(): void {\n return this.StopPolling();\n }\n\n /**\n * Gets active agents as an observable\n * @param conversationId Optional conversation ID to filter by\n */\n GetActiveAgents(conversationId?: string): Observable<AgentWithStatus[]> {\n if (conversationId) {\n return this.ActiveAgents$.pipe(\n map(agents => agents.filter(a => UUIDsEqual(a.run.ConversationID, conversationId))),\n shareReplay(1)\n );\n }\n return this.ActiveAgents$;\n }\n\n /** @deprecated Use {@link GetActiveAgents}. */\n getActiveAgents(conversationId?: string): Observable<AgentWithStatus[]> {\n return this.GetActiveAgents(conversationId);\n }\n\n /**\n * Gets a specific agent by ID\n * @param agentRunId The agent run ID\n */\n GetAgent(agentRunId: string): AgentWithStatus | undefined {\n return this._activeAgents$.value.find(a => UUIDsEqual(a.run.ID, agentRunId));\n }\n\n /** @deprecated Use {@link GetAgent}. */\n getAgent(agentRunId: string): AgentWithStatus | undefined {\n return this.GetAgent(agentRunId);\n }\n\n /**\n * Manually refreshes active agents\n * @param conversationId Optional conversation ID to filter by\n */\n async Refresh(conversationId?: string): Promise<void> {\n await this.loadActiveAgents(conversationId);\n }\n\n /** @deprecated Use {@link Refresh}. */\n async refresh(conversationId?: string): Promise<void> {\n return this.Refresh(conversationId);\n }\n\n /**\n * Loads active agents from the database\n */\n private async loadActiveAgents(conversationId?: string): Promise<void> {\n if (!this.currentUser) {\n return;\n }\n\n this.pollCycleCount++;\n const timestamp = new Date().toISOString();\n LogStatusEx({message: `[${timestamp}] 🤖 AgentStateService.loadActiveAgents - Polling for active agents (conversation: ${conversationId || 'ALL'}, cycle: ${this.pollCycleCount})`, verboseOnly: true});\n\n try {\n const rv = RunView.FromMetadataProvider(this.Provider);\n // Valid statuses: Running, Completed, Paused, Failed, Cancelled\n let filter = `Status IN ('Running', 'Paused')`;\n\n if (conversationId) {\n filter += ` AND ConversationID='${conversationId}'`;\n }\n\n LogStatusEx({message: `[${timestamp}] 🤖 AgentStateService - Executing RunView for AI Agent Runs`, verboseOnly: true});\n const result = await rv.RunView<MJAIAgentRunEntity>(\n {\n EntityName: 'MJ: AI Agent Runs',\n ExtraFilter: filter,\n OrderBy: 'StartedAt DESC',\n MaxRows: 50,\n ResultType: 'entity_object'\n },\n this.currentUser\n );\n\n if (result.Success) {\n const runs = result.Results || [];\n LogStatusEx({message: `[${timestamp}] 🤖 AgentStateService - Found ${runs.length} active agent(s)`, verboseOnly: true});\n const agentsWithStatus = runs.map(run => this.mapRunToAgentWithStatus(run));\n this._activeAgents$.next(agentsWithStatus);\n\n // Stop polling if no active agents AND minimum cycles met (optimization to reduce DB load).\n // The minimum cycle guard prevents premature shutdown when fire-and-forget returns\n // before the server has created the agent run record.\n if (runs.length === 0 && this.pollSubscription && this.pollCycleCount >= this.minimumPollCycles) {\n LogStatusEx({message: `[${timestamp}] 🤖 AgentStateService - No active agents after ${this.pollCycleCount} cycles, stopping polling`, verboseOnly: true});\n this.StopPolling();\n }\n }\n } catch (error) {\n console.error('Failed to load active agents:', error);\n }\n }\n\n /**\n * Maps an agent run to include status and confidence information\n */\n private mapRunToAgentWithStatus(run: MJAIAgentRunEntity): AgentWithStatus {\n const status = this.determineAgentStatus(run);\n const confidence = this.extractConfidence(run);\n\n return {\n run,\n status,\n confidence\n };\n }\n\n /**\n * Determines the agent status based on the run entity\n */\n private determineAgentStatus(run: MJAIAgentRunEntity): AgentStatus {\n const status = run.Status?.toLowerCase() || 'running';\n\n // Check for errors\n if (status === 'error' || status === 'failed') {\n return 'error';\n }\n\n // Check for completion\n if (status === 'completed' || status === 'complete' || status === 'success') {\n return 'completed';\n }\n\n // Determine stage based on progress or elapsed time\n if (run.StartedAt) {\n const elapsed = Date.now() - new Date(run.StartedAt).getTime();\n const seconds = elapsed / 1000;\n\n // First 5 seconds: acknowledging\n if (seconds < 5) {\n return 'acknowledging';\n }\n\n // Check if nearing completion (has results or output)\n if (run.Result || run.Status === 'Completed') {\n // If there's output, likely completing\n return 'completing';\n }\n\n // Otherwise, working\n return 'working';\n }\n\n // Default to acknowledging if just started\n return 'acknowledging';\n }\n\n /**\n * Extracts confidence score from agent run if available\n */\n private extractConfidence(run: MJAIAgentRunEntity): number | null {\n // Try to parse confidence from Result or other fields\n // This is a placeholder - adjust based on actual data structure\n try {\n if (run.Result) {\n const result = typeof run.Result === 'string' ? JSON.parse(run.Result) : run.Result;\n if (result.confidence != null) {\n return parseFloat(result.confidence);\n }\n }\n } catch {\n // Ignore parse errors\n }\n\n return null;\n }\n\n /**\n * Cancels an agent run\n * @param agentRunId The agent run ID to cancel\n */\n async CancelAgent(agentRunId: string): Promise<boolean> {\n if (!this.currentUser) {\n return false;\n }\n\n try {\n const agent = this.GetAgent(agentRunId);\n if (!agent) {\n return false;\n }\n\n agent.run.Status = 'Cancelled';\n const saved = await agent.run.Save();\n\n if (saved) {\n // Refresh the active agents list\n await this.Refresh();\n return true;\n }\n } catch (error) {\n console.error('Failed to cancel agent:', error);\n }\n\n return false;\n }\n\n /** @deprecated Use {@link CancelAgent}. */\n async cancelAgent(agentRunId: string): Promise<boolean> {\n return this.CancelAgent(agentRunId);\n }\n\n /**\n * Updates the poll interval\n * @param milliseconds The new poll interval in milliseconds\n */\n SetPollInterval(milliseconds: number): void {\n this.pollInterval = milliseconds;\n\n // Restart polling if currently active\n if (this.pollSubscription && this.currentUser) {\n this.StartPolling(this.currentUser);\n }\n }\n\n /** @deprecated Use {@link SetPollInterval}. */\n setPollInterval(milliseconds: number): void {\n return this.SetPollInterval(milliseconds);\n }\n}\n"]}
1
+ {"version":3,"file":"agent-state.service.js","sourceRoot":"","sources":["../../../src/lib/services/agent-state.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,eAAe,EAAc,QAAQ,EAAgB,MAAM,MAAM,CAAC;AAC3E,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAY,QAAQ,EAAqB,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAA8C,MAAM,+BAA+B,CAAC;;AAU/G;;;GAGG;AAIH,MAAM,OAAO,iBAAiB;IACpB,cAAc,GAAG,IAAI,eAAe,CAAoB,EAAE,CAAC,CAAC;IAC5D,gBAAgB,CAAgB;IAChC,WAAW,CAAY;IAC/B,sGAAsG;IAC9F,kBAAkB,CAAU;IAC5B,SAAS,GAA6B,IAAI,CAAC;IAC3C,YAAY,GAAW,KAAK,CAAC,CAAC,8DAA8D;IAC5F,cAAc,GAAG,CAAC,CAAC;IAC3B;2FACuF;IACtE,iBAAiB,GAAG,CAAC,CAAC;IAEvC,4B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B,iBAAiB,WAAjB,iBAAiB,mBAFhB,MAAM;;iFAEP,iBAAiB;cAH7B,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB","sourcesContent":["import { Injectable, OnDestroy } from '@angular/core';\nimport { BehaviorSubject, Observable, interval, Subscription } from 'rxjs';\nimport { map, shareReplay, switchMap } from 'rxjs/operators';\nimport { LogStatusEx, RunView, UserInfo, Metadata, IMetadataProvider } from '@memberjunction/core';\nimport { EscapeSQLString, UUIDsEqual } from '@memberjunction/global';\nimport { ConversationEngine, MJAIAgentRunEntity, type ConversationScope } from '@memberjunction/core-entities';\n\nexport type AgentStatus = 'acknowledging' | 'working' | 'completing' | 'completed' | 'error';\n\nexport interface AgentWithStatus {\n run: MJAIAgentRunEntity;\n status: AgentStatus;\n confidence: number | null;\n}\n\n/**\n * Manages agent state and provides real-time updates for active agents\n * Polls for agent status changes and provides reactive streams\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class AgentStateService implements OnDestroy {\n private _activeAgents$ = new BehaviorSubject<AgentWithStatus[]>([]);\n private pollSubscription?: Subscription;\n private currentUser?: UserInfo;\n /** The conversation and scope polling was started with, so a restart (SetPollInterval) keeps them. */\n private pollConversationId?: string;\n private pollScope: ConversationScope | null = null;\n private pollInterval: number = 30000; // Poll every 30 seconds (reduced from 3s to minimize DB load)\n private pollCycleCount = 0;\n /** Minimum poll cycles before allowing auto-stop. Prevents premature shutdown\n * when fire-and-forget ACK returns before the server creates the agent run record. */\n private readonly minimumPollCycles = 3;\n\n // Public observable streams\n public readonly ActiveAgents$ = this._activeAgents$.asObservable();\n\n /** @deprecated Use {@link ActiveAgents$}. */\n public get activeAgents$() {\n return this.ActiveAgents$;\n }\n\n private _provider: IMetadataProvider | null = null;\n\n constructor() {}\n\n /**\n * Set the metadata provider this service should use. When unset, falls back to Metadata.Provider.\n */\n public set Provider(value: IMetadataProvider | null) {\n this._provider = value;\n }\n\n public get Provider(): IMetadataProvider {\n return this._provider ?? Metadata.Provider;\n }\n\n ngOnDestroy(): void {\n this.StopPolling();\n }\n\n /**\n * Starts polling for active agents\n * @param currentUser The current user context\n * @param conversationId Optional conversation ID to filter by\n * @param scope The conversation scope whose runs are read; the trunk of `conversationId` when null\n */\n StartPolling(currentUser: UserInfo, conversationId?: string, scope: ConversationScope | null = null): void {\n this.currentUser = currentUser;\n this.StopPolling();\n this.pollConversationId = conversationId;\n this.pollScope = scope;\n this.pollCycleCount = 0;\n\n // Initial load\n this.loadActiveAgents(conversationId, scope);\n\n // Start polling\n this.pollSubscription = interval(this.pollInterval)\n .pipe(switchMap(() => this.loadActiveAgents(conversationId, scope)))\n .subscribe();\n }\n\n /** @deprecated Use {@link StartPolling}. */\n startPolling(currentUser: UserInfo, conversationId?: string, scope: ConversationScope | null = null): void {\n return this.StartPolling(currentUser, conversationId, scope);\n }\n\n /**\n * Stops polling for active agents\n */\n StopPolling(): void {\n if (this.pollSubscription) {\n this.pollSubscription.unsubscribe();\n this.pollSubscription = undefined;\n }\n }\n\n /** @deprecated Use {@link StopPolling}. */\n stopPolling(): void {\n return this.StopPolling();\n }\n\n /**\n * Gets active agents as an observable\n * @param conversationId Optional conversation ID to filter by\n */\n GetActiveAgents(conversationId?: string): Observable<AgentWithStatus[]> {\n if (conversationId) {\n return this.ActiveAgents$.pipe(\n map(agents => agents.filter(a => UUIDsEqual(a.run.ConversationID, conversationId))),\n shareReplay(1)\n );\n }\n return this.ActiveAgents$;\n }\n\n /** @deprecated Use {@link GetActiveAgents}. */\n getActiveAgents(conversationId?: string): Observable<AgentWithStatus[]> {\n return this.GetActiveAgents(conversationId);\n }\n\n /**\n * Gets a specific agent by ID\n * @param agentRunId The agent run ID\n */\n GetAgent(agentRunId: string): AgentWithStatus | undefined {\n return this._activeAgents$.value.find(a => UUIDsEqual(a.run.ID, agentRunId));\n }\n\n /** @deprecated Use {@link GetAgent}. */\n getAgent(agentRunId: string): AgentWithStatus | undefined {\n return this.GetAgent(agentRunId);\n }\n\n /**\n * Manually refreshes active agents\n * @param conversationId Optional conversation ID to filter by\n * @param scope The conversation scope whose runs are read; the trunk of `conversationId` when null\n */\n async Refresh(conversationId?: string, scope: ConversationScope | null = null): Promise<void> {\n await this.loadActiveAgents(conversationId, scope);\n }\n\n /** @deprecated Use {@link Refresh}. */\n async refresh(conversationId?: string, scope: ConversationScope | null = null): Promise<void> {\n return this.Refresh(conversationId, scope);\n }\n\n /**\n * Loads the running and paused agent runs from the database. With a conversation, only runs\n * whose conversation detail is in `scope` (the trunk of `conversationId` when null), plus the\n * conversation's runs that have no conversation detail, which belong to every path.\n */\n private async loadActiveAgents(conversationId?: string, scope: ConversationScope | null = null): Promise<void> {\n if (!this.currentUser) {\n return;\n }\n\n this.pollCycleCount++;\n const timestamp = new Date().toISOString();\n LogStatusEx({message: `[${timestamp}] 🤖 AgentStateService.loadActiveAgents - Polling for active agents (conversation: ${conversationId || 'ALL'}, cycle: ${this.pollCycleCount})`, verboseOnly: true});\n\n try {\n const rv = RunView.FromMetadataProvider(this.Provider);\n // Valid statuses: Running, Completed, Paused, Failed, Cancelled\n let filter = `Status IN ('Running', 'Paused')`;\n\n if (conversationId) {\n const inScope = ConversationEngine.ScopeSubquery(scope ?? ConversationEngine.TrunkScope(conversationId));\n filter += ` AND (${inScope} OR ([ConversationID]='${EscapeSQLString(conversationId)}' AND [ConversationDetailID] IS NULL))`;\n }\n\n LogStatusEx({message: `[${timestamp}] 🤖 AgentStateService - Executing RunView for AI Agent Runs`, verboseOnly: true});\n const result = await rv.RunView<MJAIAgentRunEntity>(\n {\n EntityName: 'MJ: AI Agent Runs',\n ExtraFilter: filter,\n OrderBy: 'StartedAt DESC',\n MaxRows: 50,\n ResultType: 'entity_object'\n },\n this.currentUser\n );\n\n if (result.Success) {\n const runs = result.Results || [];\n LogStatusEx({message: `[${timestamp}] 🤖 AgentStateService - Found ${runs.length} active agent(s)`, verboseOnly: true});\n const agentsWithStatus = runs.map(run => this.mapRunToAgentWithStatus(run));\n this._activeAgents$.next(agentsWithStatus);\n\n // Stop polling if no active agents AND minimum cycles met (optimization to reduce DB load).\n // The minimum cycle guard prevents premature shutdown when fire-and-forget returns\n // before the server has created the agent run record.\n if (runs.length === 0 && this.pollSubscription && this.pollCycleCount >= this.minimumPollCycles) {\n LogStatusEx({message: `[${timestamp}] 🤖 AgentStateService - No active agents after ${this.pollCycleCount} cycles, stopping polling`, verboseOnly: true});\n this.StopPolling();\n }\n }\n } catch (error) {\n console.error('Failed to load active agents:', error);\n }\n }\n\n /**\n * Maps an agent run to include status and confidence information\n */\n private mapRunToAgentWithStatus(run: MJAIAgentRunEntity): AgentWithStatus {\n const status = this.determineAgentStatus(run);\n const confidence = this.extractConfidence(run);\n\n return {\n run,\n status,\n confidence\n };\n }\n\n /**\n * Determines the agent status based on the run entity\n */\n private determineAgentStatus(run: MJAIAgentRunEntity): AgentStatus {\n const status = run.Status?.toLowerCase() || 'running';\n\n // Check for errors\n if (status === 'error' || status === 'failed') {\n return 'error';\n }\n\n // Check for completion\n if (status === 'completed' || status === 'complete' || status === 'success') {\n return 'completed';\n }\n\n // Determine stage based on progress or elapsed time\n if (run.StartedAt) {\n const elapsed = Date.now() - new Date(run.StartedAt).getTime();\n const seconds = elapsed / 1000;\n\n // First 5 seconds: acknowledging\n if (seconds < 5) {\n return 'acknowledging';\n }\n\n // A run that is no longer Running has reached its final block\n if (run.Status !== 'Running') {\n return 'completing';\n }\n\n // Otherwise, working\n return 'working';\n }\n\n // Default to acknowledging if just started\n return 'acknowledging';\n }\n\n /**\n * Extracts confidence score from agent run if available\n */\n private extractConfidence(run: MJAIAgentRunEntity): number | null {\n // Try to parse confidence from the run payload (FinalPayload, or Result on older rows)\n // This is a placeholder - adjust based on actual data structure\n try {\n const payload = run.FinalPayload ?? run.Result;\n if (payload) {\n const result: { confidence?: number | string } | null = JSON.parse(payload);\n if (result?.confidence != null) {\n return parseFloat(String(result.confidence));\n }\n }\n } catch {\n // Ignore parse errors\n }\n\n return null;\n }\n\n /**\n * Stops an agent run that is still in flight.\n *\n * The run's row is the control channel: this marks it `Cancelled` with reason `User Request`,\n * and the server process that owns the run notices within a few seconds (the agent-run\n * watchdog's cancellation poll), aborts the in-flight step through the run's cancellation\n * token, and finalizes the run — keeping the payload as it stood — and its reply as stopped.\n * No request reaches the running process directly, so this works whichever replica owns it.\n *\n * The row is loaded fresh rather than taken from the polled active-agent list, which refreshes\n * every 30 seconds and may not hold a run that started a moment ago.\n *\n * @returns true when the row was marked; false when the run was not found, had already\n * finished (nothing to stop), or the save was refused.\n */\n async CancelAgent(agentRunId: string): Promise<boolean> {\n try {\n const run = await this.Provider.GetEntityObject<MJAIAgentRunEntity>('MJ: AI Agent Runs', this.currentUser);\n if (!await run.Load(agentRunId)) {\n return false;\n }\n if (run.Status !== 'Running' && run.Status !== 'Paused') {\n return false;\n }\n\n run.Status = 'Cancelled';\n run.CancellationReason = 'User Request';\n const saved = await run.Save();\n if (!saved) {\n console.error(`Failed to stop agent run ${agentRunId}: ${run.LatestResult?.CompleteMessage ?? 'unknown error'}`);\n return false;\n }\n\n await this.Refresh();\n return true;\n } catch (error) {\n console.error('Failed to cancel agent:', error);\n return false;\n }\n }\n\n /**\n * Stops the in-flight run behind an agent's reply message, for callers that know the\n * conversation detail but not yet the run (the run row is created a moment after the reply\n * placeholder). Finds the newest Running or Paused run for that detail and stops it.\n *\n * @returns true when a run was found and marked; false otherwise.\n */\n async CancelAgentForDetail(conversationDetailId: string): Promise<boolean> {\n try {\n const rv = RunView.FromMetadataProvider(this.Provider);\n const result = await rv.RunView<{ ID: string }>(\n {\n EntityName: 'MJ: AI Agent Runs',\n ExtraFilter: `ConversationDetailID='${conversationDetailId}' AND Status IN ('Running', 'Paused')`,\n OrderBy: 'StartedAt DESC',\n MaxRows: 1,\n Fields: ['ID'],\n ResultType: 'simple'\n },\n this.currentUser\n );\n const runId = result.Success ? result.Results?.[0]?.ID : undefined;\n if (!runId) {\n return false;\n }\n return await this.CancelAgent(runId);\n } catch (error) {\n console.error('Failed to find the agent run to cancel:', error);\n return false;\n }\n }\n\n /** @deprecated Use {@link CancelAgent}. */\n async cancelAgent(agentRunId: string): Promise<boolean> {\n return this.CancelAgent(agentRunId);\n }\n\n /**\n * Updates the poll interval\n * @param milliseconds The new poll interval in milliseconds\n */\n SetPollInterval(milliseconds: number): void {\n this.pollInterval = milliseconds;\n\n // Restart polling if currently active, on the same conversation and scope\n if (this.pollSubscription && this.currentUser) {\n this.StartPolling(this.currentUser, this.pollConversationId, this.pollScope);\n }\n }\n\n /** @deprecated Use {@link SetPollInterval}. */\n setPollInterval(milliseconds: number): void {\n return this.SetPollInterval(milliseconds);\n }\n}\n"]}
@@ -118,15 +118,6 @@ export declare class ArtifactStateService {
118
118
  ClearCache(): void;
119
119
  /** @deprecated Use {@link ClearCache}. */
120
120
  clearCache(): void;
121
- /**
122
- * Loads artifacts for a conversation
123
- * @param conversationId The conversation ID
124
- * @param currentUser The current user context
125
- * @returns Array of artifacts
126
- */
127
- LoadArtifactsForConversation(conversationId: string, currentUser: UserInfo): Promise<MJArtifactEntity[]>;
128
- /** @deprecated Use {@link LoadArtifactsForConversation}. */
129
- loadArtifactsForConversation(conversationId: string, currentUser: UserInfo): Promise<MJArtifactEntity[]>;
130
121
  /**
131
122
  * Loads artifacts for a collection
132
123
  * @param collectionId The collection ID
@@ -1 +1 @@
1
- {"version":3,"file":"artifact-state.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/artifact-state.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,UAAU,EAAiB,MAAM,MAAM,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EAAqB,QAAQ,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;;AAE1E;;;GAGG;AACH,qBAGa,oBAAoB;IAiDnB,OAAO,CAAC,yBAAyB;IAhD7C,OAAO,CAAC,kBAAk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AC,IAAI,CAAC;IAIzH;;;;;OAKG;IACG,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC1G,oDAAoD;IAC9C,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;yCA7lB/F,oBAAoB;6CAApB,oBAAoB;CAgmBhC"}
@@ -210,38 +210,6 @@ export class ArtifactStateService {
210
210
  clearCache() {
211
211
  return this.ClearCache();
212
212
  }
213
- /**
214
- * Loads artifacts for a conversation
215
- * @param conversationId The conversation ID
216
- * @param currentUser The current user context
217
- * @returns Array of artifacts
218
- */
219
- async LoadArtifactsForConversation(conversationId, currentUser) {
220
- try {
221
- const rv = RunView.FromMetadataProvider(this.Provider);
222
- const result = await rv.RunView({
223
- EntityName: 'MJ: Artifacts',
224
- ExtraFilter: `ConversationID='${conversationId}'`,
225
- OrderBy: '__mj_CreatedAt DESC',
226
- MaxRows: 1000,
227
- ResultType: 'entity_object'
228
- }, currentUser);
229
- if (result.Success && result.Results) {
230
- // Cache all artifacts
231
- result.Results.forEach(artifact => this.CacheArtifact(artifact));
232
- return result.Results;
233
- }
234
- return [];
235
- }
236
- catch (error) {
237
- console.error('Error loading artifacts:', error);
238
- return [];
239
- }
240
- }
241
- /** @deprecated Use {@link LoadArtifactsForConversation}. */
242
- async loadArtifactsForConversation(conversationId, currentUser) {
243
- return this.LoadArtifactsForConversation(conversationId, currentUser);
244
- }
245
213
  /**
246
214
  * Loads artifacts for a collection
247
215
  * @param collectionId The collection ID
@@ -491,6 +459,7 @@ export class ArtifactStateService {
491
459
  let targetVersionId = versionId;
492
460
  if (!targetVersionId) {
493
461
  const rv = RunView.FromMetadataProvider(this.Provider);
462
+ // conversation-scope: artifact-wide read, no conversation path applies
494
463
  const versionResult = await rv.RunView({
495
464
  EntityName: 'MJ: Artifact Versions',
496
465
  ExtraFilter: `ArtifactID='${artifactId}'`,