@inhuman.tools/plexus-expectations 0.1.0 → 0.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.
Files changed (33) hide show
  1. package/package.json +4 -4
  2. package/dist/driver/PEWDriverConnection.d.ts +0 -139
  3. package/dist/driver/PEWDriverConnection.d.ts.map +0 -1
  4. package/dist/driver/PEWDriverConnection.js +0 -298
  5. package/dist/driver/PEWDriverConnection.js.map +0 -1
  6. package/dist/error-with-invariant.d.ts +0 -9
  7. package/dist/error-with-invariant.d.ts.map +0 -1
  8. package/dist/error-with-invariant.js +0 -12
  9. package/dist/error-with-invariant.js.map +0 -1
  10. package/dist/shared/attention.d.ts +0 -27
  11. package/dist/shared/attention.d.ts.map +0 -1
  12. package/dist/shared/attention.js +0 -116
  13. package/dist/shared/attention.js.map +0 -1
  14. package/dist/shared/models/ApprovableExpectation.d.ts +0 -15
  15. package/dist/shared/models/ApprovableExpectation.d.ts.map +0 -1
  16. package/dist/shared/models/ApprovableExpectation.js +0 -138
  17. package/dist/shared/models/ApprovableExpectation.js.map +0 -1
  18. package/dist/shared/models/IntrospectingPlexusModel.d.ts +0 -8
  19. package/dist/shared/models/IntrospectingPlexusModel.d.ts.map +0 -1
  20. package/dist/shared/models/IntrospectingPlexusModel.js +0 -48
  21. package/dist/shared/models/IntrospectingPlexusModel.js.map +0 -1
  22. package/dist/shared/models/ProgrammaticJob.d.ts +0 -6
  23. package/dist/shared/models/ProgrammaticJob.d.ts.map +0 -1
  24. package/dist/shared/models/ProgrammaticJob.js +0 -80
  25. package/dist/shared/models/ProgrammaticJob.js.map +0 -1
  26. package/dist/shared/models/WorkExpectationWithIntrospection.d.ts +0 -4
  27. package/dist/shared/models/WorkExpectationWithIntrospection.d.ts.map +0 -1
  28. package/dist/shared/models/WorkExpectationWithIntrospection.js +0 -28
  29. package/dist/shared/models/WorkExpectationWithIntrospection.js.map +0 -1
  30. package/dist/shared/resolution.d.ts +0 -39
  31. package/dist/shared/resolution.d.ts.map +0 -1
  32. package/dist/shared/resolution.js +0 -124
  33. package/dist/shared/resolution.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inhuman.tools/plexus-expectations",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Work graph: WorkExpectation (PEW), Job + honoring executor.",
5
5
  "license": "MIT",
6
6
  "author": "Merkle Bonsai",
@@ -37,7 +37,7 @@
37
37
  "zod": "^4.4.3",
38
38
  "tslib": "2.8.1",
39
39
  "xstate": "5.32.5",
40
- "@inhuman.tools/error-with-invariant": "^0.1.0"
40
+ "@inhuman.tools/error-with-invariant": "^0.2.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^24.0.0",
@@ -48,8 +48,8 @@
48
48
  "yjs": "13.6.33",
49
49
  "mobx": "6.16.1",
50
50
  "@here.build/plexus": "^0.9.6",
51
- "@-internal-/tsconfig": "0.0.0",
52
- "@-internal-/eslint-configs": "0.0.0"
51
+ "@-internal-/eslint-configs": "0.0.0",
52
+ "@-internal-/tsconfig": "0.0.0"
53
53
  },
54
54
  "repository": {
55
55
  "type": "git",
@@ -1,139 +0,0 @@
1
- import type { PlexusAwareness } from "@here.build/plexus";
2
- import type { ExpectationActor } from "./ExpectationActor.js";
3
- import { type Attention } from "../shared/attention.js";
4
- import type { AnyWorkExpectation, WorkExpectation } from "../shared/models/WorkExpectation.js";
5
- import type { ReadyState } from "../shared/types.js";
6
- /** Duck-typed — drivers may ship a different Zod major than this package. */
7
- export type ConfigurationSchema = {
8
- safeParse(data: unknown): {
9
- readonly success: true;
10
- readonly data: unknown;
11
- } | {
12
- readonly success: false;
13
- readonly error: {
14
- readonly issues: ReadonlyArray<{
15
- readonly message?: string;
16
- }>;
17
- };
18
- };
19
- };
20
- /** Process-local. Secrets are never a Plexus field. */
21
- export type ConnectionSecretsView = {
22
- readonly revision?: number;
23
- get(field: string): unknown | undefined;
24
- /** MCP env_* enumerates deposited fields. */
25
- all?(): Readonly<Record<string, unknown>> | undefined;
26
- /** Hosts that persist a refreshed session (reauth) implement this. */
27
- replace?(secrets: Readonly<Record<string, string>>): void;
28
- };
29
- /** Module-graph duplication breaks instanceof; the elevation gate checks this brand too. */
30
- export declare const PEW_DRIVER_CONNECTION_BRAND = "@inhuman.tools/plexus-expectations:PEWDriverConnection@1";
31
- /** A connection construction the driver already knows will work. */
32
- export type DriverOffer = {
33
- readonly name: string;
34
- readonly description: string;
35
- readonly live: boolean;
36
- readonly adoptable: boolean;
37
- readonly settings: Readonly<Record<string, unknown>>;
38
- };
39
- /**
40
- * Driver extras the orchestrator mirrors onto `spec.live`.
41
- * Core process facts live on `readyState` / `error` / `offers`.
42
- */
43
- export declare function extraLiveFromState(state: object): Record<string, unknown>;
44
- /**
45
- * The CLASS is the driver (one loaded module per driver name).
46
- * The INSTANCE is a live connection (one per connection id).
47
- *
48
- * CLAIM DOES NOT LIVE HERE. Which WorkExpectation classes this driver handles
49
- * lives on the advertised driver record (`can`): dynamically loaded code does
50
- * not get to declare its own authority.
51
- *
52
- * Live state is report only — no machinery branches on it. Instance bootstrap
53
- * truth is `bootstrapDone` / `bootstrapPending`. Drivers read {@link attention}
54
- * as the reduced token, never clientIds.
55
- *
56
- * YAML doors ({@link configurationSchema} / {@link secretsSchema}) parse
57
- * without `new`. Secrets stay a live view — the host may replace it (reauth).
58
- */
59
- export declare abstract class PEWDriverConnection<E extends AnyWorkExpectation = AnyWorkExpectation, C = Readonly<Record<string, unknown>>> implements AsyncDisposable {
60
- readonly connectionId: string;
61
- static readonly pewBrand: string;
62
- /**
63
- * YAML settings shape. Default is a passthrough record — subclasses replace
64
- * this with a real object schema (transforms included). First issue message
65
- * is what construct / parse throw.
66
- */
67
- static readonly configurationSchema: ConfigurationSchema;
68
- static readonly configurationLabel: string;
69
- static configurationError(message: string): string;
70
- /** YAML settings door. Does not construct an instance. */
71
- static parseConfiguration(settings?: unknown): unknown;
72
- static readonly secretsSchema: ConfigurationSchema;
73
- static secretsError(message: string): string;
74
- /** YAML secrets door. Does not construct an instance. */
75
- static parseSecrets(secrets?: unknown): unknown;
76
- /** Shared on the prototype chain — own extras per subclass. */
77
- static readonly state: Record<string, unknown>;
78
- static readonly offers: readonly DriverOffer[];
79
- /** Kernel-plane occupancy hub. Orchestrator assignment is own-per-class. */
80
- static awareness: PlexusAwareness | undefined;
81
- static driverName: string;
82
- /**
83
- * A getter, not `@computed` — MobX: the decorator's initializer pins to the
84
- * declaring class, so subclasses would share one computed.
85
- */
86
- static get attention(): Attention;
87
- accessor readyState: ReadyState;
88
- accessor error: string;
89
- /**
90
- * MobX: shallow — extras (models, tools, account) are replaced wholesale.
91
- * Override the accessor with a wider literal to add driver facts.
92
- */
93
- accessor state: Record<string, unknown>;
94
- accessor awareness: PlexusAwareness | undefined;
95
- get attention(): Attention;
96
- constructor(connectionId: string, settings?: unknown, secrets?: ConnectionSecretsView | Readonly<Record<string, unknown>>);
97
- readonly settings: C;
98
- /** Live view. The host may replace it (reauth). */
99
- secrets: ConnectionSecretsView;
100
- /**
101
- * Host binds the disk writer for this connection's settings bag.
102
- * Parsed settings stay readonly; a driver that learns a value overrides this.
103
- */
104
- bindSettingsWriter(_write: (patch: Readonly<Record<string, unknown>>) => void): void;
105
- abstract bootstrap(): Promise<void>;
106
- bootstrapDone: boolean;
107
- bootstrapPending: Promise<void> | null;
108
- /** `resolve()` threw — the connection is broken, not the work. */
109
- broken: boolean;
110
- /** Concurrent callers share one promise. Async settlement is its own MobX action. */
111
- ensureBootstrapStarted(): Promise<void>;
112
- failReady(error: unknown): void;
113
- protected abstract resolve(expectation: E): ExpectationActor<E>;
114
- /** Nothing in PEW calls this; hosts or tests may. */
115
- [Symbol.asyncDispose](): Promise<void>;
116
- private readonly actors;
117
- private readonly liveActors;
118
- has(expectation: WorkExpectation): boolean;
119
- resolveExpectation<T extends AnyWorkExpectation>(expectation: T): ExpectationActor<T>;
120
- release(expectation: WorkExpectation): void;
121
- /**
122
- * Logout/drop aborts interned work. Not park. Subclasses abort `#inflight`.
123
- */
124
- abortOnDrop(reason: unknown): void;
125
- /**
126
- * Honor one demand.
127
- * `resolve()` throwing is a broken connection, not a failed expectation.
128
- */
129
- handle(expectation: WorkExpectation): void;
130
- }
131
- /**
132
- * A concrete `PEWDriverConnection` subclass — constructable, not abstract.
133
- * `loadDriverModule` returns `unknown`; {@link isDriverConnectionClass} is the gate.
134
- */
135
- export type DriverConnectionClass = {
136
- [K in keyof typeof PEWDriverConnection]: (typeof PEWDriverConnection)[K];
137
- } & (new (...args: ConstructorParameters<typeof PEWDriverConnection>) => PEWDriverConnection);
138
- export declare function isDriverConnectionClass(value: unknown): value is DriverConnectionClass;
139
- //# sourceMappingURL=PEWDriverConnection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PEWDriverConnection.d.ts","sourceRoot":"","sources":["../../src/driver/PEWDriverConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC/F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,6EAA6E;AAC7E,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,CACP,IAAI,EAAE,OAAO,GAEX;QAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;KAAE,GAClD;QAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE;YAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;gBAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAA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CAAC;CACzE,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,mBAAmB,CAAC,KAAK,mBAAmB,CAAC,CAAC;AAE9F,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAOtF"}
@@ -1,298 +0,0 @@
1
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
- var useValue = arguments.length > 2;
3
- for (var i = 0; i < initializers.length; i++) {
4
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
- }
6
- return useValue ? value : void 0;
7
- };
8
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
- var _, done = false;
14
- for (var i = decorators.length - 1; i >= 0; i--) {
15
- var context = {};
16
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
- if (kind === "accessor") {
21
- if (result === void 0) continue;
22
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
- if (_ = accept(result.get)) descriptor.get = _;
24
- if (_ = accept(result.set)) descriptor.set = _;
25
- if (_ = accept(result.init)) initializers.unshift(_);
26
- }
27
- else if (_ = accept(result)) {
28
- if (kind === "field") initializers.unshift(_);
29
- else descriptor[key] = _;
30
- }
31
- }
32
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
- done = true;
34
- };
35
- import { DefaultedWeakMap } from "@here.build/collections";
36
- import { action, computed, observable, toJS } from "mobx";
37
- import { pewConfigurationSchema, pewSecretsSchema } from "../schemas/connection.js";
38
- import { attentionOf } from "../shared/attention.js";
39
- const EMPTY_SECRETS = { get: () => undefined };
40
- /** Module-graph duplication breaks instanceof; the elevation gate checks this brand too. */
41
- // eslint-disable-next-line no-secrets/no-secrets -- package identity tag, not a secret
42
- export const PEW_DRIVER_CONNECTION_BRAND = "@inhuman.tools/plexus-expectations:PEWDriverConnection@1";
43
- /**
44
- * Driver extras the orchestrator mirrors onto `spec.live`.
45
- * Core process facts live on `readyState` / `error` / `offers`.
46
- */
47
- export function extraLiveFromState(state) {
48
- const extra = {};
49
- for (const [key, value] of Object.entries(state)) {
50
- if (value === undefined)
51
- continue;
52
- extra[key] = toJS(value);
53
- }
54
- return extra;
55
- }
56
- /**
57
- * The CLASS is the driver (one loaded module per driver name).
58
- * The INSTANCE is a live connection (one per connection id).
59
- *
60
- * CLAIM DOES NOT LIVE HERE. Which WorkExpectation classes this driver handles
61
- * lives on the advertised driver record (`can`): dynamically loaded code does
62
- * not get to declare its own authority.
63
- *
64
- * Live state is report only — no machinery branches on it. Instance bootstrap
65
- * truth is `bootstrapDone` / `bootstrapPending`. Drivers read {@link attention}
66
- * as the reduced token, never clientIds.
67
- *
68
- * YAML doors ({@link configurationSchema} / {@link secretsSchema}) parse
69
- * without `new`. Secrets stay a live view — the host may replace it (reauth).
70
- */
71
- let PEWDriverConnection = (() => {
72
- var _a, _b;
73
- let _instanceExtraInitializers = [];
74
- let _readyState_decorators;
75
- let _readyState_initializers = [];
76
- let _readyState_extraInitializers = [];
77
- let _error_decorators;
78
- let _error_initializers = [];
79
- let _error_extraInitializers = [];
80
- let _state_decorators;
81
- let _state_initializers = [];
82
- let _state_extraInitializers = [];
83
- let _awareness_decorators;
84
- let _awareness_initializers = [];
85
- let _awareness_extraInitializers = [];
86
- let _get_attention_decorators;
87
- let _ensureBootstrapStarted_decorators;
88
- let _failReady_decorators;
89
- return class PEWDriverConnection {
90
- static {
91
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
92
- __esDecorate(this, null, _readyState_decorators, { kind: "accessor", name: "readyState", static: false, private: false, access: { has: obj => "readyState" in obj, get: obj => obj.readyState, set: (obj, value) => { obj.readyState = value; } }, metadata: _metadata }, _readyState_initializers, _readyState_extraInitializers);
93
- __esDecorate(this, null, _error_decorators, { kind: "accessor", name: "error", static: false, private: false, access: { has: obj => "error" in obj, get: obj => obj.error, set: (obj, value) => { obj.error = value; } }, metadata: _metadata }, _error_initializers, _error_extraInitializers);
94
- __esDecorate(this, null, _state_decorators, { kind: "accessor", name: "state", static: false, private: false, access: { has: obj => "state" in obj, get: obj => obj.state, set: (obj, value) => { obj.state = value; } }, metadata: _metadata }, _state_initializers, _state_extraInitializers);
95
- __esDecorate(this, null, _awareness_decorators, { kind: "accessor", name: "awareness", static: false, private: false, access: { has: obj => "awareness" in obj, get: obj => obj.awareness, set: (obj, value) => { obj.awareness = value; } }, metadata: _metadata }, _awareness_initializers, _awareness_extraInitializers);
96
- __esDecorate(this, null, _get_attention_decorators, { kind: "getter", name: "attention", static: false, private: false, access: { has: obj => "attention" in obj, get: obj => obj.attention }, metadata: _metadata }, null, _instanceExtraInitializers);
97
- __esDecorate(this, null, _ensureBootstrapStarted_decorators, { kind: "method", name: "ensureBootstrapStarted", static: false, private: false, access: { has: obj => "ensureBootstrapStarted" in obj, get: obj => obj.ensureBootstrapStarted }, metadata: _metadata }, null, _instanceExtraInitializers);
98
- __esDecorate(this, null, _failReady_decorators, { kind: "method", name: "failReady", static: false, private: false, access: { has: obj => "failReady" in obj, get: obj => obj.failReady }, metadata: _metadata }, null, _instanceExtraInitializers);
99
- if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
100
- }
101
- connectionId = __runInitializers(this, _instanceExtraInitializers);
102
- // ── driver side (the CLASS is the driver) ─────────────────────────────
103
- static pewBrand = PEW_DRIVER_CONNECTION_BRAND;
104
- /**
105
- * YAML settings shape. Default is a passthrough record — subclasses replace
106
- * this with a real object schema (transforms included). First issue message
107
- * is what construct / parse throw.
108
- */
109
- static configurationSchema = pewConfigurationSchema;
110
- static configurationLabel = "";
111
- static configurationError(message) {
112
- const label = this.configurationLabel.trim();
113
- return label === "" ? `connection config invalid: ${message}` : `${label} connection config invalid: ${message}`;
114
- }
115
- /** YAML settings door. Does not construct an instance. */
116
- static parseConfiguration(settings = {}) {
117
- const result = this.configurationSchema.safeParse(settings ?? {});
118
- if (result.success)
119
- return result.data;
120
- const message = result.error.issues[0]?.message ?? "invalid";
121
- throw new Error(this.configurationError(message));
122
- }
123
- static secretsSchema = pewSecretsSchema;
124
- static secretsError(message) {
125
- const label = this.configurationLabel.trim();
126
- return label === "" ? `connection secrets invalid: ${message}` : `${label} connection secrets invalid: ${message}`;
127
- }
128
- /** YAML secrets door. Does not construct an instance. */
129
- static parseSecrets(secrets = {}) {
130
- const result = this.secretsSchema.safeParse(secrets ?? {});
131
- if (result.success)
132
- return result.data;
133
- const message = result.error.issues[0]?.message ?? "invalid";
134
- throw new Error(this.secretsError(message));
135
- }
136
- /** Shared on the prototype chain — own extras per subclass. */
137
- static state = {};
138
- static offers = [];
139
- /** Kernel-plane occupancy hub. Orchestrator assignment is own-per-class. */
140
- static awareness;
141
- static driverName = "";
142
- /**
143
- * A getter, not `@computed` — MobX: the decorator's initializer pins to the
144
- * declaring class, so subclasses would share one computed.
145
- */
146
- static get attention() {
147
- const hub = this.awareness;
148
- const name = this.driverName;
149
- if (hub === undefined || name === "")
150
- return "none";
151
- return attentionOf(hub, { kind: "driver", name });
152
- }
153
- #readyState_accessor_storage = __runInitializers(this, _readyState_initializers, null);
154
- // ── connection side (the INSTANCE is the connection) ──────────────────
155
- get readyState() { return this.#readyState_accessor_storage; }
156
- set readyState(value) { this.#readyState_accessor_storage = value; }
157
- #error_accessor_storage = (__runInitializers(this, _readyState_extraInitializers), __runInitializers(this, _error_initializers, ""));
158
- get error() { return this.#error_accessor_storage; }
159
- set error(value) { this.#error_accessor_storage = value; }
160
- #state_accessor_storage = (__runInitializers(this, _error_extraInitializers), __runInitializers(this, _state_initializers, {}));
161
- /**
162
- * MobX: shallow — extras (models, tools, account) are replaced wholesale.
163
- * Override the accessor with a wider literal to add driver facts.
164
- */
165
- get state() { return this.#state_accessor_storage; }
166
- set state(value) { this.#state_accessor_storage = value; }
167
- #awareness_accessor_storage = (__runInitializers(this, _state_extraInitializers), __runInitializers(this, _awareness_initializers, undefined));
168
- get awareness() { return this.#awareness_accessor_storage; }
169
- set awareness(value) { this.#awareness_accessor_storage = value; }
170
- get attention() {
171
- const hub = this.awareness;
172
- if (hub === undefined)
173
- return "none";
174
- return attentionOf(hub, { kind: "connection", id: this.connectionId });
175
- }
176
- constructor(connectionId, settings = {}, secrets = EMPTY_SECRETS) {
177
- this.connectionId = connectionId;
178
- const cls = new.target;
179
- this.settings = cls.parseConfiguration(settings);
180
- const view = typeof secrets.get === "function"
181
- ? secrets
182
- : {
183
- get: (field) => secrets[field],
184
- all: () => secrets,
185
- };
186
- cls.parseSecrets(view.all?.() ?? {});
187
- this.secrets = view;
188
- }
189
- settings = __runInitializers(this, _awareness_extraInitializers);
190
- /** Live view. The host may replace it (reauth). */
191
- secrets;
192
- /**
193
- * Host binds the disk writer for this connection's settings bag.
194
- * Parsed settings stay readonly; a driver that learns a value overrides this.
195
- */
196
- bindSettingsWriter(_write) { }
197
- bootstrapDone = false;
198
- bootstrapPending = null;
199
- /** `resolve()` threw — the connection is broken, not the work. */
200
- broken = false;
201
- /** Concurrent callers share one promise. Async settlement is its own MobX action. */
202
- ensureBootstrapStarted() {
203
- if (this.bootstrapDone)
204
- return Promise.resolve();
205
- if (this.bootstrapPending)
206
- return this.bootstrapPending;
207
- this.readyState = "bootstrapping";
208
- this.error = "";
209
- this.bootstrapPending = this.bootstrap().then(action(() => {
210
- this.bootstrapDone = true;
211
- this.readyState = "ready";
212
- this.error = "";
213
- }), action((error) => {
214
- this.readyState = "failed";
215
- this.error = error instanceof Error ? error.message : String(error);
216
- throw error;
217
- }));
218
- return this.bootstrapPending;
219
- }
220
- failReady(error) {
221
- this.broken = true;
222
- this.readyState = "failed";
223
- this.error = error instanceof Error ? error.message : String(error);
224
- }
225
- /** Nothing in PEW calls this; hosts or tests may. */
226
- async [(_readyState_decorators = [observable], _error_decorators = [observable], _state_decorators = [(_a = observable).shallow.bind(_a)], _awareness_decorators = [(_b = observable).ref.bind(_b)], _get_attention_decorators = [computed], _ensureBootstrapStarted_decorators = [action], _failReady_decorators = [action], Symbol.asyncDispose)]() { }
227
- actors = new DefaultedWeakMap((expectation) => {
228
- const actor = this.resolve(expectation);
229
- this.liveActors.add(actor);
230
- return actor;
231
- });
232
- liveActors = new Set();
233
- has(expectation) {
234
- return this.actors.has(expectation);
235
- }
236
- resolveExpectation(expectation) {
237
- return this.actors.get(expectation);
238
- }
239
- release(expectation) {
240
- if (!this.actors.has(expectation))
241
- return;
242
- const actor = this.actors.get(expectation);
243
- this.actors.delete(expectation);
244
- this.liveActors.delete(actor);
245
- actor.leave();
246
- }
247
- /**
248
- * Logout/drop aborts interned work. Not park. Subclasses abort `#inflight`.
249
- */
250
- abortOnDrop(reason) {
251
- for (const actor of this.liveActors)
252
- actor.abort(reason);
253
- }
254
- /**
255
- * Honor one demand.
256
- * `resolve()` throwing is a broken connection, not a failed expectation.
257
- */
258
- handle(expectation) {
259
- if (this.broken)
260
- return;
261
- if (expectation.isDone)
262
- return;
263
- if (this.has(expectation)) {
264
- const existing = this.resolveExpectation(expectation);
265
- if (!existing.started)
266
- existing.start();
267
- return;
268
- }
269
- let actor;
270
- try {
271
- actor = this.resolveExpectation(expectation);
272
- }
273
- catch (error) {
274
- this.failReady(error);
275
- return;
276
- }
277
- // Awareness / host policy may have sealed the work while resolve() ran.
278
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- resolve() can seal via spawn hooks
279
- if (expectation.isDone) {
280
- actor.leave();
281
- return;
282
- }
283
- if (!actor.started) {
284
- actor.start();
285
- }
286
- }
287
- };
288
- })();
289
- export { PEWDriverConnection };
290
- export function isDriverConnectionClass(value) {
291
- if (typeof value !== "function")
292
- return false;
293
- if (value.pewBrand === PEW_DRIVER_CONNECTION_BRAND)
294
- return true;
295
- return (typeof value.prototype === "object" &&
296
- value.prototype instanceof PEWDriverConnection);
297
- }
298
- //# sourceMappingURL=PEWDriverConnection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PEWDriverConnection.js","sourceRoot":"","sources":["../../src/driver/PEWDriverConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG1D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,WAAW,EAAkB,MAAM,wBAAwB,CAAC;AAuBrE,MAAM,aAAa,GAA0B,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;AAEtE,4FAA4F;AAC5F,uFAAuF;AACvF,MAAM,CAAC,MAAM,2BAA2B,GAAG,0DAA0D,CAAC;AAWtG;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,O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AAC;QAC3D,CAAC;QAED;;;WAGG;QACH,MAAM,CAAC,WAA4B;YACjC,IAAI,IAAI,CAAC,MAAM;gBAAE,OAAO;YACxB,IAAI,WAAW,CAAC,MAAM;gBAAE,OAAO;YAC/B,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;gBACtD,IAAI,CAAC,QAAQ,CAAC,OAAO;oBAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACxC,OAAO;YACT,CAAC;YAED,IAAI,KAA4B,CAAC;YACjC,IAAI,CAAC;gBACH,KAAK,GAAG,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBACtB,OAAO;YACT,CAAC;YAED,wEAAwE;YACxE,6GAA6G;YAC7G,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;gBACvB,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,OAAO;YACT,CAAC;YAED,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBACnB,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;;;SA9MmB,mBAAmB;AAyNzC,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,IAAI,OAAO,KAAK,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9C,IAAK,KAAgC,CAAC,QAAQ,KAAK,2BAA2B;QAAE,OAAO,IAAI,CAAC;IAC5F,OAAO,CACL,OAAQ,KAAiC,CAAC,SAAS,KAAK,QAAQ;QAC/D,KAA+B,CAAC,SAAS,YAAY,mBAAmB,CAC1E,CAAC;AACJ,CAAC","sourcesContent":["import { DefaultedWeakMap } from \"@here.build/collections\";\nimport type { PlexusAwareness } from \"@here.build/plexus\";\nimport { action, computed, observable, toJS } from \"mobx\";\n\nimport type { ExpectationActor } from \"./ExpectationActor.js\";\nimport { pewConfigurationSchema, pewSecretsSchema } from \"../schemas/connection.js\";\nimport { attentionOf, type Attention } from \"../shared/attention.js\";\nimport type { AnyWorkExpectation, WorkExpectation } from \"../shared/models/WorkExpectation.js\";\nimport type { ReadyState } from \"../shared/types.js\";\n\n/** Duck-typed — drivers may ship a different Zod major than this package. */\nexport type ConfigurationSchema = {\n safeParse(\n data: unknown,\n ):\n | { readonly success: true; readonly data: unknown }\n | { readonly success: false; readonly error: { readonly issues: ReadonlyArray<{ readonly message?: string }> } };\n};\n\n/** Process-local. Secrets are never a Plexus field. */\nexport type ConnectionSecretsView = {\n readonly revision?: number;\n get(field: string): unknown | undefined;\n /** MCP env_* enumerates deposited fields. */\n all?(): Readonly<Record<string, unknown>> | undefined;\n /** Hosts that persist a refreshed session (reauth) implement this. */\n replace?(secrets: Readonly<Record<string, string>>): void;\n};\n\nconst EMPTY_SECRETS: ConnectionSecretsView = { get: () => undefined };\n\n/** Module-graph duplication breaks instanceof; the elevation gate checks this brand too. */\n// eslint-disable-next-line no-secrets/no-secrets -- package identity tag, not a secret\nexport const PEW_DRIVER_CONNECTION_BRAND = \"@inhuman.tools/plexus-expectations:PEWDriverConnection@1\";\n\n/** A connection construction the driver already knows will work. */\nexport type DriverOffer = {\n readonly name: string;\n readonly description: string;\n readonly live: boolean;\n readonly adoptable: boolean;\n readonly settings: Readonly<Record<string, unknown>>;\n};\n\n/**\n * Driver extras the orchestrator mirrors onto `spec.live`.\n * Core process facts live on `readyState` / `error` / `offers`.\n */\nexport function extraLiveFromState(state: object): Record<string, unknown> {\n const extra: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(state)) {\n if (value === undefined) continue;\n extra[key] = toJS(value);\n }\n return extra;\n}\n\n/**\n * The CLASS is the driver (one loaded module per driver name).\n * The INSTANCE is a live connection (one per connection id).\n *\n * CLAIM DOES NOT LIVE HERE. Which WorkExpectation classes this driver handles\n * lives on the advertised driver record (`can`): dynamically loaded code does\n * not get to declare its own authority.\n *\n * Live state is report only — no machinery branches on it. Instance bootstrap\n * truth is `bootstrapDone` / `bootstrapPending`. Drivers read {@link attention}\n * as the reduced token, never clientIds.\n *\n * YAML doors ({@link configurationSchema} / {@link secretsSchema}) parse\n * without `new`. Secrets stay a live view — the host may replace it (reauth).\n */\nexport abstract class PEWDriverConnection<\n E extends AnyWorkExpectation = AnyWorkExpectation,\n C = Readonly<Record<string, unknown>>,\n> implements AsyncDisposable {\n // ── driver side (the CLASS is the driver) ─────────────────────────────\n static readonly pewBrand: string = PEW_DRIVER_CONNECTION_BRAND;\n\n /**\n * YAML settings shape. Default is a passthrough record — subclasses replace\n * this with a real object schema (transforms included). First issue message\n * is what construct / parse throw.\n */\n static readonly configurationSchema: ConfigurationSchema = pewConfigurationSchema;\n\n static readonly configurationLabel: string = \"\";\n\n static configurationError(message: string): string {\n const label = this.configurationLabel.trim();\n return label === \"\" ? `connection config invalid: ${message}` : `${label} connection config invalid: ${message}`;\n }\n\n /** YAML settings door. Does not construct an instance. */\n static parseConfiguration(settings: unknown = {}): unknown {\n const result = this.configurationSchema.safeParse(settings ?? {});\n if (result.success) return result.data;\n const message = result.error.issues[0]?.message ?? \"invalid\";\n throw new Error(this.configurationError(message));\n }\n\n static readonly secretsSchema: ConfigurationSchema = pewSecretsSchema;\n\n static secretsError(message: string): string {\n const label = this.configurationLabel.trim();\n return label === \"\" ? `connection secrets invalid: ${message}` : `${label} connection secrets invalid: ${message}`;\n }\n\n /** YAML secrets door. Does not construct an instance. */\n static parseSecrets(secrets: unknown = {}): unknown {\n const result = this.secretsSchema.safeParse(secrets ?? {});\n if (result.success) return result.data;\n const message = result.error.issues[0]?.message ?? \"invalid\";\n throw new Error(this.secretsError(message));\n }\n\n /** Shared on the prototype chain — own extras per subclass. */\n static readonly state: Record<string, unknown> = {};\n static readonly offers: readonly DriverOffer[] = [];\n\n /** Kernel-plane occupancy hub. Orchestrator assignment is own-per-class. */\n static awareness: PlexusAwareness | undefined;\n static driverName = \"\";\n\n /**\n * A getter, not `@computed` — MobX: the decorator's initializer pins to the\n * declaring class, so subclasses would share one computed.\n */\n static get attention(): Attention {\n const hub = this.awareness;\n const name = this.driverName;\n if (hub === undefined || name === \"\") return \"none\";\n return attentionOf(hub, { kind: \"driver\", name });\n }\n\n // ── connection side (the INSTANCE is the connection) ──────────────────\n @observable accessor readyState: ReadyState = null;\n @observable accessor error: string = \"\";\n /**\n * MobX: shallow — extras (models, tools, account) are replaced wholesale.\n * Override the accessor with a wider literal to add driver facts.\n */\n @observable.shallow accessor state: Record<string, unknown> = {};\n\n @observable.ref accessor awareness: PlexusAwareness | undefined = undefined;\n\n @computed\n get attention(): Attention {\n const hub = this.awareness;\n if (hub === undefined) return \"none\";\n return attentionOf(hub, { kind: \"connection\", id: this.connectionId });\n }\n\n constructor(\n public readonly connectionId: string,\n settings: unknown = {},\n secrets: ConnectionSecretsView | Readonly<Record<string, unknown>> = EMPTY_SECRETS,\n ) {\n const cls = new.target as typeof PEWDriverConnection;\n this.settings = cls.parseConfiguration(settings) as C;\n const view: ConnectionSecretsView =\n typeof (secrets as ConnectionSecretsView).get === \"function\"\n ? (secrets as ConnectionSecretsView)\n : {\n get: (field) => (secrets as Readonly<Record<string, unknown>>)[field],\n all: () => secrets as Readonly<Record<string, unknown>>,\n };\n cls.parseSecrets(view.all?.() ?? {});\n this.secrets = view;\n }\n readonly settings: C;\n /** Live view. The host may replace it (reauth). */\n secrets: ConnectionSecretsView;\n\n /**\n * Host binds the disk writer for this connection's settings bag.\n * Parsed settings stay readonly; a driver that learns a value overrides this.\n */\n bindSettingsWriter(_write: (patch: Readonly<Record<string, unknown>>) => void): void {}\n\n abstract bootstrap(): Promise<void>;\n\n bootstrapDone = false;\n bootstrapPending: Promise<void> | null = null;\n /** `resolve()` threw — the connection is broken, not the work. */\n broken = false;\n /** Concurrent callers share one promise. Async settlement is its own MobX action. */\n @action\n ensureBootstrapStarted(): Promise<void> {\n if (this.bootstrapDone) return Promise.resolve();\n if (this.bootstrapPending) return this.bootstrapPending;\n this.readyState = \"bootstrapping\";\n this.error = \"\";\n this.bootstrapPending = this.bootstrap().then(\n action(() => {\n this.bootstrapDone = true;\n this.readyState = \"ready\";\n this.error = \"\";\n }),\n action((error: unknown) => {\n this.readyState = \"failed\";\n this.error = error instanceof Error ? error.message : String(error);\n throw error;\n }),\n );\n return this.bootstrapPending;\n }\n\n @action\n failReady(error: unknown): void {\n this.broken = true;\n this.readyState = \"failed\";\n this.error = error instanceof Error ? error.message : String(error);\n }\n\n protected abstract resolve(expectation: E): ExpectationActor<E>;\n /** Nothing in PEW calls this; hosts or tests may. */\n async [Symbol.asyncDispose](): Promise<void> {}\n\n private readonly actors = new DefaultedWeakMap<WorkExpectation, ExpectationActor<any>>((expectation: WorkExpectation): ExpectationActor<any> => {\n const actor = this.resolve(expectation as E);\n this.liveActors.add(actor);\n return actor;\n});\n private readonly liveActors = new Set<ExpectationActor<any>>();\n\n has(expectation: WorkExpectation): boolean {\n return this.actors.has(expectation);\n }\n resolveExpectation<T extends AnyWorkExpectation>(expectation: T): ExpectationActor<T> {\n return this.actors.get(expectation);\n }\n release(expectation: WorkExpectation): void {\n if (!this.actors.has(expectation)) return;\n const actor = this.actors.get(expectation);\n this.actors.delete(expectation);\n this.liveActors.delete(actor);\n actor.leave();\n }\n\n /**\n * Logout/drop aborts interned work. Not park. Subclasses abort `#inflight`.\n */\n abortOnDrop(reason: unknown): void {\n for (const actor of this.liveActors) actor.abort(reason);\n }\n\n /**\n * Honor one demand.\n * `resolve()` throwing is a broken connection, not a failed expectation.\n */\n handle(expectation: WorkExpectation): void {\n if (this.broken) return;\n if (expectation.isDone) return;\n if (this.has(expectation)) {\n const existing = this.resolveExpectation(expectation);\n if (!existing.started) existing.start();\n return;\n }\n\n let actor: ExpectationActor<any>;\n try {\n actor = this.resolveExpectation(expectation);\n } catch (error) {\n this.failReady(error);\n return;\n }\n\n // Awareness / host policy may have sealed the work while resolve() ran.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- resolve() can seal via spawn hooks\n if (expectation.isDone) {\n actor.leave();\n return;\n }\n\n if (!actor.started) {\n actor.start();\n }\n }\n}\n\n/**\n * A concrete `PEWDriverConnection` subclass — constructable, not abstract.\n * `loadDriverModule` returns `unknown`; {@link isDriverConnectionClass} is the gate.\n */\nexport type DriverConnectionClass = {\n [K in keyof typeof PEWDriverConnection]: (typeof PEWDriverConnection)[K];\n} & (new (...args: ConstructorParameters<typeof PEWDriverConnection>) => PEWDriverConnection);\n\nexport function isDriverConnectionClass(value: unknown): value is DriverConnectionClass {\n if (typeof value !== \"function\") return false;\n if ((value as { pewBrand?: unknown }).pewBrand === PEW_DRIVER_CONNECTION_BRAND) return true;\n return (\n typeof (value as { prototype?: unknown }).prototype === \"object\" &&\n (value as { prototype: object }).prototype instanceof PEWDriverConnection\n );\n}\n"]}
@@ -1,9 +0,0 @@
1
- /**
2
- * Error whose `static invariant` throws `new this(...ctorArgs)`.
3
- * Not on ErrorConstructor — a receiver with extra constructor args
4
- * (`(code, message)`) does not fight `(condition, message?)`.
5
- */
6
- export declare class ErrorWithInvariant extends Error {
7
- static invariant<T extends new (...args: any) => ErrorWithInvariant>(this: T, condition: unknown, ...args: ConstructorParameters<T>): asserts condition;
8
- }
9
- //# sourceMappingURL=error-with-invariant.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-with-invariant.d.ts","sourceRoot":"","sources":["../src/error-with-invariant.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,KAAK,kBAAkB,EACjE,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,OAAO,EAClB,GAAG,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,SAAS;CAGrB"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Error whose `static invariant` throws `new this(...ctorArgs)`.
3
- * Not on ErrorConstructor — a receiver with extra constructor args
4
- * (`(code, message)`) does not fight `(condition, message?)`.
5
- */
6
- export class ErrorWithInvariant extends Error {
7
- static invariant(condition, ...args) {
8
- if (!condition)
9
- throw new this(...args);
10
- }
11
- }
12
- //# sourceMappingURL=error-with-invariant.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-with-invariant.js","sourceRoot":"","sources":["../src/error-with-invariant.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,MAAM,CAAC,SAAS,CAEd,SAAkB,EAClB,GAAG,IAA8B;QAEjC,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["/**\n * Error whose `static invariant` throws `new this(...ctorArgs)`.\n * Not on ErrorConstructor — a receiver with extra constructor args\n * (`(code, message)`) does not fight `(condition, message?)`.\n */\nexport class ErrorWithInvariant extends Error {\n static invariant<T extends new (...args: any) => ErrorWithInvariant>(\n this: T,\n condition: unknown,\n ...args: ConstructorParameters<T>\n ): asserts condition {\n if (!condition) throw new this(...args);\n }\n}\n"]}
@@ -1,27 +0,0 @@
1
- /**
2
- * Attention occupancy. Clients publish on kernel awareness; PEW reduces to
3
- * none | ambient | focused. Interned connections outlive a session wrap, so
4
- * occupancy is not session-plane. Drivers read the reduced token — never clientIds.
5
- */
6
- import { type PlexusAwareness } from "@here.build/plexus";
7
- import { ConnectionSpec } from "./models/ConnectionSpec.js";
8
- import { DriverSpec } from "./models/DriverSpec.js";
9
- export type Attention = "none" | "ambient" | "focused";
10
- export declare const ATTENTION_LANE = "attention";
11
- export declare const ATTENTION_FOCUS_LANE = "attentionFocus";
12
- export type AttentionRef = {
13
- readonly kind: "driver";
14
- readonly name: string;
15
- } | {
16
- readonly kind: "connection";
17
- readonly id: string;
18
- };
19
- export type AttentionSubject = DriverSpec | ConnectionSpec;
20
- export type AttentionSource = AttentionSubject | Iterable<AttentionSubject | null | undefined> | null | undefined;
21
- export declare function attentionRefFromSpec(spec: AttentionSubject): AttentionRef;
22
- export declare function collectAttentionRefs(source: AttentionSource): AttentionRef[];
23
- export declare function publishAttention(hub: PlexusAwareness, refs: readonly AttentionRef[]): void;
24
- export declare function publishAttentionFocus(hub: PlexusAwareness, ref: AttentionRef | null): void;
25
- /** Union of every client's occupancy. Focused wins over ambient. */
26
- export declare function attentionOf(hub: PlexusAwareness, target: AttentionRef): Attention;
27
- //# sourceMappingURL=attention.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attention.d.ts","sourceRoot":"","sources":["../../src/shared/attention.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAEvD,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAErD,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,cAAc,CAAC;AAE3D,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAElH,wBA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