@memberjunction/ai-bridge-server 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 +120 -42
- package/dist/ai-bridge-engine.d.ts +663 -0
- package/dist/ai-bridge-engine.d.ts.map +1 -0
- package/dist/ai-bridge-engine.js +1085 -0
- package/dist/ai-bridge-engine.js.map +1 -0
- package/dist/calendar-source.d.ts +142 -0
- package/dist/calendar-source.d.ts.map +1 -0
- package/dist/calendar-source.js +63 -0
- package/dist/calendar-source.js.map +1 -0
- package/dist/calendar-watcher.d.ts +174 -0
- package/dist/calendar-watcher.d.ts.map +1 -0
- package/dist/calendar-watcher.js +248 -0
- package/dist/calendar-watcher.js.map +1 -0
- package/dist/identity-provisioner.d.ts +109 -0
- package/dist/identity-provisioner.d.ts.map +1 -0
- package/dist/identity-provisioner.js +71 -0
- package/dist/identity-provisioner.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/join-url-resolver.d.ts +37 -0
- package/dist/join-url-resolver.d.ts.map +1 -0
- package/dist/join-url-resolver.js +102 -0
- package/dist/join-url-resolver.js.map +1 -0
- package/dist/loopback-bridge.d.ts +165 -0
- package/dist/loopback-bridge.d.ts.map +1 -0
- package/dist/loopback-bridge.js +255 -0
- package/dist/loopback-bridge.js.map +1 -0
- package/dist/multi-agent-room-coordinator.d.ts +198 -0
- package/dist/multi-agent-room-coordinator.d.ts.map +1 -0
- package/dist/multi-agent-room-coordinator.js +296 -0
- package/dist/multi-agent-room-coordinator.js.map +1 -0
- package/dist/scheduled-bridge-runner.d.ts +126 -0
- package/dist/scheduled-bridge-runner.d.ts.map +1 -0
- package/dist/scheduled-bridge-runner.js +140 -0
- package/dist/scheduled-bridge-runner.js.map +1 -0
- package/package.json +34 -7
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { LogError, LogStatus, RunView, } from '@memberjunction/core';
|
|
2
|
+
import { UUIDsEqual } from '@memberjunction/global';
|
|
3
|
+
import { AIBridgeEngineBase } from '@memberjunction/ai-bridge-base';
|
|
4
|
+
import { ResolveProviderFromJoinUrl } from './join-url-resolver.js';
|
|
5
|
+
const SESSION_BRIDGE_ENTITY = 'MJ: AI Agent Session Bridges';
|
|
6
|
+
const AGENT_SESSION_ENTITY = 'MJ: AI Agent Sessions';
|
|
7
|
+
/**
|
|
8
|
+
* A trivial in-memory {@link ICalendarCursorStore} (the default). Cursors live for the process
|
|
9
|
+
* lifetime; on restart the watcher re-polls from scratch and the dedupe check prevents double-creating
|
|
10
|
+
* bridges for invites it already scheduled.
|
|
11
|
+
*/
|
|
12
|
+
export class InMemoryCalendarCursorStore {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.cursors = new Map();
|
|
15
|
+
}
|
|
16
|
+
/** @inheritdoc */
|
|
17
|
+
Get(identityID) {
|
|
18
|
+
return this.cursors.get(identityID.toLowerCase());
|
|
19
|
+
}
|
|
20
|
+
/** @inheritdoc */
|
|
21
|
+
Set(identityID, cursor) {
|
|
22
|
+
this.cursors.set(identityID.toLowerCase(), cursor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The **calendar watcher** — the headline "invite the agent like a person" join method.
|
|
27
|
+
*
|
|
28
|
+
* For each active agent identity of `IdentityType='Email'`, the watcher polls that identity's
|
|
29
|
+
* calendar (via the injected {@link ICalendarSource}) for new invites, and for every invite where the
|
|
30
|
+
* agent is an attendee it creates a **Scheduled** {@link MJAIAgentSessionBridgeEntity}
|
|
31
|
+
* (`JoinMethod='Invite'`, `Status='Scheduled'`, `ScheduledStartTime=invite.StartTime`,
|
|
32
|
+
* `Address=joinUrl`, `ProviderID` resolved from the join URL) plus the linked `AIAgentSession` the
|
|
33
|
+
* bridge attaches to. The {@link ScheduledBridgeRunner} later starts these at their start time.
|
|
34
|
+
*
|
|
35
|
+
* Design properties (all per spec):
|
|
36
|
+
* - **Provider-agnostic.** All calendar-API specifics live behind {@link ICalendarSource}; this class
|
|
37
|
+
* knows only the normalized {@link NormalizedCalendarInvite} shape.
|
|
38
|
+
* - **Idempotent.** Before creating a bridge it checks for an existing one with the same
|
|
39
|
+
* `ExternalConnectionID` (set to the invite's `ExternalEventID`). The same invite never double-books.
|
|
40
|
+
* - **Tolerant.** A failing identity or source is logged and the sweep continues to the next identity;
|
|
41
|
+
* one bad calendar never blocks the others.
|
|
42
|
+
* - **No timer.** The watcher only exposes {@link Sweep}; the host schedules the polling loop (matching
|
|
43
|
+
* the engine janitor's "documented hook, not a hard timer" posture).
|
|
44
|
+
*
|
|
45
|
+
* @see `/plans/realtime/realtime-bridges-architecture.md` §5 (Invite/Calendar join + agent identity).
|
|
46
|
+
*/
|
|
47
|
+
export class CalendarWatcher {
|
|
48
|
+
constructor(config) {
|
|
49
|
+
this.sourceResolver = config.SourceResolver;
|
|
50
|
+
this.contextUser = config.ContextUser;
|
|
51
|
+
this.metadataProvider = config.MetadataProvider;
|
|
52
|
+
this.engine = config.Engine ?? AIBridgeEngineBase.Instance;
|
|
53
|
+
this.cursorStore = config.CursorStore ?? new InMemoryCalendarCursorStore();
|
|
54
|
+
this.now = config.Now ?? (() => Date.now());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Runs one full sweep across every active `Email` agent identity. The host schedules this on its
|
|
58
|
+
* own cadence (e.g. every minute). Never throws — a per-identity failure is captured in the
|
|
59
|
+
* returned {@link CalendarSweepResult} and the sweep proceeds.
|
|
60
|
+
*
|
|
61
|
+
* @returns Observability counts for the sweep.
|
|
62
|
+
*/
|
|
63
|
+
async Sweep() {
|
|
64
|
+
const result = {
|
|
65
|
+
IdentitiesScanned: 0,
|
|
66
|
+
IdentitiesWithoutSource: 0,
|
|
67
|
+
IdentitiesFailed: 0,
|
|
68
|
+
InvitesSeen: 0,
|
|
69
|
+
BridgesCreated: 0,
|
|
70
|
+
Duplicates: 0,
|
|
71
|
+
Unroutable: 0,
|
|
72
|
+
};
|
|
73
|
+
for (const identity of this.activeEmailIdentities()) {
|
|
74
|
+
result.IdentitiesScanned++;
|
|
75
|
+
await this.sweepIdentity(identity, result);
|
|
76
|
+
}
|
|
77
|
+
LogStatus(`[CalendarWatcher] Sweep done: ${result.BridgesCreated} new bridge(s) across ` +
|
|
78
|
+
`${result.IdentitiesScanned} identity(ies) (${result.Duplicates} dup, ` +
|
|
79
|
+
`${result.Unroutable} unroutable, ${result.IdentitiesFailed} failed).`);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
/** The active `Email`-type agent identities from the cache (the only ones a calendar watcher serves). */
|
|
83
|
+
activeEmailIdentities() {
|
|
84
|
+
return this.engine.AgentIdentities.filter(i => i.IsActive === true && i.IdentityType === 'Email');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sweeps a single identity: resolves its source, polls it, and processes each new invite. All
|
|
88
|
+
* failures are caught here so one identity never aborts the whole sweep.
|
|
89
|
+
*
|
|
90
|
+
* @param identity The agent identity to sweep.
|
|
91
|
+
* @param result The running sweep result to update.
|
|
92
|
+
*/
|
|
93
|
+
async sweepIdentity(identity, result) {
|
|
94
|
+
const provider = this.engine.Providers.find(p => UUIDsEqual(p.ID, identity.ProviderID));
|
|
95
|
+
const source = this.sourceResolver(identity, provider);
|
|
96
|
+
if (!source) {
|
|
97
|
+
result.IdentitiesWithoutSource++;
|
|
98
|
+
return; // no calendar bound for this identity — nothing to poll.
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const cursor = this.cursorStore.Get(identity.ID);
|
|
102
|
+
const poll = await source.ListUpcomingInvites(identity.IdentityValue, cursor);
|
|
103
|
+
if (poll.NextCursor) {
|
|
104
|
+
this.cursorStore.Set(identity.ID, poll.NextCursor);
|
|
105
|
+
}
|
|
106
|
+
for (const invite of poll.Invites) {
|
|
107
|
+
result.InvitesSeen++;
|
|
108
|
+
await this.processInvite(identity, invite, result);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
result.IdentitiesFailed++;
|
|
113
|
+
LogError(`[CalendarWatcher] Source poll failed for identity ${identity.IdentityValue} ` +
|
|
114
|
+
`(${identity.ID}); skipping: ${err instanceof Error ? err.message : String(err)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Processes one invite for an identity: validates attendance + join URL + start time, resolves the
|
|
119
|
+
* provider, dedupes, and creates the scheduled bridge. A failure on one invite is logged and the
|
|
120
|
+
* next invite is still processed.
|
|
121
|
+
*
|
|
122
|
+
* @param identity The agent identity the invite was polled for.
|
|
123
|
+
* @param invite The normalized invite.
|
|
124
|
+
* @param result The running sweep result to update.
|
|
125
|
+
*/
|
|
126
|
+
async processInvite(identity, invite, result) {
|
|
127
|
+
if (!this.isAttendee(identity, invite.Attendees)) {
|
|
128
|
+
return; // the agent isn't actually invited — ignore (defensive against over-broad sources).
|
|
129
|
+
}
|
|
130
|
+
if (!invite.JoinUrl || invite.JoinUrl.trim().length === 0) {
|
|
131
|
+
return; // nothing to bridge to (not an online meeting).
|
|
132
|
+
}
|
|
133
|
+
if (this.isPast(invite)) {
|
|
134
|
+
return; // the meeting already ended/started in the past — don't schedule a stale join.
|
|
135
|
+
}
|
|
136
|
+
const provider = ResolveProviderFromJoinUrl(invite.JoinUrl, this.engine.Providers);
|
|
137
|
+
if (!provider) {
|
|
138
|
+
result.Unroutable++;
|
|
139
|
+
return; // platform unrecognised or no active provider configured for it.
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
if (await this.bridgeExistsForEvent(invite.ExternalEventID)) {
|
|
143
|
+
result.Duplicates++;
|
|
144
|
+
return; // idempotent — already scheduled this invite.
|
|
145
|
+
}
|
|
146
|
+
await this.createScheduledBridge(identity, invite, provider);
|
|
147
|
+
result.BridgesCreated++;
|
|
148
|
+
LogStatus(`[CalendarWatcher] Scheduled bridge for invite '${invite.Subject ?? invite.ExternalEventID}' ` +
|
|
149
|
+
`→ ${provider.Name} at ${invite.StartTime.toISOString()} (agent ${identity.AgentID}).`);
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
LogError(`[CalendarWatcher] Failed to schedule bridge for invite ${invite.ExternalEventID}: ` +
|
|
153
|
+
`${err instanceof Error ? err.message : String(err)}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** True when the identity's address is among the invite's attendees (case-insensitive, trim-tolerant). */
|
|
157
|
+
isAttendee(identity, attendees) {
|
|
158
|
+
const target = (identity.IdentityValue ?? '').trim().toLowerCase();
|
|
159
|
+
if (target.length === 0) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return attendees.some(a => (a.Email ?? '').trim().toLowerCase() === target);
|
|
163
|
+
}
|
|
164
|
+
/** True when the invite's start time is at/before now (clock-injected) — a stale invite to skip. */
|
|
165
|
+
isPast(invite) {
|
|
166
|
+
return invite.StartTime.getTime() <= this.now();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Dedupe check: is there already an `AIAgentSessionBridge` for this calendar event? The watcher
|
|
170
|
+
* stamps the invite's `ExternalEventID` onto `ExternalConnectionID` at creation, so a match means
|
|
171
|
+
* the invite was already scheduled (this sweep or a previous one / a prior process).
|
|
172
|
+
*
|
|
173
|
+
* @param externalEventID The invite's platform event id.
|
|
174
|
+
* @returns `true` when a bridge already exists for the event.
|
|
175
|
+
*/
|
|
176
|
+
async bridgeExistsForEvent(externalEventID) {
|
|
177
|
+
const rv = RunView.FromMetadataProvider(this.metadataProvider);
|
|
178
|
+
const escaped = externalEventID.replace(/'/g, "''");
|
|
179
|
+
const existing = await rv.RunView({
|
|
180
|
+
EntityName: SESSION_BRIDGE_ENTITY,
|
|
181
|
+
ExtraFilter: `ExternalConnectionID='${escaped}' AND JoinMethod='Invite'`,
|
|
182
|
+
ResultType: 'simple',
|
|
183
|
+
MaxRows: 1,
|
|
184
|
+
}, this.contextUser);
|
|
185
|
+
// On a read failure, treat as "not existing" would risk a duplicate; instead fail safe by
|
|
186
|
+
// reporting existence so we skip creation and log — a missed join is recoverable, a double
|
|
187
|
+
// bridge is noisier. But a failed RunView usually means a transient issue; we surface it.
|
|
188
|
+
if (!existing.Success) {
|
|
189
|
+
LogError(`[CalendarWatcher] Dedupe check failed: ${existing.ErrorMessage}`);
|
|
190
|
+
return true; // fail safe: skip creating to avoid a possible duplicate.
|
|
191
|
+
}
|
|
192
|
+
return existing.Results.length > 0;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Creates the linked `AIAgentSession` and the `Scheduled` `AIAgentSessionBridge` for an invite.
|
|
196
|
+
* The session is the durable record the bridge attaches to (mirroring the on-demand path); the
|
|
197
|
+
* bridge row carries everything the {@link ScheduledBridgeRunner} needs to start it at its time.
|
|
198
|
+
*
|
|
199
|
+
* @param identity The agent identity invited.
|
|
200
|
+
* @param invite The normalized invite.
|
|
201
|
+
* @param provider The resolved transport provider.
|
|
202
|
+
* @returns The saved bridge row.
|
|
203
|
+
* @throws When the session or bridge row cannot be saved.
|
|
204
|
+
*/
|
|
205
|
+
async createScheduledBridge(identity, invite, provider) {
|
|
206
|
+
const agentSessionID = await this.createAgentSession(identity);
|
|
207
|
+
const row = await this.metadataProvider.GetEntityObject(SESSION_BRIDGE_ENTITY, this.contextUser);
|
|
208
|
+
row.NewRecord();
|
|
209
|
+
row.AgentSessionID = agentSessionID;
|
|
210
|
+
row.ProviderID = provider.ID;
|
|
211
|
+
row.Direction = 'Inbound';
|
|
212
|
+
row.JoinMethod = 'Invite';
|
|
213
|
+
row.TurnMode = 'Passive';
|
|
214
|
+
row.Status = 'Scheduled';
|
|
215
|
+
row.ScheduledStartTime = invite.StartTime;
|
|
216
|
+
row.Address = invite.JoinUrl ?? null;
|
|
217
|
+
// Stamp the calendar event id as the external connection id — this is the dedupe key.
|
|
218
|
+
row.ExternalConnectionID = invite.ExternalEventID;
|
|
219
|
+
const saved = await row.Save();
|
|
220
|
+
if (!saved) {
|
|
221
|
+
throw new Error(`Failed to create Scheduled AIAgentSessionBridge: ${row.LatestResult?.CompleteMessage ?? 'unknown error'}`);
|
|
222
|
+
}
|
|
223
|
+
return row;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Creates the `AIAgentSession` the scheduled bridge attaches to, in the pre-active `Idle` state
|
|
227
|
+
* (it is fully hydrated when the {@link ScheduledBridgeRunner} actually starts the bridge at its
|
|
228
|
+
* time). Owned + audited by the watcher's context user. Returns the new session id.
|
|
229
|
+
*
|
|
230
|
+
* @param identity The agent identity (carries the `AgentID`).
|
|
231
|
+
* @returns The new agent-session id.
|
|
232
|
+
* @throws When the session row cannot be saved.
|
|
233
|
+
*/
|
|
234
|
+
async createAgentSession(identity) {
|
|
235
|
+
const session = await this.metadataProvider.GetEntityObject(AGENT_SESSION_ENTITY, this.contextUser);
|
|
236
|
+
session.NewRecord();
|
|
237
|
+
session.AgentID = identity.AgentID;
|
|
238
|
+
session.UserID = this.contextUser.ID;
|
|
239
|
+
session.Status = 'Idle'; // pre-active — the runner brings it Active when it connects the bridge.
|
|
240
|
+
const saved = await session.Save();
|
|
241
|
+
if (!saved) {
|
|
242
|
+
throw new Error(`Failed to create AIAgentSession for agent ${identity.AgentID}: ` +
|
|
243
|
+
`${session.LatestResult?.CompleteMessage ?? 'unknown error'}`);
|
|
244
|
+
}
|
|
245
|
+
return session.ID;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=calendar-watcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-watcher.js","sourceRoot":"","sources":["../src/calendar-watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,QAAQ,EACR,SAAS,EACT,OAAO,GACV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CA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AE,CAAC;QACnC,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CACX,6CAA6C,QAAQ,CAAC,OAAO,IAAI;gBAC7D,GAAG,OAAO,CAAC,YAAY,EAAE,eAAe,IAAI,eAAe,EAAE,CACpE,CAAC;QACN,CAAC;QACD,OAAO,OAAO,CAAC,EAAE,CAAC;IACtB,CAAC;CACJ"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { MJAIBridgeAgentIdentityEntity } from '@memberjunction/core-entities';
|
|
2
|
+
/**
|
|
3
|
+
* A request to provision a tenant calendar/mailbox (or telephony) identity for an agent on a bridge
|
|
4
|
+
* provider — "give Sage a real `sage@customer.com` mailbox the customer's own directory."
|
|
5
|
+
*
|
|
6
|
+
* @see `/plans/realtime/realtime-bridges-architecture.md` §5 ("the agent as a first-class identity in
|
|
7
|
+
* the customer's tenant").
|
|
8
|
+
*/
|
|
9
|
+
export interface AgentIdentityProvisionRequest {
|
|
10
|
+
/** The agent to provision an identity for (`AIAgent.ID`). */
|
|
11
|
+
AgentID: string;
|
|
12
|
+
/** The bridge provider the identity lives on (`AIBridgeProvider.ID`). */
|
|
13
|
+
ProviderID: string;
|
|
14
|
+
/**
|
|
15
|
+
* The kind of identity to provision. `Email` → a tenant calendar mailbox (the headline
|
|
16
|
+
* invite/calendar method); `PhoneNumber` → a DID for inbound telephony; `AccountID` → a platform
|
|
17
|
+
* account handle. Matches `AIBridgeAgentIdentity.IdentityType`.
|
|
18
|
+
*/
|
|
19
|
+
IdentityType: 'Email' | 'PhoneNumber' | 'AccountID';
|
|
20
|
+
/**
|
|
21
|
+
* The requested identity value when the caller already knows it (e.g. a desired mailbox address
|
|
22
|
+
* the admin pre-created). When omitted, the production provisioner allocates one (a mailbox in the
|
|
23
|
+
* tenant, a number from the carrier pool) and returns it.
|
|
24
|
+
*/
|
|
25
|
+
RequestedValue?: string;
|
|
26
|
+
/** A human-friendly display name for the identity (e.g. the agent's name). */
|
|
27
|
+
DisplayName?: string;
|
|
28
|
+
/** Free-form provider-specific provisioning hints (tenant id, OU, number region, …). */
|
|
29
|
+
Configuration?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The result of a provisioning request — the concrete identity that was created/claimed.
|
|
33
|
+
*/
|
|
34
|
+
export interface AgentIdentityProvisionResult {
|
|
35
|
+
/** The provisioned identity value (the mailbox address / phone number / account id). */
|
|
36
|
+
IdentityValue: string;
|
|
37
|
+
/** The display name set on the identity. */
|
|
38
|
+
DisplayName?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Provider-specific result detail to persist on the identity's `Configuration` (the external
|
|
41
|
+
* object id of the created mailbox, the credential reference, the carrier order id, …). Never
|
|
42
|
+
* contains a raw secret — secrets go through MJ's credential system and are referenced by id.
|
|
43
|
+
*/
|
|
44
|
+
Configuration?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The **identity-provisioning seam** — provisions a tenant mailbox/calendar (or telephony) identity
|
|
48
|
+
* for an agent on a provider. This is a *documented seam*, not a built integration: the schema
|
|
49
|
+
* (`AIBridgeAgentIdentity`) already holds the *result*, so all this interface does is define the shape
|
|
50
|
+
* production wires to Microsoft Graph admin / Google Workspace Admin SDK / a telephony carrier API.
|
|
51
|
+
*
|
|
52
|
+
* Kept deliberately thin (one method) — over-building here is explicitly out of scope; the value is
|
|
53
|
+
* the clean boundary + the TODO marking where the real admin APIs bind.
|
|
54
|
+
*/
|
|
55
|
+
export interface IAgentIdentityProvisioner {
|
|
56
|
+
/**
|
|
57
|
+
* Provisions an identity for an agent and returns the concrete value (+ provider detail). The
|
|
58
|
+
* caller persists the result onto an {@link MJAIBridgeAgentIdentityEntity} (see
|
|
59
|
+
* {@link ApplyProvisionResultToIdentity}); this method does NOT write the row itself, keeping the
|
|
60
|
+
* provisioner free of MJ entity concerns.
|
|
61
|
+
*
|
|
62
|
+
* @param request What to provision.
|
|
63
|
+
* @returns The provisioned identity detail.
|
|
64
|
+
* @throws On provisioning failure (the production binding surfaces admin-API errors here).
|
|
65
|
+
*/
|
|
66
|
+
Provision(request: AgentIdentityProvisionRequest): Promise<AgentIdentityProvisionResult>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The error a not-yet-bound {@link IAgentIdentityProvisioner} throws — distinct type so a host can
|
|
70
|
+
* detect "provisioning not wired" vs. a genuine admin-API failure.
|
|
71
|
+
*/
|
|
72
|
+
export declare class IdentityProvisionerNotBoundError extends Error {
|
|
73
|
+
constructor(target: string);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* **Production-binding stub** {@link IAgentIdentityProvisioner}.
|
|
77
|
+
*
|
|
78
|
+
* Provisioning a real tenant mailbox/calendar (or a DID) is a delegated-admin operation against the
|
|
79
|
+
* customer's directory — Microsoft Graph (`/users` + mailbox + calendar permissions), Google
|
|
80
|
+
* Workspace Admin SDK, or a telephony carrier's number-ordering API — gated by admin consent and
|
|
81
|
+
* minimal scopes, with the credential stored in MJ's credential system and referenced (never inline)
|
|
82
|
+
* by the provider/identity `Configuration`.
|
|
83
|
+
*
|
|
84
|
+
* Because that handshake is a per-deployment, governed flow (see the architecture's open sub-question
|
|
85
|
+
* on the provisioning handshake), this stub throws {@link IdentityProvisionerNotBoundError} until a
|
|
86
|
+
* host binds the real admin API. The seam + the schema are what's in scope now.
|
|
87
|
+
*
|
|
88
|
+
* @remarks **TODO (production):** implement against Microsoft Graph / Google Workspace Admin SDK /
|
|
89
|
+
* the telephony carrier API per the request's `IdentityType` + provider; resolve the admin credential
|
|
90
|
+
* from the provider `Configuration` via the credential system; return the created mailbox/number.
|
|
91
|
+
*/
|
|
92
|
+
export declare class StubAgentIdentityProvisioner implements IAgentIdentityProvisioner {
|
|
93
|
+
/** @inheritdoc */
|
|
94
|
+
Provision(request: AgentIdentityProvisionRequest): Promise<AgentIdentityProvisionResult>;
|
|
95
|
+
/** Maps an identity type to the admin surface label used in the not-bound error. */
|
|
96
|
+
private targetLabel;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Applies a {@link AgentIdentityProvisionResult} onto a (new or existing)
|
|
100
|
+
* {@link MJAIBridgeAgentIdentityEntity} from the original request — the small bridge between the
|
|
101
|
+
* provisioning seam (which returns plain data) and the MJ entity layer (which the caller saves). Pure
|
|
102
|
+
* field-mapping; the caller owns `NewRecord()`/`Save()` so this stays provider-free and testable.
|
|
103
|
+
*
|
|
104
|
+
* @param identity The identity entity to populate (already `NewRecord()`'d for an insert).
|
|
105
|
+
* @param request The original provisioning request (carries `AgentID` / `ProviderID` / `IdentityType`).
|
|
106
|
+
* @param result The provisioning result to apply.
|
|
107
|
+
*/
|
|
108
|
+
export declare function ApplyProvisionResultToIdentity(identity: MJAIBridgeAgentIdentityEntity, request: AgentIdentityProvisionRequest, result: AgentIdentityProvisionResult): void;
|
|
109
|
+
//# sourceMappingURL=identity-provisioner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-provisioner.d.ts","sourceRoot":"","sources":["../src/identity-provisioner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,WAAW,6BAA6B;IAC1C,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAEhB,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,YAAY,EAAE,OAAO,GAAG,aAAa,GAAG,WAAW,CAAC;IAEpD;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IACzC,wFAAwF;IACxF,aAAa,EAAE,MAAM,CAAC;IAEtB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;;;;;OASG;IACH,SAAS,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAC5F;AAED;;;GAGG;AACH,qBAAa,gCAAiC,SAAQ,KAAK;gBAC3C,MAAM,EAAE,MAAM;CAQ7B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,4BAA6B,YAAW,yBAAyB;IAC1E,kBAAkB;IACL,SAAS,CAClB,OAAO,EAAE,6BAA6B,GACvC,OAAO,CAAC,4BAA4B,CAAC;IAMxC,oFAAoF;IACpF,OAAO,CAAC,WAAW;CAWtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC1C,QAAQ,EAAE,6BAA6B,EACvC,OAAO,EAAE,6BAA6B,EACtC,MAAM,EAAE,4BAA4B,GACrC,IAAI,CAUN"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error a not-yet-bound {@link IAgentIdentityProvisioner} throws — distinct type so a host can
|
|
3
|
+
* detect "provisioning not wired" vs. a genuine admin-API failure.
|
|
4
|
+
*/
|
|
5
|
+
export class IdentityProvisionerNotBoundError extends Error {
|
|
6
|
+
constructor(target) {
|
|
7
|
+
super(`Agent identity provisioner for '${target}' is not bound. ` +
|
|
8
|
+
`Production wires the ${target} admin API (Microsoft Graph / Google Workspace Admin / ` +
|
|
9
|
+
`telephony carrier); the schema already holds the result.`);
|
|
10
|
+
this.name = 'IdentityProvisionerNotBoundError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* **Production-binding stub** {@link IAgentIdentityProvisioner}.
|
|
15
|
+
*
|
|
16
|
+
* Provisioning a real tenant mailbox/calendar (or a DID) is a delegated-admin operation against the
|
|
17
|
+
* customer's directory — Microsoft Graph (`/users` + mailbox + calendar permissions), Google
|
|
18
|
+
* Workspace Admin SDK, or a telephony carrier's number-ordering API — gated by admin consent and
|
|
19
|
+
* minimal scopes, with the credential stored in MJ's credential system and referenced (never inline)
|
|
20
|
+
* by the provider/identity `Configuration`.
|
|
21
|
+
*
|
|
22
|
+
* Because that handshake is a per-deployment, governed flow (see the architecture's open sub-question
|
|
23
|
+
* on the provisioning handshake), this stub throws {@link IdentityProvisionerNotBoundError} until a
|
|
24
|
+
* host binds the real admin API. The seam + the schema are what's in scope now.
|
|
25
|
+
*
|
|
26
|
+
* @remarks **TODO (production):** implement against Microsoft Graph / Google Workspace Admin SDK /
|
|
27
|
+
* the telephony carrier API per the request's `IdentityType` + provider; resolve the admin credential
|
|
28
|
+
* from the provider `Configuration` via the credential system; return the created mailbox/number.
|
|
29
|
+
*/
|
|
30
|
+
export class StubAgentIdentityProvisioner {
|
|
31
|
+
/** @inheritdoc */
|
|
32
|
+
async Provision(request) {
|
|
33
|
+
// TODO(production): bind the directory/carrier admin API for request.IdentityType + provider,
|
|
34
|
+
// resolve the admin credential from provider Configuration, and allocate the identity.
|
|
35
|
+
throw new IdentityProvisionerNotBoundError(this.targetLabel(request.IdentityType));
|
|
36
|
+
}
|
|
37
|
+
/** Maps an identity type to the admin surface label used in the not-bound error. */
|
|
38
|
+
targetLabel(identityType) {
|
|
39
|
+
switch (identityType) {
|
|
40
|
+
case 'PhoneNumber':
|
|
41
|
+
return 'telephony carrier';
|
|
42
|
+
case 'AccountID':
|
|
43
|
+
return 'platform account';
|
|
44
|
+
case 'Email':
|
|
45
|
+
default:
|
|
46
|
+
return 'calendar/mailbox directory';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Applies a {@link AgentIdentityProvisionResult} onto a (new or existing)
|
|
52
|
+
* {@link MJAIBridgeAgentIdentityEntity} from the original request — the small bridge between the
|
|
53
|
+
* provisioning seam (which returns plain data) and the MJ entity layer (which the caller saves). Pure
|
|
54
|
+
* field-mapping; the caller owns `NewRecord()`/`Save()` so this stays provider-free and testable.
|
|
55
|
+
*
|
|
56
|
+
* @param identity The identity entity to populate (already `NewRecord()`'d for an insert).
|
|
57
|
+
* @param request The original provisioning request (carries `AgentID` / `ProviderID` / `IdentityType`).
|
|
58
|
+
* @param result The provisioning result to apply.
|
|
59
|
+
*/
|
|
60
|
+
export function ApplyProvisionResultToIdentity(identity, request, result) {
|
|
61
|
+
identity.AgentID = request.AgentID;
|
|
62
|
+
identity.ProviderID = request.ProviderID;
|
|
63
|
+
identity.IdentityType = request.IdentityType;
|
|
64
|
+
identity.IdentityValue = result.IdentityValue;
|
|
65
|
+
identity.DisplayName = result.DisplayName ?? request.DisplayName ?? null;
|
|
66
|
+
identity.IsActive = true;
|
|
67
|
+
if (result.Configuration) {
|
|
68
|
+
identity.Configuration = JSON.stringify(result.Configuration);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=identity-provisioner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-provisioner.js","sourceRoot":"","sources":["../src/identity-provisioner.ts"],"names":[],"mappings":"AA8EA;;;GAGG;AACH,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IACvD,YAAY,MAAc;QACtB,KAAK,CACD,mCAAmC,MAAM,kBAAkB;YACvD,wBAAwB,MAAM,yDAAyD;YACvF,0DAA0D,CACjE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;IACnD,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,4BAA4B;IACrC,kBAAkB;IACX,KAAK,CAAC,SAAS,CAClB,OAAsC;QAEtC,8FAA8F;QAC9F,uFAAuF;QACvF,MAAM,IAAI,gCAAgC,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IACvF,CAAC;IAED,oFAAoF;IAC5E,WAAW,CAAC,YAA2D;QAC3E,QAAQ,YAAY,EAAE,CAAC;YACnB,KAAK,aAAa;gBACd,OAAO,mBAAmB,CAAC;YAC/B,KAAK,WAAW;gBACZ,OAAO,kBAAkB,CAAC;YAC9B,KAAK,OAAO,CAAC;YACb;gBACI,OAAO,4BAA4B,CAAC;QAC5C,CAAC;IACL,CAAC;CACJ;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,8BAA8B,CAC1C,QAAuC,EACvC,OAAsC,EACtC,MAAoC;IAEpC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACnC,QAAQ,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACzC,QAAQ,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC7C,QAAQ,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAC9C,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC;IACzE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;IACzB,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QACvB,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAClE,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './ai-bridge-engine.js';
|
|
2
|
+
export * from './multi-agent-room-coordinator.js';
|
|
3
|
+
export * from './loopback-bridge.js';
|
|
4
|
+
export * from './join-url-resolver.js';
|
|
5
|
+
export * from './calendar-source.js';
|
|
6
|
+
export * from './calendar-watcher.js';
|
|
7
|
+
export * from './scheduled-bridge-runner.js';
|
|
8
|
+
export * from './identity-provisioner.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './ai-bridge-engine.js';
|
|
2
|
+
export * from './multi-agent-room-coordinator.js';
|
|
3
|
+
export * from './loopback-bridge.js';
|
|
4
|
+
export * from './join-url-resolver.js';
|
|
5
|
+
export * from './calendar-source.js';
|
|
6
|
+
export * from './calendar-watcher.js';
|
|
7
|
+
export * from './scheduled-bridge-runner.js';
|
|
8
|
+
export * from './identity-provisioner.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MJAIBridgeProviderEntity } from '@memberjunction/core-entities';
|
|
2
|
+
/**
|
|
3
|
+
* The canonical platform a meeting/call join URL belongs to. This is the *platform identity* a join
|
|
4
|
+
* URL resolves to — distinct from (but used to find) an {@link MJAIBridgeProviderEntity} row. Kept as
|
|
5
|
+
* a union type (repo convention — union over enum) so it exports cleanly and a new platform is a
|
|
6
|
+
* one-line addition.
|
|
7
|
+
*/
|
|
8
|
+
export type JoinUrlPlatform = 'Zoom' | 'Microsoft Teams' | 'Google Meet' | 'Cisco Webex' | 'Slack' | 'Discord' | 'RingCentral' | 'GoTo Meeting' | 'BlueJeans';
|
|
9
|
+
/**
|
|
10
|
+
* Classifies a meeting/call join URL into its {@link JoinUrlPlatform} by hostname — a **pure**,
|
|
11
|
+
* dependency-free function. Returns `null` for an empty/malformed URL or an unrecognised host.
|
|
12
|
+
*
|
|
13
|
+
* The match is a strict domain-suffix test on the parsed hostname, never a naive substring scan, so
|
|
14
|
+
* a hostile URL that merely *contains* a known token in its path or as a deceptive prefix
|
|
15
|
+
* (`https://evil.com/zoom.us/j/123`, `https://zoom.us.attacker.com/...`) does **not** match the
|
|
16
|
+
* legitimate platform.
|
|
17
|
+
*
|
|
18
|
+
* @param url The raw join URL (e.g. `'https://us02web.zoom.us/j/8675309?pwd=abc'`).
|
|
19
|
+
* @returns The platform the URL belongs to, or `null` when none matches.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ClassifyJoinUrl(url: string): JoinUrlPlatform | null;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves a meeting/call join URL to the matching **active** {@link MJAIBridgeProviderEntity} from a
|
|
24
|
+
* candidate set (typically `AIBridgeEngine.Providers`) — a **pure** function over its inputs. First
|
|
25
|
+
* classifies the URL via {@link ClassifyJoinUrl}, then finds the active provider whose `Name` matches
|
|
26
|
+
* the platform (case-insensitive, trim-tolerant).
|
|
27
|
+
*
|
|
28
|
+
* Returns `null` when the URL is unrecognised, OR when no active provider for that platform is
|
|
29
|
+
* registered (the platform is known but not configured in this tenant — the watcher then skips the
|
|
30
|
+
* invite rather than guessing a transport).
|
|
31
|
+
*
|
|
32
|
+
* @param url The raw join URL from a calendar invite.
|
|
33
|
+
* @param providers The candidate providers to resolve against (e.g. the engine's cached registry).
|
|
34
|
+
* @returns The matching active provider, or `null`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ResolveProviderFromJoinUrl(url: string, providers: ReadonlyArray<MJAIBridgeProviderEntity>): MJAIBridgeProviderEntity | null;
|
|
37
|
+
//# sourceMappingURL=join-url-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-url-resolver.d.ts","sourceRoot":"","sources":["../src/join-url-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GACrB,MAAM,GACN,iBAAiB,GACjB,aAAa,GACb,aAAa,GACb,OAAO,GACP,SAAS,GACT,aAAa,GACb,cAAc,GACd,WAAW,CAAC;AAqClB;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAWnE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CACtC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,aAAa,CAAC,wBAAwB,CAAC,GACnD,wBAAwB,GAAG,IAAI,CAUjC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host-suffix → platform rule table. Ordered most-specific-first is unnecessary because matching
|
|
3
|
+
* is by full domain-suffix (no rule is a suffix of another here), but new rules should still prefer
|
|
4
|
+
* the most specific registrable host. Covers the meeting platforms in the bridge build set
|
|
5
|
+
* (`/plans/realtime/realtime-bridges-architecture.md` §8) plus the two EOL platforms for completeness.
|
|
6
|
+
*/
|
|
7
|
+
const JOIN_URL_RULES = [
|
|
8
|
+
{ HostSuffix: 'zoom.us', Platform: 'Zoom' },
|
|
9
|
+
{ HostSuffix: 'zoomgov.com', Platform: 'Zoom' },
|
|
10
|
+
{ HostSuffix: 'teams.microsoft.com', Platform: 'Microsoft Teams' },
|
|
11
|
+
{ HostSuffix: 'teams.live.com', Platform: 'Microsoft Teams' },
|
|
12
|
+
{ HostSuffix: 'meet.google.com', Platform: 'Google Meet' },
|
|
13
|
+
{ HostSuffix: 'webex.com', Platform: 'Cisco Webex' },
|
|
14
|
+
{ HostSuffix: 'slack.com', Platform: 'Slack' },
|
|
15
|
+
{ HostSuffix: 'discord.com', Platform: 'Discord' },
|
|
16
|
+
{ HostSuffix: 'discord.gg', Platform: 'Discord' },
|
|
17
|
+
{ HostSuffix: 'ringcentral.com', Platform: 'RingCentral' },
|
|
18
|
+
{ HostSuffix: 'rcv.io', Platform: 'RingCentral' },
|
|
19
|
+
{ HostSuffix: 'goto.com', Platform: 'GoTo Meeting' },
|
|
20
|
+
{ HostSuffix: 'gotomeeting.com', Platform: 'GoTo Meeting' },
|
|
21
|
+
{ HostSuffix: 'bluejeans.com', Platform: 'BlueJeans' },
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Classifies a meeting/call join URL into its {@link JoinUrlPlatform} by hostname — a **pure**,
|
|
25
|
+
* dependency-free function. Returns `null` for an empty/malformed URL or an unrecognised host.
|
|
26
|
+
*
|
|
27
|
+
* The match is a strict domain-suffix test on the parsed hostname, never a naive substring scan, so
|
|
28
|
+
* a hostile URL that merely *contains* a known token in its path or as a deceptive prefix
|
|
29
|
+
* (`https://evil.com/zoom.us/j/123`, `https://zoom.us.attacker.com/...`) does **not** match the
|
|
30
|
+
* legitimate platform.
|
|
31
|
+
*
|
|
32
|
+
* @param url The raw join URL (e.g. `'https://us02web.zoom.us/j/8675309?pwd=abc'`).
|
|
33
|
+
* @returns The platform the URL belongs to, or `null` when none matches.
|
|
34
|
+
*/
|
|
35
|
+
export function ClassifyJoinUrl(url) {
|
|
36
|
+
const hostname = parseHostname(url);
|
|
37
|
+
if (!hostname) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
for (const rule of JOIN_URL_RULES) {
|
|
41
|
+
if (hostnameEndsWith(hostname, rule.HostSuffix)) {
|
|
42
|
+
return rule.Platform;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolves a meeting/call join URL to the matching **active** {@link MJAIBridgeProviderEntity} from a
|
|
49
|
+
* candidate set (typically `AIBridgeEngine.Providers`) — a **pure** function over its inputs. First
|
|
50
|
+
* classifies the URL via {@link ClassifyJoinUrl}, then finds the active provider whose `Name` matches
|
|
51
|
+
* the platform (case-insensitive, trim-tolerant).
|
|
52
|
+
*
|
|
53
|
+
* Returns `null` when the URL is unrecognised, OR when no active provider for that platform is
|
|
54
|
+
* registered (the platform is known but not configured in this tenant — the watcher then skips the
|
|
55
|
+
* invite rather than guessing a transport).
|
|
56
|
+
*
|
|
57
|
+
* @param url The raw join URL from a calendar invite.
|
|
58
|
+
* @param providers The candidate providers to resolve against (e.g. the engine's cached registry).
|
|
59
|
+
* @returns The matching active provider, or `null`.
|
|
60
|
+
*/
|
|
61
|
+
export function ResolveProviderFromJoinUrl(url, providers) {
|
|
62
|
+
const platform = ClassifyJoinUrl(url);
|
|
63
|
+
if (!platform) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const target = platform.toLowerCase();
|
|
67
|
+
const match = providers.find(p => p.Status === 'Active' && (p.Name ?? '').trim().toLowerCase() === target);
|
|
68
|
+
return match ?? null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Parses the lowercased hostname from a URL. Tolerant of a missing scheme (prepends `https://` so a
|
|
72
|
+
* bare `zoom.us/j/123` still parses) and returns `null` for anything unparseable.
|
|
73
|
+
*
|
|
74
|
+
* @param url The raw URL.
|
|
75
|
+
* @returns The lowercased hostname, or `null`.
|
|
76
|
+
*/
|
|
77
|
+
function parseHostname(url) {
|
|
78
|
+
const trimmed = (url ?? '').trim();
|
|
79
|
+
if (trimmed.length === 0) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
83
|
+
try {
|
|
84
|
+
return new URL(withScheme).hostname.toLowerCase();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* True domain-suffix test: `hostname` equals `suffix` or ends with `'.' + suffix`. This is what makes
|
|
92
|
+
* `us02web.zoom.us` match `zoom.us` while `zoom.us.attacker.com` does NOT (its suffix is
|
|
93
|
+
* `attacker.com`, not `zoom.us`).
|
|
94
|
+
*
|
|
95
|
+
* @param hostname The already-lowercased hostname to test.
|
|
96
|
+
* @param suffix The already-lowercased registrable host suffix.
|
|
97
|
+
* @returns `true` when `hostname` is on (or under) `suffix`.
|
|
98
|
+
*/
|
|
99
|
+
function hostnameEndsWith(hostname, suffix) {
|
|
100
|
+
return hostname === suffix || hostname.endsWith(`.${suffix}`);
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=join-url-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-url-resolver.js","sourceRoot":"","sources":["../src/join-url-resolver.ts"],"names":[],"mappings":"AA+BA;;;;;GAKG;AACH,MAAM,cAAc,GAA+B;IAC/C,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE;IAC3C,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE;IAC/C,EAAE,UAAU,EAAE,qBAAqB,EAAE,QAAQ,EAAE,iBAAiB,EAAE;IAClE,EAAE,UAAU,EAAE,gBAAgB,EAAE,QAAQ,EAAE,iBAAiB,EAAE;IAC7D,EAAE,UAAU,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,EAAE;IAC1D,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE;IACpD,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE;IAC9C,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE;IAClD,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ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