@mcp-abap-adt/http 19.0.0 → 19.2.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.
@@ -1,318 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InstancePool = exports.STATE_HANDLE_HEADER = exports.PoolClosedError = exports.BatchWithHandleError = exports.POOL_CLOSED_WORDS = exports.BATCH_WITH_HANDLE_WORDS = void 0;
4
- exports.handleOf = handleOf;
5
- exports.handleFrom = handleFrom;
6
- const auth_1 = require("@mcp-abap-adt/lib/auth");
7
- const state_1 = require("@mcp-abap-adt/lib/state");
8
- /** The `400` words of a batch carrying `state_handle`. */
9
- exports.BATCH_WITH_HANDLE_WORDS = 'a JSON-RPC batch cannot carry state_handle';
10
- /** The `503` words of a request after the shutdown began. */
11
- exports.POOL_CLOSED_WORDS = 'the server is shutting down';
12
- class BatchWithHandleError extends Error {
13
- constructor() {
14
- super(exports.BATCH_WITH_HANDLE_WORDS);
15
- this.name = 'BatchWithHandleError';
16
- }
17
- }
18
- exports.BatchWithHandleError = BatchWithHandleError;
19
- class PoolClosedError extends Error {
20
- constructor() {
21
- super(exports.POOL_CLOSED_WORDS);
22
- this.name = 'PoolClosedError';
23
- }
24
- }
25
- exports.PoolClosedError = PoolClosedError;
26
- /** The `state_handle` of a single `tools/call`; a batch carrying one is refused. */
27
- function handleOf(body) {
28
- const one = (m) => {
29
- const call = m;
30
- const handle = call?.params?.arguments?.state_handle;
31
- return call?.method === 'tools/call' && typeof handle === 'string'
32
- ? handle
33
- : undefined;
34
- };
35
- if (Array.isArray(body)) {
36
- if (body.some((m) => one(m) !== undefined))
37
- throw new BatchWithHandleError();
38
- return undefined;
39
- }
40
- return one(body);
41
- }
42
- /** The request header that carries the handle on Streamable HTTP. */
43
- exports.STATE_HANDLE_HEADER = 'x-mcp-state-handle';
44
- /**
45
- * The handle a request routes by: the `x-mcp-state-handle` header first, else
46
- * the `state_handle` of a single `tools/call` (`handleOf`; the debugger tools
47
- * keep their argument). A JSON-RPC batch carrying `state_handle` is refused
48
- * whether or not the header is there. A header that is not one non-empty
49
- * value is absent.
50
- */
51
- function handleFrom(headers, body) {
52
- const argument = handleOf(body);
53
- const header = headers[exports.STATE_HANDLE_HEADER];
54
- return typeof header === 'string' && header !== '' ? header : argument;
55
- }
56
- /**
57
- * What a failed undo is reported as: the state's own words of what it could
58
- * not undo (`StateCleanupError.failures`, the parts' fixed words), else what
59
- * the failure reader makes of it, else its class — never a thrown message.
60
- */
61
- const failureWordsOf = (e) => {
62
- const failures = ownFailures(e);
63
- if (failures !== undefined)
64
- return failures.join('; ');
65
- return (0, auth_1.failureOf)(e)?.message ?? (0, auth_1.errorClassOf)(e);
66
- };
67
- function ownFailures(e) {
68
- if (e === null || typeof e !== 'object')
69
- return undefined;
70
- try {
71
- const descriptor = Object.getOwnPropertyDescriptor(e, 'failures');
72
- const value = descriptor && 'value' in descriptor ? descriptor.value : undefined;
73
- return Array.isArray(value) && value.every((f) => typeof f === 'string')
74
- ? value
75
- : undefined;
76
- }
77
- catch {
78
- return undefined;
79
- }
80
- }
81
- class InstancePool {
82
- held = new Map();
83
- /** handle → entry, kept in step with each instance's handle (`onChange`). */
84
- index = new Map();
85
- /** Requests working on an instance; no entry for an instance nobody works on. */
86
- busy = new Map();
87
- subscribed = new WeakSet();
88
- evicting = new Map();
89
- /** Disposal failed: the message. */
90
- failed = new Map();
91
- /** Disposal failed or still finishing: owned for shutdown. */
92
- retained = new Set();
93
- active = new Set();
94
- admitting = true;
95
- /** Instances whose terminal close ran: they left the pool for good. */
96
- closed = new WeakSet();
97
- /**
98
- * What a failure is named by: an ordinal per instance. Never the handle — it
99
- * is a bearer secret, and these lines reach the log at shutdown.
100
- */
101
- ordinals = new WeakMap();
102
- nextOrdinal = 1;
103
- nameOf(instance) {
104
- let n = this.ordinals.get(instance);
105
- if (n === undefined) {
106
- n = this.nextOrdinal++;
107
- this.ordinals.set(instance, n);
108
- }
109
- return `instance ${n}`;
110
- }
111
- size() {
112
- return this.held.size;
113
- }
114
- byHandle(handle) {
115
- const entry = this.index.get(handle);
116
- // The index follows rotation; the check keeps a stale key from ever routing.
117
- return entry && entry.instance.stateHandle === handle ? entry : undefined;
118
- }
119
- keep(instance) {
120
- if (this.held.has(instance))
121
- return;
122
- const entry = {
123
- instance,
124
- handle: instance.stateHandle,
125
- tail: Promise.resolve(),
126
- unsubscribe: () => { },
127
- };
128
- this.held.set(instance, entry);
129
- this.index.set(entry.handle, entry);
130
- entry.unsubscribe = instance.state.onChange(() => this.rekey(entry));
131
- }
132
- /** The handle rotated (a complete stop): the old one stops routing at once. */
133
- rekey(entry) {
134
- const now = entry.instance.stateHandle;
135
- if (now === entry.handle)
136
- return;
137
- if (this.index.get(entry.handle) === entry)
138
- this.index.delete(entry.handle);
139
- entry.handle = now;
140
- this.index.set(now, entry);
141
- }
142
- drop(instance) {
143
- const entry = this.held.get(instance);
144
- if (!entry)
145
- return;
146
- entry.unsubscribe();
147
- this.held.delete(instance);
148
- if (this.index.get(entry.handle) === entry)
149
- this.index.delete(entry.handle);
150
- }
151
- /**
152
- * `refuseUnknown` (a tool call): a handle that names no instance in the
153
- * pool — never one, or one whose state ended — is refused here with
154
- * `StateUnavailableError`, before any instance is made or anything logs
155
- * on; the answer is the same whatever the handle was. Without a handle, a
156
- * new instance as ever.
157
- */
158
- async serve(request, create, work) {
159
- if (!this.admitting)
160
- throw new PoolClosedError();
161
- const run = this.route(request, create, work);
162
- this.active.add(run);
163
- try {
164
- await run;
165
- }
166
- finally {
167
- this.active.delete(run);
168
- }
169
- }
170
- route(request, create, work) {
171
- const entry = request.handle ? this.byHandle(request.handle) : undefined;
172
- // The handle is a bearer secret: it reaches its instance whoever sends it.
173
- // An unknown handle on a tool call is not available, answered here; on any
174
- // other request (initialize, a list) it gets a new instance, which logs on
175
- // nowhere until a tool call.
176
- if (!entry) {
177
- if (request.handle && request.refuseUnknown)
178
- return Promise.reject(new state_1.StateUnavailableError());
179
- return this.run(create(), work);
180
- }
181
- const turn = entry.tail.then(() =>
182
- // Revalidate: the instance may have left the pool, be leaving it, or
183
- // have rotated its handle while this request waited.
184
- this.held.get(entry.instance) === entry &&
185
- !this.evicting.has(entry.instance) &&
186
- entry.instance.stateHandle === request.handle
187
- ? this.run(entry.instance, work)
188
- : request.refuseUnknown
189
- ? Promise.reject(new state_1.StateUnavailableError())
190
- : this.run(create(), work));
191
- entry.tail = turn.catch(() => undefined);
192
- return turn;
193
- }
194
- async run(instance, work) {
195
- if (!this.subscribed.has(instance)) {
196
- this.subscribed.add(instance);
197
- instance.state.onEmpty(() => {
198
- if (!this.busy.get(instance))
199
- void this.evict(instance);
200
- });
201
- }
202
- this.busy.set(instance, (this.busy.get(instance) ?? 0) + 1);
203
- try {
204
- await work(instance);
205
- }
206
- finally {
207
- const left = (this.busy.get(instance) ?? 1) - 1;
208
- if (left > 0)
209
- this.busy.set(instance, left);
210
- else
211
- this.busy.delete(instance);
212
- await this.settle(instance);
213
- }
214
- }
215
- /** After a request: what holds state is kept; the rest is disposed. */
216
- async settle(instance) {
217
- if (instance.holdsState()) {
218
- this.keep(instance);
219
- return;
220
- }
221
- if (!this.busy.get(instance))
222
- await this.evict(instance);
223
- }
224
- /**
225
- * Once at a time per instance: dispose it. It leaves the pool only when it
226
- * holds nothing afterwards — an asynchronous part may finish later, and
227
- * `onEmpty` calls this again then. A disposal that fails keeps the instance,
228
- * fresh or held, for a retry. The guard is set before disposing, so a part
229
- * that empties synchronously inside dispose() re-enters harmlessly.
230
- */
231
- evict(instance) {
232
- const running = this.evicting.get(instance);
233
- if (running)
234
- return running;
235
- let done;
236
- const eviction = new Promise((resolve) => {
237
- done = resolve;
238
- });
239
- this.evicting.set(instance, eviction);
240
- void (async () => {
241
- try {
242
- await instance.dispose();
243
- this.failed.delete(instance);
244
- if (!instance.holdsState()) {
245
- this.drop(instance);
246
- this.retained.delete(instance);
247
- // It left the pool: its connections end with a logoff.
248
- await this.terminalClose(instance);
249
- }
250
- else {
251
- this.retained.add(instance); // still finishing: owned until it empties
252
- }
253
- }
254
- catch (e) {
255
- this.failed.set(instance, `${this.nameOf(instance)}: ${failureWordsOf(e)}`);
256
- this.retained.add(instance); // fresh or held: kept for shutdown's retry
257
- if (!instance.holdsState()) {
258
- // Nothing left to route to: out of the index and the count; only
259
- // `retained` keeps it, for the retry.
260
- this.drop(instance);
261
- }
262
- }
263
- finally {
264
- this.evicting.delete(instance);
265
- done();
266
- }
267
- })();
268
- return eviction;
269
- }
270
- /** The terminal close of an instance leaving the pool, once. */
271
- async terminalClose(instance) {
272
- if (this.closed.has(instance))
273
- return;
274
- this.closed.add(instance);
275
- await instance.terminalClose?.();
276
- }
277
- /** Stops admission (shutdown, in the latch's tick): every later request is `503`. */
278
- stopAdmitting() {
279
- this.admitting = false;
280
- }
281
- /**
282
- * Stop admission; let running requests and disposals finish; dispose what is
283
- * held or retained; wait until each has settled (an asynchronous part
284
- * finishes when its last event arrives — no timer); retry once what still
285
- * holds; report what is still left. Every instance it owned then leaves the
286
- * pool through its terminal close — its connections closed with a logoff
287
- * whatever its undo answered.
288
- */
289
- async shutdown() {
290
- this.admitting = false;
291
- await Promise.allSettled([...this.active]);
292
- await Promise.allSettled([...this.evicting.values()]);
293
- const owned = [...new Set([...this.held.keys(), ...this.retained])];
294
- for (const instance of owned)
295
- await this.evict(instance);
296
- // Every instance settles first — a disposal that threw may still have
297
- // cleanup finishing on its own.
298
- await Promise.allSettled(owned.map((i) => i.state.settled()));
299
- for (const instance of owned) {
300
- // Clean: nothing held and no failure left (a later eviction cleared it).
301
- if (!instance.holdsState() && !this.failed.has(instance))
302
- continue;
303
- this.failed.delete(instance);
304
- // Still held, or a disposal that threw: once more, and what that leaves is reported.
305
- await this.evict(instance);
306
- await instance.state.settled();
307
- if (instance.holdsState() && !this.failed.has(instance)) {
308
- const left = instance.state.failures().join('; ');
309
- this.failed.set(instance, `${this.nameOf(instance)}: ${left || 'state is still held'}`);
310
- }
311
- }
312
- // Leaving for good: the logoffs are written whatever the undo answered.
313
- await Promise.all(owned.map((instance) => this.terminalClose(instance)));
314
- return [...this.failed.values()];
315
- }
316
- }
317
- exports.InstancePool = InstancePool;
318
- //# sourceMappingURL=InstancePool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InstancePool.js","sourceRoot":"","sources":["../src/InstancePool.ts"],"names":[],"mappings":";;;AAuEA,4BAcC;AAYD,gCAOC;AAhFD,iDAAiE;AACjE,mDAGiC;AAgBjC,0DAA0D;AAC7C,QAAA,uBAAuB,GAClC,4CAA4C,CAAC;AAE/C,6DAA6D;AAChD,QAAA,iBAAiB,GAAG,6BAA6B,CAAC;AAE/D,MAAa,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,+BAAuB,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC;AAED,MAAa,eAAgB,SAAQ,KAAK;IACxC;QACE,KAAK,CAAC,yBAAiB,CAAC,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAOD,oFAAoF;AACpF,SAAgB,QAAQ,CAAC,IAAa;IACpC,MAAM,GAAG,GAAG,CAAC,CAAU,EAAsB,EAAE;QAC7C,MAAM,IAAI,GAAG,CAAmC,CAAC;QACjD,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC;QACrD,OAAO,IAAI,EAAE,MAAM,KAAK,YAAY,IAAI,OAAO,MAAM,KAAK,QAAQ;YAChE,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC,CAAC;IACF,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK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;YAC7B,qFAAqF;YACrF,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC3B,MAAM,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YAC/B,IAAI,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACxD,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,QAAQ,EACR,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,qBAAqB,EAAE,CAC7D,CAAC;YACJ,CAAC;QACH,CAAC;QACD,wEAAwE;QACxE,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACzE,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACnC,CAAC;CACF;AAxPD,oCAwPC"}
@@ -1,160 +0,0 @@
1
- import type { TlsConfig } from '@mcp-abap-adt/lib/config';
2
- import type { IHttpApplication, RouteRegistrationOptions } from '@mcp-abap-adt/lib/embeddable';
3
- import { BaseMcpServer, type IBackgroundRuns } from '@mcp-abap-adt/lib/embeddable';
4
- import type { IHandlersRegistry } from '@mcp-abap-adt/lib/handlers';
5
- import { type StateLogger } from '@mcp-abap-adt/lib/state';
6
- import type { Logger } from '@mcp-abap-adt/logger';
7
- export interface StreamableHttpServerOptions {
8
- /**
9
- * The idle bound on held state, in minutes: each instance's state ends
10
- * after this long without a tool call. At least 30; default 30.
11
- */
12
- stateIdleMinutes?: number;
13
- /** Where the state's lifecycle lines go; default stderr, always on. */
14
- stateLogger?: StateLogger;
15
- /**
16
- * Batch mode: each pooled instance (`createPerRequestServer`) gets an
17
- * `InstanceBatch` of its own, created with these settings (the
18
- * launcher's). Absent: no instance has one, and the batch tools answer
19
- * `batch_mode_unavailable`.
20
- */
21
- batch?: {
22
- keepRawParts: boolean;
23
- };
24
- /**
25
- * Host to bind to (only used when no external app is provided)
26
- * @default "127.0.0.1"
27
- */
28
- host?: string;
29
- /**
30
- * Port to listen on (only used when no external app is provided)
31
- * @default 3000
32
- */
33
- port?: number;
34
- /**
35
- * Whether to return JSON responses (vs SSE streams)
36
- * @default true
37
- */
38
- enableJsonResponse?: boolean;
39
- /**
40
- * Path for the MCP endpoint
41
- * @default "/mcp/stream/http"
42
- */
43
- path?: string;
44
- /**
45
- * Logger instance
46
- */
47
- logger?: Logger;
48
- /**
49
- * Server version
50
- */
51
- version?: string;
52
- /**
53
- * External HTTP application to register routes on
54
- * When provided, start() will only register routes without creating a server
55
- * This enables integration with existing Express/CDS/CAP servers
56
- */
57
- app?: IHttpApplication;
58
- /**
59
- * TLS configuration for HTTPS support
60
- */
61
- tls?: TlsConfig;
62
- /** Allowed Host header values (DNS-rebinding protection; exact, incl. port) */
63
- allowedHosts?: string[];
64
- /** Allowed Origin header values (DNS-rebinding protection; exact, incl. scheme) */
65
- allowedOrigins?: string[];
66
- /** Enable DNS-rebinding protection (requires allowedHosts and/or allowedOrigins) */
67
- enableDnsRebindingProtection?: boolean;
68
- /**
69
- * Where background runs and their answers are kept, handed to every
70
- * instance (the launcher's `InMemoryBackgroundRuns` of
71
- * `@mcp-abap-adt/background-runs-memory`). Absent:
72
- * `background: true` is refused.
73
- */
74
- backgroundRuns?: IBackgroundRuns;
75
- }
76
- /**
77
- * The Streamable HTTP server. Each HTTP POST is an MCP session of its own, on
78
- * a new server instance or the pooled one its `state_handle` names.
79
- * Credentials come only from each request's `x-sap-*` headers, through
80
- * lib's `headerSource`: nothing is stored, shared or cached across requests,
81
- * except the connections held state opened. A request without them is
82
- * answered `400` (`ping` excepted), and so is one carrying
83
- * `x-mcp-destination` — destinations are core's (stdio).
84
- *
85
- * Supports two modes:
86
- * 1. Standalone mode: Creates its own Express server (when no app option provided)
87
- * 2. Embedded mode: Registers routes on external app (when app option provided)
88
- */
89
- export declare class StreamableHttpServer extends BaseMcpServer {
90
- private readonly handlersRegistry;
91
- private readonly host;
92
- private readonly port;
93
- private readonly enableJsonResponse;
94
- private readonly path;
95
- private readonly externalApp?;
96
- private readonly version;
97
- private standaloneServer?;
98
- /** The listener stopped, until its last connections are closed after the last step. */
99
- private stoppedListener?;
100
- private readonly tls?;
101
- private readonly allowedHosts?;
102
- private readonly allowedOrigins?;
103
- private readonly enableDnsRebindingProtection?;
104
- /** The instances that hold state between requests (spec D9). */
105
- private readonly pool;
106
- private readonly stateIdleMinutes?;
107
- private readonly stateLogger;
108
- private readonly backgroundRunsStore;
109
- private readonly batchSettings;
110
- constructor(handlersRegistry: IHandlersRegistry, opts?: StreamableHttpServerOptions);
111
- /**
112
- * Creates the request handler function
113
- * Can be used to register on external app or internal Express
114
- */
115
- private createRequestHandler;
116
- /**
117
- * Register routes on an external HTTP application
118
- * Use this when integrating with existing Express/CDS/CAP server
119
- *
120
- * @param app - External HTTP application (Express, CDS, etc.)
121
- * @param options - Route registration options
122
- */
123
- registerRoutes(app: IHttpApplication, _options?: RouteRegistrationOptions): void;
124
- /**
125
- * Get the configured endpoint path
126
- */
127
- getPath(): string;
128
- /**
129
- * Start the server
130
- *
131
- * In standalone mode (no external app): Creates Express server and starts listening
132
- * In embedded mode (external app provided): Only registers routes on external app
133
- */
134
- start(): Promise<void>;
135
- /**
136
- * The shutdown's first step, in the latch's tick: the pool stops
137
- * admitting — every later request is answered `503`.
138
- */
139
- beginShutdown(): void;
140
- /** Stops taking connections. Embedded on an external app there is no listener of its own. */
141
- stopListening(): void;
142
- /**
143
- * The launcher's shutdown, after the logoffs (lib's
144
- * `installTransportShutdown`), and `stop()`: nothing is answered any more —
145
- * the connections still open on the stopped listener (a request whose tool
146
- * was interrupted, a client's idle keep-alive) are closed, so none keeps
147
- * the process alive.
148
- */
149
- releaseConnections(): void;
150
- /**
151
- * For a host that stops the server itself (embedded): admission stops, the
152
- * listener closes, then the pool's shutdown (no timer). Rejects with what
153
- * could not be undone. A launcher's shutdown does not run this: it logs
154
- * every owned connection off at once and interrupts the running tools
155
- * (lib's `installTransportShutdown`).
156
- */
157
- stop(): Promise<void>;
158
- private createPerRequestServer;
159
- }
160
- //# sourceMappingURL=StreamableHttpServer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StreamableHttpServer.d.ts","sourceRoot":"","sources":["../src/StreamableHttpServer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAEV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEL,aAAa,EACb,KAAK,eAAe,EAErB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAepE,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAenD,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uEAAuE;IACvE,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;;OAKG;IACH,KAAK,CAAC,EAAE;QAAE,YAAY,EAAE,OAAO,CAAA;KAAE,CAAC;IAClC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAA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