@manifesto-ai/sdk 3.18.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,16 +4,16 @@
4
4
 
5
5
  `@manifesto-ai/sdk` is the default package for applications that start with `createManifesto()`.
6
6
 
7
- > **Current Contract Note:** The current SDK contract is the activation-first model documented in [docs/sdk-SPEC.md](docs/sdk-SPEC.md). It includes typed `createIntent()` object binding, intent explanation reads, `simulate()` with optional debug-grade `diagnostics.trace`, `@manifesto-ai/sdk/extensions`, and `createSimulationSession(instance)`.
7
+ > **Current Contract Note:** The current SDK contract is the activation-first v5 model documented in [docs/sdk-SPEC.md](docs/sdk-SPEC.md). It includes typed action candidates through `action.*`, projected `snapshot()` reads, `observe`, `inspect`, `@manifesto-ai/sdk/extensions`, and `createSimulationSession(app)`.
8
8
 
9
9
  ## When to Use It
10
10
 
11
11
  Use the SDK when you want:
12
12
 
13
13
  - the shortest path to a running base runtime
14
- - typed intent creation through `MEL.actions.*`
14
+ - typed action submission through `action.*`
15
15
  - optional typed effect authoring through `@manifesto-ai/sdk/effects`
16
- - `dispatchAsync`, subscriptions, legality queries, explanation reads, dry-run simulation with optional trace diagnostics, and snapshot reads in one package
16
+ - action-candidate check/preview/submit, observers, legality queries, optional trace diagnostics, and snapshot reads in one package
17
17
  - projected Snapshot reads by default, with canonical inspection available explicitly
18
18
  - safe post-activation arbitrary-snapshot tooling through `@manifesto-ai/sdk/extensions`
19
19
 
@@ -23,11 +23,10 @@ Use the SDK when you want:
23
23
  import { createManifesto } from "@manifesto-ai/sdk";
24
24
 
25
25
  const manifesto = createManifesto<CounterDomain>(counterSchema, {});
26
- const instance = manifesto.activate();
26
+ const app = manifesto.activate();
27
27
 
28
- const intent = instance.createIntent(instance.MEL.actions.increment);
29
- await instance.dispatchAsync(intent);
30
- console.log(instance.getSnapshot().data.count);
28
+ await app.action.increment.submit();
29
+ console.log(app.snapshot().state.count);
31
30
  ```
32
31
 
33
32
  Base runtime reads cover availability, dispatchability, intent explanation, dry-run simulation, optional debug-grade trace diagnostics, subscriptions, events, and both projected and canonical snapshot access.
@@ -0,0 +1 @@
1
+ import{c as W,g as G,h as X,m as J}from"./chunk-MIE55XWV.js";import{a as b,d as k,f as O}from"./chunk-TG2UPPZN.js";async function Q(e,o,s,c,l){let p=e.getCanonicalSnapshot(),f=o.projectSnapshot(p),T=e.evaluateIntentLegalityFor(p,c),E=e.deriveIntentAdmission(p,T);if(T.kind!=="admitted"){let N=E,h=ce(e,T),y={code:h.code,reason:h.message};return{kind:"rejected",intent:T.intent,admission:N,beforeSnapshot:f,beforeCanonicalSnapshot:p,rejection:y,rejectionError:h}}let g=E,A;try{A=await e.executeHost(T.intent,{context:l})}catch(N){let h=ue(N);return{kind:"failed",intent:T.intent,admission:g,beforeSnapshot:f,beforeCanonicalSnapshot:p,failure:h,errorInfo:e.classifyExecutionFailure(h,"host"),published:!1}}let x=e.createExecutionDiagnostics(A);if(A.status==="error"){let N=A.error??new b("HOST_ERROR","Host dispatch failed"),{publishedSnapshot:h,publishedCanonicalSnapshot:y}=s.publishFailedHostResult(A.snapshot);return{kind:"failed",intent:T.intent,admission:g,beforeSnapshot:f,beforeCanonicalSnapshot:p,failure:N,errorInfo:e.classifyExecutionFailure(N,"host"),published:!0,diagnostics:x,outcome:e.deriveExecutionOutcome(p,y)}}let{publishedSnapshot:w,publishedCanonicalSnapshot:z}=s.publishCompletedHostResult(A.snapshot);return{kind:"completed",intent:T.intent,admission:g,publishedSnapshot:w,outcome:e.deriveExecutionOutcome(p,z),diagnostics:x}}function ce(e,o){if(o.kind==="unavailable")return e.createUnavailableError(o.intent);if(o.kind==="invalid-input")return o.error;if(o.kind==="not-dispatchable")return e.createNotDispatchableError(o.intent);throw new b("SDK_REPORT_ERROR","Cannot derive a rejected dispatch error for an admitted intent")}function ue(e){return e instanceof Error?e:new Error(String(e))}function F(e){let o;try{o=structuredClone(e)}catch(s){throw new b("INVALID_INPUT",`Action input must be structured-cloneable: ${s instanceof Error?s.message:String(s)}`)}return Y(o)}function K(e){try{return{ok:!0,value:F(e)}}catch(o){if(o instanceof b)return{ok:!1,error:o};throw o}}function Y(e,o=new WeakSet){if(e==null||typeof e!="object")return e;let s=e;if(o.has(s)||Object.isFrozen(e))return e;o.add(s);for(let c of Reflect.ownKeys(s))Y(s[c],o);return Object.freeze(e)}function de(e,o={},s=!1){let c=D(o),l=e[W],p=X({setVisibleSnapshot:e.setVisibleSnapshot,restoreVisibleSnapshot:e.restoreVisibleSnapshot,getCanonicalSnapshot:e.getCanonicalSnapshot}),f=new Map;for(let t of e.getActionMetadata())f.set(t.name,pe(t));let T=Object.create(null);for(let t of f.keys()){let n=N(t);Object.defineProperty(T,t,{enumerable:!0,configurable:!1,writable:!1,value:n})}function E(t,n){if(e.isDisposed())return()=>{};let i;try{i=t(e.getSnapshot())}catch{i=void 0}return e.subscribe(t,r=>{let u=i;i=r,n(r,u)})}let g=Object.freeze({state:E,event(t,n){return e.isDisposed()?()=>{}:e.on(t,n)}}),A={action:Object.freeze(T),state:w(),computed:z(),observe:g,inspect:Object.freeze({graph:e.getSchemaGraph,canonicalSnapshot:e.getCanonicalSnapshot,action(t){return C(t)},availableActions(){return Object.freeze(e.getAvailableActions().map(t=>C(t)))},schemaHash(){return e.getCanonicalSnapshot().meta.schemaHash}}),snapshot:e.getSnapshot,context:H,injectContext(t){if(s){c=D({...c,context:e.captureExternalContext(t)});return}e.replaceExternalContext(t)},updateContext(t){if(!s)return e.updateExternalContext(t);let n=t(H());return c=D({...c,context:e.captureExternalContext(n)}),c.context??e.getExternalContext()},with(t){return de(e,ne(t),!0)},dispose:e.dispose};return Object.freeze(J(A,e));function x(t,n,i){return Object.freeze({name:t,ref:n,value:()=>i(e.getSnapshot()),observe:r=>E(i,r)})}function w(){let t=Object.create(null);for(let n of Object.keys(e.refs.state)){let i=e.refs.state[n];Object.defineProperty(t,n,{enumerable:!0,configurable:!1,writable:!1,value:x(n,i,r=>r.state[n])})}return Object.freeze(t)}function z(){let t=Object.create(null);for(let n of Object.keys(e.refs.computed)){let i=e.refs.computed[n];Object.defineProperty(t,n,{enumerable:!0,configurable:!1,writable:!1,value:x(n,i,r=>r.computed[n])})}return Object.freeze(t)}function N(t){return Object.freeze({info:()=>C(t),available:()=>e.isActionAvailable(t),check:(...n)=>{let i=y(t,n);return V(i)},preview:(...n)=>{let i=y(t,n);return L(i)},submit:(...n)=>{let i=y(t,n);return _(i)},bind:(...n)=>h(t,n)})}function h(t,n){let i=y(t,n),r=K([...n]),u=()=>r.ok?y(t,r.value):i;return Object.freeze({action:t,input:i.input,check:()=>V(u()),preview:()=>L(u()),submit:()=>_(u()),intent:()=>{let a=u();return a.inputError?null:a.intent}})}function y(t,n){let i=e.refs.actions[t],r=te(t,n),u=K(r);if(!u.ok)return Object.freeze({actionName:t,input:void 0,intent:null,inputError:u.error});try{let a=F(e.createIntent(i,...n)),d=e.validateIntentInputFor(e.getCanonicalSnapshot(),a);return Object.freeze({actionName:t,input:u.value,intent:a,inputError:d})}catch(a){if(!(a instanceof b))throw a;return Object.freeze({actionName:t,input:u.value,intent:null,inputError:a})}}function te(t,n){return n.length===0?void 0:e.getActionMetadata(t).publicArity>1?Object.freeze([...n]):n.length===1?n[0]:Object.freeze([...n])}function V(t){let n=e.getCanonicalSnapshot();return P(t,n).admission}function L(t){let n=e.getCanonicalSnapshot(),i=l.projectSnapshot(n),r=P(t,n);if(!r.admission.ok||r.intent===null)return Object.freeze({admitted:!1,admission:r.admission});let u=r.intent,a=e.createComputeContext(u,M()),d=e.simulateSync(n,u,{context:a}),S=l.projectSnapshot(d.snapshot);return Object.freeze({admitted:!0,status:d.status,before:i,after:S,changes:G(i,S),requirements:d.requirements,newAvailableActions:e.getAvailableActionsFor(d.snapshot).map(I=>C(I)),...me(d.diagnostics,c.diagnostics),error:d.snapshot.system.lastError})}async function _(t){if(e.isDisposed())throw new k;let n=t.intent?e.createComputeContext(t.intent,M()):null;return e.enqueue(async()=>{if(e.isDisposed())throw new k;let i=e.getCanonicalSnapshot(),r=P(t,i);if(!r.admission.ok||r.intent===null){let m=r.admission;return U(t.actionName,t.intent,m,i),Object.freeze({ok:!1,mode:"base",action:t.actionName,admission:m})}let u=r.intent;ie(t.actionName,u,r.admission,i),ae(t.actionName,u,i);let a=await Q(e,l,p,u,n??e.createComputeContext(u,M()));if(a.kind==="rejected"){let m=j(t.actionName,a.admission,a.rejection.reason);return U(t.actionName,a.intent,m,a.beforeCanonicalSnapshot),Object.freeze({ok:!1,mode:"base",action:t.actionName,admission:m})}if(a.kind==="failed"){let m=a.outcome?.canonical.afterCanonicalSnapshot??a.beforeCanonicalSnapshot,$=ee(m);if(!a.published||$||!m.system.lastError){let se=$??he(a.failure,a.intent,m);throw B(t.actionName,a.intent,se,m),new O(a.failure.message,"runtime",{cause:a.failure})}}let d=(a.kind==="completed",a.outcome);if(!d){let m=v(a.kind==="failed"?a.failure:new Error("Submission produced no terminal outcome"),a.intent,e.getCanonicalSnapshot());throw B(t.actionName,a.intent,m,e.getCanonicalSnapshot()),new O(m.message,"runtime")}let S=Te(d,a.intent,a.diagnostics),I=d.canonical.afterCanonicalSnapshot;if(d.canonical.status==="pending"){let m=v(new Error("Base submit produced a pending runtime snapshot"),a.intent,I);throw B(t.actionName,a.intent,m,I),new O(m.message,"runtime")}re(t.actionName,a.intent,S,I);let q=le(c.report,t.actionName,d,S,a.diagnostics);return Object.freeze({ok:!0,mode:"base",status:"settled",action:t.actionName,before:d.projected.beforeSnapshot,after:d.projected.afterSnapshot,outcome:S,...q!==void 0?{report:q}:{}})})}function H(){return c.context??e.getExternalContext()}function M(){return c.context??e.captureExternalContext()}function ne(t){return D({...c,...t.context!==void 0?{context:e.captureExternalContext(t.context)}:{},...t.diagnostics!==void 0?{diagnostics:t.diagnostics}:{},...t.report!==void 0?{report:t.report}:{}})}function P(t,n){if(!e.isActionAvailableFor(n,t.actionName))return{admission:Object.freeze({ok:!1,action:t.actionName,layer:"availability",code:"ACTION_UNAVAILABLE",message:`Action "${t.actionName}" is unavailable against the current visible snapshot`,blockers:oe(t,n)}),intent:null};if(t.inputError||!t.intent)return{admission:Object.freeze({ok:!1,action:t.actionName,layer:"input",code:"INVALID_INPUT",message:t.inputError?.message??"Invalid action input",blockers:Object.freeze([])}),intent:null};let i=e.evaluateIntentLegalityFor(n,t.intent);if(i.kind==="admitted")return{admission:Object.freeze({ok:!0,action:t.actionName}),intent:i.intent};let r=e.deriveIntentAdmission(n,i);return{admission:j(t.actionName,r),intent:null}}function j(t,n,i){if(n.failure.kind==="invalid_input"){let u=n.failure;return Object.freeze({ok:!1,action:t,layer:"input",code:"INVALID_INPUT",message:u.error.message,blockers:Object.freeze([])})}if(n.failure.kind==="not_dispatchable"){let u=n.failure;return Object.freeze({ok:!1,action:t,layer:"dispatchability",code:"INTENT_NOT_DISPATCHABLE",message:i??`Action "${t}" is not dispatchable against the current visible snapshot`,blockers:u.blockers.map(a=>Z(a,"INTENT_NOT_DISPATCHABLE"))})}let r=n.failure;return Object.freeze({ok:!1,action:t,layer:"availability",code:"ACTION_UNAVAILABLE",message:i??`Action "${t}" is unavailable against the current visible snapshot`,blockers:(r.blockers??[]).map(u=>Z(u,"ACTION_UNAVAILABLE"))})}function oe(t,n){if(!t.intent){let u=Object.freeze({type:String(t.actionName),intentId:`availability:${String(t.actionName)}`}),a=e.evaluateIntentLegalityFor(n,u),d=e.deriveIntentAdmission(n,a);return d.kind!=="blocked"||d.failure.kind!=="unavailable"?Object.freeze([]):j(t.actionName,d).blockers}let i=e.evaluateIntentLegalityFor(n,t.intent),r=e.deriveIntentAdmission(n,i);return r.kind!=="blocked"||r.failure.kind!=="unavailable"?Object.freeze([]):j(t.actionName,r).blockers}function C(t){let n=f.get(t);if(!n)throw new b("UNKNOWN_ACTION",`Action "${String(t)}" is not declared by this Manifesto schema`);return n}function ie(t,n,i,r){e.emitEvent("submission:admitted",{...R(t,n,r),admission:i})}function U(t,n,i,r){e.emitEvent("submission:rejected",{...R(t,n,r),admission:i})}function ae(t,n,i){e.emitEvent("submission:submitted",R(t,n,i))}function re(t,n,i,r){e.emitEvent("submission:settled",{...R(t,n,r),outcome:i})}function B(t,n,i,r){e.emitEvent("submission:failed",{...R(t,n,r),stage:"runtime",error:i})}function R(t,n,i){return{action:t,mode:"base",...n?.intentId?{intentId:n.intentId}:{},schemaHash:i.meta.schemaHash,snapshotVersion:i.meta.version}}}function me(e,o){return!e||o==="none"?{}:o==="summary"?{diagnostics:{}}:{diagnostics:{trace:e.trace}}}function le(e,o,s,c,l){if(e!=="none")return Object.freeze({mode:"base",action:String(o),changes:s.projected.changedPaths,requirements:s.canonical.pendingRequirements,outcome:c,...e==="full"&&l!==void 0?{diagnostics:l}:{}})}function D(e){return Object.freeze({...e})}function pe(e){let o=e.input?.type==="object"?e.input.fields??{}:{},s=e.params.length>0?e.params:Object.keys(o),c=e.annotations,l=typeof c?.title=="string"?c.title:void 0;return Object.freeze({name:e.name,...l!==void 0?{title:l}:{},...e.description!==void 0?{description:e.description}:{},parameters:Object.freeze(s.map(p=>{let f=o[p];return Object.freeze({name:p,required:f?.required??!0,...f?.type!==void 0?{type:fe(f.type)}:{},...f?.description!==void 0?{description:f.description}:{}})})),...c!==void 0?{annotations:c}:{}})}function fe(e){return typeof e=="string"?e:typeof e=="object"&&e!==null&&"enum"in e?"enum":"unknown"}function Z(e,o){return Object.freeze({path:Object.freeze([]),code:o,message:e.description??o,detail:Object.freeze({layer:e.layer,expression:e.expression})})}function Te(e,o,s){let c=be(s);if(c!==null)return Object.freeze({kind:"stop",reason:c});let l=e.canonical.afterCanonicalSnapshot;return l.system.lastError?Object.freeze({kind:"fail",error:l.system.lastError}):e.canonical.status==="error"?Object.freeze({kind:"fail",error:v(new Error("Runtime completed with error status"),o,l)}):Object.freeze({kind:"ok"})}function be(e){let o=e?.hostTraces?.slice().reverse().find(s=>s.terminatedBy==="halt");if(!o)return null;for(let s of Object.values(o.nodes))if(s.kind==="halt"){let c=s.inputs.reason;return typeof c=="string"?c:"halted"}return"halted"}function v(e,o,s){return Object.freeze({code:e instanceof b?e.code:"SUBMISSION_FAILED",message:e.message,source:{actionId:o.intentId??"",nodePath:"runtime.submit"},timestamp:s.meta.timestamp})}function he(e,o,s){return ye(s)??v(e,o,s)}function ye(e){return e.system.lastError?e.system.lastError:ee(e)}function ee(e){let o=e.namespaces?.host;if(o&&typeof o=="object"&&!Array.isArray(o)){let s=o.lastError;if(Ae(s))return s}return null}function Ae(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;let o=e;return typeof o.code=="string"&&typeof o.message=="string"&&typeof o.timestamp=="number"&&!!o.source&&typeof o.source=="object"&&typeof o.source.actionId=="string"&&typeof o.source.nodePath=="string"}export{de as a};
@@ -0,0 +1 @@
1
+ import{a as E,e as $}from"./chunk-TG2UPPZN.js";import{evaluateComputed as st,getAvailableActions as ct,isErr as lt,isActionAvailable as pt,isIntentDispatchable as ut}from"@manifesto-ai/core";import{extractSchemaGraph as dt}from"@manifesto-ai/compiler";function St(e){return{visibleComputedKeys:Object.keys(e.computed.fields)}}function J(e,t){return{state:Be(e.state),computed:He(e.computed,t),system:{status:e.system.status,lastError:e.system.lastError},meta:{schemaHash:e.meta.schemaHash}}}function bt(e,t){return J(e,t)}function g(e){return ue(structuredClone(e))}function pe(e,t){return Ue(e,t)}function Be(e){return structuredClone(e)}function He(e,t){let n={};for(let o of t.visibleComputedKeys)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return structuredClone(n)}function Ue(e,t){return P(e,t,new WeakMap)}function P(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 o=e,r=t,y=Object.prototype.toString.call(o),i=Object.prototype.toString.call(r);if(y!==i)return!1;let a=n.get(o);if(a?.has(r))return!0;if(a||(a=new WeakSet,n.set(o,a)),a.add(r),Array.isArray(o)&&Array.isArray(r)){if(o.length!==r.length)return!1;for(let c=0;c<o.length;c+=1){let m=Object.prototype.hasOwnProperty.call(o,c),b=Object.prototype.hasOwnProperty.call(r,c);if(m!==b||m&&!P(o[c],r[c],n))return!1}return!0}if(o instanceof Date&&r instanceof Date)return o.getTime()===r.getTime();if(o instanceof RegExp&&r instanceof RegExp)return o.source===r.source&&o.flags===r.flags;if(ArrayBuffer.isView(o)&&ArrayBuffer.isView(r)){if(o.constructor!==r.constructor||o.byteLength!==r.byteLength)return!1;let c=new Uint8Array(o.buffer,o.byteOffset,o.byteLength),m=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);return c.every((b,S)=>b===m[S])}if(o instanceof ArrayBuffer&&r instanceof ArrayBuffer){if(o.byteLength!==r.byteLength)return!1;let c=new Uint8Array(o),m=new Uint8Array(r);return c.every((b,S)=>b===m[S])}if(o instanceof Map&&r instanceof Map){if(o.size!==r.size)return!1;let c=Array.from(o.entries()),m=Array.from(r.entries());return c.every(([b,S],T)=>{let A=m[T];if(!A)return!1;let[R,j]=A;return P(b,R,n)&&P(S,j,n)})}if(o instanceof Set&&r instanceof Set){if(o.size!==r.size)return!1;let c=Array.from(o.values()),m=Array.from(r.values());return c.every((b,S)=>P(b,m[S],n))}let l=ce(o),p=ce(r);if(l.length!==p.length)return!1;for(let c=0;c<l.length;c+=1){let m=l[c],b=p[c];if(m!==b)return!1;let S=o[m],T=r[b];if(!P(S,T,n))return!1}return!0}function ce(e){return Object.keys(e).filter(t=>e[t]!==void 0).sort()}function ue(e,t=new WeakSet){if(e==null||typeof e!="object")return e;if(le(e))return de(e);let n=e;if(t.has(n)||Object.isFrozen(e))return e;t.add(n);for(let o of Reflect.ownKeys(n)){let r=n[o];if(le(r)){qe(n,o,r);continue}ue(r,t)}return Object.freeze(e)}function le(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)}function de(e){return structuredClone(e)}function qe(e,t,n){let o=Object.getOwnPropertyDescriptor(e,t);!o||!("value"in o)||Object.defineProperty(e,t,{enumerable:o.enumerable??!0,configurable:!1,get(){return de(n)}})}var W=Symbol("manifesto-sdk.action-param-names"),$e=Symbol("manifesto-sdk.action-single-param-object-value"),B=Symbol("manifesto-sdk.runtime-kernel-factory"),_=Symbol("manifesto-sdk.activation-state"),M=Symbol("manifesto-sdk.extension-kernel");var Je=/^(state|computed|action):.+$/;function X(e){let t=new Set(e.nodes.map(a=>a.id)),n=new Map,o=new Map,r=(a,l,p)=>{let c=a.get(l);if(c){c.add(p);return}a.set(l,new Set([p]))};for(let a of e.edges)r(n,a.from,a.to),r(o,a.to,a.from);let y=a=>{let l=Object.freeze({nodes:Object.freeze(e.nodes.filter(p=>a.has(p.id))),edges:Object.freeze(e.edges.filter(p=>a.has(p.from)&&a.has(p.to)))});return X(l)},i=(a,l)=>{let p=We(a,t),c=[p],m=new Set([p]),b=l==="incoming"?o:n;for(;c.length>0;){let S=c.shift();if(S)for(let T of b.get(S)??[])m.has(T)||(m.add(T),c.push(T))}return y(m)};return Object.freeze({nodes:e.nodes,edges:e.edges,traceUp(a){return i(a,"incoming")},traceDown(a){return i(a,"outgoing")}})}function We(e,t){if(typeof e=="string"){if(!Je.test(e))throw new E("SCHEMA_ERROR",'SchemaGraph node id must use "state:<name>", "computed:<name>", or "action:<name>"');if(!t.has(e))throw new E("SCHEMA_ERROR",`Unknown SchemaGraph node id "${e}"`);return e}let n;switch(e.__kind){case"ActionRef":n=`action:${String(e.name)}`;break;case"FieldRef":n=`state:${e.name}`;break;case"ComputedRef":n=`computed:${e.name}`;break;default:throw new E("SCHEMA_ERROR","Unsupported SchemaGraph ref lookup target")}if(!t.has(n))throw new E("SCHEMA_ERROR",`SchemaGraph node "${n}" is not part of the projected graph`);return n}import{validateIntentInput as Qe}from"@manifesto-ai/core";function fe({getAvailableActionsFor:e,projectSnapshotFromCanonical:t}){function n(i,a){let l=e(i),p=e(a),c=Object.freeze(p.filter(b=>!l.includes(b))),m=Object.freeze(l.filter(b=>!p.includes(b)));return Object.freeze({before:l,after:p,unlocked:c,locked:m})}function o(i,a){let l=g(i),p=g(a),c=t(l),m=t(p);return Object.freeze({projected:Object.freeze({beforeSnapshot:c,afterSnapshot:m,changedPaths:K(c,m),availability:n(l,p)}),canonical:Object.freeze({beforeCanonicalSnapshot:l,afterCanonicalSnapshot:p,pendingRequirements:p.system.pendingRequirements,status:p.system.status})})}function r(i,a){let l=Ye(i),p=l;return Object.freeze({message:l.message,...typeof p.code=="string"?{code:p.code}:{},...typeof l.name=="string"?{name:l.name}:{},stage:a})}function y(i){return Object.freeze({hostTraces:g(i.traces)})}return Object.freeze({deriveExecutionOutcome:o,classifyExecutionFailure:r,createExecutionDiagnostics:y})}function K(e,t){let n=new Map,o=new WeakMap,r=(i,a)=>{let l=Xe(i);n.set(l,Object.freeze({path:Object.freeze([...i]),kind:a}))},y=(i,a,l)=>{if(Object.is(i,a))return;if(i===null||a===null){r(l,"changed");return}if(typeof i!="object"||typeof a!="object"){r(l,"changed");return}let p=i,c=a,m=o.get(p);if(m?.has(c))return;if(m?m.add(c):o.set(p,new WeakSet([c])),Array.isArray(i)||Array.isArray(a)){if(!Array.isArray(i)||!Array.isArray(a)){r(l,"changed");return}let S=Math.max(i.length,a.length);for(let T=0;T<S;T+=1){let A=Object.prototype.hasOwnProperty.call(i,T),R=Object.prototype.hasOwnProperty.call(a,T),j=[...l,T];if(A!==R){r(j,A?"unset":"set");continue}!A&&!R||y(i[T],a[T],j)}return}if(!me(i)||!me(a)){r(l,"changed");return}let b=new Set([...Object.keys(i),...Object.keys(a)]);for(let S of[...b].sort()){let T=Object.prototype.hasOwnProperty.call(i,S),A=Object.prototype.hasOwnProperty.call(a,S),R=[...l,S];if(T!==A){r(R,T?"unset":"set");continue}y(i[S],a[S],R)}};return y(e.state,t.state,["state"]),y(e.computed,t.computed,["computed"]),y(e.system,t.system,["system"]),y(e.meta,t.meta,["meta"]),Object.freeze([...n.entries()].sort(([i],[a])=>i.localeCompare(a)).map(([,i])=>i))}function me(e){return Object.prototype.toString.call(e)==="[object Object]"}function Xe(e){return e.map(t=>typeof t=="number"?`[${t}]`:t).join(".")}function Ye(e){return e instanceof Error?e:new Error(String(e))}function he({schema:e,ensureIntentId:t,getAvailableActionsFor:n,isActionAvailableFor:o,isIntentDispatchableFor:r,projectSnapshotFromCanonical:y,getSimulateSync:i}){function a(h,x,u){return Object.freeze({layer:h,expression:x,evaluatedResult:!1,...u!==void 0?{description:u}:{}})}function l(h,x){let u=x.type,d=e.actions[u];return d?o(h,u)?r(h,x)?Object.freeze([]):Object.freeze(d.dispatchable?[a("dispatchable",d.dispatchable,d.description)]:[]):Object.freeze(d.available?[a("available",d.available,d.description)]:[]):Object.freeze([])}function p(h){return new E("ACTION_UNAVAILABLE",`Action "${h.type}" is unavailable against the current visible snapshot`)}function c(h){return new E("INTENT_NOT_DISPATCHABLE",`Action "${h.type}" is available, but the bound intent is not dispatchable against the current visible snapshot`)}function m(h){return new E("INVALID_INPUT",h)}function b(h,x){let u=Qe(e,x);return u?m(u):null}function S(h,x){let u=t(x),d=u.type;if(!o(h,d))return{kind:"unavailable",intent:u,actionName:d};let C=b(h,u);if(C)return{kind:"invalid-input",intent:u,actionName:d,error:C};let I=l(h,u);return I.length>0?{kind:"not-dispatchable",intent:u,actionName:d,blockers:I}:{kind:"admitted",intent:u,actionName:d}}function T(h,x){return x.kind==="unavailable"?Object.freeze({kind:"blocked",actionName:x.actionName,failure:{kind:"unavailable",blockers:l(h,x.intent)}}):x.kind==="invalid-input"?Object.freeze({kind:"blocked",actionName:x.actionName,failure:{kind:"invalid_input",error:{code:"INVALID_INPUT",message:x.error.message}}}):x.kind==="not-dispatchable"?Object.freeze({kind:"blocked",actionName:x.actionName,failure:{kind:"not_dispatchable",blockers:x.blockers}}):Object.freeze({kind:"admitted",actionName:x.actionName})}function A(h,x){let u=S(h,x);if(u.kind==="unavailable")return Object.freeze({kind:"blocked",actionName:u.actionName,available:!1,dispatchable:!1,blockers:l(h,u.intent)});if(u.kind==="invalid-input")throw u.error;if(u.kind==="not-dispatchable")return Object.freeze({kind:"blocked",actionName:u.actionName,available:!0,dispatchable:!1,blockers:u.blockers});let d=i()(h,u.intent),C=y(h),I=y(d.snapshot);return Object.freeze({kind:"admitted",actionName:u.actionName,available:!0,dispatchable:!0,status:d.status,requirements:d.requirements,canonicalSnapshot:d.snapshot,snapshot:I,newAvailableActions:n(d.snapshot),changedPaths:K(C,I)})}function R(h,x){throw x}function j(h){return R(h,p(h))}function N(h,x){return R(h,m(x))}function F(h){return R(h,c(h))}return Object.freeze({getIntentBlockersFor:l,validateIntentInputFor:b,evaluateIntentLegalityFor:S,deriveIntentAdmission:T,explainIntentFor:A,createUnavailableError:p,createNotDispatchableError:c,rejectInvalidInput:N,rejectUnavailable:j,rejectNotDispatchable:F})}function ye({setVisibleSnapshot:e,restoreVisibleSnapshot:t,getCanonicalSnapshot:n}){function o(i,a){return e(i,a)}function r(i){let a=o(i);return Object.freeze({publishedSnapshot:a,publishedCanonicalSnapshot:n()})}function y(i){let a=o(i);return Object.freeze({publishedSnapshot:a,publishedCanonicalSnapshot:n()})}return Object.freeze({replaceVisibleSnapshot:o,restoreVisibleSnapshot:t,publishCompletedHostResult:r,publishFailedHostResult:y})}import{apply as Ze,applyNamespaceDeltas as Te,applySystemDelta as et,computeSync as tt}from"@manifesto-ai/core";import{getHostState as nt}from"@manifesto-ai/host";function Se(e,t){return{...e,timestamp:t,children:e.children.map(n=>Se(n,t))}}function ot(e){let t={};function n(o){t[o.id]=o,o.children.forEach(n)}return n(e),t}function at(e,t){let n=Se(e.root,t);return{...e,duration:0,root:n,nodes:ot(n)}}function be({schema:e,hostContextProvider:t,evaluateIntentLegalityFor:n}){function o(a,l){let c=nt(a)?.intentSlots??{},m=l.input===void 0?{type:l.type}:{type:l.type,input:l.input};return Te(a,[{namespace:"host",patches:[{op:"set",path:[{kind:"prop",name:"intentSlots"}],value:{...c,[l.intentId]:m}}]}])}function r(a){return new E("ACTION_UNAVAILABLE",`Action "${a.type}" is unavailable against the provided canonical snapshot`)}function y(a){return new E("INTENT_NOT_DISPATCHABLE",`Action "${a.type}" is available, but the bound intent is not dispatchable against the provided canonical snapshot`)}return Object.freeze({withHostIntentSlot:o,createSimulationUnavailableError:r,createSimulationNotDispatchableError:y,simulateSync:(a,l,p)=>{let c=n(a,l);if(c.kind==="unavailable")throw r(c.intent);if(c.kind==="invalid-input")throw c.error;if(c.kind==="not-dispatchable")throw y(c.intent);let m=c.intent,b=p?.context??t.createFrozenContext(m.intentId,p?.externalContext),S=o(structuredClone(a),m),T=tt(e,S,m,b),A=Ze(e,S,T.patches),R=Te(A,T.namespaceDelta??[]),j=et(R,T.systemDelta);return Object.freeze({snapshot:g(j),patches:g(T.patches),systemDelta:g(T.systemDelta),status:T.status,requirements:g(T.systemDelta.addRequirements??[]),diagnostics:Object.freeze({trace:g(at(T.trace,a.meta.timestamp))})})}})}function xe({host:e,initialCanonicalSnapshot:t,projectSnapshotFromCanonical:n}){let o=structuredClone(t),r=n(o),y=g(o),i=Promise.resolve(),a=!1,l=new Set,p=new Map;function c(u,d){if(a)return()=>{};let C,I=!1;try{C=u(r),I=!0}catch{C=void 0,I=!1}let v={selector:u,listener:d,lastValue:C,initialized:I};return l.add(v),()=>{l.delete(v)}}function m(u,d){if(a)return()=>{};let C=p.get(u);return C||(C=new Set,p.set(u,C)),C.add(d),()=>{C?.delete(d)}}function b(){return r}function S(){return y}function T(){return structuredClone(o)}function A(u,d){o=structuredClone(u),e.reset(structuredClone(o)),y=g(o);let C=n(o),I=!pe(C,r);return I&&(r=C),d?.notify!==!1&&I&&x(r),r}function R(){e.reset(structuredClone(o))}function j(u,d){let C=p.get(u);if(C)for(let I of C)try{I(d)}catch{}}function N(u){let d=i.catch(()=>{}).then(u);return i=d.then(()=>{},()=>{}),d}function F(){a||(a=!0,l.clear(),p.clear())}function h(){return a}function x(u){for(let d of l){let C;try{C=d.selector(u)}catch{continue}if(!(d.initialized&&Object.is(d.lastValue,C))){d.lastValue=C,d.initialized=!0;try{d.listener(C)}catch{}}}}return{subscribe:c,on:m,getSnapshot:b,getCanonicalSnapshot:S,getVisibleCoreSnapshot:T,setVisibleSnapshot:A,restoreVisibleSnapshot:R,emitEvent:j,enqueue:N,dispose:F,isDisposed:h}}function Ce(){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)})}import{validateExternalContext as rt}from"@manifesto-ai/core";function G(e,t,n){let o=it(t===void 0?{}:t,n),r=rt(e,o);if(!r.valid){let y=r.errors.map(i=>i.path?`${i.path}: ${i.message}`:i.message).join("; ");throw new E("INVALID_CONTEXT",`Invalid context for ${n}: ${y}`)}return o}function Y(e,t,n,o){return n===void 0?t:G(e,n,o)}function it(e,t){return Ie(e)||D(t,[],"Context must be a plain JSON object"),Object.freeze(Re(e,t,[],new WeakSet))}function Ee(e,t,n,o){if(e===null)return null;switch(typeof e){case"string":case"boolean":return e;case"number":if(Number.isFinite(e))return e;D(t,n,"Context numbers must be finite");case"undefined":D(t,n,"Context must not contain undefined");case"function":D(t,n,"Context must not contain functions");case"symbol":D(t,n,"Context must not contain symbols");case"bigint":D(t,n,"Context must not contain bigint values");case"object":break}if(Array.isArray(e)){o.has(e)&&D(t,n,"Context must not contain cycles"),o.add(e),Ae(e,t,n),ge(e,t,n);let y=[];for(let i=0;i<e.length;i+=1)Object.prototype.hasOwnProperty.call(e,i)||D(t,[...n,i],"Context arrays must not contain holes"),y.push(Ee(e[i],t,[...n,i],o));return o.delete(e),Object.freeze(y)}Ie(e)||D(t,n,"Context objects must be plain JSON objects"),o.has(e)&&D(t,n,"Context must not contain cycles"),o.add(e);let r=Re(e,t,n,o);return o.delete(e),Object.freeze(r)}function Re(e,t,n,o){Ae(e,t,n),ge(e,t,n);let r=Object.create(null);for(let[y,i]of Object.entries(e))r[y]=Ee(i,t,[...n,y],o);return r}function Ie(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Ae(e,t,n){for(let[o,r]of Object.entries(Object.getOwnPropertyDescriptors(e)))(r.get||r.set)&&D(t,[...n,o],"Context must not contain getters or setters")}function ge(e,t,n){Object.getOwnPropertySymbols(e).length>0&&D(t,n,"Context must not contain symbol keys")}function D(e,t,n){let o=t.length===0?"$context":`$context.${t.map(String).join(".")}`;throw new E("INVALID_CONTEXT",`Invalid context for ${e} at ${o}: ${n}`)}var mt=new Set(["then","constructor","prototype","__proto__"]);function ft(e){if(e.params)return e.params;let t=e.input;return!t||t.type!=="object"||!t.fields?[]:Object.keys(t.fields)}function ht(e){return typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function"}function yt({schema:e,projectionPlan:t,actionAnnotations:n,host:o,hostContextProvider:r,MEL:y,createIntent:i,initialContext:a}){let l=y,p=o.getSnapshot();if(!p)throw new E("SCHEMA_ERROR","Host failed to initialize its genesis snapshot");function c(s){return g(J(s,t))}function m(s){let f=st(e,s);if(lt(f))throw new E("SNAPSHOT_REHYDRATION_FAILED",`Failed to rehydrate restored snapshot computed values: ${f.error.message}`,{cause:f.error});return{...s,computed:f.value}}let b=xe({host:o,initialCanonicalSnapshot:p,projectSnapshotFromCanonical:c}),{subscribe:S,on:T,getSnapshot:A,getCanonicalSnapshot:R,getVisibleCoreSnapshot:j,setVisibleSnapshot:N,restoreVisibleSnapshot:F,emitEvent:h,enqueue:x,dispose:u,isDisposed:d}=b,C=X(dt(e)),I=Object.keys(e.actions);Tt(I);let v=G(e,a,"createManifesto"),Q=Object.freeze(Object.fromEntries(I.map(s=>{let f=e.actions[s],L=l.actions[s]?.[W],ie=Object.freeze(Array.isArray(L)?[...L]:ft(f)),se=L===null?1:ie.length,Ve=f.input?.required===!1?0:se;return[s,Object.freeze({name:s,params:ie,publicArity:se,requiredArity:Ve,input:f.input,...f.inputType!==void 0?{inputType:f.inputType}:{},description:f.description,...n[s]!==void 0?{annotations:n[s]}:{},hasDispatchableGate:f.dispatchable!==void 0})]}))),De=Object.freeze(I.map(s=>Q[s]));function w(s){return Object.freeze([...ct(e,s)])}let H=fe({getAvailableActionsFor:w,projectSnapshotFromCanonical:c});function Oe(){return w(R())}let ke=(s=>s!==void 0?Q[String(s)]:De);function z(s,f){return pt(e,s,String(f))}function Me(s){return z(R(),s)}function V(s,f){return ut(e,s,f)}let we=((s,...f)=>V(R(),i(s,...f)));function Z(s){return s.intentId&&s.intentId.length>0?s:{...s,intentId:Ce()}}async function Pe(s,f){return o.dispatch(s,f)}function Ne(){return v}function Fe(s){return v=G(e,s,"injectContext"),v}function Le(s){let f=s(v);if(ht(f))throw new E("INVALID_CONTEXT","updateContext() updater must return a synchronous JSON context value");return v=G(e,f,"updateContext"),v}function ee(s){return Y(e,v,s,"transition")}function te(s,f){let k=f===void 0?v:Y(e,v,f,"transition");return r.createFrozenContext(s.intentId,k)}let U=null,O=he({schema:e,ensureIntentId:Z,getAvailableActionsFor:w,isActionAvailableFor:z,isIntentDispatchableFor:V,projectSnapshotFromCanonical:c,getSimulateSync:()=>{if(!U)throw new E("SCHEMA_ERROR","Runtime simulation surface is not initialized");return U}}),ne=be({schema:e,hostContextProvider:r,evaluateIntentLegalityFor:O.evaluateIntentLegalityFor});U=ne.simulateSync;let oe=ye({setVisibleSnapshot:N,restoreVisibleSnapshot:F,getCanonicalSnapshot:R}),ae=O.getIntentBlockersFor,_e=((s,...f)=>ae(R(),i(s,...f))),q=(s,f,k)=>{let L=k?.context??te(f,k?.externalContext??ee());return ne.simulateSync(s,f,{context:L})};function Ke(s){let f=c(s.snapshot);return Object.freeze({snapshot:f,changedPaths:K(A(),f),newAvailableActions:w(s.snapshot),requirements:s.requirements,status:s.status,diagnostics:s.diagnostics})}let re=(s=>Ke(q(R(),s))),Ge=((s,...f)=>re(i(s,...f))),ze=Object.freeze({refs:l,MEL:y,schema:e,createIntent:i,getCanonicalSnapshot:R,projectSnapshot:s=>c(s),simulateSync:(s,f)=>{let k=q(s,f);return Object.freeze({snapshot:k.snapshot,patches:k.patches,requirements:k.requirements,status:k.status,diagnostics:k.diagnostics})},getAvailableActionsFor:w,isActionAvailableFor:z,isIntentDispatchableFor:V,explainIntentFor:O.explainIntentFor});return{schema:e,refs:l,MEL:y,createIntent:i,subscribe:S,on:T,getSnapshot:A,getAvailableActionsFor:w,getAvailableActions:Oe,getIntentBlockersFor:ae,getActionMetadata:ke,isActionAvailableFor:z,isActionAvailable:Me,isIntentDispatchableFor:V,isIntentDispatchable:we,getIntentBlockers:_e,getSchemaGraph(){return C},simulateSync:q,simulate:Ge,simulateIntent:re,dispose:u,isDisposed:d,getCanonicalSnapshot:R,getVisibleCoreSnapshot:j,rehydrateSnapshot:m,setVisibleSnapshot:oe.replaceVisibleSnapshot,restoreVisibleSnapshot:oe.restoreVisibleSnapshot,emitEvent:h,enqueue:x,ensureIntentId:Z,executeHost:Pe,createComputeContext:te,getExternalContext:Ne,replaceExternalContext:Fe,updateExternalContext:Le,captureExternalContext:ee,validateIntentInputFor:O.validateIntentInputFor,evaluateIntentLegalityFor:O.evaluateIntentLegalityFor,deriveIntentAdmission:O.deriveIntentAdmission,deriveExecutionOutcome:H.deriveExecutionOutcome,classifyExecutionFailure:H.classifyExecutionFailure,createExecutionDiagnostics:H.createExecutionDiagnostics,createUnavailableError:O.createUnavailableError,createNotDispatchableError:O.createNotDispatchableError,rejectInvalidInput:O.rejectInvalidInput,rejectUnavailable:O.rejectUnavailable,rejectNotDispatchable:O.rejectNotDispatchable,[M]:ze}}function Tt(e){let t=e.filter(n=>mt.has(n));if(t.length!==0)throw new E("RESERVED_ACTION_NAME",`Action name${t.length===1?"":"s"} ${t.map(n=>`"${n}"`).join(", ")} ${t.length===1?"is":"are"} reserved by the SDK public action namespace`)}function cn(e,t,n){Object.defineProperty(e,B,{enumerable:!1,configurable:!1,writable:!1,value:t});let o=n??je(e)??{activated:!1};return je(e)||Object.defineProperty(e,_,{enumerable:!1,configurable:!1,writable:!1,value:o}),e}function ln(e){let n=e[B];if(typeof n!="function")throw new E("SCHEMA_ERROR","ComposableManifesto is missing its runtime kernel factory");return n}function pn(e,t){return Object.defineProperty(e,M,{enumerable:!1,configurable:!1,writable:!1,value:t[M]}),e}function un(e){let n=e[M];if(!n)throw new E("SCHEMA_ERROR","Activated runtime is missing its extension kernel");return n}function ve(e){let n=e[_];if(!n)throw new E("SCHEMA_ERROR","ComposableManifesto is missing its activation state");return n}function dn(e){if(ve(e).activated)throw new $}function mn(e){let t=ve(e);if(t.activated)throw new $;t.activated=!0}function je(e){return e[_]??null}export{W as a,$e as b,M as c,St as d,bt as e,g as f,K as g,ye as h,Ce as i,yt as j,cn as k,ln as l,pn as m,un as n,ve as o,dn as p,mn as q};
@@ -0,0 +1 @@
1
+ var n=class extends Error{code;constructor(e,t,s){super(t,s),this.name="ManifestoError",this.code=e}},o=class extends n{effectType;constructor(e){super("RESERVED_EFFECT",`Effect type "${e}" is reserved and cannot be overridden`),this.name="ReservedEffectError",this.effectType=e}},a=class extends n{diagnostics;constructor(e,t){super("COMPILE_ERROR",t),this.name="CompileError",this.diagnostics=e}},i=class extends n{constructor(){super("DISPOSED","Cannot use a disposed Manifesto runtime"),this.name="DisposedError"}},l=class extends n{constructor(){super("ALREADY_ACTIVATED","ComposableManifesto.activate() may only be called once"),this.name="AlreadyActivatedError"}},d=class extends n{stage;constructor(e,t="runtime",s){super("SUBMISSION_FAILED",e,s),this.name="SubmissionFailedError",this.stage=t}};export{n as a,o as b,a as c,i as d,l as e,d as f};
@@ -1,7 +1,7 @@
1
- import { type ComputeStatus, type DomainSchema, type Patch, type Requirement, type Snapshot as CoreSnapshot, type SystemDelta } from "@manifesto-ai/core";
1
+ import { type ComputeStatus, type Context, type DomainSchema, type JsonValue, type Patch, type Requirement, type Snapshot as CoreSnapshot, type SystemDelta } from "@manifesto-ai/core";
2
2
  import type { HostContextProvider, HostResult, ManifestoHost } from "@manifesto-ai/host";
3
3
  import { ManifestoError } from "../errors.js";
4
- import type { BaseLaws, CanonicalSnapshot, ComposableManifesto, DispatchBlocker, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, IntentAdmission, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, SchemaGraph, SimulationDiagnostics, Snapshot, TypedCreateIntent, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIntent, TypedIsIntentDispatchable, TypedMEL, TypedOn, TypedSimulate, TypedSimulateIntent, TypedSubscribe } from "../types.js";
4
+ import type { ActionAnnotation, BaseLaws, CanonicalSnapshot, ComposableManifesto, ContextUpdater, DispatchExecutionOutcome, DispatchBlocker, DomainExternalContext, ExternalContext, ExecutionDiagnostics, ExecutionFailureInfo, IntentAdmission, ManifestoDomainShape, ManifestoEvent, ManifestoEventPayloadMap, ProjectedSnapshot, SchemaGraph, SimulationDiagnostics, TypedCreateIntent, TypedDomainRefs, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIntent, TypedIsIntentDispatchable, TypedMEL, TypedOn, TypedSimulate, TypedSimulateIntent, TypedSubscribe } from "../types.js";
5
5
  import type { SnapshotProjectionPlan } from "../projection/snapshot-projection.js";
6
6
  import type { ExtensionKernel } from "../extensions-types.js";
7
7
  import type { IntentLegalityEvaluation } from "../runtime/facets.js";
@@ -18,11 +18,13 @@ export type SimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape
18
18
  };
19
19
  export interface RuntimeKernel<T extends ManifestoDomainShape> {
20
20
  readonly schema: DomainSchema;
21
+ readonly refs: TypedDomainRefs<T>;
22
+ /** @deprecated Use refs. */
21
23
  readonly MEL: TypedMEL<T>;
22
24
  readonly createIntent: TypedCreateIntent<T>;
23
25
  readonly subscribe: TypedSubscribe<T>;
24
26
  readonly on: TypedOn<T>;
25
- readonly getSnapshot: () => Snapshot<T["state"]>;
27
+ readonly getSnapshot: () => ProjectedSnapshot<T>;
26
28
  readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
27
29
  readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
28
30
  readonly getAvailableActions: () => readonly (keyof T["actions"])[];
@@ -34,7 +36,10 @@ export interface RuntimeKernel<T extends ManifestoDomainShape> {
34
36
  readonly isIntentDispatchable: TypedIsIntentDispatchable<T>;
35
37
  readonly getIntentBlockers: TypedGetIntentBlockers<T>;
36
38
  readonly getSchemaGraph: () => SchemaGraph;
37
- readonly simulateSync: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => SimulateResult<T>;
39
+ readonly simulateSync: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>, options?: {
40
+ readonly externalContext?: DomainExternalContext<T>;
41
+ readonly context?: Context;
42
+ }) => SimulateResult<T>;
38
43
  readonly simulate: TypedSimulate<T>;
39
44
  readonly simulateIntent: TypedSimulateIntent<T>;
40
45
  readonly dispose: () => void;
@@ -42,16 +47,22 @@ export interface RuntimeKernel<T extends ManifestoDomainShape> {
42
47
  readonly getVisibleCoreSnapshot: () => CoreSnapshot;
43
48
  readonly setVisibleSnapshot: (snapshot: CoreSnapshot, options?: {
44
49
  readonly notify?: boolean;
45
- }) => Snapshot<T["state"]>;
50
+ }) => ProjectedSnapshot<T>;
51
+ readonly rehydrateSnapshot: (snapshot: CoreSnapshot) => CoreSnapshot;
46
52
  readonly restoreVisibleSnapshot: () => void;
47
- readonly emitEvent: <K extends ManifestoEvent>(event: K, payload: ManifestoEventMap<T>[K]) => void;
53
+ readonly emitEvent: <K extends ManifestoEvent>(event: K, payload: ManifestoEventPayloadMap[K]) => void;
48
54
  readonly enqueue: <R>(task: () => Promise<R>) => Promise<R>;
49
55
  readonly ensureIntentId: (intent: TypedIntent<T>) => TypedIntent<T>;
50
56
  readonly executeHost: (intent: TypedIntent<T>, options?: HostDispatchOptions) => Promise<HostResult>;
57
+ readonly createComputeContext: (intent: TypedIntent<T>, externalContext?: ExternalContext) => Context;
58
+ readonly getExternalContext: () => DomainExternalContext<T>;
59
+ readonly replaceExternalContext: (next: DomainExternalContext<T>) => DomainExternalContext<T>;
60
+ readonly updateExternalContext: (updater: ContextUpdater<DomainExternalContext<T>>) => DomainExternalContext<T>;
61
+ readonly captureExternalContext: (override?: ExternalContext) => DomainExternalContext<T>;
51
62
  readonly validateIntentInputFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => ManifestoError | null;
52
63
  readonly evaluateIntentLegalityFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => IntentLegalityEvaluation<T>;
53
64
  readonly deriveIntentAdmission: (snapshot: CanonicalSnapshot<T["state"]>, legality: IntentLegalityEvaluation<T>) => IntentAdmission<T>;
54
- readonly deriveExecutionOutcome: (beforeSnapshot: CanonicalSnapshot<T["state"]>, afterSnapshot: CanonicalSnapshot<T["state"]>) => ExecutionOutcome<T>;
65
+ readonly deriveExecutionOutcome: (beforeSnapshot: CanonicalSnapshot<T["state"]>, afterSnapshot: CanonicalSnapshot<T["state"]>) => DispatchExecutionOutcome<T>;
55
66
  readonly classifyExecutionFailure: (error: unknown, stage: "host" | "seal") => ExecutionFailureInfo;
56
67
  readonly createExecutionDiagnostics: (result: HostResult) => ExecutionDiagnostics;
57
68
  readonly createUnavailableError: (intent: TypedIntent<T>) => ManifestoError;
@@ -61,18 +72,18 @@ export interface RuntimeKernel<T extends ManifestoDomainShape> {
61
72
  readonly rejectNotDispatchable: (intent: TypedIntent<T>) => never;
62
73
  readonly [EXTENSION_KERNEL]: ExtensionKernel<T>;
63
74
  }
64
- type RuntimePublicReadFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "schema" | "MEL" | "createIntent" | "subscribe" | "on" | "getSnapshot" | "getCanonicalSnapshot" | "getAvailableActions" | "isIntentDispatchable" | "getIntentBlockers" | "getActionMetadata" | "isActionAvailable" | "getSchemaGraph" | "simulate" | "simulateIntent">;
75
+ type RuntimePublicReadFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "schema" | "MEL" | "createIntent" | "subscribe" | "on" | "getSnapshot" | "getCanonicalSnapshot" | "getAvailableActionsFor" | "getAvailableActions" | "isIntentDispatchable" | "getIntentBlockers" | "getActionMetadata" | "isActionAvailable" | "getSchemaGraph" | "simulateSync" | "simulate" | "simulateIntent" | "getExternalContext" | "replaceExternalContext" | "updateExternalContext" | "captureExternalContext">;
65
76
  type RuntimeLifecycleFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "dispose" | "isDisposed" | "enqueue">;
66
- type RuntimeExecutionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "ensureIntentId" | "executeHost">;
67
- type RuntimeSealAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isActionAvailable" | "validateIntentInputFor" | "isIntentDispatchableFor" | "rejectUnavailable" | "rejectInvalidInput" | "rejectNotDispatchable">;
77
+ type RuntimeExecutionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "ensureIntentId" | "executeHost" | "createComputeContext" | "captureExternalContext">;
78
+ type RuntimeSealAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isActionAvailable" | "isActionAvailableFor" | "validateIntentInputFor" | "isIntentDispatchableFor" | "rejectUnavailable" | "rejectInvalidInput" | "rejectNotDispatchable">;
68
79
  type RuntimeReportAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "evaluateIntentLegalityFor" | "deriveIntentAdmission" | "createUnavailableError" | "createNotDispatchableError">;
69
- type RuntimePublicationFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "getVisibleCoreSnapshot" | "setVisibleSnapshot" | "restoreVisibleSnapshot">;
80
+ type RuntimePublicationFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "getVisibleCoreSnapshot" | "setVisibleSnapshot" | "rehydrateSnapshot" | "restoreVisibleSnapshot">;
70
81
  type RuntimeReportingFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "deriveExecutionOutcome" | "classifyExecutionFailure" | "createExecutionDiagnostics">;
71
82
  type RuntimeDispatchEventsFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "emitEvent">;
72
83
  type RuntimeExtensionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, typeof EXTENSION_KERNEL>;
73
84
  export type LineageRuntimeKernel<T extends ManifestoDomainShape> = RuntimePublicReadFacet<T> & RuntimeLifecycleFacet<T> & RuntimeExecutionFacet<T> & RuntimeSealAdmissionFacet<T> & RuntimeReportAdmissionFacet<T> & RuntimePublicationFacet<T> & RuntimeReportingFacet<T> & RuntimeDispatchEventsFacet<T> & RuntimeExtensionFacet<T>;
74
85
  export type LineageRuntimeKernelFactory<T extends ManifestoDomainShape> = () => LineageRuntimeKernel<T>;
75
- export type GovernanceRuntimeKernel<T extends ManifestoDomainShape> = RuntimePublicReadFacet<T> & RuntimeLifecycleFacet<T> & RuntimeExecutionFacet<T> & RuntimeSealAdmissionFacet<T> & RuntimePublicationFacet<T> & Pick<RuntimeKernel<T>, "deriveExecutionOutcome"> & RuntimeDispatchEventsFacet<T> & RuntimeExtensionFacet<T>;
86
+ export type GovernanceRuntimeKernel<T extends ManifestoDomainShape> = RuntimePublicReadFacet<T> & RuntimeLifecycleFacet<T> & RuntimeExecutionFacet<T> & RuntimeSealAdmissionFacet<T> & RuntimeReportAdmissionFacet<T> & RuntimePublicationFacet<T> & Pick<RuntimeKernel<T>, "deriveExecutionOutcome"> & RuntimeDispatchEventsFacet<T> & RuntimeExtensionFacet<T>;
76
87
  export type GovernanceRuntimeKernelFactory<T extends ManifestoDomainShape> = () => GovernanceRuntimeKernel<T>;
77
88
  export type WaitForProposalRuntimeKernel<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isDisposed" | "deriveExecutionOutcome">;
78
89
  export type RuntimeKernelFactory<T extends ManifestoDomainShape> = () => RuntimeKernel<T>;
@@ -83,10 +94,12 @@ export type InternalComposableManifesto<T extends ManifestoDomainShape, Laws ext
83
94
  export type RuntimeKernelOptions<T extends ManifestoDomainShape> = {
84
95
  readonly schema: DomainSchema;
85
96
  readonly projectionPlan: SnapshotProjectionPlan;
97
+ readonly actionAnnotations: Readonly<Record<string, ActionAnnotation>>;
86
98
  readonly host: ManifestoHost;
87
99
  readonly hostContextProvider: HostContextProvider;
88
100
  readonly MEL: TypedMEL<T>;
89
101
  readonly createIntent: TypedCreateIntent<T>;
102
+ readonly initialContext?: Record<string, JsonValue>;
90
103
  };
91
104
  export declare function attachRuntimeKernelFactory<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>, factory: RuntimeKernelFactory<T>, activationState?: ActivationState): InternalComposableManifesto<T, Laws>;
92
105
  export declare function getRuntimeKernelFactory<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): RuntimeKernelFactory<T>;
package/dist/effects.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Patch } from "@manifesto-ai/core";
2
- import type { EffectHandler, FieldRef, ManifestoDomainShape, TypedMEL } from "./types.js";
2
+ import type { EffectHandler, FieldRef, ManifestoDomainShape, TypedDomainRefs } from "./types.js";
3
3
  type MergeableObject<TValue> = TValue extends readonly unknown[] ? never : TValue extends object ? TValue : never;
4
4
  type RefValue<TRef extends FieldRef<unknown>> = TRef extends FieldRef<infer TValue> ? TValue : never;
5
5
  type MergeValue<TRef extends FieldRef<unknown>> = Partial<MergeableObject<RefValue<TRef>>>;
@@ -8,6 +8,6 @@ export type PatchBuilder = {
8
8
  unset<TRef extends FieldRef<unknown>>(ref: TRef): Patch;
9
9
  merge<TRef extends FieldRef<unknown>>(ref: TRef, value: MergeValue<TRef>): Patch;
10
10
  };
11
- type DefineEffectsFactory<T extends ManifestoDomainShape> = (ops: PatchBuilder, MEL: TypedMEL<T>) => Record<string, EffectHandler>;
11
+ type DefineEffectsFactory<T extends ManifestoDomainShape> = (ops: PatchBuilder, refs: TypedDomainRefs<T>) => Record<string, EffectHandler>;
12
12
  export declare function defineEffects<T extends ManifestoDomainShape>(factory: DefineEffectsFactory<T>): Record<string, EffectHandler>;
13
13
  export {};
package/dist/effects.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-BDIXNUQ3.js";import{mergePatch as u,propSegment as l,setPatch as T,unsetPatch as h}from"@manifesto-ai/core";function p(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function r(e,n){if(!n||typeof n!="object")throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() expects a FieldRef from defineEffects(..., MEL.state.*)`);let t=n;if(t.__kind!=="FieldRef"||typeof t.name!="string"||t.name.length===0)throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() expects a FieldRef from defineEffects(..., MEL.state.*)`);if(t.name.startsWith("$"))throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() does not allow reserved platform namespaces such as "${t.name}"`)}function m(e){if(!p(e))throw new a("SCHEMA_ERROR","PatchBuilder.merge() expects a plain object value")}function i(e){let n=new Map,t=Object.freeze(Object.create(null));return new Proxy(t,{get(R,f,d){if(typeof f!="string")return Reflect.get(R,f,d);let o=n.get(f);if(o)return o;let c=Object.freeze({__kind:e,name:f});return n.set(f,c),c}})}function s(e){return[l(e.name)]}var w=Object.freeze({set(e,n){return r("set",e),T(s(e),n)},unset(e){return r("unset",e),h(s(e))},merge(e,n){return r("merge",e),m(n),u(s(e),n)}}),g=Object.freeze({actions:i("ActionRef"),state:i("FieldRef"),computed:i("ComputedRef")});function E(e){return e(w,g)}export{E as defineEffects};
1
+ import{a}from"./chunk-TG2UPPZN.js";import{mergePatch as u,propSegment as l,setPatch as T,unsetPatch as h}from"@manifesto-ai/core";function m(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function r(e,n){if(!n||typeof n!="object")throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() expects a FieldRef from defineEffects(..., refs.state.*)`);let t=n;if(t.__kind!=="FieldRef"||typeof t.name!="string"||t.name.length===0)throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() expects a FieldRef from defineEffects(..., refs.state.*)`);if(t.name.startsWith("$"))throw new a("SCHEMA_ERROR",`PatchBuilder.${e}() does not allow reserved platform namespaces such as "${t.name}"`)}function p(e){if(!m(e))throw new a("SCHEMA_ERROR","PatchBuilder.merge() expects a plain object value")}function s(e){let n=new Map,t=Object.freeze(Object.create(null));return new Proxy(t,{get(c,f,d){if(typeof f!="string")return Reflect.get(c,f,d);let o=n.get(f);if(o)return o;let R=Object.freeze({__kind:e,name:f});return n.set(f,R),R}})}function i(e){return[l(e.name)]}var w=Object.freeze({set(e,n){return r("set",e),T(i(e),n)},unset(e){return r("unset",e),h(i(e))},merge(e,n){return r("merge",e),p(n),u(i(e),n)}}),g=Object.freeze({actions:s("ActionRef"),state:s("FieldRef"),computed:s("ComputedRef")});function y(e){return e(w,g)}export{y as defineEffects};
package/dist/errors.d.ts CHANGED
@@ -35,3 +35,7 @@ export declare class DisposedError extends ManifestoError {
35
35
  export declare class AlreadyActivatedError extends ManifestoError {
36
36
  constructor();
37
37
  }
38
+ export declare class SubmissionFailedError extends ManifestoError {
39
+ readonly stage: "runtime" | "settlement";
40
+ constructor(message: string, stage?: "runtime" | "settlement", options?: ErrorOptions);
41
+ }
@@ -1,5 +1,5 @@
1
1
  import type { ComputeStatus, DomainSchema, Patch, Requirement } from "@manifesto-ai/core";
2
- import type { CanonicalSnapshot, CreateIntentArgs, IntentExplanation, ManifestoDomainShape, SimulationDiagnostics, Snapshot, TypedActionRef, TypedCreateIntent, TypedIntent, TypedMEL } from "./types.js";
2
+ import type { CanonicalSnapshot, CreateIntentArgs, IntentExplanation, ManifestoDomainShape, ProjectedSnapshot, SimulationDiagnostics, TypedActionRef, TypedCreateIntent, TypedIntent, TypedDomainRefs, TypedMEL } from "./types.js";
3
3
  export type ExtensionSimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape> = {
4
4
  readonly snapshot: CanonicalSnapshot<T["state"]>;
5
5
  readonly patches: readonly Patch[];
@@ -8,11 +8,13 @@ export type ExtensionSimulateResult<T extends ManifestoDomainShape = ManifestoDo
8
8
  readonly diagnostics?: SimulationDiagnostics;
9
9
  };
10
10
  export interface ExtensionKernel<T extends ManifestoDomainShape> {
11
+ readonly refs: TypedDomainRefs<T>;
12
+ /** @deprecated Use refs. */
11
13
  readonly MEL: TypedMEL<T>;
12
14
  readonly schema: DomainSchema;
13
15
  readonly createIntent: TypedCreateIntent<T>;
14
16
  readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
15
- readonly projectSnapshot: (snapshot: CanonicalSnapshot<T["state"]>) => Snapshot<T["state"]>;
17
+ readonly projectSnapshot: (snapshot: CanonicalSnapshot<T["state"]>) => ProjectedSnapshot<T>;
16
18
  readonly simulateSync: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => ExtensionSimulateResult<T>;
17
19
  readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
18
20
  readonly isActionAvailableFor: (snapshot: CanonicalSnapshot<T["state"]>, actionName: keyof T["actions"]) => boolean;
@@ -23,7 +25,7 @@ export type SimulationSessionStatus = ComputeStatus | "idle" | "computing";
23
25
  export type SimulationActionRef<T extends ManifestoDomainShape = ManifestoDomainShape> = TypedActionRef<T, keyof T["actions"]>;
24
26
  export type SimulationSessionStep<T extends ManifestoDomainShape = ManifestoDomainShape> = {
25
27
  readonly intent: TypedIntent<T>;
26
- readonly snapshot: Snapshot<T["state"]>;
28
+ readonly snapshot: ProjectedSnapshot<T>;
27
29
  readonly canonicalSnapshot: CanonicalSnapshot<T["state"]>;
28
30
  readonly availableActions: readonly SimulationActionRef<T>[];
29
31
  readonly requirements: readonly Requirement[];
@@ -31,7 +33,7 @@ export type SimulationSessionStep<T extends ManifestoDomainShape = ManifestoDoma
31
33
  readonly isTerminal: boolean;
32
34
  };
33
35
  export type SimulationSessionResult<T extends ManifestoDomainShape = ManifestoDomainShape> = {
34
- readonly snapshot: Snapshot<T["state"]>;
36
+ readonly snapshot: ProjectedSnapshot<T>;
35
37
  readonly canonicalSnapshot: CanonicalSnapshot<T["state"]>;
36
38
  readonly depth: number;
37
39
  readonly trajectory: readonly SimulationSessionStep<T>[];
@@ -41,7 +43,7 @@ export type SimulationSessionResult<T extends ManifestoDomainShape = ManifestoDo
41
43
  readonly isTerminal: boolean;
42
44
  };
43
45
  export interface SimulationSession<T extends ManifestoDomainShape> {
44
- readonly snapshot: Snapshot<T["state"]>;
46
+ readonly snapshot: ProjectedSnapshot<T>;
45
47
  readonly canonicalSnapshot: CanonicalSnapshot<T["state"]>;
46
48
  readonly depth: number;
47
49
  readonly trajectory: readonly SimulationSessionStep<T>[];
@@ -1 +1 @@
1
- import{f as m,o as c}from"./chunk-BSGOCNTO.js";import{a as S}from"./chunk-BDIXNUQ3.js";function p(n){return n==="pending"||n==="halted"||n==="error"}function d(n){return n.__kind==="ActionRef"}function l(n){return Object.freeze([...n])}function u(n,e,t){return Object.freeze(t?[]:n.getAvailableActionsFor(e).map(i=>n.MEL.actions[i]))}function y(n,e,t,i,s){let a=p(s);return Object.freeze({intent:m(n),snapshot:e.projectSnapshot(t),canonicalSnapshot:t,availableActions:u(e,t,a),requirements:l(i),status:s,isTerminal:a})}function T(n,e){return Object.freeze({snapshot:e.snapshot,canonicalSnapshot:e.canonicalSnapshot,depth:e.depth,trajectory:e.trajectory,availableActions:e.availableActions,requirements:e.requirements,status:e.status,isTerminal:e.isTerminal,finish(){return e},next(i,...s){if(e.isTerminal)throw new S("SIMULATION_SESSION_TERMINAL","SimulationSession.next() cannot advance a terminal session");let a=d(i)?n.createIntent(i,...s):i,r=n.simulateSync(e.canonicalSnapshot,a),o=y(a,n,r.snapshot,r.requirements,r.status),f=Object.freeze({snapshot:o.snapshot,canonicalSnapshot:r.snapshot,depth:e.depth+1,trajectory:l([...e.trajectory,o]),availableActions:o.availableActions,requirements:o.requirements,status:o.status,isTerminal:o.isTerminal});return T(n,f)}})}function h(n){let e=c(n),t=e.getCanonicalSnapshot(),i=t.system.status,s=p(i);return T(e,Object.freeze({snapshot:e.projectSnapshot(t),canonicalSnapshot:t,depth:0,trajectory:Object.freeze([]),availableActions:u(e,t,s),requirements:l(t.system.pendingRequirements),status:i,isTerminal:s}))}function v(n){return c(n)}export{h as createSimulationSession,v as getExtensionKernel};
1
+ import{f as m,n as c}from"./chunk-MIE55XWV.js";import{a as S}from"./chunk-TG2UPPZN.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.refs.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,8 +9,8 @@
9
9
  */
10
10
  export type { SdkManifest } from "./manifest.js";
11
11
  export { createManifesto } from "./create-manifesto.js";
12
- export type { ActivatedInstance, ActionArgs, CreateIntentArgs, DispatchReport, ActionObjectBindingArgs, DispatchBlocker, AvailableActionDelta, TypedActionMetadata, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIsIntentDispatchable, BaseLaws, BaseComposableLaws, CanonicalPlatformNamespaces, CanonicalSnapshot, ComposableManifesto, ComputedRef, EffectContext, EffectHandler, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, FieldRef, GovernedComposableLaws, GovernanceLaws, IntentAdmission, IntentAdmissionFailure, IntentExplanation, InvalidInputInfo, LineageComposableLaws, LineageLaws, ManifestoBaseInstance, ManifestoDispatchRuntime, ManifestoDecoratedRuntimeByLaws, ManifestoDomainShape, ManifestoEvent, ManifestoEventMap, ManifestoEventPayload, ManifestoLegalityRuntime, ManifestoRuntimeByLaws, Selector, SimulationDiagnostics, SimulateResult, ProjectedDiff, CanonicalOutcome, SchemaGraph, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, SchemaGraphNodeRef, Snapshot, TypedActionRef, TypedCommitAsync, TypedCreateIntent, TypedDispatchAsync, TypedIntent, TypedMEL, TypedOn, TypedSimulate, TypedSimulateIntent, TypedSubscribe, Unsubscribe, } from "./types.js";
13
- export { AlreadyActivatedError, CompileError, DisposedError, ManifestoError, ReservedEffectError, } from "./errors.js";
12
+ export type { ActivatedInstance, ActionAnnotation, ActionArgs, ActionHandle, ActionInfo, ActionInput, ActionName, ActionParameterInfo, ActionSurface, Admission, AdmissionFailure, AdmissionOk, CreateIntentArgs, CreateManifestoOptions, ContextUpdater, DomainExternalContext, BaseManifestoApp, BaseSubmissionResult, DispatchReport, DispatchExecutionOutcome, DispatchProjectedDiff, DispatchCanonicalOutcome, ActionObjectBindingArgs, Blocker, BoundAction, DispatchBlocker, AvailableActionDelta, TypedActionMetadata, TypedGetActionMetadata, TypedGetIntentBlockers, TypedIsIntentDispatchable, BaseLaws, BaseComposableLaws, BaseWriteReport, CanonicalNamespaces, CanonicalSnapshot, ComposableManifesto, ComputedReadSurface, ComputedRef, ChangedPath, EffectContext, EffectHandler, ExecutionDiagnostics, ExecutionFailureInfo, ExecutionOutcome, ExecutionView, ExternalContext, FieldRef, GovernedComposableLaws, GovernanceLaws, GovernanceSettlementResult, GovernanceSettlementSurface, GovernanceSubmissionResult, IntentAdmission, IntentAdmissionFailure, IntentExplanation, InvalidInputInfo, JsonValue, LineageComposableLaws, LineageLaws, LineageSubmissionResult, LineageWriteReport, ManifestoApp, ManifestoDecoratedRuntimeByLaws, ManifestoDomainShape, ManifestoEvent, ManifestoEventName, ManifestoEventPayload, ManifestoEventPayloadMap, ManifestoRuntimeByLaws, ObserveSurface, Selector, SimulationDiagnostics, SimulateResult, ProjectedDiff, ProjectedSnapshot, ProposalRef, PreviewDiagnosticsMode, PreviewResult, PathSegment, CanonicalOutcome, ProjectedReadHandle, RuntimeMode, SchemaGraph, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, SchemaGraphNodeRef, Snapshot, StateReadSurface, SubmissionResult, SubmitReportMode, SubmitResultFor, TypedActionRef, TypedCreateIntent, TypedDomainRefs, TypedIntent, TypedMEL, TypedOn, TypedSubscribe, Unsubscribe, WorldRecord, } from "./types.js";
13
+ export { AlreadyActivatedError, CompileError, DisposedError, ManifestoError, ReservedEffectError, SubmissionFailedError, } 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";
16
16
  export { createSnapshot } from "@manifesto-ai/core";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import{a as v}from"./chunk-JM42OG2H.js";import{a as d,b as h,d as w,e as x,f as I,j as y,k as E,l as k,r as _}from"./chunk-BSGOCNTO.js";import{a as l,b,c as g,d as B,e as F}from"./chunk-BDIXNUQ3.js";import{createHostContextProvider as J,createHost as Y,defaultRuntime as X}from"@manifesto-ai/host";import{extractDefaults as Q}from"@manifesto-ai/core";import{semanticPathToPatchPath as K}from"@manifesto-ai/core";function U(e){return typeof e=="object"&&e!==null&&"key"in e&&"into"in e}function N(e,t){if(U(e))return{patches:[{op:"set",path:L(e.into),value:q(e.key)}]};let{path:n,target:a}=e,r=W(n,t);return a?{patches:[{op:"set",path:L(a),value:r.value}]}:{patches:[]}}function q(e){switch(e){case"uuid":return y();case"timestamp":case"time.now":return Date.now();case"isoTimestamp":return new Date().toISOString();default:return null}}function L(e){let t=H(e),n=t.startsWith("data.")?t.slice(5):t;return K(n)}function H(e){return e.startsWith("/")?e.slice(1).replace(/\//g,"."):e}function W(e,t){let a=H(e).split(".");if(a.length===0)return{value:void 0,found:!1};let[r,...i]=a,o;switch(r){case"data":o=t.data;break;case"computed":o=t.computed;break;case"system":o=t.system;break;case"meta":o=t.meta;break;default:o=t.data,i.unshift(r);break}for(let s of i){if(o==null||typeof o!="object")return{value:void 0,found:!1};o=o[s]}return{value:o,found:o!==void 0}}var u="system.get",j="system.",$=Object.freeze({__baseLaws:!0});function P(e,t,n){let a=X,r=Y(e,{initialData:Q(e.state),runtime:a}),i=J(a);r.registerEffect(u,async(o,s,m)=>{let{patches:c}=N(s,m.snapshot);return c});for(let[o,s]of Object.entries(n)){let m=async(c,f,p)=>await s(f,{snapshot:I(x(p.snapshot,t))});r.registerEffect(o,m)}return{host:r,contextProvider:i}}import{createIntent as Z}from"@manifesto-ai/core";function M(){return(e,...t)=>{let n=e,a=y(),r=ee(n,t);return Z(String(e.name),r,a)}}function ee(e,t){let n=Object.hasOwn(e,d)?e[d]:[];if(t.length!==0){if(n===null){if(t.length===1&&S(t[0]))return t[0];throw new l("INVALID_INTENT_ARGS",`Action "${String(e.name)}" requires a single object argument because positional parameter metadata is unavailable`)}if(n.length===0){if(t.length===1)return t[0];throw new l("INVALID_INTENT_ARGS",`Action "${String(e.name)}" does not accept multiple positional arguments`)}return n.length===1&&t.length===1&&S(t[0])&&e[h]?{[n[0]??"arg0"]:t[0]}:n.length===1&&t.length===1&&te(t[0],n[0])||t.length===1&&S(t[0])&&n.length>1?t[0]:Object.fromEntries(t.map((a,r)=>[n[r]??`arg${r}`,a]))}}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function te(e,t){if(!t||!S(e))return!1;let n=Object.keys(e);return n.length===1&&n[0]===t}import{hashSchemaSync as ce}from"@manifesto-ai/core";import{compileMelDomain as ne,parse as ae,tokenize as oe}from"@manifesto-ai/compiler";function V(e){let t=ne(e,{mode:"domain"});if(t.errors.length>0){let a=t.errors.map(r=>{let i=r.location;if(!i||i.start.line===0&&i.start.column===0)return`[${r.code}] ${r.message}`;let o=`[${r.code}] ${r.message} (${i.start.line}:${i.start.column})`,s=e.split(`
2
- `)[i.start.line-1];if(!s)return o;let m=String(i.start.line).padStart(4," "),c=Math.max(1,i.end.line===i.start.line?Math.min(i.end.column-i.start.column,Math.max(1,s.length-i.start.column+1)):1),f=" ".repeat(m.length+3+i.start.column-1);return`${o}
3
- ${m} | ${s}
4
- ${f}${"^".repeat(c)}`}).join(`
1
+ import{a as k}from"./chunk-CEARNDBI.js";import{a as m,b as p,d as D,e as T,f as I,i as v,j as A,k as w,q as _}from"./chunk-MIE55XWV.js";import{a as c,b as h,c as y,d as G,e as F,f as K}from"./chunk-TG2UPPZN.js";import{createHostContextProvider as W,createHost as U,defaultRuntime as J}from"@manifesto-ai/host";import{createSnapshot as X,evaluateComputed as Y,extractDefaults as q,isOk as Q}from"@manifesto-ai/core";function S(e,t,n){let o=J,a=W(o),r=X(q(e.state),e.hash,a.createInitialContext()),i=Y(e,r),s=U(e,{initialSnapshot:Q(i)?{...r,computed:i.value}:r,runtime:o});for(let[l,d]of Object.entries(n)){let u=async(pe,$,z)=>await d($,{snapshot:I(T(z.snapshot,t))});s.registerEffect(l,u)}return{host:s,contextProvider:a}}import{createIntent as Z}from"@manifesto-ai/core";function b(){return(e,...t)=>{let n=e,o=v(),a=ee(n,t);return Z(String(e.name),a,o)}}function ee(e,t){let n=Object.hasOwn(e,m)?e[m]:[];if(t.length!==0){if(n===null){if(t.length===1&&f(t[0]))return t[0];throw new c("INVALID_INTENT_ARGS",`Action "${String(e.name)}" requires a single object argument because positional parameter metadata is unavailable`)}if(n.length===0)throw new c("INVALID_INTENT_ARGS",`Action "${String(e.name)}" does not accept input`);return n.length===1&&t.length===1&&f(t[0])&&e[p]?{[n[0]??"arg0"]:t[0]}:n.length===1&&t.length===1&&te(t[0],n[0])||t.length===1&&f(t[0])&&n.length>1?t[0]:Object.fromEntries(t.map((o,a)=>[n[a]??`arg${a}`,o]))}}function f(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function te(e,t){if(!t||!f(e))return!1;let n=Object.keys(e);return n.length===1&&n[0]===t}import{compileMelModule as ne,parse as oe,tokenize as ae}from"@manifesto-ai/compiler";function L(e){let t=ne(e,{mode:"module"});if(t.errors.length>0){let o=t.errors.map(a=>{let r=a.location;if(!r||r.start.line===0&&r.start.column===0)return`[${a.code}] ${a.message}`;let i=`[${a.code}] ${a.message} (${r.start.line}:${r.start.column})`,s=e.split(`
2
+ `)[r.start.line-1];if(!s)return i;let l=String(r.start.line).padStart(4," "),d=Math.max(1,r.end.line===r.start.line?Math.min(r.end.column-r.start.column,Math.max(1,s.length-r.start.column+1)):1),u=" ".repeat(l.length+3+r.start.column-1);return`${i}
3
+ ${l} | ${s}
4
+ ${u}${"^".repeat(d)}`}).join(`
5
5
 
6
- `);throw new g(t.errors,`MEL compilation failed:
7
- ${a}`)}if(!t.schema)throw new l("COMPILE_ERROR","MEL compilation produced no schema");let n=t.schema;return{schema:n,actionParamMetadata:O(n,se(e)),actionSingleParamObjectValueMetadata:T(n)}}function O(e,t){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([n,a])=>{let r=t?.[n];if(r&&r.length>0)return[n,Object.freeze([...r])];if(a.params&&a.params.length>0){let o=Object.freeze([...a.params]);return[n,o]}if(!a.input||a.input.type!=="object"||!a.input.fields)return[n,[]];let i=re(a.input);return[n,i.length<=1?i:null]})))}function T(e){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([t,n])=>[t,ie(e,n)])))}function re(e){return!e||e.type!=="object"||!e.fields?[]:Object.keys(e.fields)}function ie(e,t){if(t.params?.length===1&&t.inputType){let n=R(t.inputType,t.params[0]??"",e.types);return n?A(n,e.types):!1}if(t.input?.type==="object"&&t.input.fields&&Object.keys(t.input.fields).length===1){let[n]=Object.keys(t.input.fields);return(n?t.input.fields[n]:void 0)?.type==="object"}return!1}function R(e,t,n,a=[]){if(e.kind==="ref"){if(a.includes(e.name))return null;let r=n[e.name];return r?R(r.definition,t,n,[...a,e.name]):null}if(e.kind==="union"){let r=e.types.filter(i=>!C(i,n,a));return r.length===1?R(r[0],t,n,a):null}return e.kind!=="object"?null:e.fields[t]?.type??null}function A(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let a=t[e.name];return a?A(a.definition,t,[...n,e.name]):!1}if(e.kind==="union"){let a=e.types.filter(r=>!C(r,t,n));return a.length===1?A(a[0],t,n):!1}return e.kind==="object"||e.kind==="record"||e.kind==="primitive"&&e.type==="object"}function C(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let a=t[e.name];return a?C(a.definition,t,[...n,e.name]):!1}return e.kind==="primitive"&&e.type==="null"||e.kind==="literal"&&e.value===null}function se(e){let t=oe(e);if(t.diagnostics.some(a=>a.severity==="error"))return;let n=ae(t.tokens);if(n.program)return Object.freeze(Object.fromEntries(n.program.domain.members.filter(a=>a.kind==="action").map(a=>[a.name,Object.freeze(a.params.map(r=>r.name))])))}function G(e){if(typeof e!="string"&&le(e))throw new l("SCHEMA_ERROR","DomainModule is a compiler tooling artifact. Pass module.schema or MEL source to createManifesto().");let t=typeof e=="string"?V(e):{schema:e,actionParamMetadata:O(e),actionSingleParamObjectValueMetadata:T(e)},n=me(t.schema);return fe(n),{schema:n,actionParamMetadata:t.actionParamMetadata,actionSingleParamObjectValueMetadata:t.actionSingleParamObjectValueMetadata,projectionPlan:w(n)}}function le(e){return typeof e=="object"&&e!==null&&"schema"in e&&"graph"in e&&"annotations"in e}function me(e){let t={...e.state.fields},n=!1;if(!t.$host)t.$host={type:"object",required:!1,default:{}},n=!0;else{if(t.$host.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$host' must be an object field");t.$host.default===void 0&&(t.$host={...t.$host,default:{}},n=!0)}if(!t.$mel)t.$mel={type:"object",required:!1,default:{guards:{intent:{}}},fields:{guards:{type:"object",required:!1,default:{intent:{}},fields:{intent:{type:"object",required:!1,default:{}}}}}},n=!0;else{if(t.$mel.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel' must be an object field");{let o=t.$mel;o.default===void 0&&(o={...o,default:{guards:{intent:{}}}},n=!0);let s=o.fields??{},m=s.guards;if(!m)o={...o,fields:{...s,guards:{type:"object",required:!1,default:{intent:{}},fields:{intent:{type:"object",required:!1,default:{}}}}}},n=!0;else{if(m.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel.guards' must be an object field");{let c=m;c.default===void 0&&(c={...c,default:{intent:{}}},n=!0);let f=c.fields??{},p=f.intent;if(!p)c={...c,fields:{...f,intent:{type:"object",required:!1,default:{}}}},n=!0;else{if(p.type!=="object")throw new l("SCHEMA_ERROR","Reserved namespace '$mel.guards.intent' must be an object field");p.default===void 0&&(c={...c,fields:{...f,intent:{...p,default:{}}}},n=!0)}c!==m&&(o={...o,fields:{...s,guards:c}})}}o!==t.$mel&&(t.$mel=o)}}if(!n)return e;let a={...e,state:{...e.state,fields:t}},{hash:r,...i}=a;return{...a,hash:ce(i)}}function fe(e){for(let t of Object.keys(e.actions??{}))if(t.startsWith(j))throw new l("RESERVED_NAMESPACE",`Action type "${t}" uses reserved namespace prefix "${j}"`)}function D(e,t,n){let a=Object.fromEntries(Object.keys(e.actions).map(o=>{let s={__kind:"ActionRef",name:o};return Object.defineProperty(s,d,{enumerable:!1,configurable:!1,writable:!1,value:Object.hasOwn(t,o)?t[o]:[]}),Object.defineProperty(s,h,{enumerable:!1,configurable:!1,writable:!1,value:n[o]??!1}),[o,Object.freeze(s)]})),r=Object.fromEntries(Object.keys(e.state.fields).filter(o=>!o.startsWith("$")).map(o=>[o,Object.freeze({__kind:"FieldRef",name:o})])),i=Object.fromEntries(Object.keys(e.computed.fields).map(o=>[o,Object.freeze({__kind:"ComputedRef",name:o})]));return Object.freeze({actions:Object.freeze(a),state:Object.freeze(r),computed:Object.freeze(i)})}function z(e,t){if(u in t)throw new b(u);let n=G(e),a={_laws:$,schema:n.schema,activate(){_(a);let r=P(n.schema,n.projectionPlan,t);return v(E({schema:n.schema,projectionPlan:n.projectionPlan,host:r.host,hostContextProvider:r.contextProvider,MEL:D(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:M()}))}};return k(a,()=>{let r=P(n.schema,n.projectionPlan,t);return E({schema:n.schema,projectionPlan:n.projectionPlan,host:r.host,hostContextProvider:r.contextProvider,MEL:D(n.schema,n.actionParamMetadata,n.actionSingleParamObjectValueMetadata),createIntent:M()})})}import{createSnapshot as et}from"@manifesto-ai/core";export{F as AlreadyActivatedError,g as CompileError,B as DisposedError,l as ManifestoError,b as ReservedEffectError,z as createManifesto,et as createSnapshot};
6
+ `);throw new y(t.errors,`MEL compilation failed:
7
+ ${o}`)}if(!t.module)throw new c("COMPILE_ERROR","MEL compilation produced no schema");let n=t.module.schema;return{schema:n,actionParamMetadata:g(n,se(e)),actionSingleParamObjectValueMetadata:P(n),actionAnnotations:j(t.module.annotations)}}function j(e){return Object.freeze(e?Object.fromEntries(Object.entries(e.entries).filter(([t])=>t.startsWith("action:")).map(([t,n])=>[t.slice(7),Object.freeze(Object.fromEntries(n.map(a=>[a.tag,a.payload??!0])))])):{})}function g(e,t){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([n,o])=>{let a=t?.[n];if(a&&a.length>0)return[n,Object.freeze([...a])];if(o.params&&o.params.length>0){let i=Object.freeze([...o.params]);return[n,i]}if(!o.input||o.input.type!=="object"||!o.input.fields)return[n,[]];let r=re(o.input);return[n,r.length<=1?r:null]})))}function P(e){return Object.freeze(Object.fromEntries(Object.entries(e.actions).map(([t,n])=>[t,ie(e,n)])))}function re(e){return!e||e.type!=="object"||!e.fields?[]:Object.keys(e.fields)}function ie(e,t){if(t.params?.length===1&&t.inputType){let n=M(t.inputType,t.params[0]??"",e.types);return n?E(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 M(e,t,n,o=[]){if(e.kind==="ref"){if(o.includes(e.name))return null;let a=n[e.name];return a?M(a.definition,t,n,[...o,e.name]):null}if(e.kind==="union"){let a=e.types.filter(r=>!R(r,n,o));return a.length===1?M(a[0],t,n,o):null}return e.kind!=="object"?null:e.fields[t]?.type??null}function E(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let o=t[e.name];return o?E(o.definition,t,[...n,e.name]):!1}if(e.kind==="union"){let o=e.types.filter(a=>!R(a,t,n));return o.length===1?E(o[0],t,n):!1}return e.kind==="object"||e.kind==="record"||e.kind==="primitive"&&e.type==="object"}function R(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let o=t[e.name];return o?R(o.definition,t,[...n,e.name]):!1}return e.kind==="primitive"&&e.type==="null"||e.kind==="literal"&&e.value===null}function se(e){let t=ae(e);if(t.diagnostics.some(o=>o.severity==="error"))return;let n=oe(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(a=>a.name))])))}var O="system.get",C="system.",N=Object.freeze({__baseLaws:!0});function H(e,t){if(typeof e!="string"&&me(e))throw new c("SCHEMA_ERROR","DomainModule is a compiler tooling artifact. Pass module.schema or MEL source to createManifesto().");let n=typeof e=="string"?L(e):{schema:e,actionParamMetadata:g(e),actionSingleParamObjectValueMetadata:P(e),actionAnnotations:j()};return le(n.schema),{schema:n.schema,actionParamMetadata:n.actionParamMetadata,actionSingleParamObjectValueMetadata:n.actionSingleParamObjectValueMetadata,actionAnnotations:ce(n.actionAnnotations,t),projectionPlan:D(n.schema)}}function ce(e,t){if(!t)return e;let n=new Map;for(let[o,a]of Object.entries(e))n.set(o,a);for(let[o,a]of Object.entries(t))n.set(o,Object.freeze({...n.get(o)??{},...a}));return Object.freeze(Object.fromEntries(n))}function me(e){return typeof e=="object"&&e!==null&&"schema"in e&&"graph"in e&&"annotations"in e}function le(e){V(e.state.fields,"state.fields");for(let t of Object.keys(e.actions??{}))if(t.startsWith(C))throw new c("RESERVED_NAMESPACE",`Action type "${t}" uses reserved namespace prefix "${C}"`)}function V(e,t){for(let[n,o]of Object.entries(e)){let a=`${t}.${n}`;if(n.startsWith("$"))throw new c("SCHEMA_ERROR",`State field "${a}" uses reserved namespace prefix "$"`);o.type==="object"&&o.fields&&V(o.fields,a)}}function x(e,t,n){let o=Object.fromEntries(Object.keys(e.actions).map(i=>{let s={__kind:"ActionRef",name:i};return Object.defineProperty(s,m,{enumerable:!1,configurable:!1,writable:!1,value:Object.hasOwn(t,i)?t[i]:[]}),Object.defineProperty(s,p,{enumerable:!1,configurable:!1,writable:!1,value:n[i]??!1}),[i,Object.freeze(s)]})),a=Object.fromEntries(Object.keys(e.state.fields).filter(i=>!i.startsWith("$")).map(i=>[i,Object.freeze({__kind:"FieldRef",name:i})])),r=Object.fromEntries(Object.keys(e.computed.fields).map(i=>[i,Object.freeze({__kind:"ComputedRef",name:i})]));return Object.freeze({actions:Object.freeze(o),state:Object.freeze(a),computed:Object.freeze(r)})}function B(e,t,n){if(O in t)throw new h(O);let o=H(e,n?.annotations),a={_laws:N,schema:o.schema,activate(){_(a);let r=S(o.schema,o.projectionPlan,t);return k(A({schema:o.schema,projectionPlan:o.projectionPlan,host:r.host,hostContextProvider:r.contextProvider,MEL:x(o.schema,o.actionParamMetadata,o.actionSingleParamObjectValueMetadata),createIntent:b(),actionAnnotations:o.actionAnnotations,initialContext:n?.context}))}};return w(a,()=>{let r=S(o.schema,o.projectionPlan,t);return A({schema:o.schema,projectionPlan:o.projectionPlan,host:r.host,hostContextProvider:r.contextProvider,MEL:x(o.schema,o.actionParamMetadata,o.actionSingleParamObjectValueMetadata),createIntent:b(),actionAnnotations:o.actionAnnotations,initialContext:n?.context})})}import{createSnapshot as Je}from"@manifesto-ai/core";export{F as AlreadyActivatedError,y as CompileError,G as DisposedError,c as ManifestoError,h as ReservedEffectError,K as SubmissionFailedError,B as createManifesto,Je as createSnapshot};
@@ -1,5 +1,7 @@
1
+ import { type AnnotationIndex } from "@manifesto-ai/compiler";
1
2
  import { type DomainSchema } from "@manifesto-ai/core";
2
- import type { ActionParamMetadata, ActionSingleParamObjectValueMetadata, CompiledSchema } from "./shared.js";
3
+ import type { ActionParamMetadata, ActionAnnotationMap, ActionSingleParamObjectValueMetadata, CompiledSchema } from "./shared.js";
3
4
  export declare function compileSchema(source: string): CompiledSchema;
5
+ export declare function deriveActionAnnotations(annotations?: AnnotationIndex | null): ActionAnnotationMap;
4
6
  export declare function deriveActionParamMetadata(schema: DomainSchema, actionParamOrder?: Readonly<Record<string, readonly string[]>>): Readonly<Record<string, ActionParamMetadata>>;
5
7
  export declare function deriveSingleParamObjectValueMetadata(schema: DomainSchema): Readonly<Record<string, ActionSingleParamObjectValueMetadata>>;
@@ -1,3 +1,3 @@
1
- import type { BaseComposableLaws, ComposableManifesto, EffectHandler, ManifestoDomainShape } from "../types.js";
1
+ import type { BaseComposableLaws, ComposableManifesto, CreateManifestoOptions, DomainExternalContext, EffectHandler, ManifestoDomainShape } from "../types.js";
2
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>;
3
+ export declare function createManifesto<T extends ManifestoDomainShape>(schemaInput: DomainSchema | string, effects: Record<string, EffectHandler>, options?: CreateManifestoOptions<DomainExternalContext<T>>): ComposableManifesto<T, BaseComposableLaws>;
@@ -1,3 +1,3 @@
1
1
  import { type DomainSchema } from "@manifesto-ai/core";
2
- import type { ResolvedSchema } from "./shared.js";
3
- export declare function resolveSchema(schema: DomainSchema | string): ResolvedSchema;
2
+ import type { ActionAnnotationMap, ResolvedSchema } from "./shared.js";
3
+ export declare function resolveSchema(schema: DomainSchema | string, callerAnnotations?: ActionAnnotationMap): ResolvedSchema;
@@ -1,7 +1,7 @@
1
1
  import type { HostContextProvider, ManifestoHost } from "@manifesto-ai/host";
2
2
  import type { DomainSchema } from "@manifesto-ai/core";
3
3
  import { ACTION_PARAM_NAMES, ACTION_SINGLE_PARAM_OBJECT_VALUE } from "../compat/runtime-symbols.js";
4
- import type { BaseComposableLaws, ManifestoDomainShape, TypedActionRef } from "../types.js";
4
+ import type { ActionAnnotation, BaseComposableLaws, ManifestoDomainShape, TypedActionRef } from "../types.js";
5
5
  import type { SnapshotProjectionPlan } from "../projection/snapshot-projection.js";
6
6
  export declare const RESERVED_EFFECT_TYPE = "system.get";
7
7
  export declare const RESERVED_NAMESPACE_PREFIX = "system.";
@@ -12,10 +12,12 @@ export type RuntimeActionRef = TypedActionRef<ManifestoDomainShape> & {
12
12
  };
13
13
  export type ActionParamMetadata = readonly string[] | null;
14
14
  export type ActionSingleParamObjectValueMetadata = boolean;
15
+ export type ActionAnnotationMap = Readonly<Record<string, ActionAnnotation>>;
15
16
  export type ResolvedSchema = {
16
17
  readonly schema: DomainSchema;
17
18
  readonly actionParamMetadata: Readonly<Record<string, ActionParamMetadata>>;
18
19
  readonly actionSingleParamObjectValueMetadata: Readonly<Record<string, ActionSingleParamObjectValueMetadata>>;
20
+ readonly actionAnnotations: ActionAnnotationMap;
19
21
  readonly projectionPlan: SnapshotProjectionPlan;
20
22
  };
21
23
  export type CompiledSchema = Omit<ResolvedSchema, "projectionPlan">;
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export type SdkManifest = {
5
5
  readonly name: "@manifesto-ai/sdk";
6
- readonly specVersion: "3.0.0";
6
+ readonly specVersion: "5.0.0";
7
7
  readonly phase: "draft";
8
8
  };
@@ -1,23 +1,21 @@
1
1
  import { type DomainSchema, type Snapshot as CoreSnapshot } from "@manifesto-ai/core";
2
- export type CanonicalPlatformNamespaces = {
3
- $host?: Record<string, unknown>;
4
- $mel?: Record<string, unknown>;
5
- [k: `$${string}`]: unknown;
6
- };
7
- export type Snapshot<T = unknown> = {
8
- data: T;
9
- computed: Record<string, unknown>;
2
+ export type CanonicalNamespaces = CoreSnapshot["namespaces"];
3
+ export type Snapshot<TState = unknown, TComputed = Record<string, unknown>> = {
4
+ state: TState;
5
+ computed: TComputed;
10
6
  system: Pick<CoreSnapshot["system"], "status" | "lastError">;
11
7
  meta: Pick<CoreSnapshot["meta"], "schemaHash">;
12
8
  };
13
- export type CanonicalSnapshot<T = unknown> = Omit<CoreSnapshot, "data"> & {
14
- data: T & CanonicalPlatformNamespaces;
9
+ export type CanonicalSnapshot<TState = unknown, TComputed = Record<string, unknown>> = Omit<CoreSnapshot, "state" | "computed"> & {
10
+ state: TState;
11
+ computed: TComputed;
12
+ namespaces: CanonicalNamespaces;
15
13
  };
16
14
  export type SnapshotProjectionPlan = {
17
15
  visibleComputedKeys: readonly string[];
18
16
  };
19
17
  export declare function buildSnapshotProjectionPlan(schema: DomainSchema): SnapshotProjectionPlan;
20
- export declare function projectCanonicalSnapshot<T = unknown>(snapshot: CoreSnapshot, plan: SnapshotProjectionPlan): Snapshot<T>;
21
- export declare function projectEffectContextSnapshot<T = unknown>(snapshot: CoreSnapshot, plan: SnapshotProjectionPlan): Snapshot<T>;
18
+ export declare function projectCanonicalSnapshot<TState = unknown, TComputed = Record<string, unknown>>(snapshot: CoreSnapshot, plan: SnapshotProjectionPlan): Snapshot<TState, TComputed>;
19
+ export declare function projectEffectContextSnapshot<TState = unknown, TComputed = Record<string, unknown>>(snapshot: CoreSnapshot, plan: SnapshotProjectionPlan): Snapshot<TState, TComputed>;
22
20
  export declare function cloneAndDeepFreeze<T>(value: T): T;
23
- export declare function projectedSnapshotsEqual<T>(left: Snapshot<T>, right: Snapshot<T>): boolean;
21
+ export declare function projectedSnapshotsEqual<TState, TComputed = Record<string, unknown>>(left: Snapshot<TState, TComputed>, right: Snapshot<TState, TComputed>): boolean;
package/dist/provider.js CHANGED
@@ -1 +1 @@
1
- import{a as c}from"./chunk-JM42OG2H.js";import{k as e,l as t,m as n,n as a,p as r,q as o,r as i}from"./chunk-BSGOCNTO.js";import"./chunk-BDIXNUQ3.js";export{i as activateComposable,o as assertComposableNotActivated,a as attachExtensionKernel,t as attachRuntimeKernelFactory,c as createBaseRuntimeInstance,e as createRuntimeKernel,r as getActivationState,n as getRuntimeKernelFactory};
1
+ import{a as c}from"./chunk-CEARNDBI.js";import{j as e,k as t,l as n,m as a,o as r,p as o,q as i}from"./chunk-MIE55XWV.js";import"./chunk-TG2UPPZN.js";export{i as activateComposable,o as assertComposableNotActivated,a as attachExtensionKernel,t as attachRuntimeKernelFactory,c as createBaseRuntimeInstance,e as createRuntimeKernel,r as getActivationState,n as getRuntimeKernelFactory};
@@ -0,0 +1,9 @@
1
+ import { ManifestoError } from "../errors.js";
2
+ export declare function cloneAndFreezeActionPayload<T>(value: T): T;
3
+ export declare function tryCloneAndFreezeActionPayload<T>(value: T): {
4
+ readonly ok: true;
5
+ readonly value: T;
6
+ } | {
7
+ readonly ok: false;
8
+ readonly error: ManifestoError;
9
+ };
@@ -1,5 +1,5 @@
1
1
  import { type DomainSchema, type Snapshot as CoreSnapshot } from "@manifesto-ai/core";
2
- import type { CanonicalSnapshot, ManifestoDomainShape, ManifestoEventMap, Snapshot, TypedIntent } from "../types.js";
2
+ import type { CanonicalSnapshot, ManifestoDomainShape, ProjectedSnapshot, TypedIntent } from "../types.js";
3
3
  import type { RuntimeAdmission, RuntimeSimulateSync } from "./facets.js";
4
4
  type RuntimeAdmissionOptions<T extends ManifestoDomainShape> = {
5
5
  readonly schema: DomainSchema;
@@ -7,9 +7,8 @@ type RuntimeAdmissionOptions<T extends ManifestoDomainShape> = {
7
7
  readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
8
8
  readonly isActionAvailableFor: (snapshot: CanonicalSnapshot<T["state"]>, name: keyof T["actions"]) => boolean;
9
9
  readonly isIntentDispatchableFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => boolean;
10
- readonly projectSnapshotFromCanonical: (snapshot: CoreSnapshot) => Snapshot<T["state"]>;
10
+ readonly projectSnapshotFromCanonical: (snapshot: CoreSnapshot) => ProjectedSnapshot<T>;
11
11
  readonly getSimulateSync: () => RuntimeSimulateSync<T>;
12
- readonly emitEvent: <K extends keyof ManifestoEventMap<T>>(event: K, payload: ManifestoEventMap<T>[K]) => void;
13
12
  };
14
- export declare function createRuntimeAdmission<T extends ManifestoDomainShape>({ schema, ensureIntentId, getAvailableActionsFor, isActionAvailableFor, isIntentDispatchableFor, projectSnapshotFromCanonical, getSimulateSync, emitEvent, }: RuntimeAdmissionOptions<T>): RuntimeAdmission<T>;
13
+ export declare function createRuntimeAdmission<T extends ManifestoDomainShape>({ schema, ensureIntentId, getAvailableActionsFor, isActionAvailableFor, isIntentDispatchableFor, projectSnapshotFromCanonical, getSimulateSync, }: RuntimeAdmissionOptions<T>): RuntimeAdmission<T>;
15
14
  export {};