@memberjunction/conversations-runtime 0.0.1 → 5.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -43
- package/dist/ConversationsRuntime.d.ts +193 -0
- package/dist/ConversationsRuntime.d.ts.map +1 -0
- package/dist/ConversationsRuntime.js +268 -0
- package/dist/ConversationsRuntime.js.map +1 -0
- package/dist/adapters/IActiveTaskTracker.d.ts +49 -0
- package/dist/adapters/IActiveTaskTracker.d.ts.map +1 -0
- package/dist/adapters/IActiveTaskTracker.js +26 -0
- package/dist/adapters/IActiveTaskTracker.js.map +1 -0
- package/dist/adapters/INotificationAdapter.d.ts +60 -0
- package/dist/adapters/INotificationAdapter.d.ts.map +1 -0
- package/dist/adapters/INotificationAdapter.js +45 -0
- package/dist/adapters/INotificationAdapter.js.map +1 -0
- package/dist/adapters/ISessionsAdapter.d.ts +124 -0
- package/dist/adapters/ISessionsAdapter.d.ts.map +1 -0
- package/dist/adapters/ISessionsAdapter.js +44 -0
- package/dist/adapters/ISessionsAdapter.js.map +1 -0
- package/dist/agent-runner/ConversationAgentRunner.d.ts +121 -0
- package/dist/agent-runner/ConversationAgentRunner.d.ts.map +1 -0
- package/dist/agent-runner/ConversationAgentRunner.js +191 -0
- package/dist/agent-runner/ConversationAgentRunner.js.map +1 -0
- package/dist/bridge/ConversationBridge.d.ts +93 -0
- package/dist/bridge/ConversationBridge.d.ts.map +1 -0
- package/dist/bridge/ConversationBridge.js +105 -0
- package/dist/bridge/ConversationBridge.js.map +1 -0
- package/dist/context/IConversationsRuntimeContext.d.ts +29 -0
- package/dist/context/IConversationsRuntimeContext.d.ts.map +1 -0
- package/dist/context/IConversationsRuntimeContext.js +21 -0
- package/dist/context/IConversationsRuntimeContext.js.map +1 -0
- package/dist/default-agent/DefaultAgentResolver.d.ts +87 -0
- package/dist/default-agent/DefaultAgentResolver.d.ts.map +1 -0
- package/dist/default-agent/DefaultAgentResolver.js +103 -0
- package/dist/default-agent/DefaultAgentResolver.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/mentions/MentionParser.d.ts +109 -0
- package/dist/mentions/MentionParser.d.ts.map +1 -0
- package/dist/mentions/MentionParser.js +276 -0
- package/dist/mentions/MentionParser.js.map +1 -0
- package/dist/sessions/SessionsObserver.d.ts +87 -0
- package/dist/sessions/SessionsObserver.d.ts.map +1 -0
- package/dist/sessions/SessionsObserver.js +103 -0
- package/dist/sessions/SessionsObserver.js.map +1 -0
- package/dist/streaming/ConversationStreaming.d.ts +169 -0
- package/dist/streaming/ConversationStreaming.d.ts.map +1 -0
- package/dist/streaming/ConversationStreaming.js +355 -0
- package/dist/streaming/ConversationStreaming.js.map +1 -0
- package/package.json +33 -7
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Observability surface for AI Agent Sessions & Channels lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* `SessionsObserver` is the runtime's framework-agnostic re-broadcaster of
|
|
5
|
+
* session lifecycle events that originate from PR #2787's Sessions/Channels
|
|
6
|
+
* infrastructure. It does NOT subscribe directly to any Angular service or
|
|
7
|
+
* realtime client — those concerns live behind an {@link ISessionsAdapter} the
|
|
8
|
+
* host registers at bootstrap (typically `RealtimeSessionsAdapter` in
|
|
9
|
+
* `@memberjunction/ng-conversations`, but anything implementing the contract
|
|
10
|
+
* works — a React host, a Node test harness, a server-side runner, etc.).
|
|
11
|
+
*
|
|
12
|
+
* **What you get on `SessionLifecycle$`:**
|
|
13
|
+
* - `session-started` — a new realtime session has fully started (sessionId is
|
|
14
|
+
* non-null, the realtime client is connected). Adapter implementations are
|
|
15
|
+
* responsible for emitting only AFTER all the prerequisites are satisfied
|
|
16
|
+
* (e.g., the Angular `RealtimeSessionsAdapter` waits for both `Active$` AND a
|
|
17
|
+
* non-null `agentSessionId`).
|
|
18
|
+
* - `session-channel` — a channel (voice/whiteboard/whatever) opened or closed
|
|
19
|
+
* inside the session. The `state` union is intentionally narrow
|
|
20
|
+
* (`'open' | 'closed'`) because no per-channel transition observable exists
|
|
21
|
+
* today; see `ISessionsAdapter` JSDoc for the rationale.
|
|
22
|
+
* - `session-ended` — the session ended client-side. `reason` is a narrowed
|
|
23
|
+
* union (`'explicit' | 'error' | 'unknown'`) — see `ISessionsAdapter`.
|
|
24
|
+
*
|
|
25
|
+
* **What you DON'T get:** server-side close events that fire while the user's
|
|
26
|
+
* tab is gone (janitor sweep, host shutdown). Those flow into the `MJ: AI Agent
|
|
27
|
+
* Sessions` row's `CloseReason` column but are not pushed to the client today.
|
|
28
|
+
* Admin/observability tooling polls the entity for those — out of scope for
|
|
29
|
+
* the orchestration runtime.
|
|
30
|
+
*
|
|
31
|
+
* @module @memberjunction/conversations-runtime
|
|
32
|
+
*/
|
|
33
|
+
import { Observable } from 'rxjs';
|
|
34
|
+
import { ISessionsAdapter, SessionLifecycleEvent } from '../adapters/ISessionsAdapter.js';
|
|
35
|
+
export type { SessionLifecycleEvent, SessionChannelState, SessionEndReason, } from '../adapters/ISessionsAdapter.js';
|
|
36
|
+
/**
|
|
37
|
+
* Observes Sessions/Channels lifecycle from the registered adapter and
|
|
38
|
+
* re-broadcasts via `SessionLifecycle$`.
|
|
39
|
+
*
|
|
40
|
+
* **Lifecycle:** constructed once by `ConversationsRuntime` (singleton). Stays
|
|
41
|
+
* subscribed to the adapter's stream until `Dispose()` is called. Adapter swaps
|
|
42
|
+
* via `UseSessionsAdapter` unsubscribe the prior adapter cleanly.
|
|
43
|
+
*
|
|
44
|
+
* Usually accessed via `ConversationsRuntime.Instance.Sessions`.
|
|
45
|
+
*/
|
|
46
|
+
export declare class SessionsObserver {
|
|
47
|
+
/**
|
|
48
|
+
* Stream of session lifecycle events from whatever adapter is currently
|
|
49
|
+
* registered. Subscribers see only events that occur AFTER they subscribe —
|
|
50
|
+
* `SessionsObserver` does not replay history (use `RealtimeSessionReviewService`
|
|
51
|
+
* for past-session loading, separate concern).
|
|
52
|
+
*/
|
|
53
|
+
readonly SessionLifecycle$: Observable<SessionLifecycleEvent>;
|
|
54
|
+
private readonly _lifecycle$;
|
|
55
|
+
private _adapter;
|
|
56
|
+
private _adapterSub;
|
|
57
|
+
constructor();
|
|
58
|
+
/**
|
|
59
|
+
* Register the adapter that produces session events. Replaces any prior
|
|
60
|
+
* adapter and cleanly tears down the previous subscription. Typically called
|
|
61
|
+
* once at host bootstrap (e.g., Angular's `ConversationsRuntimeBootstrap`),
|
|
62
|
+
* but multiple swaps are supported (e.g., test harnesses that switch
|
|
63
|
+
* adapters between cases).
|
|
64
|
+
*/
|
|
65
|
+
UseSessionsAdapter(adapter: ISessionsAdapter): void;
|
|
66
|
+
/**
|
|
67
|
+
* Whether a non-default adapter is currently registered. Useful for
|
|
68
|
+
* diagnostics ("are sessions actually wired up on this host?") and for
|
|
69
|
+
* features that should gate themselves on real wiring.
|
|
70
|
+
*/
|
|
71
|
+
get IsWired(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* The currently registered adapter. Provided for diagnostics; consumers
|
|
74
|
+
* should subscribe to `SessionLifecycle$` instead of reaching into the
|
|
75
|
+
* adapter directly.
|
|
76
|
+
*/
|
|
77
|
+
get Adapter(): ISessionsAdapter;
|
|
78
|
+
/**
|
|
79
|
+
* Tear down the adapter subscription and complete the lifecycle stream.
|
|
80
|
+
* Safe to call multiple times. After Dispose, subscribers will receive a
|
|
81
|
+
* `complete` notification on `SessionLifecycle$`.
|
|
82
|
+
*/
|
|
83
|
+
Dispose(): void;
|
|
84
|
+
/** Forwards adapter events into our internal Subject. */
|
|
85
|
+
private subscribeToAdapter;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=SessionsObserver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionsObserver.d.ts","sourceRoot":"","sources":["../../src/sessions/SessionsObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,UAAU,EAAyB,MAAM,MAAM,CAAC;AACzD,OAAO,EACH,gBAAgB,EAEhB,qBAAqB,EACxB,MAAM,8BAA8B,CAAC;AAItC,YAAY,EACR,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,GACnB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;;;GASG;AACH,qBAAa,gBAAgB;IACzB;;;;;OAKG;IACH,SAAgB,iBAAiB,EAAE,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAErE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwC;IACpE,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,WAAW,CAA6B;;IAShD;;;;;;OAMG;IACI,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAM1D;;;;OAIG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;;OAIG;IACH,IAAW,OAAO,IAAI,gBAAgB,CAErC;IAED;;;;OAIG;IACI,OAAO,IAAI,IAAI;IAMtB,yDAAyD;IACzD,OAAO,CAAC,kBAAkB;CAS7B"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Observability surface for AI Agent Sessions & Channels lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* `SessionsObserver` is the runtime's framework-agnostic re-broadcaster of
|
|
5
|
+
* session lifecycle events that originate from PR #2787's Sessions/Channels
|
|
6
|
+
* infrastructure. It does NOT subscribe directly to any Angular service or
|
|
7
|
+
* realtime client — those concerns live behind an {@link ISessionsAdapter} the
|
|
8
|
+
* host registers at bootstrap (typically `RealtimeSessionsAdapter` in
|
|
9
|
+
* `@memberjunction/ng-conversations`, but anything implementing the contract
|
|
10
|
+
* works — a React host, a Node test harness, a server-side runner, etc.).
|
|
11
|
+
*
|
|
12
|
+
* **What you get on `SessionLifecycle$`:**
|
|
13
|
+
* - `session-started` — a new realtime session has fully started (sessionId is
|
|
14
|
+
* non-null, the realtime client is connected). Adapter implementations are
|
|
15
|
+
* responsible for emitting only AFTER all the prerequisites are satisfied
|
|
16
|
+
* (e.g., the Angular `RealtimeSessionsAdapter` waits for both `Active$` AND a
|
|
17
|
+
* non-null `agentSessionId`).
|
|
18
|
+
* - `session-channel` — a channel (voice/whiteboard/whatever) opened or closed
|
|
19
|
+
* inside the session. The `state` union is intentionally narrow
|
|
20
|
+
* (`'open' | 'closed'`) because no per-channel transition observable exists
|
|
21
|
+
* today; see `ISessionsAdapter` JSDoc for the rationale.
|
|
22
|
+
* - `session-ended` — the session ended client-side. `reason` is a narrowed
|
|
23
|
+
* union (`'explicit' | 'error' | 'unknown'`) — see `ISessionsAdapter`.
|
|
24
|
+
*
|
|
25
|
+
* **What you DON'T get:** server-side close events that fire while the user's
|
|
26
|
+
* tab is gone (janitor sweep, host shutdown). Those flow into the `MJ: AI Agent
|
|
27
|
+
* Sessions` row's `CloseReason` column but are not pushed to the client today.
|
|
28
|
+
* Admin/observability tooling polls the entity for those — out of scope for
|
|
29
|
+
* the orchestration runtime.
|
|
30
|
+
*
|
|
31
|
+
* @module @memberjunction/conversations-runtime
|
|
32
|
+
*/
|
|
33
|
+
import { Subject } from 'rxjs';
|
|
34
|
+
import { NoOpSessionsAdapter, } from '../adapters/ISessionsAdapter.js';
|
|
35
|
+
/**
|
|
36
|
+
* Observes Sessions/Channels lifecycle from the registered adapter and
|
|
37
|
+
* re-broadcasts via `SessionLifecycle$`.
|
|
38
|
+
*
|
|
39
|
+
* **Lifecycle:** constructed once by `ConversationsRuntime` (singleton). Stays
|
|
40
|
+
* subscribed to the adapter's stream until `Dispose()` is called. Adapter swaps
|
|
41
|
+
* via `UseSessionsAdapter` unsubscribe the prior adapter cleanly.
|
|
42
|
+
*
|
|
43
|
+
* Usually accessed via `ConversationsRuntime.Instance.Sessions`.
|
|
44
|
+
*/
|
|
45
|
+
export class SessionsObserver {
|
|
46
|
+
constructor() {
|
|
47
|
+
this._lifecycle$ = new Subject();
|
|
48
|
+
this._adapterSub = null;
|
|
49
|
+
this.SessionLifecycle$ = this._lifecycle$.asObservable();
|
|
50
|
+
// Default to no-op so consumers can subscribe immediately without an adapter.
|
|
51
|
+
this._adapter = new NoOpSessionsAdapter();
|
|
52
|
+
this.subscribeToAdapter();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Register the adapter that produces session events. Replaces any prior
|
|
56
|
+
* adapter and cleanly tears down the previous subscription. Typically called
|
|
57
|
+
* once at host bootstrap (e.g., Angular's `ConversationsRuntimeBootstrap`),
|
|
58
|
+
* but multiple swaps are supported (e.g., test harnesses that switch
|
|
59
|
+
* adapters between cases).
|
|
60
|
+
*/
|
|
61
|
+
UseSessionsAdapter(adapter) {
|
|
62
|
+
this._adapterSub?.unsubscribe();
|
|
63
|
+
this._adapter = adapter;
|
|
64
|
+
this.subscribeToAdapter();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether a non-default adapter is currently registered. Useful for
|
|
68
|
+
* diagnostics ("are sessions actually wired up on this host?") and for
|
|
69
|
+
* features that should gate themselves on real wiring.
|
|
70
|
+
*/
|
|
71
|
+
get IsWired() {
|
|
72
|
+
return !(this._adapter instanceof NoOpSessionsAdapter);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The currently registered adapter. Provided for diagnostics; consumers
|
|
76
|
+
* should subscribe to `SessionLifecycle$` instead of reaching into the
|
|
77
|
+
* adapter directly.
|
|
78
|
+
*/
|
|
79
|
+
get Adapter() {
|
|
80
|
+
return this._adapter;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Tear down the adapter subscription and complete the lifecycle stream.
|
|
84
|
+
* Safe to call multiple times. After Dispose, subscribers will receive a
|
|
85
|
+
* `complete` notification on `SessionLifecycle$`.
|
|
86
|
+
*/
|
|
87
|
+
Dispose() {
|
|
88
|
+
this._adapterSub?.unsubscribe();
|
|
89
|
+
this._adapterSub = null;
|
|
90
|
+
this._lifecycle$.complete();
|
|
91
|
+
}
|
|
92
|
+
/** Forwards adapter events into our internal Subject. */
|
|
93
|
+
subscribeToAdapter() {
|
|
94
|
+
this._adapterSub = this._adapter.SessionLifecycle$.subscribe({
|
|
95
|
+
next: (event) => this._lifecycle$.next(event),
|
|
96
|
+
// Don't surface adapter errors to consumers — they're host-specific.
|
|
97
|
+
// The adapter is responsible for its own resilience; we just keep
|
|
98
|
+
// our broadcast stream alive for the next adapter swap.
|
|
99
|
+
error: () => undefined,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=SessionsObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionsObserver.js","sourceRoot":"","sources":["../../src/sessions/SessionsObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAc,OAAO,EAAgB,MAAM,MAAM,CAAC;AACzD,OAAO,EAEH,mBAAmB,GAEtB,MAAM,8BAA8B,CAAC;AAUtC;;;;;;;;;GASG;AACH,MAAM,OAAO,gBAAgB;IAazB;QAJiB,gBAAW,GAAG,IAAI,OAAO,EAAyB,CAAC;QAE5D,gBAAW,GAAwB,IAAI,CAAC;QAG5C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;QACzD,8EAA8E;QAC9E,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAC1C,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACI,kBAAkB,CAAC,OAAyB;QAC/C,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,IAAW,OAAO;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,YAAY,mBAAmB,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAED,yDAAyD;IACjD,kBAAkB;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,SAAS,CAAC;YACzD,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC;YAC7C,qEAAqE;YACrE,kEAAkE;YAClE,wDAAwD;YACxD,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS;SACzB,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Pure-TypeScript streaming layer for conversation progress + completion.
|
|
3
|
+
*
|
|
4
|
+
* Ported from `@memberjunction/ng-conversations/src/lib/services/conversation-streaming.service.ts`.
|
|
5
|
+
* The original was largely framework-agnostic — the `@Injectable()` decorator was the only
|
|
6
|
+
* Angular dep, and `OnDestroy` was its only Angular lifecycle hook. We strip both, replace
|
|
7
|
+
* `OnDestroy` with an explicit `Dispose()` method, and route `removeByAgentRunId` calls
|
|
8
|
+
* through the {@link IActiveTaskTracker} adapter instead of Angular DI.
|
|
9
|
+
*
|
|
10
|
+
* Maintains a single PubSub subscription to `GraphQLDataProvider.PushStatusUpdates()` and
|
|
11
|
+
* routes progress + completion events to registered per-message callbacks. Handles late-
|
|
12
|
+
* arrival replay (5-min window) so a component that mounts after an agent run finished can
|
|
13
|
+
* still see the completion.
|
|
14
|
+
*
|
|
15
|
+
* @module @memberjunction/conversations-runtime
|
|
16
|
+
*/
|
|
17
|
+
import { Subject } from 'rxjs';
|
|
18
|
+
import { IConversationsRuntimeContext } from '../context/IConversationsRuntimeContext.js';
|
|
19
|
+
/**
|
|
20
|
+
* Completion event broadcast when an agent finishes. Includes enriched result data from
|
|
21
|
+
* the server's fire-and-forget completion event.
|
|
22
|
+
*/
|
|
23
|
+
export interface CompletionEvent {
|
|
24
|
+
conversationDetailId: string;
|
|
25
|
+
agentRunId: string;
|
|
26
|
+
/** Whether the agent execution succeeded. */
|
|
27
|
+
success?: boolean;
|
|
28
|
+
/** Error message if the agent execution failed. */
|
|
29
|
+
errorMessage?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Metadata structure for message progress updates. */
|
|
32
|
+
export interface MessageProgressMetadata {
|
|
33
|
+
/** Progress details (from RunAIAgentResolver). */
|
|
34
|
+
progress?: {
|
|
35
|
+
hierarchicalStep?: string;
|
|
36
|
+
percentage?: number;
|
|
37
|
+
message?: string;
|
|
38
|
+
stepCount?: number;
|
|
39
|
+
agentName?: string;
|
|
40
|
+
agentType?: string;
|
|
41
|
+
};
|
|
42
|
+
/** Agent run information (from RunAIAgentResolver). */
|
|
43
|
+
agentRun?: {
|
|
44
|
+
Agent?: string;
|
|
45
|
+
ConversationDetailID?: string;
|
|
46
|
+
ID?: string;
|
|
47
|
+
};
|
|
48
|
+
/** Agent run ID (alternative to agentRun.ID). */
|
|
49
|
+
agentRunId?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Single progress update for a message. */
|
|
52
|
+
export interface MessageProgressUpdate {
|
|
53
|
+
message: string;
|
|
54
|
+
percentComplete?: number;
|
|
55
|
+
taskName?: string;
|
|
56
|
+
conversationDetailId: string;
|
|
57
|
+
metadata?: MessageProgressMetadata;
|
|
58
|
+
stepCount?: number;
|
|
59
|
+
/** Which backend resolver published this update. */
|
|
60
|
+
resolver?: 'TaskOrchestrator' | 'RunAIAgentResolver' | string;
|
|
61
|
+
}
|
|
62
|
+
/** Callback type for progress updates. */
|
|
63
|
+
export type MessageProgressCallback = (progress: MessageProgressUpdate) => Promise<void> | void;
|
|
64
|
+
/** Connection status for the streaming service. */
|
|
65
|
+
export type StreamingConnectionStatus = 'connected' | 'disconnected' | 'error' | 'reconnecting';
|
|
66
|
+
/**
|
|
67
|
+
* Global streaming service that manages PubSub subscriptions for all conversations.
|
|
68
|
+
*
|
|
69
|
+
* Maintains a single GraphQL subscription and routes updates to registered per-message
|
|
70
|
+
* callbacks, regardless of which conversation is currently visible. This ensures
|
|
71
|
+
* messages update correctly even when users navigate away and return.
|
|
72
|
+
*
|
|
73
|
+
* Usually accessed via `ConversationsRuntime.Instance.Streaming`.
|
|
74
|
+
*/
|
|
75
|
+
export declare class ConversationStreaming {
|
|
76
|
+
private readonly context;
|
|
77
|
+
private pushStatusSubscription?;
|
|
78
|
+
private readonly callbackRegistry;
|
|
79
|
+
private readonly recentCompletions;
|
|
80
|
+
private readonly connectionStatus$;
|
|
81
|
+
private initialized;
|
|
82
|
+
private reconnectionTimeout?;
|
|
83
|
+
/**
|
|
84
|
+
* Observable for components to subscribe to completion events in real-time.
|
|
85
|
+
* Emits enriched completion data once per agent finish.
|
|
86
|
+
*/
|
|
87
|
+
readonly completionEvents$: Subject<CompletionEvent>;
|
|
88
|
+
/**
|
|
89
|
+
* @param context Runtime context providing live access to the registered
|
|
90
|
+
* {@link IActiveTaskTracker}. Read on every event dispatch so adapter swaps
|
|
91
|
+
* after construction are picked up immediately.
|
|
92
|
+
*/
|
|
93
|
+
constructor(context: IConversationsRuntimeContext);
|
|
94
|
+
/**
|
|
95
|
+
* Initialize the global PubSub subscription. Idempotent — safe to call multiple
|
|
96
|
+
* times. Should be called once at app startup (e.g., the Angular widget calls
|
|
97
|
+
* this when the workspace mounts).
|
|
98
|
+
*/
|
|
99
|
+
initialize(): void;
|
|
100
|
+
/** Current connection status as an observable. */
|
|
101
|
+
getConnectionStatus$(): import("rxjs").Observable<StreamingConnectionStatus>;
|
|
102
|
+
/** Current connection status value (synchronous). */
|
|
103
|
+
getConnectionStatus(): StreamingConnectionStatus;
|
|
104
|
+
/**
|
|
105
|
+
* Register a callback for a specific conversation detail (message). The callback
|
|
106
|
+
* is invoked whenever progress updates arrive for that message.
|
|
107
|
+
*/
|
|
108
|
+
registerMessageCallback(conversationDetailId: string, callback: MessageProgressCallback): void;
|
|
109
|
+
/**
|
|
110
|
+
* Unregister a callback for a specific conversation detail. When `callback` is
|
|
111
|
+
* omitted, ALL callbacks for that message are removed.
|
|
112
|
+
*/
|
|
113
|
+
unregisterMessageCallback(conversationDetailId: string, callback?: MessageProgressCallback): void;
|
|
114
|
+
/** Total number of registered callbacks (diagnostic). */
|
|
115
|
+
getRegisteredCallbackCount(): number;
|
|
116
|
+
/** Number of distinct messages currently being tracked (diagnostic). */
|
|
117
|
+
getTrackedMessageCount(): number;
|
|
118
|
+
/**
|
|
119
|
+
* Replay a recently completed event so a late-mounting component can pick it up.
|
|
120
|
+
* Returns `undefined` if no completion is in the 5-minute replay window.
|
|
121
|
+
*/
|
|
122
|
+
getRecentCompletion(conversationDetailId: string): {
|
|
123
|
+
agentRunId: string;
|
|
124
|
+
} | undefined;
|
|
125
|
+
/** Clear a recent completion after the late-mounting component has handled it. */
|
|
126
|
+
clearRecentCompletion(conversationDetailId: string): void;
|
|
127
|
+
/**
|
|
128
|
+
* Diagnostic snapshot for a specific message — used by debugging tools to dump
|
|
129
|
+
* live in-memory state.
|
|
130
|
+
*/
|
|
131
|
+
getDiagnosticSnapshot(messageId: string): {
|
|
132
|
+
hasCallbacks: boolean;
|
|
133
|
+
callbackCount: number;
|
|
134
|
+
recentCompletion: {
|
|
135
|
+
conversationDetailId: string;
|
|
136
|
+
agentRunId: string;
|
|
137
|
+
timestamp: Date;
|
|
138
|
+
} | undefined;
|
|
139
|
+
connectionStatus: StreamingConnectionStatus;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Tear down subscriptions and clear state. Call at app shutdown or in tests
|
|
143
|
+
* between cases.
|
|
144
|
+
*/
|
|
145
|
+
Dispose(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Route an incoming PubSub status update to the right handler based on which
|
|
148
|
+
* resolver published it.
|
|
149
|
+
*/
|
|
150
|
+
private handlePushStatusUpdate;
|
|
151
|
+
/**
|
|
152
|
+
* Route a TaskOrchestrator progress update to the message-scoped callback set,
|
|
153
|
+
* keyed by `conversationDetailId`.
|
|
154
|
+
*/
|
|
155
|
+
private routeTaskProgress;
|
|
156
|
+
/**
|
|
157
|
+
* Route a RunAIAgentResolver progress update. Handles both progress messages and
|
|
158
|
+
* completion messages (which include enriched result data and trigger the
|
|
159
|
+
* `completionEvents$` broadcast + active-task cleanup).
|
|
160
|
+
*/
|
|
161
|
+
private routeAgentProgress;
|
|
162
|
+
/** Invoke every callback registered for `conversationDetailId`, swallowing per-callback errors. */
|
|
163
|
+
private dispatchCallbacks;
|
|
164
|
+
/** Schedule a reconnection attempt after a connection error or completion. */
|
|
165
|
+
private scheduleReconnection;
|
|
166
|
+
/** Evict completions older than the replay window to bound memory. */
|
|
167
|
+
private cleanupOldCompletions;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=ConversationStreaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversationStreaming.d.ts","sourceRoot":"","sources":["../../src/streaming/ConversationStreaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAmB,OAAO,EAAgB,MAAM,MAAM,CAAC;AAG9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAEvF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC5B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mDAAmD;IACnD,YAAY,CAAC,EAAE,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