@memberjunction/ai-bridge-server 6.2.0-edge.2 → 6.2.0-edge.4
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 +86 -12
- package/dist/ai-bridge-engine.d.ts +436 -38
- package/dist/ai-bridge-engine.d.ts.map +1 -1
- package/dist/ai-bridge-engine.js +878 -84
- package/dist/ai-bridge-engine.js.map +1 -1
- package/dist/bridge-prior-transcript.d.ts +39 -0
- package/dist/bridge-prior-transcript.d.ts.map +1 -0
- package/dist/bridge-prior-transcript.js +56 -0
- package/dist/bridge-prior-transcript.js.map +1 -0
- package/dist/calendar-watcher.d.ts.map +1 -1
- package/dist/calendar-watcher.js +1 -0
- package/dist/calendar-watcher.js.map +1 -1
- package/dist/dtmf-coalescer.d.ts +32 -0
- package/dist/dtmf-coalescer.d.ts.map +1 -0
- package/dist/dtmf-coalescer.js +60 -0
- package/dist/dtmf-coalescer.js.map +1 -0
- package/dist/full-duplex-turn-gate.d.ts +155 -0
- package/dist/full-duplex-turn-gate.d.ts.map +1 -0
- package/dist/full-duplex-turn-gate.js +229 -0
- package/dist/full-duplex-turn-gate.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/loopback-bridge.d.ts +33 -1
- package/dist/loopback-bridge.d.ts.map +1 -1
- package/dist/loopback-bridge.js +39 -0
- package/dist/loopback-bridge.js.map +1 -1
- package/dist/multi-agent-room-coordinator.d.ts +226 -24
- package/dist/multi-agent-room-coordinator.d.ts.map +1 -1
- package/dist/multi-agent-room-coordinator.js +376 -39
- package/dist/multi-agent-room-coordinator.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { IMetadataProvider, IStartupSink, UserInfo } from '@memberjunction/core';
|
|
2
2
|
import { BaseSingleton } from '@memberjunction/global';
|
|
3
|
-
import { IRealtimeSession } from '@memberjunction/ai';
|
|
3
|
+
import { IRealtimeSession, type Fmp4Init } from '@memberjunction/ai';
|
|
4
4
|
import { MJAIBridgeProviderEntity, MJAIBridgeAgentIdentityEntity, MJAIBridgeProviderChannelEntity } from '@memberjunction/core-entities';
|
|
5
|
-
import { AIBridgeEngineBase, BaseRealtimeBridge, BridgeDisconnectReason, TurnTakingPolicy, TurnTakingPolicyConfig, BridgeTurnMode, IAddressedMatcher, IWorthSayingScorer, IBridgeChannelHost, BridgeChannelToolDefinition, BridgeChannelToolResult, BridgeNativeSdkBinding } from '@memberjunction/ai-bridge-base';
|
|
6
|
-
import { MultiAgentRoomCoordinator } from './multi-agent-room-coordinator.js';
|
|
5
|
+
import { AIBridgeEngineBase, BaseRealtimeBridge, BridgeDisconnectReason, TurnTakingPolicy, TurnTakingPolicyConfig, BridgeTurnMode, IAddressedMatcher, IWorthSayingScorer, IBridgeChannelHost, BridgeChannelToolDefinition, BridgeChannelToolResult, BridgeNativeSdkBinding, ModelSideAddressedMatcher, ResolvedTurnAddressingMode, TurnAddressingMode } from '@memberjunction/ai-bridge-base';
|
|
6
|
+
import { MultiAgentRoomCoordinator, RoomCoordinatorLimits, RoomFloorState } from './multi-agent-room-coordinator.js';
|
|
7
|
+
import { FullDuplexTurnGate, HumanSpeechDetector } from './full-duplex-turn-gate.js';
|
|
8
|
+
import { DtmfCoalescer } from './dtmf-coalescer.js';
|
|
9
|
+
import { BridgeTranscriptTurn } from './bridge-prior-transcript.js';
|
|
7
10
|
/**
|
|
8
11
|
* Finalizes the co-agent observability run(s) for an agent session when a bridge is torn down WITHOUT a
|
|
9
12
|
* live in-memory session — a prior-boot orphan or a cross-host reap, where the agent layer's `Close()`-wrapped
|
|
@@ -98,33 +101,53 @@ export interface TurnModeratorContext {
|
|
|
98
101
|
*/
|
|
99
102
|
export type TurnModerator = (ctx: TurnModeratorContext) => Promise<string[]>;
|
|
100
103
|
/**
|
|
101
|
-
* The
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
104
|
+
* The identity of the server instance that hosts this engine, and of its current boot. The engine stamps
|
|
105
|
+
* {@link IHostInstanceIdentity.GetHostInstanceID} into the `HostInstanceID` of every `MJ: AI Agent Session Bridges`
|
|
106
|
+
* row it creates, and its orphan reconcile ({@link AIBridgeEngine.ReconcileOrphans}) closes the rows that
|
|
107
|
+
* {@link IHostInstanceIdentity.IsPriorBoot} says an earlier boot of this instance left.
|
|
108
|
+
*
|
|
109
|
+
* An instance must be something only one live process can be at a time, so that a row stamped by another boot of it
|
|
110
|
+
* was left by a process that has ended. MJServer's instance is a host and the port it serves on; it injects the
|
|
111
|
+
* identity its `MJ: AI Agent Sessions` rows carry (`hostname:port:pid:bootId`). The identity is **injected**
|
|
112
|
+
* ({@link AIBridgeEngine.SetHostInstanceIdentity}) so this server-tier engine has no dependency on MJServer (a
|
|
113
|
+
* layering inversion) and tests can supply a fixed one; a {@link DefaultHostInstanceIdentity} applies until then.
|
|
105
114
|
*
|
|
106
115
|
* @see `/plans/realtime/realtime-bridges-architecture.md` §10 (host affinity + janitor).
|
|
107
116
|
*/
|
|
108
117
|
export interface IHostInstanceIdentity {
|
|
109
|
-
/**
|
|
118
|
+
/** This boot's id, stamped into the `HostInstanceID` of the bridge rows it creates. */
|
|
110
119
|
GetHostInstanceID(): string;
|
|
111
|
-
/**
|
|
112
|
-
|
|
120
|
+
/**
|
|
121
|
+
* The prefix every boot of this instance stamps and no other instance's id starts with. The reconcile reads the
|
|
122
|
+
* open bridge rows under it (a SQL `LIKE`), then asks {@link IHostInstanceIdentity.IsPriorBoot} about each one.
|
|
123
|
+
*/
|
|
124
|
+
GetInstancePrefix(): string;
|
|
125
|
+
/**
|
|
126
|
+
* Whether a `HostInstanceID` was stamped by another boot of this instance, a process that has ended. False for
|
|
127
|
+
* this boot's id, for any other instance's, and for null. The reconcile closes a row only when this is true, so
|
|
128
|
+
* the check must be exact: a SQL `LIKE` reads a `_` in a host name as any character.
|
|
129
|
+
*
|
|
130
|
+
* @param hostInstanceID A bridge row's `HostInstanceID`.
|
|
131
|
+
*/
|
|
132
|
+
IsPriorBoot(hostInstanceID: string | null | undefined): boolean;
|
|
113
133
|
}
|
|
114
134
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
135
|
+
* The {@link IHostInstanceIdentity} the engine uses until the host injects one: this process alone, on this host.
|
|
136
|
+
* Its id is `hostname:pid-<pid>:<pid>:<bootId>`, the shape MJServer gives a process that serves no port, so
|
|
137
|
+
* {@link DefaultHostInstanceIdentity.IsPriorBoot} matches only an earlier process that had this pid on this host,
|
|
138
|
+
* which has ended. It never matches another live process's bridges. A host whose instance outlives a restart (MJServer:
|
|
139
|
+
* a host and a port) injects its own identity, so that its reconcile closes what an earlier boot left.
|
|
119
140
|
*/
|
|
120
141
|
export declare class DefaultHostInstanceIdentity implements IHostInstanceIdentity {
|
|
121
|
-
private readonly
|
|
142
|
+
private readonly instancePrefix;
|
|
122
143
|
private readonly instanceId;
|
|
123
144
|
constructor();
|
|
124
145
|
/** @inheritdoc */
|
|
125
146
|
GetHostInstanceID(): string;
|
|
126
147
|
/** @inheritdoc */
|
|
127
|
-
|
|
148
|
+
GetInstancePrefix(): string;
|
|
149
|
+
/** @inheritdoc */
|
|
150
|
+
IsPriorBoot(hostInstanceID: string | null | undefined): boolean;
|
|
128
151
|
}
|
|
129
152
|
/**
|
|
130
153
|
* Parameters for {@link AIBridgeEngine.StartBridgeSession}.
|
|
@@ -169,6 +192,25 @@ export interface StartBridgeSessionParams {
|
|
|
169
192
|
TurnScorer?: IWorthSayingScorer;
|
|
170
193
|
/** Optional extra turn-taking tuning (silence window, throttle, score threshold, clock). */
|
|
171
194
|
TurnTuning?: Partial<Omit<TurnTakingPolicyConfig, 'Mode' | 'Matcher' | 'Scorer'>>;
|
|
195
|
+
/**
|
|
196
|
+
* How this session decides it was addressed. `'Auto'` (the default when set) uses the MODEL's own
|
|
197
|
+
* judgement when its session reports full-duplex capability and falls back to name matching otherwise;
|
|
198
|
+
* `'ModelSide'` / `'Regex'` force one. When omitted the engine keeps the legacy behaviour and uses
|
|
199
|
+
* {@link StartBridgeSessionParams.TurnMatcher} as given. An explicit `TurnMatcher` is still honoured as
|
|
200
|
+
* the `Regex`-side matcher (e.g. a 1:1 call's always-addressed matcher).
|
|
201
|
+
*/
|
|
202
|
+
TurnAddressing?: TurnAddressingMode;
|
|
203
|
+
/**
|
|
204
|
+
* Whether this session is full-duplex. When omitted, defaults to
|
|
205
|
+
* `RealtimeSession.Capabilities?.FullDuplex === true`.
|
|
206
|
+
*/
|
|
207
|
+
FullDuplex?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Whether a full-duplex model's outbound audio runs through the room floor gate in a MULTI-agent room
|
|
210
|
+
* (the safety net behind the model's own turn-taking). Defaults to `true`; sessions whose model is not
|
|
211
|
+
* full-duplex are never gated. Set `false` to let a full-duplex agent speak freely (debugging).
|
|
212
|
+
*/
|
|
213
|
+
FullDuplexTurnGate?: boolean;
|
|
172
214
|
/**
|
|
173
215
|
* **Multi-agent meeting mode.** When `true`, the realtime model's blind auto-response was disabled at
|
|
174
216
|
* session start (the agent layer set `disableAutoResponse` on the model session), so the BRIDGE is the
|
|
@@ -224,6 +266,85 @@ export interface StartBridgeSessionParams {
|
|
|
224
266
|
* + per-agent `turnTaking.mode` from this agent's config.
|
|
225
267
|
*/
|
|
226
268
|
TargetAgentID?: string;
|
|
269
|
+
/**
|
|
270
|
+
* Where THIS session's final transcript lines go. When set, every final line (both roles) is written through
|
|
271
|
+
* it directly — no room scribe is elected and the process-wide transcript sink is bypassed. A phone call uses
|
|
272
|
+
* it to write into the call's own conversation instead of a shared "Meeting Room" one.
|
|
273
|
+
*/
|
|
274
|
+
TranscriptSink?: BridgeTranscriptSink;
|
|
275
|
+
/**
|
|
276
|
+
* Called when the caller/participant talks over the agent (a true barge-in). The telephony host uses it to drop
|
|
277
|
+
* queued spoken progress, which is now stale. It must NOT abort delegated work: the host policy (mirroring the
|
|
278
|
+
* browser runtime, `RealtimeSessionRuntime.ts` ~L1956-1963) is that the user keeps talking while delegated work
|
|
279
|
+
* runs, and cancelling on speech would kill exactly the jobs they asked for. Explicit cancellation is a separate
|
|
280
|
+
* act (the phone's `cancel_pending_work` tool). Must not throw; a throw is logged and swallowed.
|
|
281
|
+
*/
|
|
282
|
+
OnBargeIn?: () => void;
|
|
283
|
+
/**
|
|
284
|
+
* Re-opens the model session after it drops mid-call, seeded with the conversation so far. When absent a
|
|
285
|
+
* dropped model session ends the call. Called at most {@link MAX_MODEL_RECOVERY_ATTEMPTS} time(s) per session;
|
|
286
|
+
* the returned session MUST use the same audio sample rates as the one it replaces.
|
|
287
|
+
*/
|
|
288
|
+
RecoverRealtimeSession?: BridgeRealtimeSessionRecovery;
|
|
289
|
+
/**
|
|
290
|
+
* Re-opens the model session WITHOUT its avatar, seeded with the conversation so far, when the bridge reports it can
|
|
291
|
+
* no longer show the avatar ({@link BaseRealtimeBridge.OnAvatarUnavailable}: its decoders kept failing, or the room
|
|
292
|
+
* refused the video track). The replacement renders audio only, so the model stops generating video nobody sees.
|
|
293
|
+
* Called at most once per session, apart from {@link RecoverRealtimeSession}'s attempts. When absent, the session goes
|
|
294
|
+
* on as it is (audio still plays; the avatar's video is generated and not shown).
|
|
295
|
+
*/
|
|
296
|
+
RecoverRealtimeSessionWithoutAvatar?: BridgeRealtimeSessionRecovery;
|
|
297
|
+
/**
|
|
298
|
+
* Called once at the end of {@link AIBridgeEngine.StopBridgeSession} for this session, after the bridge row is
|
|
299
|
+
* terminal — the place for the host to close the rest of the session's bookkeeping (the agent session row, a
|
|
300
|
+
* capacity lease). Must not throw; a throw is logged and swallowed.
|
|
301
|
+
*/
|
|
302
|
+
OnSessionEnded?: (reason: BridgeDisconnectReason) => void | Promise<void>;
|
|
303
|
+
}
|
|
304
|
+
/** What {@link StartBridgeSessionParams.RecoverRealtimeSession} is told about the loss it is recovering from. */
|
|
305
|
+
export interface BridgeRealtimeSessionRecoveryRequest {
|
|
306
|
+
/** Role-tagged transcript of the conversation so far, ready to frame into the new session's prompt. */
|
|
307
|
+
PriorTranscript: string;
|
|
308
|
+
/** 1-based attempt number. */
|
|
309
|
+
Attempt: number;
|
|
310
|
+
/** Why the previous session was considered lost. */
|
|
311
|
+
Reason: string;
|
|
312
|
+
}
|
|
313
|
+
/** Opens a replacement realtime model session after the current one was lost. */
|
|
314
|
+
export type BridgeRealtimeSessionRecovery = (request: BridgeRealtimeSessionRecoveryRequest) => Promise<IRealtimeSession>;
|
|
315
|
+
/**
|
|
316
|
+
* Executes the turn-taking host tools for one session. Structurally the agents layer's
|
|
317
|
+
* `BridgeLocalToolHandler` (declared here so the engine takes no dependency on `@memberjunction/ai-agents`):
|
|
318
|
+
* the layer that owns the model session passes it to its runtime's `SetLocalToolHandler`.
|
|
319
|
+
*/
|
|
320
|
+
export interface BridgeTurnTakingToolHandler {
|
|
321
|
+
/** Whether this handler owns `toolName` (`i_am_addressed`, `yield_turn`). */
|
|
322
|
+
Handles(toolName: string): boolean;
|
|
323
|
+
/** Runs one call; the returned JSON string is handed back to the model. Never throws. */
|
|
324
|
+
Execute(call: {
|
|
325
|
+
ToolName: string;
|
|
326
|
+
Arguments: string;
|
|
327
|
+
}): Promise<string>;
|
|
328
|
+
}
|
|
329
|
+
/** One agent seated in a room, as the turn-taking observability surface describes it. */
|
|
330
|
+
export interface RoomTurnAgentInfo {
|
|
331
|
+
/** The agent's `MJ: AI Agent Sessions` id (matches the coordinator's ids in {@link RoomFloorState}). */
|
|
332
|
+
AgentSessionID: string;
|
|
333
|
+
/** The bridge row id (what stops/removes the agent). */
|
|
334
|
+
SessionBridgeID: string;
|
|
335
|
+
/** The names the agent answers to; the first is its display name. */
|
|
336
|
+
Names: string[];
|
|
337
|
+
/** The configured turn-taking mode. */
|
|
338
|
+
TurnMode: BridgeTurnMode;
|
|
339
|
+
/** How it decides it was addressed (after capability resolution). */
|
|
340
|
+
Addressing: ResolvedTurnAddressingMode;
|
|
341
|
+
/** Whether its model is full-duplex (its outbound audio runs through the floor gate). */
|
|
342
|
+
FullDuplex: boolean;
|
|
343
|
+
}
|
|
344
|
+
/** A room's live turn-taking state: the coordinator's floor state plus who is seated. See {@link AIBridgeEngine.GetRoomTurnSnapshot}. */
|
|
345
|
+
export interface RoomTurnSnapshot extends RoomFloorState {
|
|
346
|
+
/** The agents seated in the room. */
|
|
347
|
+
Agents: RoomTurnAgentInfo[];
|
|
227
348
|
}
|
|
228
349
|
/**
|
|
229
350
|
* The live, in-memory handle for one running bridged session held by the engine. Carries the driver,
|
|
@@ -243,6 +364,24 @@ export interface ActiveBridgeSession {
|
|
|
243
364
|
RealtimeSession: IRealtimeSession;
|
|
244
365
|
/** The per-session turn-taking policy gating generation. */
|
|
245
366
|
TurnPolicy: TurnTakingPolicy;
|
|
367
|
+
/** How this session decides it was addressed (the mode actually in effect after capability resolution). */
|
|
368
|
+
AddressingMode?: ResolvedTurnAddressingMode;
|
|
369
|
+
/** The model-side addressing latch the model's `i_am_addressed` signal feeds — present only in `ModelSide` mode. */
|
|
370
|
+
ModelSideMatcher?: ModelSideAddressedMatcher;
|
|
371
|
+
/** Whether this session operates in full-duplex conversational mode. */
|
|
372
|
+
FullDuplex: boolean;
|
|
373
|
+
/** The floor gate over this full-duplex model's outbound audio (see {@link FullDuplexTurnGate}); absent for turn-based models. */
|
|
374
|
+
TurnGate?: FullDuplexTurnGate;
|
|
375
|
+
/** Detects human speech in inbound room audio so the room's agents yield to it; present with {@link ActiveBridgeSession.TurnGate}. */
|
|
376
|
+
HumanSpeech?: HumanSpeechDetector;
|
|
377
|
+
/**
|
|
378
|
+
* Executes the turn-taking host tools (`i_am_addressed`, `yield_turn`) for this session. Present for
|
|
379
|
+
* full-duplex / model-side sessions in a room; the layer that owns the model session binds it as its
|
|
380
|
+
* local tool handler (the tool DEFINITIONS are {@link TURN_TAKING_TOOL_DEFINITIONS}).
|
|
381
|
+
*/
|
|
382
|
+
TurnTakingToolHandler?: BridgeTurnTakingToolHandler;
|
|
383
|
+
/** Whether this session has been told how to take turns in a shared room (the framing note is sent once, when the room becomes multi-agent). */
|
|
384
|
+
TurnTakingAnnounced?: boolean;
|
|
246
385
|
/**
|
|
247
386
|
* Whether the model's blind auto-response is OFF for this session (multi-agent meeting). When `true`
|
|
248
387
|
* the bridge is the sole speech trigger — a `Speak` decision issues one `RequestSpokenUpdate`. When
|
|
@@ -293,6 +432,13 @@ export interface ActiveBridgeSession {
|
|
|
293
432
|
* no speaker label. Approximate (single-speaker-at-a-time); `undefined` until the first diarized frame.
|
|
294
433
|
*/
|
|
295
434
|
LastInboundSpeaker?: string;
|
|
435
|
+
/**
|
|
436
|
+
* The camera and screen sources whose frames reached the current model session (`SourceID` → the label the model was
|
|
437
|
+
* given). A source not in it is new to the model, which is told what it can now see before its first frame; when one
|
|
438
|
+
* in it ends, the model is told, by that label, that it can no longer see it (and only about sources it actually saw).
|
|
439
|
+
* Cleared when a recovered session replaces the model.
|
|
440
|
+
*/
|
|
441
|
+
SeenVideoSources: Map<string, string>;
|
|
296
442
|
/** This agent's participation style for the room moderator (`'proactive'` | `'addressed-only'`). */
|
|
297
443
|
ParticipationMode: 'proactive' | 'addressed-only';
|
|
298
444
|
/** The names/aliases this agent answers to (moderator roster + addressed-only fallback). */
|
|
@@ -326,6 +472,37 @@ export interface ActiveBridgeSession {
|
|
|
326
472
|
* when no channel host was supplied. Never throws — resolves to a structured failure.
|
|
327
473
|
*/
|
|
328
474
|
ExecuteServerChannelTool?: (toolName: string, argsJson: string) => Promise<BridgeChannelToolResult>;
|
|
475
|
+
/** This session's own transcript sink (see {@link StartBridgeSessionParams.TranscriptSink}), when supplied. */
|
|
476
|
+
TranscriptSink?: BridgeTranscriptSink;
|
|
477
|
+
/** Barge-in hook (see {@link StartBridgeSessionParams.OnBargeIn}). */
|
|
478
|
+
OnBargeIn?: () => void;
|
|
479
|
+
/** Model-session recovery factory (see {@link StartBridgeSessionParams.RecoverRealtimeSession}). */
|
|
480
|
+
RecoverRealtimeSession?: BridgeRealtimeSessionRecovery;
|
|
481
|
+
/** The audio-only replacement factory (see {@link StartBridgeSessionParams.RecoverRealtimeSessionWithoutAvatar}). */
|
|
482
|
+
RecoverRealtimeSessionWithoutAvatar?: BridgeRealtimeSessionRecovery;
|
|
483
|
+
/** Whether the model session was already replaced because its avatar could not be shown (once per session). */
|
|
484
|
+
AvatarReplaced?: boolean;
|
|
485
|
+
/**
|
|
486
|
+
* The avatar stream's latest init segment, read: its audio track's timescale lets the floor gate count an avatar
|
|
487
|
+
* piece's speaking time. Every stream (a turn, a resumed or replaced model session) opens with its own init.
|
|
488
|
+
*/
|
|
489
|
+
AvatarInit?: Fmp4Init | null;
|
|
490
|
+
/** End-of-session hook (see {@link StartBridgeSessionParams.OnSessionEnded}). */
|
|
491
|
+
OnSessionEnded?: (reason: BridgeDisconnectReason) => void | Promise<void>;
|
|
492
|
+
/** The last final transcript turns, kept so a re-opened model session can be told what was said. */
|
|
493
|
+
TranscriptTail: BridgeTranscriptTurn[];
|
|
494
|
+
/** How many times the model session has been re-opened (capped by {@link MAX_MODEL_RECOVERY_ATTEMPTS}). */
|
|
495
|
+
ModelRecoveryAttempts: number;
|
|
496
|
+
/** High-resolution timestamp (ms) when the most recent user turn completed, for transcript-to-next-audio latency telemetry. */
|
|
497
|
+
LastUserSpeechEndMs?: number;
|
|
498
|
+
/** Whether a model-session recovery is in flight; inbound audio is dropped meanwhile. */
|
|
499
|
+
ModelRecovering: boolean;
|
|
500
|
+
/** Set once the session is being torn down, so a model-loss signal during teardown is ignored. */
|
|
501
|
+
Ending: boolean;
|
|
502
|
+
/** Coalesces the caller's keypad presses into one note for the model (telephony only). */
|
|
503
|
+
DtmfCoalescer?: DtmfCoalescer;
|
|
504
|
+
/** Epoch-ms of the last write of the agent session row's `LastActiveAt`. */
|
|
505
|
+
LastSessionHeartbeatMs: number;
|
|
329
506
|
}
|
|
330
507
|
/**
|
|
331
508
|
* Server-tier engine for the Realtime Bridge plane — **coordination + execution**.
|
|
@@ -350,8 +527,8 @@ export interface ActiveBridgeSession {
|
|
|
350
527
|
* `AIAgentSessionBridgeParticipant` rows.
|
|
351
528
|
* - **Turn-taking integration** — holds a {@link TurnTakingPolicy} per session and feeds diarized
|
|
352
529
|
* transcript segments through it, acting on the decision (Speak / PostToChat / Silent).
|
|
353
|
-
* - **Janitor scaffold** — {@link ReconcileOrphans} force-closes Connected bridges left by
|
|
354
|
-
*
|
|
530
|
+
* - **Janitor scaffold** — {@link ReconcileOrphans} force-closes Connected bridges left by an earlier
|
|
531
|
+
* boot of this instance (see {@link IHostInstanceIdentity}), following the `SessionJanitor` shape.
|
|
355
532
|
*
|
|
356
533
|
* The engine never constructs the realtime model: the {@link IRealtimeSession} is injected via
|
|
357
534
|
* {@link StartBridgeSessionParams}, keeping the only coupling the transport seam itself and making
|
|
@@ -364,6 +541,8 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
364
541
|
private runFinalizer?;
|
|
365
542
|
/** Interval handle for the self-scheduled stale-session sweep (started via {@link StartStaleSessionSweep}). */
|
|
366
543
|
private staleSweepTimer?;
|
|
544
|
+
/** Interval handle for the periodic prior-boot orphan reconciliation (see {@link StartOrphanReconciliation}). */
|
|
545
|
+
private orphanReconcileTimer?;
|
|
367
546
|
private idleTtlMs;
|
|
368
547
|
private maxDurationMs;
|
|
369
548
|
private emptyGraceMs;
|
|
@@ -372,9 +551,13 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
372
551
|
private transcriptSink?;
|
|
373
552
|
/** roomKey (lowercased) → the bridge id of that room's current transcript scribe. Election dedup. */
|
|
374
553
|
private readonly roomScribes;
|
|
375
|
-
/**
|
|
376
|
-
|
|
377
|
-
|
|
554
|
+
/**
|
|
555
|
+
* Diagnostic: the bridges (by `SessionBridgeID`) that have logged their first inbound media frame. An ending bridge
|
|
556
|
+
* adds no id, and {@link StopBridgeSession} drops its id, so a long-running host keeps only its live bridges.
|
|
557
|
+
*/
|
|
558
|
+
private readonly diagInbound;
|
|
559
|
+
/** Diagnostic: the bridges that have logged the agent's first outbound audio, kept the same way as {@link diagInbound}. */
|
|
560
|
+
private readonly diagOutbound;
|
|
378
561
|
/** In-memory registry of bridged sessions this process currently hosts, keyed by bridge id (lowercased). */
|
|
379
562
|
private activeSessions;
|
|
380
563
|
/** Per-room, per-utterance-text last-dispatch timestamps — collapses duplicate transcriptions (see {@link ROOM_TURN_DEDUP_MS}). */
|
|
@@ -415,7 +598,11 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
415
598
|
/**
|
|
416
599
|
* Deferred-startup entry point (per {@link IStartupSink}). Warms the ONE composed base cache by
|
|
417
600
|
* delegating to {@link AIBridgeEngineBase.Config}; mirrors `AIEngine.HandleStartup`. No double
|
|
418
|
-
* load — there is only the base's cache to warm.
|
|
601
|
+
* load — there is only the base's cache to warm. Then starts the same-process stale-session sweep.
|
|
602
|
+
*
|
|
603
|
+
* It does not start the orphan reconcile. The host starts that ({@link StartOrphanReconciliation}) once it owns
|
|
604
|
+
* its instance: the deferred startup can run before MJServer listens on its port, while another live MJAPI may
|
|
605
|
+
* still hold that port, and a reconcile then would close that MJAPI's bridges as this instance's orphans.
|
|
419
606
|
*
|
|
420
607
|
* @param contextUser The boot/system user context.
|
|
421
608
|
* @param provider Optional metadata provider override (multi-provider scenarios).
|
|
@@ -490,11 +677,12 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
490
677
|
/** Returns a provider's auto-attach (default) channels. @see AIBridgeEngineBase.DefaultChannelsForProvider */
|
|
491
678
|
DefaultChannelsForProvider(providerId: string): MJAIBridgeProviderChannelEntity[];
|
|
492
679
|
/**
|
|
493
|
-
* Injects the
|
|
494
|
-
*
|
|
495
|
-
*
|
|
680
|
+
* Injects the identity of the server instance hosting this engine ({@link IHostInstanceIdentity}): the engine
|
|
681
|
+
* stamps it into every bridge row it creates and reconciles orphans by it. Call it once at boot, before anything
|
|
682
|
+
* can start a bridge. MJServer's `Serve` passes the identity its agent-session rows carry, right after it sets its
|
|
683
|
+
* port. Until then the engine uses a {@link DefaultHostInstanceIdentity}.
|
|
496
684
|
*
|
|
497
|
-
* @param identity The identity
|
|
685
|
+
* @param identity The identity to use.
|
|
498
686
|
*/
|
|
499
687
|
SetHostInstanceIdentity(identity: IHostInstanceIdentity): void;
|
|
500
688
|
/**
|
|
@@ -564,6 +752,8 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
564
752
|
* @returns `true` when the durable row reached a `Disconnected` state.
|
|
565
753
|
*/
|
|
566
754
|
StopBridgeSession(sessionBridgeID: string, reason: BridgeDisconnectReason, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<boolean>;
|
|
755
|
+
/** Runs the host's end-of-session hook. A failure is logged — teardown bookkeeping must not be blocked by it. */
|
|
756
|
+
private runSessionEndedHook;
|
|
567
757
|
/**
|
|
568
758
|
* Wires the bidirectional media transport seam between a bridge driver and a realtime session —
|
|
569
759
|
* the single piece of code that completes the realtime engine's deferred server-bridged media
|
|
@@ -571,9 +761,11 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
571
761
|
* that pipe.
|
|
572
762
|
*
|
|
573
763
|
* Two hooks, one per direction:
|
|
574
|
-
* - **Inbound** (`bridge.OnMedia` → `session.SendInput`): what the agent HEARS
|
|
575
|
-
* {@link BridgeMediaFrame} from the endpoint is unwrapped to its raw `ArrayBuffer` payload and
|
|
576
|
-
* streamed straight to the model.
|
|
764
|
+
* - **Inbound** (`bridge.OnMedia` → `session.SendInput`): what the agent HEARS (and, for a video model, SEES).
|
|
765
|
+
* Each inbound {@link BridgeMediaFrame} from the endpoint is unwrapped to its raw `ArrayBuffer` payload and
|
|
766
|
+
* streamed straight to the model. Camera and screen frames go only to a session that declares inbound video; the
|
|
767
|
+
* first frame of a source new to the model session is preceded by a note naming it, and the end of a source the
|
|
768
|
+
* model saw is followed by one (see {@link VideoSourceSeenNote}, {@link VideoSourceEndedNote}).
|
|
577
769
|
* - **Outbound** (`session.OnOutput` → `bridge.SendMedia`): what the agent SAYS. Each model
|
|
578
770
|
* output `ArrayBuffer` is wrapped in an outbound audio {@link BridgeMediaFrame} and sent into
|
|
579
771
|
* the meeting/call.
|
|
@@ -584,6 +776,55 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
584
776
|
* @param active The live bridged session whose driver and realtime session are wired together.
|
|
585
777
|
*/
|
|
586
778
|
private wireTransportSeam;
|
|
779
|
+
/**
|
|
780
|
+
* Tells the model what it can now see, right before the first frame of a camera or screen new to the current model
|
|
781
|
+
* session: the first source, the next one after a switch, a source seen again after it ended, or a replacement
|
|
782
|
+
* session's first frame. Records the source, so its end is reported. A frame without a `SourceID` is not tracked.
|
|
783
|
+
* Reads `active.RealtimeSession` each time: a recovered session replaces it.
|
|
784
|
+
*
|
|
785
|
+
* @param active The live bridged session.
|
|
786
|
+
* @param frame The camera or screen frame about to be sent.
|
|
787
|
+
*/
|
|
788
|
+
private tellModelVideoSourceSeen;
|
|
789
|
+
/**
|
|
790
|
+
* Tells the model it can no longer see a camera or screen whose frames reached it (the person stopped letting agents
|
|
791
|
+
* see them, left, stopped sharing or turned the camera off, or the view moved to another source), so it stops
|
|
792
|
+
* describing the last frame as current. The note names the source as the model was told with its first frame, not by
|
|
793
|
+
* the label the driver reports at the end: the two differ when the person was renamed in between, or had no name when
|
|
794
|
+
* that first frame was read. A source the model never saw is ignored. Reads `active.RealtimeSession` each time: a
|
|
795
|
+
* recovered session replaces it.
|
|
796
|
+
*
|
|
797
|
+
* @param active The live bridged session.
|
|
798
|
+
* @param source The source that ended, as the driver reported it.
|
|
799
|
+
*/
|
|
800
|
+
private tellModelVideoSourceEnded;
|
|
801
|
+
/**
|
|
802
|
+
* Wires everything that hangs off the MODEL session: barge-in, the lifecycle (drop) signals, and — unless the
|
|
803
|
+
* media plane is detached — the agent's outbound audio/video. Called at connect AND again for a replacement
|
|
804
|
+
* session after a recovery, so every handler checks it still belongs to the active session.
|
|
805
|
+
*
|
|
806
|
+
* @param active The live bridged session.
|
|
807
|
+
*/
|
|
808
|
+
private wireModelSession;
|
|
809
|
+
/**
|
|
810
|
+
* Sends one frame of the agent's video to the bridge on `video-out`, with its MIME type so the driver can publish it
|
|
811
|
+
* (a fragmented MP4 piece as an avatar), and what the frame says about its video (see {@link frameVideoFacts}). In a
|
|
812
|
+
* full-duplex multi-agent room the frame passes the floor gate first.
|
|
813
|
+
*/
|
|
814
|
+
private forwardVideoFrame;
|
|
815
|
+
/**
|
|
816
|
+
* The floor gate's verdict on one video frame. An fMP4 piece carries the voice on its audio track, so a fragment is
|
|
817
|
+
* counted by its audio's duration: that is how long the agent speaks. A fragment its driver marks `Idle` (the face an
|
|
818
|
+
* avatar shows between answers) counts as no speech, whatever its audio track holds; so does one with video only.
|
|
819
|
+
* Neither starts a burst or takes the floor (see {@link FullDuplexTurnGate.OnOutputDuration}). An init segment
|
|
820
|
+
* carries no speech: it is remembered (its audio track's timescale times the fragments) and passes. An encoded chunk
|
|
821
|
+
* or an image carries no voice (that comes through `OnOutput`, which is gated) and passes.
|
|
822
|
+
*/
|
|
823
|
+
private gateVideoFrame;
|
|
824
|
+
/** A true barge-in: flush queued audio, drop stale room moderator state, free the floor, tell the host. */
|
|
825
|
+
private handleBargeIn;
|
|
826
|
+
/** Tells the host about a barge-in so it can drop now-stale narration (never delegated work). A hook failure is logged, never fatal. */
|
|
827
|
+
private notifyBargeIn;
|
|
587
828
|
/**
|
|
588
829
|
* Unwraps a {@link BridgeMediaFrame} to the raw `ArrayBuffer` the realtime session consumes,
|
|
589
830
|
* preferring the binary `Bytes` payload and decoding `Base64` when only that is present. Returns
|
|
@@ -620,6 +861,37 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
620
861
|
*/
|
|
621
862
|
private wireParticipantTracking;
|
|
622
863
|
private wireTelephonyLifecycle;
|
|
864
|
+
/**
|
|
865
|
+
* Routes the caller's keypad presses to the model as one short context note per burst ("the caller pressed
|
|
866
|
+
* 1234"). Capability-gated: a provider with DTMF off throws from `OnDTMF`, which just means no keypad input.
|
|
867
|
+
*/
|
|
868
|
+
private wireInboundDtmf;
|
|
869
|
+
/**
|
|
870
|
+
* Subscribes to the model session's fatal-error and unexpected-close signals. Either means the caller is now
|
|
871
|
+
* talking to a dead line, so it starts {@link handleModelLoss}. Both can fire for one drop; the handler
|
|
872
|
+
* de-duplicates.
|
|
873
|
+
*/
|
|
874
|
+
private wireModelLifecycle;
|
|
875
|
+
/**
|
|
876
|
+
* The model session dropped mid-call. Re-open it ONCE, seeded with what was said, and carry on; if that is not
|
|
877
|
+
* possible (no recovery factory, attempts spent, the factory fails, or the replacement uses different audio
|
|
878
|
+
* rates) end the call cleanly instead of leaving the caller in silence.
|
|
879
|
+
*/
|
|
880
|
+
private handleModelLoss;
|
|
881
|
+
/** Swaps a recovered model session in for the lost one, or refuses it when it cannot carry the call's audio. */
|
|
882
|
+
private adoptRecoveredSession;
|
|
883
|
+
/**
|
|
884
|
+
* The bridge can no longer show the agent's avatar: replace the model session, once, with one that renders no avatar
|
|
885
|
+
* (through the host's {@link StartBridgeSessionParams.RecoverRealtimeSessionWithoutAvatar}), seeded with what was said,
|
|
886
|
+
* so the model stops generating video nobody sees and, if the voice decoder was the one that failed, the voice comes
|
|
887
|
+
* back as PCM. Inbound audio is held back while the replacement opens, as in a recovery. If it fails, the session goes
|
|
888
|
+
* on as it was.
|
|
889
|
+
*/
|
|
890
|
+
private replaceModelSessionWithoutAvatar;
|
|
891
|
+
/** Ends a call whose model session cannot be recovered: a spoken goodbye at the carrier (telephony), then a clean stop. */
|
|
892
|
+
private endCallAfterModelLoss;
|
|
893
|
+
/** Closes a realtime session, logging (never throwing) a provider error. */
|
|
894
|
+
private closeQuietly;
|
|
623
895
|
/**
|
|
624
896
|
* Decides whether an emptied room should auto-leave. Marks {@link ActiveBridgeSession.HasSeenHuman}
|
|
625
897
|
* once any human is present; when a human WAS present and the roster drops to agents-only, it arms a
|
|
@@ -732,11 +1004,108 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
732
1004
|
* @param action The decided action (`Speak` / `PostToChat` / `Silent`).
|
|
733
1005
|
*/
|
|
734
1006
|
private applyTurnDecision;
|
|
1007
|
+
/**
|
|
1008
|
+
* Gives a FULL-DUPLEX model the floor gate + human-speech detector (see {@link FullDuplexTurnGate})
|
|
1009
|
+
* ONLY when moderator mode (`MJ_REALTIME_MODERATOR_MODE=on`) is explicitly enabled (or explicitly opted into).
|
|
1010
|
+
* In normal operation (solo and multi-agent rooms alike), full-duplex models are never gated:
|
|
1011
|
+
* native full-duplex models are better at turn-taking and ignoring background noise.
|
|
1012
|
+
*
|
|
1013
|
+
* @param active The freshly connected session.
|
|
1014
|
+
* @param params The start parameters (`FullDuplexTurnGate: false` opts out).
|
|
1015
|
+
*/
|
|
1016
|
+
private wireFullDuplexTurnGate;
|
|
1017
|
+
/**
|
|
1018
|
+
* Runs one chunk of a full-duplex model's outbound audio through its floor gate. Sessions without a gate,
|
|
1019
|
+
* and rooms with a single agent, are never gated.
|
|
1020
|
+
*
|
|
1021
|
+
* @param active The speaking session.
|
|
1022
|
+
* @param byteLength The chunk size (PCM16).
|
|
1023
|
+
* @returns Whether to forward the chunk, drop it, or cut the burst (drop + flush queued audio).
|
|
1024
|
+
*/
|
|
1025
|
+
private gateOutput;
|
|
1026
|
+
/**
|
|
1027
|
+
* Runs one chunk of a full-duplex model's outbound speech through its floor gate by how long it plays (an avatar
|
|
1028
|
+
* piece). Sessions without a gate, and rooms with a single agent, are never gated.
|
|
1029
|
+
*
|
|
1030
|
+
* @param active The speaking session.
|
|
1031
|
+
* @param durationMs How long the chunk's speech plays.
|
|
1032
|
+
*/
|
|
1033
|
+
private gateOutputDuration;
|
|
1034
|
+
/** Asks the session's floor gate about one chunk (when it is gated at all) and acts on the floor it took or lost. */
|
|
1035
|
+
private applyTurnGate;
|
|
1036
|
+
/** Whether an inbound speaker label belongs to a human (diarized, and not a peer `agent-…` bot). */
|
|
1037
|
+
private isHumanSpeaker;
|
|
1038
|
+
/**
|
|
1039
|
+
* Watches inbound room audio for a human speaking and, on the first activity, makes every agent yield.
|
|
1040
|
+
* Only a DIARIZED human counts — without a speaker label the audio could be a peer agent, and a peer must
|
|
1041
|
+
* never preempt another agent's turn.
|
|
1042
|
+
*/
|
|
1043
|
+
private observeInboundHumanSpeech;
|
|
1044
|
+
/**
|
|
1045
|
+
* A human started talking: tell the coordinator (humans win), and for the agent that was holding the floor
|
|
1046
|
+
* flush its queued audio, mute the rest of its burst, free its floor, and fire the barge-in hook so the host
|
|
1047
|
+
* drops now-stale narration. Delegated work keeps running — the same policy as a direct barge-in.
|
|
1048
|
+
*
|
|
1049
|
+
* @param roomKey The room the human spoke in.
|
|
1050
|
+
*/
|
|
1051
|
+
private preemptForHuman;
|
|
1052
|
+
/**
|
|
1053
|
+
* Binds the turn-taking host tools (`i_am_addressed`, `yield_turn`) to a session that needs them: a
|
|
1054
|
+
* full-duplex model in a room, or any model using model-side addressing. The tool DEFINITIONS are
|
|
1055
|
+
* {@link TURN_TAKING_TOOL_DEFINITIONS}; the layer that owns the model session registers them at connect and
|
|
1056
|
+
* installs {@link ActiveBridgeSession.TurnTakingToolHandler} as its local tool handler.
|
|
1057
|
+
*
|
|
1058
|
+
* @param active The live bridged session.
|
|
1059
|
+
*/
|
|
1060
|
+
private wireTurnTakingTools;
|
|
1061
|
+
/**
|
|
1062
|
+
* Once a room holds 2+ agents, tells each tool-equipped (full-duplex / model-side) agent in it — once — how to
|
|
1063
|
+
* take turns: speak when addressed, stop for a person, only acknowledge briefly over someone, hand over by name.
|
|
1064
|
+
* It is a context note rather than part of the system prompt on purpose: the FIRST agent joins before anyone
|
|
1065
|
+
* else, and a solo agent in a one-on-one call must keep answering everything it hears.
|
|
1066
|
+
*
|
|
1067
|
+
* @param roomKey The room to announce in (no-op when `undefined`, or while the room has a single agent).
|
|
1068
|
+
*/
|
|
1069
|
+
private announceTurnTaking;
|
|
1070
|
+
/** Runs one turn-taking tool call and returns the JSON the model is handed back. Never throws. */
|
|
1071
|
+
private executeTurnTakingTool;
|
|
1072
|
+
/**
|
|
1073
|
+
* The model said it is addressed: latch the model-side matcher and — in a multi-agent room — reserve the
|
|
1074
|
+
* floor NOW, before any audio, so a peer cannot start in the gap. A denial tells the model to stay silent,
|
|
1075
|
+
* which is how a cooperative model learns it lost the race.
|
|
1076
|
+
*/
|
|
1077
|
+
private onModelAddressed;
|
|
1078
|
+
/**
|
|
1079
|
+
* The model hands the floor over, optionally to a named agent: release it, reserve it for the target, and
|
|
1080
|
+
* nudge the target to speak. A name that matches nobody degrades to a plain release.
|
|
1081
|
+
*/
|
|
1082
|
+
private onModelYield;
|
|
1083
|
+
/** Finds another agent in the room by any of its names (case-insensitive), excluding the asker. */
|
|
1084
|
+
private findRoomAgentByName;
|
|
1085
|
+
/** Tells a hand-off target it was given the floor and triggers it to speak (when its driver can be triggered). */
|
|
1086
|
+
private handOffFloor;
|
|
1087
|
+
/**
|
|
1088
|
+
* Adjusts the turn-taking limits every room uses (the agent-to-agent loop cap, hand-off TTL, human-speech
|
|
1089
|
+
* hold). Omitted values keep their current setting. Call once at startup to tune.
|
|
1090
|
+
*
|
|
1091
|
+
* @param limits The limits to change.
|
|
1092
|
+
*/
|
|
1093
|
+
ConfigureTurnLimits(limits: RoomCoordinatorLimits): void;
|
|
1094
|
+
/**
|
|
1095
|
+
* A room's live turn-taking state: who holds the floor, whether a human is speaking, any pending hand-off,
|
|
1096
|
+
* the loop-cap progress, recent floor/backchannel/yield events, and who is seated. Read-only; the test bed
|
|
1097
|
+
* polls it. `null` when the room is unknown (no agent in it).
|
|
1098
|
+
*
|
|
1099
|
+
* @param roomKey The room (external connection id — a LiveKit room's name).
|
|
1100
|
+
* @returns The snapshot, or `null`.
|
|
1101
|
+
*/
|
|
1102
|
+
GetRoomTurnSnapshot(roomKey: string): RoomTurnSnapshot | null;
|
|
735
1103
|
/**
|
|
736
1104
|
* Builds the per-session {@link TurnTakingPolicy} from the start params.
|
|
737
1105
|
*
|
|
738
1106
|
* @param params The session parameters.
|
|
739
|
-
* @
|
|
1107
|
+
* @param fullDuplex Whether the session's model reports full-duplex capability (enables model-side addressing).
|
|
1108
|
+
* @returns The configured policy plus the addressing mode in effect and the model-side latch, when any.
|
|
740
1109
|
*/
|
|
741
1110
|
private buildTurnPolicy;
|
|
742
1111
|
/**
|
|
@@ -842,24 +1211,53 @@ export declare class AIBridgeEngine extends BaseSingleton<AIBridgeEngine> implem
|
|
|
842
1211
|
* The host opts in once at startup; {@link StopStaleSessionSweep} cancels it (e.g. for tests/shutdown).
|
|
843
1212
|
*/
|
|
844
1213
|
StartStaleSessionSweep(intervalMs?: number): void;
|
|
1214
|
+
/**
|
|
1215
|
+
* Refreshes `LastActiveAt` on the agent-session row of every live bridge that has not been touched for
|
|
1216
|
+
* {@link SESSION_HEARTBEAT_INTERVAL_MS}. The host session janitor closes sessions idle past its threshold; a
|
|
1217
|
+
* long phone call writes nothing else to the row, so without this it would be closed (and its run finalized)
|
|
1218
|
+
* mid-call. Tolerant: a failed write is logged and the rest are still touched.
|
|
1219
|
+
*
|
|
1220
|
+
* @param nowMs Current epoch-ms (injectable for tests).
|
|
1221
|
+
* @returns The number of rows refreshed.
|
|
1222
|
+
*/
|
|
1223
|
+
HeartbeatLiveSessions(nowMs?: number): Promise<number>;
|
|
1224
|
+
/** Writes `LastActiveAt = now` on the session's agent-session row. Returns whether it saved. */
|
|
1225
|
+
private touchAgentSession;
|
|
1226
|
+
/**
|
|
1227
|
+
* Reconciles prior-boot orphans ({@link ReconcileOrphans}) once now and then every
|
|
1228
|
+
* {@link ORPHAN_RECONCILE_INTERVAL_MS}. Idempotent — a no-op while already scheduled. The timer is `unref`'d.
|
|
1229
|
+
*
|
|
1230
|
+
* The host calls it once it owns its instance, so that no other live process can be that instance: MJServer calls
|
|
1231
|
+
* it after the server listens on its port. {@link HandleStartup} does not start it.
|
|
1232
|
+
*
|
|
1233
|
+
* @param contextUser The user the reconciliation writes run as.
|
|
1234
|
+
* @param provider The metadata provider for the reads/writes.
|
|
1235
|
+
* @param intervalMs How often to reconcile after the first pass.
|
|
1236
|
+
*/
|
|
1237
|
+
StartOrphanReconciliation(contextUser: UserInfo, provider: IMetadataProvider, intervalMs?: number): void;
|
|
1238
|
+
/** Cancels the periodic orphan reconciliation, if running. */
|
|
1239
|
+
StopOrphanReconciliation(): void;
|
|
845
1240
|
/** Cancels the self-scheduled stale-session sweep, if running. */
|
|
846
1241
|
StopStaleSessionSweep(): void;
|
|
847
1242
|
/**
|
|
848
|
-
* Force-closes `Connected`/`Connecting` bridges
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
1243
|
+
* Force-closes the `Connected`/`Connecting` bridges an **earlier boot of this instance** left, stamping
|
|
1244
|
+
* `CloseReason = 'Janitor'` and finalizing each one's co-agent run. Mirrors `SessionJanitor.RunStartupRecovery`:
|
|
1245
|
+
* a crash/redeploy vaporizes the in-memory driver sockets but leaves the durable rows reading `Connected`
|
|
1246
|
+
* forever; this reconciles them.
|
|
1247
|
+
*
|
|
1248
|
+
* Ownership comes from the injected {@link IHostInstanceIdentity}: the read is narrowed to the rows under its
|
|
1249
|
+
* instance prefix other than this boot's, and a row is closed only when
|
|
1250
|
+
* {@link IHostInstanceIdentity.IsPriorBoot} says another boot of this instance stamped it. Another instance's
|
|
1251
|
+
* bridges (another MJAPI on this host, or on another host) are never touched, live or not.
|
|
852
1252
|
*
|
|
853
|
-
*
|
|
854
|
-
* application (MJServer's startup + janitor timer) so this engine package carries no timer/IO of
|
|
855
|
-
* its own; call this method from that scheduler.
|
|
1253
|
+
* Run it only once this process owns its instance; {@link StartOrphanReconciliation} schedules it.
|
|
856
1254
|
*
|
|
857
1255
|
* @param contextUser The system user the reconciliation writes run as.
|
|
858
1256
|
* @param provider The metadata provider for the reconciliation reads/writes.
|
|
859
1257
|
* @returns The number of orphaned bridges closed.
|
|
860
1258
|
*/
|
|
861
1259
|
ReconcileOrphans(contextUser: UserInfo, provider: IMetadataProvider): Promise<number>;
|
|
862
|
-
/** Loads the
|
|
1260
|
+
/** Loads the bridge rows the janitor filter matches: the candidates {@link ReconcileOrphans} checks one by one. */
|
|
863
1261
|
private loadOrphanRows;
|
|
864
1262
|
/**
|
|
865
1263
|
* Binds the SDK factory onto a resolved driver before `Connect`. Precedence: a per-session
|