@manifesto-ai/sdk 2.3.0 → 3.1.1

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/index.d.ts CHANGED
@@ -1,426 +1,16 @@
1
- import { DomainSchema, Snapshot as Snapshot$1, Patch, Intent, SetPatch, UnsetPatch, MergePatch } from '@manifesto-ai/core';
2
- export { ComputeResult, Snapshot as CoreSnapshot, DomainSchema, ErrorValue, Intent, MergePatch, Patch, Requirement, SetPatch, TraceGraph, UnsetPatch, createCore, createIntent, createSnapshot } from '@manifesto-ai/core';
3
- export { HostOptions, HostResult } from '@manifesto-ai/host';
4
- export { CoordinatorSealGenesisParams, CoordinatorSealNextParams, ExecuteApprovedProposalInput, GovernanceEventDispatcher, GovernedWorldStore, RecoveredWorldRuntimeCompletion, ResumeExecutingProposalInput, SealResult, SealedWorldRuntimeCompletion, WorldConfig, WorldCoordinator, WorldExecutionOptions, WorldExecutionResult, WorldExecutor, WorldInstance, WorldRuntime, WorldRuntimeCompletion, WorldStoreTransaction, createWorld } from '@manifesto-ai/world';
5
-
6
1
  /**
7
- * SDK package identity and SPEC version metadata.
8
- * Used for phase tracking and compatibility verification.
9
- */
10
- type SdkManifest = {
11
- readonly name: '@manifesto-ai/sdk';
12
- readonly specVersion: '2.0.0';
13
- readonly phase: 'released';
14
- };
15
-
16
- /**
17
- * SDK Public Types
18
- *
19
- * Defines ManifestoInstance, ManifestoConfig, event types, and supporting types.
20
- *
21
- * @see SDK SPEC
22
- * @module
23
- */
24
-
25
- /**
26
- * Typed Snapshot with generic data shape.
27
- *
28
- * Core's Snapshot uses `data: unknown`. This overlay provides type-safe
29
- * access to domain data via the generic parameter T.
30
- *
31
- * The SDK does not add compatibility fields here; it transparently follows the
32
- * current Core Snapshot surface.
33
- */
34
- type Snapshot<T = unknown> = Omit<Snapshot$1, "data"> & {
35
- data: T;
36
- };
37
- /**
38
- * Context provided to effect handlers.
39
- *
40
- * Simplified from Host's EffectContext (2-param contract).
41
- */
42
- type EffectContext<T = unknown> = {
43
- /** Current snapshot (read-only). */
44
- readonly snapshot: Readonly<Snapshot<T>>;
45
- };
46
- /**
47
- * SDK-level effect handler.
48
- *
49
- * Users provide this simplified 2-param handler; SDK adapts it
50
- * to Host's 3-param EffectHandler internally.
51
- */
52
- type EffectHandler = (params: unknown, ctx: EffectContext) => Promise<readonly Patch[]>;
53
- /**
54
- * Configuration for createManifesto().
55
- *
56
- * @see SDK SPEC v2.0.0
57
- */
58
- interface ManifestoConfig<T = unknown> {
59
- /**
60
- * Required: Domain schema defining state, computed, actions.
61
- * Accepts either a compiled DomainSchema or MEL text string.
62
- *
63
- * @see SDK-CONFIG-1
64
- */
65
- schema: DomainSchema | string;
66
- /**
67
- * Required: Effect handlers keyed by effect type.
68
- *
69
- * @see SDK-CONFIG-2
70
- */
71
- effects: Record<string, EffectHandler>;
72
- /**
73
- * Optional: Guard function for intent validation.
74
- */
75
- guard?: (intent: Intent, snapshot: Snapshot<T>) => boolean;
76
- /**
77
- * Optional: Restore from persisted snapshot.
78
- */
79
- snapshot?: Snapshot<T>;
80
- }
81
- /**
82
- * Selector function — projects a value from the typed snapshot.
83
- */
84
- type Selector<T, R> = (snapshot: Snapshot<T>) => R;
85
- /**
86
- * Unsubscribe function returned by subscribe() and on().
87
- */
88
- type Unsubscribe = () => void;
89
- /**
90
- * ManifestoInstance — the sole runtime handle returned by createManifesto().
91
- *
92
- * 7 methods, no more.
93
- *
94
- * @see SDK SPEC v2.0.0
95
- */
96
- interface ManifestoInstance<T = unknown> {
97
- /**
98
- * Fire-and-forget intent dispatch.
99
- *
100
- * Enqueues the intent for serial processing. Returns immediately.
101
- *
102
- * @throws DisposedError if instance is disposed (SDK-DISPATCH-4)
103
- * @see SDK-DISPATCH-1, SDK-DISPATCH-2, SDK-DISPATCH-3
104
- */
105
- dispatch(intent: Intent): void;
106
- /**
107
- * Subscribe to state changes via selector.
108
- *
109
- * Fires only at terminal snapshot, at most once per intent.
110
- *
111
- * @see SDK-SUB-1, SDK-SUB-2, SDK-SUB-3, SDK-SUB-4
112
- */
113
- subscribe<R>(selector: Selector<T, R>, listener: (value: R) => void): Unsubscribe;
114
- /**
115
- * Listen to intent lifecycle events (telemetry channel).
116
- *
117
- * Payload type is narrowed by event name.
118
- *
119
- * @see SDK-EVENT-1, SDK-EVENT-2, SDK-EVENT-3
120
- */
121
- on<K extends ManifestoEvent>(event: K, handler: (payload: ManifestoEventMap<T>[K]) => void): Unsubscribe;
122
- /**
123
- * Check whether an action is currently dispatchable against the current snapshot.
124
- */
125
- isActionAvailable(actionName: string): boolean;
126
- /**
127
- * Return all action names that are currently dispatchable.
128
- */
129
- getAvailableActions(): readonly string[];
130
- /**
131
- * Get the current snapshot synchronously.
132
- *
133
- * @see SDK-SNAP-1
134
- */
135
- getSnapshot(): Snapshot<T>;
136
- /**
137
- * Dispose the instance and release resources.
138
- *
139
- * @see SDK-DISPOSE-1, SDK-DISPOSE-2, SDK-DISPOSE-3
140
- */
141
- dispose(): void;
142
- }
143
- /**
144
- * Typed event map — payload narrowed by event name.
145
- *
146
- * @see SDK SPEC v1.0.0 §8
147
- */
148
- interface ManifestoEventMap<T = unknown> {
149
- "dispatch:completed": {
150
- intentId: string;
151
- intent: Intent;
152
- snapshot: Snapshot<T>;
153
- };
154
- "dispatch:rejected": {
155
- intentId: string;
156
- intent: Intent;
157
- reason: string;
158
- };
159
- "dispatch:failed": {
160
- intentId: string;
161
- intent: Intent;
162
- error: Error;
163
- };
164
- }
165
- /**
166
- * Telemetry event types for the `on()` channel.
167
- *
168
- * @see SDK SPEC v1.0.0 §8
169
- */
170
- type ManifestoEvent = keyof ManifestoEventMap;
171
- /**
172
- * Union of all event payloads (for backward compatibility).
173
- *
174
- * Prefer using `ManifestoEventMap<T>[K]` with typed `on()` instead.
175
- *
176
- * @see SDK-INV-6 — intentId is always present
177
- */
178
- type ManifestoEventPayload<T = unknown> = ManifestoEventMap<T>[ManifestoEvent];
179
-
180
- /**
181
- * createManifesto() Factory
182
- *
183
- * The sole SDK-owned concept. Creates a ManifestoInstance for the default
184
- * direct-dispatch path by composing schema compilation and Host execution into
185
- * a single handle. Governed World composition remains explicit outside this
186
- * factory.
187
- *
188
- * @see SDK SPEC v1.0.0 §5
189
- * @see ADR-010
190
- * @module
191
- */
192
-
193
- /**
194
- * Create a ManifestoInstance.
195
- *
196
- * This is the sole entry point for SDK consumers. It composes the protocol
197
- * axes required for the default direct-dispatch runtime into a single handle with
198
- * 7 methods: dispatch, subscribe, on, isActionAvailable,
199
- * getAvailableActions, getSnapshot, dispose.
200
- *
201
- * @see SDK-FACTORY-1 through SDK-FACTORY-5
202
- * @see SDK-INV-1 through SDK-INV-6
203
- */
204
- declare function createManifesto<T = unknown>(config: ManifestoConfig<T>): ManifestoInstance<T>;
205
-
206
- /**
207
- * dispatchAsync() — Non-normative convenience utility
208
- *
209
- * Promise-based wrapper around dispatch() + on().
210
- * Resolves when the intent reaches a terminal state.
211
- *
212
- * @see SDK SPEC v1.0.0 §14.3
213
- * @module
214
- */
215
-
216
- /**
217
- * Error thrown when an intent is rejected by a guard.
218
- */
219
- declare class DispatchRejectedError extends Error {
220
- readonly code = "DISPATCH_REJECTED";
221
- readonly intentId: string;
222
- constructor(intentId: string, reason?: string);
223
- }
224
- /**
225
- * Dispatch an intent and wait for it to complete.
226
- *
227
- * - Resolves with the terminal Snapshot on `dispatch:completed`
228
- * - Rejects with the error on `dispatch:failed`
229
- * - Rejects with DispatchRejectedError on `dispatch:rejected`
230
- *
231
- * This is a convenience utility derived entirely from `dispatch` + `on`.
232
- * It does NOT violate the "one owned concept" rule.
233
- *
234
- * @see SDK SPEC v1.0.0 §14.3
235
- */
236
- declare function dispatchAsync<T = unknown>(instance: ManifestoInstance<T>, intent: Intent): Promise<Snapshot<T>>;
237
-
238
- /**
239
- * SDK v1.0.0 Error Types
240
- *
241
- * @see SDK SPEC v1.0.0 §12
242
- * @see SDK-ERR-1, SDK-ERR-2, SDK-ERR-3
243
- * @module
244
- */
245
- /**
246
- * Base error for all SDK errors.
247
- *
248
- * @see SDK-ERR-1
249
- */
250
- declare class ManifestoError extends Error {
251
- readonly code: string;
252
- constructor(code: string, message: string, options?: ErrorOptions);
253
- }
254
- /**
255
- * Thrown when user effects attempt to override reserved effect types (e.g. system.get).
256
- *
257
- * @see SDK-ERR-2, SDK-INV-4
258
- */
259
- declare class ReservedEffectError extends ManifestoError {
260
- readonly effectType: string;
261
- constructor(effectType: string);
262
- }
263
- /**
264
- * Thrown when MEL compilation fails. Exposes full diagnostic info.
265
- *
266
- * @see SDK-ERR-4
267
- */
268
- declare class CompileError extends ManifestoError {
269
- readonly diagnostics: readonly CompileDiagnostic[];
270
- constructor(diagnostics: readonly CompileDiagnostic[], formattedMessage: string);
271
- }
272
- /**
273
- * Minimal diagnostic shape exposed by SDK.
274
- * Matches @manifesto-ai/compiler Diagnostic but avoids hard dependency.
275
- */
276
- interface CompileDiagnostic {
277
- readonly severity: "error" | "warning" | "info";
278
- readonly code: string;
279
- readonly message: string;
280
- readonly location: {
281
- readonly start: {
282
- readonly line: number;
283
- readonly column: number;
284
- readonly offset: number;
285
- };
286
- readonly end: {
287
- readonly line: number;
288
- readonly column: number;
289
- readonly offset: number;
290
- };
291
- };
292
- readonly source?: string;
293
- readonly suggestion?: string;
294
- }
295
- /**
296
- * Thrown when dispatch is called on a disposed instance.
297
- *
298
- * @see SDK-ERR-3, SDK-DISPATCH-4
299
- */
300
- declare class DisposedError extends ManifestoError {
301
- constructor();
302
- }
303
-
304
- /**
305
- * Depth counter for recursive type operations.
306
- * Prevents infinite recursion in TypeScript's type system.
307
- *
308
- * Usage: Prev[4] = 3, Prev[3] = 2, ... Prev[0] = never
309
- */
310
- type Prev = [never, 0, 1, 2, 3, 4];
311
- /**
312
- * Extract all valid dot-separated paths from a data type.
313
- *
314
- * - Object keys become path segments
315
- * - Nested objects generate dot-separated paths (e.g. "user.name")
316
- * - Arrays, primitives, and Record<string, T> are leaf nodes
317
- * (Record sub-paths are not supported by Core's path resolution)
318
- * - Limited to 3 levels of nesting to avoid TS recursion limits
319
- * (root key + 3 nested levels = max 4 path segments)
320
- *
321
- * @example
322
- * type State = { user: { name: string; age: number }; count: number };
323
- * type P = DataPaths<State>;
324
- * // "user" | "user.name" | "user.age" | "count"
325
- */
326
- type DataPaths<T, D extends number = 3> = [D] extends [never] ? never : T extends Record<string, unknown> ? T extends unknown[] ? never : {
327
- [K in keyof T & string]: K | (NonNullable<T[K]> extends Record<string, unknown> ? NonNullable<T[K]> extends unknown[] ? never : string extends keyof NonNullable<T[K]> ? never : `${K}.${DataPaths<NonNullable<T[K]>, Prev[D]>}` : never);
328
- }[keyof T & string] : never;
329
- /**
330
- * Resolve the value type at a dot-separated path.
331
- *
332
- * @example
333
- * type State = { user: { name: string } };
334
- * type V = ValueAt<State, "user.name">; // string
335
- * type U = ValueAt<State, "user">; // { name: string }
336
- */
337
- type ValueAt<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? ValueAt<NonNullable<T[K]>, Rest> : never : P extends keyof T ? T[P] : never;
338
- /**
339
- * Paths that resolve to plain object types (valid targets for merge).
340
- * Arrays and primitives are excluded since merge performs shallow object merge.
341
- *
342
- * @example
343
- * type State = { user: { name: string }; tags: string[]; count: number };
344
- * type M = ObjectPaths<State>;
345
- * // "user" (tags and count excluded - not plain objects)
346
- */
347
- type ObjectPaths<T, D extends number = 3> = [D] extends [never] ? never : T extends Record<string, unknown> ? T extends unknown[] ? never : {
348
- [K in keyof T & string]: (NonNullable<T[K]> extends Record<string, unknown> ? NonNullable<T[K]> extends unknown[] ? never : K : never) | (NonNullable<T[K]> extends Record<string, unknown> ? NonNullable<T[K]> extends unknown[] ? never : string extends keyof NonNullable<T[K]> ? never : `${K}.${ObjectPaths<NonNullable<T[K]>, Prev[D]>}` : never);
349
- }[keyof T & string] : never;
350
- /**
351
- * Type-safe patch operations builder.
352
- *
353
- * Provides IDE autocomplete for state paths and compile-time type checking
354
- * for patch values. All methods return standard Patch objects compatible
355
- * with Core's apply() function.
356
- * System mutation convenience APIs are intentionally excluded.
357
- *
358
- * @typeParam TData - The shape of domain state (snapshot.data)
359
- */
360
- interface TypedOps<TData extends Record<string, unknown>> {
361
- /**
362
- * Create a set patch — replace value at path (create if missing).
363
- *
364
- * @example
365
- * ops.set('count', 5);
366
- * ops.set('user.name', 'Alice');
367
- */
368
- set<P extends DataPaths<TData>>(path: P, value: Exclude<ValueAt<TData, P>, undefined>): SetPatch;
369
- /**
370
- * Create an unset patch — remove property at path.
371
- *
372
- * @example
373
- * ops.unset('temporaryField');
374
- */
375
- unset<P extends DataPaths<TData>>(path: P): UnsetPatch;
376
- /**
377
- * Create a merge patch — shallow merge at object path.
378
- * Only valid for paths that resolve to plain object types.
379
- *
380
- * @example
381
- * ops.merge('user', { name: 'Bob' });
382
- */
383
- merge<P extends ObjectPaths<TData>>(path: P, value: {
384
- [K in keyof ValueAt<TData, P>]?: Exclude<ValueAt<TData, P>[K], undefined>;
385
- }): MergePatch;
386
- /**
387
- * Raw (untyped) patch creation — escape hatch for dynamic paths
388
- * or platform namespace ($*) targets.
389
- */
390
- raw: {
391
- set(path: string, value: unknown): SetPatch;
392
- unset(path: string): UnsetPatch;
393
- merge(path: string, value: Record<string, unknown>): MergePatch;
394
- };
395
- }
396
- /**
397
- * Create a type-safe patch operations builder.
398
- *
399
- * Injects the domain state type to enable:
400
- * - IDE autocomplete on all valid state paths
401
- * - Compile-time type checking of patch values
402
- * - Merge restricted to object-typed paths
403
- *
404
- * @typeParam TData - The shape of domain state (snapshot.data)
405
- *
406
- * @example
407
- * type State = {
408
- * count: number;
409
- * user: { name: string; age: number };
410
- * tags: string[];
411
- * };
412
- *
413
- * const ops = defineOps<State>();
2
+ * @manifesto-ai/sdk v3.0.0
414
3
  *
415
- * ops.set('count', 5); // OK value: number
416
- * ops.set('user.name', 'Alice'); // OK — value: string
417
- * ops.set('count', 'hello'); // TS error — expected number
418
- * ops.merge('user', { name: 'B' }); // OK — partial object merge
419
- * ops.unset('tags'); // OK
4
+ * SDK hard cut around the activation boundary.
420
5
  *
421
- * // Escape hatch for dynamic / platform paths
422
- * ops.raw.set('$host.custom', { key: 'value' });
6
+ * @see sdk-SPEC-v3.0.0-draft.md
7
+ * @see ADR-017
8
+ * @packageDocumentation
423
9
  */
424
- declare function defineOps<TData extends Record<string, unknown>>(): TypedOps<TData>;
425
-
426
- export { type CompileDiagnostic, CompileError, type DataPaths, DispatchRejectedError, DisposedError, type EffectContext, type EffectHandler, type ManifestoConfig, ManifestoError, type ManifestoEvent, type ManifestoEventMap, type ManifestoEventPayload, type ManifestoInstance, type ObjectPaths, ReservedEffectError, type SdkManifest, type Selector, type Snapshot, type TypedOps, type Unsubscribe, type ValueAt, createManifesto, defineOps, dispatchAsync };
10
+ export type { SdkManifest } from "./manifest.js";
11
+ export { createManifesto } from "./create-manifesto.js";
12
+ export type { ActivatedInstance, ActionArgs, BaseLaws, BaseComposableLaws, ComposableManifesto, ComputedRef, EffectContext, EffectHandler, FieldRef, GovernedComposableLaws, GovernanceLaws, LineageComposableLaws, LineageLaws, ManifestoBaseInstance, ManifestoDecoratedRuntimeByLaws, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, ManifestoEventPayload, ManifestoRuntimeByLaws, Selector, Snapshot, TypedActionRef, TypedCommitAsync, TypedCreateIntent, TypedDispatchAsync, TypedMEL, TypedOn, TypedSubscribe, Unsubscribe, } from "./types.js";
13
+ export { AlreadyActivatedError, CompileError, DisposedError, ManifestoError, ReservedEffectError, } from "./errors.js";
14
+ export type { CompileDiagnostic } from "./errors.js";
15
+ export type { DomainSchema, Intent, Patch, Snapshot as CoreSnapshot, } from "@manifesto-ai/core";
16
+ export { createSnapshot } from "@manifesto-ai/core";