@manifesto-ai/sdk 3.18.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { ComputeStatus, DomainSchema, ExprNode, Intent, Patch, Requirement, TraceGraph } from "@manifesto-ai/core";
1
+ import type { ComputeStatus, DomainSchema, ErrorValue, ExprNode, Intent, JsonValue, Patch, Requirement, TraceGraph } from "@manifesto-ai/core";
2
+ export type { JsonValue } from "@manifesto-ai/core";
2
3
  import type { SchemaGraph as CompilerSchemaGraph, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind } from "@manifesto-ai/compiler";
3
- import type { CanonicalPlatformNamespaces, CanonicalSnapshot, Snapshot } from "./projection/snapshot-projection.js";
4
+ import type { CanonicalNamespaces, CanonicalSnapshot, Snapshot } from "./projection/snapshot-projection.js";
4
5
  type ActionFn = {
5
6
  bivarianceHack(...args: unknown[]): unknown;
6
7
  }["bivarianceHack"];
@@ -8,6 +9,7 @@ export type ManifestoDomainShape = {
8
9
  readonly actions: Record<string, ActionFn>;
9
10
  readonly state: Record<string, unknown>;
10
11
  readonly computed: Record<string, unknown>;
12
+ readonly context?: ExternalContext;
11
13
  };
12
14
  export type BaseLaws = {
13
15
  readonly __baseLaws: true;
@@ -44,7 +46,7 @@ export type ComputedRef<TValue> = {
44
46
  readonly name: string;
45
47
  readonly _type?: TValue;
46
48
  };
47
- export type TypedMEL<T extends ManifestoDomainShape> = {
49
+ export type TypedDomainRefs<T extends ManifestoDomainShape> = {
48
50
  readonly actions: {
49
51
  readonly [K in keyof T["actions"]]: TypedActionRef<T, K>;
50
52
  };
@@ -55,11 +57,266 @@ export type TypedMEL<T extends ManifestoDomainShape> = {
55
57
  readonly [K in keyof T["computed"]]: ComputedRef<T["computed"][K]>;
56
58
  };
57
59
  };
60
+ /**
61
+ * @deprecated Use TypedDomainRefs. This compatibility alias is retained for
62
+ * older helper/provider code that still names the typed ref surface "MEL".
63
+ */
64
+ export type TypedMEL<T extends ManifestoDomainShape> = TypedDomainRefs<T>;
58
65
  export type ActionArgs<T extends ManifestoDomainShape, K extends keyof T["actions"]> = T["actions"][K] extends (...args: infer P) => unknown ? P : never;
66
+ export type RuntimeMode = "base" | "lineage" | "governance";
67
+ export type ActionName<T extends ManifestoDomainShape> = keyof T["actions"] & string;
68
+ type ActionInputFromArgs<TArgs extends readonly unknown[]> = TArgs extends readonly [] ? undefined : 2 extends TArgs["length"] ? Readonly<TArgs> : TArgs extends readonly [unknown, unknown, ...unknown[]] ? Readonly<TArgs> : TArgs[0];
69
+ export type ActionInput<T extends ManifestoDomainShape, K extends ActionName<T>> = ActionInputFromArgs<ActionArgs<T, K>>;
70
+ export type ProjectedSnapshot<T extends ManifestoDomainShape> = Snapshot<T["state"], T["computed"]>;
71
+ export type ExternalContext = Readonly<Record<string, JsonValue>>;
72
+ export type DomainExternalContext<T extends ManifestoDomainShape> = T extends {
73
+ readonly context: infer TContext extends ExternalContext;
74
+ } ? Readonly<TContext> : ExternalContext;
75
+ export type ContextUpdater<TContext extends ExternalContext = ExternalContext> = (current: Readonly<TContext>) => TContext;
76
+ export type PreviewDiagnosticsMode = "none" | "summary" | "trace";
77
+ export type SubmitReportMode = "none" | "summary" | "full";
78
+ export type ExecutionView<TContext extends ExternalContext = ExternalContext> = {
79
+ readonly context?: TContext;
80
+ readonly diagnostics?: PreviewDiagnosticsMode;
81
+ readonly report?: SubmitReportMode;
82
+ };
83
+ export type ActionAnnotation = Readonly<Record<string, unknown>>;
84
+ export type CreateManifestoOptions<TContext extends ExternalContext = ExternalContext> = {
85
+ readonly annotations?: Readonly<Record<string, ActionAnnotation>>;
86
+ readonly context?: TContext;
87
+ };
88
+ export type ActionParameterInfo = {
89
+ readonly name: string;
90
+ readonly required: boolean;
91
+ readonly type?: string;
92
+ readonly description?: string;
93
+ };
94
+ export type ActionInfo<Name extends string = string> = {
95
+ readonly name: Name;
96
+ readonly title?: string;
97
+ readonly description?: string;
98
+ readonly parameters: readonly ActionParameterInfo[];
99
+ readonly annotations?: ActionAnnotation;
100
+ };
101
+ export type Blocker = {
102
+ readonly path: ReadonlyArray<string | number>;
103
+ readonly code: string;
104
+ readonly message: string;
105
+ readonly detail?: Readonly<Record<string, unknown>>;
106
+ };
107
+ export type AdmissionOk<Name extends string = string> = {
108
+ readonly ok: true;
109
+ readonly action: Name;
110
+ };
111
+ export type AdmissionFailure<Name extends string = string> = {
112
+ readonly ok: false;
113
+ readonly action: Name;
114
+ readonly layer: "availability" | "input" | "dispatchability";
115
+ readonly code: "ACTION_UNAVAILABLE" | "INVALID_INPUT" | "INTENT_NOT_DISPATCHABLE";
116
+ readonly message: string;
117
+ readonly blockers: readonly Blocker[];
118
+ };
119
+ export type Admission<Name extends string = string> = AdmissionOk<Name> | AdmissionFailure<Name>;
120
+ export type PathSegment = string | number;
121
+ export type ChangedPath = {
122
+ readonly path: readonly PathSegment[];
123
+ readonly kind: "set" | "unset" | "changed";
124
+ };
125
+ export type PreviewDiagnostics = {
126
+ readonly trace?: TraceGraph;
127
+ };
128
+ export type PreviewResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
129
+ readonly admitted: false;
130
+ readonly admission: AdmissionFailure<K>;
131
+ } | {
132
+ readonly admitted: true;
133
+ readonly status: "complete" | "pending" | "halted" | "error";
134
+ readonly before: ProjectedSnapshot<T>;
135
+ readonly after: ProjectedSnapshot<T>;
136
+ readonly changes: readonly ChangedPath[];
137
+ readonly requirements: readonly Requirement[];
138
+ readonly newAvailableActions?: readonly ActionInfo[];
139
+ readonly diagnostics?: PreviewDiagnostics;
140
+ readonly error?: ErrorValue | null;
141
+ };
142
+ export type ExecutionDetail = Readonly<Record<string, unknown>>;
143
+ export type ExecutionOutcome = {
144
+ readonly kind: "ok";
145
+ readonly detail?: ExecutionDetail;
146
+ } | {
147
+ readonly kind: "stop";
148
+ readonly reason: string;
149
+ readonly detail?: ExecutionDetail;
150
+ } | {
151
+ readonly kind: "fail";
152
+ readonly error: ErrorValue;
153
+ readonly detail?: ExecutionDetail;
154
+ };
155
+ export type BaseWriteReport = {
156
+ readonly mode: "base";
157
+ readonly action: string;
158
+ readonly changes: readonly ChangedPath[];
159
+ readonly requirements: readonly Requirement[];
160
+ readonly outcome: ExecutionOutcome;
161
+ readonly diagnostics?: ExecutionDiagnostics;
162
+ };
163
+ export type WorldRecord = {
164
+ readonly worldId: string;
165
+ readonly schemaHash: string;
166
+ readonly snapshotHash: string;
167
+ readonly parentWorldId: string | null;
168
+ readonly terminalStatus: "completed" | "failed";
169
+ };
170
+ export type LineageWriteReport = {
171
+ readonly mode: "lineage";
172
+ readonly action: string;
173
+ readonly worldId: string;
174
+ readonly branchId: string;
175
+ readonly headAdvanced: boolean;
176
+ readonly published: boolean;
177
+ readonly outcome: ExecutionOutcome;
178
+ readonly sealedSnapshotHash: string;
179
+ readonly changes: readonly ChangedPath[];
180
+ readonly requirements: readonly Requirement[];
181
+ readonly diagnostics?: ExecutionDiagnostics;
182
+ };
183
+ export type GovernanceSettlementReport = {
184
+ readonly mode: "governance";
185
+ readonly status: "settled";
186
+ readonly action: string;
187
+ readonly proposal: ProposalRef;
188
+ readonly baseWorldId: string;
189
+ readonly worldId: string;
190
+ readonly sealedSnapshotHash: string;
191
+ readonly published: boolean;
192
+ readonly outcome: ExecutionOutcome;
193
+ readonly changes: readonly ChangedPath[];
194
+ readonly requirements: readonly Requirement[];
195
+ } | {
196
+ readonly mode: "governance";
197
+ readonly status: "rejected" | "superseded" | "expired" | "cancelled";
198
+ readonly action: string;
199
+ readonly proposal: ProposalRef;
200
+ readonly decision?: DecisionRecord;
201
+ } | {
202
+ readonly mode: "governance";
203
+ readonly status: "settlement_failed";
204
+ readonly action: string;
205
+ readonly proposal?: ProposalRef;
206
+ readonly stage: "authority" | "runtime" | "settlement" | "persistence" | "observation";
207
+ readonly error: ErrorValue;
208
+ };
209
+ export type ProposalRef = string;
210
+ export type DecisionRecord = Readonly<Record<string, unknown>>;
211
+ export type BaseSubmissionResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
212
+ readonly ok: true;
213
+ readonly mode: "base";
214
+ readonly status: "settled";
215
+ readonly action: K;
216
+ readonly before: ProjectedSnapshot<T>;
217
+ readonly after: ProjectedSnapshot<T>;
218
+ readonly outcome: ExecutionOutcome;
219
+ readonly report?: BaseWriteReport;
220
+ } | {
221
+ readonly ok: false;
222
+ readonly mode: "base";
223
+ readonly action: K;
224
+ readonly admission: AdmissionFailure<K>;
225
+ };
226
+ export type LineageSubmissionResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
227
+ readonly ok: true;
228
+ readonly mode: "lineage";
229
+ readonly status: "settled";
230
+ readonly action: K;
231
+ readonly before: ProjectedSnapshot<T>;
232
+ readonly after: ProjectedSnapshot<T>;
233
+ readonly world: WorldRecord;
234
+ readonly outcome: ExecutionOutcome;
235
+ readonly report?: LineageWriteReport;
236
+ } | {
237
+ readonly ok: false;
238
+ readonly mode: "lineage";
239
+ readonly action: K;
240
+ readonly admission: AdmissionFailure<K>;
241
+ };
242
+ export type GovernanceSubmissionResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
243
+ readonly ok: true;
244
+ readonly mode: "governance";
245
+ readonly status: "pending";
246
+ readonly action: K;
247
+ readonly proposal: ProposalRef;
248
+ waitForSettlement(): Promise<GovernanceSettlementResult<T, K>>;
249
+ } | {
250
+ readonly ok: false;
251
+ readonly mode: "governance";
252
+ readonly action: K;
253
+ readonly admission: AdmissionFailure<K>;
254
+ };
255
+ export type GovernanceSettlementResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
256
+ readonly ok: true;
257
+ readonly mode: "governance";
258
+ readonly status: "settled";
259
+ readonly action: K;
260
+ readonly proposal: ProposalRef;
261
+ readonly world: WorldRecord;
262
+ readonly before: ProjectedSnapshot<T>;
263
+ readonly after: ProjectedSnapshot<T>;
264
+ readonly outcome: ExecutionOutcome;
265
+ readonly report?: GovernanceSettlementReport;
266
+ } | {
267
+ readonly ok: true;
268
+ readonly mode: "governance";
269
+ readonly status: "rejected" | "superseded" | "expired" | "cancelled";
270
+ readonly action: K;
271
+ readonly proposal: ProposalRef;
272
+ readonly decision?: DecisionRecord;
273
+ readonly report?: GovernanceSettlementReport;
274
+ } | {
275
+ readonly ok: false;
276
+ readonly mode: "governance";
277
+ readonly status: "settlement_failed";
278
+ readonly action: K;
279
+ readonly proposal: ProposalRef;
280
+ readonly error: ErrorValue;
281
+ readonly report?: GovernanceSettlementReport;
282
+ };
283
+ export type SubmissionResult<T extends ManifestoDomainShape, K extends ActionName<T>> = BaseSubmissionResult<T, K> | LineageSubmissionResult<T, K> | GovernanceSubmissionResult<T, K>;
284
+ export type SubmitResultFor<TMode extends RuntimeMode, T extends ManifestoDomainShape, K extends ActionName<T>> = TMode extends "base" ? BaseSubmissionResult<T, K> : TMode extends "lineage" ? LineageSubmissionResult<T, K> : TMode extends "governance" ? GovernanceSubmissionResult<T, K> : SubmissionResult<T, K>;
285
+ export type ActionHandle<T extends ManifestoDomainShape, K extends ActionName<T>, TMode extends RuntimeMode> = {
286
+ info(): ActionInfo<K>;
287
+ available(): boolean;
288
+ check(...args: ActionArgs<T, K>): Admission<K>;
289
+ preview(...args: ActionArgs<T, K>): PreviewResult<T, K>;
290
+ submit(...args: ActionArgs<T, K>): Promise<SubmitResultFor<TMode, T, K>>;
291
+ bind(...args: ActionArgs<T, K>): BoundAction<T, K, TMode>;
292
+ };
293
+ export type BoundAction<T extends ManifestoDomainShape, K extends ActionName<T>, TMode extends RuntimeMode> = {
294
+ readonly action: K;
295
+ readonly input: ActionInput<T, K>;
296
+ check(): Admission<K>;
297
+ preview(): PreviewResult<T, K>;
298
+ submit(): Promise<SubmitResultFor<TMode, T, K>>;
299
+ intent(): Intent | null;
300
+ };
301
+ export type ActionSurface<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
302
+ readonly [K in ActionName<T>]: ActionHandle<T, K, TMode>;
303
+ };
59
304
  export type ActionObjectBindingArgs<T extends ManifestoDomainShape, K extends keyof T["actions"]> = ActionArgs<T, K> extends [unknown, ...unknown[]] ? [params: Record<string, unknown>] : never;
60
305
  export type CreateIntentArgs<T extends ManifestoDomainShape, K extends keyof T["actions"]> = ActionArgs<T, K> | ActionObjectBindingArgs<T, K>;
61
- export type Selector<T, R> = (snapshot: Snapshot<T>) => R;
306
+ export type Selector<TState, R, TComputed = Record<string, unknown>> = (snapshot: Snapshot<TState, TComputed>) => R;
62
307
  export type Unsubscribe = () => void;
308
+ export type ProjectedReadHandle<TValue, TRef> = {
309
+ readonly name: string;
310
+ readonly ref: TRef;
311
+ value(): TValue;
312
+ observe(listener: (next: TValue, prev: TValue) => void): Unsubscribe;
313
+ };
314
+ export type StateReadSurface<T extends ManifestoDomainShape> = {
315
+ readonly [K in keyof T["state"]]: ProjectedReadHandle<T["state"][K], FieldRef<T["state"][K]>>;
316
+ };
317
+ export type ComputedReadSurface<T extends ManifestoDomainShape> = {
318
+ readonly [K in keyof T["computed"]]: ProjectedReadHandle<T["computed"][K], ComputedRef<T["computed"][K]>>;
319
+ };
63
320
  declare const MANIFESTO_INTENT_BRAND: unique symbol;
64
321
  export type TypedIntent<T extends ManifestoDomainShape, K extends keyof T["actions"] = keyof T["actions"]> = Intent & {
65
322
  readonly [MANIFESTO_INTENT_BRAND]: {
@@ -68,7 +325,7 @@ export type TypedIntent<T extends ManifestoDomainShape, K extends keyof T["actio
68
325
  };
69
326
  };
70
327
  export type TypedCreateIntent<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => TypedIntent<T, K>;
71
- export type TypedDispatchAsync<T extends ManifestoDomainShape> = (intent: TypedIntent<T>) => Promise<Snapshot<T["state"]>>;
328
+ export type TypedDispatchAsync<T extends ManifestoDomainShape> = (intent: TypedIntent<T>) => Promise<ProjectedSnapshot<T>>;
72
329
  export type TypedCommitAsync<T extends ManifestoDomainShape> = TypedDispatchAsync<T>;
73
330
  export type SchemaGraphNodeRef = TypedActionRef<ManifestoDomainShape> | FieldRef<unknown> | ComputedRef<unknown>;
74
331
  export type SchemaGraph = CompilerSchemaGraph & {
@@ -78,8 +335,8 @@ export type SchemaGraph = CompilerSchemaGraph & {
78
335
  traceDown(nodeId: SchemaGraphNodeId): SchemaGraph;
79
336
  };
80
337
  export type SimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape> = {
81
- readonly snapshot: Snapshot<T["state"]>;
82
- readonly changedPaths: readonly string[];
338
+ readonly snapshot: ProjectedSnapshot<T>;
339
+ readonly changedPaths: readonly ChangedPath[];
83
340
  readonly newAvailableActions: readonly (keyof T["actions"])[];
84
341
  readonly requirements: readonly Requirement[];
85
342
  readonly status: ComputeStatus;
@@ -116,22 +373,24 @@ export type AvailableActionDelta<T extends ManifestoDomainShape = ManifestoDomai
116
373
  readonly unlocked: readonly (keyof T["actions"])[];
117
374
  readonly locked: readonly (keyof T["actions"])[];
118
375
  };
119
- export type ProjectedDiff<T extends ManifestoDomainShape = ManifestoDomainShape> = {
120
- readonly beforeSnapshot: Snapshot<T["state"]>;
121
- readonly afterSnapshot: Snapshot<T["state"]>;
122
- readonly changedPaths: readonly string[];
376
+ export type DispatchProjectedDiff<T extends ManifestoDomainShape = ManifestoDomainShape> = {
377
+ readonly beforeSnapshot: ProjectedSnapshot<T>;
378
+ readonly afterSnapshot: ProjectedSnapshot<T>;
379
+ readonly changedPaths: readonly ChangedPath[];
123
380
  readonly availability: AvailableActionDelta<T>;
124
381
  };
125
- export type CanonicalOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
382
+ export type DispatchCanonicalOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
126
383
  readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
127
384
  readonly afterCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
128
385
  readonly pendingRequirements: readonly Requirement[];
129
386
  readonly status: CanonicalSnapshot<T["state"]>["system"]["status"];
130
387
  };
131
- export type ExecutionOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
132
- readonly projected: ProjectedDiff<T>;
133
- readonly canonical: CanonicalOutcome<T>;
388
+ export type DispatchExecutionOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
389
+ readonly projected: DispatchProjectedDiff<T>;
390
+ readonly canonical: DispatchCanonicalOutcome<T>;
134
391
  };
392
+ export type ProjectedDiff<T extends ManifestoDomainShape = ManifestoDomainShape> = DispatchProjectedDiff<T>;
393
+ export type CanonicalOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = DispatchCanonicalOutcome<T>;
135
394
  export type ExecutionFailureInfo = {
136
395
  readonly message: string;
137
396
  readonly code?: string;
@@ -148,7 +407,7 @@ export type DispatchReport<T extends ManifestoDomainShape = ManifestoDomainShape
148
407
  readonly kind: "admitted";
149
408
  readonly actionName: keyof T["actions"] & string;
150
409
  };
151
- readonly outcome: ExecutionOutcome<T>;
410
+ readonly outcome: DispatchExecutionOutcome<T>;
152
411
  readonly diagnostics?: ExecutionDiagnostics;
153
412
  } | {
154
413
  readonly kind: "rejected";
@@ -156,7 +415,7 @@ export type DispatchReport<T extends ManifestoDomainShape = ManifestoDomainShape
156
415
  readonly admission: Extract<IntentAdmission<T>, {
157
416
  readonly kind: "blocked";
158
417
  }>;
159
- readonly beforeSnapshot: Snapshot<T["state"]>;
418
+ readonly beforeSnapshot: ProjectedSnapshot<T>;
160
419
  readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
161
420
  readonly rejection: {
162
421
  readonly code: "ACTION_UNAVAILABLE" | "INTENT_NOT_DISPATCHABLE" | "INVALID_INPUT";
@@ -169,12 +428,12 @@ export type DispatchReport<T extends ManifestoDomainShape = ManifestoDomainShape
169
428
  readonly kind: "admitted";
170
429
  readonly actionName: keyof T["actions"] & string;
171
430
  };
172
- readonly beforeSnapshot: Snapshot<T["state"]>;
431
+ readonly beforeSnapshot: ProjectedSnapshot<T>;
173
432
  readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
174
433
  readonly error: ExecutionFailureInfo;
175
434
  readonly published: boolean;
176
435
  readonly diagnostics?: ExecutionDiagnostics;
177
- readonly outcome?: ExecutionOutcome<T>;
436
+ readonly outcome?: DispatchExecutionOutcome<T>;
178
437
  };
179
438
  export type IntentExplanation<T extends ManifestoDomainShape = ManifestoDomainShape> = {
180
439
  readonly kind: "blocked";
@@ -196,18 +455,22 @@ export type IntentExplanation<T extends ManifestoDomainShape = ManifestoDomainSh
196
455
  readonly status: ComputeStatus;
197
456
  readonly requirements: readonly Requirement[];
198
457
  readonly canonicalSnapshot: CanonicalSnapshot<T["state"]>;
199
- readonly snapshot: Snapshot<T["state"]>;
458
+ readonly snapshot: ProjectedSnapshot<T>;
200
459
  readonly newAvailableActions: readonly (keyof T["actions"])[];
201
- readonly changedPaths: readonly string[];
460
+ readonly changedPaths: readonly ChangedPath[];
202
461
  };
203
462
  export type TypedSimulate<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => SimulateResult<T>;
204
463
  export type TypedSimulateIntent<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(intent: TypedIntent<T, K>) => SimulateResult<T>;
205
- export type TypedSubscribe<T extends ManifestoDomainShape> = <R>(selector: Selector<T["state"], R>, listener: (value: R) => void) => Unsubscribe;
464
+ export type TypedSubscribe<T extends ManifestoDomainShape> = <R>(selector: Selector<T["state"], R, T["computed"]>, listener: (value: R) => void) => Unsubscribe;
206
465
  export type TypedActionMetadata<T extends ManifestoDomainShape, K extends keyof T["actions"] = keyof T["actions"]> = {
207
466
  readonly name: K;
208
467
  readonly params: readonly string[];
468
+ readonly publicArity: number;
469
+ readonly requiredArity: number;
209
470
  readonly input: DomainSchema["actions"][string]["input"];
471
+ readonly inputType?: DomainSchema["actions"][string]["inputType"];
210
472
  readonly description: string | undefined;
473
+ readonly annotations?: ActionAnnotation;
211
474
  readonly hasDispatchableGate: boolean;
212
475
  };
213
476
  export type TypedGetActionMetadata<T extends ManifestoDomainShape> = {
@@ -222,35 +485,95 @@ export type DispatchBlocker = {
222
485
  };
223
486
  export type TypedIsIntentDispatchable<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => boolean;
224
487
  export type TypedGetIntentBlockers<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => readonly DispatchBlocker[];
225
- export interface ManifestoEventMap<T extends ManifestoDomainShape> {
226
- "dispatch:completed": {
227
- readonly intentId: string;
228
- readonly intent: TypedIntent<T>;
229
- readonly snapshot: Snapshot<T["state"]>;
488
+ export type SubmissionEventBase = {
489
+ readonly action: string;
490
+ readonly mode: RuntimeMode;
491
+ readonly intentId?: string;
492
+ readonly schemaHash: string;
493
+ readonly snapshotVersion?: number;
494
+ };
495
+ export type ProposalEventBase = {
496
+ readonly proposal: ProposalRef;
497
+ readonly action: string;
498
+ readonly schemaHash: string;
499
+ };
500
+ export type ManifestoEventPayloadMap = {
501
+ readonly "submission:admitted": SubmissionEventBase & {
502
+ readonly admission: AdmissionOk;
230
503
  };
231
- "dispatch:rejected": {
232
- readonly intentId: string;
233
- readonly intent: TypedIntent<T>;
234
- readonly code: "ACTION_UNAVAILABLE" | "INTENT_NOT_DISPATCHABLE" | "INVALID_INPUT";
235
- readonly reason: string;
504
+ readonly "submission:rejected": SubmissionEventBase & {
505
+ readonly admission: AdmissionFailure;
236
506
  };
237
- "dispatch:failed": {
238
- readonly intentId: string;
239
- readonly intent: TypedIntent<T>;
240
- readonly error: Error;
241
- readonly snapshot?: Snapshot<T["state"]>;
507
+ readonly "submission:submitted": SubmissionEventBase;
508
+ readonly "submission:pending": SubmissionEventBase & {
509
+ readonly mode: "governance";
510
+ readonly proposal: ProposalRef;
242
511
  };
243
- }
244
- export type ManifestoEvent = "dispatch:completed" | "dispatch:rejected" | "dispatch:failed";
245
- export type ManifestoEventPayload<T extends ManifestoDomainShape> = ManifestoEventMap<T>[ManifestoEvent];
246
- export type TypedOn<T extends ManifestoDomainShape> = <K extends ManifestoEvent>(event: K, handler: (payload: ManifestoEventMap<T>[K]) => void) => Unsubscribe;
512
+ readonly "submission:settled": SubmissionEventBase & {
513
+ readonly mode: "base" | "lineage" | "governance";
514
+ readonly outcome: ExecutionOutcome;
515
+ readonly proposal?: ProposalRef;
516
+ readonly worldId?: string;
517
+ };
518
+ readonly "submission:failed": SubmissionEventBase & {
519
+ readonly stage: "runtime" | "settlement";
520
+ readonly error: ErrorValue;
521
+ readonly proposal?: ProposalRef;
522
+ };
523
+ readonly "proposal:created": ProposalEventBase;
524
+ readonly "proposal:decided": ProposalEventBase & {
525
+ readonly decision: DecisionRecord;
526
+ };
527
+ readonly "proposal:superseded": ProposalEventBase & {
528
+ readonly supersededBy?: ProposalRef;
529
+ };
530
+ readonly "proposal:expired": ProposalEventBase & {
531
+ readonly reason?: string;
532
+ };
533
+ readonly "proposal:cancelled": ProposalEventBase & {
534
+ readonly reason?: string;
535
+ };
536
+ };
537
+ export type ManifestoEventName = keyof ManifestoEventPayloadMap;
538
+ export type ManifestoEventPayload<Event extends ManifestoEventName> = ManifestoEventPayloadMap[Event];
539
+ export type ManifestoEvent = ManifestoEventName;
540
+ export type TypedOn<T extends ManifestoDomainShape> = <K extends ManifestoEvent>(event: K, handler: (payload: ManifestoEventPayloadMap[K]) => void) => Unsubscribe;
541
+ export type ObserveSurface<T extends ManifestoDomainShape> = {
542
+ state<S>(selector: (snapshot: ProjectedSnapshot<T>) => S, listener: (next: S, prev: S) => void): Unsubscribe;
543
+ event<Event extends ManifestoEventName>(event: Event, listener: (payload: ManifestoEventPayload<Event>) => void): Unsubscribe;
544
+ };
545
+ export type InspectSurface<T extends ManifestoDomainShape> = {
546
+ graph(): SchemaGraph;
547
+ canonicalSnapshot(): CanonicalSnapshot<T["state"]>;
548
+ action<Name extends ActionName<T>>(name: Name): ActionInfo<Name>;
549
+ availableActions(): readonly ActionInfo<ActionName<T>>[];
550
+ schemaHash(): string;
551
+ };
552
+ export type BaseManifestoApp<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
553
+ readonly action: ActionSurface<T, TMode>;
554
+ readonly state: StateReadSurface<T>;
555
+ readonly computed: ComputedReadSurface<T>;
556
+ readonly observe: ObserveSurface<T>;
557
+ readonly inspect: InspectSurface<T>;
558
+ snapshot(): ProjectedSnapshot<T>;
559
+ context(): DomainExternalContext<T>;
560
+ injectContext(context: DomainExternalContext<T>): void;
561
+ updateContext(updater: ContextUpdater<DomainExternalContext<T>>): DomainExternalContext<T>;
562
+ with(view: ExecutionView<DomainExternalContext<T>>): ManifestoApp<T, TMode>;
563
+ dispose(): void;
564
+ };
565
+ export type GovernanceSettlementSurface<T extends ManifestoDomainShape> = {
566
+ waitForSettlement(ref: ProposalRef): Promise<GovernanceSettlementResult<T, ActionName<T>>>;
567
+ };
568
+ type EmptySurface = Record<never, never>;
569
+ export type ManifestoApp<T extends ManifestoDomainShape, TMode extends RuntimeMode> = BaseManifestoApp<T, TMode> & ([TMode] extends ["governance"] ? GovernanceSettlementSurface<T> : EmptySurface);
247
570
  export type ManifestoBaseInstance<T extends ManifestoDomainShape> = {
248
571
  readonly createIntent: TypedCreateIntent<T>;
249
572
  readonly dispatchAsync: TypedDispatchAsync<T>;
250
573
  readonly dispatchAsyncWithReport: (intent: TypedIntent<T>) => Promise<DispatchReport<T>>;
251
574
  readonly subscribe: TypedSubscribe<T>;
252
575
  readonly on: TypedOn<T>;
253
- readonly getSnapshot: () => Snapshot<T["state"]>;
576
+ readonly getSnapshot: () => ProjectedSnapshot<T>;
254
577
  readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
255
578
  readonly getAvailableActions: () => readonly (keyof T["actions"])[];
256
579
  readonly isIntentDispatchable: TypedIsIntentDispatchable<T>;
@@ -263,14 +586,16 @@ export type ManifestoBaseInstance<T extends ManifestoDomainShape> = {
263
586
  readonly getSchemaGraph: () => SchemaGraph;
264
587
  readonly simulate: TypedSimulate<T>;
265
588
  readonly simulateIntent: TypedSimulateIntent<T>;
589
+ readonly refs: TypedDomainRefs<T>;
590
+ /** @deprecated Use refs. */
266
591
  readonly MEL: TypedMEL<T>;
267
592
  readonly schema: DomainSchema;
268
593
  readonly dispose: () => void;
269
594
  };
270
- export type ManifestoLegalityRuntime<T extends ManifestoDomainShape> = Pick<ManifestoBaseInstance<T>, "createIntent" | "whyNot" | "simulate" | "simulateIntent" | "MEL">;
595
+ export type ManifestoLegalityRuntime<T extends ManifestoDomainShape> = Pick<ManifestoBaseInstance<T>, "createIntent" | "whyNot" | "simulate" | "simulateIntent" | "refs" | "MEL">;
271
596
  export type ManifestoDispatchRuntime<T extends ManifestoDomainShape> = Pick<ManifestoBaseInstance<T>, "dispatchAsync" | "dispatchAsyncWithReport">;
272
597
  export interface ManifestoRuntimeByLaws<T extends ManifestoDomainShape> {
273
- readonly base: ManifestoBaseInstance<T>;
598
+ readonly base: ManifestoApp<T, "base">;
274
599
  }
275
600
  export interface ManifestoDecoratedRuntimeByLaws<T extends ManifestoDomainShape> {
276
601
  }
@@ -280,7 +605,7 @@ export type ActivatedInstance<T extends ManifestoDomainShape, Laws> = Laws exten
280
605
  } ? Runtime : never : Laws extends LineageLaws ? ResolvedManifestoRuntimeByLaws<T> extends {
281
606
  readonly lineage: infer Runtime;
282
607
  } ? Runtime : never : ManifestoRuntimeByLaws<T>["base"];
283
- export type { CanonicalPlatformNamespaces, CanonicalSnapshot, Snapshot, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, };
608
+ export type { CanonicalNamespaces, CanonicalSnapshot, Snapshot, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, };
284
609
  export type ComposableManifesto<T extends ManifestoDomainShape, Laws extends BaseLaws = BaseComposableLaws> = {
285
610
  readonly _laws: Laws;
286
611
  readonly schema: DomainSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifesto-ai/sdk",
3
- "version": "3.18.0",
3
+ "version": "5.0.0",
4
4
  "description": "Manifesto SDK - Activation-first public API for the base runtime",
5
5
  "author": "eggplantiny <eggplantiny@gmail.com>",
6
6
  "license": "MIT",
@@ -47,9 +47,9 @@
47
47
  "dist"
48
48
  ],
49
49
  "dependencies": {
50
- "@manifesto-ai/compiler": "3.8.0",
51
- "@manifesto-ai/core": "2.13.0",
52
- "@manifesto-ai/host": "2.9.1"
50
+ "@manifesto-ai/compiler": "5.0.0",
51
+ "@manifesto-ai/host": "5.0.0",
52
+ "@manifesto-ai/core": "5.0.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "typescript": "^5.9.3",
@@ -1 +0,0 @@
1
- var n=class extends Error{code;constructor(e,o,d){super(o,d),this.name="ManifestoError",this.code=e}},s=class extends n{effectType;constructor(e){super("RESERVED_EFFECT",`Effect type "${e}" is reserved and cannot be overridden`),this.name="ReservedEffectError",this.effectType=e}},t=class extends n{diagnostics;constructor(e,o){super("COMPILE_ERROR",o),this.name="CompileError",this.diagnostics=e}},a=class extends n{constructor(){super("DISPOSED","Cannot use a disposed Manifesto runtime"),this.name="DisposedError"}},i=class extends n{constructor(){super("ALREADY_ACTIVATED","ComposableManifesto.activate() may only be called once"),this.name="AlreadyActivatedError"}};export{n as a,s as b,t as c,a as d,i as e};
@@ -1 +0,0 @@
1
- import{a as E,e as B}from"./chunk-BDIXNUQ3.js";import{getAvailableActions as Ue,isActionAvailable as qe,isIntentDispatchable as $e}from"@manifesto-ai/core";import{extractSchemaGraph as We}from"@manifesto-ai/compiler";var ge=new Set(["$item","$index","$array"]);function Ye(e){let t=e.computed.fields,n=new Map;function a(r,u){let i=n.get(r);if(i!==void 0)return i;if(u.has(r))return!1;u.add(r);let c=t[r];if(!c)return u.delete(r),n.set(r,!0),!0;for(let s of De(c.expr)){if(Oe(s))return u.delete(r),n.set(r,!1),!1;let l=je(s,t);if(l!==null&&!a(l,u))return u.delete(r),n.set(r,!1),!1}return u.delete(r),n.set(r,!0),!0}return{visibleComputedKeys:Object.keys(t).filter(r=>a(r,new Set))}}function H(e,t){return{data:Ce(e.data),computed:Me(e.computed,t),system:{status:e.system.status,lastError:e.system.lastError},meta:{schemaHash:e.meta.schemaHash}}}function Qe(e,t){return H(e,t)}function x(e){return ee(structuredClone(e))}function Z(e,t){return we(e,t)}function Ce(e){if(e==null)return e;if(Array.isArray(e)||typeof e!="object")return structuredClone(e);let t={};for(let[n,a]of Object.entries(e))n.startsWith("$")||(t[n]=a);return structuredClone(t)}function Me(e,t){let n={};for(let a of t.visibleComputedKeys)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a]);return structuredClone(n)}function je(e,t){if(Object.prototype.hasOwnProperty.call(t,e))return e;if(!e.startsWith("computed."))return null;let n=e.slice(9);return Object.prototype.hasOwnProperty.call(t,n)?n:null}function ke(e){return e.startsWith("/")?e.slice(1).replace(/\//g,"."):e}function Oe(e){let t=ke(e),n=t.startsWith("data.")?t.slice(5):t,o=/^([^.[\]]+)/.exec(n)?.[1]??"";return o.startsWith("$")?!ge.has(o):!1}function De(e){let t=[],n=new WeakSet,a=o=>{if(o==null)return;if(Array.isArray(o)){o.forEach(a);return}if(typeof o!="object")return;let r=o;if(!n.has(r)&&(n.add(r),r.kind!=="lit")){if(r.kind==="get"&&typeof r.path=="string"){t.push(r.path);return}for(let u of Object.values(r))a(u)}};return a(e),t}function we(e,t){return O(e,t,new WeakMap)}function O(e,t,n){if(Object.is(e,t))return!0;if(typeof e!=typeof t)return!1;if(e===null||t===null)return e===t;if(typeof e!="object"||typeof t!="object")return!1;let a=e,o=t,r=Object.prototype.toString.call(a),u=Object.prototype.toString.call(o);if(r!==u)return!1;let i=n.get(a);if(i?.has(o))return!0;if(i||(i=new WeakSet,n.set(a,i)),i.add(o),Array.isArray(a)&&Array.isArray(o)){if(a.length!==o.length)return!1;for(let l=0;l<a.length;l+=1){let y=Object.prototype.hasOwnProperty.call(a,l),f=Object.prototype.hasOwnProperty.call(o,l);if(y!==f||y&&!O(a[l],o[l],n))return!1}return!0}if(a instanceof Date&&o instanceof Date)return a.getTime()===o.getTime();if(a instanceof RegExp&&o instanceof RegExp)return a.source===o.source&&a.flags===o.flags;if(ArrayBuffer.isView(a)&&ArrayBuffer.isView(o)){if(a.constructor!==o.constructor||a.byteLength!==o.byteLength)return!1;let l=new Uint8Array(a.buffer,a.byteOffset,a.byteLength),y=new Uint8Array(o.buffer,o.byteOffset,o.byteLength);return l.every((f,S)=>f===y[S])}if(a instanceof ArrayBuffer&&o instanceof ArrayBuffer){if(a.byteLength!==o.byteLength)return!1;let l=new Uint8Array(a),y=new Uint8Array(o);return l.every((f,S)=>f===y[S])}if(a instanceof Map&&o instanceof Map){if(a.size!==o.size)return!1;let l=Array.from(a.entries()),y=Array.from(o.entries());return l.every(([f,S],b)=>{let v=y[b];if(!v)return!1;let[A,M]=v;return O(f,A,n)&&O(S,M,n)})}if(a instanceof Set&&o instanceof Set){if(a.size!==o.size)return!1;let l=Array.from(a.values()),y=Array.from(o.values());return l.every((f,S)=>O(f,y[S],n))}let c=Y(a),s=Y(o);if(c.length!==s.length)return!1;for(let l=0;l<c.length;l+=1){let y=c[l],f=s[l];if(y!==f)return!1;let S=a[y],b=o[f];if(!O(S,b,n))return!1}return!0}function Y(e){return Object.keys(e).filter(t=>e[t]!==void 0).sort()}function ee(e,t=new WeakSet){if(e==null||typeof e!="object")return e;if(Q(e))return te(e);let n=e;if(t.has(n)||Object.isFrozen(e))return e;t.add(n);for(let a of Reflect.ownKeys(n)){let o=n[a];if(Q(o)){Ne(n,a,o);continue}ee(o,t)}return Object.freeze(e)}function Q(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)}function te(e){return structuredClone(e)}function Ne(e,t,n){let a=Object.getOwnPropertyDescriptor(e,t);!a||!("value"in a)||Object.defineProperty(e,t,{enumerable:a.enumerable??!0,configurable:!1,get(){return te(n)}})}var V=Symbol("manifesto-sdk.action-param-names"),Pe=Symbol("manifesto-sdk.action-single-param-object-value"),_=Symbol("manifesto-sdk.runtime-kernel-factory"),P=Symbol("manifesto-sdk.activation-state"),j=Symbol("manifesto-sdk.extension-kernel");var Ke=/^(state|computed|action):.+$/;function U(e){let t=new Set(e.nodes.map(i=>i.id)),n=new Map,a=new Map,o=(i,c,s)=>{let l=i.get(c);if(l){l.add(s);return}i.set(c,new Set([s]))};for(let i of e.edges)o(n,i.from,i.to),o(a,i.to,i.from);let r=i=>{let c=Object.freeze({nodes:Object.freeze(e.nodes.filter(s=>i.has(s.id))),edges:Object.freeze(e.edges.filter(s=>i.has(s.from)&&i.has(s.to)))});return U(c)},u=(i,c)=>{let s=Le(i,t),l=[s],y=new Set([s]),f=c==="incoming"?a:n;for(;l.length>0;){let S=l.shift();if(S)for(let b of f.get(S)??[])y.has(b)||(y.add(b),l.push(b))}return r(y)};return Object.freeze({nodes:e.nodes,edges:e.edges,traceUp(i){return u(i,"incoming")},traceDown(i){return u(i,"outgoing")}})}function Le(e,t){if(typeof e=="string"){if(!Ke.test(e))throw new E("SCHEMA_ERROR",'SchemaGraph node id must use "state:<name>", "computed:<name>", or "action:<name>"');if(!t.has(e))throw new E("SCHEMA_ERROR",`Unknown SchemaGraph node id "${e}"`);return e}let n;switch(e.__kind){case"ActionRef":n=`action:${String(e.name)}`;break;case"FieldRef":n=`state:${e.name}`;break;case"ComputedRef":n=`computed:${e.name}`;break;default:throw new E("SCHEMA_ERROR","Unsupported SchemaGraph ref lookup target")}if(!t.has(n))throw new E("SCHEMA_ERROR",`SchemaGraph node "${n}" is not part of the projected graph`);return n}import{validateIntentInput as Ge}from"@manifesto-ai/core";function ne(e,t,n){let a={intentId:t.intentId??"",intent:t,code:n.code,reason:n.message};return e("dispatch:rejected",a),a}function ae(e,t,n,a){e("dispatch:failed",{intentId:t.intentId??"",intent:t,error:n,...a!==void 0?{snapshot:a}:{}})}function oe(e,t,n){e("dispatch:completed",{intentId:t.intentId??"",intent:t,snapshot:n})}function se({getAvailableActionsFor:e,projectSnapshotFromCanonical:t}){function n(u,i){let c=e(u),s=e(i),l=Object.freeze(s.filter(f=>!c.includes(f))),y=Object.freeze(c.filter(f=>!s.includes(f)));return Object.freeze({before:c,after:s,unlocked:l,locked:y})}function a(u,i){let c=x(u),s=x(i),l=t(c),y=t(s);return Object.freeze({projected:Object.freeze({beforeSnapshot:l,afterSnapshot:y,changedPaths:K(l,y),availability:n(c,s)}),canonical:Object.freeze({beforeCanonicalSnapshot:c,afterCanonicalSnapshot:s,pendingRequirements:s.system.pendingRequirements,status:s.system.status})})}function o(u,i){let c=Fe(u),s=c;return Object.freeze({message:c.message,...typeof s.code=="string"?{code:s.code}:{},...typeof c.name=="string"?{name:c.name}:{},stage:i})}function r(u){return Object.freeze({hostTraces:x(u.traces)})}return Object.freeze({deriveExecutionOutcome:a,classifyExecutionFailure:o,createExecutionDiagnostics:r})}function K(e,t){let n=new Set,a=new WeakMap,o=(r,u,i)=>{if(Object.is(r,u))return;if(r===null||u===null){n.add(i);return}if(typeof r!="object"||typeof u!="object"){n.add(i);return}let c=r,s=u,l=a.get(c);if(l?.has(s))return;if(l?l.add(s):a.set(c,new WeakSet([s])),Array.isArray(r)||Array.isArray(u)){if(!Array.isArray(r)||!Array.isArray(u)){n.add(i);return}let f=Math.max(r.length,u.length);for(let S=0;S<f;S+=1){let b=Object.prototype.hasOwnProperty.call(r,S),v=Object.prototype.hasOwnProperty.call(u,S),A=`${i}[${S}]`;if(b!==v){n.add(A);continue}!b&&!v||o(r[S],u[S],A)}return}if(!ie(r)||!ie(u)){n.add(i);return}let y=new Set([...Object.keys(r),...Object.keys(u)]);for(let f of[...y].sort()){let S=Object.prototype.hasOwnProperty.call(r,f),b=Object.prototype.hasOwnProperty.call(u,f),v=`${i}.${f}`;if(S!==b){n.add(v);continue}o(r[f],u[f],v)}};return o(e.data,t.data,"data"),o(e.computed,t.computed,"computed"),o(e.system,t.system,"system"),o(e.meta,t.meta,"meta"),Object.freeze([...n].sort())}function ie(e){return Object.prototype.toString.call(e)==="[object Object]"}function Fe(e){return e instanceof Error?e:new Error(String(e))}function re({schema:e,ensureIntentId:t,getAvailableActionsFor:n,isActionAvailableFor:a,isIntentDispatchableFor:o,projectSnapshotFromCanonical:r,getSimulateSync:u,emitEvent:i}){function c(T,h,p){return Object.freeze({layer:T,expression:h,evaluatedResult:!1,...p!==void 0?{description:p}:{}})}function s(T,h){let p=h.type,d=e.actions[p];return d?a(T,p)?o(T,h)?Object.freeze([]):Object.freeze(d.dispatchable?[c("dispatchable",d.dispatchable,d.description)]:[]):Object.freeze(d.available?[c("available",d.available,d.description)]:[]):Object.freeze([])}function l(T){return new E("ACTION_UNAVAILABLE",`Action "${T.type}" is unavailable against the current visible snapshot`)}function y(T){return new E("INTENT_NOT_DISPATCHABLE",`Action "${T.type}" is available, but the bound intent is not dispatchable against the current visible snapshot`)}function f(T){return new E("INVALID_INPUT",T)}function S(T,h){let p=Ge(e,h);return p?f(p):null}function b(T,h){let p=t(h),d=p.type;if(!a(T,d))return{kind:"unavailable",intent:p,actionName:d};let I=S(T,p);if(I)return{kind:"invalid-input",intent:p,actionName:d,error:I};let C=s(T,p);return C.length>0?{kind:"not-dispatchable",intent:p,actionName:d,blockers:C}:{kind:"admitted",intent:p,actionName:d}}function v(T,h){return h.kind==="unavailable"?Object.freeze({kind:"blocked",actionName:h.actionName,failure:{kind:"unavailable",blockers:s(T,h.intent)}}):h.kind==="invalid-input"?Object.freeze({kind:"blocked",actionName:h.actionName,failure:{kind:"invalid_input",error:{code:"INVALID_INPUT",message:h.error.message}}}):h.kind==="not-dispatchable"?Object.freeze({kind:"blocked",actionName:h.actionName,failure:{kind:"not_dispatchable",blockers:h.blockers}}):Object.freeze({kind:"admitted",actionName:h.actionName})}function A(T,h){let p=b(T,h);if(p.kind==="unavailable")return Object.freeze({kind:"blocked",actionName:p.actionName,available:!1,dispatchable:!1,blockers:s(T,p.intent)});if(p.kind==="invalid-input")throw p.error;if(p.kind==="not-dispatchable")return Object.freeze({kind:"blocked",actionName:p.actionName,available:!0,dispatchable:!1,blockers:p.blockers});let d=u()(T,p.intent),I=r(T),C=r(d.snapshot);return Object.freeze({kind:"admitted",actionName:p.actionName,available:!0,dispatchable:!0,status:d.status,requirements:d.requirements,canonicalSnapshot:d.snapshot,snapshot:C,newAvailableActions:n(d.snapshot),changedPaths:K(I,C)})}function M(T,h){throw ne(i,T,h),h}function D(T){return M(T,l(T))}function w(T,h){return M(T,f(h))}function N(T){return M(T,y(T))}return Object.freeze({getIntentBlockersFor:s,validateIntentInputFor:S,evaluateIntentLegalityFor:b,deriveIntentAdmission:v,explainIntentFor:A,createUnavailableError:l,createNotDispatchableError:y,rejectInvalidInput:w,rejectUnavailable:D,rejectNotDispatchable:N})}function ce({setVisibleSnapshot:e,restoreVisibleSnapshot:t,getCanonicalSnapshot:n,emitEvent:a}){function o(i,c){return e(i,c)}function r(i,c){let s=o(c);return oe(a,i,s),Object.freeze({publishedSnapshot:s,publishedCanonicalSnapshot:n()})}function u(i,c,s){let l=o(s);return ae(a,i,c,l),Object.freeze({publishedSnapshot:l,publishedCanonicalSnapshot:n()})}return Object.freeze({replaceVisibleSnapshot:o,restoreVisibleSnapshot:t,publishCompletedHostResult:r,publishFailedHostResult:u})}import{apply as le,applySystemDelta as _e,computeSync as ze}from"@manifesto-ai/core";import{getHostState as Be}from"@manifesto-ai/host";function pe(e,t){return{...e,timestamp:t,children:e.children.map(n=>pe(n,t))}}function He(e){let t={};function n(a){t[a.id]=a,a.children.forEach(n)}return n(e),t}function Ve(e,t){let n=pe(e.root,t);return{...e,duration:0,root:n,nodes:He(n)}}function ue({schema:e,hostContextProvider:t,evaluateIntentLegalityFor:n}){function a(i,c,s){let y=Be(i.data)?.intentSlots??{},f=c.input===void 0?{type:c.type}:{type:c.type,input:c.input};return le(e,i,[{op:"merge",path:[{kind:"prop",name:"$host"}],value:{intentSlots:{...y,[c.intentId]:f}}}],s)}function o(i){return new E("ACTION_UNAVAILABLE",`Action "${i.type}" is unavailable against the provided canonical snapshot`)}function r(i){return new E("INTENT_NOT_DISPATCHABLE",`Action "${i.type}" is available, but the bound intent is not dispatchable against the provided canonical snapshot`)}return Object.freeze({withHostIntentSlot:a,createSimulationUnavailableError:o,createSimulationNotDispatchableError:r,simulateSync:(i,c)=>{let s=n(i,c);if(s.kind==="unavailable")throw o(s.intent);if(s.kind==="invalid-input")throw s.error;if(s.kind==="not-dispatchable")throw r(s.intent);let l=s.intent,y=t.createFrozenContext(l.intentId),f=a(structuredClone(i),l,y),S=ze(e,f,l,y),b=le(e,f,S.patches,y),v=_e(b,S.systemDelta);return Object.freeze({snapshot:x(v),patches:x(S.patches),systemDelta:x(S.systemDelta),status:S.status,requirements:x(S.systemDelta.addRequirements),diagnostics:Object.freeze({trace:x(Ve(S.trace,i.meta.timestamp))})})}})}function de({host:e,initialCanonicalSnapshot:t,projectSnapshotFromCanonical:n}){let a=structuredClone(t),o=n(a),r=x(a),u=Promise.resolve(),i=!1,c=new Set,s=new Map;function l(h,p){if(i)return()=>{};let d,I=!1;try{d=h(o),I=!0}catch{d=void 0,I=!1}let C={selector:h,listener:p,lastValue:d,initialized:I};return c.add(C),()=>{c.delete(C)}}function y(h,p){if(i)return()=>{};let d=s.get(h);return d||(d=new Set,s.set(h,d)),d.add(p),()=>{d?.delete(p)}}function f(){return o}function S(){return r}function b(){return structuredClone(a)}function v(h,p){a=structuredClone(h),e.reset(structuredClone(a)),r=x(a);let d=n(a),I=!Z(d,o);return I&&(o=d),p?.notify!==!1&&I&&T(o),o}function A(){e.reset(structuredClone(a))}function M(h,p){let d=s.get(h);if(d)for(let I of d)try{I(p)}catch{}}function D(h){let p=u.catch(()=>{}).then(h);return u=p.then(()=>{},()=>{}),p}function w(){i||(i=!0,c.clear(),s.clear())}function N(){return i}function T(h){for(let p of c){let d;try{d=p.selector(h)}catch{continue}if(!(p.initialized&&Object.is(p.lastValue,d))){p.lastValue=d,p.initialized=!0;try{p.listener(d)}catch{}}}}return{subscribe:l,on:y,getSnapshot:f,getCanonicalSnapshot:S,getVisibleCoreSnapshot:b,setVisibleSnapshot:v,restoreVisibleSnapshot:A,emitEvent:M,enqueue:D,dispose:w,isDisposed:N}}function fe(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function Xe(e){if(e.params)return e.params;let t=e.input;return!t||t.type!=="object"||!t.fields?[]:Object.keys(t.fields)}function Je({schema:e,projectionPlan:t,host:n,hostContextProvider:a,MEL:o,createIntent:r}){let u=n.getSnapshot();if(!u)throw new E("SCHEMA_ERROR","Host failed to initialize its genesis snapshot");function i(m){return x(H(m,t))}let c=de({host:n,initialCanonicalSnapshot:u,projectSnapshotFromCanonical:i}),{subscribe:s,on:l,getSnapshot:y,getCanonicalSnapshot:f,getVisibleCoreSnapshot:S,setVisibleSnapshot:b,restoreVisibleSnapshot:v,emitEvent:A,enqueue:M,dispose:D,isDisposed:w}=c,N=U(We(e)),T=Object.keys(e.actions),h=Object.freeze(Object.fromEntries(T.map(m=>{let R=e.actions[m],J=o.actions[m]?.[V],Ae=Object.freeze(Array.isArray(J)?[...J]:Xe(R));return[m,Object.freeze({name:m,params:Ae,input:R.input,description:R.description,hasDispatchableGate:R.dispatchable!==void 0})]}))),p=Object.freeze(T.map(m=>h[m]));function d(m){return Object.freeze([...Ue(e,m)])}let I=se({getAvailableActionsFor:d,projectSnapshotFromCanonical:i});function C(){return d(f())}let ye=(m=>m!==void 0?h[String(m)]:p);function L(m,R){return qe(e,m,String(R))}function Te(m){return L(f(),m)}function F(m,R){return $e(e,m,R)}let Se=((m,...R)=>F(f(),r(m,...R)));function q(m){return m.intentId&&m.intentId.length>0?m:{...m,intentId:fe()}}async function be(m,R){return n.dispatch(m,R)}let z=null,g=re({schema:e,ensureIntentId:q,getAvailableActionsFor:d,isActionAvailableFor:L,isIntentDispatchableFor:F,projectSnapshotFromCanonical:i,getSimulateSync:()=>{if(!z)throw new E("SCHEMA_ERROR","Runtime simulation surface is not initialized");return z},emitEvent:A}),G=ue({schema:e,hostContextProvider:a,evaluateIntentLegalityFor:g.evaluateIntentLegalityFor});z=G.simulateSync;let $=ce({setVisibleSnapshot:b,restoreVisibleSnapshot:v,getCanonicalSnapshot:f,emitEvent:A}),W=g.getIntentBlockersFor,Re=((m,...R)=>W(f(),r(m,...R))),Ee=G.simulateSync;function Ie(m){let R=i(m.snapshot);return Object.freeze({snapshot:R,changedPaths:K(y(),R),newAvailableActions:d(m.snapshot),requirements:m.requirements,status:m.status,diagnostics:m.diagnostics})}let X=(m=>Ie(G.simulateSync(f(),m))),ve=((m,...R)=>X(r(m,...R))),xe=Object.freeze({MEL:o,schema:e,createIntent:r,getCanonicalSnapshot:f,projectSnapshot:m=>i(m),simulateSync:(m,R)=>{let k=G.simulateSync(m,R);return Object.freeze({snapshot:k.snapshot,patches:k.patches,requirements:k.requirements,status:k.status,diagnostics:k.diagnostics})},getAvailableActionsFor:d,isActionAvailableFor:L,isIntentDispatchableFor:F,explainIntentFor:g.explainIntentFor});return{schema:e,MEL:o,createIntent:r,subscribe:s,on:l,getSnapshot:y,getAvailableActionsFor:d,getAvailableActions:C,getIntentBlockersFor:W,getActionMetadata:ye,isActionAvailableFor:L,isActionAvailable:Te,isIntentDispatchableFor:F,isIntentDispatchable:Se,getIntentBlockers:Re,getSchemaGraph(){return N},simulateSync:Ee,simulate:ve,simulateIntent:X,dispose:D,isDisposed:w,getCanonicalSnapshot:f,getVisibleCoreSnapshot:S,setVisibleSnapshot:$.replaceVisibleSnapshot,restoreVisibleSnapshot:$.restoreVisibleSnapshot,emitEvent:A,enqueue:M,ensureIntentId:q,executeHost:be,validateIntentInputFor:g.validateIntentInputFor,evaluateIntentLegalityFor:g.evaluateIntentLegalityFor,deriveIntentAdmission:g.deriveIntentAdmission,deriveExecutionOutcome:I.deriveExecutionOutcome,classifyExecutionFailure:I.classifyExecutionFailure,createExecutionDiagnostics:I.createExecutionDiagnostics,createUnavailableError:g.createUnavailableError,createNotDispatchableError:g.createNotDispatchableError,rejectInvalidInput:g.rejectInvalidInput,rejectUnavailable:g.rejectUnavailable,rejectNotDispatchable:g.rejectNotDispatchable,[j]:xe}}function Gt(e,t,n){Object.defineProperty(e,_,{enumerable:!1,configurable:!1,writable:!1,value:t});let a=n??me(e)??{activated:!1};return me(e)||Object.defineProperty(e,P,{enumerable:!1,configurable:!1,writable:!1,value:a}),e}function _t(e){let n=e[_];if(typeof n!="function")throw new E("SCHEMA_ERROR","ComposableManifesto is missing its runtime kernel factory");return n}function zt(e,t){return Object.defineProperty(e,j,{enumerable:!1,configurable:!1,writable:!1,value:t[j]}),e}function Bt(e){let n=e[j];if(!n)throw new E("SCHEMA_ERROR","Activated runtime is missing its extension kernel");return n}function he(e){let n=e[P];if(!n)throw new E("SCHEMA_ERROR","ComposableManifesto is missing its activation state");return n}function Ht(e){if(he(e).activated)throw new B}function Vt(e){let t=he(e);if(t.activated)throw new B;t.activated=!0}function me(e){return e[P]??null}export{V as a,Pe as b,j as c,Ye as d,Qe as e,x as f,ne as g,ae as h,ce as i,fe as j,Je as k,Gt as l,_t as m,zt as n,Bt as o,he as p,Ht as q,Vt as r};
@@ -1 +0,0 @@
1
- import{c as y,g as S,h as b,i as E,n as I}from"./chunk-BSGOCNTO.js";import{a as m,d as p}from"./chunk-BDIXNUQ3.js";async function f(t,i,d,h){let s=t.getCanonicalSnapshot(),a=i.projectSnapshot(s),e=t.evaluateIntentLegalityFor(s,h),u=t.deriveIntentAdmission(s,e);if(e.kind!=="admitted"){let r=u,c=j(t,e),l=S(t.emitEvent,e.intent,c);return{kind:"rejected",intent:e.intent,admission:r,beforeSnapshot:a,beforeCanonicalSnapshot:s,rejection:l,rejectionError:c}}let n=u,o;try{o=await t.executeHost(e.intent)}catch(r){let c=g(r);return b(t.emitEvent,e.intent,c),{kind:"failed",intent:e.intent,admission:n,beforeSnapshot:a,beforeCanonicalSnapshot:s,failure:c,errorInfo:t.classifyExecutionFailure(c,"host"),published:!1}}let T=t.createExecutionDiagnostics(o);if(o.status==="error"){let r=o.error??new m("HOST_ERROR","Host dispatch failed"),{publishedSnapshot:c,publishedCanonicalSnapshot:l}=d.publishFailedHostResult(e.intent,r,o.snapshot);return{kind:"failed",intent:e.intent,admission:n,beforeSnapshot:a,beforeCanonicalSnapshot:s,failure:r,errorInfo:t.classifyExecutionFailure(r,"host"),published:!0,diagnostics:T,outcome:t.deriveExecutionOutcome(s,l)}}let{publishedSnapshot:x,publishedCanonicalSnapshot:A}=d.publishCompletedHostResult(e.intent,o.snapshot);return{kind:"completed",intent:e.intent,admission:n,publishedSnapshot:x,outcome:t.deriveExecutionOutcome(s,A),diagnostics:T}}function R(t){if(t.kind==="completed")return t.publishedSnapshot;throw t.kind==="rejected"?t.rejectionError:t.failure}function D(t){return t.kind==="completed"?Object.freeze({kind:"completed",intent:t.intent,admission:t.admission,outcome:t.outcome,diagnostics:t.diagnostics}):t.kind==="rejected"?Object.freeze({kind:"rejected",intent:t.intent,admission:t.admission,beforeSnapshot:t.beforeSnapshot,beforeCanonicalSnapshot:t.beforeCanonicalSnapshot,rejection:t.rejection}):Object.freeze({kind:"failed",intent:t.intent,admission:t.admission,beforeSnapshot:t.beforeSnapshot,beforeCanonicalSnapshot:t.beforeCanonicalSnapshot,error:t.errorInfo,published:t.published,...t.diagnostics!==void 0?{diagnostics:t.diagnostics}:{},...t.outcome!==void 0?{outcome:t.outcome}:{}})}function j(t,i){if(i.kind==="unavailable")return t.createUnavailableError(i.intent);if(i.kind==="invalid-input")return i.error;if(i.kind==="not-dispatchable")return t.createNotDispatchableError(i.intent);throw new m("SDK_REPORT_ERROR","Cannot derive a rejected dispatch error for an admitted intent")}function g(t){return t instanceof Error?t:new Error(String(t))}function F(t){let i=t[y],d=E({setVisibleSnapshot:t.setVisibleSnapshot,restoreVisibleSnapshot:t.restoreVisibleSnapshot,getCanonicalSnapshot:t.getCanonicalSnapshot,emitEvent:t.emitEvent});function h(n){if(t.isDisposed())return Promise.reject(new p);let o=t.ensureIntentId(n);return t.enqueue(async()=>{if(t.isDisposed())throw new p;return R(await f(t,i,d,o))})}function s(n){if(t.isDisposed())return Promise.reject(new p);let o=t.ensureIntentId(n);return t.enqueue(async()=>{if(t.isDisposed())throw new p;return D(await f(t,i,d,o))})}function a(n){return i.explainIntentFor(t.getCanonicalSnapshot(),n)}function e(n){return a(n)}function u(n){let o=a(n);return o.kind==="blocked"?o.blockers:null}return I({createIntent:t.createIntent,dispatchAsync:h,dispatchAsyncWithReport:s,subscribe:t.subscribe,on:t.on,getSnapshot:t.getSnapshot,getCanonicalSnapshot:t.getCanonicalSnapshot,getAvailableActions:t.getAvailableActions,isIntentDispatchable:t.isIntentDispatchable,getIntentBlockers:t.getIntentBlockers,explainIntent:a,why:e,whyNot:u,getActionMetadata:t.getActionMetadata,isActionAvailable:t.isActionAvailable,getSchemaGraph:t.getSchemaGraph,simulate:t.simulate,simulateIntent:t.simulateIntent,MEL:t.MEL,schema:t.schema,dispose:t.dispose},t)}export{F as a};
@@ -1,4 +0,0 @@
1
- import { type Patch, type Snapshot as CoreSnapshot } from "@manifesto-ai/core";
2
- export declare function executeSystemGet(params: unknown, snapshot: CoreSnapshot): {
3
- patches: Patch[];
4
- };
@@ -1,7 +0,0 @@
1
- import { type ManifestoDomainShape, type ManifestoEventMap, type Snapshot, type TypedIntent } from "../types.js";
2
- import { ManifestoError } from "../errors.js";
3
- type RuntimeEmitEvent<T extends ManifestoDomainShape> = <K extends keyof ManifestoEventMap<T>>(event: K, payload: ManifestoEventMap<T>[K]) => void;
4
- export declare function emitDispatchRejectedEvent<T extends ManifestoDomainShape>(emitEvent: RuntimeEmitEvent<T>, intent: TypedIntent<T>, error: ManifestoError): ManifestoEventMap<T>["dispatch:rejected"];
5
- export declare function emitDispatchFailedEvent<T extends ManifestoDomainShape>(emitEvent: RuntimeEmitEvent<T>, intent: TypedIntent<T>, error: Error, snapshot?: Snapshot<T["state"]>): void;
6
- export declare function emitDispatchCompletedEvent<T extends ManifestoDomainShape>(emitEvent: RuntimeEmitEvent<T>, intent: TypedIntent<T>, snapshot: Snapshot<T["state"]>): void;
7
- export {};