@memberjunction/ai-bridge-server 6.2.0-edge.5 → 6.2.0-edge.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@memberjunction/ai-bridge-server",
3
3
  "type": "module",
4
- "version": "6.2.0-edge.5",
4
+ "version": "6.2.0-edge.7",
5
5
  "description": "MemberJunction: Server-tier coordination + execution for Realtime Bridges — completes the unified media-transport seam (the bridge ↔ IRealtimeSession pipe), bot-session lifecycle, host affinity + janitor, participant tracking, and turn-taking integration. Mirrors the AIEngineBase/AIEngine pair.",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -11,18 +11,14 @@
11
11
  "author": "MemberJunction.com",
12
12
  "license": "BUSL-1.1",
13
13
  "dependencies": {
14
- "@memberjunction/core": "6.2.0-edge.5",
15
- "@memberjunction/global": "6.2.0-edge.5",
16
- "@memberjunction/core-entities": "6.2.0-edge.5",
17
- "@memberjunction/ai": "6.2.0-edge.5",
18
- "@memberjunction/ai-bridge-base": "6.2.0-edge.5",
14
+ "@memberjunction/core": "6.2.0-edge.7",
15
+ "@memberjunction/global": "6.2.0-edge.7",
16
+ "@memberjunction/core-entities": "6.2.0-edge.7",
17
+ "@memberjunction/ai": "6.2.0-edge.7",
18
+ "@memberjunction/ai-bridge-base": "6.2.0-edge.7",
19
+ "@memberjunction/communication-types": "6.2.0-edge.7",
19
20
  "rxjs": "^7.8.2"
20
21
  },
21
- "//optionalDependencies": "@microsoft/microsoft-graph-client and googleapis are OPTIONAL PEER SDKs (CLAUDE rule 8, category 2): this package never statically imports either. They back the calendar + identity-provisioner seams only. GraphCalendarSource/GraphAdmin provisioning wire IGraphCalendarLike/IGraphAdminLike over @microsoft/microsoft-graph-client (calendarView delta + POST /users); GoogleCalendarSource/Google Workspace provisioning wire IGoogleCalendarLike/IGoogleWorkspaceAdminLike over googleapis (calendar.events.list syncToken + admin.users.insert). The telephony-carrier number-order path is injected via ITelephonyCarrierLike (the carrier SDK is declared by each telephony provider package, not here). All surfaces are injected behind structural interfaces so the package builds + unit-tests with no install and no network, and are loaded only when a Graph/Google-backed identity is configured at deployment.",
22
- "optionalDependencies": {
23
- "@microsoft/microsoft-graph-client": "^3.0.7",
24
- "googleapis": "^144.0.0"
25
- },
26
22
  "devDependencies": {
27
23
  "@types/node": "24.10.11",
28
24
  "ts-node-dev": "^2.0.0",
@@ -1,153 +0,0 @@
1
- /**
2
- * @fileoverview Concrete production bindings for the calendar seams declared in
3
- * {@link ./calendar-source}. Each wraps an OPTIONAL PEER SDK behind the existing injected
4
- * surface (`IGraphCalendarLike` / `IGoogleCalendarLike`) so the package still builds and
5
- * unit-tests with no SDK installed and no network (CLAUDE rule 8, category 2 — optional peer
6
- * SDK loaded only when a calendar-backed identity is configured at deployment).
7
- *
8
- * Mirrors the Teams `RealGraphCallsClient` pattern: a lazy, memoized module loader + a structural
9
- * surface so the vendor SDK's real types never leak. Auth tokens are **pre-resolved upstream** (the
10
- * host acquires an app/delegated token from the provider `Configuration` via MJ's credential system
11
- * and injects it here) — token ACQUISITION is deliberately not this client's job, keeping it pure
12
- * and testable; the deployment-specific client-credentials flow lives in the host wiring.
13
- *
14
- * @module @memberjunction/ai-bridge-server
15
- */
16
- import type { IGraphCalendarLike, GraphEventPage, IGoogleCalendarLike, GoogleEventPage, GoogleListEventsArgs } from './calendar-source.js';
17
- /** One fluent Graph request — the subset of verbs/headers the calendar reader issues. */
18
- export interface GraphCalendarRequestLike {
19
- /** Adds a request header (used for `Prefer: outlook.timezone="UTC"`); returns `this` for chaining. */
20
- header(name: string, value: string): GraphCalendarRequestLike;
21
- /** Issues `GET {path}`; resolves the parsed JSON response. */
22
- get(): Promise<unknown>;
23
- }
24
- /** The constructed Graph client surface — just the `api(path)` request-builder entry point. */
25
- export interface GraphCalendarClientLike {
26
- /** Begins a fluent request against a Graph resource path (e.g. `/users/{id}/calendarView/delta`). */
27
- api(path: string): GraphCalendarRequestLike;
28
- }
29
- /** The `@microsoft/microsoft-graph-client` module surface we use (`Client.init({ authProvider })`). */
30
- export interface GraphCalendarModuleLike {
31
- /** The `Client` class with its `init` static factory. */
32
- Client: {
33
- init(options: GraphCalendarInitOptions): GraphCalendarClientLike;
34
- };
35
- }
36
- /** The `Client.init` options subset — just the bearer-token `authProvider` callback. */
37
- export interface GraphCalendarInitOptions {
38
- /** The Graph auth-provider callback; the SDK calls it per request and expects `done(error, token)`. */
39
- authProvider(done: (error: Error | null, accessToken: string | null) => void): void;
40
- }
41
- /** Loads the `@microsoft/microsoft-graph-client` module. Overridable in tests; defaults to a lazy import. */
42
- export type GraphCalendarModuleLoader = () => Promise<GraphCalendarModuleLike>;
43
- /** Credentials the {@link GraphCalendarClient} authenticates with — a pre-resolved bearer token. */
44
- export interface GraphCalendarCredentials {
45
- /** A pre-resolved OAuth bearer / application token with `Calendars.Read` scope (resolved upstream). */
46
- AccessToken: string;
47
- }
48
- /**
49
- * Options for {@link GraphCalendarClient}. The first-poll window bounds the initial
50
- * `calendarView` delta; subsequent polls follow the opaque `@odata.deltaLink` cursor.
51
- */
52
- export interface GraphCalendarClientOptions {
53
- /** Pre-resolved Graph credentials. */
54
- Credentials: GraphCalendarCredentials;
55
- /** How far forward the FIRST poll's calendarView window extends (days). Defaults to 30. */
56
- LookaheadDays?: number;
57
- /** Test seam: override the module loader. Defaults to the lazy dynamic import. */
58
- ModuleLoader?: GraphCalendarModuleLoader;
59
- /** Test seam: a fixed "now" for the first-poll window (so window math is deterministic). */
60
- Now?: Date;
61
- }
62
- /** Lazily loads + memoizes `@microsoft/microsoft-graph-client`; throws a clear install hint on failure. */
63
- export declare const DefaultGraphCalendarModuleLoader: GraphCalendarModuleLoader;
64
- /** @deprecated Use {@link DefaultGraphCalendarModuleLoader}. */
65
- export declare const defaultGraphCalendarModuleLoader: GraphCalendarModuleLoader;
66
- /**
67
- * A real {@link IGraphCalendarLike} over Microsoft Graph (`GET /users/{id}/calendarView/delta`).
68
- * The first poll requests a forward window (`startDateTime`..`endDateTime`) in UTC; later polls pass
69
- * the opaque cursor (`@odata.nextLink` within a poll, `@odata.deltaLink` between polls) straight back
70
- * to Graph. The constructed client is built once on first use and reused.
71
- */
72
- export declare class GraphCalendarClient implements IGraphCalendarLike {
73
- private readonly options;
74
- private readonly loadModule;
75
- private clientPromise?;
76
- constructor(options: GraphCalendarClientOptions);
77
- /** @inheritdoc */
78
- listEvents(userId: string, cursor?: string): Promise<GraphEventPage>;
79
- /** Builds the first-poll `calendarView/delta` path with a UTC `[now, now+lookahead]` window. */
80
- private firstPollPath;
81
- /** Normalizes the raw Graph delta response to the seam's {@link GraphEventPage} shape. */
82
- private toEventPage;
83
- /** Builds (once) + memoizes the authenticated Graph client. */
84
- private client;
85
- }
86
- /** The `calendar.events.list` surface we call — resolves a page of events. */
87
- export interface GoogleEventsApiLike {
88
- /** Lists one page of events; resolves `{ data: { items, nextPageToken, nextSyncToken } }`. */
89
- list(params: Record<string, unknown>): Promise<{
90
- data?: unknown;
91
- }>;
92
- }
93
- /** The constructed Google Calendar client surface — `events.list`. */
94
- export interface GoogleCalendarClientLike {
95
- /** The `events` resource collection. */
96
- events: GoogleEventsApiLike;
97
- }
98
- /** The `googleapis` module surface we use (`google.calendar({ version, auth })`). */
99
- export interface GoogleApisModuleLike {
100
- /** The `google` namespace with the `calendar` client factory. */
101
- google: {
102
- calendar(options: {
103
- version: string;
104
- auth: unknown;
105
- }): GoogleCalendarClientLike;
106
- };
107
- }
108
- /** Loads the `googleapis` module. Overridable in tests; defaults to a lazy import. */
109
- export type GoogleApisModuleLoader = () => Promise<GoogleApisModuleLike>;
110
- /**
111
- * Options for {@link GoogleCalendarClient}. `Auth` is a pre-built `googleapis` auth client (an
112
- * OAuth2 client or a JWT/service-account client) resolved upstream from the provider `Configuration`
113
- * via MJ's credential system — token acquisition is not this client's job.
114
- */
115
- export interface GoogleCalendarClientOptions {
116
- /** A pre-built googleapis auth client (OAuth2 / JWT / service-account), resolved upstream. */
117
- Auth: unknown;
118
- /** How far forward the FIRST poll's `timeMin`..`timeMax` window extends (days). Defaults to 30. */
119
- LookaheadDays?: number;
120
- /** Test seam: override the module loader. Defaults to the lazy dynamic import. */
121
- ModuleLoader?: GoogleApisModuleLoader;
122
- /** Test seam: a fixed "now" for the first-poll window. */
123
- Now?: Date;
124
- }
125
- /** Lazily loads + memoizes `googleapis`; throws a clear install hint on failure. */
126
- export declare const DefaultGoogleApisModuleLoader: GoogleApisModuleLoader;
127
- /** @deprecated Use {@link DefaultGoogleApisModuleLoader}. */
128
- export declare const defaultGoogleApisModuleLoader: GoogleApisModuleLoader;
129
- /**
130
- * A real {@link IGoogleCalendarLike} over `calendar.events.list`. The first poll requests a forward
131
- * window (`timeMin`..`timeMax`, `singleEvents`, ordered) so Google returns an initial `nextSyncToken`;
132
- * later polls pass the `syncToken` (between polls) or `pageToken` (within a poll) verbatim. The
133
- * constructed client is built once on first use and reused.
134
- */
135
- export declare class GoogleCalendarClient implements IGoogleCalendarLike {
136
- private readonly options;
137
- private readonly loadModule;
138
- private clientPromise?;
139
- constructor(options: GoogleCalendarClientOptions);
140
- /** @inheritdoc */
141
- listEvents(args: GoogleListEventsArgs): Promise<GoogleEventPage>;
142
- /**
143
- * Builds `events.list` params. A `syncToken`/`pageToken` poll passes only the token (Google
144
- * rejects window params alongside a sync token); a fresh poll sends the forward window + the
145
- * `singleEvents`/`orderBy` flags that make Google issue an initial `nextSyncToken`.
146
- */
147
- private buildListParams;
148
- /** Normalizes the raw `events.list` data to the seam's {@link GoogleEventPage} shape. */
149
- private toEventPage;
150
- /** Builds (once) + memoizes the Google Calendar client. */
151
- private client;
152
- }
153
- //# sourceMappingURL=calendar-clients.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calendar-clients.d.ts","sourceRoot":"","sources":["../src/calendar-clients.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACR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AAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,0DAA0D;IAC1D,GAAG,CAAC,EAAE,IAAI,CAAC;CACd;AAED,oFAAoF;AACpF,eAAO,MAAM,6BAA6B,EAAE,sBAe3C,CAAC;AAEF,6DAA6D;AAC7D,eAAO,MAAM,6BAA6B,EAAE,sBAAsD,CAAC;AAEnG;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,mBAAmB;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,aAAa,CAAC,CAAoC;gBAE9C,OAAO,EAAE,2BAA2B;IAKhD,kBAAkB;IACL,UAAU,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IAM7E;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAmBvB,yFAAyF;IACzF,OAAO,CAAC,WAAW;IAYnB,2DAA2D;IAC3D,OAAO,CAAC,MAAM;CAQjB"}
@@ -1,194 +0,0 @@
1
- /**
2
- * @fileoverview Concrete production bindings for the calendar seams declared in
3
- * {@link ./calendar-source}. Each wraps an OPTIONAL PEER SDK behind the existing injected
4
- * surface (`IGraphCalendarLike` / `IGoogleCalendarLike`) so the package still builds and
5
- * unit-tests with no SDK installed and no network (CLAUDE rule 8, category 2 — optional peer
6
- * SDK loaded only when a calendar-backed identity is configured at deployment).
7
- *
8
- * Mirrors the Teams `RealGraphCallsClient` pattern: a lazy, memoized module loader + a structural
9
- * surface so the vendor SDK's real types never leak. Auth tokens are **pre-resolved upstream** (the
10
- * host acquires an app/delegated token from the provider `Configuration` via MJ's credential system
11
- * and injects it here) — token ACQUISITION is deliberately not this client's job, keeping it pure
12
- * and testable; the deployment-specific client-credentials flow lives in the host wiring.
13
- *
14
- * @module @memberjunction/ai-bridge-server
15
- */
16
- /** Lazily loads + memoizes `@microsoft/microsoft-graph-client`; throws a clear install hint on failure. */
17
- export const DefaultGraphCalendarModuleLoader = async () => {
18
- try {
19
- const mod = await import('@microsoft/microsoft-graph-client');
20
- const resolved = unwrap(mod);
21
- if (!isGraphModule(resolved)) {
22
- throw new Error('the @microsoft/microsoft-graph-client module did not export a Client.init factory');
23
- }
24
- return resolved;
25
- }
26
- catch (err) {
27
- const message = err instanceof Error ? err.message : String(err);
28
- throw new Error("GraphCalendarClient could not load '@microsoft/microsoft-graph-client'. Install it in the deployment " +
29
- `that polls Graph calendars (it is an optional peer dependency). Underlying error: ${message}`);
30
- }
31
- };
32
- /** @deprecated Use {@link DefaultGraphCalendarModuleLoader}. */
33
- export const defaultGraphCalendarModuleLoader = DefaultGraphCalendarModuleLoader;
34
- /**
35
- * A real {@link IGraphCalendarLike} over Microsoft Graph (`GET /users/{id}/calendarView/delta`).
36
- * The first poll requests a forward window (`startDateTime`..`endDateTime`) in UTC; later polls pass
37
- * the opaque cursor (`@odata.nextLink` within a poll, `@odata.deltaLink` between polls) straight back
38
- * to Graph. The constructed client is built once on first use and reused.
39
- */
40
- export class GraphCalendarClient {
41
- constructor(options) {
42
- this.options = options;
43
- this.loadModule = options.ModuleLoader ?? DefaultGraphCalendarModuleLoader;
44
- }
45
- /** @inheritdoc */
46
- async listEvents(userId, cursor) {
47
- const client = await this.client();
48
- // A cursor is a full Graph nextLink/deltaLink URL — request it verbatim. The first poll builds
49
- // a fresh calendarView/delta path with a UTC forward window and the UTC timezone preference.
50
- const path = cursor ?? this.firstPollPath(userId);
51
- const raw = await client.api(path).header('Prefer', 'outlook.timezone="UTC"').get();
52
- return this.toEventPage(raw);
53
- }
54
- /** Builds the first-poll `calendarView/delta` path with a UTC `[now, now+lookahead]` window. */
55
- firstPollPath(userId) {
56
- const now = this.options.Now ?? new Date();
57
- const lookaheadDays = this.options.LookaheadDays ?? DEFAULT_LOOKAHEAD_DAYS;
58
- const end = new Date(now.getTime() + lookaheadDays * MS_PER_DAY);
59
- const start = encodeURIComponent(now.toISOString());
60
- const finish = encodeURIComponent(end.toISOString());
61
- const id = encodeURIComponent(userId);
62
- return `/users/${id}/calendarView/delta?startDateTime=${start}&endDateTime=${finish}`;
63
- }
64
- /** Normalizes the raw Graph delta response to the seam's {@link GraphEventPage} shape. */
65
- toEventPage(raw) {
66
- const obj = (raw ?? {});
67
- const value = Array.isArray(obj.value) ? obj.value : [];
68
- const nextLink = readString(obj['@odata.nextLink']);
69
- const deltaLink = readString(obj['@odata.deltaLink']);
70
- return {
71
- value,
72
- ...(nextLink ? { nextLink } : {}),
73
- ...(deltaLink ? { deltaLink } : {}),
74
- };
75
- }
76
- /** Builds (once) + memoizes the authenticated Graph client. */
77
- client() {
78
- if (!this.clientPromise) {
79
- this.clientPromise = this.loadModule().then((mod) => mod.Client.init({
80
- authProvider: (done) => done(null, this.options.Credentials.AccessToken),
81
- }));
82
- }
83
- return this.clientPromise;
84
- }
85
- }
86
- /** Lazily loads + memoizes `googleapis`; throws a clear install hint on failure. */
87
- export const DefaultGoogleApisModuleLoader = async () => {
88
- try {
89
- const mod = await import('googleapis');
90
- const resolved = unwrap(mod);
91
- if (!isGoogleModule(resolved)) {
92
- throw new Error('the googleapis module did not export a google.calendar factory');
93
- }
94
- return resolved;
95
- }
96
- catch (err) {
97
- const message = err instanceof Error ? err.message : String(err);
98
- throw new Error("GoogleCalendarClient could not load 'googleapis'. Install it in the deployment that polls Google " +
99
- `calendars (it is an optional peer dependency). Underlying error: ${message}`);
100
- }
101
- };
102
- /** @deprecated Use {@link DefaultGoogleApisModuleLoader}. */
103
- export const defaultGoogleApisModuleLoader = DefaultGoogleApisModuleLoader;
104
- /**
105
- * A real {@link IGoogleCalendarLike} over `calendar.events.list`. The first poll requests a forward
106
- * window (`timeMin`..`timeMax`, `singleEvents`, ordered) so Google returns an initial `nextSyncToken`;
107
- * later polls pass the `syncToken` (between polls) or `pageToken` (within a poll) verbatim. The
108
- * constructed client is built once on first use and reused.
109
- */
110
- export class GoogleCalendarClient {
111
- constructor(options) {
112
- this.options = options;
113
- this.loadModule = options.ModuleLoader ?? DefaultGoogleApisModuleLoader;
114
- }
115
- /** @inheritdoc */
116
- async listEvents(args) {
117
- const client = await this.client();
118
- const response = await client.events.list(this.buildListParams(args));
119
- return this.toEventPage(response?.data);
120
- }
121
- /**
122
- * Builds `events.list` params. A `syncToken`/`pageToken` poll passes only the token (Google
123
- * rejects window params alongside a sync token); a fresh poll sends the forward window + the
124
- * `singleEvents`/`orderBy` flags that make Google issue an initial `nextSyncToken`.
125
- */
126
- buildListParams(args) {
127
- const base = { calendarId: args.calendarId };
128
- if (args.pageToken) {
129
- return { ...base, pageToken: args.pageToken };
130
- }
131
- if (args.syncToken) {
132
- return { ...base, syncToken: args.syncToken };
133
- }
134
- const now = this.options.Now ?? new Date();
135
- const lookaheadDays = this.options.LookaheadDays ?? DEFAULT_LOOKAHEAD_DAYS;
136
- return {
137
- ...base,
138
- timeMin: now.toISOString(),
139
- timeMax: new Date(now.getTime() + lookaheadDays * MS_PER_DAY).toISOString(),
140
- singleEvents: true,
141
- orderBy: 'startTime',
142
- };
143
- }
144
- /** Normalizes the raw `events.list` data to the seam's {@link GoogleEventPage} shape. */
145
- toEventPage(data) {
146
- const obj = (data ?? {});
147
- const items = Array.isArray(obj.items) ? obj.items : [];
148
- const nextPageToken = readString(obj.nextPageToken);
149
- const nextSyncToken = readString(obj.nextSyncToken);
150
- return {
151
- items,
152
- ...(nextPageToken ? { nextPageToken } : {}),
153
- ...(nextSyncToken ? { nextSyncToken } : {}),
154
- };
155
- }
156
- /** Builds (once) + memoizes the Google Calendar client. */
157
- client() {
158
- if (!this.clientPromise) {
159
- this.clientPromise = this.loadModule().then((mod) => mod.google.calendar({ version: 'v3', auth: this.options.Auth }));
160
- }
161
- return this.clientPromise;
162
- }
163
- }
164
- // ──────────────────────────────────────────────────────────────────────────────
165
- // Shared helpers.
166
- // ──────────────────────────────────────────────────────────────────────────────
167
- /** Forward-window default (days) shared by both first-poll path builders. */
168
- const DEFAULT_LOOKAHEAD_DAYS = 30;
169
- const MS_PER_DAY = 24 * 60 * 60 * 1000;
170
- /** Returns a non-empty trimmed string, or `undefined` for anything else. */
171
- function readString(value) {
172
- return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
173
- }
174
- /** Unwraps a module from CJS/ESM interop (`module` or `module.default`). */
175
- function unwrap(mod) {
176
- if (mod && typeof mod === 'object' && 'default' in mod) {
177
- const inner = mod.default;
178
- if (inner && typeof inner === 'object') {
179
- return inner;
180
- }
181
- }
182
- return mod;
183
- }
184
- /** Structural guard: exposes `Client.init`. */
185
- function isGraphModule(value) {
186
- const client = value?.Client;
187
- return client != null && typeof client.init === 'function';
188
- }
189
- /** Structural guard: exposes `google.calendar`. */
190
- function isGoogleModule(value) {
191
- const google = value?.google;
192
- return google != null && typeof google.calendar === 'function';
193
- }
194
- //# sourceMappingURL=calendar-clients.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calendar-clients.js","sourceRoot":"","sources":["../src/calendar-clients.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkEH,2GAA2G;AAC3G,MAAM,CAAC,MAAM,gCAAgC,GAA8B,KAAK,IAAI,EAAE;IAClF,IAAI,CAAC;QACD,MAAM,GAAG,GAAY,MAAM,MAAM,CAAC,mCAAmC,CAAC,CAAC;QACvE,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;QACzG,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,MAAM,IAAI,KAAK,CACX,uGAAuG;YACnG,qFA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