@memberjunction/ng-conversations 6.2.0-edge.4 → 6.2.0-edge.6

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 (144) hide show
  1. package/README.md +29 -0
  2. package/dist/lib/components/attachment/image-viewer.component.d.ts +3 -1
  3. package/dist/lib/components/attachment/image-viewer.component.d.ts.map +1 -1
  4. package/dist/lib/components/attachment/image-viewer.component.js +5 -1
  5. package/dist/lib/components/attachment/image-viewer.component.js.map +1 -1
  6. package/dist/lib/components/conversation/conversation-agent-picker.component.d.ts +1 -1
  7. package/dist/lib/components/conversation/conversation-agent-picker.component.js +3 -3
  8. package/dist/lib/components/conversation/conversation-agent-picker.component.js.map +1 -1
  9. package/dist/lib/components/conversation/conversation-chat-area.component.d.ts +88 -20
  10. package/dist/lib/components/conversation/conversation-chat-area.component.d.ts.map +1 -1
  11. package/dist/lib/components/conversation/conversation-chat-area.component.js +785 -387
  12. package/dist/lib/components/conversation/conversation-chat-area.component.js.map +1 -1
  13. package/dist/lib/components/message/message-input.component.d.ts +60 -20
  14. package/dist/lib/components/message/message-input.component.d.ts.map +1 -1
  15. package/dist/lib/components/message/message-input.component.js +290 -389
  16. package/dist/lib/components/message/message-input.component.js.map +1 -1
  17. package/dist/lib/components/message/message-item.component.d.ts +153 -17
  18. package/dist/lib/components/message/message-item.component.d.ts.map +1 -1
  19. package/dist/lib/components/message/message-item.component.js +1400 -299
  20. package/dist/lib/components/message/message-item.component.js.map +1 -1
  21. package/dist/lib/components/message/message-list.component.d.ts +25 -2
  22. package/dist/lib/components/message/message-list.component.d.ts.map +1 -1
  23. package/dist/lib/components/message/message-list.component.js +79 -40
  24. package/dist/lib/components/message/message-list.component.js.map +1 -1
  25. package/dist/lib/components/overlay/chat-overlay.component.d.ts +19 -0
  26. package/dist/lib/components/overlay/chat-overlay.component.d.ts.map +1 -1
  27. package/dist/lib/components/overlay/chat-overlay.component.js +125 -13
  28. package/dist/lib/components/overlay/chat-overlay.component.js.map +1 -1
  29. package/dist/lib/components/project/project-form-modal.component.js +2 -2
  30. package/dist/lib/components/project/project-form-modal.component.js.map +1 -1
  31. package/dist/lib/components/realtime/realtime-agent-banner.component.d.ts +6 -1
  32. package/dist/lib/components/realtime/realtime-agent-banner.component.d.ts.map +1 -1
  33. package/dist/lib/components/realtime/realtime-agent-banner.component.js +110 -82
  34. package/dist/lib/components/realtime/realtime-agent-banner.component.js.map +1 -1
  35. package/dist/lib/components/realtime/realtime-call-failure-notice.d.ts +13 -0
  36. package/dist/lib/components/realtime/realtime-call-failure-notice.d.ts.map +1 -0
  37. package/dist/lib/components/realtime/realtime-call-failure-notice.js +21 -0
  38. package/dist/lib/components/realtime/realtime-call-failure-notice.js.map +1 -0
  39. package/dist/lib/components/realtime/realtime-composer.component.js +114 -102
  40. package/dist/lib/components/realtime/realtime-composer.component.js.map +1 -1
  41. package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts +21 -2
  42. package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts.map +1 -1
  43. package/dist/lib/components/realtime/realtime-session-overlay.component.js +113 -76
  44. package/dist/lib/components/realtime/realtime-session-overlay.component.js.map +1 -1
  45. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.d.ts.map +1 -1
  46. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js +7 -1
  47. package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js.map +1 -1
  48. package/dist/lib/components/sidebar/routines-section.component.js +1 -1
  49. package/dist/lib/components/sidebar/routines-section.component.js.map +1 -1
  50. package/dist/lib/components/task/tasks-full-view.component.d.ts +152 -31
  51. package/dist/lib/components/task/tasks-full-view.component.d.ts.map +1 -1
  52. package/dist/lib/components/task/tasks-full-view.component.js +2227 -214
  53. package/dist/lib/components/task/tasks-full-view.component.js.map +1 -1
  54. package/dist/lib/components/tasks/tasks-dropdown.component.js +4 -4
  55. package/dist/lib/components/tasks/tasks-dropdown.component.js.map +1 -1
  56. package/dist/lib/components/workspace/conversation-workspace.component.d.ts +11 -1
  57. package/dist/lib/components/workspace/conversation-workspace.component.d.ts.map +1 -1
  58. package/dist/lib/components/workspace/conversation-workspace.component.js +25 -28
  59. package/dist/lib/components/workspace/conversation-workspace.component.js.map +1 -1
  60. package/dist/lib/services/agent-state.service.d.ts.map +1 -1
  61. package/dist/lib/services/agent-state.service.js +8 -8
  62. package/dist/lib/services/agent-state.service.js.map +1 -1
  63. package/dist/lib/services/browser-realtime-media-host.d.ts +7 -7
  64. package/dist/lib/services/browser-realtime-media-host.js +8 -78
  65. package/dist/lib/services/browser-realtime-media-host.js.map +1 -1
  66. package/dist/lib/services/conversation-agent.service.d.ts +53 -20
  67. package/dist/lib/services/conversation-agent.service.d.ts.map +1 -1
  68. package/dist/lib/services/conversation-agent.service.js +108 -54
  69. package/dist/lib/services/conversation-agent.service.js.map +1 -1
  70. package/dist/lib/services/conversation-detail-window.store.d.ts +5 -0
  71. package/dist/lib/services/conversation-detail-window.store.d.ts.map +1 -1
  72. package/dist/lib/services/conversation-detail-window.store.js +52 -5
  73. package/dist/lib/services/conversation-detail-window.store.js.map +1 -1
  74. package/dist/lib/services/conversation-naming.d.ts.map +1 -1
  75. package/dist/lib/services/conversation-naming.js +9 -2
  76. package/dist/lib/services/conversation-naming.js.map +1 -1
  77. package/dist/lib/services/conversation-tasks-filter.d.ts +15 -0
  78. package/dist/lib/services/conversation-tasks-filter.d.ts.map +1 -0
  79. package/dist/lib/services/conversation-tasks-filter.js +69 -0
  80. package/dist/lib/services/conversation-tasks-filter.js.map +1 -0
  81. package/dist/lib/services/realtime-audio-recorder.d.ts +94 -86
  82. package/dist/lib/services/realtime-audio-recorder.d.ts.map +1 -1
  83. package/dist/lib/services/realtime-audio-recorder.js +222 -195
  84. package/dist/lib/services/realtime-audio-recorder.js.map +1 -1
  85. package/dist/lib/services/realtime-session.service.d.ts +30 -2
  86. package/dist/lib/services/realtime-session.service.d.ts.map +1 -1
  87. package/dist/lib/services/realtime-session.service.js +35 -7
  88. package/dist/lib/services/realtime-session.service.js.map +1 -1
  89. package/dist/lib/services/recording/libopus-wasm-binary.d.ts +3 -0
  90. package/dist/lib/services/recording/libopus-wasm-binary.d.ts.map +1 -0
  91. package/dist/lib/services/recording/libopus-wasm-binary.js +489 -0
  92. package/dist/lib/services/recording/libopus-wasm-binary.js.map +1 -0
  93. package/dist/lib/services/recording/libopus-worker-source.d.ts +48 -0
  94. package/dist/lib/services/recording/libopus-worker-source.d.ts.map +1 -0
  95. package/dist/lib/services/recording/libopus-worker-source.js +170 -0
  96. package/dist/lib/services/recording/libopus-worker-source.js.map +1 -0
  97. package/dist/lib/services/recording/linear-resampler.d.ts +45 -0
  98. package/dist/lib/services/recording/linear-resampler.d.ts.map +1 -0
  99. package/dist/lib/services/recording/linear-resampler.js +85 -0
  100. package/dist/lib/services/recording/linear-resampler.js.map +1 -0
  101. package/dist/lib/services/recording/opus-packet-encoder.d.ts +50 -0
  102. package/dist/lib/services/recording/opus-packet-encoder.d.ts.map +1 -0
  103. package/dist/lib/services/recording/opus-packet-encoder.js +41 -0
  104. package/dist/lib/services/recording/opus-packet-encoder.js.map +1 -0
  105. package/dist/lib/services/recording/wasm-opus-encoder.d.ts +86 -0
  106. package/dist/lib/services/recording/wasm-opus-encoder.d.ts.map +1 -0
  107. package/dist/lib/services/recording/wasm-opus-encoder.js +232 -0
  108. package/dist/lib/services/recording/wasm-opus-encoder.js.map +1 -0
  109. package/dist/lib/services/recording/webcodecs-opus-encoder.d.ts +39 -0
  110. package/dist/lib/services/recording/webcodecs-opus-encoder.d.ts.map +1 -0
  111. package/dist/lib/services/recording/webcodecs-opus-encoder.js +101 -0
  112. package/dist/lib/services/recording/webcodecs-opus-encoder.js.map +1 -0
  113. package/dist/lib/services/search.service.d.ts.map +1 -1
  114. package/dist/lib/services/search.service.js +3 -16
  115. package/dist/lib/services/search.service.js.map +1 -1
  116. package/dist/lib/utils/agent-failure-display.d.ts +14 -0
  117. package/dist/lib/utils/agent-failure-display.d.ts.map +1 -0
  118. package/dist/lib/utils/agent-failure-display.js +26 -0
  119. package/dist/lib/utils/agent-failure-display.js.map +1 -0
  120. package/dist/lib/utils/distinct-artifacts.d.ts +9 -3
  121. package/dist/lib/utils/distinct-artifacts.d.ts.map +1 -1
  122. package/dist/lib/utils/distinct-artifacts.js +24 -5
  123. package/dist/lib/utils/distinct-artifacts.js.map +1 -1
  124. package/dist/lib/utils/message-list-order.d.ts +13 -0
  125. package/dist/lib/utils/message-list-order.d.ts.map +1 -0
  126. package/dist/lib/utils/message-list-order.js +31 -0
  127. package/dist/lib/utils/message-list-order.js.map +1 -0
  128. package/dist/lib/utils/pin-state.d.ts +11 -0
  129. package/dist/lib/utils/pin-state.d.ts.map +1 -0
  130. package/dist/lib/utils/pin-state.js +9 -0
  131. package/dist/lib/utils/pin-state.js.map +1 -0
  132. package/dist/public-api.d.ts +1 -0
  133. package/dist/public-api.d.ts.map +1 -1
  134. package/dist/public-api.js +1 -0
  135. package/dist/public-api.js.map +1 -1
  136. package/package.json +36 -36
  137. package/dist/lib/services/browser-recording-unload-guard.d.ts +0 -30
  138. package/dist/lib/services/browser-recording-unload-guard.d.ts.map +0 -1
  139. package/dist/lib/services/browser-recording-unload-guard.js +0 -43
  140. package/dist/lib/services/browser-recording-unload-guard.js.map +0 -1
  141. package/dist/lib/services/realtime-pcm-wav.d.ts +0 -79
  142. package/dist/lib/services/realtime-pcm-wav.d.ts.map +0 -1
  143. package/dist/lib/services/realtime-pcm-wav.js +0 -213
  144. package/dist/lib/services/realtime-pcm-wav.js.map +0 -1
@@ -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,CA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AAM,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"}
@@ -193,9 +193,8 @@ export class AgentStateService {
193
193
  if (seconds < 5) {
194
194
  return 'acknowledging';
195
195
  }
196
- // Check if nearing completion (has results or output)
197
- if (run.Result || run.Status === 'Completed') {
198
- // If there's output, likely completing
196
+ // A run that is no longer Running has reached its final block
197
+ if (run.Status !== 'Running') {
199
198
  return 'completing';
200
199
  }
201
200
  // Otherwise, working
@@ -208,13 +207,14 @@ export class AgentStateService {
208
207
  * Extracts confidence score from agent run if available
209
208
  */
210
209
  extractConfidence(run) {
211
- // Try to parse confidence from Result or other fields
210
+ // Try to parse confidence from the run payload (FinalPayload, or Result on older rows)
212
211
  // This is a placeholder - adjust based on actual data structure
213
212
  try {
214
- if (run.Result) {
215
- const result = typeof run.Result === 'string' ? JSON.parse(run.Result) : run.Result;
216
- if (result.confidence != null) {
217
- 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));
218
218
  }
219
219
  }
220
220
  }
@@ -1 +1 @@
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,O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CAAC,UAAkB;QAClC,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,YAAoB;QAClC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,0EAA0E;QAC1E,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC9C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,eAAe,CAAC,YAAoB;QAClC,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;2GA/VU,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 { 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 // 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 * 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"]}
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,CA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C,UAAU,CAAC,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,YAAoB;QAClC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,0EAA0E;QAC1E,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC9C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,eAAe,CAAC,YAAoB;QAClC,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;2GA/VU,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 { 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"]}
@@ -4,9 +4,9 @@ import { type DisplayCaptureOptions, type DisplayCaptureResult, type ILocalMedia
4
4
  * The browser's implementation of the realtime runtime's media seam.
5
5
  *
6
6
  * Everything here is the half of a realtime session that genuinely *is* platform-specific:
7
- * how the microphone is requested, and how captured audio becomes bytes we can upload. The
8
- * orchestration around it — mint, connect, transcripts, tools, narration, channels, teardown —
9
- * lives in `@memberjunction/realtime-runtime` and is identical on every host.
7
+ * how the microphone is requested, and how captured audio becomes Opus packets. The
8
+ * orchestration around it — mint, connect, transcripts, tools, narration, channels, shard
9
+ * upload, teardown — lives in `@memberjunction/realtime-runtime` and is identical on every host.
10
10
  */
11
11
  export declare class BrowserRealtimeMediaHost implements IRealtimeMediaHost {
12
12
  /**
@@ -26,10 +26,10 @@ export declare class BrowserRealtimeMediaHost implements IRealtimeMediaHost {
26
26
  */
27
27
  RequestDisplayCapture(options?: DisplayCaptureOptions): Promise<DisplayCaptureResult>;
28
28
  /**
29
- * Wraps the browser recorder so the runtime never sees a `Blob`.
30
- *
31
- * Returns `null` when the platform cannot record, which the runtime treats as "recording is
32
- * simply off" rather than an error — recording is consent-gated and optional by design.
29
+ * A fresh, unstarted 48 kHz Opus recorder for this call. {@link RealtimeAudioRecorder}
30
+ * implements the runtime's recorder contract itself (packets out, sample count back), so no
31
+ * adapter sits in between. When the browser cannot record, the recorder disables itself on
32
+ * Start and the runtime sees `IsRecording === false`, which it treats as "recording is off".
33
33
  */
34
34
  CreateRecorder(): IRealtimeSessionRecorder | null;
35
35
  }
@@ -4,9 +4,9 @@ import { RealtimeAudioRecorder } from './realtime-audio-recorder';
4
4
  * The browser's implementation of the realtime runtime's media seam.
5
5
  *
6
6
  * Everything here is the half of a realtime session that genuinely *is* platform-specific:
7
- * how the microphone is requested, and how captured audio becomes bytes we can upload. The
8
- * orchestration around it — mint, connect, transcripts, tools, narration, channels, teardown —
9
- * lives in `@memberjunction/realtime-runtime` and is identical on every host.
7
+ * how the microphone is requested, and how captured audio becomes Opus packets. The
8
+ * orchestration around it — mint, connect, transcripts, tools, narration, channels, shard
9
+ * upload, teardown — lives in `@memberjunction/realtime-runtime` and is identical on every host.
10
10
  */
11
11
  export class BrowserRealtimeMediaHost {
12
12
  /**
@@ -32,83 +32,13 @@ export class BrowserRealtimeMediaHost {
32
32
  return RequestDisplayCapture(options);
33
33
  }
34
34
  /**
35
- * Wraps the browser recorder so the runtime never sees a `Blob`.
36
- *
37
- * Returns `null` when the platform cannot record, which the runtime treats as "recording is
38
- * simply off" rather than an error — recording is consent-gated and optional by design.
35
+ * A fresh, unstarted 48 kHz Opus recorder for this call. {@link RealtimeAudioRecorder}
36
+ * implements the runtime's recorder contract itself (packets out, sample count back), so no
37
+ * adapter sits in between. When the browser cannot record, the recorder disables itself on
38
+ * Start and the runtime sees `IsRecording === false`, which it treats as "recording is off".
39
39
  */
40
40
  CreateRecorder() {
41
- return new BrowserRealtimeSessionRecorder(new RealtimeAudioRecorder());
42
- }
43
- }
44
- /**
45
- * Adapts {@link RealtimeAudioRecorder} (which speaks `Blob`, because that is what `MediaRecorder`
46
- * and the Web Audio API hand you) to the runtime's byte-agnostic recorder contract.
47
- *
48
- * The base64 encoding that used to sit in the session service lives here now. That is the correct
49
- * home for it: a browser reaches for `FileReader`, React Native reads a file off disk, and a test
50
- * harness holds bytes in memory — three different answers to a question the orchestration layer
51
- * should never have been asking.
52
- */
53
- class BrowserRealtimeSessionRecorder {
54
- recorder;
55
- constructor(recorder) {
56
- this.recorder = recorder;
57
- }
58
- get IsRecording() {
59
- return this.recorder.IsRecording;
60
- }
61
- get SampleRate() {
62
- return this.recorder.SampleRate;
63
- }
64
- get MimeType() {
65
- return this.recorder.MimeType;
66
- }
67
- Start(micStream, remoteStream) {
68
- this.recorder.Start(micStream, remoteStream);
69
- }
70
- AttachRemoteStream(stream) {
71
- this.recorder.AttachRemoteStream(stream);
72
- }
73
- ReplaceMicrophone(micStream) {
74
- this.recorder.ReplaceMicrophone(micStream);
75
- }
76
- NowOffsetMs() {
77
- return this.recorder.NowOffsetMs();
78
- }
79
- GetPeaks() {
80
- return this.recorder.GetPeaks();
81
- }
82
- async SnapshotNewSegmentBase64() {
83
- const segment = this.recorder.SnapshotNewSegment();
84
- if (!segment || segment.size === 0) {
85
- return null;
86
- }
87
- return this.blobToBase64(segment);
88
- }
89
- async StopAndEncode() {
90
- const blob = await this.recorder.Stop();
91
- if (!blob || blob.size === 0) {
92
- return null;
93
- }
94
- return this.blobToBase64(blob);
95
- }
96
- /**
97
- * Encodes a {@link Blob} as base64 with the `data:` prefix stripped, via {@link FileReader}.
98
- * Resolves to `null` rather than rejecting — a failed encode costs us the recording, never
99
- * the live call.
100
- */
101
- blobToBase64(blob) {
102
- return new Promise((resolve) => {
103
- const reader = new FileReader();
104
- reader.onloadend = () => {
105
- const result = typeof reader.result === 'string' ? reader.result : '';
106
- const comma = result.indexOf(',');
107
- resolve(comma >= 0 ? result.slice(comma + 1) : null);
108
- };
109
- reader.onerror = () => resolve(null);
110
- reader.readAsDataURL(blob);
111
- });
41
+ return new RealtimeAudioRecorder();
112
42
  }
113
43
  }
114
44
  //# sourceMappingURL=browser-realtime-media-host.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser-realtime-media-host.js","sourceRoot":"","sources":["../../../src/lib/services/browser-realtime-media-host.ts"],"names":[],"mappings":"AAIA,OAAO,EAIH,oBAAoB,EACpB,qBAAqB,GACxB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE;;;;;;;GAOG;AACH,MAAM,OAAO,wBAAwB;IACjC;;;;OAIG;IACI,KAAK,CAAC,iBAAiB;QAC1B,OAAO,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,0BAA0B;QAC7B,OAAO,IAAI,oBAAoB,EAAE,CAAC;IACtC,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,OAA+B;QACxD,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,cAAc;QACjB,OAAO,IAAI,8BAA8B,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC;IAC3E,CAAC;CACJ;AAED;;;;;;;;GAQG;AACH,MAAM,8BAA8B;IACH;IAA7B,YAA6B,QAA+B;QAA/B,aAAQ,GAAR,QAAQ,CAAuB;IAAG,CAAC;IAEhE,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IACrC,CAAC;IAED,I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AAO,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,EAAE;YAC1C,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAChC,MAAM,CAAC,SAAS,GAAG,GAAG,EAAE;gBACpB,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtE,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAClC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACzD,CAAC,CAAC;YACF,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["import {\n IRealtimeMediaHost,\n IRealtimeSessionRecorder,\n} from '@memberjunction/realtime-runtime';\nimport {\n type DisplayCaptureOptions,\n type DisplayCaptureResult,\n type ILocalMediaController,\n LocalMediaController,\n RequestDisplayCapture,\n} from '@memberjunction/ai-realtime-client/media';\nimport { RealtimeAudioRecorder } from './realtime-audio-recorder';\n\n/**\n * The browser's implementation of the realtime runtime's media seam.\n *\n * Everything here is the half of a realtime session that genuinely *is* platform-specific:\n * how the microphone is requested, and how captured audio becomes bytes we can upload. The\n * orchestration around it — mint, connect, transcripts, tools, narration, channels, teardown —\n * lives in `@memberjunction/realtime-runtime` and is identical on every host.\n */\nexport class BrowserRealtimeMediaHost implements IRealtimeMediaHost {\n /**\n * Requests the microphone through the standard Web API, which surfaces the browser's own\n * permission prompt. A denial rejects, and the runtime treats that as a failed session start.\n * The runtime uses {@link CreateLocalMediaController} instead when it is present, as it is here.\n */\n public async AcquireMicrophone(): Promise<MediaStream> {\n return navigator.mediaDevices.getUserMedia({ audio: true });\n }\n\n /**\n * The browser's camera-and-microphone controller. The runtime starts the microphone through it,\n * so a call follows a device switch and keeps going when a headset is unplugged.\n */\n public CreateLocalMediaController(): ILocalMediaController {\n return new LocalMediaController();\n }\n\n /**\n * Opens the browser's share picker for the session's screen share: a screen, window or tab, or one panel of\n * this page where the browser can narrow a capture to it.\n */\n public RequestDisplayCapture(options?: DisplayCaptureOptions): Promise<DisplayCaptureResult> {\n return RequestDisplayCapture(options);\n }\n\n /**\n * Wraps the browser recorder so the runtime never sees a `Blob`.\n *\n * Returns `null` when the platform cannot record, which the runtime treats as \"recording is\n * simply off\" rather than an error — recording is consent-gated and optional by design.\n */\n public CreateRecorder(): IRealtimeSessionRecorder | null {\n return new BrowserRealtimeSessionRecorder(new RealtimeAudioRecorder());\n }\n}\n\n/**\n * Adapts {@link RealtimeAudioRecorder} (which speaks `Blob`, because that is what `MediaRecorder`\n * and the Web Audio API hand you) to the runtime's byte-agnostic recorder contract.\n *\n * The base64 encoding that used to sit in the session service lives here now. That is the correct\n * home for it: a browser reaches for `FileReader`, React Native reads a file off disk, and a test\n * harness holds bytes in memory — three different answers to a question the orchestration layer\n * should never have been asking.\n */\nclass BrowserRealtimeSessionRecorder implements IRealtimeSessionRecorder {\n constructor(private readonly recorder: RealtimeAudioRecorder) {}\n\n public get IsRecording(): boolean {\n return this.recorder.IsRecording;\n }\n\n public get SampleRate(): number {\n return this.recorder.SampleRate;\n }\n\n public get MimeType(): string {\n return this.recorder.MimeType;\n }\n\n public Start(micStream: MediaStream, remoteStream: MediaStream | null): void {\n this.recorder.Start(micStream, remoteStream);\n }\n\n public AttachRemoteStream(stream: MediaStream): void {\n this.recorder.AttachRemoteStream(stream);\n }\n\n public ReplaceMicrophone(micStream: MediaStream): void {\n this.recorder.ReplaceMicrophone(micStream);\n }\n\n public NowOffsetMs(): number {\n return this.recorder.NowOffsetMs();\n }\n\n public GetPeaks(): number[] {\n return this.recorder.GetPeaks();\n }\n\n public async SnapshotNewSegmentBase64(): Promise<string | null> {\n const segment = this.recorder.SnapshotNewSegment();\n if (!segment || segment.size === 0) {\n return null;\n }\n return this.blobToBase64(segment);\n }\n\n public async StopAndEncode(): Promise<string | null> {\n const blob = await this.recorder.Stop();\n if (!blob || blob.size === 0) {\n return null;\n }\n return this.blobToBase64(blob);\n }\n\n /**\n * Encodes a {@link Blob} as base64 with the `data:` prefix stripped, via {@link FileReader}.\n * Resolves to `null` rather than rejecting — a failed encode costs us the recording, never\n * the live call.\n */\n private blobToBase64(blob: Blob): Promise<string | null> {\n return new Promise<string | null>((resolve) => {\n const reader = new FileReader();\n reader.onloadend = () => {\n const result = typeof reader.result === 'string' ? reader.result : '';\n const comma = result.indexOf(',');\n resolve(comma >= 0 ? result.slice(comma + 1) : null);\n };\n reader.onerror = () => resolve(null);\n reader.readAsDataURL(blob);\n });\n }\n}\n"]}
1
+ {"version":3,"file":"browser-realtime-media-host.js","sourceRoot":"","sources":["../../../src/lib/services/browser-realtime-media-host.ts"],"names":[],"mappings":"AAIA,OAAO,EAIH,oBAAoB,EACpB,qBAAqB,GACxB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE;;;;;;;GAOG;AACH,MAAM,OAAO,wBAAwB;IACjC;;;;OAIG;IACI,KAAK,CAAC,iBAAiB;QAC1B,OAAO,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,0BAA0B;QAC7B,OAAO,IAAI,oBAAoB,EAAE,CAAC;IACtC,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,OAA+B;QACxD,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,cAAc;QACjB,OAAO,IAAI,qBAAqB,EAAE,CAAC;IACvC,CAAC;CACJ","sourcesContent":["import {\n IRealtimeMediaHost,\n IRealtimeSessionRecorder,\n} from '@memberjunction/realtime-runtime';\nimport {\n type DisplayCaptureOptions,\n type DisplayCaptureResult,\n type ILocalMediaController,\n LocalMediaController,\n RequestDisplayCapture,\n} from '@memberjunction/ai-realtime-client/media';\nimport { RealtimeAudioRecorder } from './realtime-audio-recorder';\n\n/**\n * The browser's implementation of the realtime runtime's media seam.\n *\n * Everything here is the half of a realtime session that genuinely *is* platform-specific:\n * how the microphone is requested, and how captured audio becomes Opus packets. The\n * orchestration around it — mint, connect, transcripts, tools, narration, channels, shard\n * upload, teardown — lives in `@memberjunction/realtime-runtime` and is identical on every host.\n */\nexport class BrowserRealtimeMediaHost implements IRealtimeMediaHost {\n /**\n * Requests the microphone through the standard Web API, which surfaces the browser's own\n * permission prompt. A denial rejects, and the runtime treats that as a failed session start.\n * The runtime uses {@link CreateLocalMediaController} instead when it is present, as it is here.\n */\n public async AcquireMicrophone(): Promise<MediaStream> {\n return navigator.mediaDevices.getUserMedia({ audio: true });\n }\n\n /**\n * The browser's camera-and-microphone controller. The runtime starts the microphone through it,\n * so a call follows a device switch and keeps going when a headset is unplugged.\n */\n public CreateLocalMediaController(): ILocalMediaController {\n return new LocalMediaController();\n }\n\n /**\n * Opens the browser's share picker for the session's screen share: a screen, window or tab, or one panel of\n * this page where the browser can narrow a capture to it.\n */\n public RequestDisplayCapture(options?: DisplayCaptureOptions): Promise<DisplayCaptureResult> {\n return RequestDisplayCapture(options);\n }\n\n /**\n * A fresh, unstarted 48 kHz Opus recorder for this call. {@link RealtimeAudioRecorder}\n * implements the runtime's recorder contract itself (packets out, sample count back), so no\n * adapter sits in between. When the browser cannot record, the recorder disables itself on\n * Start and the runtime sees `IsRecording === false`, which it treats as \"recording is off\".\n */\n public CreateRecorder(): IRealtimeSessionRecorder | null {\n return new RealtimeAudioRecorder();\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { IMetadataProvider } from '@memberjunction/core';
3
- import { type RunDecisionParams, type RunDecisionResult } from '@memberjunction/graphql-dataprovider';
3
+ import { type RunDecisionParams, type RunDecisionResult, type AgentReplyAcknowledgement } from '@memberjunction/graphql-dataprovider';
4
4
  import { ExecuteAgentResult, AgentExecutionProgressCallback } from '@memberjunction/ai-core-plus';
5
5
  import { MJConversationDetailEntity } from '@memberjunction/core-entities';
6
6
  import { MJAIAgentEntityExtended, MJAIAgentRunEntityExtended } from '@memberjunction/ai-core-plus';
@@ -46,6 +46,24 @@ export interface IntentCheckResult {
46
46
  reasoning: string;
47
47
  targetArtifactVersionId?: string;
48
48
  }
49
+ /**
50
+ * Where a sub-agent's reply sits in the conversation. The server sets it (only the server writes agent replies), from
51
+ * these checked inputs.
52
+ */
53
+ export interface SubAgentThreading {
54
+ /** The message the reply threads under, when not the user's message (a delegate's reply sits under the manager's). */
55
+ ReplyParentId?: string | null;
56
+ /**
57
+ * An agent (the conversation manager) whose line "Continuing with **{agent}** for refinement..." the server posts
58
+ * before the reply; the reply threads under it.
59
+ */
60
+ AnnouncedByAgentId?: string | null;
61
+ /**
62
+ * The branch the turn runs on when it forks off an earlier message on another branch (such as Regenerate, which
63
+ * creates a new fork before running the agent while the user's message stays on its original branch).
64
+ */
65
+ ReplyBranchId?: string | null;
66
+ }
49
67
  /**
50
68
  * Angular DI service for conversation-level agent orchestration.
51
69
  *
@@ -123,19 +141,21 @@ export declare class ConversationAgentService {
123
141
  * Process a message through the conversation manager agent. Delegates to
124
142
  * `ConversationsRuntime.Instance.AgentRunner.processMessage(...)`.
125
143
  *
126
- * Signature is preserved verbatim from the original service so existing
127
- * call sites continue to compile. The unused `conversationHistory`
128
- * parameter is kept for backwards compatibility (it was already
129
- * documented as "kept for backwards compatibility but not used" in the
130
- * original).
144
+ * The unused `conversationHistory` parameter is kept for backwards compatibility (it was already
145
+ * documented as "kept for backwards compatibility but not used" in the original).
146
+ *
147
+ * @param onReplyAccepted Called with the reply row the server creates for the turn (only the server
148
+ * writes agent replies), before any progress: key the turn's task and completion by its ID.
131
149
  */
132
- ProcessMessage(conversationId: string, message: MJConversationDetailEntity, conversationHistory: MJConversationDetailEntity[], conversationDetailId: string, onProgress?: AgentExecutionProgressCallback, appContext?: Record<string, unknown> | null, planMode?: boolean, requestedSkillIDs?: string[],
150
+ ProcessMessage(conversationId: string, message: MJConversationDetailEntity, conversationHistory: MJConversationDetailEntity[], onReplyAccepted: (reply: AgentReplyAcknowledgement) => void, onProgress?: AgentExecutionProgressCallback, appContext?: Record<string, unknown> | null, planMode?: boolean, requestedSkillIDs?: string[],
133
151
  /** The agents the conversation manager may delegate to. Null or omitted allows every agent. */
134
152
  allowedAgentIDs?: readonly string[] | null,
135
153
  /** The first moment of the conversation the run may read. Null or omitted reads all of it. */
136
- agentHistoryFrom?: Date | null): Promise<ExecuteAgentResult | null>;
154
+ agentHistoryFrom?: Date | null,
155
+ /** The branch the turn runs on when it forks off an earlier message on another branch. */
156
+ replyBranchId?: string | null): Promise<ExecuteAgentResult | null>;
137
157
  /** @deprecated Use {@link ProcessMessage}. */
138
- processMessage(conversationId: string, message: MJConversationDetailEntity, conversationHistory: MJConversationDetailEntity[], conversationDetailId: string, onProgress?: AgentExecutionProgressCallback, appContext?: Record<string, unknown> | null, planMode?: boolean, requestedSkillIDs?: string[], allowedAgentIDs?: readonly string[] | null, agentHistoryFrom?: Date | null): Promise<ExecuteAgentResult | null>;
158
+ processMessage(conversationId: string, message: MJConversationDetailEntity, conversationHistory: MJConversationDetailEntity[], onReplyAccepted: (reply: AgentReplyAcknowledgement) => void, onProgress?: AgentExecutionProgressCallback, appContext?: Record<string, unknown> | null, planMode?: boolean, requestedSkillIDs?: string[], allowedAgentIDs?: readonly string[] | null, agentHistoryFrom?: Date | null, replyBranchId?: string | null): Promise<ExecuteAgentResult | null>;
139
159
  /**
140
160
  * Configuration preset an agent was pinned to by a previous `@mention` in this conversation.
141
161
  *
@@ -176,12 +196,17 @@ export declare class ConversationAgentService {
176
196
  *
177
197
  * Stays on the Angular shim because it directly uses AgentClientService.
178
198
  * Could move to the runtime in a follow-up if needed.
199
+ *
200
+ * @param onReplyAccepted Called with the reply row the server creates for the run (only the server
201
+ * writes agent replies), before any progress: key the run's task and completion by its ID.
179
202
  */
180
- InvokeSubAgent(agentName: string, conversationId: string, message: MJConversationDetailEntity, conversationHistory: MJConversationDetailEntity[], reasoning: string, conversationDetailId: string, payload?: Record<string, unknown> | null, onProgress?: AgentExecutionProgressCallback, sourceArtifactId?: string, sourceArtifactVersionId?: string, agentConfigurationPresetId?: string, appContext?: Record<string, unknown> | null, planMode?: boolean, requestedSkillIDs?: string[],
203
+ InvokeSubAgent(agentName: string, conversationId: string, message: MJConversationDetailEntity, conversationHistory: MJConversationDetailEntity[], reasoning: string, onReplyAccepted: (reply: AgentReplyAcknowledgement) => void, payload?: Record<string, unknown> | null, onProgress?: AgentExecutionProgressCallback, sourceArtifactId?: string, sourceArtifactVersionId?: string, agentConfigurationPresetId?: string, appContext?: Record<string, unknown> | null, planMode?: boolean, requestedSkillIDs?: string[],
181
204
  /** The first moment of the conversation the run may read. Null or omitted reads all of it. */
182
- agentHistoryFrom?: Date | null): Promise<ExecuteAgentResult | null>;
205
+ agentHistoryFrom?: Date | null,
206
+ /** Where the reply sits in the conversation. Omitted, it answers `message` directly. */
207
+ threading?: SubAgentThreading | null): Promise<ExecuteAgentResult | null>;
183
208
  /** @deprecated Use {@link InvokeSubAgent}. */
184
- invokeSubAgent(agentName: string, conversationId: string, message: MJConversationDetailEntity, conversationHistory: MJConversationDetailEntity[], reasoning: string, conversationDetailId: string, payload?: Record<string, unknown> | null, onProgress?: AgentExecutionProgressCallback, sourceArtifactId?: string, sourceArtifactVersionId?: string, agentConfigurationPresetId?: string, appContext?: Record<string, unknown> | null, planMode?: boolean, requestedSkillIDs?: string[], agentHistoryFrom?: Date | null): Promise<ExecuteAgentResult | null>;
209
+ invokeSubAgent(agentName: string, conversationId: string, message: MJConversationDetailEntity, conversationHistory: MJConversationDetailEntity[], reasoning: string, onReplyAccepted: (reply: AgentReplyAcknowledgement) => void, payload?: Record<string, unknown> | null, onProgress?: AgentExecutionProgressCallback, sourceArtifactId?: string, sourceArtifactVersionId?: string, agentConfigurationPresetId?: string, appContext?: Record<string, unknown> | null, planMode?: boolean, requestedSkillIDs?: string[], agentHistoryFrom?: Date | null, threading?: SubAgentThreading | null): Promise<ExecuteAgentResult | null>;
185
210
  /**
186
211
  * Check if user's latest message should continue with the previous agent or route through Sage.
187
212
  * Uses fast inference (<500ms) to determine intent and avoid unnecessary Sage overhead.
@@ -230,7 +255,7 @@ export declare class ConversationAgentService {
230
255
  * plausible, and wrong: the same failure class as {@link FindLatestAgentOutputVersion},
231
256
  * closed the same way.
232
257
  *
233
- * Two reads, not the four the old shape would have needed — see
258
+ * Three reads: the agent's replies, their Output versions, and the artifacts' names. See
234
259
  * {@link AgentArtifactSummary} for why dropping `runId` removes the join back to agent runs.
235
260
  *
236
261
  * @param historyFrom The chat's history floor, when set (see {@link FindAgentArtifacts}).
@@ -249,7 +274,7 @@ export declare class ConversationAgentService {
249
274
  * again" exchanges where payload continuity matters most. A null payload is a LEGAL agent
250
275
  * input, so the failure is silent: the agent regenerates from scratch instead of modifying.
251
276
  *
252
- * One round trip. The subquery walks details -> Output junctions, and versions carry
277
+ * Two reads: the agent's replies, then their newest Output version. Versions carry
253
278
  * `__mj_CreatedAt`, so "newest" is expressible without joining back for `Sequence`.
254
279
  *
255
280
  * @param historyFrom The chat's history floor. When set, only artifacts on replies written at
@@ -261,18 +286,26 @@ export declare class ConversationAgentService {
261
286
  FindLatestAgentOutputVersion(conversationId: string, agentId: string, historyFrom?: Date | null, branchId?: string | null): Promise<AgentPayloadSource | null>;
262
287
  /**
263
288
  * `ArtifactVersion.ID IN (...)` for every OUTPUT artifact an agent produced on one
264
- * conversation path, in messages no rerun replaced. Shared by {@link FindLatestAgentOutputVersion} and
265
- * {@link findAllAgentArtifacts} so the two can never disagree about what "this agent's
266
- * artifacts" means.
289
+ * conversation path, in messages no rerun replaced, or null when the agent has no such reply
290
+ * there. Shared by {@link FindLatestAgentOutputVersion} and {@link findAllAgentArtifacts} so
291
+ * the two can never disagree about what "this agent's artifacts" means.
292
+ *
293
+ * The replies are read with their own RunView ({@link agentReplyIds}), so the row-level
294
+ * security on conversation messages applies. A subquery over their view would skip it, and the
295
+ * server refuses one for a user whose read of messages is row-filtered.
296
+ */
297
+ private agentOutputVersionFilter;
298
+ /**
299
+ * IDs of the agent's replies on one conversation path, in messages no rerun replaced, written
300
+ * at or after the history floor when one is set. Empty when the path cannot be built
301
+ * ({@link branchPathFilter}) or the read fails.
267
302
  *
268
303
  * Filters on the DETAIL's `Status <> 'Error'` rather than the agent run's
269
304
  * `Status = 'Completed'` (which is what the array scan this replaced used). Doing it on the
270
305
  * run would mean joining back to `MJ: AI Agent Runs` purely to restate a condition the
271
306
  * detail already carries.
272
- *
273
- * @param pathFilter The conversation-and-branch predicate from {@link branchPathFilter}.
274
307
  */
275
- private agentOutputVersionFilter;
308
+ private agentReplyIds;
276
309
  /**
277
310
  * The SQL predicate for one branch's path in a conversation, from
278
311
  * `ConversationEngine.BranchPathFilterFresh`. A null or omitted branch is the trunk and costs
@@ -1 +1 @@
1
- {"version":3,"file":"conversation-agent.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/conversation-agent.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAY,iBAAiB,EAAqB,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAwC,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC5I,OAAO,EAAE,kBAAkB,EAAE,8BAA8B,EAAkC,MAAM,8BAA8B,CAAC;AAElI,OAAO,EAEL,0BAA0B,EAG3B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CA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,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAO/E;;;;;;;;OAQG;IACU,kBAAkB,CAC7B,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,IAAI,GAAG,IAAI,EACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAIlC;;;;;;;;;;;;;;;;;;;;;OAqBG;YACW,qBAAqB;IAqCnC,kEAAkE;YACpD,iBAAiB;IAoB/B;;;;;;;;;;;;;;;;;;OAkBG;IACU,4BAA4B,CACvC,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,IAAI,GAAG,IAAI,EACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAUrC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,wBAAwB;IAYhC;;;;;;;;;OASG;YACW,gBAAgB;IAU9B;;;;;;OAMG;IACU,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAI3F;;;;;OAKG;YACW,qBAAqB;yCAhvBxB,wBAAwB;6CAAxB,wBAAwB;CAgxBpC"}
1
+ {"version":3,"file":"conversation-agent.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/conversation-agent.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAyB,iBAAiB,EAAqB,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAwC,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,KAAK,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAC5K,OAAO,EAAE,kBAAkB,EAAE,8BAA8B,EAAkC,MAAM,8BAA8B,CAAC;AAElI,OAAO,EAEL,0BAA0B,EAG3B,MAA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