@manifesto-ai/sdk 3.9.0 → 3.12.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/README.md CHANGED
@@ -12,6 +12,7 @@ Use the SDK when you want:
12
12
 
13
13
  - the shortest path to a running base runtime
14
14
  - typed intent creation through `MEL.actions.*`
15
+ - optional typed effect authoring through `@manifesto-ai/sdk/effects`
15
16
  - `dispatchAsync`, subscriptions, legality queries, explanation reads, dry-run simulation, and snapshot reads in one package
16
17
  - projected Snapshot reads by default, with canonical inspection available explicitly
17
18
  - safe post-activation arbitrary-snapshot tooling through `@manifesto-ai/sdk/extensions`
@@ -31,6 +32,8 @@ console.log(instance.getSnapshot().data.count);
31
32
 
32
33
  Base runtime reads cover availability, dispatchability, intent explanation, dry-run simulation, subscriptions, events, and both projected and canonical snapshot access.
33
34
 
35
+ Effect authoring helpers live on the dedicated `@manifesto-ai/sdk/effects` subpath. The root package stays centered on `createManifesto()`.
36
+
34
37
  If you need review, approval, or sealed history later, compose `@manifesto-ai/lineage` and `@manifesto-ai/governance` before `activate()`. If you need arbitrary-snapshot tooling after activation, use `@manifesto-ai/sdk/extensions`.
35
38
 
36
39
  ## Docs
@@ -0,0 +1 @@
1
+ import{a as I,d as L,e as B}from"./chunk-BDIXNUQ3.js";import{apply as ee,applySystemDelta as ze,computeSync as Ve,getAvailableActions as Fe,isActionAvailable as Ue,isIntentDispatchable as $e,validateIntentInput as qe}from"@manifesto-ai/core";import{extractSchemaGraph as We}from"@manifesto-ai/compiler";import{getHostState as Xe}from"@manifesto-ai/host";var Ne=new Set(["$item","$index","$array"]);function at(e){let n=e.computed.fields,a=new Map;function s(l,h){let r=a.get(l);if(r!==void 0)return r;if(h.has(l))return!1;h.add(l);let y=n[l];if(!y)return h.delete(l),a.set(l,!0),!0;for(let u of Ke(y.expr)){if(Ge(u))return h.delete(l),a.set(l,!1),!1;let p=Le(u,n);if(p!==null&&!s(p,h))return h.delete(l),a.set(l,!1),!1}return h.delete(l),a.set(l,!0),!0}return{visibleComputedKeys:Object.keys(n).filter(l=>s(l,new Set))}}function G(e,n){return{data:De(e.data),computed:Pe(e.computed,n),system:{status:e.system.status,lastError:e.system.lastError},meta:{schemaHash:e.meta.schemaHash}}}function ot(e,n){return G(e,n)}function w(e){return Q(structuredClone(e))}function Y(e,n){return _e(e,n)}function De(e){if(e==null)return e;if(Array.isArray(e)||typeof e!="object")return structuredClone(e);let n={};for(let[a,s]of Object.entries(e))a.startsWith("$")||(n[a]=s);return structuredClone(n)}function Pe(e,n){let a={};for(let s of n.visibleComputedKeys)Object.prototype.hasOwnProperty.call(e,s)&&(a[s]=e[s]);return structuredClone(a)}function Le(e,n){if(Object.prototype.hasOwnProperty.call(n,e))return e;if(!e.startsWith("computed."))return null;let a=e.slice(9);return Object.prototype.hasOwnProperty.call(n,a)?a:null}function Be(e){return e.startsWith("/")?e.slice(1).replace(/\//g,"."):e}function Ge(e){let n=Be(e),a=n.startsWith("data.")?n.slice(5):n,i=/^([^.[\]]+)/.exec(a)?.[1]??"";return i.startsWith("$")?!Ne.has(i):!1}function Ke(e){let n=[],a=new WeakSet,s=i=>{if(i==null)return;if(Array.isArray(i)){i.forEach(s);return}if(typeof i!="object")return;let l=i;if(!a.has(l)&&(a.add(l),l.kind!=="lit")){if(l.kind==="get"&&typeof l.path=="string"){n.push(l.path);return}for(let h of Object.values(l))s(h)}};return s(e),n}function _e(e,n){return C(e,n,new WeakMap)}function C(e,n,a){if(Object.is(e,n))return!0;if(typeof e!=typeof n)return!1;if(e===null||n===null)return e===n;if(typeof e!="object"||typeof n!="object")return!1;let s=e,i=n,l=Object.prototype.toString.call(s),h=Object.prototype.toString.call(i);if(l!==h)return!1;let r=a.get(s);if(r?.has(i))return!0;if(r||(r=new WeakSet,a.set(s,r)),r.add(i),Array.isArray(s)&&Array.isArray(i)){if(s.length!==i.length)return!1;for(let p=0;p<s.length;p+=1){let T=Object.prototype.hasOwnProperty.call(s,p),f=Object.prototype.hasOwnProperty.call(i,p);if(T!==f||T&&!C(s[p],i[p],a))return!1}return!0}if(s instanceof Date&&i instanceof Date)return s.getTime()===i.getTime();if(s instanceof RegExp&&i instanceof RegExp)return s.source===i.source&&s.flags===i.flags;if(ArrayBuffer.isView(s)&&ArrayBuffer.isView(i)){if(s.constructor!==i.constructor||s.byteLength!==i.byteLength)return!1;let p=new Uint8Array(s.buffer,s.byteOffset,s.byteLength),T=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);return p.every((f,m)=>f===T[m])}if(s instanceof ArrayBuffer&&i instanceof ArrayBuffer){if(s.byteLength!==i.byteLength)return!1;let p=new Uint8Array(s),T=new Uint8Array(i);return p.every((f,m)=>f===T[m])}if(s instanceof Map&&i instanceof Map){if(s.size!==i.size)return!1;let p=Array.from(s.entries()),T=Array.from(i.entries());return p.every(([f,m],S)=>{let g=T[S];if(!g)return!1;let[v,E]=g;return C(f,v,a)&&C(m,E,a)})}if(s instanceof Set&&i instanceof Set){if(s.size!==i.size)return!1;let p=Array.from(s.values()),T=Array.from(i.values());return p.every((f,m)=>C(f,T[m],a))}let y=X(s),u=X(i);if(y.length!==u.length)return!1;for(let p=0;p<y.length;p+=1){let T=y[p],f=u[p];if(T!==f)return!1;let m=s[T],S=i[f];if(!C(m,S,a))return!1}return!0}function X(e){return Object.keys(e).filter(n=>e[n]!==void 0).sort()}function Q(e,n=new WeakSet){if(e==null||typeof e!="object")return e;if(J(e))return Z(e);let a=e;if(n.has(a)||Object.isFrozen(e))return e;n.add(a);for(let s of Reflect.ownKeys(a)){let i=a[s];if(J(i)){He(a,s,i);continue}Q(i,n)}return Object.freeze(e)}function J(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)}function Z(e){return structuredClone(e)}function He(e,n,a){let s=Object.getOwnPropertyDescriptor(e,n);!s||!("value"in s)||Object.defineProperty(e,n,{enumerable:s.enumerable??!0,configurable:!1,get(){return Z(a)}})}var Je=Symbol("manifesto-sdk.action-param-names"),dt=Symbol("manifesto-sdk.action-single-param-object-value"),oe=Symbol("manifesto-sdk.runtime-kernel-factory"),K=Symbol("manifesto-sdk.activation-state"),M=Symbol("manifesto-sdk.extension-kernel"),Ye=/^(state|computed|action):.+$/;function re(e){let n=new Set(e.nodes.map(r=>r.id)),a=new Map,s=new Map,i=(r,y,u)=>{let p=r.get(y);if(p){p.add(u);return}r.set(y,new Set([u]))};for(let r of e.edges)i(a,r.from,r.to),i(s,r.to,r.from);let l=r=>{let y=Object.freeze({nodes:Object.freeze(e.nodes.filter(u=>r.has(u.id))),edges:Object.freeze(e.edges.filter(u=>r.has(u.from)&&r.has(u.to)))});return re(y)},h=(r,y)=>{let u=Qe(r,n),p=[u],T=new Set([u]),f=y==="incoming"?s:a;for(;p.length>0;){let m=p.shift();if(m)for(let S of f.get(m)??[])T.has(S)||(T.add(S),p.push(S))}return l(T)};return Object.freeze({nodes:e.nodes,edges:e.edges,traceUp(r){return h(r,"incoming")},traceDown(r){return h(r,"outgoing")}})}function Qe(e,n){if(typeof e=="string"){if(!Ye.test(e))throw new I("SCHEMA_ERROR",'SchemaGraph node id must use "state:<name>", "computed:<name>", or "action:<name>"');if(!n.has(e))throw new I("SCHEMA_ERROR",`Unknown SchemaGraph node id "${e}"`);return e}let a;switch(e.__kind){case"ActionRef":a=`action:${String(e.name)}`;break;case"FieldRef":a=`state:${e.name}`;break;case"ComputedRef":a=`computed:${e.name}`;break;default:throw new I("SCHEMA_ERROR","Unsupported SchemaGraph ref lookup target")}if(!n.has(a))throw new I("SCHEMA_ERROR",`SchemaGraph node "${a}" is not part of the projected graph`);return a}function te(e,n){let a=new Set,s=new WeakMap,i=(l,h,r)=>{if(Object.is(l,h))return;if(l===null||h===null){a.add(r);return}if(typeof l!="object"||typeof h!="object"){a.add(r);return}let y=l,u=h,p=s.get(y);if(p?.has(u))return;if(p?p.add(u):s.set(y,new WeakSet([u])),Array.isArray(l)||Array.isArray(h)){if(!Array.isArray(l)||!Array.isArray(h)){a.add(r);return}let f=Math.max(l.length,h.length);for(let m=0;m<f;m+=1){let S=Object.prototype.hasOwnProperty.call(l,m),g=Object.prototype.hasOwnProperty.call(h,m),v=`${r}[${m}]`;if(S!==g){a.add(v);continue}!S&&!g||i(l[m],h[m],v)}return}if(!ne(l)||!ne(h)){a.add(r);return}let T=new Set([...Object.keys(l),...Object.keys(h)]);for(let f of[...T].sort()){let m=Object.prototype.hasOwnProperty.call(l,f),S=Object.prototype.hasOwnProperty.call(h,f),g=`${r}.${f}`;if(m!==S){a.add(g);continue}i(l[f],h[f],g)}};return i(e.data,n.data,"data"),i(e.computed,n.computed,"computed"),i(e.system,n.system,"system"),i(e.meta,n.meta,"meta"),Object.freeze([...a].sort())}function ne(e){return Object.prototype.toString.call(e)==="[object Object]"}function ut(e,n,a){Object.defineProperty(e,oe,{enumerable:!1,configurable:!1,writable:!1,value:n});let s=a??ae(e)??{activated:!1};return ae(e)||Object.defineProperty(e,K,{enumerable:!1,configurable:!1,writable:!1,value:s}),e}function ft(e){let a=e[oe];if(typeof a!="function")throw new I("SCHEMA_ERROR","ComposableManifesto is missing its runtime kernel factory");return a}function Ze(e,n){return Object.defineProperty(e,M,{enumerable:!1,configurable:!1,writable:!1,value:n[M]}),e}function ht(e){let a=e[M];if(!a)throw new I("SCHEMA_ERROR","Activated runtime is missing its extension kernel");return a}function se(e){let a=e[K];if(!a)throw new I("SCHEMA_ERROR","ComposableManifesto is missing its activation state");return a}function yt(e){if(se(e).activated)throw new B}function Tt(e){let n=se(e);if(n.activated)throw new B;n.activated=!0}function ae(e){return e[K]??null}function et(e){if(e.params)return e.params;let n=e.input;return!n||n.type!=="object"||!n.fields?[]:Object.keys(n.fields)}function mt({schema:e,projectionPlan:n,host:a,hostContextProvider:s,MEL:i,createIntent:l}){let h=a.getSnapshot();if(!h)throw new I("SCHEMA_ERROR","Host failed to initialize its genesis snapshot");function r(t){return w(G(t,n))}let y=structuredClone(h),u=r(y),p=w(y),T=Promise.resolve(),f=!1,m=re(We(e)),S=Object.keys(e.actions),g=Object.freeze(Object.fromEntries(S.map(t=>{let c=e.actions[t],d=i.actions[t]?.[Je],b=Object.freeze(Array.isArray(d)?[...d]:et(c));return[t,Object.freeze({name:t,params:b,input:c.input,description:c.description,hasDispatchableGate:c.dispatchable!==void 0})]}))),v=Object.freeze(S.map(t=>g[t])),E=new Set,k=new Map;function ie(t,c){if(f)return()=>{};let o,d=!1;try{o=t(u),d=!0}catch{o=void 0,d=!1}let b={selector:t,listener:c,lastValue:o,initialized:d};return E.add(b),()=>{E.delete(b)}}function ce(t,c){if(f)return()=>{};let o=k.get(t);return o||(o=new Set,k.set(t,o)),o.add(c),()=>{o?.delete(c)}}function le(){return u}function _(){return p}function R(t){return Object.freeze([...Fe(e,t)])}function pe(){return R(p)}function H(t,c,o){return Object.freeze({layer:t,expression:c,evaluatedResult:!1,...o!==void 0?{description:o}:{}})}let de=(t=>t!==void 0?g[String(t)]:v);function j(t,c){return Ue(e,t,String(c))}function ue(t){return j(p,t)}function O(t,c){return $e(e,t,c)}let fe=((t,...c)=>O(p,l(t,...c)));function N(t,c){let o=c.type,d=e.actions[o];return d?j(t,o)?O(t,c)?Object.freeze([]):Object.freeze(d.dispatchable?[H("dispatchable",d.dispatchable,d.description)]:[]):Object.freeze(d.available?[H("available",d.available,d.description)]:[]):Object.freeze([])}let he=((t,...c)=>N(p,l(t,...c)));function z(t,c){let o=F(c),d=o.type;if(!j(t,d))return{kind:"unavailable",intent:o,actionName:d};let b=W(t,o);if(b)return{kind:"invalid-input",intent:o,actionName:d,error:b};let A=N(t,o);return A.length>0?{kind:"not-dispatchable",intent:o,actionName:d,blockers:A}:{kind:"admitted",intent:o,actionName:d}}function ye(t,c){let o=z(t,c);if(o.kind==="unavailable")return Object.freeze({kind:"blocked",actionName:o.actionName,available:!1,dispatchable:!1,blockers:N(t,o.intent)});if(o.kind==="invalid-input")throw o.error;if(o.kind==="not-dispatchable")return Object.freeze({kind:"blocked",actionName:o.actionName,available:!0,dispatchable:!1,blockers:o.blockers});let d=D(t,o.intent),b=r(t),A=r(d.snapshot);return Object.freeze({kind:"admitted",actionName:o.actionName,available:!0,dispatchable:!0,status:d.status,requirements:d.requirements,canonicalSnapshot:d.snapshot,snapshot:A,newAvailableActions:R(d.snapshot),changedPaths:te(b,A)})}function Te(){return m}function me(t,c,o){let b=Xe(t.data)?.intentSlots??{},A=c.input===void 0?{type:c.type}:{type:c.type,input:c.input};return ee(e,t,[{op:"merge",path:[{kind:"prop",name:"$host"}],value:{intentSlots:{...b,[c.intentId]:A}}}],o)}function Se(t){return new I("ACTION_UNAVAILABLE",`Action "${t.type}" is unavailable against the provided canonical snapshot`)}function be(t){return new I("INTENT_NOT_DISPATCHABLE",`Action "${t.type}" is available, but the bound intent is not dispatchable against the provided canonical snapshot`)}function D(t,c){let o=z(t,c);if(o.kind==="unavailable")throw Se(o.intent);if(o.kind==="invalid-input")throw o.error;if(o.kind==="not-dispatchable")throw be(o.intent);let d=o.intent,b=s.createFrozenContext(d.intentId),A=me(structuredClone(t),d,b),x=Ve(e,A,d,b),ke=ee(e,A,x.patches,b),Oe=ze(ke,x.systemDelta);return Object.freeze({snapshot:w(Oe),patches:w(x.patches),systemDelta:w(x.systemDelta),status:x.status,requirements:w(x.systemDelta.addRequirements)})}let Ie=((t,...c)=>{let o=D(p,l(t,...c)),d=r(o.snapshot);return Object.freeze({snapshot:d,changedPaths:te(u,d),newAvailableActions:R(o.snapshot),requirements:o.requirements,status:o.status})});function ge(){f||(f=!0,E.clear(),k.clear())}function Ae(t,c){y=structuredClone(t),a.reset(structuredClone(y)),p=w(y);let o=r(y),d=!Y(o,u);return d&&(u=o),c?.notify!==!1&&d&&je(u),u}function we(){a.reset(structuredClone(y))}function V(t,c){let o=k.get(t);if(o)for(let d of o)try{d(c)}catch{}}function ve(t){let c=T.catch(()=>{}).then(t);return T=c.then(()=>{},()=>{}),c}function F(t){return t.intentId&&t.intentId.length>0?t:{...t,intentId:nt()}}async function Ee(t,c){return a.dispatch(t,c)}function U(t){return new I("ACTION_UNAVAILABLE",`Action "${t.type}" is unavailable against the current visible snapshot`)}function $(t){return new I("INTENT_NOT_DISPATCHABLE",`Action "${t.type}" is available, but the bound intent is not dispatchable against the current visible snapshot`)}function q(t){return new I("INVALID_INPUT",t)}function W(t,c){let o=qe(e,c);return o?q(o):null}function P(t,c){throw V("dispatch:rejected",{intentId:t.intentId??"",intent:t,code:c.code,reason:c.message}),c}function xe(t){return P(t,U(t))}function Ce(t,c){return P(t,q(c))}function Re(t){return P(t,$(t))}function je(t){for(let c of E){let o;try{o=c.selector(t)}catch{continue}if(!(c.initialized&&Object.is(c.lastValue,o))){c.lastValue=o,c.initialized=!0;try{c.listener(o)}catch{}}}}let Me=Object.freeze({MEL:i,schema:e,createIntent:l,getCanonicalSnapshot:_,projectSnapshot:t=>r(t),simulateSync:(t,c)=>{let o=D(t,c);return Object.freeze({snapshot:o.snapshot,patches:o.patches,requirements:o.requirements,status:o.status})},getAvailableActionsFor:R,isActionAvailableFor:j,isIntentDispatchableFor:O,explainIntentFor:ye});return{schema:e,MEL:i,createIntent:l,subscribe:ie,on:ce,getSnapshot:le,getAvailableActionsFor:R,getAvailableActions:pe,getIntentBlockersFor:N,getActionMetadata:de,isActionAvailableFor:j,isActionAvailable:ue,isIntentDispatchableFor:O,isIntentDispatchable:fe,getIntentBlockers:he,getSchemaGraph:Te,simulateSync:D,simulate:Ie,dispose:ge,isDisposed:()=>f,getCanonicalSnapshot:_,getVisibleCoreSnapshot:()=>structuredClone(y),setVisibleSnapshot:Ae,restoreVisibleSnapshot:we,emitEvent:V,enqueue:ve,ensureIntentId:F,executeHost:Ee,validateIntentInputFor:W,createUnavailableError:U,createNotDispatchableError:$,rejectInvalidInput:Ce,rejectUnavailable:xe,rejectNotDispatchable:Re,[M]:Me}}function St(e){let n=e[M];async function a(r){if(e.isDisposed())throw new L;if(!e.isActionAvailable(r.type))return e.rejectUnavailable(r);let y=e.validateIntentInputFor(e.getCanonicalSnapshot(),r);if(y)return e.rejectInvalidInput(r,y.message);if(!e.isIntentDispatchableFor(e.getCanonicalSnapshot(),r))return e.rejectNotDispatchable(r);let u;try{u=await e.executeHost(r)}catch(T){let f=tt(T);throw e.emitEvent("dispatch:failed",{intentId:r.intentId??"",intent:r,error:f}),f}if(u.status==="error"){let T=e.setVisibleSnapshot(u.snapshot),f=u.error??new I("HOST_ERROR","Host dispatch failed");throw e.emitEvent("dispatch:failed",{intentId:r.intentId??"",intent:r,error:f,snapshot:T}),f}let p=e.setVisibleSnapshot(u.snapshot);return e.emitEvent("dispatch:completed",{intentId:r.intentId??"",intent:r,snapshot:p}),p}function s(r){if(e.isDisposed())return Promise.reject(new L);let y=e.ensureIntentId(r);return e.enqueue(()=>a(y))}function i(r){return n.explainIntentFor(e.getCanonicalSnapshot(),r)}function l(r){return i(r)}function h(r){let y=i(r);return y.kind==="blocked"?y.blockers:null}return Ze({createIntent:e.createIntent,dispatchAsync:s,subscribe:e.subscribe,on:e.on,getSnapshot:e.getSnapshot,getCanonicalSnapshot:e.getCanonicalSnapshot,getAvailableActions:e.getAvailableActions,isIntentDispatchable:e.isIntentDispatchable,getIntentBlockers:e.getIntentBlockers,explainIntent:i,why:l,whyNot:h,getActionMetadata:e.getActionMetadata,isActionAvailable:e.isActionAvailable,getSchemaGraph:e.getSchemaGraph,simulate:e.simulate,MEL:e.MEL,schema:e.schema,dispose:e.dispose},e)}function tt(e){return e instanceof Error?e:new Error(String(e))}function nt(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)})}export{at as a,ot as b,w as c,Je as d,dt as e,ut as f,ft as g,Ze as h,ht as i,se as j,yt as k,Tt as l,mt as m,St as n};
@@ -0,0 +1 @@
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};
@@ -0,0 +1,13 @@
1
+ import { type Patch } from "@manifesto-ai/core";
2
+ import type { EffectHandler, FieldRef, ManifestoDomainShape, TypedMEL } from "./types.js";
3
+ type MergeableObject<TValue> = TValue extends readonly unknown[] ? never : TValue extends object ? TValue : never;
4
+ type RefValue<TRef extends FieldRef<unknown>> = TRef extends FieldRef<infer TValue> ? TValue : never;
5
+ type MergeValue<TRef extends FieldRef<unknown>> = Partial<MergeableObject<RefValue<TRef>>>;
6
+ export type PatchBuilder = {
7
+ set<TRef extends FieldRef<unknown>>(ref: TRef, value: RefValue<TRef>): Patch;
8
+ unset<TRef extends FieldRef<unknown>>(ref: TRef): Patch;
9
+ merge<TRef extends FieldRef<unknown>>(ref: TRef, value: MergeValue<TRef>): Patch;
10
+ };
11
+ type DefineEffectsFactory<T extends ManifestoDomainShape> = (ops: PatchBuilder, MEL: TypedMEL<T>) => Record<string, EffectHandler>;
12
+ export declare function defineEffects<T extends ManifestoDomainShape>(factory: DefineEffectsFactory<T>): Record<string, EffectHandler>;
13
+ export {};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-BDIXNUQ3.js";import{mergePatch as u,propSegment as l,setPatch as T,unsetPatch as h}from"@manifesto-ai/core";function p(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function r(e,n){if(!n||typeof n!="object")throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() expects a FieldRef from defineEffects(..., MEL.state.*)`);let t=n;if(t.__kind!=="FieldRef"||typeof t.name!="string"||t.name.length===0)throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() expects a FieldRef from defineEffects(..., MEL.state.*)`);if(t.name.startsWith("$"))throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() does not allow reserved platform namespaces such as "${t.name}"`)}function m(e){if(!p(e))throw new a("SCHEMA_ERROR","PatchBuilder.merge() expects a plain object value")}function i(e){let n=new Map,t=Object.freeze(Object.create(null));return new Proxy(t,{get(R,f,d){if(typeof f!="string")return Reflect.get(R,f,d);let o=n.get(f);if(o)return o;let c=Object.freeze({__kind:e,name:f});return n.set(f,c),c}})}function s(e){return[l(e.name)]}var w=Object.freeze({set(e,n){return r("set",e),T(s(e),n)},unset(e){return r("unset",e),h(s(e))},merge(e,n){return r("merge",e),m(n),u(s(e),n)}}),g=Object.freeze({actions:i("ActionRef"),state:i("FieldRef"),computed:i("ComputedRef")});function E(e){return e(w,g)}export{E as defineEffects};
@@ -1 +1 @@
1
- import{a as S,h as m,n as c}from"./chunk-WQHIS7VM.js";function p(n){return n==="pending"||n==="halted"||n==="error"}function d(n){return n.__kind==="ActionRef"}function l(n){return Object.freeze([...n])}function u(n,e,t){return Object.freeze(t?[]:n.getAvailableActionsFor(e).map(i=>n.MEL.actions[i]))}function y(n,e,t,i,s){let a=p(s);return Object.freeze({intent:m(n),snapshot:e.projectSnapshot(t),canonicalSnapshot:t,availableActions:u(e,t,a),requirements:l(i),status:s,isTerminal:a})}function T(n,e){return Object.freeze({snapshot:e.snapshot,canonicalSnapshot:e.canonicalSnapshot,depth:e.depth,trajectory:e.trajectory,availableActions:e.availableActions,requirements:e.requirements,status:e.status,isTerminal:e.isTerminal,finish(){return e},next(i,...s){if(e.isTerminal)throw new S("SIMULATION_SESSION_TERMINAL","SimulationSession.next() cannot advance a terminal session");let a=d(i)?n.createIntent(i,...s):i,r=n.simulateSync(e.canonicalSnapshot,a),o=y(a,n,r.snapshot,r.requirements,r.status),f=Object.freeze({snapshot:o.snapshot,canonicalSnapshot:r.snapshot,depth:e.depth+1,trajectory:l([...e.trajectory,o]),availableActions:o.availableActions,requirements:o.requirements,status:o.status,isTerminal:o.isTerminal});return T(n,f)}})}function h(n){let e=c(n),t=e.getCanonicalSnapshot(),i=t.system.status,s=p(i);return T(e,Object.freeze({snapshot:e.projectSnapshot(t),canonicalSnapshot:t,depth:0,trajectory:Object.freeze([]),availableActions:u(e,t,s),requirements:l(t.system.pendingRequirements),status:i,isTerminal:s}))}function v(n){return c(n)}export{h as createSimulationSession,v as getExtensionKernel};
1
+ import{c as m,i as c}from"./chunk-A2FB6LGY.js";import{a as S}from"./chunk-BDIXNUQ3.js";function p(n){return n==="pending"||n==="halted"||n==="error"}function d(n){return n.__kind==="ActionRef"}function l(n){return Object.freeze([...n])}function u(n,e,t){return Object.freeze(t?[]:n.getAvailableActionsFor(e).map(i=>n.MEL.actions[i]))}function y(n,e,t,i,s){let a=p(s);return Object.freeze({intent:m(n),snapshot:e.projectSnapshot(t),canonicalSnapshot:t,availableActions:u(e,t,a),requirements:l(i),status:s,isTerminal:a})}function T(n,e){return Object.freeze({snapshot:e.snapshot,canonicalSnapshot:e.canonicalSnapshot,depth:e.depth,trajectory:e.trajectory,availableActions:e.availableActions,requirements:e.requirements,status:e.status,isTerminal:e.isTerminal,finish(){return e},next(i,...s){if(e.isTerminal)throw new S("SIMULATION_SESSION_TERMINAL","SimulationSession.next() cannot advance a terminal session");let a=d(i)?n.createIntent(i,...s):i,r=n.simulateSync(e.canonicalSnapshot,a),o=y(a,n,r.snapshot,r.requirements,r.status),f=Object.freeze({snapshot:o.snapshot,canonicalSnapshot:r.snapshot,depth:e.depth+1,trajectory:l([...e.trajectory,o]),availableActions:o.availableActions,requirements:o.requirements,status:o.status,isTerminal:o.isTerminal});return T(n,f)}})}function h(n){let e=c(n),t=e.getCanonicalSnapshot(),i=t.system.status,s=p(i);return T(e,Object.freeze({snapshot:e.projectSnapshot(t),canonicalSnapshot:t,depth:0,trajectory:Object.freeze([]),availableActions:u(e,t,s),requirements:l(t.system.pendingRequirements),status:i,isTerminal:s}))}function v(n){return c(n)}export{h as createSimulationSession,v as getExtensionKernel};
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as d,b as h,c as y,d as H,e as N,f as R,g as M,h as x,i as m,j as b,k as O,q as A,r as g,s as T}from"./chunk-WQHIS7VM.js";import{createHostContextProvider as G,createHost as z,defaultRuntime as V}from"@manifesto-ai/host";import{createIntent as B,extractDefaults as F,hashSchemaSync as K,semanticPathToPatchPath as U}from"@manifesto-ai/core";import{compileMelDomain as q,parse as W,tokenize as J}from"@manifesto-ai/compiler";var S="system.get",w="system.",X=Object.freeze({__baseLaws:!0});function Y(e,t){if(S in t)throw new h(S);let n=Q(e);te(n.schema);let a={_laws:X,schema:n.schema,activate(){A(a);let o=D(n.schema,n.projectionPlan,t);return T(g({schema:n.schema,projectionPlan:n.projectionPlan,host:o.host,hostContextProvider:o.contextProvider,MEL:k(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:C()}))}};return O(a,()=>{let o=D(n.schema,n.projectionPlan,t);return g({schema:n.schema,projectionPlan:n.projectionPlan,host:o.host,hostContextProvider:o.contextProvider,MEL:k(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:C()})})}function Q(e){let t=typeof e=="string"?Z(e):{schema:e,actionParamMetadata:I(e),actionSingleParamObjectValueMetadata:_(e)},n=ee(t.schema);return{schema:n,actionParamMetadata:t.actionParamMetadata,actionSingleParamObjectValueMetadata:t.actionSingleParamObjectValueMetadata,projectionPlan:R(n)}}function Z(e){let t=q(e,{mode:"domain"});if(t.errors.length>0){let a=t.errors.map(o=>{let s=o.location;if(!s||s.start.line===0&&s.start.column===0)return`[${o.code}] ${o.message}`;let r=`[${o.code}] ${o.message} (${s.start.line}:${s.start.column})`,i=e.split(`
1
+ import{a as R,b as M,c as x,d as m,e as b,f as O,l as A,m as g,n as T}from"./chunk-A2FB6LGY.js";import{a as d,b as h,c as y,d as H,e as N}from"./chunk-BDIXNUQ3.js";import{createHostContextProvider as G,createHost as z,defaultRuntime as V}from"@manifesto-ai/host";import{createIntent as B,extractDefaults as F,hashSchemaSync as K,semanticPathToPatchPath as U}from"@manifesto-ai/core";import{compileMelDomain as q,parse as W,tokenize as J}from"@manifesto-ai/compiler";var S="system.get",w="system.",X=Object.freeze({__baseLaws:!0});function Y(e,t){if(S in t)throw new h(S);let n=Q(e);te(n.schema);let a={_laws:X,schema:n.schema,activate(){A(a);let o=D(n.schema,n.projectionPlan,t);return T(g({schema:n.schema,projectionPlan:n.projectionPlan,host:o.host,hostContextProvider:o.contextProvider,MEL:k(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:C()}))}};return O(a,()=>{let o=D(n.schema,n.projectionPlan,t);return g({schema:n.schema,projectionPlan:n.projectionPlan,host:o.host,hostContextProvider:o.contextProvider,MEL:k(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:C()})})}function Q(e){let t=typeof e=="string"?Z(e):{schema:e,actionParamMetadata:I(e),actionSingleParamObjectValueMetadata:_(e)},n=ee(t.schema);return{schema:n,actionParamMetadata:t.actionParamMetadata,actionSingleParamObjectValueMetadata:t.actionSingleParamObjectValueMetadata,projectionPlan:R(n)}}function Z(e){let t=q(e,{mode:"domain"});if(t.errors.length>0){let a=t.errors.map(o=>{let s=o.location;if(!s||s.start.line===0&&s.start.column===0)return`[${o.code}] ${o.message}`;let r=`[${o.code}] ${o.message} (${s.start.line}:${s.start.column})`,i=e.split(`
2
2
  `)[s.start.line-1];if(!i)return r;let l=String(s.start.line).padStart(4," "),c=Math.max(1,s.end.line===s.start.line?Math.min(s.end.column-s.start.column,Math.max(1,i.length-s.start.column+1)):1),u=" ".repeat(l.length+3+s.start.column-1);return`${r}
3
3
  ${l} | ${i}
4
4
  ${u}${"^".repeat(c)}`}).join(`
package/dist/provider.js CHANGED
@@ -1 +1 @@
1
- import{k as t,l as e,m as a,o as n,p as o,q as i,r}from"./chunk-WQHIS7VM.js";export{i as activateComposable,o as assertComposableNotActivated,a as attachExtensionKernel,t as attachRuntimeKernelFactory,r as createRuntimeKernel,n as getActivationState,e as getRuntimeKernelFactory};
1
+ import{f as t,g as e,h as a,j as n,k as o,l as i,m as r}from"./chunk-A2FB6LGY.js";import"./chunk-BDIXNUQ3.js";export{i as activateComposable,o as assertComposableNotActivated,a as attachExtensionKernel,t as attachRuntimeKernelFactory,r as createRuntimeKernel,n as getActivationState,e as getRuntimeKernelFactory};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifesto-ai/sdk",
3
- "version": "3.9.0",
3
+ "version": "3.12.1",
4
4
  "description": "Manifesto SDK - Activation-first public API for the base runtime",
5
5
  "author": "eggplantiny <eggplantiny@gmail.com>",
6
6
  "license": "MIT",
@@ -30,6 +30,10 @@
30
30
  "types": "./dist/index.d.ts",
31
31
  "import": "./dist/index.js"
32
32
  },
33
+ "./effects": {
34
+ "types": "./dist/effects.d.ts",
35
+ "import": "./dist/effects.js"
36
+ },
33
37
  "./extensions": {
34
38
  "types": "./dist/extensions.d.ts",
35
39
  "import": "./dist/extensions.js"
@@ -43,9 +47,9 @@
43
47
  "dist"
44
48
  ],
45
49
  "dependencies": {
46
- "@manifesto-ai/compiler": "3.3.0",
47
- "@manifesto-ai/core": "2.11.0",
48
- "@manifesto-ai/host": "2.8.0"
50
+ "@manifesto-ai/compiler": "3.3.1",
51
+ "@manifesto-ai/core": "2.11.1",
52
+ "@manifesto-ai/host": "2.8.1"
49
53
  },
50
54
  "devDependencies": {
51
55
  "typescript": "^5.9.3",
@@ -1 +0,0 @@
1
- var S=class extends Error{code;constructor(n,a,r){super(a,r),this.name="ManifestoError",this.code=n}},X=class extends S{effectType;constructor(n){super("RESERVED_EFFECT",`Effect type "${n}" is reserved and cannot be overridden`),this.name="ReservedEffectError",this.effectType=n}},Y=class extends S{diagnostics;constructor(n,a){super("COMPILE_ERROR",a),this.name="CompileError",this.diagnostics=n}},M=class extends S{constructor(){super("DISPOSED","Cannot use a disposed Manifesto runtime"),this.name="DisposedError"}},O=class extends S{constructor(){super("ALREADY_ACTIVATED","ComposableManifesto.activate() may only be called once"),this.name="AlreadyActivatedError"}};import{apply as ne,applySystemDelta as Fe,computeSync as Ue,getAvailableActions as $e,isActionAvailable as qe,isIntentDispatchable as We,validateIntentInput as Xe}from"@manifesto-ai/core";import{extractSchemaGraph as Ye}from"@manifesto-ai/compiler";import{getHostState as Je}from"@manifesto-ai/host";var Pe=new Set(["$item","$index","$array"]);function st(e){let n=e.computed.fields,a=new Map;function r(l,y){let s=a.get(l);if(s!==void 0)return s;if(y.has(l))return!1;y.add(l);let h=n[l];if(!h)return y.delete(l),a.set(l,!0),!0;for(let u of He(h.expr)){if(_e(u))return y.delete(l),a.set(l,!1),!1;let d=Ge(u,n);if(d!==null&&!r(d,y))return y.delete(l),a.set(l,!1),!1}return y.delete(l),a.set(l,!0),!0}return{visibleComputedKeys:Object.keys(n).filter(l=>r(l,new Set))}}function G(e,n){return{data:Le(e.data),computed:Be(e.computed,n),system:{status:e.system.status,lastError:e.system.lastError},meta:{schemaHash:e.meta.schemaHash}}}function it(e,n){return G(e,n)}function E(e){return ee(structuredClone(e))}function Z(e,n){return ze(e,n)}function Le(e){if(e==null)return e;if(Array.isArray(e)||typeof e!="object")return structuredClone(e);let n={};for(let[a,r]of Object.entries(e))a.startsWith("$")||(n[a]=r);return structuredClone(n)}function Be(e,n){let a={};for(let r of n.visibleComputedKeys)Object.prototype.hasOwnProperty.call(e,r)&&(a[r]=e[r]);return structuredClone(a)}function Ge(e,n){if(Object.prototype.hasOwnProperty.call(n,e))return e;if(!e.startsWith("computed."))return null;let a=e.slice(9);return Object.prototype.hasOwnProperty.call(n,a)?a:null}function Ke(e){return e.startsWith("/")?e.slice(1).replace(/\//g,"."):e}function _e(e){let n=Ke(e),a=n.startsWith("data.")?n.slice(5):n,i=/^([^.[\]]+)/.exec(a)?.[1]??"";return i.startsWith("$")?!Pe.has(i):!1}function He(e){let n=[],a=new WeakSet,r=i=>{if(i==null)return;if(Array.isArray(i)){i.forEach(r);return}if(typeof i!="object")return;let l=i;if(!a.has(l)&&(a.add(l),l.kind!=="lit")){if(l.kind==="get"&&typeof l.path=="string"){n.push(l.path);return}for(let y of Object.values(l))r(y)}};return r(e),n}function ze(e,n){return C(e,n,new WeakMap)}function C(e,n,a){if(Object.is(e,n))return!0;if(typeof e!=typeof n)return!1;if(e===null||n===null)return e===n;if(typeof e!="object"||typeof n!="object")return!1;let r=e,i=n,l=Object.prototype.toString.call(r),y=Object.prototype.toString.call(i);if(l!==y)return!1;let s=a.get(r);if(s?.has(i))return!0;if(s||(s=new WeakSet,a.set(r,s)),s.add(i),Array.isArray(r)&&Array.isArray(i)){if(r.length!==i.length)return!1;for(let d=0;d<r.length;d+=1){let m=Object.prototype.hasOwnProperty.call(r,d),f=Object.prototype.hasOwnProperty.call(i,d);if(m!==f||m&&!C(r[d],i[d],a))return!1}return!0}if(r instanceof Date&&i instanceof Date)return r.getTime()===i.getTime();if(r instanceof RegExp&&i instanceof RegExp)return r.source===i.source&&r.flags===i.flags;if(ArrayBuffer.isView(r)&&ArrayBuffer.isView(i)){if(r.constructor!==i.constructor||r.byteLength!==i.byteLength)return!1;let d=new Uint8Array(r.buffer,r.byteOffset,r.byteLength),m=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);return d.every((f,T)=>f===m[T])}if(r instanceof ArrayBuffer&&i instanceof ArrayBuffer){if(r.byteLength!==i.byteLength)return!1;let d=new Uint8Array(r),m=new Uint8Array(i);return d.every((f,T)=>f===m[T])}if(r instanceof Map&&i instanceof Map){if(r.size!==i.size)return!1;let d=Array.from(r.entries()),m=Array.from(i.entries());return d.every(([f,T],b)=>{let g=m[b];if(!g)return!1;let[x,w]=g;return C(f,x,a)&&C(T,w,a)})}if(r instanceof Set&&i instanceof Set){if(r.size!==i.size)return!1;let d=Array.from(r.values()),m=Array.from(i.values());return d.every((f,T)=>C(f,m[T],a))}let h=J(r),u=J(i);if(h.length!==u.length)return!1;for(let d=0;d<h.length;d+=1){let m=h[d],f=u[d];if(m!==f)return!1;let T=r[m],b=i[f];if(!C(T,b,a))return!1}return!0}function J(e){return Object.keys(e).filter(n=>e[n]!==void 0).sort()}function ee(e,n=new WeakSet){if(e==null||typeof e!="object")return e;if(Q(e))return te(e);let a=e;if(n.has(a)||Object.isFrozen(e))return e;n.add(a);for(let r of Reflect.ownKeys(a)){let i=a[r];if(Q(i)){Ve(a,r,i);continue}ee(i,n)}return Object.freeze(e)}function Q(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)}function te(e){return structuredClone(e)}function Ve(e,n,a){let r=Object.getOwnPropertyDescriptor(e,n);!r||!("value"in r)||Object.defineProperty(e,n,{enumerable:r.enumerable??!0,configurable:!1,get(){return te(a)}})}var Qe=Symbol("manifesto-sdk.action-param-names"),yt=Symbol("manifesto-sdk.action-single-param-object-value"),se=Symbol("manifesto-sdk.runtime-kernel-factory"),K=Symbol("manifesto-sdk.activation-state"),k=Symbol("manifesto-sdk.extension-kernel"),Ze=/^(state|computed|action):.+$/;function ie(e){let n=new Set(e.nodes.map(s=>s.id)),a=new Map,r=new Map,i=(s,h,u)=>{let d=s.get(h);if(d){d.add(u);return}s.set(h,new Set([u]))};for(let s of e.edges)i(a,s.from,s.to),i(r,s.to,s.from);let l=s=>{let h=Object.freeze({nodes:Object.freeze(e.nodes.filter(u=>s.has(u.id))),edges:Object.freeze(e.edges.filter(u=>s.has(u.from)&&s.has(u.to)))});return ie(h)},y=(s,h)=>{let u=et(s,n),d=[u],m=new Set([u]),f=h==="incoming"?r:a;for(;d.length>0;){let T=d.shift();if(T)for(let b of f.get(T)??[])m.has(b)||(m.add(b),d.push(b))}return l(m)};return Object.freeze({nodes:e.nodes,edges:e.edges,traceUp(s){return y(s,"incoming")},traceDown(s){return y(s,"outgoing")}})}function et(e,n){if(typeof e=="string"){if(!Ze.test(e))throw new S("SCHEMA_ERROR",'SchemaGraph node id must use "state:<name>", "computed:<name>", or "action:<name>"');if(!n.has(e))throw new S("SCHEMA_ERROR",`Unknown SchemaGraph node id "${e}"`);return e}let a;switch(e.__kind){case"ActionRef":a=`action:${String(e.name)}`;break;case"FieldRef":a=`state:${e.name}`;break;case"ComputedRef":a=`computed:${e.name}`;break;default:throw new S("SCHEMA_ERROR","Unsupported SchemaGraph ref lookup target")}if(!n.has(a))throw new S("SCHEMA_ERROR",`SchemaGraph node "${a}" is not part of the projected graph`);return a}function ae(e,n){let a=new Set,r=new WeakMap,i=(l,y,s)=>{if(Object.is(l,y))return;if(l===null||y===null){a.add(s);return}if(typeof l!="object"||typeof y!="object"){a.add(s);return}let h=l,u=y,d=r.get(h);if(d?.has(u))return;if(d?d.add(u):r.set(h,new WeakSet([u])),Array.isArray(l)||Array.isArray(y)){if(!Array.isArray(l)||!Array.isArray(y)){a.add(s);return}let f=Math.max(l.length,y.length);for(let T=0;T<f;T+=1){let b=Object.prototype.hasOwnProperty.call(l,T),g=Object.prototype.hasOwnProperty.call(y,T),x=`${s}[${T}]`;if(b!==g){a.add(x);continue}!b&&!g||i(l[T],y[T],x)}return}if(!oe(l)||!oe(y)){a.add(s);return}let m=new Set([...Object.keys(l),...Object.keys(y)]);for(let f of[...m].sort()){let T=Object.prototype.hasOwnProperty.call(l,f),b=Object.prototype.hasOwnProperty.call(y,f),g=`${s}.${f}`;if(T!==b){a.add(g);continue}i(l[f],y[f],g)}};return i(e.data,n.data,"data"),i(e.computed,n.computed,"computed"),i(e.system,n.system,"system"),i(e.meta,n.meta,"meta"),Object.freeze([...a].sort())}function oe(e){return Object.prototype.toString.call(e)==="[object Object]"}function ht(e,n,a){Object.defineProperty(e,se,{enumerable:!1,configurable:!1,writable:!1,value:n});let r=a??re(e)??{activated:!1};return re(e)||Object.defineProperty(e,K,{enumerable:!1,configurable:!1,writable:!1,value:r}),e}function mt(e){let a=e[se];if(typeof a!="function")throw new S("SCHEMA_ERROR","ComposableManifesto is missing its runtime kernel factory");return a}function tt(e,n){return Object.defineProperty(e,k,{enumerable:!1,configurable:!1,writable:!1,value:n[k]}),e}function Tt(e){let a=e[k];if(!a)throw new S("SCHEMA_ERROR","Activated runtime is missing its extension kernel");return a}function ce(e){let a=e[K];if(!a)throw new S("SCHEMA_ERROR","ComposableManifesto is missing its activation state");return a}function St(e){if(ce(e).activated)throw new O}function bt(e){let n=ce(e);if(n.activated)throw new O;n.activated=!0}function re(e){return e[K]??null}function nt(e){if(e.params)return e.params;let n=e.input;return!n||n.type!=="object"||!n.fields?[]:Object.keys(n.fields)}function It({schema:e,projectionPlan:n,host:a,hostContextProvider:r,MEL:i,createIntent:l}){let y=a.getSnapshot();if(!y)throw new S("SCHEMA_ERROR","Host failed to initialize its genesis snapshot");function s(t){return E(G(t,n))}let h=structuredClone(y),u=s(h),d=E(h),m=Promise.resolve(),f=!1,T=ie(Ye(e)),b=Object.keys(e.actions),g=Object.freeze(Object.fromEntries(b.map(t=>{let c=e.actions[t],p=i.actions[t]?.[Qe],I=Object.freeze(Array.isArray(p)?[...p]:nt(c));return[t,Object.freeze({name:t,params:I,input:c.input,description:c.description,hasDispatchableGate:c.dispatchable!==void 0})]}))),x=Object.freeze(b.map(t=>g[t])),w=new Set,D=new Map;function le(t,c){if(f)return()=>{};let o,p=!1;try{o=t(u),p=!0}catch{o=void 0,p=!1}let I={selector:t,listener:c,lastValue:o,initialized:p};return w.add(I),()=>{w.delete(I)}}function de(t,c){if(f)return()=>{};let o=D.get(t);return o||(o=new Set,D.set(t,o)),o.add(c),()=>{o?.delete(c)}}function pe(){return u}function _(){return d}function R(t){return Object.freeze([...$e(e,t)])}function ue(){return R(d)}function H(t,c,o){return Object.freeze({layer:t,expression:c,evaluatedResult:!1,...o!==void 0?{description:o}:{}})}let fe=(t=>t!==void 0?g[String(t)]:x);function j(t,c){return qe(e,t,String(c))}function ye(t){return j(d,t)}function N(t,c){return We(e,t,c)}let he=((t,...c)=>N(d,l(t,...c)));function P(t,c){let o=c.type,p=e.actions[o];return p?j(t,o)?N(t,c)?Object.freeze([]):Object.freeze(p.dispatchable?[H("dispatchable",p.dispatchable,p.description)]:[]):Object.freeze(p.available?[H("available",p.available,p.description)]:[]):Object.freeze([])}let me=((t,...c)=>P(d,l(t,...c)));function z(t,c){let o=F(c),p=o.type;if(!j(t,p))return{kind:"unavailable",intent:o,actionName:p};let I=W(t,o);if(I)return{kind:"invalid-input",intent:o,actionName:p,error:I};let A=P(t,o);return A.length>0?{kind:"not-dispatchable",intent:o,actionName:p,blockers:A}:{kind:"admitted",intent:o,actionName:p}}function Te(t,c){let o=z(t,c);if(o.kind==="unavailable")return Object.freeze({kind:"blocked",actionName:o.actionName,available:!1,dispatchable:!1,blockers:P(t,o.intent)});if(o.kind==="invalid-input")throw o.error;if(o.kind==="not-dispatchable")return Object.freeze({kind:"blocked",actionName:o.actionName,available:!0,dispatchable:!1,blockers:o.blockers});let p=L(t,o.intent),I=s(t),A=s(p.snapshot);return Object.freeze({kind:"admitted",actionName:o.actionName,available:!0,dispatchable:!0,status:p.status,requirements:p.requirements,canonicalSnapshot:p.snapshot,snapshot:A,newAvailableActions:R(p.snapshot),changedPaths:ae(I,A)})}function Se(){return T}function be(t,c,o){let I=Je(t.data)?.intentSlots??{},A=c.input===void 0?{type:c.type}:{type:c.type,input:c.input};return ne(e,t,[{op:"merge",path:[{kind:"prop",name:"$host"}],value:{intentSlots:{...I,[c.intentId]:A}}}],o)}function Ie(t){return new S("ACTION_UNAVAILABLE",`Action "${t.type}" is unavailable against the provided canonical snapshot`)}function ge(t){return new S("INTENT_NOT_DISPATCHABLE",`Action "${t.type}" is available, but the bound intent is not dispatchable against the provided canonical snapshot`)}function L(t,c){let o=z(t,c);if(o.kind==="unavailable")throw Ie(o.intent);if(o.kind==="invalid-input")throw o.error;if(o.kind==="not-dispatchable")throw ge(o.intent);let p=o.intent,I=r.createFrozenContext(p.intentId),A=be(structuredClone(t),p,I),v=Ue(e,A,p,I),De=ne(e,A,v.patches,I),Ne=Fe(De,v.systemDelta);return Object.freeze({snapshot:E(Ne),patches:E(v.patches),systemDelta:E(v.systemDelta),status:v.status,requirements:E(v.systemDelta.addRequirements)})}let Ae=((t,...c)=>{let o=L(d,l(t,...c)),p=s(o.snapshot);return Object.freeze({snapshot:p,changedPaths:ae(u,p),newAvailableActions:R(o.snapshot),requirements:o.requirements,status:o.status})});function Ee(){f||(f=!0,w.clear(),D.clear())}function xe(t,c){h=structuredClone(t),a.reset(structuredClone(h)),d=E(h);let o=s(h),p=!Z(o,u);return p&&(u=o),c?.notify!==!1&&p&&Oe(u),u}function we(){a.reset(structuredClone(h))}function V(t,c){let o=D.get(t);if(o)for(let p of o)try{p(c)}catch{}}function ve(t){let c=m.catch(()=>{}).then(t);return m=c.then(()=>{},()=>{}),c}function F(t){return t.intentId&&t.intentId.length>0?t:{...t,intentId:ot()}}async function Ce(t,c){return a.dispatch(t,c)}function U(t){return new S("ACTION_UNAVAILABLE",`Action "${t.type}" is unavailable against the current visible snapshot`)}function $(t){return new S("INTENT_NOT_DISPATCHABLE",`Action "${t.type}" is available, but the bound intent is not dispatchable against the current visible snapshot`)}function q(t){return new S("INVALID_INPUT",t)}function W(t,c){let o=Xe(e,c);return o?q(o):null}function B(t,c){throw V("dispatch:rejected",{intentId:t.intentId??"",intent:t,code:c.code,reason:c.message}),c}function Re(t){return B(t,U(t))}function je(t,c){return B(t,q(c))}function Me(t){return B(t,$(t))}function Oe(t){for(let c of w){let o;try{o=c.selector(t)}catch{continue}if(!(c.initialized&&Object.is(c.lastValue,o))){c.lastValue=o,c.initialized=!0;try{c.listener(o)}catch{}}}}let ke=Object.freeze({MEL:i,schema:e,createIntent:l,getCanonicalSnapshot:_,projectSnapshot:t=>s(t),simulateSync:(t,c)=>{let o=L(t,c);return Object.freeze({snapshot:o.snapshot,patches:o.patches,requirements:o.requirements,status:o.status})},getAvailableActionsFor:R,isActionAvailableFor:j,isIntentDispatchableFor:N,explainIntentFor:Te});return{schema:e,MEL:i,createIntent:l,subscribe:le,on:de,getSnapshot:pe,getAvailableActionsFor:R,getAvailableActions:ue,getIntentBlockersFor:P,getActionMetadata:fe,isActionAvailableFor:j,isActionAvailable:ye,isIntentDispatchableFor:N,isIntentDispatchable:he,getIntentBlockers:me,getSchemaGraph:Se,simulateSync:L,simulate:Ae,dispose:Ee,isDisposed:()=>f,getCanonicalSnapshot:_,getVisibleCoreSnapshot:()=>structuredClone(h),setVisibleSnapshot:xe,restoreVisibleSnapshot:we,emitEvent:V,enqueue:ve,ensureIntentId:F,executeHost:Ce,validateIntentInputFor:W,createUnavailableError:U,createNotDispatchableError:$,rejectInvalidInput:je,rejectUnavailable:Re,rejectNotDispatchable:Me,[k]:ke}}function gt(e){let n=e[k];async function a(s){if(e.isDisposed())throw new M;if(!e.isActionAvailable(s.type))return e.rejectUnavailable(s);let h=e.validateIntentInputFor(e.getCanonicalSnapshot(),s);if(h)return e.rejectInvalidInput(s,h.message);if(!e.isIntentDispatchableFor(e.getCanonicalSnapshot(),s))return e.rejectNotDispatchable(s);let u;try{u=await e.executeHost(s)}catch(m){let f=at(m);throw e.emitEvent("dispatch:failed",{intentId:s.intentId??"",intent:s,error:f}),f}if(u.status==="error"){let m=e.setVisibleSnapshot(u.snapshot),f=u.error??new S("HOST_ERROR","Host dispatch failed");throw e.emitEvent("dispatch:failed",{intentId:s.intentId??"",intent:s,error:f,snapshot:m}),f}let d=e.setVisibleSnapshot(u.snapshot);return e.emitEvent("dispatch:completed",{intentId:s.intentId??"",intent:s,snapshot:d}),d}function r(s){if(e.isDisposed())return Promise.reject(new M);let h=e.ensureIntentId(s);return e.enqueue(()=>a(h))}function i(s){return n.explainIntentFor(e.getCanonicalSnapshot(),s)}function l(s){return i(s)}function y(s){let h=i(s);return h.kind==="blocked"?h.blockers:null}return tt({createIntent:e.createIntent,dispatchAsync:r,subscribe:e.subscribe,on:e.on,getSnapshot:e.getSnapshot,getCanonicalSnapshot:e.getCanonicalSnapshot,getAvailableActions:e.getAvailableActions,isIntentDispatchable:e.isIntentDispatchable,getIntentBlockers:e.getIntentBlockers,explainIntent:i,why:l,whyNot:y,getActionMetadata:e.getActionMetadata,isActionAvailable:e.isActionAvailable,getSchemaGraph:e.getSchemaGraph,simulate:e.simulate,MEL:e.MEL,schema:e.schema,dispose:e.dispose},e)}function at(e){return e instanceof Error?e:new Error(String(e))}function ot(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)})}export{S as a,X as b,Y as c,M as d,O as e,st as f,it as g,E as h,Qe as i,yt as j,ht as k,mt as l,tt as m,Tt as n,ce as o,St as p,bt as q,It as r,gt as s};