@manifesto-ai/compiler 3.9.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/analyzer/expr-type-surface.d.ts +1 -0
- package/dist/analyzer/validator.d.ts +7 -4
- package/dist/api/compile-mel-patch-collector.d.ts +5 -6
- package/dist/api/compile-mel.d.ts +4 -4
- package/dist/api/index.d.ts +2 -2
- package/dist/{chunk-PGOH34S3.js → chunk-A356Y7I6.js} +1 -1
- package/dist/{chunk-5MK25QWV.js → chunk-HOS3TLHW.js} +1 -1
- package/dist/chunk-JYNK3VUK.js +23 -0
- package/dist/esbuild.js +1 -1
- package/dist/evaluation/context.d.ts +32 -6
- package/dist/generator/ir.d.ts +25 -3
- package/dist/generator/lowering.d.ts +7 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +18 -18
- package/dist/lowering/context.d.ts +7 -9
- package/dist/lowering/errors.d.ts +2 -2
- package/dist/lowering/lower-runtime-patch.d.ts +1 -1
- package/dist/node-loader.js +1 -1
- package/dist/parser/ast.d.ts +21 -2
- package/dist/parser/parser.d.ts +3 -0
- package/dist/rollup.js +1 -1
- package/dist/rspack.js +1 -1
- package/dist/unplugin.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-53553ZHJ.js +0 -27
package/dist/generator/ir.d.ts
CHANGED
|
@@ -5,16 +5,27 @@
|
|
|
5
5
|
import type { Diagnostic } from "../diagnostics/types.js";
|
|
6
6
|
import type { ProgramNode } from "../parser/ast.js";
|
|
7
7
|
import type { MelExprNode } from "../lowering/lower-expr.js";
|
|
8
|
-
import { type ExprNode as RuntimeExprNode, type FlowNode as RuntimeFlowNode
|
|
8
|
+
import { type ExprNode as RuntimeExprNode, type FlowNode as RuntimeFlowNode } from "@manifesto-ai/core";
|
|
9
9
|
/**
|
|
10
10
|
* Core ExprNode types (simplified, matching core/schema/expr.ts)
|
|
11
11
|
*/
|
|
12
12
|
export type CoreExprNode = RuntimeExprNode;
|
|
13
13
|
export type CompilerExprNode = MelExprNode;
|
|
14
14
|
/**
|
|
15
|
-
* Core FlowNode
|
|
15
|
+
* Core FlowNode type (kept attached to @manifesto-ai/core to avoid schema drift).
|
|
16
16
|
*/
|
|
17
17
|
export type CoreFlowNode = RuntimeFlowNode;
|
|
18
|
+
type CompilerFlowPatchSegment = {
|
|
19
|
+
kind: "prop";
|
|
20
|
+
name: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "index";
|
|
23
|
+
index: number;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "expr";
|
|
26
|
+
expr: CompilerExprNode;
|
|
27
|
+
};
|
|
28
|
+
type CompilerFlowPatchPath = CompilerFlowPatchSegment[];
|
|
18
29
|
export type CompilerFlowNode = {
|
|
19
30
|
kind: "seq";
|
|
20
31
|
steps: CompilerFlowNode[];
|
|
@@ -26,8 +37,12 @@ export type CompilerFlowNode = {
|
|
|
26
37
|
} | {
|
|
27
38
|
kind: "patch";
|
|
28
39
|
op: "set" | "unset" | "merge";
|
|
29
|
-
path:
|
|
40
|
+
path: CompilerFlowPatchPath;
|
|
30
41
|
value?: CompilerExprNode;
|
|
42
|
+
} | {
|
|
43
|
+
kind: "causalGuard";
|
|
44
|
+
guardId: string;
|
|
45
|
+
body: CompilerFlowNode;
|
|
31
46
|
} | {
|
|
32
47
|
kind: "effect";
|
|
33
48
|
type: string;
|
|
@@ -67,6 +82,10 @@ export interface StateSpec {
|
|
|
67
82
|
fields: Record<string, FieldSpec>;
|
|
68
83
|
fieldTypes?: Record<string, TypeDefinition>;
|
|
69
84
|
}
|
|
85
|
+
export interface ContextSpec {
|
|
86
|
+
fields: Record<string, FieldSpec>;
|
|
87
|
+
fieldTypes?: Record<string, TypeDefinition>;
|
|
88
|
+
}
|
|
70
89
|
/**
|
|
71
90
|
* Computed field specification
|
|
72
91
|
*/
|
|
@@ -153,6 +172,7 @@ export interface DomainSchema {
|
|
|
153
172
|
/** v0.3.3: Named type declarations */
|
|
154
173
|
types: Record<string, TypeSpec>;
|
|
155
174
|
state: StateSpec;
|
|
175
|
+
context?: ContextSpec;
|
|
156
176
|
computed: ComputedSpec;
|
|
157
177
|
actions: Record<string, ActionSpec>;
|
|
158
178
|
meta?: {
|
|
@@ -167,6 +187,7 @@ export interface CanonicalDomainSchema {
|
|
|
167
187
|
hash: string;
|
|
168
188
|
types: Record<string, TypeSpec>;
|
|
169
189
|
state: StateSpec;
|
|
190
|
+
context?: ContextSpec;
|
|
170
191
|
computed: {
|
|
171
192
|
fields: Record<string, CompilerComputedFieldSpec>;
|
|
172
193
|
};
|
|
@@ -190,3 +211,4 @@ export declare function generateCanonical(program: ProgramNode): GenerateCanonic
|
|
|
190
211
|
* Generate runtime-ready DomainSchema from MEL AST.
|
|
191
212
|
*/
|
|
192
213
|
export declare function generate(program: ProgramNode): GenerateResult;
|
|
214
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* System Value Lowering
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Retired System Value Lowering Compatibility Hook
|
|
3
|
+
*
|
|
4
|
+
* v5 keeps Core independent from MEL-owned storage. The previous lowering
|
|
5
|
+
* strategy used MEL namespace slots as runtime bookkeeping, which made Core
|
|
6
|
+
* and Host paths depend on MEL-specific shape. Current v5 MEL rejects
|
|
7
|
+
* `$system.*` and `$meta.*`; this compatibility hook remains a no-op for
|
|
8
|
+
* older callers that still pass the option.
|
|
5
9
|
*/
|
|
6
10
|
import type { DomainSchema } from "./ir.js";
|
|
7
|
-
/**
|
|
8
|
-
* Apply system value lowering to a domain schema
|
|
9
|
-
*/
|
|
10
11
|
export declare function lowerSystemValues(schema: DomainSchema): DomainSchema;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ export * from "./analyzer/index.js";
|
|
|
10
10
|
export * from "./diagnostics/index.js";
|
|
11
11
|
export * from "./generator/index.js";
|
|
12
12
|
export { renderTypeExpr, renderTypeField, renderValue, renderExprNode, renderPatchOp, extractTypeName, renderFragment, renderFragments, renderFragmentsByKind, renderAsDomain, type TypeExpr, type TypeField, type ExprNode as RendererExprNode, type PatchOp, type AddTypeOp, type AddFieldOp, type SetFieldTypeOp, type SetDefaultValueOp, type AddConstraintOp, type AddComputedOp, type AddActionAvailableOp, type RenderOptions, type PatchFragment, type FragmentRenderOptions, } from "./renderer/index.js";
|
|
13
|
-
export
|
|
14
|
-
|
|
13
|
+
export type { AllowedSysPrefix, ExprLoweringContext, PatchLoweringContext, LoweringErrorCode, MelPrimitive, MelPathSegment, MelPathNode, MelSystemPath, MelObjField, MelExprNode, MelTypeExpr, MelTypeField, MelPatchOp, MelPatchFragment, LoweredTypeExpr, LoweredTypeField, LoweredPatchOp, SchemaConditionalPatchOp,
|
|
14
|
+
/** @deprecated Use SchemaConditionalPatchOp */
|
|
15
|
+
ConditionalPatchOp, } from "./lowering/index.js";
|
|
16
|
+
export { DEFAULT_SCHEMA_CONTEXT, DEFAULT_ACTION_CONTEXT, DEFAULT_DISPATCHABLE_CONTEXT, EFFECT_ARGS_CONTEXT, DEFAULT_PATCH_CONTEXT, LoweringError, invalidKindForContext, unknownCallFn, invalidSysPath, unsupportedBase, invalidShape, unknownNodeKind, lowerExprNode, lowerPatchFragments, } from "./lowering/index.js";
|
|
15
17
|
export * from "./api/index.js";
|
|
16
18
|
export * from "./annotations.js";
|
|
17
19
|
export * from "./schema-graph.js";
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import{$ as
|
|
2
|
-
`)[
|
|
3
|
-
${
|
|
4
|
-
${
|
|
1
|
+
import{$ as j,A as ze,B as He,C as Ke,D as x,E as Xe,F as Ye,G as R,H as W,I as z,J as H,K,L as X,M as Y,N as J,O as Q,P as Z,Q as ee,R as te,S as ne,T as re,U as ie,V as Je,W as w,X as D,Y as P,Z as Qe,_ as v,a as Ae,aa as Ze,b as Oe,ba as et,c as Te,ca as tt,d as be,e as Fe,f as Ce,g as Se,h as _e,i as Re,j as we,k as De,l as T,m as Pe,n as ve,o as je,p as Ie,q as Me,r as Le,s as Ue,t as Ve,u as qe,v as b,w as Ge,x as Be,y as _,z as We}from"./chunk-JYNK3VUK.js";var I={E001:{code:"E001",message:"$runtime.* and $context.* can be used only in bound action flow expressions",category:"semantic"},E002:{code:"E002",message:"Dollar namespace values cannot be used in state initializers",category:"semantic"},E003:{code:"E003",message:"Invalid or retired dollar namespace reference",category:"semantic"},E004:{code:"E004",message:"Identifier starts with reserved prefix '__sys__'",category:"syntax"},E005:{code:"E005",message:"available expression must be pure over schema and snapshot only",category:"semantic"},E006:{code:"E006",message:"fail must be inside a guard (when, once, or onceIntent)",category:"semantic"},E007:{code:"E007",message:"stop must be inside a guard (when, once, or onceIntent)",category:"semantic"},E008:{code:"E008",message:"stop message suggests waiting/pending - use 'Already processed' style instead",category:"semantic"},E009:{code:"E009",message:"Primitive aggregation (sum, min, max) only allowed in computed",category:"semantic"},E010:{code:"E010",message:"Primitive aggregation does not allow composition - use direct reference only",category:"semantic"},E011:{code:"E011",message:"reduce/fold/scan is forbidden - use sum, min, max for aggregation",category:"semantic"},E013:{code:"E013",message:"Circular include detected",category:"semantic"},E014:{code:"E014",message:"Include expansion depth exceeds limit",category:"semantic"},E015:{code:"E015",message:"Include target is not a declared flow",category:"semantic"},E016:{code:"E016",message:"Include not allowed in InnerStmt position",category:"semantic"},E017:{code:"E017",message:"once() not allowed in flow",category:"semantic"},E018:{code:"E018",message:"onceIntent not allowed in flow",category:"semantic"},E019:{code:"E019",message:"patch not allowed in flow",category:"semantic"},E020:{code:"E020",message:"effect not allowed in flow",category:"semantic"},E021:{code:"E021",message:"Flow parameter name conflicts with top-level identifier",category:"semantic"},E022:{code:"E022",message:"Flow and action share the same name",category:"semantic"},E023:{code:"E023",message:"Wrong number of arguments for included flow",category:"semantic"},E024:{code:"E024",message:"Include argument type mismatch",category:"type"},E030:{code:"E030",message:"Collection element type does not have an 'id' field",category:"type"},E030a:{code:"E030a",message:"Collection element 'id' field is not a primitive type",category:"type"},E030b:{code:"E030b",message:"Duplicate '.id' values detected in state initializer",category:"type"},E031:{code:"E031",message:"updateById/removeById not allowed in this context",category:"semantic"},E032:{code:"E032",message:"Nested transform primitive",category:"semantic"},E033:{code:"E033",message:"Transform primitive collection argument is not a state path",category:"semantic"},E034:{code:"E034",message:"Transform primitive in guard condition",category:"semantic"},E035:{code:"E035",message:"Transform primitive in available condition",category:"semantic"},E040:{code:"E040",message:"Circular computed dependency",category:"semantic"},E041:{code:"E041",message:"Computed references undeclared identifier",category:"semantic"},E042:{code:"E042",message:"State initializer references non-constant value",category:"semantic"},E043:{code:"E043",message:"Non-trivial union type cannot be lowered to FieldSpec",category:"type"},E044:{code:"E044",message:"Recursive named type cannot be lowered to FieldSpec",category:"type"},E045:{code:"E045",message:"Nullable type cannot be lowered to FieldSpec",category:"type"},E046:{code:"E046",message:"Record type cannot be lowered to FieldSpec",category:"type"},E047:{code:"E047",message:"dispatchable expression must be pure (state/computed/action parameters only)",category:"semantic"},E048:{code:"E048",message:"Transform primitive in dispatchable condition",category:"semantic"},E049:{code:"E049",message:"Invalid literal clamp bounds",category:"semantic"},E050:{code:"E050",message:"Invalid match() form",category:"semantic"},E051:{code:"E051",message:"Duplicate match() key",category:"semantic"},E052:{code:"E052",message:"Invalid argmax()/argmin() form",category:"semantic"},E053:{code:"E053",message:"@meta can attach only to domain, type, type field, state field, computed, or action declarations",category:"syntax"},E054:{code:"E054",message:"Action-parameter annotations are not part of the current MEL syntax",category:"syntax"},E055:{code:"E055",message:"Annotation payloads must be JSON-like literals",category:"semantic"},E056:{code:"E056",message:"Annotation payload nesting exceeds the current MEL limit of 2 levels",category:"semantic"},E057:{code:"E057",message:"Annotation target does not map to the emitted DomainSchema",category:"semantic"},E058:{code:"E058",message:"Source-map target does not map to the emitted DomainSchema",category:"semantic"},E_STALE_MODULE:{code:"E_STALE_MODULE",message:"baseModule source hash does not match baseSource",category:"semantic"},E_FRAGMENT_PARSE_FAILED:{code:"E_FRAGMENT_PARSE_FAILED",message:"Fragment failed its operation-specific parser",category:"syntax"},E_FRAGMENT_SCOPE_VIOLATION:{code:"E_FRAGMENT_SCOPE_VIOLATION",message:"Fragment violates the requested edit scope",category:"semantic"},E_TARGET_NOT_FOUND:{code:"E_TARGET_NOT_FOUND",message:"Edit target does not exist",category:"semantic"},E_TARGET_KIND_MISMATCH:{code:"E_TARGET_KIND_MISMATCH",message:"Edit target kind is invalid for the requested operation",category:"semantic"},E_UNSAFE_RENAME_AMBIGUOUS:{code:"E_UNSAFE_RENAME_AMBIGUOUS",message:"Rename cannot update references safely and deterministically",category:"semantic"},E_REMOVE_BLOCKED_BY_REFERENCES:{code:"E_REMOVE_BLOCKED_BY_REFERENCES",message:"Remove would leave references dangling",category:"semantic"},E_UNDEFINED:{code:"E_UNDEFINED",message:"Undefined identifier",category:"semantic"},E_DUPLICATE:{code:"E_DUPLICATE",message:"Duplicate identifier",category:"semantic"},E_INVALID_ACCESS:{code:"E_INVALID_ACCESS",message:"Invalid access to identifier in this context",category:"semantic"},E_UNGUARDED_STMT:{code:"E_UNGUARDED_STMT",message:"Statement must be inside a guard (when or once)",category:"semantic"},E_UNGUARDED_PATCH:{code:"E_UNGUARDED_PATCH",message:"Patch must be inside a guard",category:"semantic"},E_UNGUARDED_EFFECT:{code:"E_UNGUARDED_EFFECT",message:"Effect must be inside a guard",category:"semantic"},E_ARG_COUNT:{code:"E_ARG_COUNT",message:"Wrong number of arguments",category:"type"},E_TYPE_MISMATCH:{code:"E_TYPE_MISMATCH",message:"Type mismatch",category:"type"},W_NON_BOOL_COND:{code:"W_NON_BOOL_COND",message:"Condition may not be boolean",category:"semantic"},W_UNUSED:{code:"W_UNUSED",message:"Unused identifier",category:"semantic"},W012:{code:"W012",message:"Anonymous object type in state field - use named type declaration instead",category:"type"},MEL_LEXER:{code:"MEL_LEXER",message:"Lexer error",category:"syntax"},MEL_PARSER:{code:"MEL_PARSER",message:"Parser error",category:"syntax"}};function at(e){return I[e]}function ot(e){let t=I[e];return t?`${e}: ${t.message}`:e}function M(e,t){let{code:n,message:a,location:i}=e;if(!i||i.start.line===0&&i.start.column===0)return`[${n}] ${a}`;let{line:p,column:c}=i.start,g=`[${n}] ${a} (${p}:${c})`;if(!t)return g;let y=t.split(`
|
|
2
|
+
`)[p-1];if(!y)return g;let u=String(p).padStart(4," "),d=`${u} | ${y}`,s=Math.max(1,i.end.line===i.start.line?Math.min(i.end.column-c,y.length-c+1):1),E=`${" ".repeat(u.length+3+c-1)}${"^".repeat(s)}`;return`${g}
|
|
3
|
+
${d}
|
|
4
|
+
${E}`}function ae(e,t){return e.map(n=>M(n,t)).join(`
|
|
5
5
|
|
|
6
|
-
`)}function rr(e,t,n){switch(e){case"+":return{kind:"add",left:t,right:n};case"-":return{kind:"sub",left:t,right:n};case"*":return{kind:"mul",left:t,right:n};case"/":return{kind:"div",left:t,right:n};case"%":return{kind:"mod",left:t,right:n};case"==":return{kind:"eq",left:t,right:n};case"!=":return{kind:"neq",left:t,right:n};case"<":return{kind:"lt",left:t,right:n};case"<=":return{kind:"lte",left:t,right:n};case">":return{kind:"gt",left:t,right:n};case">=":return{kind:"gte",left:t,right:n};case"&&":return{kind:"and",args:[t,n]};case"||":return{kind:"or",args:[t,n]};case"??":return{kind:"coalesce",args:[t,n]}}}function ar(e,t){switch(e){case"add":return{kind:"add",left:t[0],right:t[1]};case"sub":return{kind:"sub",left:t[0],right:t[1]};case"mul":return{kind:"mul",left:t[0],right:t[1]};case"div":return{kind:"div",left:t[0],right:t[1]};case"mod":return{kind:"mod",left:t[0],right:t[1]};case"neg":return{kind:"neg",arg:t[0]};case"abs":return{kind:"abs",arg:t[0]};case"min":return t.length===1?{kind:"minArray",array:t[0]}:{kind:"min",args:t};case"max":return t.length===1?{kind:"maxArray",array:t[0]}:{kind:"max",args:t};case"sum":return{kind:"sumArray",array:t[0]};case"floor":return{kind:"floor",arg:t[0]};case"ceil":return{kind:"ceil",arg:t[0]};case"round":return{kind:"round",arg:t[0]};case"sqrt":return{kind:"sqrt",arg:t[0]};case"pow":return{kind:"pow",base:t[0],exponent:t[1]};case"eq":return{kind:"eq",left:t[0],right:t[1]};case"neq":return{kind:"neq",left:t[0],right:t[1]};case"gt":return{kind:"gt",left:t[0],right:t[1]};case"gte":return{kind:"gte",left:t[0],right:t[1]};case"lt":return{kind:"lt",left:t[0],right:t[1]};case"lte":return{kind:"lte",left:t[0],right:t[1]};case"and":return{kind:"and",args:t};case"or":return{kind:"or",args:t};case"not":return{kind:"not",arg:t[0]};case"isNull":return{kind:"isNull",arg:t[0]};case"isNotNull":return{kind:"not",arg:{kind:"isNull",arg:t[0]}};case"typeof":return{kind:"typeof",arg:t[0]};case"coalesce":return{kind:"coalesce",args:t};case"concat":return{kind:"concat",args:t};case"trim":return{kind:"trim",str:t[0]};case"lower":case"toLowerCase":return{kind:"toLowerCase",str:t[0]};case"upper":case"toUpperCase":return{kind:"toUpperCase",str:t[0]};case"strlen":case"strLen":return{kind:"strLen",str:t[0]};case"substr":case"substring":return t[2]?{kind:"substring",str:t[0],start:t[1],end:t[2]}:{kind:"substring",str:t[0],start:t[1]};case"toString":return{kind:"toString",arg:t[0]};case"len":case"length":return{kind:"len",arg:t[0]};case"at":return{kind:"at",array:t[0],index:t[1]};case"first":return{kind:"first",array:t[0]};case"last":return{kind:"last",array:t[0]};case"slice":return t[2]?{kind:"slice",array:t[0],start:t[1],end:t[2]}:{kind:"slice",array:t[0],start:t[1]};case"includes":return{kind:"includes",array:t[0],item:t[1]};case"filter":return{kind:"filter",array:t[0],predicate:t[1]};case"map":return{kind:"map",array:t[0],mapper:t[1]};case"find":return{kind:"find",array:t[0],predicate:t[1]};case"every":return{kind:"every",array:t[0],predicate:t[1]};case"some":return{kind:"some",array:t[0],predicate:t[1]};case"append":return{kind:"append",array:t[0],items:t.slice(1)};case"keys":return{kind:"keys",obj:t[0]};case"values":return{kind:"values",obj:t[0]};case"entries":return{kind:"entries",obj:t[0]};case"merge":return{kind:"merge",objects:t};case"if":case"cond":return{kind:"if",cond:t[0],then:t[1],else:t[2]};default:return{kind:"object",fields:{__call:{kind:"lit",value:e},__args:{kind:"lit",value:t}}}}}import{hashSchemaSync as ge,semanticPathToPatchPath as ye}from"@manifesto-ai/core";function Z(e){let t=structuredClone(e),n=!1;for(let[s,d]of Object.entries(t.actions)){let c=Ee(s);if(O(d.flow,c),c.slots.size!==0){n=!0;for(let y of c.slots.values())ve(t.state.fields,s,y);t.actions[s]={...d,flow:be(d.flow,c)}}}if(!n)return t;let{hash:r,...a}=t,o=ge(a);return{...a,hash:o}}function Ee(e){return{actionName:e,slots:new Map}}function he(e){switch(e){case"timestamp":case"time.now":return"number";default:return"string"}}function ke(e){return e.replaceAll(".","_")}function R(e,t){let n=e[t];if(n&&n.type==="object")return n.required=!1,n.default??={},n.fields??={},n;let r={type:"object",required:!1,default:{},fields:{}};return e[t]=r,r}function ve(e,t,n){let r=R(e,"$mel"),a=R(r.fields??(r.fields={}),"sys"),o=R(a.fields??(a.fields={}),t),s=R(o.fields??(o.fields={}),n.normalizedKey),d=s.fields??(s.fields={});d.intent={type:"string",required:!1,default:null},d.value={type:he(n.key),required:!1,default:null}}function Ne(e){return ye(e)}function O(e,t){switch(e.kind){case"seq":for(let n of e.steps)O(n,t);break;case"if":A(e.cond,t),O(e.then,t),e.else&&O(e.else,t);break;case"patch":e.value&&A(e.value,t);break;case"effect":for(let n of Object.values(e.params))A(n,t);break;case"fail":e.message&&A(e.message,t);break}}function A(e,t){if(e.kind==="get"&&e.path.startsWith("$system.")){let n=e.path.slice(8);if(!t.slots.has(n)){let r=ke(n);t.slots.set(n,{key:n,normalizedKey:r,valuePath:`$mel.sys.${t.actionName}.${r}.value`,intentPath:`$mel.sys.${t.actionName}.${r}.intent`})}return}if(e.kind==="object"){for(let n of Object.values(e.fields))n&&typeof n=="object"&&"kind"in n&&A(n,t);return}for(let n of Object.values(e))if(typeof n=="object"&&n!==null)if(Array.isArray(n))for(let r of n)typeof r=="object"&&r!==null&&"kind"in r&&A(r,t);else"kind"in n&&A(n,t)}function be(e,t){if(t.slots.size===0)return e;let n=[];for(let d of t.slots.values()){let c={kind:"if",cond:{kind:"neq",left:{kind:"get",path:d.intentPath},right:{kind:"get",path:"meta.intentId"}},then:{kind:"seq",steps:[{kind:"patch",op:"set",path:Ne(d.intentPath),value:{kind:"get",path:"meta.intentId"}},{kind:"effect",type:"system.get",params:{key:{kind:"lit",value:d.key},into:{kind:"lit",value:d.valuePath}}}]}};n.push(c)}let r=[];for(let d of t.slots.values())r.push({kind:"eq",left:{kind:"get",path:d.intentPath},right:{kind:"get",path:"meta.intentId"}});let a=r.length===1?r[0]:{kind:"and",args:r},o=F(e,t),s={kind:"if",cond:a,then:o};return{kind:"seq",steps:[...n,s]}}function F(e,t){switch(e.kind){case"seq":return{kind:"seq",steps:e.steps.map(r=>F(r,t))};case"if":return{kind:"if",cond:f(e.cond,t),then:F(e.then,t),else:e.else?F(e.else,t):void 0};case"patch":return{kind:"patch",op:e.op,path:e.path,value:e.value?f(e.value,t):void 0};case"effect":let n={};for(let[r,a]of Object.entries(e.params))n[r]=f(a,t);return{kind:"effect",type:e.type,params:n};case"fail":return{kind:"fail",code:e.code,message:e.message?f(e.message,t):void 0};default:return e}}function f(e,t){if(e.kind==="get"&&e.path.startsWith("$system.")){let n=e.path.slice(8),r=t.slots.get(n);if(r)return{kind:"get",path:r.valuePath}}switch(e.kind){case"eq":case"neq":case"gt":case"gte":case"lt":case"lte":case"add":case"sub":case"mul":case"div":case"mod":return{kind:e.kind,left:f(e.left,t),right:f(e.right,t)};case"and":case"or":case"coalesce":case"concat":case"min":case"max":case"merge":return{kind:e.kind,args:e.args.map(r=>f(r,t))};case"not":case"neg":case"abs":case"floor":case"ceil":case"round":case"isNull":case"typeof":case"toString":case"len":case"keys":case"values":case"entries":case"first":case"last":return{kind:e.kind,arg:f(e.arg,t)};case"trim":case"toLowerCase":case"toUpperCase":case"strLen":return{kind:e.kind,str:f(e.str,t)};case"at":case"includes":return{kind:e.kind,array:f(e.array,t),index:f(e.index??e.item,t)};case"filter":case"map":case"find":case"every":case"some":return{kind:e.kind,array:f(e.array,t),predicate:f(e.predicate??e.mapper,t)};case"if":return{kind:"if",cond:f(e.cond,t),then:f(e.then,t),else:f(e.else,t)};case"field":return{kind:"field",object:f(e.object,t),property:e.property};case"object":let n={};for(let[r,a]of Object.entries(e.fields))n[r]=f(a,t);return{kind:"object",fields:n};case"append":return{kind:"append",array:f(e.array,t),items:e.items.map(r=>f(r,t))};default:return e}}function k(e){switch(e.kind){case"primitive":return e.name;case"literal":return Ce(e.value);case"ref":return e.name;case"array":return`Array<${k(e.element)}>`;case"record":return`Record<${k(e.key)}, ${k(e.value)}>`;case"union":return Ae(e.members);case"object":return Pe(e.fields)}}function Ce(e){return e===null?"null":typeof e=="string"?`"${ee(e)}"`:typeof e=="boolean"?e?"true":"false":String(e)}function Ae(e){return e.length===0?"never":e.map(k).join(" | ")}function Pe(e){return e.length===0?"{}":`{ ${e.map(n=>{let r=n.optional?"?":"";return`${n.name}${r}: ${k(n.type)}`}).join(", ")} }`}function S(e,t){let n=k(e.type);return t!==void 0?`${e.name}: ${n} = ${P(t)}`:e.optional?`${e.name}?: ${n}`:`${e.name}: ${n}`}function P(e){return e===null||e===void 0?"null":typeof e=="string"?`"${ee(e)}"`:typeof e=="number"?String(e):typeof e=="boolean"?e?"true":"false":Array.isArray(e)?`[${e.map(P).join(", ")}]`:typeof e=="object"?`{ ${Object.entries(e).map(([n,r])=>`${n}: ${P(r)}`).join(", ")} }`:String(e)}function ee(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function i(e){switch(e.kind){case"lit":return L(e.value);case"get":return Se(e.path);case"eq":return`eq(${i(e.left)}, ${i(e.right)})`;case"neq":return`neq(${i(e.left)}, ${i(e.right)})`;case"gt":return`gt(${i(e.left)}, ${i(e.right)})`;case"gte":return`gte(${i(e.left)}, ${i(e.right)})`;case"lt":return`lt(${i(e.left)}, ${i(e.right)})`;case"lte":return`lte(${i(e.left)}, ${i(e.right)})`;case"and":return!e.args||!Array.isArray(e.args)?"and(/* malformed: args undefined */)":`and(${e.args.map(i).join(", ")})`;case"or":return!e.args||!Array.isArray(e.args)?"or(/* malformed: args undefined */)":`or(${e.args.map(i).join(", ")})`;case"not":return e.arg?`not(${i(e.arg)})`:"not(/* malformed: arg undefined */)";case"if":return`if(${i(e.cond)}, ${i(e.then)}, ${i(e.else)})`;case"add":return`add(${i(e.left)}, ${i(e.right)})`;case"sub":return`sub(${i(e.left)}, ${i(e.right)})`;case"mul":return`mul(${i(e.left)}, ${i(e.right)})`;case"div":return`div(${i(e.left)}, ${i(e.right)})`;case"mod":return`mod(${i(e.left)}, ${i(e.right)})`;case"concat":return!e.args||!Array.isArray(e.args)?"concat(/* malformed: args undefined */)":`concat(${e.args.map(i).join(", ")})`;case"substring":return e.end!==void 0?`substring(${i(e.str)}, ${i(e.start)}, ${i(e.end)})`:`substring(${i(e.str)}, ${i(e.start)})`;case"trim":return`trim(${i(e.str)})`;case"len":return`len(${i(e.arg)})`;case"at":return`at(${i(e.array)}, ${i(e.index)})`;case"first":return`first(${i(e.array)})`;case"last":return`last(${i(e.array)})`;case"slice":return e.end!==void 0?`slice(${i(e.array)}, ${i(e.start)}, ${i(e.end)})`:`slice(${i(e.array)}, ${i(e.start)})`;case"includes":return`includes(${i(e.array)}, ${i(e.item)})`;case"filter":return`filter(${i(e.array)}, ${i(e.predicate)})`;case"map":return`map(${i(e.array)}, ${i(e.mapper)})`;case"find":return`find(${i(e.array)}, ${i(e.predicate)})`;case"every":return`every(${i(e.array)}, ${i(e.predicate)})`;case"some":return`some(${i(e.array)}, ${i(e.predicate)})`;case"append":return!e.items||!Array.isArray(e.items)?`append(${i(e.array)}, /* malformed: items undefined */)`:`append(${i(e.array)}, ${e.items.map(i).join(", ")})`;case"object":return $e(e.fields);case"field":return`${i(e.object)}.${e.property}`;case"keys":return`keys(${i(e.obj)})`;case"values":return`values(${i(e.obj)})`;case"entries":return`entries(${i(e.obj)})`;case"merge":return!e.objects||!Array.isArray(e.objects)?"merge(/* malformed: objects undefined */)":`merge(${e.objects.map(i).join(", ")})`;case"typeof":return`typeof(${i(e.arg)})`;case"isNull":return`isNull(${i(e.arg)})`;case"coalesce":return!e.args||!Array.isArray(e.args)?"coalesce(/* malformed: args undefined */)":`coalesce(${e.args.map(i).join(", ")})`;default:return`/* unknown: ${JSON.stringify(e)} */`}}function L(e){return e===null||e===void 0?"null":typeof e=="string"?`"${xe(e)}"`:typeof e=="number"?String(e):typeof e=="boolean"?e?"true":"false":Array.isArray(e)?`[${e.map(L).join(", ")}]`:typeof e=="object"?`{ ${Object.entries(e).map(([n,r])=>`${n}: ${L(r)}`).join(", ")} }`:String(e)}function Se(e){return e.startsWith("$meta.")||e.startsWith("$system.")||e.startsWith("$input.")?e:e.startsWith("data.")?e.slice(5):e}function $e(e){return`{ ${Object.entries(e).map(([n,r])=>`${n}: ${i(r)}`).join(", ")} }`}function xe(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}import{parsePath as te}from"@manifesto-ai/core";var we={indent:" ",includeComments:!1,commentPrefix:"// "};function N(e,t){let n={...we,...t};switch(e.kind){case"addType":return Re(e,n);case"addField":return Oe(e,n);case"setFieldType":return Fe(e,n);case"setDefaultValue":return je(e,n);case"addConstraint":return Te(e,n);case"addComputed":return _e(e,n);case"addActionAvailable":return De(e,n);default:return`// Unknown operation: ${JSON.stringify(e)}`}}function Re(e,t){let{indent:n}=t;if(e.typeExpr.kind==="object"){let r=e.typeExpr.fields.map(a=>`${n}${S(a)}`).join(`
|
|
6
|
+
`)}function lt(e,t,n){switch(e){case"+":return{kind:"add",left:t,right:n};case"-":return{kind:"sub",left:t,right:n};case"*":return{kind:"mul",left:t,right:n};case"/":return{kind:"div",left:t,right:n};case"%":return{kind:"mod",left:t,right:n};case"==":return{kind:"eq",left:t,right:n};case"!=":return{kind:"neq",left:t,right:n};case"<":return{kind:"lt",left:t,right:n};case"<=":return{kind:"lte",left:t,right:n};case">":return{kind:"gt",left:t,right:n};case">=":return{kind:"gte",left:t,right:n};case"&&":return{kind:"and",args:[t,n]};case"||":return{kind:"or",args:[t,n]};case"??":return{kind:"coalesce",args:[t,n]}}}function gt(e,t){switch(e){case"add":return{kind:"add",left:t[0],right:t[1]};case"sub":return{kind:"sub",left:t[0],right:t[1]};case"mul":return{kind:"mul",left:t[0],right:t[1]};case"div":return{kind:"div",left:t[0],right:t[1]};case"mod":return{kind:"mod",left:t[0],right:t[1]};case"neg":return{kind:"neg",arg:t[0]};case"abs":return{kind:"abs",arg:t[0]};case"min":return t.length===1?{kind:"minArray",array:t[0]}:{kind:"min",args:t};case"max":return t.length===1?{kind:"maxArray",array:t[0]}:{kind:"max",args:t};case"sum":return{kind:"sumArray",array:t[0]};case"floor":return{kind:"floor",arg:t[0]};case"ceil":return{kind:"ceil",arg:t[0]};case"round":return{kind:"round",arg:t[0]};case"sqrt":return{kind:"sqrt",arg:t[0]};case"pow":return{kind:"pow",base:t[0],exponent:t[1]};case"eq":return{kind:"eq",left:t[0],right:t[1]};case"neq":return{kind:"neq",left:t[0],right:t[1]};case"gt":return{kind:"gt",left:t[0],right:t[1]};case"gte":return{kind:"gte",left:t[0],right:t[1]};case"lt":return{kind:"lt",left:t[0],right:t[1]};case"lte":return{kind:"lte",left:t[0],right:t[1]};case"and":return{kind:"and",args:t};case"or":return{kind:"or",args:t};case"not":return{kind:"not",arg:t[0]};case"isNull":return{kind:"isNull",arg:t[0]};case"isNotNull":return{kind:"not",arg:{kind:"isNull",arg:t[0]}};case"typeof":return{kind:"typeof",arg:t[0]};case"coalesce":return{kind:"coalesce",args:t};case"concat":return{kind:"concat",args:t};case"trim":return{kind:"trim",str:t[0]};case"lower":case"toLowerCase":return{kind:"toLowerCase",str:t[0]};case"upper":case"toUpperCase":return{kind:"toUpperCase",str:t[0]};case"strlen":case"strLen":return{kind:"strLen",str:t[0]};case"substr":case"substring":return t[2]?{kind:"substring",str:t[0],start:t[1],end:t[2]}:{kind:"substring",str:t[0],start:t[1]};case"toString":return{kind:"toString",arg:t[0]};case"len":case"length":return{kind:"len",arg:t[0]};case"at":return{kind:"at",array:t[0],index:t[1]};case"first":return{kind:"first",array:t[0]};case"last":return{kind:"last",array:t[0]};case"slice":return t[2]?{kind:"slice",array:t[0],start:t[1],end:t[2]}:{kind:"slice",array:t[0],start:t[1]};case"includes":return{kind:"includes",array:t[0],item:t[1]};case"filter":return{kind:"filter",array:t[0],predicate:t[1]};case"map":return{kind:"map",array:t[0],mapper:t[1]};case"find":return{kind:"find",array:t[0],predicate:t[1]};case"every":return{kind:"every",array:t[0],predicate:t[1]};case"some":return{kind:"some",array:t[0],predicate:t[1]};case"append":return{kind:"append",array:t[0],items:t.slice(1)};case"keys":return{kind:"keys",obj:t[0]};case"values":return{kind:"values",obj:t[0]};case"entries":return{kind:"entries",obj:t[0]};case"merge":return{kind:"merge",objects:t};case"if":case"cond":return{kind:"if",cond:t[0],then:t[1],else:t[2]};default:return{kind:"object",fields:{__call:{kind:"lit",value:e},__args:{kind:"lit",value:t}}}}}function oe(e){return e}function f(e){switch(e.kind){case"primitive":return e.name;case"literal":return se(e.value);case"ref":return e.name;case"array":return`Array<${f(e.element)}>`;case"record":return`Record<${f(e.key)}, ${f(e.value)}>`;case"union":return de(e.members);case"object":return ce(e.fields)}}function se(e){return e===null?"null":typeof e=="string"?`"${L(e)}"`:typeof e=="boolean"?e?"true":"false":String(e)}function de(e){return e.length===0?"never":e.map(f).join(" | ")}function ce(e){return e.length===0?"{}":`{ ${e.map(n=>{let a=n.optional?"?":"";return`${n.name}${a}: ${f(n.type)}`}).join(", ")} }`}function $(e,t){let n=f(e.type);return t!==void 0?`${e.name}: ${n} = ${k(t)}`:e.optional?`${e.name}?: ${n}`:`${e.name}: ${n}`}function k(e){return e===null||e===void 0?"null":typeof e=="string"?`"${L(e)}"`:typeof e=="number"?String(e):typeof e=="boolean"?e?"true":"false":Array.isArray(e)?`[${e.map(k).join(", ")}]`:typeof e=="object"?`{ ${Object.entries(e).map(([n,a])=>`${n}: ${k(a)}`).join(", ")} }`:String(e)}function L(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function r(e){switch(e.kind){case"lit":return F(e.value);case"get":return me(e.path);case"eq":return`eq(${r(e.left)}, ${r(e.right)})`;case"neq":return`neq(${r(e.left)}, ${r(e.right)})`;case"gt":return`gt(${r(e.left)}, ${r(e.right)})`;case"gte":return`gte(${r(e.left)}, ${r(e.right)})`;case"lt":return`lt(${r(e.left)}, ${r(e.right)})`;case"lte":return`lte(${r(e.left)}, ${r(e.right)})`;case"and":return!e.args||!Array.isArray(e.args)?"and(/* malformed: args undefined */)":`and(${e.args.map(r).join(", ")})`;case"or":return!e.args||!Array.isArray(e.args)?"or(/* malformed: args undefined */)":`or(${e.args.map(r).join(", ")})`;case"not":return e.arg?`not(${r(e.arg)})`:"not(/* malformed: arg undefined */)";case"if":return`if(${r(e.cond)}, ${r(e.then)}, ${r(e.else)})`;case"add":return`add(${r(e.left)}, ${r(e.right)})`;case"sub":return`sub(${r(e.left)}, ${r(e.right)})`;case"mul":return`mul(${r(e.left)}, ${r(e.right)})`;case"div":return`div(${r(e.left)}, ${r(e.right)})`;case"mod":return`mod(${r(e.left)}, ${r(e.right)})`;case"concat":return!e.args||!Array.isArray(e.args)?"concat(/* malformed: args undefined */)":`concat(${e.args.map(r).join(", ")})`;case"substring":return e.end!==void 0?`substring(${r(e.str)}, ${r(e.start)}, ${r(e.end)})`:`substring(${r(e.str)}, ${r(e.start)})`;case"trim":return`trim(${r(e.str)})`;case"len":return`len(${r(e.arg)})`;case"at":return`at(${r(e.array)}, ${r(e.index)})`;case"first":return`first(${r(e.array)})`;case"last":return`last(${r(e.array)})`;case"slice":return e.end!==void 0?`slice(${r(e.array)}, ${r(e.start)}, ${r(e.end)})`:`slice(${r(e.array)}, ${r(e.start)})`;case"includes":return`includes(${r(e.array)}, ${r(e.item)})`;case"filter":return`filter(${r(e.array)}, ${r(e.predicate)})`;case"map":return`map(${r(e.array)}, ${r(e.mapper)})`;case"find":return`find(${r(e.array)}, ${r(e.predicate)})`;case"every":return`every(${r(e.array)}, ${r(e.predicate)})`;case"some":return`some(${r(e.array)}, ${r(e.predicate)})`;case"append":return!e.items||!Array.isArray(e.items)?`append(${r(e.array)}, /* malformed: items undefined */)`:`append(${r(e.array)}, ${e.items.map(r).join(", ")})`;case"object":return pe(e.fields);case"field":return`${r(e.object)}.${e.property}`;case"keys":return`keys(${r(e.obj)})`;case"values":return`values(${r(e.obj)})`;case"entries":return`entries(${r(e.obj)})`;case"merge":return!e.objects||!Array.isArray(e.objects)?"merge(/* malformed: objects undefined */)":`merge(${e.objects.map(r).join(", ")})`;case"typeof":return`typeof(${r(e.arg)})`;case"isNull":return`isNull(${r(e.arg)})`;case"coalesce":return!e.args||!Array.isArray(e.args)?"coalesce(/* malformed: args undefined */)":`coalesce(${e.args.map(r).join(", ")})`;default:return`/* unknown: ${JSON.stringify(e)} */`}}function F(e){return e===null||e===void 0?"null":typeof e=="string"?`"${ue(e)}"`:typeof e=="number"?String(e):typeof e=="boolean"?e?"true":"false":Array.isArray(e)?`[${e.map(F).join(", ")}]`:typeof e=="object"?`{ ${Object.entries(e).map(([n,a])=>`${n}: ${F(a)}`).join(", ")} }`:String(e)}function me(e){return e.startsWith("$meta.")||e.startsWith("$system.")||e.startsWith("$input.")?e:e.startsWith("data.")?e.slice(5):e}function pe(e){return`{ ${Object.entries(e).map(([n,a])=>`${n}: ${r(a)}`).join(", ")} }`}function ue(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}import{parsePath as U}from"@manifesto-ai/core";var le={indent:" ",includeComments:!1,commentPrefix:"// "};function h(e,t){let n={...le,...t};switch(e.kind){case"addType":return ge(e,n);case"addField":return fe(e,n);case"setFieldType":return ye(e,n);case"setDefaultValue":return Ee(e,n);case"addConstraint":return he(e,n);case"addComputed":return ke(e,n);case"addActionAvailable":return $e(e,n);default:return`// Unknown operation: ${JSON.stringify(e)}`}}function ge(e,t){let{indent:n}=t;if(e.typeExpr.kind==="object"){let a=e.typeExpr.fields.map(i=>`${n}${$(i)}`).join(`
|
|
7
7
|
`);return`type ${e.typeName} {
|
|
8
|
-
${
|
|
9
|
-
}`}return`type ${e.typeName} = ${
|
|
10
|
-
`)}function
|
|
11
|
-
`)}function
|
|
12
|
-
`)}function
|
|
13
|
-
`)}function
|
|
14
|
-
`)}function
|
|
8
|
+
${a}
|
|
9
|
+
}`}return`type ${e.typeName} = ${f(e.typeExpr)}`}function fe(e,t){let n=e.field;return"defaultValue"in n&&n.defaultValue!==void 0?$(n,n.defaultValue):$(n)}function ye(e,t){let n=f(e.typeExpr),a=V(e.path),i=[];return t.includeComments&&i.push(`${t.commentPrefix}Change ${e.path} type to: ${n}`),i.push(`${a}: ${n}`),i.join(`
|
|
10
|
+
`)}function Ee(e,t){let n=V(e.path),a=k(e.value),i=[];return t.includeComments&&i.push(`${t.commentPrefix}Set default value for ${e.path}`),i.push(`${n} = ${a}`),i.join(`
|
|
11
|
+
`)}function he(e,t){let n=r(e.rule),a=e.message?` - "${e.message}"`:"";return`${t.commentPrefix}Constraint on ${e.targetPath}: ${n}${a}`}function ke(e,t){let n=r(e.expr),a=[];return t.includeComments&&e.deps&&e.deps.length>0&&a.push(`${t.commentPrefix}Dependencies: ${e.deps.join(", ")}`),a.push(`computed ${e.name} = ${n}`),a.join(`
|
|
12
|
+
`)}function $e(e,t){let n=r(e.expr),a=[];return t.includeComments&&a.push(`${t.commentPrefix}Add availability condition to ${e.actionName}`),a.push(`action ${e.actionName}() available when ${n} {`),a.push(`${t.indent}// action body...`),a.push("}"),a.join(`
|
|
13
|
+
`)}function V(e){let t=U(e);return t[t.length-1]??""}function q(e){let t=U(e);if(t.length>=2)return t[0]}var A={indent:" ",includeComments:!0,commentPrefix:"// ",includeMetadata:!0,includeEvidence:!1,includeConfidence:!0,includeFragmentId:!1};function C(e,t){let n={...A,...t},a=[];if(n.includeMetadata){if(n.includeFragmentId&&a.push(`${n.commentPrefix}Fragment: ${e.fragmentId}`),n.includeConfidence){let p=(e.confidence*100).toFixed(0);a.push(`${n.commentPrefix}Confidence: ${p}%`)}if(n.includeEvidence&&e.evidence.length>0){a.push(`${n.commentPrefix}Evidence:`);for(let p of e.evidence)a.push(`${n.commentPrefix} - ${p}`)}}let i=h(e.op,{indent:n.indent,includeComments:n.includeComments,commentPrefix:n.commentPrefix});return a.push(i),a.join(`
|
|
14
|
+
`)}function S(e,t){let n={...A,...t};return e.map(i=>C(i,n)).join(`
|
|
15
15
|
|
|
16
|
-
`)}function
|
|
17
|
-
`).map(
|
|
18
|
-
`);
|
|
19
|
-
`).map(
|
|
20
|
-
`);
|
|
21
|
-
`)}import{parsePath as Ie}from"@manifesto-ai/core";function Me(e){return{snapshot:e.snapshot??{data:{},computed:{}},meta:e.meta,input:e.input??{},item:e.item}}function V(e,t,n){let r=structuredClone(e.data);return Le(r,t,n),{data:r,computed:e.computed}}function Le(e,t,n){let r=Ie(t),a=e;for(let s=0;s<r.length-1;s++){let d=r[s];(!(d in a)||typeof a[d]!="object")&&(a[d]={}),a=a[d]}let o=r[r.length-1];a[o]=n}import{parsePath as qe}from"@manifesto-ai/core";function v(e,t){try{return u(e,t)}catch{return null}}function u(e,t){switch(e.kind){case"lit":return e.value;case"get":return Ue(e.path,t);case"eq":return ie(e.left,e.right,t);case"neq":return Ve(e.left,e.right,t);case"gt":return T(e.left,e.right,t,(n,r)=>n>r);case"gte":return T(e.left,e.right,t,(n,r)=>n>=r);case"lt":return T(e.left,e.right,t,(n,r)=>n<r);case"lte":return T(e.left,e.right,t,(n,r)=>n<=r);case"and":return Ge(e.args,t);case"or":return We(e.args,t);case"not":return Be(e.arg,t);case"if":return ze(e.cond,e.then,e.else,t);case"add":return G(e.left,e.right,t,(n,r)=>n+r);case"sub":return G(e.left,e.right,t,(n,r)=>n-r);case"mul":return G(e.left,e.right,t,(n,r)=>n*r);case"div":return Ke(e.left,e.right,t);case"mod":return He(e.left,e.right,t);case"neg":return Ye(e.arg,t);case"min":return Je(e.args,t);case"max":return Xe(e.args,t);case"abs":return Qe(e.arg,t);case"floor":return Ze(e.arg,t);case"ceil":return et(e.arg,t);case"round":return tt(e.arg,t);case"sqrt":return nt(e.arg,t);case"pow":return rt(e.base,e.exponent,t);case"concat":return at(e.args,t);case"substring":return ot(e.str,e.start,e.end,t);case"trim":return it(e.str,t);case"len":return st(e.arg,t);case"at":return ut(e.array,e.index,t);case"first":return ct(e.array,t);case"last":return dt(e.array,t);case"slice":return lt(e.array,e.start,e.end,t);case"includes":return pt(e.array,e.item,t);case"filter":return mt(e.array,e.predicate,t);case"map":return ft(e.array,e.mapper,t);case"find":return gt(e.array,e.predicate,t);case"every":return yt(e.array,e.predicate,t);case"some":return Et(e.array,e.predicate,t);case"append":return ht(e.array,e.items,t);case"sumArray":return kt(e.array,t);case"minArray":return vt(e.array,t);case"maxArray":return Nt(e.array,t);case"object":return bt(e.fields,t);case"field":return Ct(e.object,e.property,t);case"keys":return At(e.obj,t);case"values":return Pt(e.obj,t);case"entries":return St(e.obj,t);case"merge":return $t(e.objects,t);case"typeof":return xt(e.arg,t);case"isNull":return wt(e.arg,t);case"coalesce":return Rt(e.args,t);default:return null}}function Ue(e,t){let n=qe(e);return n[0]==="meta"?x(t.meta,n.slice(1)):n[0]==="input"?x(t.input,n.slice(1)):n[0]==="$item"?t.item===void 0?null:n.length===1?t.item:x(t.item,n.slice(1)):e in t.snapshot.computed?t.snapshot.computed[e]:x(t.snapshot.data,n)}function x(e,t){if(t.length===0)return e;if(e==null||typeof e!="object")return null;let[n,...r]=t,a=e[n];return r.length===0?a===void 0?null:a:x(a,r)}function ie(e,t,n){let r=u(e,n),a=u(t,n);return _(r,a)}function Ve(e,t,n){let r=ie(e,t,n);return r===null?null:!r}function T(e,t,n,r){let a=u(e,n),o=u(t,n);return typeof a!="number"||typeof o!="number"?null:r(a,o)}function _(e,t){if(e===t)return!0;if(e===null||t===null)return e===t;if(typeof e!=typeof t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((n,r)=>_(n,t[r]));if(typeof e=="object"&&typeof t=="object"){let n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(a=>Object.prototype.hasOwnProperty.call(t,a)&&_(e[a],t[a]))}return!1}function Ge(e,t){for(let n of e){let r=u(n,t);if(r!==!0)return r===!1?!1:null}return!0}function We(e,t){for(let n of e){let r=u(n,t);if(r===!0)return!0;if(r!==!1)return null}return!1}function Be(e,t){let n=u(e,t);return typeof n!="boolean"?null:!n}function ze(e,t,n,r){let a=u(e,r);return a===!0?u(t,r):a===!1?u(n,r):null}function G(e,t,n,r){let a=u(e,n),o=u(t,n);if(typeof a!="number"||typeof o!="number")return null;let s=r(a,o);return Number.isFinite(s)?s:null}function Ke(e,t,n){let r=u(e,n),a=u(t,n);return typeof r!="number"||typeof a!="number"||a===0?null:r/a}function He(e,t,n){let r=u(e,n),a=u(t,n);return typeof r!="number"||typeof a!="number"||a===0?null:r%a}function Ye(e,t){let n=u(e,t);return typeof n=="number"?-n:null}function Je(e,t){if(e.length===0)return null;let n=null;for(let r of e){let a=u(r,t);if(typeof a!="number")return null;n=n===null?a:Math.min(n,a)}return n}function Xe(e,t){if(e.length===0)return null;let n=null;for(let r of e){let a=u(r,t);if(typeof a!="number")return null;n=n===null?a:Math.max(n,a)}return n}function Qe(e,t){let n=u(e,t);return typeof n=="number"?Math.abs(n):null}function Ze(e,t){let n=u(e,t);return typeof n=="number"?Math.floor(n):null}function et(e,t){let n=u(e,t);return typeof n=="number"?Math.ceil(n):null}function tt(e,t){let n=u(e,t);return typeof n=="number"?Math.round(n):null}function nt(e,t){let n=u(e,t);return typeof n!="number"||n<0?null:Math.sqrt(n)}function rt(e,t,n){let r=u(e,n),a=u(t,n);if(typeof r!="number"||typeof a!="number")return null;let o=Math.pow(r,a);return Number.isFinite(o)?o:null}function at(e,t){let n=[];for(let r of e){let a=u(r,t);if(typeof a!="string")return null;n.push(a)}return n.join("")}function ot(e,t,n,r){let a=u(e,r),o=u(t,r);if(typeof a!="string"||typeof o!="number")return null;if(n===void 0)return a.substring(o);let s=u(n,r);return typeof s!="number"?null:a.substring(o,s)}function it(e,t){let n=u(e,t);return typeof n!="string"?null:n.trim()}function st(e,t){let n=u(e,t);return Array.isArray(n)||typeof n=="string"?n.length:n!==null&&typeof n=="object"?Object.keys(n).length:null}function ut(e,t,n){let r=u(e,n),a=u(t,n);return Array.isArray(r)&&typeof a=="number"?a<0||a>=r.length?null:r[a]:typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof a=="string"?r[a]??null:null}function ct(e,t){let n=u(e,t);return!Array.isArray(n)||n.length===0?null:n[0]}function dt(e,t){let n=u(e,t);return!Array.isArray(n)||n.length===0?null:n[n.length-1]}function lt(e,t,n,r){let a=u(e,r),o=u(t,r);if(!Array.isArray(a)||typeof o!="number")return null;if(n===void 0)return a.slice(o);let s=u(n,r);return typeof s!="number"?null:a.slice(o,s)}function pt(e,t,n){let r=u(e,n),a=u(t,n);return Array.isArray(r)?r.some(o=>_(o,a)):null}function mt(e,t,n){let r=u(e,n);if(!Array.isArray(r))return null;let a=[];for(let o of r){let s={...n,item:o},d=u(t,s);if(d===!0)a.push(o);else if(d!==!1)return null}return a}function ft(e,t,n){let r=u(e,n);if(!Array.isArray(r))return null;let a=[];for(let o of r){let s={...n,item:o},d=u(t,s);a.push(d)}return a}function gt(e,t,n){let r=u(e,n);if(!Array.isArray(r))return null;for(let a of r){let o={...n,item:a},s=u(t,o);if(s===!0)return a;if(s!==!1)return null}return null}function yt(e,t,n){let r=u(e,n);if(!Array.isArray(r))return null;for(let a of r){let o={...n,item:a},s=u(t,o);if(s===!1)return!1;if(s!==!0)return null}return!0}function Et(e,t,n){let r=u(e,n);if(!Array.isArray(r))return null;for(let a of r){let o={...n,item:a},s=u(t,o);if(s===!0)return!0;if(s!==!1)return null}return!1}function ht(e,t,n){let r=u(e,n);if(!Array.isArray(r))return null;let a=t.map(o=>u(o,n));return[...r,...a]}function kt(e,t){let n=u(e,t);if(!Array.isArray(n))return null;let r=0;for(let a of n){if(typeof a!="number")return null;r+=a}return r}function vt(e,t){let n=u(e,t);if(!Array.isArray(n)||n.length===0)return null;let r=null;for(let a of n){if(typeof a!="number")return null;r=r===null?a:Math.min(r,a)}return r}function Nt(e,t){let n=u(e,t);if(!Array.isArray(n)||n.length===0)return null;let r=null;for(let a of n){if(typeof a!="number")return null;r=r===null?a:Math.max(r,a)}return r}function bt(e,t){let n={};for(let r of Object.keys(e).sort($)){let a=e[r];n[r]=u(a,t)}return n}function Ct(e,t,n){let r=u(e,n);return r===null||typeof r!="object"||Array.isArray(r)?null:r[t]??null}function At(e,t){let n=u(e,t);return n===null||typeof n!="object"||Array.isArray(n)?null:Object.keys(n).sort($)}function Pt(e,t){let n=u(e,t);return n===null||typeof n!="object"||Array.isArray(n)?null:Object.keys(n).sort($).map(r=>n[r])}function St(e,t){let n=u(e,t);return n===null||typeof n!="object"||Array.isArray(n)?null:Object.keys(n).sort($).map(r=>[r,n[r]])}function $t(e,t){let n={};for(let r of e){let a=u(r,t);if(a===null||typeof a!="object"||Array.isArray(a))return null;Object.assign(n,a)}return n}function xt(e,t){let n=u(e,t);return n===null?"null":Array.isArray(n)?"array":typeof n}function wt(e,t){return u(e,t)===null}function Rt(e,t){for(let n of e){let r=u(n,t);if(r!=null)return r}return null}function Ot(e,t){let n=[],r=[],a=t.snapshot;for(let o of e){let s={...t,snapshot:a};if(o.condition!==void 0){let c=v(o.condition,s);if(c!==!0){let y=c===!1?"false":c===null?"null":"non-boolean";r.push({fragmentId:o.fragmentId,reason:y});continue}}let d={fragmentId:o.fragmentId,op:o.op,confidence:o.confidence,conditionEvaluated:o.condition!==void 0};n.push(d),a=jt(a,o.op,s)}return{patches:n,skipped:r,finalSnapshot:a}}function Ft(e,t){return e.filter(n=>n.condition===void 0?!0:v(n.condition,t)===!0).map(n=>({fragmentId:n.fragmentId,op:n.op,confidence:n.confidence,conditionEvaluated:n.condition!==void 0}))}function jt(e,t,n){switch(t.kind){case"setDefaultValue":return V(e,t.path,t.value);case"addType":case"addField":case"setFieldType":case"addConstraint":case"addComputed":case"addActionAvailable":return e}}function Tt(e,t){switch(e.kind){case"addType":case"addField":case"setFieldType":case"setDefaultValue":return e;case"addConstraint":return{...e};case"addComputed":return{...e};case"addActionAvailable":return{...e}}}function _t(e,t){return e===void 0?!0:v(e,t)===!0}function Dt(e,t){if(e===void 0)return{passes:!0,reason:"no-condition"};let n=v(e,t);return n===!0?{passes:!0,reason:"true"}:n===!1?{passes:!1,reason:"false"}:n===null?{passes:!1,reason:"null"}:{passes:!1,reason:"non-boolean"}}import{mergeAtPatchPath as It,patchPathToDisplayString as se,setByPatchPath as Mt,unsetByPatchPath as Lt}from"@manifesto-ai/core";var qt=new Set(["__proto__","constructor","prototype"]);function Ut(e,t){return le(e,t).patches}function le(e,t){let n=[],r=[],a=[],o=t.snapshot,s=[];for(let d=0;d<e.length;d++){let c=e[d],y=c.op==="set"&&D(c.path),E=s.length>0,m=y||!E?o:s[s.length-1].snapshot,p={...t,snapshot:m};if(c.condition!==void 0){let C=v(c.condition,p);if(C!==!0){let me=C===!1?"false":C===null?"null":"non-boolean";r.push({index:d,path:de(c.path),reason:me});continue}}let g=Wt(c.path,p);if(!g.ok){r.push({index:d,path:de(c.path),reason:"invalid-path"}),a.push(`Skipped runtime patch at index ${d}: ${g.warning}`);continue}let h=g.path,b=c.value?v(c.value,p):void 0,l=Vt(c.op,h,b);if(l!==null&&!(c.op==="unset"&&D(c.path)&&(!E||!ce(s[s.length-1].markerPath,h)))){if(n.push(l),o=Gt(o,l),c.op==="set"&&D(c.path)){s.push({markerPath:h,snapshot:o});continue}c.op==="unset"&&D(c.path)&&s.length>0&&ce(s[s.length-1].markerPath,h)&&s.pop()}}return{patches:n,skipped:r,warnings:a,finalSnapshot:o}}function Vt(e,t,n){switch(e){case"set":return{op:"set",path:t,value:n};case"unset":return{op:"unset",path:t};case"merge":return zt(n)?{op:"merge",path:t,value:n}:{op:"set",path:t,value:null}}}function Gt(e,t){let n=e.data;return{data:(()=>{switch(t.op){case"set":return Mt(n,t.path,t.value);case"unset":return Lt(n,t.path);case"merge":return It(n,t.path,t.value)}})(),computed:e.computed}}function Wt(e,t){if(e.length===0)return{ok:!1,warning:"path is empty"};let n=[];for(let r=0;r<e.length;r++){let a=e[r];if(a.kind==="prop"){if(!pe(a.name))return{ok:!1,warning:`invalid prop segment '${a.name}'`};n.push({kind:"prop",name:a.name});continue}let o=v(a.expr,t),s=Bt(o);if(s===null)return{ok:!1,warning:`expr segment at index ${r} resolved to invalid value`};n.push(s)}return{ok:!0,path:n}}function Bt(e){return typeof e=="number"&&Number.isInteger(e)&&Number.isFinite(e)&&e>=0?{kind:"index",index:e}:typeof e=="string"&&e.length>0&&pe(e)?{kind:"prop",name:e}:null}function pe(e){return e.length>0&&!qt.has(e)}function D(e){return ue(e,["$mel","__whenGuards"])||ue(e,["$mel","__onceScopeGuards"])}function ue(e,t){if(e.length<t.length)return!1;for(let n=0;n<t.length;n++){let r=e[n];if(r.kind!=="prop"||r.name!==t[n])return!1}return!0}function ce(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],a=t[n];if(r.kind!==a.kind||r.kind==="prop"&&a.kind==="prop"&&r.name!==a.name||r.kind==="index"&&a.kind==="index"&&r.index!==a.index)return!1}return!0}function de(e){let t=[];for(let n of e){if(n.kind==="prop"){t.push({kind:"prop",name:n.name});continue}return t.length===0?"[expr]":`${se(t)}.[expr]`}return t.length===0?"":se(t)}function zt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}var Kt="3.5.0";function Ht(e,t={}){let n=[],r=performance.now(),a=I(e);if(n.push({phase:"lex",durationMs:performance.now()-r,details:{tokenCount:a.tokens.length}}),w(a.diagnostics))return{schema:null,trace:n,warnings:a.diagnostics.filter(l=>l.severity==="warning"),errors:a.diagnostics.filter(l=>l.severity==="error"),success:!1};let o=performance.now(),s=M(a.tokens),d=s.diagnostics;if(n.push({phase:"parse",durationMs:performance.now()-o}),w(d))return{schema:null,trace:n,warnings:d.filter(l=>l.severity==="warning"),errors:d.filter(l=>l.severity==="error"),success:!1};let c=[],y=performance.now(),E=H(s.program);if(c.push(...E.diagnostics),!t.skipSemanticAnalysis){let l=W(E.program),C=B(E.program);c.push(...l.diagnostics,...C.diagnostics)}if(n.push({phase:"analyze",durationMs:performance.now()-y}),c.some(l=>l.severity==="error"))return{schema:null,trace:n,warnings:c.filter(l=>l.severity==="warning"),errors:c.filter(l=>l.severity==="error"),success:!1};let m=performance.now(),p=z(E.program);if(c.push(...p.diagnostics),n.push({phase:"generate",durationMs:performance.now()-m}),!t.skipSemanticAnalysis&&p.schema){let l=K(E.program,p.schema);c.push(...l.diagnostics);let C=J(E.program,e,p.schema,Y(Kt));c.push(...C.diagnostics)}t.skipSemanticAnalysis&&c.push(...s.diagnostics);let g=c.filter(l=>l.severity==="error");if(p.schema===null||g.length>0)return{schema:null,trace:n,warnings:c.filter(l=>l.severity==="warning"),errors:g,success:!1};let h=p.schema;if(t.lowerSystemValues){let l=performance.now();h=Z(h),n.push({phase:"lower",durationMs:performance.now()-l})}let b=c.filter(l=>l.severity==="warning");return{schema:h,trace:n,warnings:b,errors:c.filter(l=>l.severity==="error"),success:g.length===0}}function ta(e){let t=I(e);return w(t.diagnostics)?{program:null,diagnostics:t.diagnostics}:M(t.tokens)}function na(e){return Ht(e).errors}export{Pn as DEFAULT_ACTION_CONTEXT,Sn as DEFAULT_DISPATCHABLE_CONTEXT,xn as DEFAULT_PATCH_CONTEXT,An as DEFAULT_SCHEMA_CONTEXT,X as DIAGNOSTIC_CODES,$n as EFFECT_ARGS_CONTEXT,Yt as KEYWORDS,on as Lexer,wn as LoweringError,gn as Parser,cn as Precedence,Jt as RESERVED_KEYWORDS,yn as Scope,En as ScopeAnalyzer,Cn as SemanticValidator,W as analyzeScope,V as applyPatchToWorkingSnapshot,K as buildAnnotationIndex,na as check,Dt as classifyCondition,Ht as compile,Bn as compileFragmentInContext,Vn as compileMelDomain,Gn as compileMelModule,Wn as compileMelPatch,hn as createError,Me as createEvaluationContext,vn as createInfo,nn as createLocation,rn as createPointLocation,tn as createPosition,en as createToken,kn as createWarning,_t as evaluateCondition,Ot as evaluateConditionalPatchOps,v as evaluateExpr,Tt as evaluatePatchExpressions,Ft as evaluatePatches,Ut as evaluateRuntimePatches,le as evaluateRuntimePatchesWithTrace,Un as extractSchemaGraph,re as extractTypeName,bn as filterBySeverity,Q as formatDiagnostic,Jn as formatDiagnosticCode,fe as formatDiagnostics,z as generate,qn as generateCanonical,dn as getBinaryPrecedence,Yn as getDiagnosticInfo,Zt as getKeywordKind,w as hasErrors,Rn as invalidKindForContext,Tn as invalidShape,Fn as invalidSysPath,pn as isBinaryOp,Nn as isError,sn as isExprNode,Xt as isKeyword,Qt as isReserved,fn as isRightAssociative,un as isStmtNode,mn as isUnaryOp,Dn as lowerExprNode,In as lowerPatchFragments,Ln as lowerRuntimePatch,Mn as lowerRuntimePatches,Z as lowerSystemValues,an as mergeLocations,rr as normalizeExpr,ar as normalizeFunctionCall,M as parse,ta as parseSource,oe as renderAsDomain,i as renderExprNode,q as renderFragment,U as renderFragments,ae as renderFragmentsByKind,N as renderPatchOp,k as renderTypeExpr,S as renderTypeField,P as renderValue,ln as tokenToBinaryOp,I as tokenize,On as unknownCallFn,_n as unknownNodeKind,jn as unsupportedBase,B as validateSemantics};
|
|
16
|
+
`)}function G(e,t){let n={...A,...t},a={};for(let p of e){let c=p.op.kind;a[c]||(a[c]=[]),a[c].push(p)}let i={};for(let[p,c]of Object.entries(a))i[p]=S(c,n);return i}function B(e,t,n){let i={...A,...n}.indent??" ",p=[],c=[],g=[],m=[],y=[],u=[];for(let s of t)switch(s.op.kind){case"addType":p.push(s);break;case"addField":case"setFieldType":c.push(s);break;case"setDefaultValue":g.push(s);break;case"addComputed":m.push(s);break;case"addConstraint":y.push(s);break;case"addActionAvailable":u.push(s);break}let d=[];if(d.push(`domain ${e} {`),c.length>0||g.length>0){d.push(`${i}state {`);for(let s of[...c,...g]){let l=h(s.op,{indent:i+i,includeComments:!1});d.push(`${i}${i}${l}`)}d.push(`${i}}`),d.push("")}for(let s of p){let E=h(s.op,{indent:i,includeComments:!1}).split(`
|
|
17
|
+
`).map(N=>`${i}${N}`).join(`
|
|
18
|
+
`);d.push(E),d.push("")}for(let s of m){let l=h(s.op,{indent:i,includeComments:!1});d.push(`${i}${l}`)}m.length>0&&d.push("");for(let s of y){let l=h(s.op,{indent:i,includeComments:!0});d.push(`${i}${l}`)}y.length>0&&d.push("");for(let s of u){let E=h(s.op,{indent:i,includeComments:!1}).split(`
|
|
19
|
+
`).map(N=>`${i}${N}`).join(`
|
|
20
|
+
`);d.push(E),d.push("")}return d.push("}"),d.join(`
|
|
21
|
+
`)}var Ne="3.5.0";function xe(e,t={}){let n=[],a=performance.now(),i=T(e);if(n.push({phase:"lex",durationMs:performance.now()-a,details:{tokenCount:i.tokens.length}}),x(i.diagnostics))return{schema:null,trace:n,warnings:i.diagnostics.filter(o=>o.severity==="warning"),errors:i.diagnostics.filter(o=>o.severity==="error"),success:!1};let p=performance.now(),c=b(i.tokens),g=c.diagnostics;if(n.push({phase:"parse",durationMs:performance.now()-p}),x(g))return{schema:null,trace:n,warnings:g.filter(o=>o.severity==="warning"),errors:g.filter(o=>o.severity==="error"),success:!1};let m=[],y=performance.now(),u=P(c.program);if(m.push(...u.diagnostics),!t.skipSemanticAnalysis){let o=_(u.program),O=R(u.program);m.push(...o.diagnostics,...O.diagnostics)}if(n.push({phase:"analyze",durationMs:performance.now()-y}),m.some(o=>o.severity==="error"))return{schema:null,trace:n,warnings:m.filter(o=>o.severity==="warning"),errors:m.filter(o=>o.severity==="error"),success:!1};let d=performance.now(),s=w(u.program);if(m.push(...s.diagnostics),n.push({phase:"generate",durationMs:performance.now()-d}),!t.skipSemanticAnalysis&&s.schema){let o=D(u.program,s.schema);m.push(...o.diagnostics);let O=j(u.program,e,s.schema,v(Ne));m.push(...O.diagnostics)}t.skipSemanticAnalysis&&m.push(...c.diagnostics);let l=m.filter(o=>o.severity==="error");if(s.schema===null||l.length>0)return{schema:null,trace:n,warnings:m.filter(o=>o.severity==="warning"),errors:l,success:!1};let E=s.schema;if(t.lowerSystemValues){let o=performance.now();E=E,n.push({phase:"lower",durationMs:performance.now()-o})}let N=m.filter(o=>o.severity==="warning");return{schema:E,trace:n,warnings:N,errors:m.filter(o=>o.severity==="error"),success:l.length===0}}function Kt(e){let t=T(e);return x(t.diagnostics)?{program:null,diagnostics:t.diagnostics}:b(t.tokens)}function Xt(e){return xe(e).errors}export{z as DEFAULT_ACTION_CONTEXT,H as DEFAULT_DISPATCHABLE_CONTEXT,X as DEFAULT_PATCH_CONTEXT,W as DEFAULT_SCHEMA_CONTEXT,I as DIAGNOSTIC_CODES,K as EFFECT_ARGS_CONTEXT,Ae as KEYWORDS,De as Lexer,Y as LoweringError,qe as Parser,je as Precedence,Oe as RESERVED_KEYWORDS,Ge as Scope,Be as ScopeAnalyzer,Ye as SemanticValidator,_ as analyzeScope,D as buildAnnotationIndex,Xt as check,xe as compile,tt as compileFragmentInContext,Ze as compileMelDomain,et as compileMelModule,We as createError,He as createInfo,_e as createLocation,Re as createPointLocation,Se as createPosition,Ce as createToken,ze as createWarning,Qe as extractSchemaGraph,q as extractTypeName,Xe as filterBySeverity,M as formatDiagnostic,ot as formatDiagnosticCode,ae as formatDiagnostics,w as generate,Je as generateCanonical,Ie as getBinaryPrecedence,at as getDiagnosticInfo,Fe as getKeywordKind,x as hasErrors,J as invalidKindForContext,te as invalidShape,Z as invalidSysPath,Le as isBinaryOp,Ke as isError,Pe as isExprNode,Te as isKeyword,be as isReserved,Ve as isRightAssociative,ve as isStmtNode,Ue as isUnaryOp,re as lowerExprNode,ie as lowerPatchFragments,oe as lowerSystemValues,we as mergeLocations,lt as normalizeExpr,gt as normalizeFunctionCall,b as parse,Kt as parseSource,B as renderAsDomain,r as renderExprNode,C as renderFragment,S as renderFragments,G as renderFragmentsByKind,h as renderPatchOp,f as renderTypeExpr,$ as renderTypeField,k as renderValue,Me as tokenToBinaryOp,T as tokenize,Q as unknownCallFn,ne as unknownNodeKind,ee as unsupportedBase,R as validateSemantics};
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
* @see SPEC v0.4.0 §17.2
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
|
-
* Allowed
|
|
9
|
+
* Allowed dollar path prefixes.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* 'system'
|
|
11
|
+
* Current v5 lowering admits direct input and bound action context/runtime
|
|
12
|
+
* reads. Retired 'meta'/'system' prefixes are rejected before lowering.
|
|
13
13
|
*
|
|
14
|
-
* @see
|
|
14
|
+
* @see ADR-027
|
|
15
15
|
*/
|
|
16
|
-
export type AllowedSysPrefix = "
|
|
16
|
+
export type AllowedSysPrefix = "input" | "runtime" | "context";
|
|
17
17
|
/**
|
|
18
18
|
* Context for single expression lowering.
|
|
19
19
|
*
|
|
@@ -27,8 +27,7 @@ export interface ExprLoweringContext {
|
|
|
27
27
|
*/
|
|
28
28
|
mode: "schema" | "action";
|
|
29
29
|
/**
|
|
30
|
-
* Allowed
|
|
31
|
-
* In Translator path: only ["meta", "input"]
|
|
30
|
+
* Allowed dollar path prefixes.
|
|
32
31
|
*
|
|
33
32
|
* @see FDR-MEL-071
|
|
34
33
|
*/
|
|
@@ -60,8 +59,7 @@ export interface ExprLoweringContext {
|
|
|
60
59
|
*/
|
|
61
60
|
export interface PatchLoweringContext {
|
|
62
61
|
/**
|
|
63
|
-
* Allowed
|
|
64
|
-
* In Translator path: only ["meta", "input"]
|
|
62
|
+
* Allowed dollar path prefixes.
|
|
65
63
|
*
|
|
66
64
|
* @see FDR-MEL-071
|
|
67
65
|
*/
|
|
@@ -15,7 +15,7 @@ export type LoweringErrorCode =
|
|
|
15
15
|
"INVALID_KIND_FOR_CONTEXT"
|
|
16
16
|
/** Unknown function name in call node */
|
|
17
17
|
| "UNKNOWN_CALL_FN"
|
|
18
|
-
/**
|
|
18
|
+
/** Disallowed dollar namespace path */
|
|
19
19
|
| "INVALID_SYS_PATH"
|
|
20
20
|
/** get.base is not var(item) */
|
|
21
21
|
| "UNSUPPORTED_BASE"
|
|
@@ -54,7 +54,7 @@ export declare function invalidKindForContext(kind: string, context: string, pat
|
|
|
54
54
|
*/
|
|
55
55
|
export declare function unknownCallFn(fn: string, path?: string[]): LoweringError;
|
|
56
56
|
/**
|
|
57
|
-
* Create a lowering error for invalid
|
|
57
|
+
* Create a lowering error for invalid dollar namespace path.
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
60
|
* throw invalidSysPath(["system", "uuid"]);
|
|
@@ -72,7 +72,7 @@ export interface MelRuntimePatch {
|
|
|
72
72
|
* Runtime ConditionalPatchOp for snapshot state mutations.
|
|
73
73
|
*
|
|
74
74
|
* This is the intermediate representation between Translator output
|
|
75
|
-
* and final concrete Patch[].
|
|
75
|
+
* and final concrete Patch[]. Callers must call evaluateRuntimePatches()
|
|
76
76
|
* to get concrete values.
|
|
77
77
|
*
|
|
78
78
|
* @see SPEC v0.4.0 §17.5, §20
|
package/dist/node-loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as n}from"./chunk-
|
|
1
|
+
import{c as n}from"./chunk-HOS3TLHW.js";import"./chunk-JYNK3VUK.js";import{readFile as i}from"fs/promises";import{fileURLToPath as c}from"url";function u(o){let[t]=o.split("?",1),[r]=t.split("#",1);return r}function s(o){return u(o).endsWith(".mel")}function a(o){try{return c(o)}catch{return o}}var h=async(o,t,r)=>s(o)?{...await r(o,t),shortCircuit:!0}:r(o,t),p=async(o,t,r)=>{if(!s(o))return r(o,t);let e=await i(new URL(o),"utf8");return{format:"module",source:n(e,a(o)),shortCircuit:!0}};export{p as load,h as resolve};
|
package/dist/parser/ast.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export interface AnnotationNode extends ASTNode {
|
|
|
47
47
|
/**
|
|
48
48
|
* Domain member types
|
|
49
49
|
*/
|
|
50
|
-
export type DomainMember = StateNode | ComputedNode | ActionNode | FlowDeclNode;
|
|
50
|
+
export type DomainMember = StateNode | ContextNode | ComputedNode | ActionNode | FlowDeclNode;
|
|
51
51
|
/**
|
|
52
52
|
* Type declaration (v0.3.3)
|
|
53
53
|
* Syntax: type Name = TypeExpr
|
|
@@ -75,6 +75,24 @@ export interface StateFieldNode extends ASTNode {
|
|
|
75
75
|
typeExpr: TypeExprNode;
|
|
76
76
|
initializer?: ExprNode;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Context block declaration.
|
|
80
|
+
*
|
|
81
|
+
* Declares the shape of direct-injected external context. Values are supplied
|
|
82
|
+
* by the runtime, so context fields do not carry initializers.
|
|
83
|
+
*/
|
|
84
|
+
export interface ContextNode extends ASTNode {
|
|
85
|
+
kind: "context";
|
|
86
|
+
fields: ContextFieldNode[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Context field declaration.
|
|
90
|
+
*/
|
|
91
|
+
export interface ContextFieldNode extends ASTNode {
|
|
92
|
+
kind: "contextField";
|
|
93
|
+
name: string;
|
|
94
|
+
typeExpr: TypeExprNode;
|
|
95
|
+
}
|
|
78
96
|
/**
|
|
79
97
|
* Computed value declaration
|
|
80
98
|
*/
|
|
@@ -271,7 +289,8 @@ export interface IdentifierExprNode extends ASTNode {
|
|
|
271
289
|
name: string;
|
|
272
290
|
}
|
|
273
291
|
/**
|
|
274
|
-
*
|
|
292
|
+
* Dollar namespace identifier expression ($runtime.*, $context.*, $input.*,
|
|
293
|
+
* retired $system/$meta).
|
|
275
294
|
*/
|
|
276
295
|
export interface SystemIdentExprNode extends ASTNode {
|
|
277
296
|
kind: "systemIdent";
|
package/dist/parser/parser.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export declare class Parser {
|
|
|
36
36
|
private parseDomainMember;
|
|
37
37
|
private parseState;
|
|
38
38
|
private parseStateField;
|
|
39
|
+
private parseContext;
|
|
40
|
+
private parseContextField;
|
|
39
41
|
private parseComputed;
|
|
40
42
|
private parseAction;
|
|
41
43
|
private parseFlowDecl;
|
|
@@ -89,6 +91,7 @@ export declare class Parser {
|
|
|
89
91
|
private check;
|
|
90
92
|
private isOnceIntentContext;
|
|
91
93
|
private isFlowDeclContext;
|
|
94
|
+
private isContextDeclContext;
|
|
92
95
|
private isIncludeContext;
|
|
93
96
|
private match;
|
|
94
97
|
private consume;
|
package/dist/rollup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-A356Y7I6.js";import"./chunk-HOS3TLHW.js";import"./chunk-JYNK3VUK.js";var l=e.rollup,t=l;export{t as default,l as melPlugin};
|
package/dist/rspack.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-A356Y7I6.js";import"./chunk-HOS3TLHW.js";import"./chunk-JYNK3VUK.js";var t=e.rspack,o=t;export{o as default,t as melPlugin};
|
package/dist/unplugin.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Single implementation that targets Vite, Webpack, Rollup, esbuild, and Rspack.
|
|
5
5
|
*/
|
|
6
|
-
import type { DomainSchema } from "
|
|
6
|
+
import type { DomainSchema } from "./generator/ir.js";
|
|
7
7
|
export type MelCodegenArtifact = {
|
|
8
8
|
readonly schema: DomainSchema;
|
|
9
9
|
readonly sourceId: string;
|
package/dist/vite.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-A356Y7I6.js";import"./chunk-HOS3TLHW.js";import"./chunk-JYNK3VUK.js";var t=e.vite,o=t;export{o as default,t as melPlugin};
|
package/dist/webpack.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-A356Y7I6.js";import"./chunk-HOS3TLHW.js";import"./chunk-JYNK3VUK.js";var t=e.webpack,o=t;export{o as default,t as melPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manifesto-ai/compiler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Manifesto Compiler - MEL (Manifesto Expression Language) to DomainSchema compiler",
|
|
5
5
|
"author": "eggplantiny <eggplantiny@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@anthropic-ai/sdk": "^0.26.0",
|
|
64
|
-
"@manifesto-ai/core": "^
|
|
64
|
+
"@manifesto-ai/core": "^5.0.0",
|
|
65
65
|
"openai": "^4.0.0",
|
|
66
66
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
67
67
|
"zod": "^4.3.6"
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"vitest": "^4.1.2",
|
|
98
98
|
"webpack": "^5.106.1",
|
|
99
99
|
"zod": "^4.3.6",
|
|
100
|
-
"@manifesto-ai/core": "
|
|
100
|
+
"@manifesto-ai/core": "5.0.0"
|
|
101
101
|
},
|
|
102
102
|
"files": [
|
|
103
103
|
"dist"
|