@spine-event-engine/ai 0.0.0-stage → 2.0.0-snapshot.24

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.
Files changed (53) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +73 -2
  3. package/REFERENCE.md +238 -0
  4. package/dist/index.d.ts +31 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +26 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/internal/contracts.d.ts +648 -0
  9. package/dist/internal/contracts.d.ts.map +1 -0
  10. package/dist/internal/contracts.js +15 -0
  11. package/dist/internal/contracts.js.map +1 -0
  12. package/dist/internal/decision.d.ts +54 -0
  13. package/dist/internal/decision.d.ts.map +1 -0
  14. package/dist/internal/decision.js +197 -0
  15. package/dist/internal/decision.js.map +1 -0
  16. package/dist/internal/execution.d.ts +309 -0
  17. package/dist/internal/execution.d.ts.map +1 -0
  18. package/dist/internal/execution.js +143 -0
  19. package/dist/internal/execution.js.map +1 -0
  20. package/dist/internal/mcp-protocol.d.ts +282 -0
  21. package/dist/internal/mcp-protocol.d.ts.map +1 -0
  22. package/dist/internal/mcp-protocol.js +32 -0
  23. package/dist/internal/mcp-protocol.js.map +1 -0
  24. package/dist/internal/mcp.d.ts +36 -0
  25. package/dist/internal/mcp.d.ts.map +1 -0
  26. package/dist/internal/mcp.js +144 -0
  27. package/dist/internal/mcp.js.map +1 -0
  28. package/dist/internal/model.d.ts +103 -0
  29. package/dist/internal/model.d.ts.map +1 -0
  30. package/dist/internal/model.js +292 -0
  31. package/dist/internal/model.js.map +1 -0
  32. package/dist/internal/registration.d.ts +102 -0
  33. package/dist/internal/registration.d.ts.map +1 -0
  34. package/dist/internal/registration.js +65 -0
  35. package/dist/internal/registration.js.map +1 -0
  36. package/dist/internal/registry.d.ts +102 -0
  37. package/dist/internal/registry.d.ts.map +1 -0
  38. package/dist/internal/registry.js +250 -0
  39. package/dist/internal/registry.js.map +1 -0
  40. package/dist/internal/schema.d.ts +70 -0
  41. package/dist/internal/schema.d.ts.map +1 -0
  42. package/dist/internal/schema.js +329 -0
  43. package/dist/internal/schema.js.map +1 -0
  44. package/dist/spi/adapter.d.ts +11 -0
  45. package/dist/spi/adapter.d.ts.map +1 -0
  46. package/dist/spi/adapter.js +21 -0
  47. package/dist/spi/adapter.js.map +1 -0
  48. package/dist/spi/runtime.d.ts +10 -0
  49. package/dist/spi/runtime.d.ts.map +1 -0
  50. package/dist/spi/runtime.js +20 -0
  51. package/dist/spi/runtime.js.map +1 -0
  52. package/dist/tsconfig.tsbuildinfo +1 -0
  53. package/package.json +37 -3
@@ -0,0 +1,102 @@
1
+ import type { MessageSchema } from "@spine-event-engine/core";
2
+ import type { ModelRef } from "@spine-event-engine/proto/agent";
3
+ import type { AiRegistryOptions } from "./contracts.js";
4
+ import type { AiModel } from "./model.js";
5
+ import { type AiBackendRegistration } from "./registration.js";
6
+ import { type McpServerRegistration } from "./mcp.js";
7
+ /**
8
+ * Application registry with fixed build policy and append-only deployments.
9
+ */
10
+ export declare class AiRegistry {
11
+ /**
12
+ * Creates a registry only through the factory.
13
+ */
14
+ private constructor();
15
+ /**
16
+ * Creates a validated application registry.
17
+ *
18
+ * @param options Defaults, limits and queue bounds.
19
+ * @returns Registry with append-only deployments and build-time tool policy.
20
+ */
21
+ static create(options: AiRegistryOptions): AiRegistry;
22
+ /**
23
+ * Adds one unique adapter deployment, including after Bounded Context build.
24
+ *
25
+ * @param deployment Factory-created adapter registration.
26
+ * @returns This registry for configuration chaining.
27
+ */
28
+ register(deployment: AiBackendRegistration): this;
29
+ /**
30
+ * Registers one unique MCP server policy.
31
+ *
32
+ * @param server Factory-created MCP configuration.
33
+ * @returns This registry for configuration chaining.
34
+ */
35
+ registerTools(server: McpServerRegistration): this;
36
+ }
37
+ /**
38
+ * Sets registration to its immutable build state.
39
+ *
40
+ * @param registry Application configuration.
41
+ */
42
+ export declare const freezeRegistry: (registry: AiRegistry) => void;
43
+ /**
44
+ * Inputs for the per-kind selection precedence and repository allowlist.
45
+ */
46
+ export interface AiSelection {
47
+ /**
48
+ * Declared generation or decision kind.
49
+ */
50
+ readonly kind: "generation" | "decision";
51
+ /**
52
+ * Registered application capabilities considered for selection.
53
+ */
54
+ readonly models: readonly AiModel<MessageSchema, MessageSchema>[];
55
+ /**
56
+ * Explicit model selected for this Agent instance.
57
+ */
58
+ readonly instancePreference?: ModelRef;
59
+ /**
60
+ * Repository model preference for this kind.
61
+ */
62
+ readonly repositoryDefault?: ModelRef;
63
+ /**
64
+ * Bounded Context model preference for this kind.
65
+ */
66
+ readonly contextDefault?: ModelRef;
67
+ /**
68
+ * Repository allowlist of permitted deployment references.
69
+ */
70
+ readonly allowedModels?: readonly ModelRef[];
71
+ }
72
+ /**
73
+ * Resolves one deployment by Proto value and validates its capabilities.
74
+ *
75
+ * @param registry Configured application registry.
76
+ * @param selection Effective scope preferences and registered capabilities.
77
+ * @returns Registered deployment selected for this invocation.
78
+ */
79
+ export declare const selectDeployment: (registry: AiRegistry, selection: AiSelection) => AiBackendRegistration;
80
+ /**
81
+ * Returns frozen application options for internal runtime binding.
82
+ *
83
+ * @param registry Application registry.
84
+ * @returns Immutable configuration options.
85
+ */
86
+ export declare const registryOptions: (registry: AiRegistry) => Readonly<AiRegistryOptions>;
87
+ /**
88
+ * Finds a factory-created MCP registration by configured server ID.
89
+ *
90
+ * @param registry Application configuration.
91
+ * @param id Configured MCP server identifier.
92
+ * @returns Registered server, or absence when the ID is not configured.
93
+ */
94
+ export declare const mcpRegistration: (registry: AiRegistry, id: string) => McpServerRegistration | undefined;
95
+ /**
96
+ * Returns a frozen snapshot of configured MCP registrations.
97
+ *
98
+ * @param registry Application configuration.
99
+ * @returns Registrations in configuration order without the mutable registry map.
100
+ */
101
+ export declare const mcpRegistrations: (registry: AiRegistry) => readonly McpServerRegistration[];
102
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","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MG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,UAAU,EACpB,WAAW,WAAW,KACrB,qBA6BF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,UAAU,KAAG,QAAQ,CAAC,iBAAiB,CAEhF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,UAAU,EACpB,IAAI,MAAM,KACT,qBAAqB,GAAG,SAA0C,CAAC;AAEtE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,UAAU,KAAG,SAAS,qBAAqB,EAClC,CAAC"}
@@ -0,0 +1,250 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { isAiModel, modelRefKey, ModelRef as ModelRefFactory, positiveInteger } from "./model.js";
15
+ import { backendDefinition } from "./registration.js";
16
+ import { mcpDefinition } from "./mcp.js";
17
+ const registries = new WeakMap();
18
+ /**
19
+ * Copies only explicitly configured whole-signal ceilings.
20
+ *
21
+ * @param limits Caller-supplied limits.
22
+ * @returns Immutable invocation limits.
23
+ */
24
+ const copyInvocationLimits = (limits) => {
25
+ const candidate = limits;
26
+ if (typeof candidate !== "object" || candidate === null)
27
+ throw new TypeError("invocationLimits must be an object");
28
+ return Object.freeze({
29
+ ...(limits.operations === undefined
30
+ ? {}
31
+ : { operations: positiveInteger(limits.operations, "operations") }),
32
+ ...(limits.modelRequests === undefined
33
+ ? {}
34
+ : { modelRequests: positiveInteger(limits.modelRequests, "modelRequests") }),
35
+ ...(limits.toolCalls === undefined
36
+ ? {}
37
+ : { toolCalls: positiveInteger(limits.toolCalls, "toolCalls", true) }),
38
+ ...(limits.recordedReads === undefined
39
+ ? {}
40
+ : { recordedReads: positiveInteger(limits.recordedReads, "recordedReads", true) }),
41
+ ...(limits.deadlineMs === undefined
42
+ ? {}
43
+ : { deadlineMs: positiveInteger(limits.deadlineMs, "deadlineMs") }),
44
+ ...(limits.totalInputBytes === undefined
45
+ ? {}
46
+ : { totalInputBytes: positiveInteger(limits.totalInputBytes, "totalInputBytes") }),
47
+ ...(limits.totalOutputBytes === undefined
48
+ ? {}
49
+ : { totalOutputBytes: positiveInteger(limits.totalOutputBytes, "totalOutputBytes") }),
50
+ ...(limits.maxRecoveryBytes === undefined
51
+ ? {}
52
+ : { maxRecoveryBytes: positiveInteger(limits.maxRecoveryBytes, "maxRecoveryBytes") }),
53
+ });
54
+ };
55
+ /**
56
+ * Copies optional deployment defaults by Protobuf value.
57
+ *
58
+ * @param defaults Caller-supplied defaults.
59
+ * @returns Immutable references.
60
+ */
61
+ const copyDefaults = (defaults) => {
62
+ const candidate = defaults;
63
+ if (typeof candidate !== "object" || candidate === null)
64
+ throw new TypeError("defaultModels are required");
65
+ const copy = (ref) => {
66
+ const value = ModelRefFactory.of(ref.name?.value ?? "", ref.revision?.value ?? "");
67
+ Object.freeze(value.name);
68
+ Object.freeze(value.revision);
69
+ return Object.freeze(value);
70
+ };
71
+ return Object.freeze({
72
+ ...(defaults.generation ? { generation: copy(defaults.generation) } : {}),
73
+ ...(defaults.decision ? { decision: copy(defaults.decision) } : {}),
74
+ });
75
+ };
76
+ /**
77
+ * Validates and freezes the registry's explicitly configured controls.
78
+ *
79
+ * @param options Caller-supplied defaults and optional ceilings.
80
+ * @returns Immutable registry options.
81
+ */
82
+ const copyRegistryOptions = (options) => {
83
+ const suppliedLimits = options.invocationLimits;
84
+ if (suppliedLimits === null)
85
+ throw new TypeError("invocationLimits must be an object");
86
+ const copy = Object.freeze({
87
+ defaultModels: copyDefaults(options.defaultModels),
88
+ invocationLimits: copyInvocationLimits(options.invocationLimits ?? {}),
89
+ ...(options.concurrentOperations === undefined
90
+ ? {}
91
+ : {
92
+ concurrentOperations: positiveInteger(options.concurrentOperations, "concurrentOperations"),
93
+ }),
94
+ ...(options.queuedOperations === undefined
95
+ ? {}
96
+ : { queuedOperations: positiveInteger(options.queuedOperations, "queuedOperations", true) }),
97
+ ...(options.hookTimeoutMs === undefined
98
+ ? {}
99
+ : { hookTimeoutMs: positiveInteger(options.hookTimeoutMs, "hookTimeoutMs") }),
100
+ });
101
+ if (copy.hookTimeoutMs !== undefined &&
102
+ copy.invocationLimits.deadlineMs !== undefined &&
103
+ copy.hookTimeoutMs > copy.invocationLimits.deadlineMs)
104
+ throw new TypeError("hookTimeoutMs cannot exceed invocation deadlineMs");
105
+ return copy;
106
+ };
107
+ /**
108
+ * Retrieves active registry state without exposing it on the public class.
109
+ *
110
+ * @param registry Factory-created registry.
111
+ * @returns Internal mutable configuration state.
112
+ */
113
+ const state = (registry) => {
114
+ const found = registries.get(registry);
115
+ if (!found)
116
+ throw new TypeError("registry must come from AiRegistry.create");
117
+ return found;
118
+ };
119
+ /**
120
+ * Application registry with fixed build policy and append-only deployments.
121
+ */
122
+ export class AiRegistry {
123
+ /**
124
+ * Creates a registry only through the factory.
125
+ */
126
+ constructor() {
127
+ // Only create() may install the private registry state.
128
+ }
129
+ /**
130
+ * Creates a validated application registry.
131
+ *
132
+ * @param options Defaults, limits and queue bounds.
133
+ * @returns Registry with append-only deployments and build-time tool policy.
134
+ */
135
+ static create(options) {
136
+ const copy = copyRegistryOptions(options);
137
+ const registry = new AiRegistry();
138
+ registries.set(registry, {
139
+ options: copy,
140
+ backends: new Map(),
141
+ tools: new Map(),
142
+ frozen: false,
143
+ });
144
+ return registry;
145
+ }
146
+ /**
147
+ * Adds one unique adapter deployment, including after Bounded Context build.
148
+ *
149
+ * @param deployment Factory-created adapter registration.
150
+ * @returns This registry for configuration chaining.
151
+ */
152
+ register(deployment) {
153
+ const current = state(this);
154
+ const definition = backendDefinition(deployment);
155
+ const key = modelRefKey(definition.ref);
156
+ if (current.backends.has(key))
157
+ throw new TypeError("Duplicate deployment reference");
158
+ current.backends.set(key, deployment);
159
+ return this;
160
+ }
161
+ /**
162
+ * Registers one unique MCP server policy.
163
+ *
164
+ * @param server Factory-created MCP configuration.
165
+ * @returns This registry for configuration chaining.
166
+ */
167
+ registerTools(server) {
168
+ const current = state(this);
169
+ if (current.frozen)
170
+ throw new Error("AI registry is frozen");
171
+ const definition = mcpDefinition(server);
172
+ if (current.tools.has(definition.id))
173
+ throw new TypeError("Duplicate MCP server ID");
174
+ current.tools.set(definition.id, server);
175
+ return this;
176
+ }
177
+ }
178
+ /**
179
+ * Sets registration to its immutable build state.
180
+ *
181
+ * @param registry Application configuration.
182
+ */
183
+ export const freezeRegistry = (registry) => {
184
+ const current = state(registry);
185
+ for (const kind of ["generation", "decision"]) {
186
+ const ref = current.options.defaultModels[kind];
187
+ if (!ref)
188
+ continue;
189
+ const registration = current.backends.get(modelRefKey(ref));
190
+ if (registration?.kind !== kind)
191
+ throw new TypeError(`${kind} default lacks a compatible registered deployment`);
192
+ }
193
+ current.frozen = true;
194
+ };
195
+ /**
196
+ * Resolves one deployment by Proto value and validates its capabilities.
197
+ *
198
+ * @param registry Configured application registry.
199
+ * @param selection Effective scope preferences and registered capabilities.
200
+ * @returns Registered deployment selected for this invocation.
201
+ */
202
+ export const selectDeployment = (registry, selection) => {
203
+ const kind = selection.kind;
204
+ if (kind !== "generation" && kind !== "decision")
205
+ throw new TypeError("selection kind is unsupported");
206
+ const current = state(registry);
207
+ const ref = selection.instancePreference ??
208
+ selection.repositoryDefault ??
209
+ selection.contextDefault ??
210
+ current.options.defaultModels[selection.kind];
211
+ if (!ref)
212
+ throw new TypeError(`${selection.kind} has no deployment default`);
213
+ const key = modelRefKey(ref);
214
+ if (selection.allowedModels &&
215
+ !selection.allowedModels.some((allowed) => modelRefKey(allowed) === key))
216
+ throw new TypeError("Selected deployment is not allowed by repository");
217
+ const registered = current.backends.get(key);
218
+ if (registered?.kind !== selection.kind)
219
+ throw new TypeError("Selected deployment is not registered for this kind");
220
+ const models = selection.models.filter((model) => isAiModel(model) && model.definition.kind === selection.kind);
221
+ if (models.length === 0 ||
222
+ models.some((model) => !backendDefinition(registered).supports(model.definition)))
223
+ throw new TypeError("Selected deployment lacks a registered capability");
224
+ return registered;
225
+ };
226
+ /**
227
+ * Returns frozen application options for internal runtime binding.
228
+ *
229
+ * @param registry Application registry.
230
+ * @returns Immutable configuration options.
231
+ */
232
+ export const registryOptions = (registry) => {
233
+ return state(registry).options;
234
+ };
235
+ /**
236
+ * Finds a factory-created MCP registration by configured server ID.
237
+ *
238
+ * @param registry Application configuration.
239
+ * @param id Configured MCP server identifier.
240
+ * @returns Registered server, or absence when the ID is not configured.
241
+ */
242
+ export const mcpRegistration = (registry, id) => state(registry).tools.get(id);
243
+ /**
244
+ * Returns a frozen snapshot of configured MCP registrations.
245
+ *
246
+ * @param registry Application configuration.
247
+ * @returns Registrations in configuration order without the mutable registry map.
248
+ */
249
+ export const mcpRegistrations = (registry) => Object.freeze([...state(registry).tools.values()]);
250
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/internal/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,IAAI,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElG,OAAO,EAAE,iBAAiB,EAA8B,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,aAAa,EAA8B,MAAM,UAAU,CAAC;AAuBrE,MAAM,UAAU,GAAG,IAAI,OAAO,EAA6B,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,CAAC,MAA0B,EAAsB,EAAE;IAC9E,MAAM,SAAS,GA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CAAC,CAAC;IAC3E,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAoB,EAA+B,EAAE;IACnF,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;AACjC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,QAAoB,EACpB,EAAU,EACyB,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAoB,EAAoC,EAAE,CACzF,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,70 @@
1
+ import type { MessageShape } from "@bufbuild/protobuf";
2
+ import { type MessageSchema } from "@spine-event-engine/core";
3
+ import type { AiValidationIssue } from "./contracts.js";
4
+ /**
5
+ * Provider-neutral JSON schema for one supported Protobuf output.
6
+ */
7
+ export interface AiOutputSchema {
8
+ /**
9
+ * JSON object discriminator for a message output.
10
+ */
11
+ readonly type: "object";
12
+ /**
13
+ * JSON properties derived from the Protobuf descriptor.
14
+ */
15
+ readonly properties: Readonly<Record<string, unknown>>;
16
+ /**
17
+ * JSON properties that must be supplied for admission.
18
+ */
19
+ readonly required: readonly string[];
20
+ /**
21
+ * Rejects unknown JSON properties.
22
+ */
23
+ readonly additionalProperties: false;
24
+ /**
25
+ * Oneof constraints combined with field constraints.
26
+ */
27
+ readonly allOf?: readonly unknown[];
28
+ }
29
+ /**
30
+ * Either a locally admitted Protobuf value or precise validation issues.
31
+ *
32
+ * @typeParam S - Output message descriptor.
33
+ */
34
+ export type AiCandidateResult<S extends MessageSchema> = {
35
+ /**
36
+ * Indicates exact ProtoJSON and local validation succeeded.
37
+ */
38
+ readonly ok: true;
39
+ /**
40
+ * Validated generated Protobuf output.
41
+ */
42
+ readonly value: MessageShape<S>;
43
+ } | {
44
+ /**
45
+ * Indicates candidate admission failed.
46
+ */
47
+ readonly ok: false;
48
+ /**
49
+ * Local defects available for one bounded correction.
50
+ */
51
+ readonly issues: readonly AiValidationIssue[];
52
+ };
53
+ /**
54
+ * Creates provider-neutral schema directly from a generated descriptor.
55
+ *
56
+ * @param schema Generated Protobuf output schema.
57
+ * @returns Strict schema or a field-specific unsupported-feature error.
58
+ */
59
+ export declare const deriveOutputSchema: (schema: MessageSchema) => AiOutputSchema;
60
+ /**
61
+ * Parses exact ProtoJSON, then applies Spine constraints and application validation.
62
+ *
63
+ * @typeParam S - Output message descriptor.
64
+ * @param schema Generated output descriptor.
65
+ * @param text Exact provider candidate text.
66
+ * @param check Optional pure application validator.
67
+ * @returns Admitted value or bounded local issues for a correction.
68
+ */
69
+ export declare const parseCandidate: <S extends MessageSchema>(schema: S, text: string, check?: (value: MessageShape<S>) => readonly AiValidationIssue[]) => AiCandidateResult<S>;
70
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/internal/schema.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAA0B,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEvD;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,MA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