@manifesto-ai/sdk 3.12.0 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-5BUS6Q4E.js +1 -0
- package/dist/compat/internal.d.ts +96 -0
- package/dist/compat/runtime-symbols.d.ts +8 -0
- package/dist/create-manifesto.d.ts +1 -3
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/internal.d.ts +1 -84
- package/dist/manifest/compile-schema.d.ts +5 -0
- package/dist/manifest/create-manifesto.d.ts +3 -0
- package/dist/manifest/intent-packing.d.ts +2 -0
- package/dist/manifest/internal-host.d.ts +5 -0
- package/dist/manifest/resolve-schema.d.ts +3 -0
- package/dist/manifest/shared.d.ts +25 -0
- package/dist/manifest/system-get.d.ts +4 -0
- package/dist/manifest/typed-mel.d.ts +4 -0
- package/dist/{simulation-session.d.ts → projection/simulation-session.d.ts} +2 -2
- package/dist/provider.d.ts +2 -2
- package/dist/provider.js +1 -1
- package/dist/runtime/admission.d.ts +15 -0
- package/dist/runtime/base-dispatch.d.ts +46 -0
- package/dist/runtime/base-runtime.d.ts +3 -0
- package/dist/runtime/events.d.ts +7 -0
- package/dist/runtime/facets.d.ts +73 -0
- package/dist/runtime/kernel.d.ts +3 -0
- package/dist/runtime/publication.d.ts +13 -0
- package/dist/runtime/reports.d.ts +10 -0
- package/dist/runtime/schema-graph.d.ts +3 -0
- package/dist/runtime/simulation.d.ts +17 -0
- package/dist/runtime/state-store.d.ts +11 -0
- package/dist/runtime/uuid.d.ts +1 -0
- package/dist/types.d.ts +91 -2
- package/package.json +7 -7
- package/dist/chunk-A2FB6LGY.js +0 -1
- /package/dist/{snapshot-projection.d.ts → projection/snapshot-projection.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as R,e as H}from"./chunk-BDIXNUQ3.js";import{getAvailableActions as Ge,isActionAvailable as ze,isIntentDispatchable as Be}from"@manifesto-ai/core";import{extractSchemaGraph as He}from"@manifesto-ai/compiler";var ve=new Set(["$item","$index","$array"]);function qe(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 je(c.expr)){if(ge(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:xe(e.data),computed:Ae(e.computed,t),system:{status:e.system.status,lastError:e.system.lastError},meta:{schemaHash:e.meta.schemaHash}}}function $e(e,t){return V(e,t)}function x(e){return Z(structuredClone(e))}function Q(e,t){return ke(e,t)}function xe(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 Ae(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 ge(e){let t=Ce(e),n=t.startsWith("data.")?t.slice(5):t,o=/^([^.[\]]+)/.exec(n)?.[1]??"";return o.startsWith("$")?!ve.has(o):!1}function je(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 ke(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,S)=>f===h[S])}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,S)=>f===h[S])}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,S],b)=>{let v=h[b];if(!v)return!1;let[A,j]=v;return O(f,A,n)&&O(S,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,S)=>O(f,h[S],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 S=a[h],b=o[f];if(!O(S,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)){Oe(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 Oe(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"),De=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 we=/^(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=Ne(i,t),l=[s],h=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)??[])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 Ne(e,t){if(typeof e=="string"){if(!we.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 Le}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=Pe(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 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(!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 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 oe(e){return Object.prototype.toString.call(e)==="[object Object]"}function Pe(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 S(y,m){let p=Le(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=S(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:S,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 Fe,computeSync as Ke}from"@manifesto-ai/core";import{getHostState as _e}from"@manifesto-ai/host";function le({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),S=Ke(e,f,l,h),b=ce(e,f,S.patches,h),v=Fe(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)})}})}function pe({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 S(){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:S,getVisibleCoreSnapshot:b,setVisibleSnapshot:v,restoreVisibleSnapshot:A,emitEvent:j,enqueue:D,dispose:w,isDisposed:N}}function ue(){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 Ve(e){if(e.params)return e.params;let t=e.input;return!t||t.type!=="object"||!t.fields?[]:Object.keys(t.fields)}function Ue({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(T){return x(V(T,t))}let c=pe({host:n,initialCanonicalSnapshot:u,projectSnapshotFromCanonical:i}),{subscribe:s,on:l,getSnapshot:h,getCanonicalSnapshot:f,getVisibleCoreSnapshot:S,setVisibleSnapshot:b,restoreVisibleSnapshot:v,emitEvent:A,enqueue:j,dispose:D,isDisposed:w}=c,N=q(He(e)),y=Object.keys(e.actions),m=Object.freeze(Object.fromEntries(y.map(T=>{let E=e.actions[T],P=o.actions[T]?.[U],Ie=Object.freeze(Array.isArray(P)?[...P]:Ve(E));return[T,Object.freeze({name:T,params:Ie,input:E.input,description:E.description,hasDispatchableGate:E.dispatchable!==void 0})]}))),p=Object.freeze(y.map(T=>m[T]));function d(T){return Object.freeze([...Ge(e,T)])}let I=ie({getAvailableActionsFor:d,projectSnapshotFromCanonical:i});function C(){return d(f())}let me=(T=>T!==void 0?m[String(T)]:p);function K(T,E){return ze(e,T,String(E))}function he(T){return K(f(),T)}function _(T,E){return Be(e,T,E)}let ye=((T,...E)=>_(f(),r(T,...E)));function $(T){return T.intentId&&T.intentId.length>0?T:{...T,intentId:ue()}}async function Se(T,E){return n.dispatch(T,E)}let B=null,M=se({schema:e,ensureIntentId:$,getAvailableActionsFor:d,isActionAvailableFor:K,isIntentDispatchableFor:_,projectSnapshotFromCanonical:i,getSimulateSync:()=>{if(!B)throw new R("SCHEMA_ERROR","Runtime simulation surface is not initialized");return B},emitEvent:A}),G=le({schema:e,hostContextProvider:a,evaluateIntentLegalityFor:M.evaluateIntentLegalityFor});B=G.simulateSync;let W=re({setVisibleSnapshot:b,restoreVisibleSnapshot:v,getCanonicalSnapshot:f,emitEvent:A}),X=M.getIntentBlockersFor,Te=((T,...E)=>X(f(),r(T,...E))),be=G.simulateSync,Re=((T,...E)=>{let g=G.simulateSync(f(),r(T,...E)),P=i(g.snapshot);return Object.freeze({snapshot:P,changedPaths:F(h(),P),newAvailableActions:d(g.snapshot),requirements:g.requirements,status:g.status})}),Ee=Object.freeze({MEL:o,schema:e,createIntent:r,getCanonicalSnapshot:f,projectSnapshot:T=>i(T),simulateSync:(T,E)=>{let g=G.simulateSync(T,E);return Object.freeze({snapshot:g.snapshot,patches:g.patches,requirements:g.requirements,status:g.status})},getAvailableActionsFor:d,isActionAvailableFor:K,isIntentDispatchableFor:_,explainIntentFor:M.explainIntentFor});return{schema:e,MEL:o,createIntent:r,subscribe:s,on:l,getSnapshot:h,getAvailableActionsFor:d,getAvailableActions:C,getIntentBlockersFor:X,getActionMetadata:me,isActionAvailableFor:K,isActionAvailable:he,isIntentDispatchableFor:_,isIntentDispatchable:ye,getIntentBlockers:Te,getSchemaGraph(){return N},simulateSync:be,simulate:Re,dispose:D,isDisposed:w,getCanonicalSnapshot:f,getVisibleCoreSnapshot:S,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]:Ee}}function Nt(e,t,n){Object.defineProperty(e,z,{enumerable:!1,configurable:!1,writable:!1,value:t});let a=n??de(e)??{activated:!1};return de(e)||Object.defineProperty(e,L,{enumerable:!1,configurable:!1,writable:!1,value:a}),e}function Pt(e){let n=e[z];if(typeof n!="function")throw new R("SCHEMA_ERROR","ComposableManifesto is missing its runtime kernel factory");return n}function Lt(e,t){return Object.defineProperty(e,k,{enumerable:!1,configurable:!1,writable:!1,value:t[k]}),e}function Ft(e){let n=e[k];if(!n)throw new R("SCHEMA_ERROR","Activated runtime is missing its extension kernel");return n}function fe(e){let n=e[L];if(!n)throw new R("SCHEMA_ERROR","ComposableManifesto is missing its activation state");return n}function Kt(e){if(fe(e).activated)throw new H}function _t(e){let t=fe(e);if(t.activated)throw new H;t.activated=!0}function de(e){return e[L]??null}export{U as a,De as b,k as c,qe as d,$e as e,x as f,te as g,ne as h,re as i,ue as j,Ue as k,Nt as l,Pt as m,Lt as n,Ft as o,fe as p,Kt as q,_t as r};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type ComputeStatus, type DomainSchema, type Patch, type Requirement, type Snapshot as CoreSnapshot, type SystemDelta } from "@manifesto-ai/core";
|
|
2
|
+
import type { HostContextProvider, HostResult, ManifestoHost } from "@manifesto-ai/host";
|
|
3
|
+
import { ManifestoError } from "../errors.js";
|
|
4
|
+
import type { BaseLaws, CanonicalSnapshot, ComposableManifesto, DispatchBlocker, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, IntentAdmission, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, SchemaGraph, Snapshot, TypedCreateIntent, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIntent, TypedIsIntentDispatchable, TypedMEL, TypedOn, TypedSimulate, TypedSubscribe } from "../types.js";
|
|
5
|
+
import type { SnapshotProjectionPlan } from "../projection/snapshot-projection.js";
|
|
6
|
+
import type { ExtensionKernel } from "../extensions-types.js";
|
|
7
|
+
import type { IntentLegalityEvaluation } from "../runtime/facets.js";
|
|
8
|
+
import { ACTIVATION_STATE, EXTENSION_KERNEL, RUNTIME_KERNEL_FACTORY, type ActivationState } from "./runtime-symbols.js";
|
|
9
|
+
export { ACTION_PARAM_NAMES, ACTION_SINGLE_PARAM_OBJECT_VALUE, ACTIVATION_STATE, EXTENSION_KERNEL, RUNTIME_KERNEL_FACTORY, type ActivationState, } from "./runtime-symbols.js";
|
|
10
|
+
export type HostDispatchOptions = NonNullable<Parameters<ManifestoHost["dispatch"]>[1]>;
|
|
11
|
+
export type SimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
12
|
+
readonly snapshot: CanonicalSnapshot<T["state"]>;
|
|
13
|
+
readonly patches: readonly Patch[];
|
|
14
|
+
readonly systemDelta: Readonly<SystemDelta>;
|
|
15
|
+
readonly status: ComputeStatus;
|
|
16
|
+
readonly requirements: readonly Requirement[];
|
|
17
|
+
};
|
|
18
|
+
export interface RuntimeKernel<T extends ManifestoDomainShape> {
|
|
19
|
+
readonly schema: DomainSchema;
|
|
20
|
+
readonly MEL: TypedMEL<T>;
|
|
21
|
+
readonly createIntent: TypedCreateIntent<T>;
|
|
22
|
+
readonly subscribe: TypedSubscribe<T>;
|
|
23
|
+
readonly on: TypedOn<T>;
|
|
24
|
+
readonly getSnapshot: () => Snapshot<T["state"]>;
|
|
25
|
+
readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
|
|
26
|
+
readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
|
|
27
|
+
readonly getAvailableActions: () => readonly (keyof T["actions"])[];
|
|
28
|
+
readonly getIntentBlockersFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => readonly DispatchBlocker[];
|
|
29
|
+
readonly getActionMetadata: TypedGetActionMetadata<T>;
|
|
30
|
+
readonly isActionAvailableFor: (snapshot: CanonicalSnapshot<T["state"]>, name: keyof T["actions"]) => boolean;
|
|
31
|
+
readonly isActionAvailable: (name: keyof T["actions"]) => boolean;
|
|
32
|
+
readonly isIntentDispatchableFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => boolean;
|
|
33
|
+
readonly isIntentDispatchable: TypedIsIntentDispatchable<T>;
|
|
34
|
+
readonly getIntentBlockers: TypedGetIntentBlockers<T>;
|
|
35
|
+
readonly getSchemaGraph: () => SchemaGraph;
|
|
36
|
+
readonly simulateSync: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => SimulateResult<T>;
|
|
37
|
+
readonly simulate: TypedSimulate<T>;
|
|
38
|
+
readonly dispose: () => void;
|
|
39
|
+
readonly isDisposed: () => boolean;
|
|
40
|
+
readonly getVisibleCoreSnapshot: () => CoreSnapshot;
|
|
41
|
+
readonly setVisibleSnapshot: (snapshot: CoreSnapshot, options?: {
|
|
42
|
+
readonly notify?: boolean;
|
|
43
|
+
}) => Snapshot<T["state"]>;
|
|
44
|
+
readonly restoreVisibleSnapshot: () => void;
|
|
45
|
+
readonly emitEvent: <K extends ManifestoEvent>(event: K, payload: ManifestoEventMap<T>[K]) => void;
|
|
46
|
+
readonly enqueue: <R>(task: () => Promise<R>) => Promise<R>;
|
|
47
|
+
readonly ensureIntentId: (intent: TypedIntent<T>) => TypedIntent<T>;
|
|
48
|
+
readonly executeHost: (intent: TypedIntent<T>, options?: HostDispatchOptions) => Promise<HostResult>;
|
|
49
|
+
readonly validateIntentInputFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => ManifestoError | null;
|
|
50
|
+
readonly evaluateIntentLegalityFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => IntentLegalityEvaluation<T>;
|
|
51
|
+
readonly deriveIntentAdmission: (snapshot: CanonicalSnapshot<T["state"]>, legality: IntentLegalityEvaluation<T>) => IntentAdmission<T>;
|
|
52
|
+
readonly deriveExecutionOutcome: (beforeSnapshot: CanonicalSnapshot<T["state"]>, afterSnapshot: CanonicalSnapshot<T["state"]>) => ExecutionOutcome<T>;
|
|
53
|
+
readonly classifyExecutionFailure: (error: unknown, stage: "host" | "seal") => ExecutionFailureInfo;
|
|
54
|
+
readonly createExecutionDiagnostics: (result: HostResult) => ExecutionDiagnostics;
|
|
55
|
+
readonly createUnavailableError: (intent: TypedIntent<T>) => ManifestoError;
|
|
56
|
+
readonly createNotDispatchableError: (intent: TypedIntent<T>) => ManifestoError;
|
|
57
|
+
readonly rejectInvalidInput: (intent: TypedIntent<T>, message: string) => never;
|
|
58
|
+
readonly rejectUnavailable: (intent: TypedIntent<T>) => never;
|
|
59
|
+
readonly rejectNotDispatchable: (intent: TypedIntent<T>) => never;
|
|
60
|
+
readonly [EXTENSION_KERNEL]: ExtensionKernel<T>;
|
|
61
|
+
}
|
|
62
|
+
type RuntimePublicReadFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "schema" | "MEL" | "createIntent" | "subscribe" | "on" | "getSnapshot" | "getCanonicalSnapshot" | "getAvailableActions" | "isIntentDispatchable" | "getIntentBlockers" | "getActionMetadata" | "isActionAvailable" | "getSchemaGraph" | "simulate">;
|
|
63
|
+
type RuntimeLifecycleFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "dispose" | "isDisposed" | "enqueue">;
|
|
64
|
+
type RuntimeExecutionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "ensureIntentId" | "executeHost">;
|
|
65
|
+
type RuntimeSealAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isActionAvailable" | "validateIntentInputFor" | "isIntentDispatchableFor" | "rejectUnavailable" | "rejectInvalidInput" | "rejectNotDispatchable">;
|
|
66
|
+
type RuntimeReportAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "evaluateIntentLegalityFor" | "deriveIntentAdmission" | "createUnavailableError" | "createNotDispatchableError">;
|
|
67
|
+
type RuntimePublicationFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "getVisibleCoreSnapshot" | "setVisibleSnapshot" | "restoreVisibleSnapshot">;
|
|
68
|
+
type RuntimeReportingFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "deriveExecutionOutcome" | "classifyExecutionFailure" | "createExecutionDiagnostics">;
|
|
69
|
+
type RuntimeDispatchEventsFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "emitEvent">;
|
|
70
|
+
type RuntimeExtensionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, typeof EXTENSION_KERNEL>;
|
|
71
|
+
export type LineageRuntimeKernel<T extends ManifestoDomainShape> = RuntimePublicReadFacet<T> & RuntimeLifecycleFacet<T> & RuntimeExecutionFacet<T> & RuntimeSealAdmissionFacet<T> & RuntimeReportAdmissionFacet<T> & RuntimePublicationFacet<T> & RuntimeReportingFacet<T> & RuntimeDispatchEventsFacet<T> & RuntimeExtensionFacet<T>;
|
|
72
|
+
export type LineageRuntimeKernelFactory<T extends ManifestoDomainShape> = () => LineageRuntimeKernel<T>;
|
|
73
|
+
export type GovernanceRuntimeKernel<T extends ManifestoDomainShape> = RuntimePublicReadFacet<T> & RuntimeLifecycleFacet<T> & RuntimeExecutionFacet<T> & RuntimeSealAdmissionFacet<T> & RuntimePublicationFacet<T> & Pick<RuntimeKernel<T>, "deriveExecutionOutcome"> & RuntimeDispatchEventsFacet<T> & RuntimeExtensionFacet<T>;
|
|
74
|
+
export type GovernanceRuntimeKernelFactory<T extends ManifestoDomainShape> = () => GovernanceRuntimeKernel<T>;
|
|
75
|
+
export type WaitForProposalRuntimeKernel<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isDisposed" | "deriveExecutionOutcome">;
|
|
76
|
+
export type RuntimeKernelFactory<T extends ManifestoDomainShape> = () => RuntimeKernel<T>;
|
|
77
|
+
export type InternalComposableManifesto<T extends ManifestoDomainShape, Laws extends BaseLaws> = ComposableManifesto<T, Laws> & {
|
|
78
|
+
readonly [RUNTIME_KERNEL_FACTORY]: RuntimeKernelFactory<T>;
|
|
79
|
+
readonly [ACTIVATION_STATE]: ActivationState;
|
|
80
|
+
};
|
|
81
|
+
export type RuntimeKernelOptions<T extends ManifestoDomainShape> = {
|
|
82
|
+
readonly schema: DomainSchema;
|
|
83
|
+
readonly projectionPlan: SnapshotProjectionPlan;
|
|
84
|
+
readonly host: ManifestoHost;
|
|
85
|
+
readonly hostContextProvider: HostContextProvider;
|
|
86
|
+
readonly MEL: TypedMEL<T>;
|
|
87
|
+
readonly createIntent: TypedCreateIntent<T>;
|
|
88
|
+
};
|
|
89
|
+
export declare function attachRuntimeKernelFactory<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>, factory: RuntimeKernelFactory<T>, activationState?: ActivationState): InternalComposableManifesto<T, Laws>;
|
|
90
|
+
export declare function getRuntimeKernelFactory<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): RuntimeKernelFactory<T>;
|
|
91
|
+
export declare function attachExtensionKernel<T extends ManifestoDomainShape, TInstance extends object>(runtime: TInstance, kernel: RuntimeExtensionFacet<T>): TInstance;
|
|
92
|
+
export declare function getAttachedExtensionKernel<T extends ManifestoDomainShape>(runtime: object): ExtensionKernel<T>;
|
|
93
|
+
export declare function getActivationState<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): ActivationState;
|
|
94
|
+
export declare function assertComposableNotActivated<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): void;
|
|
95
|
+
export declare function activateComposable<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): void;
|
|
96
|
+
export { createRuntimeKernel } from "../runtime/kernel.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const ACTION_PARAM_NAMES: unique symbol;
|
|
2
|
+
export declare const ACTION_SINGLE_PARAM_OBJECT_VALUE: unique symbol;
|
|
3
|
+
export declare const RUNTIME_KERNEL_FACTORY: unique symbol;
|
|
4
|
+
export declare const ACTIVATION_STATE: unique symbol;
|
|
5
|
+
export declare const EXTENSION_KERNEL: unique symbol;
|
|
6
|
+
export type ActivationState = {
|
|
7
|
+
activated: boolean;
|
|
8
|
+
};
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { type BaseComposableLaws, type ComposableManifesto, type EffectHandler, type ManifestoDomainShape } from "./types.js";
|
|
3
|
-
export declare function createManifesto<T extends ManifestoDomainShape>(schemaInput: DomainSchema | string, effects: Record<string, EffectHandler>): ComposableManifesto<T, BaseComposableLaws>;
|
|
1
|
+
export { createManifesto } from "./manifest/create-manifesto.js";
|
package/dist/extensions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionKernel } from "./extensions-types.js";
|
|
2
2
|
import type { BaseLaws, ActivatedInstance, ManifestoDomainShape } from "./types.js";
|
|
3
3
|
export type { ExtensionKernel, ExtensionSimulateResult, SimulationActionRef, SimulationSession, SimulationSessionResult, SimulationSessionStatus, SimulationSessionStep, } from "./extensions-types.js";
|
|
4
|
-
export { createSimulationSession } from "./simulation-session.js";
|
|
4
|
+
export { createSimulationSession } from "./projection/simulation-session.js";
|
|
5
5
|
export declare function getExtensionKernel<T extends ManifestoDomainShape, Laws extends BaseLaws>(app: ActivatedInstance<T, Laws>): ExtensionKernel<T>;
|
package/dist/extensions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{f as m,o as c}from"./chunk-5BUS6Q4E.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, ActionObjectBindingArgs, DispatchBlocker, TypedActionMetadata, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIsIntentDispatchable, BaseLaws, BaseComposableLaws, CanonicalPlatformNamespaces, CanonicalSnapshot, ComposableManifesto, ComputedRef, EffectContext, EffectHandler, FieldRef, GovernedComposableLaws, GovernanceLaws, IntentExplanation, LineageComposableLaws, LineageLaws, ManifestoBaseInstance, ManifestoDecoratedRuntimeByLaws, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, ManifestoEventPayload, ManifestoRuntimeByLaws, Selector, SimulateResult, 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, ManifestoDecoratedRuntimeByLaws, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, ManifestoEventPayload, ManifestoRuntimeByLaws, Selector, SimulateResult, ProjectedDiff, CanonicalOutcome, SchemaGraph, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, SchemaGraphNodeRef, Snapshot, TypedActionRef, TypedCommitAsync, TypedCreateIntent, TypedDispatchAsync, TypedIntent, TypedMEL, TypedOn, TypedSimulate, 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
|
|
2
|
-
`)[
|
|
3
|
-
${
|
|
4
|
-
${
|
|
1
|
+
import{a as y,b,c as H,d as L,e as N,f as B,g as V,h as $,i as F,j as E,k as A,l as G,n as z,r as K}from"./chunk-5BUS6Q4E.js";import{a as p,b as R,c as j,d as h,e as ne}from"./chunk-BDIXNUQ3.js";async function P(e,t,n,o){let r=e.getCanonicalSnapshot(),i=t.projectSnapshot(r),a=e.evaluateIntentLegalityFor(r,o),d=e.deriveIntentAdmission(r,a);if(a.kind!=="admitted"){let u=d,f=ae(e,a),T=V(e.emitEvent,a.intent,f);return{kind:"rejected",intent:a.intent,admission:u,beforeSnapshot:i,beforeCanonicalSnapshot:r,rejection:T,rejectionError:f}}let c=d,s;try{s=await e.executeHost(a.intent)}catch(u){let f=oe(u);return $(e.emitEvent,a.intent,f),{kind:"failed",intent:a.intent,admission:c,beforeSnapshot:i,beforeCanonicalSnapshot:r,failure:f,errorInfo:e.classifyExecutionFailure(f,"host"),published:!1}}let l=e.createExecutionDiagnostics(s);if(s.status==="error"){let u=s.error??new p("HOST_ERROR","Host dispatch failed"),{publishedSnapshot:f,publishedCanonicalSnapshot:T}=n.publishFailedHostResult(a.intent,u,s.snapshot);return{kind:"failed",intent:a.intent,admission:c,beforeSnapshot:i,beforeCanonicalSnapshot:r,failure:u,errorInfo:e.classifyExecutionFailure(u,"host"),published:!0,diagnostics:l,outcome:e.deriveExecutionOutcome(r,T)}}let{publishedSnapshot:m,publishedCanonicalSnapshot:k}=n.publishCompletedHostResult(a.intent,s.snapshot);return{kind:"completed",intent:a.intent,admission:c,publishedSnapshot:m,outcome:e.deriveExecutionOutcome(r,k),diagnostics:l}}function q(e){if(e.kind==="completed")return e.publishedSnapshot;throw e.kind==="rejected"?e.rejectionError:e.failure}function U(e){return e.kind==="completed"?Object.freeze({kind:"completed",intent:e.intent,admission:e.admission,outcome:e.outcome,diagnostics:e.diagnostics}):e.kind==="rejected"?Object.freeze({kind:"rejected",intent:e.intent,admission:e.admission,beforeSnapshot:e.beforeSnapshot,beforeCanonicalSnapshot:e.beforeCanonicalSnapshot,rejection:e.rejection}):Object.freeze({kind:"failed",intent:e.intent,admission:e.admission,beforeSnapshot:e.beforeSnapshot,beforeCanonicalSnapshot:e.beforeCanonicalSnapshot,error:e.errorInfo,published:e.published,...e.diagnostics!==void 0?{diagnostics:e.diagnostics}:{},...e.outcome!==void 0?{outcome:e.outcome}:{}})}function ae(e,t){if(t.kind==="unavailable")return e.createUnavailableError(t.intent);if(t.kind==="invalid-input")return t.error;if(t.kind==="not-dispatchable")return e.createNotDispatchableError(t.intent);throw new p("SDK_REPORT_ERROR","Cannot derive a rejected dispatch error for an admitted intent")}function oe(e){return e instanceof Error?e:new Error(String(e))}function W(e){let t=e[H],n=F({setVisibleSnapshot:e.setVisibleSnapshot,restoreVisibleSnapshot:e.restoreVisibleSnapshot,getCanonicalSnapshot:e.getCanonicalSnapshot,emitEvent:e.emitEvent});function o(c){if(e.isDisposed())return Promise.reject(new h);let s=e.ensureIntentId(c);return e.enqueue(async()=>{if(e.isDisposed())throw new h;return q(await P(e,t,n,s))})}function r(c){if(e.isDisposed())return Promise.reject(new h);let s=e.ensureIntentId(c);return e.enqueue(async()=>{if(e.isDisposed())throw new h;return U(await P(e,t,n,s))})}function i(c){return t.explainIntentFor(e.getCanonicalSnapshot(),c)}function a(c){return i(c)}function d(c){let s=i(c);return s.kind==="blocked"?s.blockers:null}return z({createIntent:e.createIntent,dispatchAsync:o,dispatchAsyncWithReport: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:a,whyNot:d,getActionMetadata:e.getActionMetadata,isActionAvailable:e.isActionAvailable,getSchemaGraph:e.getSchemaGraph,simulate:e.simulate,MEL:e.MEL,schema:e.schema,dispose:e.dispose},e)}import{createHostContextProvider as de,createHost as pe,defaultRuntime as le}from"@manifesto-ai/host";import{extractDefaults as me}from"@manifesto-ai/core";import{semanticPathToPatchPath as re}from"@manifesto-ai/core";function ie(e){return typeof e=="object"&&e!==null&&"key"in e&&"into"in e}function X(e,t){if(ie(e))return{patches:[{op:"set",path:J(e.into),value:se(e.key)}]};let{path:n,target:o}=e,r=ce(n,t);return o?{patches:[{op:"set",path:J(o),value:r.value}]}:{patches:[]}}function se(e){switch(e){case"uuid":return E();case"timestamp":case"time.now":return Date.now();case"isoTimestamp":return new Date().toISOString();default:return null}}function J(e){let t=Y(e),n=t.startsWith("data.")?t.slice(5):t;return re(n)}function Y(e){return e.startsWith("/")?e.slice(1).replace(/\//g,"."):e}function ce(e,t){let o=Y(e).split(".");if(o.length===0)return{value:void 0,found:!1};let[r,...i]=o,a;switch(r){case"data":a=t.data;break;case"computed":a=t.computed;break;case"system":a=t.system;break;case"meta":a=t.meta;break;default:a=t.data,i.unshift(r);break}for(let d of i){if(a==null||typeof a!="object")return{value:void 0,found:!1};a=a[d]}return{value:a,found:a!==void 0}}var S="system.get",M="system.",Q=Object.freeze({__baseLaws:!0});function D(e,t,n){let o=le,r=pe(e,{initialData:me(e.state),runtime:o}),i=de(o);r.registerEffect(S,async(a,d,c)=>{let{patches:s}=X(d,c.snapshot);return s});for(let[a,d]of Object.entries(n)){let c=async(s,l,m)=>await d(l,{snapshot:B(N(m.snapshot,t))});r.registerEffect(a,c)}return{host:r,contextProvider:i}}import{createIntent as ue}from"@manifesto-ai/core";function I(){return(e,...t)=>{let n=e,o=E(),r=fe(n,t);return ue(String(e.name),r,o)}}function fe(e,t){let n=Object.hasOwn(e,y)?e[y]:[];if(t.length!==0){if(n===null){if(t.length===1&&g(t[0]))return t[0];throw new p("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 p("INVALID_INTENT_ARGS",`Action "${String(e.name)}" does not accept multiple positional arguments`)}return n.length===1&&t.length===1&&g(t[0])&&e[b]?{[n[0]??"arg0"]:t[0]}:n.length===1&&t.length===1&&he(t[0],n[0])||t.length===1&&g(t[0])&&n.length>1?t[0]:Object.fromEntries(t.map((o,r)=>[n[r]??`arg${r}`,o]))}}function g(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function he(e,t){if(!t||!g(e))return!1;let n=Object.keys(e);return n.length===1&&n[0]===t}import{hashSchemaSync as Re}from"@manifesto-ai/core";import{compileMelDomain as ye,parse as Se,tokenize as be}from"@manifesto-ai/compiler";function Z(e){let t=ye(e,{mode:"domain"});if(t.errors.length>0){let o=t.errors.map(r=>{let i=r.location;if(!i||i.start.line===0&&i.start.column===0)return`[${r.code}] ${r.message}`;let a=`[${r.code}] ${r.message} (${i.start.line}:${i.start.column})`,d=e.split(`
|
|
2
|
+
`)[i.start.line-1];if(!d)return a;let c=String(i.start.line).padStart(4," "),s=Math.max(1,i.end.line===i.start.line?Math.min(i.end.column-i.start.column,Math.max(1,d.length-i.start.column+1)):1),l=" ".repeat(c.length+3+i.start.column-1);return`${a}
|
|
3
|
+
${c} | ${d}
|
|
4
|
+
${l}${"^".repeat(s)}`}).join(`
|
|
5
5
|
|
|
6
|
-
`);throw new
|
|
7
|
-
${
|
|
6
|
+
`);throw new j(t.errors,`MEL compilation failed:
|
|
7
|
+
${o}`)}if(!t.schema)throw new p("COMPILE_ERROR","MEL compilation produced no schema");let n=t.schema;return{schema:n,actionParamMetadata:O(n,Te(e)),actionSingleParamObjectValueMetadata:w(n)}}function O(e,t){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([n,o])=>{let r=t?.[n];if(r&&r.length>0)return[n,Object.freeze([...r])];if(o.params&&o.params.length>0){let a=Object.freeze([...o.params]);return[n,a]}if(!o.input||o.input.type!=="object"||!o.input.fields)return[n,[]];let i=Ee(o.input);return[n,i.length<=1?i:null]})))}function w(e){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([t,n])=>[t,ge(e,n)])))}function Ee(e){return!e||e.type!=="object"||!e.fields?[]:Object.keys(e.fields)}function ge(e,t){if(t.params?.length===1&&t.inputType){let n=x(t.inputType,t.params[0]??"",e.types);return n?C(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 x(e,t,n,o=[]){if(e.kind==="ref"){if(o.includes(e.name))return null;let r=n[e.name];return r?x(r.definition,t,n,[...o,e.name]):null}if(e.kind==="union"){let r=e.types.filter(i=>!v(i,n,o));return r.length===1?x(r[0],t,n,o):null}return e.kind!=="object"?null:e.fields[t]?.type??null}function C(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let o=t[e.name];return o?C(o.definition,t,[...n,e.name]):!1}if(e.kind==="union"){let o=e.types.filter(r=>!v(r,t,n));return o.length===1?C(o[0],t,n):!1}return e.kind==="object"||e.kind==="record"||e.kind==="primitive"&&e.type==="object"}function v(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let o=t[e.name];return o?v(o.definition,t,[...n,e.name]):!1}return e.kind==="primitive"&&e.type==="null"||e.kind==="literal"&&e.value===null}function Te(e){let t=be(e);if(t.diagnostics.some(o=>o.severity==="error"))return;let n=Se(t.tokens);if(n.program)return Object.freeze(Object.fromEntries(n.program.domain.members.filter(o=>o.kind==="action").map(o=>[o.name,Object.freeze(o.params.map(r=>r.name))])))}function ee(e){let t=typeof e=="string"?Z(e):{schema:e,actionParamMetadata:O(e),actionSingleParamObjectValueMetadata:w(e)},n=je(t.schema);return Ae(n),{schema:n,actionParamMetadata:t.actionParamMetadata,actionSingleParamObjectValueMetadata:t.actionSingleParamObjectValueMetadata,projectionPlan:L(n)}}function je(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 p("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 p("SCHEMA_ERROR","Reserved namespace '$mel' must be an object field");{let a=t.$mel;a.default===void 0&&(a={...a,default:{guards:{intent:{}}}},n=!0);let d=a.fields??{},c=d.guards;if(!c)a={...a,fields:{...d,guards:{type:"object",required:!1,default:{intent:{}},fields:{intent:{type:"object",required:!1,default:{}}}}}},n=!0;else{if(c.type!=="object")throw new p("SCHEMA_ERROR","Reserved namespace '$mel.guards' must be an object field");{let s=c;s.default===void 0&&(s={...s,default:{intent:{}}},n=!0);let l=s.fields??{},m=l.intent;if(!m)s={...s,fields:{...l,intent:{type:"object",required:!1,default:{}}}},n=!0;else{if(m.type!=="object")throw new p("SCHEMA_ERROR","Reserved namespace '$mel.guards.intent' must be an object field");m.default===void 0&&(s={...s,fields:{...l,intent:{...m,default:{}}}},n=!0)}s!==c&&(a={...a,fields:{...d,guards:s}})}}a!==t.$mel&&(t.$mel=a)}}if(!n)return e;let o={...e,state:{...e.state,fields:t}},{hash:r,...i}=o;return{...o,hash:Re(i)}}function Ae(e){for(let t of Object.keys(e.actions??{}))if(t.startsWith(M))throw new p("RESERVED_NAMESPACE",`Action type "${t}" uses reserved namespace prefix "${M}"`)}function _(e,t,n){let o=Object.fromEntries(Object.keys(e.actions).map(a=>{let d={__kind:"ActionRef",name:a};return Object.defineProperty(d,y,{enumerable:!1,configurable:!1,writable:!1,value:Object.hasOwn(t,a)?t[a]:[]}),Object.defineProperty(d,b,{enumerable:!1,configurable:!1,writable:!1,value:n[a]??!1}),[a,Object.freeze(d)]})),r=Object.fromEntries(Object.keys(e.state.fields).filter(a=>!a.startsWith("$")).map(a=>[a,Object.freeze({__kind:"FieldRef",name:a})])),i=Object.fromEntries(Object.keys(e.computed.fields).map(a=>[a,Object.freeze({__kind:"ComputedRef",name:a})]));return Object.freeze({actions:Object.freeze(o),state:Object.freeze(r),computed:Object.freeze(i)})}function te(e,t){if(S in t)throw new R(S);let n=ee(e),o={_laws:Q,schema:n.schema,activate(){K(o);let r=D(n.schema,n.projectionPlan,t);return W(A({schema:n.schema,projectionPlan:n.projectionPlan,host:r.host,hostContextProvider:r.contextProvider,MEL:_(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:I()}))}};return G(o,()=>{let r=D(n.schema,n.projectionPlan,t);return A({schema:n.schema,projectionPlan:n.projectionPlan,host:r.host,hostContextProvider:r.contextProvider,MEL:_(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:I()})})}import{createSnapshot as gt}from"@manifesto-ai/core";export{ne as AlreadyActivatedError,j as CompileError,h as DisposedError,p as ManifestoError,R as ReservedEffectError,te as createManifesto,gt as createSnapshot};
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,84 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { HostContextProvider, HostResult, ManifestoHost } from "@manifesto-ai/host";
|
|
3
|
-
import { ManifestoError } from "./errors.js";
|
|
4
|
-
import type { BaseLaws, CanonicalSnapshot, ComposableManifesto, DispatchBlocker, ManifestoBaseInstance, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, SchemaGraph, Snapshot, TypedCreateIntent, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIntent, TypedIsIntentDispatchable, TypedMEL, TypedOn, TypedSimulate, TypedSubscribe } from "./types.js";
|
|
5
|
-
import { type SnapshotProjectionPlan } from "./snapshot-projection.js";
|
|
6
|
-
import type { ExtensionKernel } from "./extensions-types.js";
|
|
7
|
-
export declare const ACTION_PARAM_NAMES: unique symbol;
|
|
8
|
-
export declare const ACTION_SINGLE_PARAM_OBJECT_VALUE: unique symbol;
|
|
9
|
-
export declare const RUNTIME_KERNEL_FACTORY: unique symbol;
|
|
10
|
-
export declare const ACTIVATION_STATE: unique symbol;
|
|
11
|
-
export declare const EXTENSION_KERNEL: unique symbol;
|
|
12
|
-
export type ActivationState = {
|
|
13
|
-
activated: boolean;
|
|
14
|
-
};
|
|
15
|
-
export type HostDispatchOptions = NonNullable<Parameters<ManifestoHost["dispatch"]>[1]>;
|
|
16
|
-
export type SimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
17
|
-
readonly snapshot: CanonicalSnapshot<T["state"]>;
|
|
18
|
-
readonly patches: readonly Patch[];
|
|
19
|
-
readonly systemDelta: Readonly<SystemDelta>;
|
|
20
|
-
readonly status: ComputeStatus;
|
|
21
|
-
readonly requirements: readonly Requirement[];
|
|
22
|
-
};
|
|
23
|
-
export interface RuntimeKernel<T extends ManifestoDomainShape> {
|
|
24
|
-
readonly schema: DomainSchema;
|
|
25
|
-
readonly MEL: TypedMEL<T>;
|
|
26
|
-
readonly createIntent: TypedCreateIntent<T>;
|
|
27
|
-
readonly subscribe: TypedSubscribe<T>;
|
|
28
|
-
readonly on: TypedOn<T>;
|
|
29
|
-
readonly getSnapshot: () => Snapshot<T["state"]>;
|
|
30
|
-
readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
|
|
31
|
-
readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
|
|
32
|
-
readonly getAvailableActions: () => readonly (keyof T["actions"])[];
|
|
33
|
-
readonly getIntentBlockersFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => readonly DispatchBlocker[];
|
|
34
|
-
readonly getActionMetadata: TypedGetActionMetadata<T>;
|
|
35
|
-
readonly isActionAvailableFor: (snapshot: CanonicalSnapshot<T["state"]>, name: keyof T["actions"]) => boolean;
|
|
36
|
-
readonly isActionAvailable: (name: keyof T["actions"]) => boolean;
|
|
37
|
-
readonly isIntentDispatchableFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => boolean;
|
|
38
|
-
readonly isIntentDispatchable: TypedIsIntentDispatchable<T>;
|
|
39
|
-
readonly getIntentBlockers: TypedGetIntentBlockers<T>;
|
|
40
|
-
readonly getSchemaGraph: () => SchemaGraph;
|
|
41
|
-
readonly simulateSync: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => SimulateResult<T>;
|
|
42
|
-
readonly simulate: TypedSimulate<T>;
|
|
43
|
-
readonly dispose: () => void;
|
|
44
|
-
readonly isDisposed: () => boolean;
|
|
45
|
-
readonly getVisibleCoreSnapshot: () => CoreSnapshot;
|
|
46
|
-
readonly setVisibleSnapshot: (snapshot: CoreSnapshot, options?: {
|
|
47
|
-
readonly notify?: boolean;
|
|
48
|
-
}) => Snapshot<T["state"]>;
|
|
49
|
-
readonly restoreVisibleSnapshot: () => void;
|
|
50
|
-
readonly emitEvent: <K extends ManifestoEvent>(event: K, payload: ManifestoEventMap<T>[K]) => void;
|
|
51
|
-
readonly enqueue: <R>(task: () => Promise<R>) => Promise<R>;
|
|
52
|
-
readonly ensureIntentId: (intent: TypedIntent<T>) => TypedIntent<T>;
|
|
53
|
-
readonly executeHost: (intent: TypedIntent<T>, options?: HostDispatchOptions) => Promise<HostResult>;
|
|
54
|
-
readonly validateIntentInputFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => ManifestoError | null;
|
|
55
|
-
readonly createUnavailableError: (intent: TypedIntent<T>) => ManifestoError;
|
|
56
|
-
readonly createNotDispatchableError: (intent: TypedIntent<T>) => ManifestoError;
|
|
57
|
-
readonly rejectInvalidInput: (intent: TypedIntent<T>, message: string) => never;
|
|
58
|
-
readonly rejectUnavailable: (intent: TypedIntent<T>) => never;
|
|
59
|
-
readonly rejectNotDispatchable: (intent: TypedIntent<T>) => never;
|
|
60
|
-
readonly [EXTENSION_KERNEL]: ExtensionKernel<T>;
|
|
61
|
-
}
|
|
62
|
-
export type RuntimeKernelFactory<T extends ManifestoDomainShape> = () => RuntimeKernel<T>;
|
|
63
|
-
export type InternalComposableManifesto<T extends ManifestoDomainShape, Laws extends BaseLaws> = ComposableManifesto<T, Laws> & {
|
|
64
|
-
readonly [RUNTIME_KERNEL_FACTORY]: RuntimeKernelFactory<T>;
|
|
65
|
-
readonly [ACTIVATION_STATE]: ActivationState;
|
|
66
|
-
};
|
|
67
|
-
type RuntimeKernelOptions<T extends ManifestoDomainShape> = {
|
|
68
|
-
readonly schema: DomainSchema;
|
|
69
|
-
readonly projectionPlan: SnapshotProjectionPlan;
|
|
70
|
-
readonly host: ManifestoHost;
|
|
71
|
-
readonly hostContextProvider: HostContextProvider;
|
|
72
|
-
readonly MEL: TypedMEL<T>;
|
|
73
|
-
readonly createIntent: TypedCreateIntent<T>;
|
|
74
|
-
};
|
|
75
|
-
export declare function attachRuntimeKernelFactory<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>, factory: RuntimeKernelFactory<T>, activationState?: ActivationState): InternalComposableManifesto<T, Laws>;
|
|
76
|
-
export declare function getRuntimeKernelFactory<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): RuntimeKernelFactory<T>;
|
|
77
|
-
export declare function attachExtensionKernel<T extends ManifestoDomainShape, TInstance extends object>(runtime: TInstance, kernel: RuntimeKernel<T>): TInstance;
|
|
78
|
-
export declare function getAttachedExtensionKernel<T extends ManifestoDomainShape>(runtime: object): ExtensionKernel<T>;
|
|
79
|
-
export declare function getActivationState<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): ActivationState;
|
|
80
|
-
export declare function assertComposableNotActivated<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): void;
|
|
81
|
-
export declare function activateComposable<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): void;
|
|
82
|
-
export declare function createRuntimeKernel<T extends ManifestoDomainShape>({ schema, projectionPlan, host, hostContextProvider, MEL, createIntent, }: RuntimeKernelOptions<T>): RuntimeKernel<T>;
|
|
83
|
-
export declare function createBaseRuntimeInstance<T extends ManifestoDomainShape>(kernel: RuntimeKernel<T>): ManifestoBaseInstance<T>;
|
|
84
|
-
export {};
|
|
1
|
+
export * from "./compat/internal.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type DomainSchema } from "@manifesto-ai/core";
|
|
2
|
+
import type { ActionParamMetadata, ActionSingleParamObjectValueMetadata, CompiledSchema } from "./shared.js";
|
|
3
|
+
export declare function compileSchema(source: string): CompiledSchema;
|
|
4
|
+
export declare function deriveActionParamMetadata(schema: DomainSchema, actionParamOrder?: Readonly<Record<string, readonly string[]>>): Readonly<Record<string, ActionParamMetadata>>;
|
|
5
|
+
export declare function deriveSingleParamObjectValueMetadata(schema: DomainSchema): Readonly<Record<string, ActionSingleParamObjectValueMetadata>>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BaseComposableLaws, ComposableManifesto, EffectHandler, ManifestoDomainShape } from "../types.js";
|
|
2
|
+
import type { DomainSchema } from "@manifesto-ai/core";
|
|
3
|
+
export declare function createManifesto<T extends ManifestoDomainShape>(schemaInput: DomainSchema | string, effects: Record<string, EffectHandler>): ComposableManifesto<T, BaseComposableLaws>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type DomainSchema } from "@manifesto-ai/core";
|
|
2
|
+
import type { EffectHandler } from "../types.js";
|
|
3
|
+
import { type SnapshotProjectionPlan } from "../projection/snapshot-projection.js";
|
|
4
|
+
import type { InternalHostBundle } from "./shared.js";
|
|
5
|
+
export declare function createInternalHost(schema: DomainSchema, projectionPlan: SnapshotProjectionPlan, effects: Record<string, EffectHandler>): InternalHostBundle;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HostContextProvider, ManifestoHost } from "@manifesto-ai/host";
|
|
2
|
+
import type { DomainSchema } from "@manifesto-ai/core";
|
|
3
|
+
import { ACTION_PARAM_NAMES, ACTION_SINGLE_PARAM_OBJECT_VALUE } from "../compat/runtime-symbols.js";
|
|
4
|
+
import type { BaseComposableLaws, ManifestoDomainShape, TypedActionRef } from "../types.js";
|
|
5
|
+
import type { SnapshotProjectionPlan } from "../projection/snapshot-projection.js";
|
|
6
|
+
export declare const RESERVED_EFFECT_TYPE = "system.get";
|
|
7
|
+
export declare const RESERVED_NAMESPACE_PREFIX = "system.";
|
|
8
|
+
export declare const BASE_LAWS: BaseComposableLaws;
|
|
9
|
+
export type RuntimeActionRef = TypedActionRef<ManifestoDomainShape> & {
|
|
10
|
+
readonly [ACTION_PARAM_NAMES]: readonly string[] | null;
|
|
11
|
+
readonly [ACTION_SINGLE_PARAM_OBJECT_VALUE]?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type ActionParamMetadata = readonly string[] | null;
|
|
14
|
+
export type ActionSingleParamObjectValueMetadata = boolean;
|
|
15
|
+
export type ResolvedSchema = {
|
|
16
|
+
readonly schema: DomainSchema;
|
|
17
|
+
readonly actionParamMetadata: Readonly<Record<string, ActionParamMetadata>>;
|
|
18
|
+
readonly actionSingleParamObjectValueMetadata: Readonly<Record<string, ActionSingleParamObjectValueMetadata>>;
|
|
19
|
+
readonly projectionPlan: SnapshotProjectionPlan;
|
|
20
|
+
};
|
|
21
|
+
export type CompiledSchema = Omit<ResolvedSchema, "projectionPlan">;
|
|
22
|
+
export type InternalHostBundle = {
|
|
23
|
+
readonly host: ManifestoHost;
|
|
24
|
+
readonly contextProvider: HostContextProvider;
|
|
25
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DomainSchema } from "@manifesto-ai/core";
|
|
2
|
+
import type { ManifestoDomainShape, TypedMEL } from "../types.js";
|
|
3
|
+
import type { ActionParamMetadata, ActionSingleParamObjectValueMetadata } from "./shared.js";
|
|
4
|
+
export declare function buildTypedMel<T extends ManifestoDomainShape>(schema: DomainSchema, actionParamMetadata: Readonly<Record<string, ActionParamMetadata>>, actionSingleParamObjectValueMetadata: Readonly<Record<string, ActionSingleParamObjectValueMetadata>>): TypedMEL<T>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { SimulationSession } from "
|
|
2
|
-
import type { ActivatedInstance, BaseLaws, ManifestoDomainShape } from "
|
|
1
|
+
import type { SimulationSession } from "../extensions-types.js";
|
|
2
|
+
import type { ActivatedInstance, BaseLaws, ManifestoDomainShape } from "../types.js";
|
|
3
3
|
export declare function createSimulationSession<T extends ManifestoDomainShape, Laws extends BaseLaws>(app: ActivatedInstance<T, Laws>): SimulationSession<T>;
|
package/dist/provider.d.ts
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* App code should prefer the main sdk entry point; decorator and provider authors
|
|
4
4
|
* can rely on this subpath when composing or promoting runtime verbs.
|
|
5
5
|
*/
|
|
6
|
-
export type { ActivationState, HostDispatchOptions, RuntimeKernel, RuntimeKernelFactory, SimulateResult, } from "./internal.js";
|
|
7
|
-
export { activateComposable, assertComposableNotActivated, attachExtensionKernel, attachRuntimeKernelFactory, createRuntimeKernel, getActivationState, getRuntimeKernelFactory, } from "./internal.js";
|
|
6
|
+
export type { ActivationState, GovernanceRuntimeKernel, GovernanceRuntimeKernelFactory, HostDispatchOptions, LineageRuntimeKernel, LineageRuntimeKernelFactory, RuntimeKernel, RuntimeKernelFactory, SimulateResult, WaitForProposalRuntimeKernel, } from "./compat/internal.js";
|
|
7
|
+
export { activateComposable, assertComposableNotActivated, attachExtensionKernel, attachRuntimeKernelFactory, createRuntimeKernel, getActivationState, getRuntimeKernelFactory, } from "./compat/internal.js";
|
package/dist/provider.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{k as e,l as t,m as n,n as a,p as r,q as o,r as i}from"./chunk-5BUS6Q4E.js";import"./chunk-BDIXNUQ3.js";export{i as activateComposable,o as assertComposableNotActivated,a as attachExtensionKernel,t as attachRuntimeKernelFactory,e as createRuntimeKernel,r as getActivationState,n as getRuntimeKernelFactory};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type DomainSchema, type Snapshot as CoreSnapshot } from "@manifesto-ai/core";
|
|
2
|
+
import type { CanonicalSnapshot, ManifestoDomainShape, ManifestoEventMap, Snapshot, TypedIntent } from "../types.js";
|
|
3
|
+
import type { RuntimeAdmission, RuntimeSimulateSync } from "./facets.js";
|
|
4
|
+
type RuntimeAdmissionOptions<T extends ManifestoDomainShape> = {
|
|
5
|
+
readonly schema: DomainSchema;
|
|
6
|
+
readonly ensureIntentId: (intent: TypedIntent<T>) => TypedIntent<T>;
|
|
7
|
+
readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
|
|
8
|
+
readonly isActionAvailableFor: (snapshot: CanonicalSnapshot<T["state"]>, name: keyof T["actions"]) => boolean;
|
|
9
|
+
readonly isIntentDispatchableFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => boolean;
|
|
10
|
+
readonly projectSnapshotFromCanonical: (snapshot: CoreSnapshot) => Snapshot<T["state"]>;
|
|
11
|
+
readonly getSimulateSync: () => RuntimeSimulateSync<T>;
|
|
12
|
+
readonly emitEvent: <K extends keyof ManifestoEventMap<T>>(event: K, payload: ManifestoEventMap<T>[K]) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function createRuntimeAdmission<T extends ManifestoDomainShape>({ schema, ensureIntentId, getAvailableActionsFor, isActionAvailableFor, isIntentDispatchableFor, projectSnapshotFromCanonical, getSimulateSync, emitEvent, }: RuntimeAdmissionOptions<T>): RuntimeAdmission<T>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { DispatchReport, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, IntentAdmission, ManifestoDomainShape, Snapshot, TypedIntent } from "../types.js";
|
|
2
|
+
import type { ExtensionKernel } from "../extensions-types.js";
|
|
3
|
+
import type { RuntimeKernel } from "../compat/internal.js";
|
|
4
|
+
import { ManifestoError } from "../errors.js";
|
|
5
|
+
import { emitDispatchRejectedEvent } from "./events.js";
|
|
6
|
+
import type { RuntimePublicationHelpers } from "./facets.js";
|
|
7
|
+
type RejectedAttempt<T extends ManifestoDomainShape> = {
|
|
8
|
+
readonly kind: "rejected";
|
|
9
|
+
readonly intent: TypedIntent<T>;
|
|
10
|
+
readonly admission: Extract<IntentAdmission<T>, {
|
|
11
|
+
readonly kind: "blocked";
|
|
12
|
+
}>;
|
|
13
|
+
readonly beforeSnapshot: Snapshot<T["state"]>;
|
|
14
|
+
readonly beforeCanonicalSnapshot: ReturnType<RuntimeKernel<T>["getCanonicalSnapshot"]>;
|
|
15
|
+
readonly rejection: ReturnType<typeof emitDispatchRejectedEvent<T>>;
|
|
16
|
+
readonly rejectionError: ManifestoError;
|
|
17
|
+
};
|
|
18
|
+
type FailedAttempt<T extends ManifestoDomainShape> = {
|
|
19
|
+
readonly kind: "failed";
|
|
20
|
+
readonly intent: TypedIntent<T>;
|
|
21
|
+
readonly admission: Extract<IntentAdmission<T>, {
|
|
22
|
+
readonly kind: "admitted";
|
|
23
|
+
}>;
|
|
24
|
+
readonly beforeSnapshot: Snapshot<T["state"]>;
|
|
25
|
+
readonly beforeCanonicalSnapshot: ReturnType<RuntimeKernel<T>["getCanonicalSnapshot"]>;
|
|
26
|
+
readonly failure: Error;
|
|
27
|
+
readonly errorInfo: ExecutionFailureInfo;
|
|
28
|
+
readonly published: boolean;
|
|
29
|
+
readonly diagnostics?: ExecutionDiagnostics;
|
|
30
|
+
readonly outcome?: ExecutionOutcome<T>;
|
|
31
|
+
};
|
|
32
|
+
type CompletedAttempt<T extends ManifestoDomainShape> = {
|
|
33
|
+
readonly kind: "completed";
|
|
34
|
+
readonly intent: TypedIntent<T>;
|
|
35
|
+
readonly admission: Extract<IntentAdmission<T>, {
|
|
36
|
+
readonly kind: "admitted";
|
|
37
|
+
}>;
|
|
38
|
+
readonly publishedSnapshot: Snapshot<T["state"]>;
|
|
39
|
+
readonly outcome: ExecutionOutcome<T>;
|
|
40
|
+
readonly diagnostics: ExecutionDiagnostics;
|
|
41
|
+
};
|
|
42
|
+
export type BaseDispatchAttemptResult<T extends ManifestoDomainShape = ManifestoDomainShape> = RejectedAttempt<T> | FailedAttempt<T> | CompletedAttempt<T>;
|
|
43
|
+
export declare function runBaseDispatchAttempt<T extends ManifestoDomainShape>(kernel: RuntimeKernel<T>, extensionKernel: Pick<ExtensionKernel<T>, "projectSnapshot">, publication: Pick<RuntimePublicationHelpers<T>, "publishCompletedHostResult" | "publishFailedHostResult">, intent: TypedIntent<T>): Promise<BaseDispatchAttemptResult<T>>;
|
|
44
|
+
export declare function attemptToDispatchAsyncResult<T extends ManifestoDomainShape>(attempt: BaseDispatchAttemptResult<T>): Snapshot<T["state"]>;
|
|
45
|
+
export declare function attemptToDispatchReport<T extends ManifestoDomainShape>(attempt: BaseDispatchAttemptResult<T>): DispatchReport<T>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ManifestoBaseInstance, ManifestoDomainShape } from "../types.js";
|
|
2
|
+
import { type RuntimeKernel } from "../compat/internal.js";
|
|
3
|
+
export declare function createBaseRuntimeInstance<T extends ManifestoDomainShape>(kernel: RuntimeKernel<T>): ManifestoBaseInstance<T>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ManifestoDomainShape, type ManifestoEventMap, type Snapshot, type TypedIntent } from "../types.js";
|
|
2
|
+
import { ManifestoError } from "../errors.js";
|
|
3
|
+
type RuntimeEmitEvent<T extends ManifestoDomainShape> = <K extends keyof ManifestoEventMap<T>>(event: K, payload: ManifestoEventMap<T>[K]) => void;
|
|
4
|
+
export declare function emitDispatchRejectedEvent<T extends ManifestoDomainShape>(emitEvent: RuntimeEmitEvent<T>, intent: TypedIntent<T>, error: ManifestoError): ManifestoEventMap<T>["dispatch:rejected"];
|
|
5
|
+
export declare function emitDispatchFailedEvent<T extends ManifestoDomainShape>(emitEvent: RuntimeEmitEvent<T>, intent: TypedIntent<T>, error: Error, snapshot?: Snapshot<T["state"]>): void;
|
|
6
|
+
export declare function emitDispatchCompletedEvent<T extends ManifestoDomainShape>(emitEvent: RuntimeEmitEvent<T>, intent: TypedIntent<T>, snapshot: Snapshot<T["state"]>): void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ComputeStatus, Patch, Requirement, Snapshot as CoreSnapshot, SystemDelta } from "@manifesto-ai/core";
|
|
2
|
+
import type { HostResult } from "@manifesto-ai/host";
|
|
3
|
+
import type { DispatchBlocker, CanonicalSnapshot, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, IntentAdmission, IntentExplanation, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, Snapshot, TypedIntent, TypedOn, TypedSubscribe } from "../types.js";
|
|
4
|
+
import type { ManifestoError } from "../errors.js";
|
|
5
|
+
export interface RuntimeStateStore<T extends ManifestoDomainShape> {
|
|
6
|
+
readonly subscribe: TypedSubscribe<T>;
|
|
7
|
+
readonly on: TypedOn<T>;
|
|
8
|
+
readonly getSnapshot: () => Snapshot<T["state"]>;
|
|
9
|
+
readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
|
|
10
|
+
readonly getVisibleCoreSnapshot: () => CoreSnapshot;
|
|
11
|
+
readonly setVisibleSnapshot: (snapshot: CoreSnapshot, options?: {
|
|
12
|
+
readonly notify?: boolean;
|
|
13
|
+
}) => Snapshot<T["state"]>;
|
|
14
|
+
readonly restoreVisibleSnapshot: () => void;
|
|
15
|
+
readonly emitEvent: <K extends ManifestoEvent>(event: K, payload: ManifestoEventMap<T>[K]) => void;
|
|
16
|
+
readonly enqueue: <R>(task: () => Promise<R>) => Promise<R>;
|
|
17
|
+
readonly dispose: () => void;
|
|
18
|
+
readonly isDisposed: () => boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface RuntimeReportHelpers<T extends ManifestoDomainShape> {
|
|
21
|
+
readonly deriveExecutionOutcome: (beforeSnapshot: CanonicalSnapshot<T["state"]>, afterSnapshot: CanonicalSnapshot<T["state"]>) => ExecutionOutcome<T>;
|
|
22
|
+
readonly classifyExecutionFailure: (error: unknown, stage: "host" | "seal") => ExecutionFailureInfo;
|
|
23
|
+
readonly createExecutionDiagnostics: (result: HostResult) => ExecutionDiagnostics;
|
|
24
|
+
}
|
|
25
|
+
export type IntentLegalityEvaluation<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
26
|
+
readonly kind: "unavailable";
|
|
27
|
+
readonly intent: TypedIntent<T>;
|
|
28
|
+
readonly actionName: keyof T["actions"] & string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: "invalid-input";
|
|
31
|
+
readonly intent: TypedIntent<T>;
|
|
32
|
+
readonly actionName: keyof T["actions"] & string;
|
|
33
|
+
readonly error: ManifestoError;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "not-dispatchable";
|
|
36
|
+
readonly intent: TypedIntent<T>;
|
|
37
|
+
readonly actionName: keyof T["actions"] & string;
|
|
38
|
+
readonly blockers: readonly DispatchBlocker[];
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "admitted";
|
|
41
|
+
readonly intent: TypedIntent<T>;
|
|
42
|
+
readonly actionName: keyof T["actions"] & string;
|
|
43
|
+
};
|
|
44
|
+
export type RuntimeSimulationResult<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
45
|
+
readonly snapshot: CanonicalSnapshot<T["state"]>;
|
|
46
|
+
readonly patches: readonly Patch[];
|
|
47
|
+
readonly systemDelta: Readonly<SystemDelta>;
|
|
48
|
+
readonly status: ComputeStatus;
|
|
49
|
+
readonly requirements: readonly Requirement[];
|
|
50
|
+
};
|
|
51
|
+
export type RuntimeSimulateSync<T extends ManifestoDomainShape = ManifestoDomainShape> = (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => RuntimeSimulationResult<T>;
|
|
52
|
+
export interface RuntimeAdmission<T extends ManifestoDomainShape> {
|
|
53
|
+
readonly getIntentBlockersFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => readonly DispatchBlocker[];
|
|
54
|
+
readonly validateIntentInputFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => ManifestoError | null;
|
|
55
|
+
readonly evaluateIntentLegalityFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => IntentLegalityEvaluation<T>;
|
|
56
|
+
readonly deriveIntentAdmission: (snapshot: CanonicalSnapshot<T["state"]>, legality: IntentLegalityEvaluation<T>) => IntentAdmission<T>;
|
|
57
|
+
readonly explainIntentFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => IntentExplanation<T>;
|
|
58
|
+
readonly createUnavailableError: (intent: TypedIntent<T>) => ManifestoError;
|
|
59
|
+
readonly createNotDispatchableError: (intent: TypedIntent<T>) => ManifestoError;
|
|
60
|
+
readonly rejectInvalidInput: (intent: TypedIntent<T>, message: string) => never;
|
|
61
|
+
readonly rejectUnavailable: (intent: TypedIntent<T>) => never;
|
|
62
|
+
readonly rejectNotDispatchable: (intent: TypedIntent<T>) => never;
|
|
63
|
+
}
|
|
64
|
+
export type PublishedRuntimeSnapshot<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
65
|
+
readonly publishedSnapshot: Snapshot<T["state"]>;
|
|
66
|
+
readonly publishedCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
|
|
67
|
+
};
|
|
68
|
+
export interface RuntimePublicationHelpers<T extends ManifestoDomainShape> {
|
|
69
|
+
readonly replaceVisibleSnapshot: RuntimeStateStore<T>["setVisibleSnapshot"];
|
|
70
|
+
readonly restoreVisibleSnapshot: RuntimeStateStore<T>["restoreVisibleSnapshot"];
|
|
71
|
+
readonly publishCompletedHostResult: (intent: TypedIntent<T>, snapshot: CoreSnapshot) => PublishedRuntimeSnapshot<T>;
|
|
72
|
+
readonly publishFailedHostResult: (intent: TypedIntent<T>, error: Error, snapshot: CoreSnapshot) => PublishedRuntimeSnapshot<T>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ManifestoDomainShape } from "../types.js";
|
|
2
|
+
import type { RuntimeKernel, RuntimeKernelOptions } from "../compat/internal.js";
|
|
3
|
+
export declare function createRuntimeKernel<T extends ManifestoDomainShape>({ schema, projectionPlan, host, hostContextProvider, MEL, createIntent, }: RuntimeKernelOptions<T>): RuntimeKernel<T>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Snapshot as CoreSnapshot } from "@manifesto-ai/core";
|
|
2
|
+
import type { CanonicalSnapshot, ManifestoDomainShape, ManifestoEventMap, Snapshot } from "../types.js";
|
|
3
|
+
import type { RuntimePublicationHelpers } from "./facets.js";
|
|
4
|
+
type RuntimePublicationOptions<T extends ManifestoDomainShape> = {
|
|
5
|
+
readonly setVisibleSnapshot: (snapshot: CoreSnapshot, options?: {
|
|
6
|
+
readonly notify?: boolean;
|
|
7
|
+
}) => Snapshot<T["state"]>;
|
|
8
|
+
readonly restoreVisibleSnapshot: () => void;
|
|
9
|
+
readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
|
|
10
|
+
readonly emitEvent: <K extends keyof ManifestoEventMap<T>>(event: K, payload: ManifestoEventMap<T>[K]) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare function createRuntimePublication<T extends ManifestoDomainShape>({ setVisibleSnapshot, restoreVisibleSnapshot, getCanonicalSnapshot, emitEvent, }: RuntimePublicationOptions<T>): RuntimePublicationHelpers<T>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snapshot as CoreSnapshot } from "@manifesto-ai/core";
|
|
2
|
+
import type { CanonicalSnapshot, ManifestoDomainShape, Snapshot } from "../types.js";
|
|
3
|
+
import type { RuntimeReportHelpers } from "./facets.js";
|
|
4
|
+
type RuntimeReportHelperOptions<T extends ManifestoDomainShape> = {
|
|
5
|
+
readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
|
|
6
|
+
readonly projectSnapshotFromCanonical: (snapshot: CoreSnapshot) => Snapshot<T["state"]>;
|
|
7
|
+
};
|
|
8
|
+
export declare function createRuntimeReportHelpers<T extends ManifestoDomainShape>({ getAvailableActionsFor, projectSnapshotFromCanonical, }: RuntimeReportHelperOptions<T>): RuntimeReportHelpers<T>;
|
|
9
|
+
export declare function diffProjectedPaths<T>(left: Snapshot<T>, right: Snapshot<T>): readonly string[];
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DomainSchema, type Snapshot as CoreSnapshot } from "@manifesto-ai/core";
|
|
2
|
+
import { type HostContextProvider } from "@manifesto-ai/host";
|
|
3
|
+
import { ManifestoError } from "../errors.js";
|
|
4
|
+
import type { CanonicalSnapshot, ManifestoDomainShape, TypedIntent } from "../types.js";
|
|
5
|
+
import type { IntentLegalityEvaluation, RuntimeSimulateSync } from "./facets.js";
|
|
6
|
+
type RuntimeSimulationOptions<T extends ManifestoDomainShape> = {
|
|
7
|
+
readonly schema: DomainSchema;
|
|
8
|
+
readonly hostContextProvider: HostContextProvider;
|
|
9
|
+
readonly evaluateIntentLegalityFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => IntentLegalityEvaluation<T>;
|
|
10
|
+
};
|
|
11
|
+
export declare function createRuntimeSimulation<T extends ManifestoDomainShape>({ schema, hostContextProvider, evaluateIntentLegalityFor, }: RuntimeSimulationOptions<T>): Readonly<{
|
|
12
|
+
withHostIntentSlot: (snapshot: CoreSnapshot, intent: TypedIntent<T>, context: ReturnType<HostContextProvider["createFrozenContext"]>) => CoreSnapshot;
|
|
13
|
+
createSimulationUnavailableError: (intent: TypedIntent<T>) => ManifestoError;
|
|
14
|
+
createSimulationNotDispatchableError: (intent: TypedIntent<T>) => ManifestoError;
|
|
15
|
+
simulateSync: RuntimeSimulateSync<T>;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snapshot as CoreSnapshot } from "@manifesto-ai/core";
|
|
2
|
+
import type { ManifestoHost } from "@manifesto-ai/host";
|
|
3
|
+
import type { ManifestoDomainShape, Snapshot } from "../types.js";
|
|
4
|
+
import type { RuntimeStateStore } from "./facets.js";
|
|
5
|
+
type RuntimeStateStoreOptions<T extends ManifestoDomainShape> = {
|
|
6
|
+
readonly host: ManifestoHost;
|
|
7
|
+
readonly initialCanonicalSnapshot: CoreSnapshot;
|
|
8
|
+
readonly projectSnapshotFromCanonical: (snapshot: CoreSnapshot) => Snapshot<T["state"]>;
|
|
9
|
+
};
|
|
10
|
+
export declare function createRuntimeStateStore<T extends ManifestoDomainShape>({ host, initialCanonicalSnapshot, projectSnapshotFromCanonical, }: RuntimeStateStoreOptions<T>): RuntimeStateStore<T>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateUUID(): string;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ComputeStatus, DomainSchema, ExprNode, Intent, Patch, Requirement } from "@manifesto-ai/core";
|
|
1
|
+
import type { ComputeStatus, DomainSchema, ExprNode, Intent, Patch, Requirement, TraceGraph } from "@manifesto-ai/core";
|
|
2
2
|
import type { SchemaGraph as CompilerSchemaGraph, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind } from "@manifesto-ai/compiler";
|
|
3
|
-
import type { CanonicalPlatformNamespaces, CanonicalSnapshot, Snapshot } from "./snapshot-projection.js";
|
|
3
|
+
import type { CanonicalPlatformNamespaces, CanonicalSnapshot, Snapshot } from "./projection/snapshot-projection.js";
|
|
4
4
|
type ActionFn = {
|
|
5
5
|
bivarianceHack(...args: unknown[]): unknown;
|
|
6
6
|
}["bivarianceHack"];
|
|
@@ -84,6 +84,94 @@ export type SimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape
|
|
|
84
84
|
readonly requirements: readonly Requirement[];
|
|
85
85
|
readonly status: ComputeStatus;
|
|
86
86
|
};
|
|
87
|
+
export type InvalidInputInfo = {
|
|
88
|
+
readonly code: "INVALID_INPUT";
|
|
89
|
+
readonly message: string;
|
|
90
|
+
};
|
|
91
|
+
export type IntentAdmissionFailure = {
|
|
92
|
+
readonly kind: "unavailable";
|
|
93
|
+
readonly blockers: readonly DispatchBlocker[];
|
|
94
|
+
} | {
|
|
95
|
+
readonly kind: "invalid_input";
|
|
96
|
+
readonly error: InvalidInputInfo;
|
|
97
|
+
} | {
|
|
98
|
+
readonly kind: "not_dispatchable";
|
|
99
|
+
readonly blockers: readonly DispatchBlocker[];
|
|
100
|
+
};
|
|
101
|
+
export type IntentAdmission<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
102
|
+
readonly kind: "admitted";
|
|
103
|
+
readonly actionName: keyof T["actions"] & string;
|
|
104
|
+
} | {
|
|
105
|
+
readonly kind: "blocked";
|
|
106
|
+
readonly actionName: keyof T["actions"] & string;
|
|
107
|
+
readonly failure: IntentAdmissionFailure;
|
|
108
|
+
};
|
|
109
|
+
export type AvailableActionDelta<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
110
|
+
readonly before: readonly (keyof T["actions"])[];
|
|
111
|
+
readonly after: readonly (keyof T["actions"])[];
|
|
112
|
+
readonly unlocked: readonly (keyof T["actions"])[];
|
|
113
|
+
readonly locked: readonly (keyof T["actions"])[];
|
|
114
|
+
};
|
|
115
|
+
export type ProjectedDiff<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
116
|
+
readonly beforeSnapshot: Snapshot<T["state"]>;
|
|
117
|
+
readonly afterSnapshot: Snapshot<T["state"]>;
|
|
118
|
+
readonly changedPaths: readonly string[];
|
|
119
|
+
readonly availability: AvailableActionDelta<T>;
|
|
120
|
+
};
|
|
121
|
+
export type CanonicalOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
122
|
+
readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
|
|
123
|
+
readonly afterCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
|
|
124
|
+
readonly pendingRequirements: readonly Requirement[];
|
|
125
|
+
readonly status: CanonicalSnapshot<T["state"]>["system"]["status"];
|
|
126
|
+
};
|
|
127
|
+
export type ExecutionOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
128
|
+
readonly projected: ProjectedDiff<T>;
|
|
129
|
+
readonly canonical: CanonicalOutcome<T>;
|
|
130
|
+
};
|
|
131
|
+
export type ExecutionFailureInfo = {
|
|
132
|
+
readonly message: string;
|
|
133
|
+
readonly code?: string;
|
|
134
|
+
readonly name?: string;
|
|
135
|
+
readonly stage?: "host" | "seal";
|
|
136
|
+
};
|
|
137
|
+
export type ExecutionDiagnostics = {
|
|
138
|
+
readonly hostTraces?: readonly TraceGraph[];
|
|
139
|
+
};
|
|
140
|
+
export type DispatchReport<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
141
|
+
readonly kind: "completed";
|
|
142
|
+
readonly intent: TypedIntent<T>;
|
|
143
|
+
readonly admission: {
|
|
144
|
+
readonly kind: "admitted";
|
|
145
|
+
readonly actionName: keyof T["actions"] & string;
|
|
146
|
+
};
|
|
147
|
+
readonly outcome: ExecutionOutcome<T>;
|
|
148
|
+
readonly diagnostics?: ExecutionDiagnostics;
|
|
149
|
+
} | {
|
|
150
|
+
readonly kind: "rejected";
|
|
151
|
+
readonly intent: TypedIntent<T>;
|
|
152
|
+
readonly admission: Extract<IntentAdmission<T>, {
|
|
153
|
+
readonly kind: "blocked";
|
|
154
|
+
}>;
|
|
155
|
+
readonly beforeSnapshot: Snapshot<T["state"]>;
|
|
156
|
+
readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
|
|
157
|
+
readonly rejection: {
|
|
158
|
+
readonly code: "ACTION_UNAVAILABLE" | "INTENT_NOT_DISPATCHABLE" | "INVALID_INPUT";
|
|
159
|
+
readonly reason: string;
|
|
160
|
+
};
|
|
161
|
+
} | {
|
|
162
|
+
readonly kind: "failed";
|
|
163
|
+
readonly intent: TypedIntent<T>;
|
|
164
|
+
readonly admission: {
|
|
165
|
+
readonly kind: "admitted";
|
|
166
|
+
readonly actionName: keyof T["actions"] & string;
|
|
167
|
+
};
|
|
168
|
+
readonly beforeSnapshot: Snapshot<T["state"]>;
|
|
169
|
+
readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
|
|
170
|
+
readonly error: ExecutionFailureInfo;
|
|
171
|
+
readonly published: boolean;
|
|
172
|
+
readonly diagnostics?: ExecutionDiagnostics;
|
|
173
|
+
readonly outcome?: ExecutionOutcome<T>;
|
|
174
|
+
};
|
|
87
175
|
export type IntentExplanation<T extends ManifestoDomainShape = ManifestoDomainShape> = {
|
|
88
176
|
readonly kind: "blocked";
|
|
89
177
|
readonly actionName: keyof T["actions"] & string;
|
|
@@ -154,6 +242,7 @@ export type TypedOn<T extends ManifestoDomainShape> = <K extends ManifestoEvent>
|
|
|
154
242
|
export type ManifestoBaseInstance<T extends ManifestoDomainShape> = {
|
|
155
243
|
readonly createIntent: TypedCreateIntent<T>;
|
|
156
244
|
readonly dispatchAsync: TypedDispatchAsync<T>;
|
|
245
|
+
readonly dispatchAsyncWithReport: (intent: TypedIntent<T>) => Promise<DispatchReport<T>>;
|
|
157
246
|
readonly subscribe: TypedSubscribe<T>;
|
|
158
247
|
readonly on: TypedOn<T>;
|
|
159
248
|
readonly getSnapshot: () => Snapshot<T["state"]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manifesto-ai/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Manifesto SDK - Activation-first public API for the base runtime",
|
|
5
5
|
"author": "eggplantiny <eggplantiny@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"dist"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@manifesto-ai/
|
|
51
|
-
"@manifesto-ai/host": "2.
|
|
52
|
-
"@manifesto-ai/
|
|
50
|
+
"@manifesto-ai/compiler": "3.4.0",
|
|
51
|
+
"@manifesto-ai/host": "2.9.0",
|
|
52
|
+
"@manifesto-ai/core": "2.12.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"typescript": "^5.9.3",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"clean": "rm -rf dist",
|
|
63
63
|
"lint": "echo 'lint not configured'",
|
|
64
64
|
"test": "pnpm run test:runtime && pnpm run test:types",
|
|
65
|
-
"test:runtime": "vitest run",
|
|
66
|
-
"test:types": "tsc -p tsconfig.types.json --noEmit",
|
|
67
|
-
"test:coverage": "vitest run --coverage"
|
|
65
|
+
"test:runtime": "node ../../node_modules/vitest/vitest.mjs run",
|
|
66
|
+
"test:types": "node ../../node_modules/typescript/bin/tsc -p tsconfig.types.json --noEmit",
|
|
67
|
+
"test:coverage": "node ../../node_modules/vitest/vitest.mjs run --coverage"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/dist/chunk-A2FB6LGY.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
|
File without changes
|