@manifesto-ai/sdk 3.17.2 → 3.18.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.
@@ -0,0 +1 @@
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 +1 @@
1
- import{c as y,g as S,h as b,i as E,n as R}from"./chunk-7TMADY2E.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 I(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 I(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 R({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,MEL:t.MEL,schema:t.schema,dispose:t.dispose},t)}export{F as a};
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,7 +1,7 @@
1
1
  import { type ComputeStatus, type DomainSchema, type Patch, type Requirement, type Snapshot as CoreSnapshot, type SystemDelta } from "@manifesto-ai/core";
2
2
  import type { HostContextProvider, HostResult, ManifestoHost } from "@manifesto-ai/host";
3
3
  import { ManifestoError } from "../errors.js";
4
- import type { BaseLaws, CanonicalSnapshot, ComposableManifesto, DispatchBlocker, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, IntentAdmission, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, SchemaGraph, SimulationDiagnostics, Snapshot, TypedCreateIntent, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIntent, TypedIsIntentDispatchable, TypedMEL, TypedOn, TypedSimulate, TypedSubscribe } from "../types.js";
4
+ import type { BaseLaws, CanonicalSnapshot, ComposableManifesto, DispatchBlocker, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, IntentAdmission, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, SchemaGraph, SimulationDiagnostics, Snapshot, TypedCreateIntent, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIntent, TypedIsIntentDispatchable, TypedMEL, TypedOn, TypedSimulate, TypedSimulateIntent, TypedSubscribe } from "../types.js";
5
5
  import type { SnapshotProjectionPlan } from "../projection/snapshot-projection.js";
6
6
  import type { ExtensionKernel } from "../extensions-types.js";
7
7
  import type { IntentLegalityEvaluation } from "../runtime/facets.js";
@@ -36,6 +36,7 @@ export interface RuntimeKernel<T extends ManifestoDomainShape> {
36
36
  readonly getSchemaGraph: () => SchemaGraph;
37
37
  readonly simulateSync: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => SimulateResult<T>;
38
38
  readonly simulate: TypedSimulate<T>;
39
+ readonly simulateIntent: TypedSimulateIntent<T>;
39
40
  readonly dispose: () => void;
40
41
  readonly isDisposed: () => boolean;
41
42
  readonly getVisibleCoreSnapshot: () => CoreSnapshot;
@@ -60,7 +61,7 @@ export interface RuntimeKernel<T extends ManifestoDomainShape> {
60
61
  readonly rejectNotDispatchable: (intent: TypedIntent<T>) => never;
61
62
  readonly [EXTENSION_KERNEL]: ExtensionKernel<T>;
62
63
  }
63
- type RuntimePublicReadFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "schema" | "MEL" | "createIntent" | "subscribe" | "on" | "getSnapshot" | "getCanonicalSnapshot" | "getAvailableActions" | "isIntentDispatchable" | "getIntentBlockers" | "getActionMetadata" | "isActionAvailable" | "getSchemaGraph" | "simulate">;
64
+ type RuntimePublicReadFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "schema" | "MEL" | "createIntent" | "subscribe" | "on" | "getSnapshot" | "getCanonicalSnapshot" | "getAvailableActions" | "isIntentDispatchable" | "getIntentBlockers" | "getActionMetadata" | "isActionAvailable" | "getSchemaGraph" | "simulate" | "simulateIntent">;
64
65
  type RuntimeLifecycleFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "dispose" | "isDisposed" | "enqueue">;
65
66
  type RuntimeExecutionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "ensureIntentId" | "executeHost">;
66
67
  type RuntimeSealAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isActionAvailable" | "validateIntentInputFor" | "isIntentDispatchableFor" | "rejectUnavailable" | "rejectInvalidInput" | "rejectNotDispatchable">;
@@ -1 +1 @@
1
- import{f as m,o as c}from"./chunk-7TMADY2E.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};
1
+ import{f as m,o as c}from"./chunk-BSGOCNTO.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.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
  export type { SdkManifest } from "./manifest.js";
11
11
  export { createManifesto } from "./create-manifesto.js";
12
- export type { ActivatedInstance, ActionArgs, CreateIntentArgs, DispatchReport, ActionObjectBindingArgs, DispatchBlocker, AvailableActionDelta, TypedActionMetadata, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIsIntentDispatchable, BaseLaws, BaseComposableLaws, CanonicalPlatformNamespaces, CanonicalSnapshot, ComposableManifesto, ComputedRef, EffectContext, EffectHandler, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, FieldRef, GovernedComposableLaws, GovernanceLaws, IntentAdmission, IntentAdmissionFailure, IntentExplanation, InvalidInputInfo, LineageComposableLaws, LineageLaws, ManifestoBaseInstance, ManifestoDecoratedRuntimeByLaws, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, ManifestoEventPayload, ManifestoRuntimeByLaws, Selector, SimulationDiagnostics, SimulateResult, ProjectedDiff, CanonicalOutcome, SchemaGraph, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, SchemaGraphNodeRef, Snapshot, TypedActionRef, TypedCommitAsync, TypedCreateIntent, TypedDispatchAsync, TypedIntent, TypedMEL, TypedOn, TypedSimulate, TypedSubscribe, Unsubscribe, } from "./types.js";
12
+ export type { ActivatedInstance, ActionArgs, CreateIntentArgs, DispatchReport, ActionObjectBindingArgs, DispatchBlocker, AvailableActionDelta, TypedActionMetadata, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIsIntentDispatchable, BaseLaws, BaseComposableLaws, CanonicalPlatformNamespaces, CanonicalSnapshot, ComposableManifesto, ComputedRef, EffectContext, EffectHandler, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, FieldRef, GovernedComposableLaws, GovernanceLaws, IntentAdmission, IntentAdmissionFailure, IntentExplanation, InvalidInputInfo, LineageComposableLaws, LineageLaws, ManifestoBaseInstance, ManifestoDispatchRuntime, ManifestoDecoratedRuntimeByLaws, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, ManifestoEventPayload, ManifestoLegalityRuntime, ManifestoRuntimeByLaws, Selector, SimulationDiagnostics, SimulateResult, ProjectedDiff, CanonicalOutcome, SchemaGraph, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, SchemaGraphNodeRef, Snapshot, TypedActionRef, TypedCommitAsync, TypedCreateIntent, TypedDispatchAsync, TypedIntent, TypedMEL, TypedOn, TypedSimulate, TypedSimulateIntent, TypedSubscribe, Unsubscribe, } from "./types.js";
13
13
  export { AlreadyActivatedError, CompileError, DisposedError, ManifestoError, ReservedEffectError, } from "./errors.js";
14
14
  export type { CompileDiagnostic } from "./errors.js";
15
15
  export type { DomainSchema, Intent, Patch, Snapshot as CoreSnapshot, } from "@manifesto-ai/core";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import{a as v}from"./chunk-EPGBNDYU.js";import{a as d,b as h,d as w,e as x,f as I,j as y,k as E,l as k,r as _}from"./chunk-7TMADY2E.js";import{a as l,b,c as g,d as B,e as F}from"./chunk-BDIXNUQ3.js";import{createHostContextProvider as J,createHost as Y,defaultRuntime as X}from"@manifesto-ai/host";import{extractDefaults as Q}from"@manifesto-ai/core";import{semanticPathToPatchPath as K}from"@manifesto-ai/core";function U(e){return typeof e=="object"&&e!==null&&"key"in e&&"into"in e}function N(e,t){if(U(e))return{patches:[{op:"set",path:L(e.into),value:q(e.key)}]};let{path:n,target:a}=e,o=W(n,t);return a?{patches:[{op:"set",path:L(a),value:o.value}]}:{patches:[]}}function q(e){switch(e){case"uuid":return y();case"timestamp":case"time.now":return Date.now();case"isoTimestamp":return new Date().toISOString();default:return null}}function L(e){let t=H(e),n=t.startsWith("data.")?t.slice(5):t;return K(n)}function H(e){return e.startsWith("/")?e.slice(1).replace(/\//g,"."):e}function W(e,t){let a=H(e).split(".");if(a.length===0)return{value:void 0,found:!1};let[o,...i]=a,r;switch(o){case"data":r=t.data;break;case"computed":r=t.computed;break;case"system":r=t.system;break;case"meta":r=t.meta;break;default:r=t.data,i.unshift(o);break}for(let s of i){if(r==null||typeof r!="object")return{value:void 0,found:!1};r=r[s]}return{value:r,found:r!==void 0}}var u="system.get",j="system.",$=Object.freeze({__baseLaws:!0});function P(e,t,n){let a=X,o=Y(e,{initialData:Q(e.state),runtime:a}),i=J(a);o.registerEffect(u,async(r,s,m)=>{let{patches:c}=N(s,m.snapshot);return c});for(let[r,s]of Object.entries(n)){let m=async(c,f,p)=>await s(f,{snapshot:I(x(p.snapshot,t))});o.registerEffect(r,m)}return{host:o,contextProvider:i}}import{createIntent as Z}from"@manifesto-ai/core";function M(){return(e,...t)=>{let n=e,a=y(),o=ee(n,t);return Z(String(e.name),o,a)}}function ee(e,t){let n=Object.hasOwn(e,d)?e[d]:[];if(t.length!==0){if(n===null){if(t.length===1&&S(t[0]))return t[0];throw new l("INVALID_INTENT_ARGS",`Action "${String(e.name)}" requires a single object argument because positional parameter metadata is unavailable`)}if(n.length===0){if(t.length===1)return t[0];throw new l("INVALID_INTENT_ARGS",`Action "${String(e.name)}" does not accept multiple positional arguments`)}return n.length===1&&t.length===1&&S(t[0])&&e[h]?{[n[0]??"arg0"]:t[0]}:n.length===1&&t.length===1&&te(t[0],n[0])||t.length===1&&S(t[0])&&n.length>1?t[0]:Object.fromEntries(t.map((a,o)=>[n[o]??`arg${o}`,a]))}}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function te(e,t){if(!t||!S(e))return!1;let n=Object.keys(e);return n.length===1&&n[0]===t}import{hashSchemaSync as ce}from"@manifesto-ai/core";import{compileMelDomain as ne,parse as ae,tokenize as re}from"@manifesto-ai/compiler";function V(e){let t=ne(e,{mode:"domain"});if(t.errors.length>0){let a=t.errors.map(o=>{let i=o.location;if(!i||i.start.line===0&&i.start.column===0)return`[${o.code}] ${o.message}`;let r=`[${o.code}] ${o.message} (${i.start.line}:${i.start.column})`,s=e.split(`
2
- `)[i.start.line-1];if(!s)return r;let m=String(i.start.line).padStart(4," "),c=Math.max(1,i.end.line===i.start.line?Math.min(i.end.column-i.start.column,Math.max(1,s.length-i.start.column+1)):1),f=" ".repeat(m.length+3+i.start.column-1);return`${r}
1
+ import{a as v}from"./chunk-JM42OG2H.js";import{a as d,b as h,d as w,e as x,f as I,j as y,k as E,l as k,r as _}from"./chunk-BSGOCNTO.js";import{a as l,b,c as g,d as B,e as F}from"./chunk-BDIXNUQ3.js";import{createHostContextProvider as J,createHost as Y,defaultRuntime as X}from"@manifesto-ai/host";import{extractDefaults as Q}from"@manifesto-ai/core";import{semanticPathToPatchPath as K}from"@manifesto-ai/core";function U(e){return typeof e=="object"&&e!==null&&"key"in e&&"into"in e}function N(e,t){if(U(e))return{patches:[{op:"set",path:L(e.into),value:q(e.key)}]};let{path:n,target:a}=e,r=W(n,t);return a?{patches:[{op:"set",path:L(a),value:r.value}]}:{patches:[]}}function q(e){switch(e){case"uuid":return y();case"timestamp":case"time.now":return Date.now();case"isoTimestamp":return new Date().toISOString();default:return null}}function L(e){let t=H(e),n=t.startsWith("data.")?t.slice(5):t;return K(n)}function H(e){return e.startsWith("/")?e.slice(1).replace(/\//g,"."):e}function W(e,t){let a=H(e).split(".");if(a.length===0)return{value:void 0,found:!1};let[r,...i]=a,o;switch(r){case"data":o=t.data;break;case"computed":o=t.computed;break;case"system":o=t.system;break;case"meta":o=t.meta;break;default:o=t.data,i.unshift(r);break}for(let s of i){if(o==null||typeof o!="object")return{value:void 0,found:!1};o=o[s]}return{value:o,found:o!==void 0}}var u="system.get",j="system.",$=Object.freeze({__baseLaws:!0});function P(e,t,n){let a=X,r=Y(e,{initialData:Q(e.state),runtime:a}),i=J(a);r.registerEffect(u,async(o,s,m)=>{let{patches:c}=N(s,m.snapshot);return c});for(let[o,s]of Object.entries(n)){let m=async(c,f,p)=>await s(f,{snapshot:I(x(p.snapshot,t))});r.registerEffect(o,m)}return{host:r,contextProvider:i}}import{createIntent as Z}from"@manifesto-ai/core";function M(){return(e,...t)=>{let n=e,a=y(),r=ee(n,t);return Z(String(e.name),r,a)}}function ee(e,t){let n=Object.hasOwn(e,d)?e[d]:[];if(t.length!==0){if(n===null){if(t.length===1&&S(t[0]))return t[0];throw new l("INVALID_INTENT_ARGS",`Action "${String(e.name)}" requires a single object argument because positional parameter metadata is unavailable`)}if(n.length===0){if(t.length===1)return t[0];throw new l("INVALID_INTENT_ARGS",`Action "${String(e.name)}" does not accept multiple positional arguments`)}return n.length===1&&t.length===1&&S(t[0])&&e[h]?{[n[0]??"arg0"]:t[0]}:n.length===1&&t.length===1&&te(t[0],n[0])||t.length===1&&S(t[0])&&n.length>1?t[0]:Object.fromEntries(t.map((a,r)=>[n[r]??`arg${r}`,a]))}}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function te(e,t){if(!t||!S(e))return!1;let n=Object.keys(e);return n.length===1&&n[0]===t}import{hashSchemaSync as ce}from"@manifesto-ai/core";import{compileMelDomain as ne,parse as ae,tokenize as oe}from"@manifesto-ai/compiler";function V(e){let t=ne(e,{mode:"domain"});if(t.errors.length>0){let a=t.errors.map(r=>{let i=r.location;if(!i||i.start.line===0&&i.start.column===0)return`[${r.code}] ${r.message}`;let o=`[${r.code}] ${r.message} (${i.start.line}:${i.start.column})`,s=e.split(`
2
+ `)[i.start.line-1];if(!s)return o;let m=String(i.start.line).padStart(4," "),c=Math.max(1,i.end.line===i.start.line?Math.min(i.end.column-i.start.column,Math.max(1,s.length-i.start.column+1)):1),f=" ".repeat(m.length+3+i.start.column-1);return`${o}
3
3
  ${m} | ${s}
4
4
  ${f}${"^".repeat(c)}`}).join(`
5
5
 
6
6
  `);throw new g(t.errors,`MEL compilation failed:
7
- ${a}`)}if(!t.schema)throw new l("COMPILE_ERROR","MEL compilation produced no schema");let n=t.schema;return{schema:n,actionParamMetadata:O(n,se(e)),actionSingleParamObjectValueMetadata:T(n)}}function O(e,t){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([n,a])=>{let o=t?.[n];if(o&&o.length>0)return[n,Object.freeze([...o])];if(a.params&&a.params.length>0){let r=Object.freeze([...a.params]);return[n,r]}if(!a.input||a.input.type!=="object"||!a.input.fields)return[n,[]];let i=oe(a.input);return[n,i.length<=1?i:null]})))}function T(e){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([t,n])=>[t,ie(e,n)])))}function oe(e){return!e||e.type!=="object"||!e.fields?[]:Object.keys(e.fields)}function ie(e,t){if(t.params?.length===1&&t.inputType){let n=A(t.inputType,t.params[0]??"",e.types);return n?R(n,e.types):!1}if(t.input?.type==="object"&&t.input.fields&&Object.keys(t.input.fields).length===1){let[n]=Object.keys(t.input.fields);return(n?t.input.fields[n]:void 0)?.type==="object"}return!1}function A(e,t,n,a=[]){if(e.kind==="ref"){if(a.includes(e.name))return null;let o=n[e.name];return o?A(o.definition,t,n,[...a,e.name]):null}if(e.kind==="union"){let o=e.types.filter(i=>!C(i,n,a));return o.length===1?A(o[0],t,n,a):null}return e.kind!=="object"?null:e.fields[t]?.type??null}function R(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let a=t[e.name];return a?R(a.definition,t,[...n,e.name]):!1}if(e.kind==="union"){let a=e.types.filter(o=>!C(o,t,n));return a.length===1?R(a[0],t,n):!1}return e.kind==="object"||e.kind==="record"||e.kind==="primitive"&&e.type==="object"}function C(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let a=t[e.name];return a?C(a.definition,t,[...n,e.name]):!1}return e.kind==="primitive"&&e.type==="null"||e.kind==="literal"&&e.value===null}function se(e){let t=re(e);if(t.diagnostics.some(a=>a.severity==="error"))return;let n=ae(t.tokens);if(n.program)return Object.freeze(Object.fromEntries(n.program.domain.members.filter(a=>a.kind==="action").map(a=>[a.name,Object.freeze(a.params.map(o=>o.name))])))}function G(e){if(typeof e!="string"&&le(e))throw new l("SCHEMA_ERROR","DomainModule is a compiler tooling artifact. Pass module.schema or MEL source to createManifesto().");let t=typeof e=="string"?V(e):{schema:e,actionParamMetadata:O(e),actionSingleParamObjectValueMetadata:T(e)},n=me(t.schema);return fe(n),{schema:n,actionParamMetadata:t.actionParamMetadata,actionSingleParamObjectValueMetadata:t.actionSingleParamObjectValueMetadata,projectionPlan:w(n)}}function le(e){return typeof e=="object"&&e!==null&&"schema"in e&&"graph"in e&&"annotations"in e}function me(e){let t={...e.state.fields},n=!1;if(!t.$host)t.$host={type:"object",required:!1,default:{}},n=!0;else{if(t.$host.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$host' must be an object field");t.$host.default===void 0&&(t.$host={...t.$host,default:{}},n=!0)}if(!t.$mel)t.$mel={type:"object",required:!1,default:{guards:{intent:{}}},fields:{guards:{type:"object",required:!1,default:{intent:{}},fields:{intent:{type:"object",required:!1,default:{}}}}}},n=!0;else{if(t.$mel.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel' must be an object field");{let r=t.$mel;r.default===void 0&&(r={...r,default:{guards:{intent:{}}}},n=!0);let s=r.fields??{},m=s.guards;if(!m)r={...r,fields:{...s,guards:{type:"object",required:!1,default:{intent:{}},fields:{intent:{type:"object",required:!1,default:{}}}}}},n=!0;else{if(m.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel.guards' must be an object field");{let c=m;c.default===void 0&&(c={...c,default:{intent:{}}},n=!0);let f=c.fields??{},p=f.intent;if(!p)c={...c,fields:{...f,intent:{type:"object",required:!1,default:{}}}},n=!0;else{if(p.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel.guards.intent' must be an object field");p.default===void 0&&(c={...c,fields:{...f,intent:{...p,default:{}}}},n=!0)}c!==m&&(r={...r,fields:{...s,guards:c}})}}r!==t.$mel&&(t.$mel=r)}}if(!n)return e;let a={...e,state:{...e.state,fields:t}},{hash:o,...i}=a;return{...a,hash:ce(i)}}function fe(e){for(let t of Object.keys(e.actions??{}))if(t.startsWith(j))throw new l("RESERVED_NAMESPACE",`Action type "${t}" uses reserved namespace prefix "${j}"`)}function D(e,t,n){let a=Object.fromEntries(Object.keys(e.actions).map(r=>{let s={__kind:"ActionRef",name:r};return Object.defineProperty(s,d,{enumerable:!1,configurable:!1,writable:!1,value:Object.hasOwn(t,r)?t[r]:[]}),Object.defineProperty(s,h,{enumerable:!1,configurable:!1,writable:!1,value:n[r]??!1}),[r,Object.freeze(s)]})),o=Object.fromEntries(Object.keys(e.state.fields).filter(r=>!r.startsWith("$")).map(r=>[r,Object.freeze({__kind:"FieldRef",name:r})])),i=Object.fromEntries(Object.keys(e.computed.fields).map(r=>[r,Object.freeze({__kind:"ComputedRef",name:r})]));return Object.freeze({actions:Object.freeze(a),state:Object.freeze(o),computed:Object.freeze(i)})}function z(e,t){if(u in t)throw new b(u);let n=G(e),a={_laws:$,schema:n.schema,activate(){_(a);let o=P(n.schema,n.projectionPlan,t);return v(E({schema:n.schema,projectionPlan:n.projectionPlan,host:o.host,hostContextProvider:o.contextProvider,MEL:D(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:M()}))}};return k(a,()=>{let o=P(n.schema,n.projectionPlan,t);return E({schema:n.schema,projectionPlan:n.projectionPlan,host:o.host,hostContextProvider:o.contextProvider,MEL:D(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:M()})})}import{createSnapshot as et}from"@manifesto-ai/core";export{F as AlreadyActivatedError,g as CompileError,B as DisposedError,l as ManifestoError,b as ReservedEffectError,z as createManifesto,et as createSnapshot};
7
+ ${a}`)}if(!t.schema)throw new l("COMPILE_ERROR","MEL compilation produced no schema");let n=t.schema;return{schema:n,actionParamMetadata:O(n,se(e)),actionSingleParamObjectValueMetadata:T(n)}}function O(e,t){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([n,a])=>{let r=t?.[n];if(r&&r.length>0)return[n,Object.freeze([...r])];if(a.params&&a.params.length>0){let o=Object.freeze([...a.params]);return[n,o]}if(!a.input||a.input.type!=="object"||!a.input.fields)return[n,[]];let i=re(a.input);return[n,i.length<=1?i:null]})))}function T(e){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([t,n])=>[t,ie(e,n)])))}function re(e){return!e||e.type!=="object"||!e.fields?[]:Object.keys(e.fields)}function ie(e,t){if(t.params?.length===1&&t.inputType){let n=R(t.inputType,t.params[0]??"",e.types);return n?A(n,e.types):!1}if(t.input?.type==="object"&&t.input.fields&&Object.keys(t.input.fields).length===1){let[n]=Object.keys(t.input.fields);return(n?t.input.fields[n]:void 0)?.type==="object"}return!1}function R(e,t,n,a=[]){if(e.kind==="ref"){if(a.includes(e.name))return null;let r=n[e.name];return r?R(r.definition,t,n,[...a,e.name]):null}if(e.kind==="union"){let r=e.types.filter(i=>!C(i,n,a));return r.length===1?R(r[0],t,n,a):null}return e.kind!=="object"?null:e.fields[t]?.type??null}function A(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let a=t[e.name];return a?A(a.definition,t,[...n,e.name]):!1}if(e.kind==="union"){let a=e.types.filter(r=>!C(r,t,n));return a.length===1?A(a[0],t,n):!1}return e.kind==="object"||e.kind==="record"||e.kind==="primitive"&&e.type==="object"}function C(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let a=t[e.name];return a?C(a.definition,t,[...n,e.name]):!1}return e.kind==="primitive"&&e.type==="null"||e.kind==="literal"&&e.value===null}function se(e){let t=oe(e);if(t.diagnostics.some(a=>a.severity==="error"))return;let n=ae(t.tokens);if(n.program)return Object.freeze(Object.fromEntries(n.program.domain.members.filter(a=>a.kind==="action").map(a=>[a.name,Object.freeze(a.params.map(r=>r.name))])))}function G(e){if(typeof e!="string"&&le(e))throw new l("SCHEMA_ERROR","DomainModule is a compiler tooling artifact. Pass module.schema or MEL source to createManifesto().");let t=typeof e=="string"?V(e):{schema:e,actionParamMetadata:O(e),actionSingleParamObjectValueMetadata:T(e)},n=me(t.schema);return fe(n),{schema:n,actionParamMetadata:t.actionParamMetadata,actionSingleParamObjectValueMetadata:t.actionSingleParamObjectValueMetadata,projectionPlan:w(n)}}function le(e){return typeof e=="object"&&e!==null&&"schema"in e&&"graph"in e&&"annotations"in e}function me(e){let t={...e.state.fields},n=!1;if(!t.$host)t.$host={type:"object",required:!1,default:{}},n=!0;else{if(t.$host.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$host' must be an object field");t.$host.default===void 0&&(t.$host={...t.$host,default:{}},n=!0)}if(!t.$mel)t.$mel={type:"object",required:!1,default:{guards:{intent:{}}},fields:{guards:{type:"object",required:!1,default:{intent:{}},fields:{intent:{type:"object",required:!1,default:{}}}}}},n=!0;else{if(t.$mel.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel' must be an object field");{let o=t.$mel;o.default===void 0&&(o={...o,default:{guards:{intent:{}}}},n=!0);let s=o.fields??{},m=s.guards;if(!m)o={...o,fields:{...s,guards:{type:"object",required:!1,default:{intent:{}},fields:{intent:{type:"object",required:!1,default:{}}}}}},n=!0;else{if(m.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel.guards' must be an object field");{let c=m;c.default===void 0&&(c={...c,default:{intent:{}}},n=!0);let f=c.fields??{},p=f.intent;if(!p)c={...c,fields:{...f,intent:{type:"object",required:!1,default:{}}}},n=!0;else{if(p.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel.guards.intent' must be an object field");p.default===void 0&&(c={...c,fields:{...f,intent:{...p,default:{}}}},n=!0)}c!==m&&(o={...o,fields:{...s,guards:c}})}}o!==t.$mel&&(t.$mel=o)}}if(!n)return e;let a={...e,state:{...e.state,fields:t}},{hash:r,...i}=a;return{...a,hash:ce(i)}}function fe(e){for(let t of Object.keys(e.actions??{}))if(t.startsWith(j))throw new l("RESERVED_NAMESPACE",`Action type "${t}" uses reserved namespace prefix "${j}"`)}function D(e,t,n){let a=Object.fromEntries(Object.keys(e.actions).map(o=>{let s={__kind:"ActionRef",name:o};return Object.defineProperty(s,d,{enumerable:!1,configurable:!1,writable:!1,value:Object.hasOwn(t,o)?t[o]:[]}),Object.defineProperty(s,h,{enumerable:!1,configurable:!1,writable:!1,value:n[o]??!1}),[o,Object.freeze(s)]})),r=Object.fromEntries(Object.keys(e.state.fields).filter(o=>!o.startsWith("$")).map(o=>[o,Object.freeze({__kind:"FieldRef",name:o})])),i=Object.fromEntries(Object.keys(e.computed.fields).map(o=>[o,Object.freeze({__kind:"ComputedRef",name:o})]));return Object.freeze({actions:Object.freeze(a),state:Object.freeze(r),computed:Object.freeze(i)})}function z(e,t){if(u in t)throw new b(u);let n=G(e),a={_laws:$,schema:n.schema,activate(){_(a);let r=P(n.schema,n.projectionPlan,t);return v(E({schema:n.schema,projectionPlan:n.projectionPlan,host:r.host,hostContextProvider:r.contextProvider,MEL:D(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:M()}))}};return k(a,()=>{let r=P(n.schema,n.projectionPlan,t);return E({schema:n.schema,projectionPlan:n.projectionPlan,host:r.host,hostContextProvider:r.contextProvider,MEL:D(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:M()})})}import{createSnapshot as et}from"@manifesto-ai/core";export{F as AlreadyActivatedError,g as CompileError,B as DisposedError,l as ManifestoError,b as ReservedEffectError,z as createManifesto,et as createSnapshot};
package/dist/provider.js CHANGED
@@ -1 +1 @@
1
- import{a as c}from"./chunk-EPGBNDYU.js";import{k as e,l as t,m as n,n as a,p as r,q as o,r as i}from"./chunk-7TMADY2E.js";import"./chunk-BDIXNUQ3.js";export{i as activateComposable,o as assertComposableNotActivated,a as attachExtensionKernel,t as attachRuntimeKernelFactory,c as createBaseRuntimeInstance,e as createRuntimeKernel,r as getActivationState,n as getRuntimeKernelFactory};
1
+ import{a as c}from"./chunk-JM42OG2H.js";import{k as e,l as t,m as n,n as a,p as r,q as o,r as i}from"./chunk-BSGOCNTO.js";import"./chunk-BDIXNUQ3.js";export{i as activateComposable,o as assertComposableNotActivated,a as attachExtensionKernel,t as attachRuntimeKernelFactory,c as createBaseRuntimeInstance,e as createRuntimeKernel,r as getActivationState,n as getRuntimeKernelFactory};
package/dist/types.d.ts CHANGED
@@ -201,6 +201,7 @@ export type IntentExplanation<T extends ManifestoDomainShape = ManifestoDomainSh
201
201
  readonly changedPaths: readonly string[];
202
202
  };
203
203
  export type TypedSimulate<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => SimulateResult<T>;
204
+ export type TypedSimulateIntent<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(intent: TypedIntent<T, K>) => SimulateResult<T>;
204
205
  export type TypedSubscribe<T extends ManifestoDomainShape> = <R>(selector: Selector<T["state"], R>, listener: (value: R) => void) => Unsubscribe;
205
206
  export type TypedActionMetadata<T extends ManifestoDomainShape, K extends keyof T["actions"] = keyof T["actions"]> = {
206
207
  readonly name: K;
@@ -261,10 +262,13 @@ export type ManifestoBaseInstance<T extends ManifestoDomainShape> = {
261
262
  readonly isActionAvailable: (name: keyof T["actions"]) => boolean;
262
263
  readonly getSchemaGraph: () => SchemaGraph;
263
264
  readonly simulate: TypedSimulate<T>;
265
+ readonly simulateIntent: TypedSimulateIntent<T>;
264
266
  readonly MEL: TypedMEL<T>;
265
267
  readonly schema: DomainSchema;
266
268
  readonly dispose: () => void;
267
269
  };
270
+ export type ManifestoLegalityRuntime<T extends ManifestoDomainShape> = Pick<ManifestoBaseInstance<T>, "createIntent" | "whyNot" | "simulate" | "simulateIntent" | "MEL">;
271
+ export type ManifestoDispatchRuntime<T extends ManifestoDomainShape> = Pick<ManifestoBaseInstance<T>, "dispatchAsync" | "dispatchAsyncWithReport">;
268
272
  export interface ManifestoRuntimeByLaws<T extends ManifestoDomainShape> {
269
273
  readonly base: ManifestoBaseInstance<T>;
270
274
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifesto-ai/sdk",
3
- "version": "3.17.2",
3
+ "version": "3.18.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",
@@ -48,8 +48,8 @@
48
48
  ],
49
49
  "dependencies": {
50
50
  "@manifesto-ai/compiler": "3.8.0",
51
- "@manifesto-ai/host": "2.9.1",
52
- "@manifesto-ai/core": "2.13.0"
51
+ "@manifesto-ai/core": "2.13.0",
52
+ "@manifesto-ai/host": "2.9.1"
53
53
  },
54
54
  "devDependencies": {
55
55
  "typescript": "^5.9.3",
@@ -1 +0,0 @@
1
- import{a as R,e as H}from"./chunk-BDIXNUQ3.js";import{getAvailableActions as He,isActionAvailable as Ve,isIntentDispatchable as Ue}from"@manifesto-ai/core";import{extractSchemaGraph as qe}from"@manifesto-ai/compiler";var xe=new Set(["$item","$index","$array"]);function Xe(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 ke(c.expr)){if(je(s))return u.delete(r),n.set(r,!1),!1;let l=Me(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 V(e,t){return{data:Ae(e.data),computed:ge(e.computed,t),system:{status:e.system.status,lastError:e.system.lastError},meta:{schemaHash:e.meta.schemaHash}}}function Je(e,t){return V(e,t)}function x(e){return Z(structuredClone(e))}function Q(e,t){return Oe(e,t)}function Ae(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 ge(e,t){let n={};for(let a of t.visibleComputedKeys)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a]);return structuredClone(n)}function Me(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 Ce(e){return e.startsWith("/")?e.slice(1).replace(/\//g,"."):e}function je(e){let t=Ce(e),n=t.startsWith("data.")?t.slice(5):t,o=/^([^.[\]]+)/.exec(n)?.[1]??"";return o.startsWith("$")?!xe.has(o):!1}function ke(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 Oe(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 h=Object.prototype.hasOwnProperty.call(a,l),f=Object.prototype.hasOwnProperty.call(o,l);if(h!==f||h&&!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),h=new Uint8Array(o.buffer,o.byteOffset,o.byteLength);return l.every((f,T)=>f===h[T])}if(a instanceof ArrayBuffer&&o instanceof ArrayBuffer){if(a.byteLength!==o.byteLength)return!1;let l=new Uint8Array(a),h=new Uint8Array(o);return l.every((f,T)=>f===h[T])}if(a instanceof Map&&o instanceof Map){if(a.size!==o.size)return!1;let l=Array.from(a.entries()),h=Array.from(o.entries());return l.every(([f,T],b)=>{let v=h[b];if(!v)return!1;let[A,j]=v;return O(f,A,n)&&O(T,j,n)})}if(a instanceof Set&&o instanceof Set){if(a.size!==o.size)return!1;let l=Array.from(a.values()),h=Array.from(o.values());return l.every((f,T)=>O(f,h[T],n))}let c=J(a),s=J(o);if(c.length!==s.length)return!1;for(let l=0;l<c.length;l+=1){let h=c[l],f=s[l];if(h!==f)return!1;let T=a[h],b=o[f];if(!O(T,b,n))return!1}return!0}function J(e){return Object.keys(e).filter(t=>e[t]!==void 0).sort()}function Z(e,t=new WeakSet){if(e==null||typeof e!="object")return e;if(Y(e))return ee(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(Y(o)){De(n,a,o);continue}Z(o,t)}return Object.freeze(e)}function Y(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)}function ee(e){return structuredClone(e)}function De(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 ee(n)}})}var U=Symbol("manifesto-sdk.action-param-names"),we=Symbol("manifesto-sdk.action-single-param-object-value"),z=Symbol("manifesto-sdk.runtime-kernel-factory"),L=Symbol("manifesto-sdk.activation-state"),k=Symbol("manifesto-sdk.extension-kernel");var Ne=/^(state|computed|action):.+$/;function q(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 q(c)},u=(i,c)=>{let s=Pe(i,t),l=[s],h=new Set([s]),f=c==="incoming"?a:n;for(;l.length>0;){let T=l.shift();if(T)for(let b of f.get(T)??[])h.has(b)||(h.add(b),l.push(b))}return r(h)};return Object.freeze({nodes:e.nodes,edges:e.edges,traceUp(i){return u(i,"incoming")},traceDown(i){return u(i,"outgoing")}})}function Pe(e,t){if(typeof e=="string"){if(!Ne.test(e))throw new R("SCHEMA_ERROR",'SchemaGraph node id must use "state:<name>", "computed:<name>", or "action:<name>"');if(!t.has(e))throw new R("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 R("SCHEMA_ERROR","Unsupported SchemaGraph ref lookup target")}if(!t.has(n))throw new R("SCHEMA_ERROR",`SchemaGraph node "${n}" is not part of the projected graph`);return n}import{validateIntentInput as Fe}from"@manifesto-ai/core";function te(e,t,n){let a={intentId:t.intentId??"",intent:t,code:n.code,reason:n.message};return e("dispatch:rejected",a),a}function ne(e,t,n,a){e("dispatch:failed",{intentId:t.intentId??"",intent:t,error:n,...a!==void 0?{snapshot:a}:{}})}function ae(e,t,n){e("dispatch:completed",{intentId:t.intentId??"",intent:t,snapshot:n})}function ie({getAvailableActionsFor:e,projectSnapshotFromCanonical:t}){function n(u,i){let c=e(u),s=e(i),l=Object.freeze(s.filter(f=>!c.includes(f))),h=Object.freeze(c.filter(f=>!s.includes(f)));return Object.freeze({before:c,after:s,unlocked:l,locked:h})}function a(u,i){let c=x(u),s=x(i),l=t(c),h=t(s);return Object.freeze({projected:Object.freeze({beforeSnapshot:l,afterSnapshot:h,changedPaths:F(l,h),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=Le(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 F(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 T=0;T<f;T+=1){let b=Object.prototype.hasOwnProperty.call(r,T),v=Object.prototype.hasOwnProperty.call(u,T),A=`${i}[${T}]`;if(b!==v){n.add(A);continue}!b&&!v||o(r[T],u[T],A)}return}if(!oe(r)||!oe(u)){n.add(i);return}let h=new Set([...Object.keys(r),...Object.keys(u)]);for(let f of[...h].sort()){let T=Object.prototype.hasOwnProperty.call(r,f),b=Object.prototype.hasOwnProperty.call(u,f),v=`${i}.${f}`;if(T!==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 oe(e){return Object.prototype.toString.call(e)==="[object Object]"}function Le(e){return e instanceof Error?e:new Error(String(e))}function se({schema:e,ensureIntentId:t,getAvailableActionsFor:n,isActionAvailableFor:a,isIntentDispatchableFor:o,projectSnapshotFromCanonical:r,getSimulateSync:u,emitEvent:i}){function c(y,m,p){return Object.freeze({layer:y,expression:m,evaluatedResult:!1,...p!==void 0?{description:p}:{}})}function s(y,m){let p=m.type,d=e.actions[p];return d?a(y,p)?o(y,m)?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(y){return new R("ACTION_UNAVAILABLE",`Action "${y.type}" is unavailable against the current visible snapshot`)}function h(y){return new R("INTENT_NOT_DISPATCHABLE",`Action "${y.type}" is available, but the bound intent is not dispatchable against the current visible snapshot`)}function f(y){return new R("INVALID_INPUT",y)}function T(y,m){let p=Fe(e,m);return p?f(p):null}function b(y,m){let p=t(m),d=p.type;if(!a(y,d))return{kind:"unavailable",intent:p,actionName:d};let I=T(y,p);if(I)return{kind:"invalid-input",intent:p,actionName:d,error:I};let C=s(y,p);return C.length>0?{kind:"not-dispatchable",intent:p,actionName:d,blockers:C}:{kind:"admitted",intent:p,actionName:d}}function v(y,m){return m.kind==="unavailable"?Object.freeze({kind:"blocked",actionName:m.actionName,failure:{kind:"unavailable",blockers:s(y,m.intent)}}):m.kind==="invalid-input"?Object.freeze({kind:"blocked",actionName:m.actionName,failure:{kind:"invalid_input",error:{code:"INVALID_INPUT",message:m.error.message}}}):m.kind==="not-dispatchable"?Object.freeze({kind:"blocked",actionName:m.actionName,failure:{kind:"not_dispatchable",blockers:m.blockers}}):Object.freeze({kind:"admitted",actionName:m.actionName})}function A(y,m){let p=b(y,m);if(p.kind==="unavailable")return Object.freeze({kind:"blocked",actionName:p.actionName,available:!1,dispatchable:!1,blockers:s(y,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()(y,p.intent),I=r(y),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:F(I,C)})}function j(y,m){throw te(i,y,m),m}function D(y){return j(y,l(y))}function w(y,m){return j(y,f(m))}function N(y){return j(y,h(y))}return Object.freeze({getIntentBlockersFor:s,validateIntentInputFor:T,evaluateIntentLegalityFor:b,deriveIntentAdmission:v,explainIntentFor:A,createUnavailableError:l,createNotDispatchableError:h,rejectInvalidInput:w,rejectUnavailable:D,rejectNotDispatchable:N})}function re({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 ae(a,i,s),Object.freeze({publishedSnapshot:s,publishedCanonicalSnapshot:n()})}function u(i,c,s){let l=o(s);return ne(a,i,c,l),Object.freeze({publishedSnapshot:l,publishedCanonicalSnapshot:n()})}return Object.freeze({replaceVisibleSnapshot:o,restoreVisibleSnapshot:t,publishCompletedHostResult:r,publishFailedHostResult:u})}import{apply as ce,applySystemDelta as Ke,computeSync as Ge}from"@manifesto-ai/core";import{getHostState as _e}from"@manifesto-ai/host";function le(e,t){return{...e,timestamp:t,children:e.children.map(n=>le(n,t))}}function ze(e){let t={};function n(a){t[a.id]=a,a.children.forEach(n)}return n(e),t}function Be(e,t){let n=le(e.root,t);return{...e,duration:0,root:n,nodes:ze(n)}}function pe({schema:e,hostContextProvider:t,evaluateIntentLegalityFor:n}){function a(i,c,s){let h=_e(i.data)?.intentSlots??{},f=c.input===void 0?{type:c.type}:{type:c.type,input:c.input};return ce(e,i,[{op:"merge",path:[{kind:"prop",name:"$host"}],value:{intentSlots:{...h,[c.intentId]:f}}}],s)}function o(i){return new R("ACTION_UNAVAILABLE",`Action "${i.type}" is unavailable against the provided canonical snapshot`)}function r(i){return new R("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,h=t.createFrozenContext(l.intentId),f=a(structuredClone(i),l,h),T=Ge(e,f,l,h),b=ce(e,f,T.patches,h),v=Ke(b,T.systemDelta);return Object.freeze({snapshot:x(v),patches:x(T.patches),systemDelta:x(T.systemDelta),status:T.status,requirements:x(T.systemDelta.addRequirements),diagnostics:Object.freeze({trace:x(Be(T.trace,i.meta.timestamp))})})}})}function ue({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(m,p){if(i)return()=>{};let d,I=!1;try{d=m(o),I=!0}catch{d=void 0,I=!1}let C={selector:m,listener:p,lastValue:d,initialized:I};return c.add(C),()=>{c.delete(C)}}function h(m,p){if(i)return()=>{};let d=s.get(m);return d||(d=new Set,s.set(m,d)),d.add(p),()=>{d?.delete(p)}}function f(){return o}function T(){return r}function b(){return structuredClone(a)}function v(m,p){a=structuredClone(m),e.reset(structuredClone(a)),r=x(a);let d=n(a),I=!Q(d,o);return I&&(o=d),p?.notify!==!1&&I&&y(o),o}function A(){e.reset(structuredClone(a))}function j(m,p){let d=s.get(m);if(d)for(let I of d)try{I(p)}catch{}}function D(m){let p=u.catch(()=>{}).then(m);return u=p.then(()=>{},()=>{}),p}function w(){i||(i=!0,c.clear(),s.clear())}function N(){return i}function y(m){for(let p of c){let d;try{d=p.selector(m)}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:h,getSnapshot:f,getCanonicalSnapshot:T,getVisibleCoreSnapshot:b,setVisibleSnapshot:v,restoreVisibleSnapshot:A,emitEvent:j,enqueue:D,dispose:w,isDisposed:N}}function de(){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 $e(e){if(e.params)return e.params;let t=e.input;return!t||t.type!=="object"||!t.fields?[]:Object.keys(t.fields)}function We({schema:e,projectionPlan:t,host:n,hostContextProvider:a,MEL:o,createIntent:r}){let u=n.getSnapshot();if(!u)throw new R("SCHEMA_ERROR","Host failed to initialize its genesis snapshot");function i(S){return x(V(S,t))}let c=ue({host:n,initialCanonicalSnapshot:u,projectSnapshotFromCanonical:i}),{subscribe:s,on:l,getSnapshot:h,getCanonicalSnapshot:f,getVisibleCoreSnapshot:T,setVisibleSnapshot:b,restoreVisibleSnapshot:v,emitEvent:A,enqueue:j,dispose:D,isDisposed:w}=c,N=q(qe(e)),y=Object.keys(e.actions),m=Object.freeze(Object.fromEntries(y.map(S=>{let E=e.actions[S],P=o.actions[S]?.[U],ve=Object.freeze(Array.isArray(P)?[...P]:$e(E));return[S,Object.freeze({name:S,params:ve,input:E.input,description:E.description,hasDispatchableGate:E.dispatchable!==void 0})]}))),p=Object.freeze(y.map(S=>m[S]));function d(S){return Object.freeze([...He(e,S)])}let I=ie({getAvailableActionsFor:d,projectSnapshotFromCanonical:i});function C(){return d(f())}let he=(S=>S!==void 0?m[String(S)]:p);function K(S,E){return Ve(e,S,String(E))}function ye(S){return K(f(),S)}function G(S,E){return Ue(e,S,E)}let Te=((S,...E)=>G(f(),r(S,...E)));function $(S){return S.intentId&&S.intentId.length>0?S:{...S,intentId:de()}}async function Se(S,E){return n.dispatch(S,E)}let B=null,M=se({schema:e,ensureIntentId:$,getAvailableActionsFor:d,isActionAvailableFor:K,isIntentDispatchableFor:G,projectSnapshotFromCanonical:i,getSimulateSync:()=>{if(!B)throw new R("SCHEMA_ERROR","Runtime simulation surface is not initialized");return B},emitEvent:A}),_=pe({schema:e,hostContextProvider:a,evaluateIntentLegalityFor:M.evaluateIntentLegalityFor});B=_.simulateSync;let W=re({setVisibleSnapshot:b,restoreVisibleSnapshot:v,getCanonicalSnapshot:f,emitEvent:A}),X=M.getIntentBlockersFor,be=((S,...E)=>X(f(),r(S,...E))),Re=_.simulateSync,Ee=((S,...E)=>{let g=_.simulateSync(f(),r(S,...E)),P=i(g.snapshot);return Object.freeze({snapshot:P,changedPaths:F(h(),P),newAvailableActions:d(g.snapshot),requirements:g.requirements,status:g.status,diagnostics:g.diagnostics})}),Ie=Object.freeze({MEL:o,schema:e,createIntent:r,getCanonicalSnapshot:f,projectSnapshot:S=>i(S),simulateSync:(S,E)=>{let g=_.simulateSync(S,E);return Object.freeze({snapshot:g.snapshot,patches:g.patches,requirements:g.requirements,status:g.status,diagnostics:g.diagnostics})},getAvailableActionsFor:d,isActionAvailableFor:K,isIntentDispatchableFor:G,explainIntentFor:M.explainIntentFor});return{schema:e,MEL:o,createIntent:r,subscribe:s,on:l,getSnapshot:h,getAvailableActionsFor:d,getAvailableActions:C,getIntentBlockersFor:X,getActionMetadata:he,isActionAvailableFor:K,isActionAvailable:ye,isIntentDispatchableFor:G,isIntentDispatchable:Te,getIntentBlockers:be,getSchemaGraph(){return N},simulateSync:Re,simulate:Ee,dispose:D,isDisposed:w,getCanonicalSnapshot:f,getVisibleCoreSnapshot:T,setVisibleSnapshot:W.replaceVisibleSnapshot,restoreVisibleSnapshot:W.restoreVisibleSnapshot,emitEvent:A,enqueue:j,ensureIntentId:$,executeHost:Se,validateIntentInputFor:M.validateIntentInputFor,evaluateIntentLegalityFor:M.evaluateIntentLegalityFor,deriveIntentAdmission:M.deriveIntentAdmission,deriveExecutionOutcome:I.deriveExecutionOutcome,classifyExecutionFailure:I.classifyExecutionFailure,createExecutionDiagnostics:I.createExecutionDiagnostics,createUnavailableError:M.createUnavailableError,createNotDispatchableError:M.createNotDispatchableError,rejectInvalidInput:M.rejectInvalidInput,rejectUnavailable:M.rejectUnavailable,rejectNotDispatchable:M.rejectNotDispatchable,[k]:Ie}}function Ft(e,t,n){Object.defineProperty(e,z,{enumerable:!1,configurable:!1,writable:!1,value:t});let a=n??fe(e)??{activated:!1};return fe(e)||Object.defineProperty(e,L,{enumerable:!1,configurable:!1,writable:!1,value:a}),e}function Kt(e){let n=e[z];if(typeof n!="function")throw new R("SCHEMA_ERROR","ComposableManifesto is missing its runtime kernel factory");return n}function Gt(e,t){return Object.defineProperty(e,k,{enumerable:!1,configurable:!1,writable:!1,value:t[k]}),e}function _t(e){let n=e[k];if(!n)throw new R("SCHEMA_ERROR","Activated runtime is missing its extension kernel");return n}function me(e){let n=e[L];if(!n)throw new R("SCHEMA_ERROR","ComposableManifesto is missing its activation state");return n}function zt(e){if(me(e).activated)throw new H}function Bt(e){let t=me(e);if(t.activated)throw new H;t.activated=!0}function fe(e){return e[L]??null}export{U as a,we as b,k as c,Xe as d,Je as e,x as f,te as g,ne as h,re as i,de as j,We as k,Ft as l,Kt as m,Gt as n,_t as o,me as p,zt as q,Bt as r};