@manifesto-ai/sdk 5.0.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # @manifesto-ai/sdk
2
2
 
3
- > Activation-first entry point for Manifesto applications.
3
+ > Base runtime entry point for Manifesto applications.
4
4
 
5
- `@manifesto-ai/sdk` is the default package for applications that start with `createManifesto()`.
5
+ `@manifesto-ai/sdk` is the package most apps should start with. It turns a MEL
6
+ domain into an activated runtime with typed actions, `snapshot()` reads, and
7
+ subscriptions.
6
8
 
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)`.
9
+ For the step-by-step app path, start with the main
10
+ [Quick Start](../../docs/guide/quick-start.md) and
11
+ [Tutorial](../../docs/tutorial/index.md). Use the package-level spec only when
12
+ you need the exact runtime contract.
8
13
 
9
14
  ## When to Use It
10
15
 
@@ -13,30 +18,42 @@ Use the SDK when you want:
13
18
  - the shortest path to a running base runtime
14
19
  - typed action submission through `action.*`
15
20
  - optional typed effect authoring through `@manifesto-ai/sdk/effects`
16
- - action-candidate check/preview/submit, observers, legality queries, optional trace diagnostics, and snapshot reads in one package
17
- - projected Snapshot reads by default, with canonical inspection available explicitly
18
- - safe post-activation arbitrary-snapshot tooling through `@manifesto-ai/sdk/extensions`
21
+ - action check/preview/submit, observers, availability queries, optional diagnostics, and `snapshot()` reads in one package
22
+ - generated domain facades from `@manifesto-ai/codegen`
23
+ - advanced inspection and simulation helpers when you are building tools around an app
19
24
 
20
25
  ## Smallest Example
21
26
 
22
27
  ```typescript
23
28
  import { createManifesto } from "@manifesto-ai/sdk";
29
+ import TodoMel from "./domain/todo.mel";
30
+ import type { TodoDomain } from "./domain/todo.domain";
24
31
 
25
- const manifesto = createManifesto<CounterDomain>(counterSchema, {});
32
+ const manifesto = createManifesto<TodoDomain>(TodoMel, {});
26
33
  const app = manifesto.activate();
27
34
 
28
- await app.action.increment.submit();
29
- console.log(app.snapshot().state.count);
35
+ await app.action.addTodo.submit("Review docs");
36
+ console.log(app.snapshot().state.todos);
30
37
  ```
31
38
 
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.
39
+ The base runtime covers the ordinary app loop: submit typed actions, read
40
+ snapshots, and observe state or lifecycle events. Availability, preview, and
41
+ inspection helpers are available when UI, agent, or debugging tooling needs
42
+ them.
33
43
 
34
44
  Effect authoring helpers live on the dedicated `@manifesto-ai/sdk/effects` subpath. The root package stays centered on `createManifesto()`.
35
45
 
36
- If you need review, approval, or sealed history later, compose `@manifesto-ai/lineage` and `@manifesto-ai/governance` before `activate()`. If you need arbitrary-snapshot tooling after activation, use `@manifesto-ai/sdk/extensions`.
46
+ If you need review, approval, policy, audit history, or restore later,
47
+ compose optional `@manifesto-ai/lineage` and `@manifesto-ai/governance`
48
+ extensions before `activate()`.
49
+ If you are building low-level runtime tooling after activation, use
50
+ `@manifesto-ai/sdk/extensions`.
37
51
 
38
52
  ## Docs
39
53
 
54
+ - [Quick Start](../../docs/guide/quick-start.md)
55
+ - [React Integration](../../docs/integration/react.md)
56
+ - [Web App + Agent](../../docs/integration/web-app-and-agent.md)
40
57
  - [Public API Reference](../../docs/api/sdk.md)
41
58
  - [SDK Guide](docs/GUIDE.md)
42
59
  - [SDK Specification](docs/sdk-SPEC.md)
@@ -0,0 +1 @@
1
+ import{c as G,g as X,h as J,l as j,o as Q}from"./chunk-L7HPZ7ZD.js";import{a as h,d as K,f as D}from"./chunk-TG2UPPZN.js";async function Y(e,o,s,c,l){let p=e.getCanonicalSnapshot(),f=o.projectSnapshot(p),T=e.evaluateIntentLegalityFor(p,c),x=e.deriveIntentAdmission(p,T);if(T.kind!=="admitted"){let A=x,y=ue(e,T),z={code:y.code,reason:y.message};return{kind:"rejected",intent:T.intent,admission:A,beforeSnapshot:f,beforeCanonicalSnapshot:p,rejection:z,rejectionError:y}}let N=x,b;try{b=await e.executeHost(T.intent,{context:l})}catch(A){let y=de(A);return{kind:"failed",intent:T.intent,admission:N,beforeSnapshot:f,beforeCanonicalSnapshot:p,failure:y,errorInfo:e.classifyExecutionFailure(y,"host"),published:!1}}let I=e.createExecutionDiagnostics(b);if(b.status==="error"){let A=b.error??new h("HOST_ERROR","Host dispatch failed"),{publishedCanonicalSnapshot:y}=s.publishFailedHostResult(b.snapshot);return{kind:"failed",intent:T.intent,admission:N,beforeSnapshot:f,beforeCanonicalSnapshot:p,failure:A,errorInfo:e.classifyExecutionFailure(A,"host"),published:!0,diagnostics:I,outcome:e.deriveExecutionOutcome(p,y)}}let{publishedSnapshot:M,publishedCanonicalSnapshot:C}=s.publishCompletedHostResult(b.snapshot);return{kind:"completed",intent:T.intent,admission:N,publishedSnapshot:M,outcome:e.deriveExecutionOutcome(p,C),diagnostics:I}}function ue(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 h("SDK_REPORT_ERROR","Cannot derive a rejected dispatch error for an admitted intent")}function de(e){return e instanceof Error?e:new Error(String(e))}function V(e){let o;try{o=structuredClone(e)}catch(s){throw new h("INVALID_INPUT",`Action input must be structured-cloneable: ${s instanceof Error?s.message:String(s)}`)}return Z(o)}function H(e){try{return{ok:!0,value:V(e)}}catch(o){if(o instanceof h)return{ok:!1,error:o};throw o}}function Z(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))Z(s[c],o);return Object.freeze(e)}function me(e,o={},s=!1){let c=v(o),l=e[G],p=J({setVisibleSnapshot:e.setVisibleSnapshot,restoreVisibleSnapshot:e.restoreVisibleSnapshot,getCanonicalSnapshot:e.getCanonicalSnapshot}),f=new Map;for(let t of e.getActionMetadata())f.set(t.name,fe(t));let T=Object.create(null),x=new Map;for(let t of f.keys()){let n=z(t);x.set(t,n),Object.defineProperty(T,t,{enumerable:!0,configurable:!1,writable:!1,value:n})}function N(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 b=Object.freeze({state:N,event(t,n){return e.isDisposed()?()=>{}:e.on(t,n)}}),I=(t=>x.get(t)),M={action:Object.freeze(T),state:A(),computed:y(),observe:b,inspect:Object.freeze({graph:e.getSchemaGraph,canonicalSnapshot:e.getCanonicalSnapshot,action(t){return O(t)},availableActions(){return Object.freeze(e.getAvailableActions().map(t=>O(t)))},schemaHash(){return e.getCanonicalSnapshot().meta.schemaHash}}),snapshot:e.getSnapshot,getAction:I,context:U,injectContext(t){if(s){c=v({...c,context:e.captureExternalContext(t)});return}e.replaceExternalContext(t)},updateContext(t){if(!s)return e.updateExternalContext(t);let n=t(U());return c=v({...c,context:e.captureExternalContext(n)}),c.context??e.getExternalContext()},with(t){return me(e,oe(t),!0)},dispose:e.dispose};return Object.freeze(Q(M,e));function C(t,n,i){return Object.freeze({name:t,ref:n,value:()=>i(e.getSnapshot()),observe:r=>N(i,r)})}function A(){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:C(n,i,r=>r.state[n])})}return Object.freeze(t)}function y(){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:C(n,i,r=>r.computed[n])})}return Object.freeze(t)}function z(t){return Object.freeze({info:()=>O(t),available:()=>e.isActionAvailable(t),check:(...n)=>{let i=E(t,n);return k(i)},preview:(...n)=>{let i=E(t,n);return L(i)},submit:(...n)=>{let i=E(t,n);return _(i)},bind:(...n)=>te(t,n)})}function te(t,n){let i=E(t,n),r=H([...n]),u=()=>r.ok?E(t,r.value):i;return Object.freeze({action:t,input:i.input,check:()=>k(u()),preview:()=>L(u()),submit:()=>_(u()),intent:()=>{let a=u();return a.inputError?null:a.intent}})}function E(t,n){let i=e.refs.actions[t],r=ne(t,n),u=H(r);if(!u.ok)return Object.freeze({actionName:t,input:void 0,intent:null,inputError:u.error});try{let a=V(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 h))throw a;return Object.freeze({actionName:t,input:u.value,intent:null,inputError:a})}}function ne(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 k(t){let n=e.getCanonicalSnapshot();return B(t,n).admission}function L(t){let n=e.getCanonicalSnapshot(),i=l.projectSnapshot(n),r=B(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,P()),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:X(i,S),requirements:d.requirements,newAvailableActions:e.getAvailableActionsFor(d.snapshot).map(R=>O(R)),...le(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,P()):null;return e.enqueue(async()=>{if(e.isDisposed())throw new K;let i=e.getCanonicalSnapshot(),r=B(t,i);if(!r.admission.ok||r.intent===null){let m=r.admission;return q(t.actionName,t.intent,m,i),Object.freeze({ok:!1,mode:"base",action:t.actionName,admission:m})}let u=r.intent;ae(t.actionName,u,r.admission,i),re(t.actionName,u,i);let a=await Y(e,l,p,u,n??e.createComputeContext(u,P()));if(a.kind==="rejected"){let m=j(t.actionName,a.admission,a.rejection.reason);return q(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 ce=$??be(a.failure,a.intent,m);throw F(t.actionName,a.intent,ce,m),new D(a.failure.message,"runtime",{cause:a.failure})}}let d=(a.kind==="completed",a.outcome);if(!d){let m=w(a.kind==="failed"?a.failure:new Error("Submission produced no terminal outcome"),a.intent,e.getCanonicalSnapshot());throw F(t.actionName,a.intent,m,e.getCanonicalSnapshot()),new D(m.message,"runtime")}let S=ye(d,a.intent,a.diagnostics),R=d.canonical.afterCanonicalSnapshot;if(d.canonical.status==="pending"){let m=w(new Error("Base submit produced a pending runtime snapshot"),a.intent,R);throw F(t.actionName,a.intent,m,R),new D(m.message,"runtime")}se(t.actionName,a.intent,S,R);let W=pe(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,...W!==void 0?{report:W}:{}})})}function U(){return c.context??e.getExternalContext()}function P(){return c.context??e.captureExternalContext()}function oe(t){return v({...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 B(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:ie(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 ie(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 O(t){let n=f.get(t);if(!n)throw new h("UNKNOWN_ACTION",`Action "${String(t)}" is not declared by this Manifesto schema`);return n}function ae(t,n,i,r){e.emitEvent("submission:admitted",{...g(t,n,r),admission:i})}function q(t,n,i,r){e.emitEvent("submission:rejected",{...g(t,n,r),admission:i})}function re(t,n,i){e.emitEvent("submission:submitted",g(t,n,i))}function se(t,n,i,r){e.emitEvent("submission:settled",{...g(t,n,r),outcome:i})}function F(t,n,i,r){e.emitEvent("submission:failed",{...g(t,n,r),stage:"runtime",error:i})}function g(t,n,i){return{action:t,mode:"base",...n?.intentId?{intentId:n.intentId}:{},schemaHash:i.meta.schemaHash,snapshotVersion:i.meta.version}}}function le(e,o){return!e||o==="none"?{}:o==="summary"?{diagnostics:{}}:{diagnostics:{trace:e.trace}}}function pe(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 v(e){return Object.freeze({...e})}function fe(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:Te(f.type)}:{},...f?.description!==void 0?{description:f.description}:{}})})),...c!==void 0?{annotations:c}:{}})}function Te(e){return typeof e=="string"?e:typeof e=="object"&&e!==null&&"enum"in e?"enum":"unknown"}function ye(e,o,s){let c=he(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:w(new Error("Runtime completed with error status"),o,l)}):Object.freeze({kind:"ok"})}function he(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 w(e,o,s){return Object.freeze({code:e instanceof h?e.code:"SUBMISSION_FAILED",message:e.message,source:{actionId:o.intentId??"",nodePath:"runtime.submit"},timestamp:s.meta.timestamp})}function be(e,o,s){return Ae(s)??w(e,o,s)}function Ae(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(Ne(s))return s}return null}function Ne(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{me as a};
@@ -0,0 +1 @@
1
+ import{a as b,e as W}from"./chunk-TG2UPPZN.js";import{evaluateComputed as St,evaluateActionAvailability as Tt,evaluateAvailableActions as bt,evaluateIntentDispatchability as At,isErr as Ct}from"@manifesto-ai/core";import{extractSchemaGraph as xt}from"@manifesto-ai/compiler";function kt(e){return{visibleComputedKeys:Object.keys(e.computed.fields)}}function Y(e,t){return{state:qe(e.state),computed:We(e.computed,t),system:{status:e.system.status,lastError:e.system.lastError},meta:{schemaHash:e.meta.schemaHash}}}function vt(e,t){return Y(e,t)}function j(e){return ye(structuredClone(e))}function he(e,t){return Ye(e,t)}function qe(e){return structuredClone(e)}function We(e,t){let n={};for(let o of t.visibleComputedKeys)Object.hasOwn(e,o)&&(n[o]=e[o]);return structuredClone(n)}function Ye(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,a=t,y=Object.prototype.toString.call(o),i=Object.prototype.toString.call(a);if(y!==i)return!1;let r=n.get(o);if(r?.has(a))return!0;if(r||(r=new WeakSet,n.set(o,r)),r.add(a),Array.isArray(o)&&Array.isArray(a)){if(o.length!==a.length)return!1;for(let c=0;c<o.length;c+=1){let h=Object.hasOwn(o,c),C=Object.hasOwn(a,c);if(h!==C||h&&!P(o[c],a[c],n))return!1}return!0}if(o instanceof Date&&a instanceof Date)return o.getTime()===a.getTime();if(o instanceof RegExp&&a instanceof RegExp)return o.source===a.source&&o.flags===a.flags;if(ArrayBuffer.isView(o)&&ArrayBuffer.isView(a)){if(o.constructor!==a.constructor||o.byteLength!==a.byteLength)return!1;let c=new Uint8Array(o.buffer,o.byteOffset,o.byteLength),h=new Uint8Array(a.buffer,a.byteOffset,a.byteLength);return c.every((C,A)=>C===h[A])}if(o instanceof ArrayBuffer&&a instanceof ArrayBuffer){if(o.byteLength!==a.byteLength)return!1;let c=new Uint8Array(o),h=new Uint8Array(a);return c.every((C,A)=>C===h[A])}if(o instanceof Map&&a instanceof Map){if(o.size!==a.size)return!1;let c=Array.from(o.entries()),h=Array.from(a.entries());return c.every(([C,A],T)=>{let g=h[T];if(!g)return!1;let[x,O]=g;return P(C,x,n)&&P(A,O,n)})}if(o instanceof Set&&a instanceof Set){if(o.size!==a.size)return!1;let c=Array.from(o.values()),h=Array.from(a.values());return c.every((C,A)=>P(C,h[A],n))}let l=fe(o),p=fe(a);if(l.length!==p.length)return!1;for(let c=0;c<l.length;c+=1){let h=l[c],C=p[c];if(h!==C)return!1;let A=o[h],T=a[C];if(!P(A,T,n))return!1}return!0}function fe(e){return Object.keys(e).filter(t=>e[t]!==void 0).sort()}function ye(e,t=new WeakSet){if(e==null||typeof e!="object")return e;if(me(e))return Se(e);let n=e;if(t.has(n)||Object.isFrozen(e))return e;t.add(n);for(let o of Reflect.ownKeys(n)){let a=n[o];if(me(a)){Xe(n,o,a);continue}ye(a,t)}return Object.freeze(e)}function me(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)}function Se(e){return structuredClone(e)}function Xe(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 Se(n)}})}var X=Symbol("manifesto-sdk.action-param-names"),Qe=Symbol("manifesto-sdk.action-single-param-object-value"),U=Symbol("manifesto-sdk.runtime-kernel-factory"),z=Symbol("manifesto-sdk.activation-state"),N=Symbol("manifesto-sdk.extension-kernel");var Ze=/^(state|computed|action):.+$/;function Q(e){let t=new Set(e.nodes.map(r=>r.id)),n=new Map,o=new Map,a=(r,l,p)=>{let c=r.get(l);if(c){c.add(p);return}r.set(l,new Set([p]))};for(let r of e.edges)a(n,r.from,r.to),a(o,r.to,r.from);let y=r=>{let l=Object.freeze({nodes:Object.freeze(e.nodes.filter(p=>r.has(p.id))),edges:Object.freeze(e.edges.filter(p=>r.has(p.from)&&r.has(p.to)))});return Q(l)},i=(r,l)=>{let p=et(r,t),c=[p],h=new Set([p]),C=l==="incoming"?o:n;for(;c.length>0;){let A=c.shift();if(A)for(let T of C.get(A)??[])h.has(T)||(h.add(T),c.push(T))}return y(h)};return Object.freeze({nodes:e.nodes,edges:e.edges,traceUp(r){return i(r,"incoming")},traceDown(r){return i(r,"outgoing")}})}function et(e,t){if(typeof e=="string"){if(!Ze.test(e))throw new b("SCHEMA_ERROR",'SchemaGraph node id must use "state:<name>", "computed:<name>", or "action:<name>"');if(!t.has(e))throw new b("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 b("SCHEMA_ERROR","Unsupported SchemaGraph ref lookup target")}if(!t.has(n))throw new b("SCHEMA_ERROR",`SchemaGraph node "${n}" is not part of the projected graph`);return n}import{validateIntentInput as ot}from"@manifesto-ai/core";function be({getAvailableActionsFor:e,projectSnapshotFromCanonical:t}){function n(i,r){let l=e(i),p=e(r),c=Object.freeze(p.filter(C=>!l.includes(C))),h=Object.freeze(l.filter(C=>!p.includes(C)));return Object.freeze({before:l,after:p,unlocked:c,locked:h})}function o(i,r){let l=j(i),p=j(r),c=t(l),h=t(p);return Object.freeze({projected:Object.freeze({beforeSnapshot:c,afterSnapshot:h,changedPaths:B(c,h),availability:n(l,p)}),canonical:Object.freeze({beforeCanonicalSnapshot:l,afterCanonicalSnapshot:p,pendingRequirements:p.system.pendingRequirements,status:p.system.status})})}function a(i,r){let l=nt(i),p=l;return Object.freeze({message:l.message,...typeof p.code=="string"?{code:p.code}:{},...typeof l.name=="string"?{name:l.name}:{},stage:r})}function y(i){return Object.freeze({hostTraces:j(i.traces)})}return Object.freeze({deriveExecutionOutcome:o,classifyExecutionFailure:a,createExecutionDiagnostics:y})}function B(e,t){let n=new Map,o=new WeakMap,a=(i,r)=>{let l=tt(i);n.set(l,Object.freeze({path:Object.freeze([...i]),kind:r}))},y=(i,r,l)=>{if(Object.is(i,r))return;if(i===null||r===null){a(l,"changed");return}if(typeof i!="object"||typeof r!="object"){a(l,"changed");return}let p=i,c=r,h=o.get(p);if(h?.has(c))return;if(h?h.add(c):o.set(p,new WeakSet([c])),Array.isArray(i)||Array.isArray(r)){if(!Array.isArray(i)||!Array.isArray(r)){a(l,"changed");return}let A=Math.max(i.length,r.length);for(let T=0;T<A;T+=1){let g=Object.hasOwn(i,T),x=Object.hasOwn(r,T),O=[...l,T];if(g!==x){a(O,g?"unset":"set");continue}!g&&!x||y(i[T],r[T],O)}return}if(!Te(i)||!Te(r)){a(l,"changed");return}let C=new Set([...Object.keys(i),...Object.keys(r)]);for(let A of[...C].sort()){let T=Object.hasOwn(i,A),g=Object.hasOwn(r,A),x=[...l,A];if(T!==g){a(x,T?"unset":"set");continue}y(i[A],r[A],x)}};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],[r])=>i.localeCompare(r)).map(([,i])=>i))}function Te(e){return Object.prototype.toString.call(e)==="[object Object]"}function tt(e){return e.map(t=>typeof t=="number"?`[${t}]`:t).join(".")}function nt(e){return e instanceof Error?e:new Error(String(e))}function Ae({schema:e,ensureIntentId:t,getAvailableActionsFor:n,isActionAvailableFor:o,evaluateActionAvailabilityFor:a,evaluateIntentDispatchabilityFor:y,projectSnapshotFromCanonical:i,getSimulateSync:r}){function l(S,m,u){return Object.freeze({layer:S,expression:m,evaluatedResult:!1,...u!==void 0?{description:u}:{}})}function p(S,m){let u=m.type,d=e.actions[u];if(!d)return Object.freeze([]);let I=a(S,u);if(I.kind==="error")return Object.freeze(d.available?[l("available",d.available,I.message)]:[]);if(!I.available)return Object.freeze(d.available?[l("available",d.available,d.description)]:[]);let E=y(S,m);return E.kind==="error"?Object.freeze(d.dispatchable?[l("dispatchable",d.dispatchable,E.message)]:[]):E.dispatchable?Object.freeze([]):Object.freeze(d.dispatchable?[l("dispatchable",d.dispatchable,d.description)]:[])}function c(S){return new b("ACTION_UNAVAILABLE",`Action "${S.type}" is unavailable against the current visible snapshot`)}function h(S){return new b("INTENT_NOT_DISPATCHABLE",`Action "${S.type}" is available, but the bound intent is not dispatchable against the current visible snapshot`)}function C(S){return new b("INVALID_INPUT",S)}function A(S,m){let u=ot(e,m);return u?C(u):null}function T(S,m){let u=t(m),d=u.type;if(!o(S,d))return{kind:"unavailable",intent:u,actionName:d};let I=A(S,u);if(I)return{kind:"invalid-input",intent:u,actionName:d,error:I};let E=p(S,u);return E.length>0?{kind:"not-dispatchable",intent:u,actionName:d,blockers:E}:{kind:"admitted",intent:u,actionName:d}}function g(S,m){return m.kind==="unavailable"?Object.freeze({kind:"blocked",actionName:m.actionName,failure:{kind:"unavailable",blockers:p(S,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 x(S,m){let u=T(S,m);if(u.kind==="unavailable")return Object.freeze({kind:"blocked",actionName:u.actionName,available:!1,dispatchable:!1,blockers:p(S,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=r()(S,u.intent),I=i(S),E=i(d.snapshot);return Object.freeze({kind:"admitted",actionName:u.actionName,available:!0,dispatchable:!0,status:d.status,requirements:d.requirements,canonicalSnapshot:d.snapshot,snapshot:E,newAvailableActions:n(d.snapshot),changedPaths:B(I,E)})}function O(S,m){throw m}function _(S){return O(S,c(S))}function L(S,m){return O(S,C(m))}function V(S){return O(S,h(S))}return Object.freeze({getIntentBlockersFor:p,validateIntentInputFor:A,evaluateIntentLegalityFor:T,deriveIntentAdmission:g,explainIntentFor:x,createUnavailableError:c,createNotDispatchableError:h,rejectInvalidInput:L,rejectUnavailable:_,rejectNotDispatchable:V})}function Ce({setVisibleSnapshot:e,restoreVisibleSnapshot:t,getCanonicalSnapshot:n}){function o(i,r){return e(i,r)}function a(i){let r=o(i);return Object.freeze({publishedSnapshot:r,publishedCanonicalSnapshot:n()})}function y(i){let r=o(i);return Object.freeze({publishedSnapshot:r,publishedCanonicalSnapshot:n()})}return Object.freeze({replaceVisibleSnapshot:o,restoreVisibleSnapshot:t,publishCompletedHostResult:a,publishFailedHostResult:y})}import{apply as at,applyNamespaceDeltas as xe,applySystemDelta as rt,computeSync as it}from"@manifesto-ai/core";import{getHostState as st}from"@manifesto-ai/host/tooling";function Ee(e,t){return{...e,timestamp:t,children:e.children.map(n=>Ee(n,t))}}function ct(e){let t={};function n(o){t[o.id]=o,o.children.forEach(n)}return n(e),t}function lt(e,t){let n=Ee(e.root,t);return{...e,duration:0,root:n,nodes:ct(n)}}function Re({schema:e,hostContextProvider:t,evaluateIntentLegalityFor:n}){function o(r,l){let c=st(r)?.intentSlots??{},h=l.input===void 0?{type:l.type}:{type:l.type,input:l.input};return xe(r,[{namespace:"host",patches:[{op:"set",path:[{kind:"prop",name:"intentSlots"}],value:{...c,[l.intentId]:h}}]}])}function a(r){return new b("ACTION_UNAVAILABLE",`Action "${r.type}" is unavailable against the provided canonical snapshot`)}function y(r){return new b("INTENT_NOT_DISPATCHABLE",`Action "${r.type}" is available, but the bound intent is not dispatchable against the provided canonical snapshot`)}return Object.freeze({withHostIntentSlot:o,createSimulationUnavailableError:a,createSimulationNotDispatchableError:y,simulateSync:(r,l,p)=>{let c=n(r,l);if(c.kind==="unavailable")throw a(c.intent);if(c.kind==="invalid-input")throw c.error;if(c.kind==="not-dispatchable")throw y(c.intent);let h=c.intent,C=p?.context??t.createFrozenContext(h.intentId,p?.externalContext),A=o(structuredClone(r),h),T=it(e,A,h,C),g=at(e,A,T.patches),x=xe(g,T.namespaceDelta??[]),O=rt(x,T.systemDelta);return Object.freeze({snapshot:j(O),patches:j(T.patches),systemDelta:j(T.systemDelta),status:T.status,requirements:j(T.systemDelta.addRequirements??[]),diagnostics:Object.freeze({trace:j(lt(T.trace,r.meta.timestamp))})})}})}import{findJsonValueViolation as Z}from"@manifesto-ai/core";var ut=["state","computed","system","meta","namespaces"];function H(e){if(e===null||typeof e!="object"||Array.isArray(e))return Z(e,"snapshot");let t=e;for(let n of ut){let o=Z(t[n],`snapshot.${n}`);if(o)return o}return t.input===void 0?null:Z(t.input,"snapshot.input")}var pt=new Set(["state","computed","system","input","meta","namespaces"]),dt=["state","system","meta"];function ft(e){if(e===null||typeof e!="object"||Array.isArray(e))throw new b("INVALID_SNAPSHOT_SHAPE","Visible snapshot must be a canonical snapshot object");let t=e,n=Object.keys(t).filter(o=>!pt.has(o));if(n.length>0){let o=n.includes("data")?' Domain state lives under "state" since v5; the v4 "data" key was renamed.':"";throw new b("INVALID_SNAPSHOT_SHAPE",`Visible snapshot has unknown top-level key(s): ${n.join(", ")}.${o} Expected only: state, computed, system, input, meta, namespaces.`)}for(let o of dt){let a=t[o];if(a===null||typeof a!="object"||Array.isArray(a))throw new b("INVALID_SNAPSHOT_SHAPE",`Visible snapshot is missing the required "${o}" object`)}}function mt(e){let t=H(e);if(t)throw new b("INVALID_SNAPSHOT_VALUE",`Visible snapshot contains a non-JSON value at ${t.path}: ${t.reason}`)}function Ie({host:e,initialCanonicalSnapshot:t,projectSnapshotFromCanonical:n}){let o=structuredClone(t),a=n(o),y=j(o),i=Promise.resolve(),r=!1,l=new Set,p=new Map;function c(m,u){if(r)return()=>{};let d,I=!1;try{d=m(a),I=!0}catch{d=void 0,I=!1}let E={selector:m,listener:u,lastValue:d,initialized:I};return l.add(E),()=>{l.delete(E)}}function h(m,u){if(r)return()=>{};let d=p.get(m);return d||(d=new Set,p.set(m,d)),d.add(u),()=>{d?.delete(u)}}function C(){return a}function A(){return y}function T(){return structuredClone(o)}function g(m,u){ft(m),mt(m),o=structuredClone(m),e.reset(structuredClone(o)),y=j(o);let d=n(o),I=!he(d,a);return I&&(a=d),u?.notify!==!1&&I&&S(a),a}function x(){e.reset(structuredClone(o))}function O(m,u){let d=p.get(m);if(d)for(let I of d)try{I(u)}catch{}}function _(m){let u=i.catch(()=>{}).then(m);return i=u.then(()=>{},()=>{}),u}function L(){r||(r=!0,l.clear(),p.clear())}function V(){return r}function S(m){for(let u of l){let d;try{d=u.selector(m)}catch{continue}if(!(u.initialized&&Object.is(u.lastValue,d))){u.lastValue=d,u.initialized=!0;try{u.listener(d)}catch{}}}}return{subscribe:c,on:h,getSnapshot:C,getCanonicalSnapshot:A,getVisibleCoreSnapshot:T,setVisibleSnapshot:g,restoreVisibleSnapshot:x,emitEvent:O,enqueue:_,dispose:L,isDisposed:V}}function ge(){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 ht}from"@manifesto-ai/core";function F(e,t,n){let o=yt(t===void 0?{}:t,n),a=ht(e,o);if(!a.valid){let y=a.errors.map(i=>i.path?`${i.path}: ${i.message}`:i.message).join("; ");throw new b("INVALID_CONTEXT",`Invalid context for ${n}: ${y}`)}return o}function ee(e,t,n,o){return n===void 0?t:F(e,n,o)}function yt(e,t){return ke(e)||k(t,[],"Context must be a plain JSON object"),Object.freeze(Oe(e,t,[],new WeakSet))}function je(e,t,n,o){if(e===null)return null;switch(typeof e){case"string":case"boolean":return e;case"number":return Number.isFinite(e)?e:k(t,n,"Context numbers must be finite");case"undefined":return k(t,n,"Context must not contain undefined");case"function":return k(t,n,"Context must not contain functions");case"symbol":return k(t,n,"Context must not contain symbols");case"bigint":return k(t,n,"Context must not contain bigint values");case"object":break}if(Array.isArray(e)){o.has(e)&&k(t,n,"Context must not contain cycles"),o.add(e),ve(e,t,n),we(e,t,n);let y=[];for(let i=0;i<e.length;i+=1)Object.hasOwn(e,i)||k(t,[...n,i],"Context arrays must not contain holes"),y.push(je(e[i],t,[...n,i],o));return o.delete(e),Object.freeze(y)}ke(e)||k(t,n,"Context objects must be plain JSON objects"),o.has(e)&&k(t,n,"Context must not contain cycles"),o.add(e);let a=Oe(e,t,n,o);return o.delete(e),Object.freeze(a)}function Oe(e,t,n,o){ve(e,t,n),we(e,t,n);let a=Object.create(null);for(let[y,i]of Object.entries(e))a[y]=je(i,t,[...n,y],o);return a}function ke(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ve(e,t,n){for(let[o,a]of Object.entries(Object.getOwnPropertyDescriptors(e)))(a.get||a.set)&&k(t,[...n,o],"Context must not contain getters or setters")}function we(e,t,n){Object.getOwnPropertySymbols(e).length>0&&k(t,n,"Context must not contain symbol keys")}function k(e,t,n){let o=t.length===0?"$context":`$context.${t.map(String).join(".")}`;throw new b("INVALID_CONTEXT",`Invalid context for ${e} at ${o}: ${n}`)}var Et=new Set(["then","constructor","prototype","__proto__"]);function Rt(e){if(e.params)return e.params;let t=e.input;return!t||t.type!=="object"||!t.fields?[]:Object.keys(t.fields)}function It(e){return typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function"}function gt({schema:e,projectionPlan:t,actionAnnotations:n,host:o,hostContextProvider:a,MEL:y,createIntent:i,initialContext:r}){let l=y,p=o.getSnapshot();if(!p)throw new b("SCHEMA_ERROR","Host failed to initialize its genesis snapshot");function c(s){return j(Y(s,t))}function h(s){let f=H({...s,computed:{}});if(f)throw new b("SNAPSHOT_REHYDRATION_FAILED",`Failed to rehydrate restored snapshot JSON values: ${f.path}: ${f.reason}`);let R=St(e,s);if(Ct(R))throw new b("SNAPSHOT_REHYDRATION_FAILED",`Failed to rehydrate restored snapshot computed values: ${R.error.message}`,{cause:R.error});let w={...s,computed:R.value},M=H(w);if(M)throw new b("SNAPSHOT_REHYDRATION_FAILED",`Failed to rehydrate restored snapshot JSON values: ${M.path}: ${M.reason}`);return w}let C=Ie({host:o,initialCanonicalSnapshot:p,projectSnapshotFromCanonical:c}),{subscribe:A,on:T,getSnapshot:g,getCanonicalSnapshot:x,getVisibleCoreSnapshot:O,setVisibleSnapshot:_,restoreVisibleSnapshot:L,emitEvent:V,enqueue:S,dispose:m,isDisposed:u}=C,d=Q(xt(e)),I=Object.keys(e.actions);jt(I);let E=F(e,r,"createManifesto"),ne=Object.freeze(Object.fromEntries(I.map(s=>{let f=e.actions[s],w=l.actions[s]?.[X],M=Object.freeze(Array.isArray(w)?[...w]:Rt(f)),de=w===null?1:M.length,Je=f.input?.required===!1?0:de;return[s,Object.freeze({name:s,params:M,publicArity:de,requiredArity:Je,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})]}))),Me=Object.freeze(I.map(s=>ne[s]));function oe(s,f){return Tt(e,s,String(f))}function ae(s,f){return At(e,s,f)}function D(s){let f=bt(e,s);return f.kind==="error"?Object.freeze([]):Object.freeze([...f.actions])}let $=be({getAvailableActionsFor:D,projectSnapshotFromCanonical:c});function Pe(){return D(x())}let _e=(s=>s!==void 0?ne[String(s)]:Me);function G(s,f){let R=oe(s,f);return R.kind==="ok"&&R.available}function Le(s){return G(x(),s)}function K(s,f){let R=ae(s,f);return R.kind==="ok"&&R.dispatchable}let Ve=((s,...f)=>K(x(),i(s,...f)));function re(s){return s.intentId&&s.intentId.length>0?s:{...s,intentId:ge()}}async function ze(s,f){return o.dispatch(s,f)}function Be(){return E}function He(s){return E=F(e,s,"injectContext"),E}function Fe(s){let f=s(E);if(It(f))throw new b("INVALID_CONTEXT","updateContext() updater must return a synchronous JSON context value");return E=F(e,f,"updateContext"),E}function ie(s){return ee(e,E,s,"transition")}function se(s,f){let R=f===void 0?E:ee(e,E,f,"transition");return a.createFrozenContext(s.intentId,R)}let J=null,v=Ae({schema:e,ensureIntentId:re,getAvailableActionsFor:D,isActionAvailableFor:G,isIntentDispatchableFor:K,evaluateActionAvailabilityFor:oe,evaluateIntentDispatchabilityFor:ae,projectSnapshotFromCanonical:c,getSimulateSync:()=>{if(!J)throw new b("SCHEMA_ERROR","Runtime simulation surface is not initialized");return J}}),ce=Re({schema:e,hostContextProvider:a,evaluateIntentLegalityFor:v.evaluateIntentLegalityFor});J=ce.simulateSync;let le=Ce({setVisibleSnapshot:_,restoreVisibleSnapshot:L,getCanonicalSnapshot:x}),ue=v.getIntentBlockersFor,Ge=((s,...f)=>ue(x(),i(s,...f))),q=(s,f,R)=>{let w=R?.context??se(f,R?.externalContext??ie());return ce.simulateSync(s,f,{context:w})};function Ke(s){let f=c(s.snapshot);return Object.freeze({snapshot:f,changedPaths:B(g(),f),newAvailableActions:D(s.snapshot),requirements:s.requirements,status:s.status,diagnostics:s.diagnostics})}let pe=(s=>Ke(q(x(),s))),Ue=((s,...f)=>pe(i(s,...f))),$e=Object.freeze({refs:l,MEL:y,schema:e,createIntent:i,getCanonicalSnapshot:x,projectSnapshot:s=>c(s),simulateSync:(s,f)=>{let R=q(s,f);return Object.freeze({snapshot:R.snapshot,patches:R.patches,requirements:R.requirements,status:R.status,diagnostics:R.diagnostics})},getAvailableActionsFor:D,isActionAvailableFor:G,isIntentDispatchableFor:K,explainIntentFor:v.explainIntentFor});return{schema:e,refs:l,MEL:y,createIntent:i,subscribe:A,on:T,getSnapshot:g,getAvailableActionsFor:D,getAvailableActions:Pe,getIntentBlockersFor:ue,getActionMetadata:_e,isActionAvailableFor:G,isActionAvailable:Le,isIntentDispatchableFor:K,isIntentDispatchable:Ve,getIntentBlockers:Ge,getSchemaGraph(){return d},simulateSync:q,simulate:Ue,simulateIntent:pe,dispose:m,isDisposed:u,getCanonicalSnapshot:x,getVisibleCoreSnapshot:O,rehydrateSnapshot:h,setVisibleSnapshot:le.replaceVisibleSnapshot,restoreVisibleSnapshot:le.restoreVisibleSnapshot,emitEvent:V,enqueue:S,ensureIntentId:re,executeHost:ze,createComputeContext:se,getExternalContext:Be,replaceExternalContext:He,updateExternalContext:Fe,captureExternalContext:ie,validateIntentInputFor:v.validateIntentInputFor,evaluateIntentLegalityFor:v.evaluateIntentLegalityFor,deriveIntentAdmission:v.deriveIntentAdmission,deriveExecutionOutcome:$.deriveExecutionOutcome,classifyExecutionFailure:$.classifyExecutionFailure,createExecutionDiagnostics:$.createExecutionDiagnostics,createUnavailableError:v.createUnavailableError,createNotDispatchableError:v.createNotDispatchableError,rejectInvalidInput:v.rejectInvalidInput,rejectUnavailable:v.rejectUnavailable,rejectNotDispatchable:v.rejectNotDispatchable,[N]:$e}}function jt(e){let t=e.filter(n=>Et.has(n));if(t.length!==0)throw new b("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 te(e,t){return Object.freeze({path:Object.freeze([]),code:t,message:e.description??t,detail:Object.freeze({layer:e.layer,expression:e.expression})})}function Ot(e,t,n){if(t.failure.kind==="invalid_input"){let a=t.failure;return Object.freeze({ok:!1,action:e,layer:"input",code:"INVALID_INPUT",message:a.error.message,blockers:Object.freeze([])})}if(t.failure.kind==="not_dispatchable"){let a=t.failure;return Object.freeze({ok:!1,action:e,layer:"dispatchability",code:"INTENT_NOT_DISPATCHABLE",message:n??`Action "${e}" is not dispatchable against the current visible snapshot`,blockers:a.blockers.map(y=>te(y,"INTENT_NOT_DISPATCHABLE"))})}let o=t.failure;return Object.freeze({ok:!1,action:e,layer:"availability",code:"ACTION_UNAVAILABLE",message:n??`Action "${e}" is unavailable against the current visible snapshot`,blockers:(o.blockers??[]).map(a=>te(a,"ACTION_UNAVAILABLE"))})}function En(e,t,n){Object.defineProperty(e,U,{enumerable:!1,configurable:!1,writable:!1,value:t});let o=n??Ne(e)??{activated:!1};return Ne(e)||Object.defineProperty(e,z,{enumerable:!1,configurable:!1,writable:!1,value:o}),e}function Rn(e){let n=e[U];if(typeof n!="function")throw new b("SCHEMA_ERROR","ComposableManifesto is missing its runtime kernel factory");return n}function In(e,t){return Object.defineProperty(e,N,{enumerable:!1,configurable:!1,writable:!1,value:t[N]}),e}function gn(e){let n=e[N];if(!n)throw new b("SCHEMA_ERROR","Activated runtime is missing its extension kernel");return n}function De(e){let n=e[z];if(!n)throw new b("SCHEMA_ERROR","ComposableManifesto is missing its activation state");return n}function jn(e){if(De(e).activated)throw new W}function On(e){let t=De(e);if(t.activated)throw new W;t.activated=!0}function Ne(e){return e[z]??null}export{X as a,Qe as b,N as c,kt as d,vt as e,j as f,B as g,Ce as h,ge as i,gt as j,te as k,Ot as l,En as m,Rn as n,In as o,gn as p,De as q,jn as r,On as s};
@@ -1,106 +1,13 @@
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
- import type { HostContextProvider, HostResult, ManifestoHost } from "@manifesto-ai/host";
3
- import { ManifestoError } from "../errors.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
- import type { SnapshotProjectionPlan } from "../projection/snapshot-projection.js";
1
+ import type { BaseLaws, ComposableManifesto, ManifestoDomainShape } from "../types.js";
6
2
  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";
3
+ import { ACTIVATION_STATE, RUNTIME_KERNEL_FACTORY, type ActivationState } from "./runtime-symbols.js";
9
4
  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
- readonly diagnostics?: SimulationDiagnostics;
18
- };
19
- export interface RuntimeKernel<T extends ManifestoDomainShape> {
20
- readonly schema: DomainSchema;
21
- readonly refs: TypedDomainRefs<T>;
22
- /** @deprecated Use refs. */
23
- readonly MEL: TypedMEL<T>;
24
- readonly createIntent: TypedCreateIntent<T>;
25
- readonly subscribe: TypedSubscribe<T>;
26
- readonly on: TypedOn<T>;
27
- readonly getSnapshot: () => ProjectedSnapshot<T>;
28
- readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
29
- readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
30
- readonly getAvailableActions: () => readonly (keyof T["actions"])[];
31
- readonly getIntentBlockersFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => readonly DispatchBlocker[];
32
- readonly getActionMetadata: TypedGetActionMetadata<T>;
33
- readonly isActionAvailableFor: (snapshot: CanonicalSnapshot<T["state"]>, name: keyof T["actions"]) => boolean;
34
- readonly isActionAvailable: (name: keyof T["actions"]) => boolean;
35
- readonly isIntentDispatchableFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => boolean;
36
- readonly isIntentDispatchable: TypedIsIntentDispatchable<T>;
37
- readonly getIntentBlockers: TypedGetIntentBlockers<T>;
38
- readonly getSchemaGraph: () => SchemaGraph;
39
- readonly simulateSync: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>, options?: {
40
- readonly externalContext?: DomainExternalContext<T>;
41
- readonly context?: Context;
42
- }) => SimulateResult<T>;
43
- readonly simulate: TypedSimulate<T>;
44
- readonly simulateIntent: TypedSimulateIntent<T>;
45
- readonly dispose: () => void;
46
- readonly isDisposed: () => boolean;
47
- readonly getVisibleCoreSnapshot: () => CoreSnapshot;
48
- readonly setVisibleSnapshot: (snapshot: CoreSnapshot, options?: {
49
- readonly notify?: boolean;
50
- }) => ProjectedSnapshot<T>;
51
- readonly rehydrateSnapshot: (snapshot: CoreSnapshot) => CoreSnapshot;
52
- readonly restoreVisibleSnapshot: () => void;
53
- readonly emitEvent: <K extends ManifestoEvent>(event: K, payload: ManifestoEventPayloadMap[K]) => void;
54
- readonly enqueue: <R>(task: () => Promise<R>) => Promise<R>;
55
- readonly ensureIntentId: (intent: TypedIntent<T>) => TypedIntent<T>;
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>;
62
- readonly validateIntentInputFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => ManifestoError | null;
63
- readonly evaluateIntentLegalityFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => IntentLegalityEvaluation<T>;
64
- readonly deriveIntentAdmission: (snapshot: CanonicalSnapshot<T["state"]>, legality: IntentLegalityEvaluation<T>) => IntentAdmission<T>;
65
- readonly deriveExecutionOutcome: (beforeSnapshot: CanonicalSnapshot<T["state"]>, afterSnapshot: CanonicalSnapshot<T["state"]>) => DispatchExecutionOutcome<T>;
66
- readonly classifyExecutionFailure: (error: unknown, stage: "host" | "seal") => ExecutionFailureInfo;
67
- readonly createExecutionDiagnostics: (result: HostResult) => ExecutionDiagnostics;
68
- readonly createUnavailableError: (intent: TypedIntent<T>) => ManifestoError;
69
- readonly createNotDispatchableError: (intent: TypedIntent<T>) => ManifestoError;
70
- readonly rejectInvalidInput: (intent: TypedIntent<T>, message: string) => never;
71
- readonly rejectUnavailable: (intent: TypedIntent<T>) => never;
72
- readonly rejectNotDispatchable: (intent: TypedIntent<T>) => never;
73
- readonly [EXTENSION_KERNEL]: ExtensionKernel<T>;
74
- }
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">;
76
- type RuntimeLifecycleFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "dispose" | "isDisposed" | "enqueue">;
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">;
79
- type RuntimeReportAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "evaluateIntentLegalityFor" | "deriveIntentAdmission" | "createUnavailableError" | "createNotDispatchableError">;
80
- type RuntimePublicationFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "getVisibleCoreSnapshot" | "setVisibleSnapshot" | "rehydrateSnapshot" | "restoreVisibleSnapshot">;
81
- type RuntimeReportingFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "deriveExecutionOutcome" | "classifyExecutionFailure" | "createExecutionDiagnostics">;
82
- type RuntimeDispatchEventsFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "emitEvent">;
83
- type RuntimeExtensionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, typeof EXTENSION_KERNEL>;
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>;
85
- export type LineageRuntimeKernelFactory<T extends ManifestoDomainShape> = () => LineageRuntimeKernel<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>;
87
- export type GovernanceRuntimeKernelFactory<T extends ManifestoDomainShape> = () => GovernanceRuntimeKernel<T>;
88
- export type WaitForProposalRuntimeKernel<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isDisposed" | "deriveExecutionOutcome">;
89
- export type RuntimeKernelFactory<T extends ManifestoDomainShape> = () => RuntimeKernel<T>;
5
+ export * from "../runtime/kernel-contract.js";
6
+ import type { RuntimeExtensionFacet, RuntimeKernelFactory } from "../runtime/kernel-contract.js";
90
7
  export type InternalComposableManifesto<T extends ManifestoDomainShape, Laws extends BaseLaws> = ComposableManifesto<T, Laws> & {
91
8
  readonly [RUNTIME_KERNEL_FACTORY]: RuntimeKernelFactory<T>;
92
9
  readonly [ACTIVATION_STATE]: ActivationState;
93
10
  };
94
- export type RuntimeKernelOptions<T extends ManifestoDomainShape> = {
95
- readonly schema: DomainSchema;
96
- readonly projectionPlan: SnapshotProjectionPlan;
97
- readonly actionAnnotations: Readonly<Record<string, ActionAnnotation>>;
98
- readonly host: ManifestoHost;
99
- readonly hostContextProvider: HostContextProvider;
100
- readonly MEL: TypedMEL<T>;
101
- readonly createIntent: TypedCreateIntent<T>;
102
- readonly initialContext?: Record<string, JsonValue>;
103
- };
104
11
  export declare function attachRuntimeKernelFactory<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>, factory: RuntimeKernelFactory<T>, activationState?: ActivationState): InternalComposableManifesto<T, Laws>;
105
12
  export declare function getRuntimeKernelFactory<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): RuntimeKernelFactory<T>;
106
13
  export declare function attachExtensionKernel<T extends ManifestoDomainShape, TInstance extends object>(runtime: TInstance, kernel: RuntimeExtensionFacet<T>): TInstance;
@@ -109,3 +16,4 @@ export declare function getActivationState<T extends ManifestoDomainShape, Laws
109
16
  export declare function assertComposableNotActivated<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): void;
110
17
  export declare function activateComposable<T extends ManifestoDomainShape, Laws extends BaseLaws>(manifesto: ComposableManifesto<T, Laws>): void;
111
18
  export { createRuntimeKernel } from "../runtime/kernel.js";
19
+ export { mapBlockedAdmission, toBlocker } from "../runtime/admission-failure.js";
@@ -1 +1 @@
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};
1
+ import{f as m,p as c}from"./chunk-L7HPZ7ZD.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,7 +9,18 @@
9
9
  */
10
10
  export type { SdkManifest } from "./manifest.js";
11
11
  export { createManifesto } from "./create-manifesto.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";
12
+ export type { ActivatedInstance, ActionAnnotation, ActionArgs, ActionHandle, ActionInfo, ActionInput, ActionName, ActionParameterInfo, ActionSurface, Admission, AdmissionFailure, AdmissionOk, CreateIntentArgs, CreateManifestoOptions, ContextUpdater, DomainExternalContext, BaseManifestoApp, BaseSubmissionResult, DynamicActionHandle, DynamicBoundAction, DispatchExecutionOutcome, DispatchProjectedDiff, DispatchCanonicalOutcome, ActionObjectBindingArgs, AdmissionBlocker, Blocker, BoundAction, DispatchBlocker, ExplanationBlocker, 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, GetAction, 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
+ /**
14
+ * v3-era intent-centric result types. Their public producers
15
+ * (dispatchAsyncWithReport / the intent-centric base instance) were retired
16
+ * by the v5 activation-first surface; these exports remain only so existing
17
+ * type-level consumers keep compiling.
18
+ *
19
+ * @deprecated Scheduled for removal in the next major release. Use the
20
+ * action-candidate surface (Admission / AdmissionFailure / SubmissionResult)
21
+ * instead.
22
+ */
23
+ export type { DispatchReport, IntentAdmission, IntentAdmissionFailure, } from "./types.js";
13
24
  export { AlreadyActivatedError, CompileError, DisposedError, ManifestoError, ReservedEffectError, SubmissionFailedError, } from "./errors.js";
14
25
  export type { CompileDiagnostic } from "./errors.js";
15
26
  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 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(`
1
+ import{a as _}from"./chunk-A3JV6JTS.js";import{a as m,b as p,d as D,e as T,f as I,i as v,j as A,m as k,s as w}from"./chunk-L7HPZ7ZD.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
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
3
  ${l} | ${s}
4
4
  ${u}${"^".repeat(d)}`}).join(`
5
5
 
6
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};
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=E(t.inputType,t.params[0]??"",e.types);return n?M(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 E(e,t,n,o=[]){if(e.kind==="ref"){if(o.includes(e.name))return null;let a=n[e.name];return a?E(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?E(a[0],t,n,o):null}return e.kind!=="object"?null:e.fields[t]?.type??null}function M(e,t,n=[]){if(e.kind==="ref"){if(n.includes(e.name))return!1;let o=t[e.name];return o?M(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?M(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){B(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 B(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&&B(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 V(e,t,n){if(O in t)throw new h(O);let o=H(e,n?.annotations),a={_laws:N,schema:o.schema,activate(){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}))}};return k(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,V as createManifesto,Je as createSnapshot};
@@ -3,6 +3,17 @@
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, GovernanceRuntimeKernel, GovernanceRuntimeKernelFactory, HostDispatchOptions, LineageRuntimeKernel, LineageRuntimeKernelFactory, RuntimeKernel, RuntimeKernelFactory, SimulateResult, WaitForProposalRuntimeKernel, } from "./compat/internal.js";
6
+ export type { ActivationState, GovernanceRuntimeKernel, GovernanceRuntimeKernelFactory, HostDispatchOptions, LineageRuntimeKernel, LineageRuntimeKernelFactory, RuntimeKernel, RuntimeKernelFactory, WaitForProposalRuntimeKernel, } from "./compat/internal.js";
7
+ export type { SimulateResult as KernelSimulateResult } from "./compat/internal.js";
8
+ import type { SimulateResult as InternalKernelSimulateResult } from "./compat/internal.js";
9
+ import type { ManifestoDomainShape } from "./types.js";
10
+ /**
11
+ * @deprecated Renamed to {@link KernelSimulateResult}: this provider-seam
12
+ * type shares its name with the projected `SimulateResult` on the main
13
+ * entry while having a different (canonical) shape. The alias will be
14
+ * removed in the next major release.
15
+ */
16
+ export type SimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape> = InternalKernelSimulateResult<T>;
7
17
  export { activateComposable, assertComposableNotActivated, attachExtensionKernel, attachRuntimeKernelFactory, createRuntimeKernel, getActivationState, getRuntimeKernelFactory, } from "./compat/internal.js";
8
18
  export { createBaseRuntimeInstance } from "./runtime/base-runtime.js";
19
+ export { mapBlockedAdmission, toBlocker } from "./runtime/admission-failure.js";
package/dist/provider.js CHANGED
@@ -1 +1 @@
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};
1
+ import{a as s}from"./chunk-A3JV6JTS.js";import{j as e,k as t,l as a,m as n,n as o,o as r,q as i,r as l,s as m}from"./chunk-L7HPZ7ZD.js";import"./chunk-TG2UPPZN.js";export{m as activateComposable,l as assertComposableNotActivated,r as attachExtensionKernel,n as attachRuntimeKernelFactory,s as createBaseRuntimeInstance,e as createRuntimeKernel,i as getActivationState,o as getRuntimeKernelFactory,a as mapBlockedAdmission,t as toBlocker};
@@ -0,0 +1,16 @@
1
+ import type { AdmissionFailure, Blocker, DispatchBlocker } from "../types.js";
2
+ /**
3
+ * Shared admission-failure mapping for runtime surfaces.
4
+ *
5
+ * The base, lineage, and governance runtimes expose the same
6
+ * action-candidate admission contract; this module is the single source
7
+ * for narrowing a blocked kernel admission into the public
8
+ * AdmissionFailure shape (previously triplicated across the three
9
+ * runtime files).
10
+ */
11
+ export declare function toBlocker(blocker: DispatchBlocker, code: Blocker["code"]): Blocker;
12
+ export declare function mapBlockedAdmission<Name extends string>(actionName: Name, admission: {
13
+ readonly failure: {
14
+ readonly kind: string;
15
+ };
16
+ }, fallbackMessage?: string): AdmissionFailure<Name>;
@@ -1,4 +1,4 @@
1
- import { type DomainSchema, type Snapshot as CoreSnapshot } from "@manifesto-ai/core";
1
+ import { type ActionAvailabilityEvaluation, type ActionDispatchabilityEvaluation, type DomainSchema, type Snapshot as CoreSnapshot } from "@manifesto-ai/core";
2
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> = {
@@ -7,8 +7,10 @@ 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 evaluateActionAvailabilityFor: (snapshot: CanonicalSnapshot<T["state"]>, name: keyof T["actions"]) => ActionAvailabilityEvaluation;
11
+ readonly evaluateIntentDispatchabilityFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => ActionDispatchabilityEvaluation;
10
12
  readonly projectSnapshotFromCanonical: (snapshot: CoreSnapshot) => ProjectedSnapshot<T>;
11
13
  readonly getSimulateSync: () => RuntimeSimulateSync<T>;
12
14
  };
13
- export declare function createRuntimeAdmission<T extends ManifestoDomainShape>({ schema, ensureIntentId, getAvailableActionsFor, isActionAvailableFor, isIntentDispatchableFor, projectSnapshotFromCanonical, getSimulateSync, }: RuntimeAdmissionOptions<T>): RuntimeAdmission<T>;
15
+ export declare function createRuntimeAdmission<T extends ManifestoDomainShape>({ schema, ensureIntentId, getAvailableActionsFor, isActionAvailableFor, evaluateActionAvailabilityFor, evaluateIntentDispatchabilityFor, projectSnapshotFromCanonical, getSimulateSync, }: RuntimeAdmissionOptions<T>): RuntimeAdmission<T>;
14
16
  export {};
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Runtime kernel contract: the full kernel interface, its facet
3
+ * decomposition, and the decorator-facing kernel aliases (#421).
4
+ *
5
+ * This file is the design home of the seam types. The facet aliases
6
+ * (LineageRuntimeKernel, GovernanceRuntimeKernel,
7
+ * WaitForProposalRuntimeKernel) are the primary dependency surfaces for
8
+ * decorator and provider code; the broad RuntimeKernel aggregate exists
9
+ * for kernel assembly and compatibility, not as the unit new code should
10
+ * depend on. compat/internal re-exports everything here unchanged, so
11
+ * the provider seam stays source-compatible.
12
+ */
13
+ import { type ComputeStatus, type DomainSchema, type JsonValue, type Patch, type Requirement, type Snapshot as CoreSnapshot, type SystemDelta } from "@manifesto-ai/core";
14
+ import type { HostContextProvider, HostResult, ManifestoHost } from "@manifesto-ai/host";
15
+ import type { Context } from "@manifesto-ai/core";
16
+ import type { ActionAnnotation, CanonicalSnapshot, 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";
17
+ import type { SnapshotProjectionPlan } from "../projection/snapshot-projection.js";
18
+ import type { IntentLegalityEvaluation } from "./facets.js";
19
+ import type { ManifestoError } from "../errors.js";
20
+ import type { ExtensionKernel } from "../extensions-types.js";
21
+ import { EXTENSION_KERNEL } from "../compat/runtime-symbols.js";
22
+ export type HostDispatchOptions = NonNullable<Parameters<ManifestoHost["dispatch"]>[1]>;
23
+ export type SimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape> = {
24
+ readonly snapshot: CanonicalSnapshot<T["state"]>;
25
+ readonly patches: readonly Patch[];
26
+ readonly systemDelta: Readonly<SystemDelta>;
27
+ readonly status: ComputeStatus;
28
+ readonly requirements: readonly Requirement[];
29
+ readonly diagnostics?: SimulationDiagnostics;
30
+ };
31
+ export interface RuntimeKernel<T extends ManifestoDomainShape> {
32
+ readonly schema: DomainSchema;
33
+ readonly refs: TypedDomainRefs<T>;
34
+ /** @deprecated Use refs. */
35
+ readonly MEL: TypedMEL<T>;
36
+ readonly createIntent: TypedCreateIntent<T>;
37
+ readonly subscribe: TypedSubscribe<T>;
38
+ readonly on: TypedOn<T>;
39
+ readonly getSnapshot: () => ProjectedSnapshot<T>;
40
+ readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
41
+ readonly getAvailableActionsFor: (snapshot: CanonicalSnapshot<T["state"]>) => readonly (keyof T["actions"])[];
42
+ readonly getAvailableActions: () => readonly (keyof T["actions"])[];
43
+ readonly getIntentBlockersFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => readonly DispatchBlocker[];
44
+ readonly getActionMetadata: TypedGetActionMetadata<T>;
45
+ readonly isActionAvailableFor: (snapshot: CanonicalSnapshot<T["state"]>, name: keyof T["actions"]) => boolean;
46
+ readonly isActionAvailable: (name: keyof T["actions"]) => boolean;
47
+ readonly isIntentDispatchableFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => boolean;
48
+ readonly isIntentDispatchable: TypedIsIntentDispatchable<T>;
49
+ readonly getIntentBlockers: TypedGetIntentBlockers<T>;
50
+ readonly getSchemaGraph: () => SchemaGraph;
51
+ readonly simulateSync: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>, options?: {
52
+ readonly externalContext?: DomainExternalContext<T>;
53
+ readonly context?: Context;
54
+ }) => SimulateResult<T>;
55
+ readonly simulate: TypedSimulate<T>;
56
+ readonly simulateIntent: TypedSimulateIntent<T>;
57
+ readonly dispose: () => void;
58
+ readonly isDisposed: () => boolean;
59
+ readonly getVisibleCoreSnapshot: () => CoreSnapshot;
60
+ readonly setVisibleSnapshot: (snapshot: CoreSnapshot, options?: {
61
+ readonly notify?: boolean;
62
+ }) => ProjectedSnapshot<T>;
63
+ readonly rehydrateSnapshot: (snapshot: CoreSnapshot) => CoreSnapshot;
64
+ readonly restoreVisibleSnapshot: () => void;
65
+ readonly emitEvent: <K extends ManifestoEvent>(event: K, payload: ManifestoEventPayloadMap[K]) => void;
66
+ readonly enqueue: <R>(task: () => Promise<R>) => Promise<R>;
67
+ readonly ensureIntentId: (intent: TypedIntent<T>) => TypedIntent<T>;
68
+ readonly executeHost: (intent: TypedIntent<T>, options?: HostDispatchOptions) => Promise<HostResult>;
69
+ readonly createComputeContext: (intent: TypedIntent<T>, externalContext?: ExternalContext) => Context;
70
+ readonly getExternalContext: () => DomainExternalContext<T>;
71
+ readonly replaceExternalContext: (next: DomainExternalContext<T>) => DomainExternalContext<T>;
72
+ readonly updateExternalContext: (updater: ContextUpdater<DomainExternalContext<T>>) => DomainExternalContext<T>;
73
+ readonly captureExternalContext: (override?: ExternalContext) => DomainExternalContext<T>;
74
+ readonly validateIntentInputFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => ManifestoError | null;
75
+ readonly evaluateIntentLegalityFor: (snapshot: CanonicalSnapshot<T["state"]>, intent: TypedIntent<T>) => IntentLegalityEvaluation<T>;
76
+ readonly deriveIntentAdmission: (snapshot: CanonicalSnapshot<T["state"]>, legality: IntentLegalityEvaluation<T>) => IntentAdmission<T>;
77
+ readonly deriveExecutionOutcome: (beforeSnapshot: CanonicalSnapshot<T["state"]>, afterSnapshot: CanonicalSnapshot<T["state"]>) => DispatchExecutionOutcome<T>;
78
+ readonly classifyExecutionFailure: (error: unknown, stage: "host" | "seal") => ExecutionFailureInfo;
79
+ readonly createExecutionDiagnostics: (result: HostResult) => ExecutionDiagnostics;
80
+ readonly createUnavailableError: (intent: TypedIntent<T>) => ManifestoError;
81
+ readonly createNotDispatchableError: (intent: TypedIntent<T>) => ManifestoError;
82
+ readonly rejectInvalidInput: (intent: TypedIntent<T>, message: string) => never;
83
+ readonly rejectUnavailable: (intent: TypedIntent<T>) => never;
84
+ readonly rejectNotDispatchable: (intent: TypedIntent<T>) => never;
85
+ readonly [EXTENSION_KERNEL]: ExtensionKernel<T>;
86
+ }
87
+ export 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">;
88
+ export type RuntimeLifecycleFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "dispose" | "isDisposed" | "enqueue">;
89
+ export type RuntimeExecutionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "ensureIntentId" | "executeHost" | "createComputeContext" | "captureExternalContext">;
90
+ export type RuntimeSealAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isActionAvailable" | "isActionAvailableFor" | "validateIntentInputFor" | "isIntentDispatchableFor" | "rejectUnavailable" | "rejectInvalidInput" | "rejectNotDispatchable">;
91
+ export type RuntimeReportAdmissionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "evaluateIntentLegalityFor" | "deriveIntentAdmission" | "createUnavailableError" | "createNotDispatchableError">;
92
+ export type RuntimePublicationFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "getVisibleCoreSnapshot" | "setVisibleSnapshot" | "rehydrateSnapshot" | "restoreVisibleSnapshot">;
93
+ export type RuntimeReportingFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "deriveExecutionOutcome" | "classifyExecutionFailure" | "createExecutionDiagnostics">;
94
+ export type RuntimeDispatchEventsFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "emitEvent">;
95
+ export type RuntimeExtensionFacet<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, typeof EXTENSION_KERNEL>;
96
+ export type LineageRuntimeKernel<T extends ManifestoDomainShape> = RuntimePublicReadFacet<T> & RuntimeLifecycleFacet<T> & RuntimeExecutionFacet<T> & RuntimeSealAdmissionFacet<T> & RuntimeReportAdmissionFacet<T> & RuntimePublicationFacet<T> & RuntimeReportingFacet<T> & RuntimeDispatchEventsFacet<T> & RuntimeExtensionFacet<T>;
97
+ export type LineageRuntimeKernelFactory<T extends ManifestoDomainShape> = () => LineageRuntimeKernel<T>;
98
+ 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>;
99
+ export type GovernanceRuntimeKernelFactory<T extends ManifestoDomainShape> = () => GovernanceRuntimeKernel<T>;
100
+ export type WaitForProposalRuntimeKernel<T extends ManifestoDomainShape> = Pick<RuntimeKernel<T>, "isDisposed" | "deriveExecutionOutcome">;
101
+ export type RuntimeKernelFactory<T extends ManifestoDomainShape> = () => RuntimeKernel<T>;
102
+ export type RuntimeKernelOptions<T extends ManifestoDomainShape> = {
103
+ readonly schema: DomainSchema;
104
+ readonly projectionPlan: SnapshotProjectionPlan;
105
+ readonly actionAnnotations: Readonly<Record<string, ActionAnnotation>>;
106
+ readonly host: ManifestoHost;
107
+ readonly hostContextProvider: HostContextProvider;
108
+ readonly MEL: TypedMEL<T>;
109
+ readonly createIntent: TypedCreateIntent<T>;
110
+ readonly initialContext?: Record<string, JsonValue>;
111
+ };
@@ -0,0 +1,7 @@
1
+ import { type JsonValueViolation, type Snapshot as CoreSnapshot } from "@manifesto-ai/core";
2
+ /**
3
+ * Snapshot `input` is transient and current genesis snapshots use
4
+ * `undefined`. Validate it only when a restore payload actually carries a
5
+ * value; persisted domain/system channels must always stay JSON-compatible.
6
+ */
7
+ export declare function findCanonicalSnapshotValueViolation(snapshot: CoreSnapshot): JsonValueViolation | null;
package/dist/types.d.ts CHANGED
@@ -98,12 +98,24 @@ export type ActionInfo<Name extends string = string> = {
98
98
  readonly parameters: readonly ActionParameterInfo[];
99
99
  readonly annotations?: ActionAnnotation;
100
100
  };
101
+ /**
102
+ * Coarse admission-stage blocker riding on {@link AdmissionFailure}.
103
+ *
104
+ * Admission stays cheap: a Blocker says THAT a candidate is blocked and at
105
+ * which layer. To learn WHY in domain terms (the MEL expressions involved),
106
+ * re-query the explanation seam — that richer stage uses
107
+ * {@link ExplanationBlocker} (`DispatchBlocker`) on `IntentExplanation`.
108
+ */
101
109
  export type Blocker = {
102
110
  readonly path: ReadonlyArray<string | number>;
103
111
  readonly code: string;
104
112
  readonly message: string;
105
113
  readonly detail?: Readonly<Record<string, unknown>>;
106
114
  };
115
+ /**
116
+ * Stage-explicit name for {@link Blocker}: the admission-stage vocabulary.
117
+ */
118
+ export type AdmissionBlocker = Blocker;
107
119
  export type AdmissionOk<Name extends string = string> = {
108
120
  readonly ok: true;
109
121
  readonly action: Name;
@@ -290,6 +302,14 @@ export type ActionHandle<T extends ManifestoDomainShape, K extends ActionName<T>
290
302
  submit(...args: ActionArgs<T, K>): Promise<SubmitResultFor<TMode, T, K>>;
291
303
  bind(...args: ActionArgs<T, K>): BoundAction<T, K, TMode>;
292
304
  };
305
+ export type DynamicActionHandle<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
306
+ info(): ActionInfo<ActionName<T>>;
307
+ available(): boolean;
308
+ check(...args: unknown[]): Admission<ActionName<T>>;
309
+ preview(...args: unknown[]): PreviewResult<T, ActionName<T>>;
310
+ submit(...args: unknown[]): Promise<SubmitResultFor<TMode, T, ActionName<T>>>;
311
+ bind(...args: unknown[]): DynamicBoundAction<T, TMode>;
312
+ };
293
313
  export type BoundAction<T extends ManifestoDomainShape, K extends ActionName<T>, TMode extends RuntimeMode> = {
294
314
  readonly action: K;
295
315
  readonly input: ActionInput<T, K>;
@@ -298,9 +318,22 @@ export type BoundAction<T extends ManifestoDomainShape, K extends ActionName<T>,
298
318
  submit(): Promise<SubmitResultFor<TMode, T, K>>;
299
319
  intent(): Intent | null;
300
320
  };
321
+ export type DynamicBoundAction<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
322
+ readonly action: ActionName<T>;
323
+ readonly input: ActionInput<T, ActionName<T>>;
324
+ check(): Admission<ActionName<T>>;
325
+ preview(): PreviewResult<T, ActionName<T>>;
326
+ submit(): Promise<SubmitResultFor<TMode, T, ActionName<T>>>;
327
+ intent(): Intent | null;
328
+ };
301
329
  export type ActionSurface<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
302
330
  readonly [K in ActionName<T>]: ActionHandle<T, K, TMode>;
303
331
  };
332
+ type PreciseActionName<T extends ManifestoDomainShape> = string extends ActionName<T> ? never : ActionName<T>;
333
+ export type GetAction<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
334
+ <K extends PreciseActionName<T>>(name: K): ActionHandle<T, K, TMode>;
335
+ (name: string): DynamicActionHandle<T, TMode> | undefined;
336
+ };
304
337
  export type ActionObjectBindingArgs<T extends ManifestoDomainShape, K extends keyof T["actions"]> = ActionArgs<T, K> extends [unknown, ...unknown[]] ? [params: Record<string, unknown>] : never;
305
338
  export type CreateIntentArgs<T extends ManifestoDomainShape, K extends keyof T["actions"]> = ActionArgs<T, K> | ActionObjectBindingArgs<T, K>;
306
339
  export type Selector<TState, R, TComputed = Record<string, unknown>> = (snapshot: Snapshot<TState, TComputed>) => R;
@@ -477,12 +510,25 @@ export type TypedGetActionMetadata<T extends ManifestoDomainShape> = {
477
510
  (): readonly TypedActionMetadata<T>[];
478
511
  <K extends keyof T["actions"]>(name: K): TypedActionMetadata<T, K>;
479
512
  };
513
+ /**
514
+ * Rich explanation-stage blocker riding on `IntentExplanation`.
515
+ *
516
+ * Carries the MEL expression behind the block. This is the upgrade target
517
+ * when a UI showing "why is this blocked" needs more than the coarse
518
+ * admission-stage {@link Blocker}: re-query the explanation seam to move
519
+ * from one vocabulary to the other.
520
+ */
480
521
  export type DispatchBlocker = {
481
522
  readonly layer: "available" | "dispatchable";
482
523
  readonly expression: ExprNode;
483
524
  readonly evaluatedResult: unknown;
484
525
  readonly description?: string;
485
526
  };
527
+ /**
528
+ * Stage-explicit name for {@link DispatchBlocker}: the explanation-stage
529
+ * vocabulary.
530
+ */
531
+ export type ExplanationBlocker = DispatchBlocker;
486
532
  export type TypedIsIntentDispatchable<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => boolean;
487
533
  export type TypedGetIntentBlockers<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => readonly DispatchBlocker[];
488
534
  export type SubmissionEventBase = {
@@ -537,7 +583,7 @@ export type ManifestoEventPayloadMap = {
537
583
  export type ManifestoEventName = keyof ManifestoEventPayloadMap;
538
584
  export type ManifestoEventPayload<Event extends ManifestoEventName> = ManifestoEventPayloadMap[Event];
539
585
  export type ManifestoEvent = ManifestoEventName;
540
- export type TypedOn<T extends ManifestoDomainShape> = <K extends ManifestoEvent>(event: K, handler: (payload: ManifestoEventPayloadMap[K]) => void) => Unsubscribe;
586
+ export type TypedOn<_T extends ManifestoDomainShape> = <K extends ManifestoEvent>(event: K, handler: (payload: ManifestoEventPayloadMap[K]) => void) => Unsubscribe;
541
587
  export type ObserveSurface<T extends ManifestoDomainShape> = {
542
588
  state<S>(selector: (snapshot: ProjectedSnapshot<T>) => S, listener: (next: S, prev: S) => void): Unsubscribe;
543
589
  event<Event extends ManifestoEventName>(event: Event, listener: (payload: ManifestoEventPayload<Event>) => void): Unsubscribe;
@@ -556,6 +602,7 @@ export type BaseManifestoApp<T extends ManifestoDomainShape, TMode extends Runti
556
602
  readonly observe: ObserveSurface<T>;
557
603
  readonly inspect: InspectSurface<T>;
558
604
  snapshot(): ProjectedSnapshot<T>;
605
+ getAction: GetAction<T, TMode>;
559
606
  context(): DomainExternalContext<T>;
560
607
  injectContext(context: DomainExternalContext<T>): void;
561
608
  updateContext(updater: ContextUpdater<DomainExternalContext<T>>): DomainExternalContext<T>;
@@ -567,6 +614,14 @@ export type GovernanceSettlementSurface<T extends ManifestoDomainShape> = {
567
614
  };
568
615
  type EmptySurface = Record<never, never>;
569
616
  export type ManifestoApp<T extends ManifestoDomainShape, TMode extends RuntimeMode> = BaseManifestoApp<T, TMode> & ([TMode] extends ["governance"] ? GovernanceSettlementSurface<T> : EmptySurface);
617
+ /**
618
+ * v3-era intent-centric instance shape, retired from the public surface by
619
+ * the v5 activation-first design. It is intentionally NOT exported from the
620
+ * package entrypoints; it remains only as the internal compat seam's view.
621
+ *
622
+ * @deprecated Scheduled for removal in the next major release together with
623
+ * the deprecated DispatchReport / IntentAdmission result types.
624
+ */
570
625
  export type ManifestoBaseInstance<T extends ManifestoDomainShape> = {
571
626
  readonly createIntent: TypedCreateIntent<T>;
572
627
  readonly dispatchAsync: TypedDispatchAsync<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifesto-ai/sdk",
3
- "version": "5.0.0",
3
+ "version": "5.1.1",
4
4
  "description": "Manifesto SDK - Activation-first public API for the base runtime",
5
5
  "author": "eggplantiny <eggplantiny@gmail.com>",
6
6
  "license": "MIT",
@@ -47,23 +47,23 @@
47
47
  "dist"
48
48
  ],
49
49
  "dependencies": {
50
- "@manifesto-ai/compiler": "5.0.0",
51
- "@manifesto-ai/host": "5.0.0",
52
- "@manifesto-ai/core": "5.0.0"
50
+ "@manifesto-ai/compiler": "5.0.2",
51
+ "@manifesto-ai/core": "5.1.1",
52
+ "@manifesto-ai/host": "5.0.2"
53
53
  },
54
54
  "devDependencies": {
55
- "typescript": "^5.9.3",
56
- "vite": "^8.0.8",
57
- "vitest": "^4.1.4"
55
+ "typescript": "^6.0.3",
56
+ "vite": "^8.0.16",
57
+ "vitest": "^4.1.9"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "rm -rf dist && tsup && tsc -p tsconfig.build.json --emitDeclarationOnly --declarationMap false --outDir dist",
61
61
  "dev": "tsc --watch",
62
62
  "clean": "rm -rf dist",
63
- "lint": "echo 'lint not configured'",
63
+ "lint": "node ../../scripts/run-biome.mjs check src",
64
64
  "test": "pnpm run test:runtime && pnpm run test:types",
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"
65
+ "test:runtime": "node ../../scripts/run-vitest.mjs run",
66
+ "test:types": "node ../../scripts/run-tsc.mjs -p tsconfig.types.json --noEmit",
67
+ "test:coverage": "node ../../scripts/run-vitest.mjs run --coverage"
68
68
  }
69
69
  }
@@ -1 +0,0 @@
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};
@@ -1 +0,0 @@
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};