@manifesto-ai/sdk 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -11
- package/dist/chunk-DPFMD6LR.js +1 -0
- package/dist/chunk-OW22XF26.js +1 -0
- package/dist/compat/internal.d.ts +5 -97
- package/dist/extensions.js +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +2 -2
- package/dist/provider.d.ts +12 -1
- package/dist/provider.js +1 -1
- package/dist/runtime/admission-failure.d.ts +16 -0
- package/dist/runtime/admission.d.ts +4 -2
- package/dist/runtime/kernel-contract.d.ts +111 -0
- package/dist/types.d.ts +56 -1
- package/package.json +8 -8
- package/dist/chunk-CEARNDBI.js +0 -1
- package/dist/chunk-MIE55XWV.js +0 -1
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
# @manifesto-ai/sdk
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Base runtime entry point for Manifesto applications.
|
|
4
4
|
|
|
5
|
-
`@manifesto-ai/sdk` is the
|
|
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
|
-
|
|
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
|
|
17
|
-
-
|
|
18
|
-
-
|
|
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<
|
|
32
|
+
const manifesto = createManifesto<TodoDomain>(TodoMel, {});
|
|
26
33
|
const app = manifesto.activate();
|
|
27
34
|
|
|
28
|
-
await app.action.
|
|
29
|
-
console.log(app.snapshot().state.
|
|
35
|
+
await app.action.addTodo.submit("Review docs");
|
|
36
|
+
console.log(app.snapshot().state.todos);
|
|
30
37
|
```
|
|
31
38
|
|
|
32
|
-
|
|
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,
|
|
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{a as C,e as q}from"./chunk-TG2UPPZN.js";import{evaluateComputed as ft,evaluateActionAvailability as mt,evaluateAvailableActions as ht,evaluateIntentDispatchability as yt,isErr as St}from"@manifesto-ai/core";import{extractSchemaGraph as bt}from"@manifesto-ai/compiler";function gt(e){return{visibleComputedKeys:Object.keys(e.computed.fields)}}function J(e,t){return{state:$e(e.state),computed:qe(e.computed,t),system:{status:e.system.status,lastError:e.system.lastError},meta:{schemaHash:e.meta.schemaHash}}}function jt(e,t){return J(e,t)}function I(e){return me(structuredClone(e))}function fe(e,t){return Je(e,t)}function $e(e){return structuredClone(e)}function qe(e,t){let n={};for(let o of t.visibleComputedKeys)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return structuredClone(n)}function Je(e,t){return D(e,t,new WeakMap)}function D(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.prototype.hasOwnProperty.call(o,c),x=Object.prototype.hasOwnProperty.call(a,c);if(h!==x||h&&!D(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((x,T)=>x===h[T])}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((x,T)=>x===h[T])}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(([x,T],b)=>{let g=h[b];if(!g)return!1;let[A,k]=g;return D(x,A,n)&&D(T,k,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((x,T)=>D(x,h[T],n))}let l=ue(o),u=ue(a);if(l.length!==u.length)return!1;for(let c=0;c<l.length;c+=1){let h=l[c],x=u[c];if(h!==x)return!1;let T=o[h],b=a[x];if(!D(T,b,n))return!1}return!0}function ue(e){return Object.keys(e).filter(t=>e[t]!==void 0).sort()}function me(e,t=new WeakSet){if(e==null||typeof e!="object")return e;if(de(e))return he(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(de(a)){We(n,o,a);continue}me(a,t)}return Object.freeze(e)}function de(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)}function he(e){return structuredClone(e)}function We(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 he(n)}})}var W=Symbol("manifesto-sdk.action-param-names"),Xe=Symbol("manifesto-sdk.action-single-param-object-value"),F=Symbol("manifesto-sdk.runtime-kernel-factory"),z=Symbol("manifesto-sdk.activation-state"),w=Symbol("manifesto-sdk.extension-kernel");var Ye=/^(state|computed|action):.+$/;function X(e){let t=new Set(e.nodes.map(r=>r.id)),n=new Map,o=new Map,a=(r,l,u)=>{let c=r.get(l);if(c){c.add(u);return}r.set(l,new Set([u]))};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(u=>r.has(u.id))),edges:Object.freeze(e.edges.filter(u=>r.has(u.from)&&r.has(u.to)))});return X(l)},i=(r,l)=>{let u=Qe(r,t),c=[u],h=new Set([u]),x=l==="incoming"?o:n;for(;c.length>0;){let T=c.shift();if(T)for(let b of x.get(T)??[])h.has(b)||(h.add(b),c.push(b))}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 Qe(e,t){if(typeof e=="string"){if(!Ye.test(e))throw new C("SCHEMA_ERROR",'SchemaGraph node id must use "state:<name>", "computed:<name>", or "action:<name>"');if(!t.has(e))throw new C("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 C("SCHEMA_ERROR","Unsupported SchemaGraph ref lookup target")}if(!t.has(n))throw new C("SCHEMA_ERROR",`SchemaGraph node "${n}" is not part of the projected graph`);return n}import{validateIntentInput as tt}from"@manifesto-ai/core";function Se({getAvailableActionsFor:e,projectSnapshotFromCanonical:t}){function n(i,r){let l=e(i),u=e(r),c=Object.freeze(u.filter(x=>!l.includes(x))),h=Object.freeze(l.filter(x=>!u.includes(x)));return Object.freeze({before:l,after:u,unlocked:c,locked:h})}function o(i,r){let l=I(i),u=I(r),c=t(l),h=t(u);return Object.freeze({projected:Object.freeze({beforeSnapshot:c,afterSnapshot:h,changedPaths:B(c,h),availability:n(l,u)}),canonical:Object.freeze({beforeCanonicalSnapshot:l,afterCanonicalSnapshot:u,pendingRequirements:u.system.pendingRequirements,status:u.system.status})})}function a(i,r){let l=et(i),u=l;return Object.freeze({message:l.message,...typeof u.code=="string"?{code:u.code}:{},...typeof l.name=="string"?{name:l.name}:{},stage:r})}function y(i){return Object.freeze({hostTraces:I(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=Ze(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 u=i,c=r,h=o.get(u);if(h?.has(c))return;if(h?h.add(c):o.set(u,new WeakSet([c])),Array.isArray(i)||Array.isArray(r)){if(!Array.isArray(i)||!Array.isArray(r)){a(l,"changed");return}let T=Math.max(i.length,r.length);for(let b=0;b<T;b+=1){let g=Object.prototype.hasOwnProperty.call(i,b),A=Object.prototype.hasOwnProperty.call(r,b),k=[...l,b];if(g!==A){a(k,g?"unset":"set");continue}!g&&!A||y(i[b],r[b],k)}return}if(!ye(i)||!ye(r)){a(l,"changed");return}let x=new Set([...Object.keys(i),...Object.keys(r)]);for(let T of[...x].sort()){let b=Object.prototype.hasOwnProperty.call(i,T),g=Object.prototype.hasOwnProperty.call(r,T),A=[...l,T];if(b!==g){a(A,b?"unset":"set");continue}y(i[T],r[T],A)}};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 ye(e){return Object.prototype.toString.call(e)==="[object Object]"}function Ze(e){return e.map(t=>typeof t=="number"?`[${t}]`:t).join(".")}function et(e){return e instanceof Error?e:new Error(String(e))}function be({schema:e,ensureIntentId:t,getAvailableActionsFor:n,isActionAvailableFor:o,evaluateActionAvailabilityFor:a,evaluateIntentDispatchabilityFor:y,projectSnapshotFromCanonical:i,getSimulateSync:r}){function l(S,m,p){return Object.freeze({layer:S,expression:m,evaluatedResult:!1,...p!==void 0?{description:p}:{}})}function u(S,m){let p=m.type,d=e.actions[p];if(!d)return Object.freeze([]);let R=a(S,p);if(R.kind==="error")return Object.freeze(d.available?[l("available",d.available,R.message)]:[]);if(!R.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 C("ACTION_UNAVAILABLE",`Action "${S.type}" is unavailable against the current visible snapshot`)}function h(S){return new C("INTENT_NOT_DISPATCHABLE",`Action "${S.type}" is available, but the bound intent is not dispatchable against the current visible snapshot`)}function x(S){return new C("INVALID_INPUT",S)}function T(S,m){let p=tt(e,m);return p?x(p):null}function b(S,m){let p=t(m),d=p.type;if(!o(S,d))return{kind:"unavailable",intent:p,actionName:d};let R=T(S,p);if(R)return{kind:"invalid-input",intent:p,actionName:d,error:R};let E=u(S,p);return E.length>0?{kind:"not-dispatchable",intent:p,actionName:d,blockers:E}:{kind:"admitted",intent:p,actionName:d}}function g(S,m){return m.kind==="unavailable"?Object.freeze({kind:"blocked",actionName:m.actionName,failure:{kind:"unavailable",blockers:u(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 A(S,m){let p=b(S,m);if(p.kind==="unavailable")return Object.freeze({kind:"blocked",actionName:p.actionName,available:!1,dispatchable:!1,blockers:u(S,p.intent)});if(p.kind==="invalid-input")throw p.error;if(p.kind==="not-dispatchable")return Object.freeze({kind:"blocked",actionName:p.actionName,available:!0,dispatchable:!1,blockers:p.blockers});let d=r()(S,p.intent),R=i(S),E=i(d.snapshot);return Object.freeze({kind:"admitted",actionName:p.actionName,available:!0,dispatchable:!0,status:d.status,requirements:d.requirements,canonicalSnapshot:d.snapshot,snapshot:E,newAvailableActions:n(d.snapshot),changedPaths:B(R,E)})}function k(S,m){throw m}function P(S){return k(S,c(S))}function M(S,m){return k(S,x(m))}function _(S){return k(S,h(S))}return Object.freeze({getIntentBlockersFor:u,validateIntentInputFor:T,evaluateIntentLegalityFor:b,deriveIntentAdmission:g,explainIntentFor:A,createUnavailableError:c,createNotDispatchableError:h,rejectInvalidInput:M,rejectUnavailable:P,rejectNotDispatchable:_})}function Te({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 nt,applyNamespaceDeltas as xe,applySystemDelta as ot,computeSync as at}from"@manifesto-ai/core";import{getHostState as rt}from"@manifesto-ai/host/tooling";function Ce(e,t){return{...e,timestamp:t,children:e.children.map(n=>Ce(n,t))}}function it(e){let t={};function n(o){t[o.id]=o,o.children.forEach(n)}return n(e),t}function st(e,t){let n=Ce(e.root,t);return{...e,duration:0,root:n,nodes:it(n)}}function Ae({schema:e,hostContextProvider:t,evaluateIntentLegalityFor:n}){function o(r,l){let c=rt(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 C("ACTION_UNAVAILABLE",`Action "${r.type}" is unavailable against the provided canonical snapshot`)}function y(r){return new C("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,u)=>{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,x=u?.context??t.createFrozenContext(h.intentId,u?.externalContext),T=o(structuredClone(r),h),b=at(e,T,h,x),g=nt(e,T,b.patches),A=xe(g,b.namespaceDelta??[]),k=ot(A,b.systemDelta);return Object.freeze({snapshot:I(k),patches:I(b.patches),systemDelta:I(b.systemDelta),status:b.status,requirements:I(b.systemDelta.addRequirements??[]),diagnostics:Object.freeze({trace:I(st(b.trace,r.meta.timestamp))})})}})}var ct=new Set(["state","computed","system","input","meta","namespaces"]),lt=["state","system","meta"];function pt(e){if(e===null||typeof e!="object"||Array.isArray(e))throw new C("INVALID_SNAPSHOT_SHAPE","Visible snapshot must be a canonical snapshot object");let t=e,n=Object.keys(t).filter(o=>!ct.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 C("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 lt){let a=t[o];if(a===null||typeof a!="object"||Array.isArray(a))throw new C("INVALID_SNAPSHOT_SHAPE",`Visible snapshot is missing the required "${o}" object`)}}function Ee({host:e,initialCanonicalSnapshot:t,projectSnapshotFromCanonical:n}){let o=structuredClone(t),a=n(o),y=I(o),i=Promise.resolve(),r=!1,l=new Set,u=new Map;function c(m,p){if(r)return()=>{};let d,R=!1;try{d=m(a),R=!0}catch{d=void 0,R=!1}let E={selector:m,listener:p,lastValue:d,initialized:R};return l.add(E),()=>{l.delete(E)}}function h(m,p){if(r)return()=>{};let d=u.get(m);return d||(d=new Set,u.set(m,d)),d.add(p),()=>{d?.delete(p)}}function x(){return a}function T(){return y}function b(){return structuredClone(o)}function g(m,p){pt(m),o=structuredClone(m),e.reset(structuredClone(o)),y=I(o);let d=n(o),R=!fe(d,a);return R&&(a=d),p?.notify!==!1&&R&&S(a),a}function A(){e.reset(structuredClone(o))}function k(m,p){let d=u.get(m);if(d)for(let R of d)try{R(p)}catch{}}function P(m){let p=i.catch(()=>{}).then(m);return i=p.then(()=>{},()=>{}),p}function M(){r||(r=!0,l.clear(),u.clear())}function _(){return r}function S(m){for(let p of l){let d;try{d=p.selector(m)}catch{continue}if(!(p.initialized&&Object.is(p.lastValue,d))){p.lastValue=d,p.initialized=!0;try{p.listener(d)}catch{}}}}return{subscribe:c,on:h,getSnapshot:x,getCanonicalSnapshot:T,getVisibleCoreSnapshot:b,setVisibleSnapshot:g,restoreVisibleSnapshot:A,emitEvent:k,enqueue:P,dispose:M,isDisposed:_}}function Re(){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 ut}from"@manifesto-ai/core";function V(e,t,n){let o=dt(t===void 0?{}:t,n),a=ut(e,o);if(!a.valid){let y=a.errors.map(i=>i.path?`${i.path}: ${i.message}`:i.message).join("; ");throw new C("INVALID_CONTEXT",`Invalid context for ${n}: ${y}`)}return o}function Y(e,t,n,o){return n===void 0?t:V(e,n,o)}function dt(e,t){return Ie(e)||O(t,[],"Context must be a plain JSON object"),Object.freeze(je(e,t,[],new WeakSet))}function ge(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:O(t,n,"Context numbers must be finite");case"undefined":return O(t,n,"Context must not contain undefined");case"function":return O(t,n,"Context must not contain functions");case"symbol":return O(t,n,"Context must not contain symbols");case"bigint":return O(t,n,"Context must not contain bigint values");case"object":break}if(Array.isArray(e)){o.has(e)&&O(t,n,"Context must not contain cycles"),o.add(e),ke(e,t,n),Oe(e,t,n);let y=[];for(let i=0;i<e.length;i+=1)Object.prototype.hasOwnProperty.call(e,i)||O(t,[...n,i],"Context arrays must not contain holes"),y.push(ge(e[i],t,[...n,i],o));return o.delete(e),Object.freeze(y)}Ie(e)||O(t,n,"Context objects must be plain JSON objects"),o.has(e)&&O(t,n,"Context must not contain cycles"),o.add(e);let a=je(e,t,n,o);return o.delete(e),Object.freeze(a)}function je(e,t,n,o){ke(e,t,n),Oe(e,t,n);let a=Object.create(null);for(let[y,i]of Object.entries(e))a[y]=ge(i,t,[...n,y],o);return a}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 ke(e,t,n){for(let[o,a]of Object.entries(Object.getOwnPropertyDescriptors(e)))(a.get||a.set)&&O(t,[...n,o],"Context must not contain getters or setters")}function Oe(e,t,n){Object.getOwnPropertySymbols(e).length>0&&O(t,n,"Context must not contain symbol keys")}function O(e,t,n){let o=t.length===0?"$context":`$context.${t.map(String).join(".")}`;throw new C("INVALID_CONTEXT",`Invalid context for ${e} at ${o}: ${n}`)}var Tt=new Set(["then","constructor","prototype","__proto__"]);function xt(e){if(e.params)return e.params;let t=e.input;return!t||t.type!=="object"||!t.fields?[]:Object.keys(t.fields)}function Ct(e){return typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function"}function At({schema:e,projectionPlan:t,actionAnnotations:n,host:o,hostContextProvider:a,MEL:y,createIntent:i,initialContext:r}){let l=y,u=o.getSnapshot();if(!u)throw new C("SCHEMA_ERROR","Host failed to initialize its genesis snapshot");function c(s){return I(J(s,t))}function h(s){let f=ft(e,s);if(St(f))throw new C("SNAPSHOT_REHYDRATION_FAILED",`Failed to rehydrate restored snapshot computed values: ${f.error.message}`,{cause:f.error});return{...s,computed:f.value}}let x=Ee({host:o,initialCanonicalSnapshot:u,projectSnapshotFromCanonical:c}),{subscribe:T,on:b,getSnapshot:g,getCanonicalSnapshot:A,getVisibleCoreSnapshot:k,setVisibleSnapshot:P,restoreVisibleSnapshot:M,emitEvent:_,enqueue:S,dispose:m,isDisposed:p}=x,d=X(bt(e)),R=Object.keys(e.actions);Et(R);let E=V(e,r,"createManifesto"),Z=Object.freeze(Object.fromEntries(R.map(s=>{let f=e.actions[s],L=l.actions[s]?.[W],le=Object.freeze(Array.isArray(L)?[...L]:xt(f)),pe=L===null?1:le.length,Ue=f.input?.required===!1?0:pe;return[s,Object.freeze({name:s,params:le,publicArity:pe,requiredArity:Ue,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})]}))),Ne=Object.freeze(R.map(s=>Z[s]));function ee(s,f){return mt(e,s,String(f))}function te(s,f){return yt(e,s,f)}function N(s){let f=ht(e,s);return f.kind==="error"?Object.freeze([]):Object.freeze([...f.actions])}let K=Se({getAvailableActionsFor:N,projectSnapshotFromCanonical:c});function De(){return N(A())}let Pe=(s=>s!==void 0?Z[String(s)]:Ne);function G(s,f){let j=ee(s,f);return j.kind==="ok"&&j.available}function Me(s){return G(A(),s)}function H(s,f){let j=te(s,f);return j.kind==="ok"&&j.dispatchable}let _e=((s,...f)=>H(A(),i(s,...f)));function ne(s){return s.intentId&&s.intentId.length>0?s:{...s,intentId:Re()}}async function Le(s,f){return o.dispatch(s,f)}function ze(){return E}function Be(s){return E=V(e,s,"injectContext"),E}function Ve(s){let f=s(E);if(Ct(f))throw new C("INVALID_CONTEXT","updateContext() updater must return a synchronous JSON context value");return E=V(e,f,"updateContext"),E}function oe(s){return Y(e,E,s,"transition")}function ae(s,f){let j=f===void 0?E:Y(e,E,f,"transition");return a.createFrozenContext(s.intentId,j)}let U=null,v=be({schema:e,ensureIntentId:ne,getAvailableActionsFor:N,isActionAvailableFor:G,isIntentDispatchableFor:H,evaluateActionAvailabilityFor:ee,evaluateIntentDispatchabilityFor:te,projectSnapshotFromCanonical:c,getSimulateSync:()=>{if(!U)throw new C("SCHEMA_ERROR","Runtime simulation surface is not initialized");return U}}),re=Ae({schema:e,hostContextProvider:a,evaluateIntentLegalityFor:v.evaluateIntentLegalityFor});U=re.simulateSync;let ie=Te({setVisibleSnapshot:P,restoreVisibleSnapshot:M,getCanonicalSnapshot:A}),se=v.getIntentBlockersFor,Ge=((s,...f)=>se(A(),i(s,...f))),$=(s,f,j)=>{let L=j?.context??ae(f,j?.externalContext??oe());return re.simulateSync(s,f,{context:L})};function He(s){let f=c(s.snapshot);return Object.freeze({snapshot:f,changedPaths:B(g(),f),newAvailableActions:N(s.snapshot),requirements:s.requirements,status:s.status,diagnostics:s.diagnostics})}let ce=(s=>He($(A(),s))),Fe=((s,...f)=>ce(i(s,...f))),Ke=Object.freeze({refs:l,MEL:y,schema:e,createIntent:i,getCanonicalSnapshot:A,projectSnapshot:s=>c(s),simulateSync:(s,f)=>{let j=$(s,f);return Object.freeze({snapshot:j.snapshot,patches:j.patches,requirements:j.requirements,status:j.status,diagnostics:j.diagnostics})},getAvailableActionsFor:N,isActionAvailableFor:G,isIntentDispatchableFor:H,explainIntentFor:v.explainIntentFor});return{schema:e,refs:l,MEL:y,createIntent:i,subscribe:T,on:b,getSnapshot:g,getAvailableActionsFor:N,getAvailableActions:De,getIntentBlockersFor:se,getActionMetadata:Pe,isActionAvailableFor:G,isActionAvailable:Me,isIntentDispatchableFor:H,isIntentDispatchable:_e,getIntentBlockers:Ge,getSchemaGraph(){return d},simulateSync:$,simulate:Fe,simulateIntent:ce,dispose:m,isDisposed:p,getCanonicalSnapshot:A,getVisibleCoreSnapshot:k,rehydrateSnapshot:h,setVisibleSnapshot:ie.replaceVisibleSnapshot,restoreVisibleSnapshot:ie.restoreVisibleSnapshot,emitEvent:_,enqueue:S,ensureIntentId:ne,executeHost:Le,createComputeContext:ae,getExternalContext:ze,replaceExternalContext:Be,updateExternalContext:Ve,captureExternalContext:oe,validateIntentInputFor:v.validateIntentInputFor,evaluateIntentLegalityFor:v.evaluateIntentLegalityFor,deriveIntentAdmission:v.deriveIntentAdmission,deriveExecutionOutcome:K.deriveExecutionOutcome,classifyExecutionFailure:K.classifyExecutionFailure,createExecutionDiagnostics:K.createExecutionDiagnostics,createUnavailableError:v.createUnavailableError,createNotDispatchableError:v.createNotDispatchableError,rejectInvalidInput:v.rejectInvalidInput,rejectUnavailable:v.rejectUnavailable,rejectNotDispatchable:v.rejectNotDispatchable,[w]:Ke}}function Et(e){let t=e.filter(n=>Tt.has(n));if(t.length!==0)throw new C("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 Q(e,t){return Object.freeze({path:Object.freeze([]),code:t,message:e.description??t,detail:Object.freeze({layer:e.layer,expression:e.expression})})}function Rt(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=>Q(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=>Q(a,"ACTION_UNAVAILABLE"))})}function hn(e,t,n){Object.defineProperty(e,F,{enumerable:!1,configurable:!1,writable:!1,value:t});let o=n??ve(e)??{activated:!1};return ve(e)||Object.defineProperty(e,z,{enumerable:!1,configurable:!1,writable:!1,value:o}),e}function yn(e){let n=e[F];if(typeof n!="function")throw new C("SCHEMA_ERROR","ComposableManifesto is missing its runtime kernel factory");return n}function Sn(e,t){return Object.defineProperty(e,w,{enumerable:!1,configurable:!1,writable:!1,value:t[w]}),e}function bn(e){let n=e[w];if(!n)throw new C("SCHEMA_ERROR","Activated runtime is missing its extension kernel");return n}function we(e){let n=e[z];if(!n)throw new C("SCHEMA_ERROR","ComposableManifesto is missing its activation state");return n}function Tn(e){if(we(e).activated)throw new q}function xn(e){let t=we(e);if(t.activated)throw new q;t.activated=!0}function ve(e){return e[z]??null}export{W as a,Xe as b,w as c,gt as d,jt as e,I as f,B as g,Te as h,Re as i,At as j,Q as k,Rt as l,hn as m,yn as n,Sn as o,bn as p,we as q,Tn as r,xn as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as G,g as X,h as J,l as j,o as Q}from"./chunk-DPFMD6LR.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};
|
|
@@ -1,106 +1,13 @@
|
|
|
1
|
-
import
|
|
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
|
|
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
|
|
11
|
-
|
|
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";
|
package/dist/extensions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{f as m,
|
|
1
|
+
import{f as m,p as c}from"./chunk-DPFMD6LR.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,
|
|
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
|
|
1
|
+
import{a as _}from"./chunk-OW22XF26.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-DPFMD6LR.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=
|
|
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};
|
package/dist/provider.d.ts
CHANGED
|
@@ -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,
|
|
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
|
|
1
|
+
import{a as s}from"./chunk-OW22XF26.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-DPFMD6LR.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,
|
|
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
|
+
};
|
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<
|
|
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.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Manifesto SDK - Activation-first public API for the base runtime",
|
|
5
5
|
"author": "eggplantiny <eggplantiny@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"dist"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@manifesto-ai/compiler": "5.0.
|
|
51
|
-
"@manifesto-ai/host": "5.0.
|
|
52
|
-
"@manifesto-ai/core": "5.
|
|
50
|
+
"@manifesto-ai/compiler": "5.0.1",
|
|
51
|
+
"@manifesto-ai/host": "5.0.1",
|
|
52
|
+
"@manifesto-ai/core": "5.1.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"typescript": "^5.9.3",
|
|
@@ -60,10 +60,10 @@
|
|
|
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": "
|
|
63
|
+
"lint": "node ../../node_modules/@biomejs/biome/bin/biome check src",
|
|
64
64
|
"test": "pnpm run test:runtime && pnpm run test:types",
|
|
65
|
-
"test:runtime": "node ../../
|
|
66
|
-
"test:types": "node ../../
|
|
67
|
-
"test:coverage": "node ../../
|
|
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
|
}
|
package/dist/chunk-CEARNDBI.js
DELETED
|
@@ -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};
|
package/dist/chunk-MIE55XWV.js
DELETED
|
@@ -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};
|