yaml-flow 3.1.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/README.md +81 -20
  2. package/board-live-cards-cli.js +37 -0
  3. package/browser/board-livegraph-runtime.js +1453 -0
  4. package/browser/board-livegraph-runtime.js.map +1 -0
  5. package/browser/card-compute.js +153 -433
  6. package/browser/live-cards.js +868 -115
  7. package/browser/live-cards.schema.json +90 -83
  8. package/dist/board-livegraph-runtime/index.cjs +1448 -0
  9. package/dist/board-livegraph-runtime/index.cjs.map +1 -0
  10. package/dist/board-livegraph-runtime/index.d.cts +101 -0
  11. package/dist/board-livegraph-runtime/index.d.ts +101 -0
  12. package/dist/board-livegraph-runtime/index.js +1441 -0
  13. package/dist/board-livegraph-runtime/index.js.map +1 -0
  14. package/dist/card-compute/index.cjs +266 -431
  15. package/dist/card-compute/index.cjs.map +1 -1
  16. package/dist/card-compute/index.d.cts +77 -49
  17. package/dist/card-compute/index.d.ts +77 -49
  18. package/dist/card-compute/index.js +263 -432
  19. package/dist/card-compute/index.js.map +1 -1
  20. package/dist/cli/board-live-cards-cli.cjs +2750 -0
  21. package/dist/cli/board-live-cards-cli.cjs.map +1 -0
  22. package/dist/cli/board-live-cards-cli.d.cts +205 -0
  23. package/dist/cli/board-live-cards-cli.d.ts +205 -0
  24. package/dist/cli/board-live-cards-cli.js +2702 -0
  25. package/dist/cli/board-live-cards-cli.js.map +1 -0
  26. package/dist/{constants-B2zqu10b.d.ts → constants-DuzE5n03.d.ts} +2 -2
  27. package/dist/{constants-DJZU1pwJ.d.cts → constants-ozjf1Ejw.d.cts} +2 -2
  28. package/dist/continuous-event-graph/index.cjs +258 -464
  29. package/dist/continuous-event-graph/index.cjs.map +1 -1
  30. package/dist/continuous-event-graph/index.d.cts +18 -358
  31. package/dist/continuous-event-graph/index.d.ts +18 -358
  32. package/dist/continuous-event-graph/index.js +255 -464
  33. package/dist/continuous-event-graph/index.js.map +1 -1
  34. package/dist/event-graph/index.cjs +4 -4
  35. package/dist/event-graph/index.cjs.map +1 -1
  36. package/dist/event-graph/index.d.cts +5 -5
  37. package/dist/event-graph/index.d.ts +5 -5
  38. package/dist/event-graph/index.js +4 -4
  39. package/dist/event-graph/index.js.map +1 -1
  40. package/dist/index.cjs +1684 -555
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +26 -7
  43. package/dist/index.d.ts +26 -7
  44. package/dist/index.js +1678 -555
  45. package/dist/index.js.map +1 -1
  46. package/dist/inference/index.cjs +138 -19
  47. package/dist/inference/index.cjs.map +1 -1
  48. package/dist/inference/index.d.cts +2 -2
  49. package/dist/inference/index.d.ts +2 -2
  50. package/dist/inference/index.js +138 -19
  51. package/dist/inference/index.js.map +1 -1
  52. package/dist/journal-DRfJiheM.d.cts +28 -0
  53. package/dist/journal-NLYuqege.d.ts +28 -0
  54. package/dist/live-cards-bridge-Or7fdEJV.d.ts +316 -0
  55. package/dist/live-cards-bridge-vGJ6tMzN.d.cts +316 -0
  56. package/dist/schedule-CMcZe5Ny.d.ts +21 -0
  57. package/dist/schedule-CiucyCan.d.cts +21 -0
  58. package/dist/step-machine/index.cjs +18 -1
  59. package/dist/step-machine/index.cjs.map +1 -1
  60. package/dist/step-machine/index.d.cts +2 -2
  61. package/dist/step-machine/index.d.ts +2 -2
  62. package/dist/step-machine/index.js +18 -1
  63. package/dist/step-machine/index.js.map +1 -1
  64. package/dist/stores/file.d.cts +1 -1
  65. package/dist/stores/file.d.ts +1 -1
  66. package/dist/stores/index.d.cts +1 -1
  67. package/dist/stores/index.d.ts +1 -1
  68. package/dist/stores/localStorage.d.cts +1 -1
  69. package/dist/stores/localStorage.d.ts +1 -1
  70. package/dist/stores/memory.d.cts +1 -1
  71. package/dist/stores/memory.d.ts +1 -1
  72. package/dist/{types-BwvgvlOO.d.cts → types-BzLD8bjb.d.cts} +1 -1
  73. package/dist/{types-ClRA8hzC.d.ts → types-C2eJ7DAV.d.ts} +1 -1
  74. package/dist/{types-DEj7OakX.d.cts → types-CMFSIjpc.d.cts} +39 -4
  75. package/dist/{types-DEj7OakX.d.ts → types-CMFSIjpc.d.ts} +39 -4
  76. package/dist/{types-FZ_eyErS.d.cts → types-ycun84cq.d.cts} +1 -0
  77. package/dist/{types-FZ_eyErS.d.ts → types-ycun84cq.d.ts} +1 -0
  78. package/dist/{validate-DEZ2Ymdb.d.ts → validate-DJQTQ6bP.d.ts} +1 -1
  79. package/dist/{validate-DqKTZg_o.d.cts → validate-ke92Cleg.d.cts} +1 -1
  80. package/examples/browser/boards/portfolio-tracker/cards/holdings-table.json +22 -0
  81. package/examples/browser/boards/portfolio-tracker/cards/portfolio-form.json +16 -0
  82. package/examples/browser/boards/portfolio-tracker/cards/portfolio-value.json +15 -0
  83. package/examples/browser/boards/portfolio-tracker/cards/price-fetch.json +15 -0
  84. package/examples/browser/boards/portfolio-tracker/fetch-prices.js +43 -0
  85. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-task-executor.cjs +96 -0
  86. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.bat +7 -0
  87. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.js +217 -0
  88. package/examples/browser/livecards-browser/index.html +41 -0
  89. package/examples/browser/{index.html → step-machine-browser/index.html} +53 -53
  90. package/examples/cli/step-machine-cli/portfolio-tracker/cards/holdings-table.json +22 -0
  91. package/examples/cli/step-machine-cli/portfolio-tracker/cards/portfolio-form.json +43 -0
  92. package/examples/cli/step-machine-cli/portfolio-tracker/cards/portfolio-value.json +15 -0
  93. package/examples/cli/step-machine-cli/portfolio-tracker/cards/price-fetch.json +15 -0
  94. package/examples/cli/step-machine-cli/portfolio-tracker/fetch-prices.js +48 -0
  95. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +58 -0
  96. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +27 -0
  97. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +25 -0
  98. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +29 -0
  99. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +27 -0
  100. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/status-cli.js +25 -0
  101. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +37 -0
  102. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +53 -0
  103. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +35 -0
  104. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +227 -0
  105. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.input.json +38 -0
  106. package/examples/cli/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +29 -0
  107. package/examples/cli/step-machine-demo/jsonata-init-board-cli.js +36 -0
  108. package/examples/cli/step-machine-demo/jsonata-init-board.flow.yaml +30 -0
  109. package/examples/cli/step-machine-demo/one-step-cli-only.flow.yaml +19 -0
  110. package/examples/cli/step-machine-demo/step-cli-echo-y.js +15 -0
  111. package/examples/cli/step-machine-demo/step2-double-cli.js +39 -0
  112. package/examples/cli/step-machine-demo/two-step-math-handlers.js +32 -0
  113. package/examples/cli/step-machine-demo/two-step-math.flow.yaml +31 -0
  114. package/examples/cli/step-machine-demo/two-step-mixed-handlers.js +24 -0
  115. package/examples/cli/step-machine-demo/two-step-mixed.flow.yaml +35 -0
  116. package/examples/example-board/board.yaml +23 -0
  117. package/examples/example-board/bootstrap_payload.json +1 -0
  118. package/examples/example-board/cards/card-chain-region-alert.json +39 -0
  119. package/examples/example-board/cards/card-chain-region-totals.json +26 -0
  120. package/examples/example-board/cards/card-chain-top-region.json +24 -0
  121. package/examples/example-board/cards/card-ex-actions.json +32 -0
  122. package/examples/example-board/cards/card-ex-chart.json +30 -0
  123. package/examples/example-board/cards/card-ex-filter.json +36 -0
  124. package/examples/example-board/cards/card-ex-filtered-by-preference.json +59 -0
  125. package/examples/example-board/cards/card-ex-form.json +91 -0
  126. package/examples/example-board/cards/card-ex-list.json +22 -0
  127. package/examples/example-board/cards/card-ex-markdown.json +17 -0
  128. package/examples/example-board/cards/card-ex-metric.json +19 -0
  129. package/examples/example-board/cards/card-ex-narrative.json +36 -0
  130. package/examples/example-board/cards/card-ex-source-http.json +28 -0
  131. package/examples/example-board/cards/card-ex-source.json +21 -0
  132. package/examples/example-board/cards/card-ex-status.json +35 -0
  133. package/examples/example-board/cards/card-ex-table.json +30 -0
  134. package/examples/example-board/cards/card-ex-todo.json +29 -0
  135. package/examples/example-board/demo-chat-handler.js +69 -0
  136. package/examples/example-board/demo-server.js +87 -0
  137. package/examples/example-board/demo-shell-browser.html +806 -0
  138. package/examples/example-board/demo-shell-with-server.html +280 -0
  139. package/examples/example-board/demo-shell.html +62 -0
  140. package/examples/example-board/demo-task-executor.js +255 -0
  141. package/examples/example-board/mock.db +15 -0
  142. package/examples/example-board/reusable-board-runtime-client.js +265 -0
  143. package/examples/example-board/reusable-runtime-artifacts-adapter.js +233 -0
  144. package/examples/example-board/reusable-server-runtime.js +1284 -0
  145. package/examples/index.html +799 -0
  146. package/examples/{batch → npm-libs/batch}/batch-step-machine.ts +1 -1
  147. package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/live-cards-board.ts +18 -18
  148. package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/live-portfolio-dashboard.ts +24 -24
  149. package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/portfolio-tracker.ts +1 -1
  150. package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/reactive-monitoring.ts +1 -1
  151. package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/reactive-pipeline.ts +1 -1
  152. package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/soc-incident-board.ts +1 -1
  153. package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/stock-dashboard.ts +1 -1
  154. package/examples/{event-graph → npm-libs/event-graph}/ci-cd-pipeline.ts +1 -1
  155. package/examples/{event-graph → npm-libs/event-graph}/executor-diamond.ts +1 -1
  156. package/examples/{event-graph → npm-libs/event-graph}/executor-pipeline.ts +1 -1
  157. package/examples/{event-graph → npm-libs/event-graph}/research-pipeline.ts +1 -1
  158. package/examples/{graph-of-graphs → npm-libs/graph-of-graphs}/multi-stage-etl.ts +1 -1
  159. package/examples/{graph-of-graphs → npm-libs/graph-of-graphs}/url-processing-pipeline.ts +1 -1
  160. package/examples/{inference → npm-libs/inference}/azure-deployment.ts +1 -1
  161. package/examples/{inference → npm-libs/inference}/copilot-cli.ts +1 -1
  162. package/examples/{inference → npm-libs/inference}/data-pipeline.ts +1 -1
  163. package/examples/{inference → npm-libs/inference}/pluggable-adapters.ts +1 -1
  164. package/examples/{node → npm-libs/node}/ai-conversation.ts +1 -1
  165. package/examples/{node → npm-libs/node}/simple-greeting.ts +2 -2
  166. package/examples/step-machine-cli/portfolio-tracker/cards/holdings-table.json +22 -0
  167. package/examples/step-machine-cli/portfolio-tracker/cards/portfolio-form.json +43 -0
  168. package/examples/step-machine-cli/portfolio-tracker/cards/portfolio-value.json +15 -0
  169. package/examples/step-machine-cli/portfolio-tracker/cards/price-fetch.json +15 -0
  170. package/examples/step-machine-cli/portfolio-tracker/fetch-prices.js +48 -0
  171. package/examples/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +58 -0
  172. package/examples/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +27 -0
  173. package/examples/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +25 -0
  174. package/examples/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +29 -0
  175. package/examples/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +27 -0
  176. package/examples/step-machine-cli/portfolio-tracker/handlers/status-cli.js +25 -0
  177. package/examples/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +37 -0
  178. package/examples/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +53 -0
  179. package/examples/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +35 -0
  180. package/examples/step-machine-cli/portfolio-tracker/portfolio-tracker-task-executor.cjs +96 -0
  181. package/examples/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +227 -0
  182. package/examples/step-machine-cli/portfolio-tracker/portfolio-tracker.input.json +38 -0
  183. package/examples/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +29 -0
  184. package/package.json +27 -2
  185. package/schema/board-status.schema.json +118 -0
  186. package/schema/card-runtime.schema.json +25 -0
  187. package/schema/flow.schema.json +5 -0
  188. package/schema/live-cards.schema.json +90 -83
  189. package/step-machine-cli.js +674 -0
  190. package/browser/ingest-board.js +0 -296
  191. package/examples/ingest.js +0 -733
  192. /package/examples/{flows → npm-libs/flows}/ai-conversation.yaml +0 -0
  193. /package/examples/{flows → npm-libs/flows}/order-processing.yaml +0 -0
  194. /package/examples/{flows → npm-libs/flows}/simple-greeting.yaml +0 -0
@@ -20,12 +20,23 @@
20
20
  * Returns the same `ValidationResult` shape as `CardCompute.validate()`.
21
21
  */
22
22
  declare function validateLiveCardSchema(node: unknown): ValidationResult;
23
+ /**
24
+ * Validate JSONata expressions in compute[] by compiling with the same parser used at runtime.
25
+ */
26
+ declare function validateLiveCardRuntimeExpressions(node: unknown): ValidationResult;
27
+ declare function validateLiveCard(node: unknown): ValidationResult;
28
+ /**
29
+ * Full validation for live card definitions:
30
+ * 1) JSON Schema structure/contract checks
31
+ * 2) Runtime JSONata parser compatibility checks for compute expressions
32
+ */
33
+ declare function validateLiveCardDefinition(node: unknown): ValidationResult;
23
34
 
24
35
  /**
25
- * card-compute — Pure JSON expression evaluator for node-based cards.
36
+ * card-compute — JSONata-powered compute engine for LiveCards nodes.
26
37
  *
27
38
  * Isomorphic: works in browser, Node.js, and bundlers.
28
- * No DOM dependency. No eval(). Pure declarative JSON expressions.
39
+ * No DOM dependency. Compute expressions are JSONata strings.
29
40
  *
30
41
  * @example
31
42
  * ```typescript
@@ -33,76 +44,93 @@ declare function validateLiveCardSchema(node: unknown): ValidationResult;
33
44
  *
34
45
  * const node = {
35
46
  * id: 'sales',
36
- * state: { data: [{ revenue: 100 }, { revenue: 200 }] },
37
- * compute: {
38
- * total: { fn: 'sum', input: 'state.data', field: 'revenue' },
39
- * avg: { fn: 'avg', input: 'state.data', field: 'revenue' },
40
- * },
47
+ * card_data: { data: [{ revenue: 100 }, { revenue: 200 }] },
48
+ * compute: [
49
+ * { bindTo: 'total', expr: '$sum(card_data.data.revenue)' },
50
+ * { bindTo: 'avg', expr: '$average(card_data.data.revenue)' },
51
+ * ],
41
52
  * };
42
- * CardCompute.run(node);
43
- * // node.state.total === 300
44
- * // node.state.avg === 150
53
+ * await CardCompute.run(node);
54
+ * // node.computed_values.total === 300
55
+ * // node.computed_values.avg === 150
45
56
  * ```
57
+ *
58
+ * Expressions are evaluated against { card_data, requires, fetched_sources, computed_values }.
59
+ * computed_values is ephemeral — never persisted to disk.
46
60
  */
47
- /** A compute expression pure JSON, arbitrarily nestable. */
48
- interface ComputeExpr {
49
- fn: string;
50
- input?: string | number | boolean | ComputeExpr | (string | number | boolean | ComputeExpr)[];
51
- field?: string;
52
- where?: ComputeExpr;
53
- apply?: ComputeExpr;
54
- cond?: ComputeExpr;
55
- then?: unknown;
56
- else?: unknown;
57
- format?: string;
58
- decimals?: number;
59
- separator?: string;
60
- direction?: 'asc' | 'desc';
61
- start?: number;
62
- end?: number;
63
- depth?: number;
64
- path?: string;
65
- value?: unknown;
61
+ /** A source definition: cli writes to outputFile; bindTo names the fetched_sources.* key in compute context. */
62
+ interface ComputeSource {
63
+ bindTo: string;
64
+ outputFile?: string;
65
+ cli?: string;
66
+ script?: string;
67
+ optionalForCompletionGating?: boolean;
66
68
  [key: string]: unknown;
67
69
  }
70
+ /** Options for CardCompute.run() */
71
+ interface RunOptions {
72
+ /** Pre-loaded source results map (keyed by bindTo). Use in browser or when caller loads files. */
73
+ sourcesData?: Record<string, unknown>;
74
+ }
75
+ /** A single compute step: bindTo names the computed_values key; expr is a JSONata expression. */
76
+ interface ComputeStep {
77
+ bindTo: string;
78
+ expr: string;
79
+ }
68
80
  /** Minimal node shape expected by CardCompute. */
69
81
  interface ComputeNode {
70
82
  id?: string;
71
- state?: Record<string, unknown>;
72
- compute?: Record<string, ComputeExpr>;
83
+ card_data?: Record<string, unknown>;
84
+ requires?: Record<string, unknown>;
85
+ sources?: ComputeSource[];
86
+ compute?: ComputeStep[];
87
+ computed_values?: Record<string, unknown>;
88
+ /** Ephemeral: populated by run() from sourcesData option. Never persisted. */
89
+ _sourcesData?: Record<string, unknown>;
73
90
  [key: string]: unknown;
74
91
  }
75
- /** Internal evaluator signature passed to compute functions. */
76
- type EvalFn = (expr: unknown, node: ComputeNode) => unknown;
77
- /** A compute function implementation. */
78
- type ComputeFn = (input: unknown, evalFn: EvalFn, opts: ComputeExpr) => unknown;
79
- declare function evalExpr(expr: unknown, node: ComputeNode): unknown;
80
- declare function run(node: ComputeNode): ComputeNode;
92
+ /**
93
+ * Run all compute steps on a node.
94
+ * Each step's expr is evaluated against { card_data, requires, fetched_sources, computed_values }.
95
+ * Results are written to node.computed_values[bindTo].
96
+ * computed_values and _sourcesData are reset on each call — ephemeral, never persisted.
97
+ *
98
+ * @param options.sourcesData Pre-loaded map of { [bindTo]: data } for fetched_sources namespace.
99
+ * In Node/CLI: loaded from outputFiles by the caller (card-handler).
100
+ * In browser: passed in by the caller (e.g. from fetch results).
101
+ */
102
+ declare function run(node: ComputeNode, options?: RunOptions): Promise<ComputeNode>;
103
+ /**
104
+ * Evaluate a single JSONata expression against a node's context.
105
+ * Context is { card_data, requires, fetched_sources, computed_values }.
106
+ */
107
+ declare function evalExpr(expr: string, node: ComputeNode): Promise<unknown>;
81
108
  declare function resolve(node: ComputeNode, path: string): unknown;
82
- declare function registerFunction(name: string, fn: ComputeFn): void;
83
109
  /** Result of validateNode — ok: true means valid, ok: false has errors[]. */
84
110
  interface ValidationResult {
85
111
  ok: boolean;
86
112
  errors: string[];
87
113
  }
114
+ declare function validateNode(node: unknown): ValidationResult;
88
115
  /**
89
- * Validate a node against the LiveCards schema.
90
- * Lightweight structural check no external dependencies.
116
+ * Enrich sources with execution context for template interpolation and prompt rendering.
117
+ * Pure function: no side effects, returns new enriched sources array.
91
118
  *
92
- * @example
93
- * ```typescript
94
- * const result = CardCompute.validate(node);
95
- * if (!result.ok) console.error(result.errors);
96
- * ```
119
+ * @param sources - Array of source definitions
120
+ * @param context - Execution context containing requires, sourcesData, computed_values
121
+ * @returns New array of sources with _requires, _sourcesData, _computed_values attached
97
122
  */
98
- declare function validateNode(node: unknown): ValidationResult;
123
+ declare function enrichSources(sources: any[] | undefined, context: {
124
+ requires?: Record<string, any>;
125
+ sourcesData?: Record<string, any>;
126
+ computed_values?: Record<string, any>;
127
+ }): any[];
99
128
  declare const CardCompute: {
100
129
  run: typeof run;
101
130
  eval: typeof evalExpr;
102
131
  resolve: typeof resolve;
103
132
  validate: typeof validateNode;
104
- registerFunction: typeof registerFunction;
105
- readonly functions: Record<string, ComputeFn>;
133
+ enrichSources: typeof enrichSources;
106
134
  };
107
135
 
108
- export { CardCompute, type ComputeExpr, type ComputeFn, type ComputeNode, type EvalFn, type ValidationResult, CardCompute as default, validateLiveCardSchema };
136
+ export { CardCompute, type ComputeNode, type ComputeSource, type ComputeStep, type RunOptions, type ValidationResult, CardCompute as default, validateLiveCard, validateLiveCardDefinition, validateLiveCardRuntimeExpressions, validateLiveCardSchema };
@@ -20,12 +20,23 @@
20
20
  * Returns the same `ValidationResult` shape as `CardCompute.validate()`.
21
21
  */
22
22
  declare function validateLiveCardSchema(node: unknown): ValidationResult;
23
+ /**
24
+ * Validate JSONata expressions in compute[] by compiling with the same parser used at runtime.
25
+ */
26
+ declare function validateLiveCardRuntimeExpressions(node: unknown): ValidationResult;
27
+ declare function validateLiveCard(node: unknown): ValidationResult;
28
+ /**
29
+ * Full validation for live card definitions:
30
+ * 1) JSON Schema structure/contract checks
31
+ * 2) Runtime JSONata parser compatibility checks for compute expressions
32
+ */
33
+ declare function validateLiveCardDefinition(node: unknown): ValidationResult;
23
34
 
24
35
  /**
25
- * card-compute — Pure JSON expression evaluator for node-based cards.
36
+ * card-compute — JSONata-powered compute engine for LiveCards nodes.
26
37
  *
27
38
  * Isomorphic: works in browser, Node.js, and bundlers.
28
- * No DOM dependency. No eval(). Pure declarative JSON expressions.
39
+ * No DOM dependency. Compute expressions are JSONata strings.
29
40
  *
30
41
  * @example
31
42
  * ```typescript
@@ -33,76 +44,93 @@ declare function validateLiveCardSchema(node: unknown): ValidationResult;
33
44
  *
34
45
  * const node = {
35
46
  * id: 'sales',
36
- * state: { data: [{ revenue: 100 }, { revenue: 200 }] },
37
- * compute: {
38
- * total: { fn: 'sum', input: 'state.data', field: 'revenue' },
39
- * avg: { fn: 'avg', input: 'state.data', field: 'revenue' },
40
- * },
47
+ * card_data: { data: [{ revenue: 100 }, { revenue: 200 }] },
48
+ * compute: [
49
+ * { bindTo: 'total', expr: '$sum(card_data.data.revenue)' },
50
+ * { bindTo: 'avg', expr: '$average(card_data.data.revenue)' },
51
+ * ],
41
52
  * };
42
- * CardCompute.run(node);
43
- * // node.state.total === 300
44
- * // node.state.avg === 150
53
+ * await CardCompute.run(node);
54
+ * // node.computed_values.total === 300
55
+ * // node.computed_values.avg === 150
45
56
  * ```
57
+ *
58
+ * Expressions are evaluated against { card_data, requires, fetched_sources, computed_values }.
59
+ * computed_values is ephemeral — never persisted to disk.
46
60
  */
47
- /** A compute expression pure JSON, arbitrarily nestable. */
48
- interface ComputeExpr {
49
- fn: string;
50
- input?: string | number | boolean | ComputeExpr | (string | number | boolean | ComputeExpr)[];
51
- field?: string;
52
- where?: ComputeExpr;
53
- apply?: ComputeExpr;
54
- cond?: ComputeExpr;
55
- then?: unknown;
56
- else?: unknown;
57
- format?: string;
58
- decimals?: number;
59
- separator?: string;
60
- direction?: 'asc' | 'desc';
61
- start?: number;
62
- end?: number;
63
- depth?: number;
64
- path?: string;
65
- value?: unknown;
61
+ /** A source definition: cli writes to outputFile; bindTo names the fetched_sources.* key in compute context. */
62
+ interface ComputeSource {
63
+ bindTo: string;
64
+ outputFile?: string;
65
+ cli?: string;
66
+ script?: string;
67
+ optionalForCompletionGating?: boolean;
66
68
  [key: string]: unknown;
67
69
  }
70
+ /** Options for CardCompute.run() */
71
+ interface RunOptions {
72
+ /** Pre-loaded source results map (keyed by bindTo). Use in browser or when caller loads files. */
73
+ sourcesData?: Record<string, unknown>;
74
+ }
75
+ /** A single compute step: bindTo names the computed_values key; expr is a JSONata expression. */
76
+ interface ComputeStep {
77
+ bindTo: string;
78
+ expr: string;
79
+ }
68
80
  /** Minimal node shape expected by CardCompute. */
69
81
  interface ComputeNode {
70
82
  id?: string;
71
- state?: Record<string, unknown>;
72
- compute?: Record<string, ComputeExpr>;
83
+ card_data?: Record<string, unknown>;
84
+ requires?: Record<string, unknown>;
85
+ sources?: ComputeSource[];
86
+ compute?: ComputeStep[];
87
+ computed_values?: Record<string, unknown>;
88
+ /** Ephemeral: populated by run() from sourcesData option. Never persisted. */
89
+ _sourcesData?: Record<string, unknown>;
73
90
  [key: string]: unknown;
74
91
  }
75
- /** Internal evaluator signature passed to compute functions. */
76
- type EvalFn = (expr: unknown, node: ComputeNode) => unknown;
77
- /** A compute function implementation. */
78
- type ComputeFn = (input: unknown, evalFn: EvalFn, opts: ComputeExpr) => unknown;
79
- declare function evalExpr(expr: unknown, node: ComputeNode): unknown;
80
- declare function run(node: ComputeNode): ComputeNode;
92
+ /**
93
+ * Run all compute steps on a node.
94
+ * Each step's expr is evaluated against { card_data, requires, fetched_sources, computed_values }.
95
+ * Results are written to node.computed_values[bindTo].
96
+ * computed_values and _sourcesData are reset on each call — ephemeral, never persisted.
97
+ *
98
+ * @param options.sourcesData Pre-loaded map of { [bindTo]: data } for fetched_sources namespace.
99
+ * In Node/CLI: loaded from outputFiles by the caller (card-handler).
100
+ * In browser: passed in by the caller (e.g. from fetch results).
101
+ */
102
+ declare function run(node: ComputeNode, options?: RunOptions): Promise<ComputeNode>;
103
+ /**
104
+ * Evaluate a single JSONata expression against a node's context.
105
+ * Context is { card_data, requires, fetched_sources, computed_values }.
106
+ */
107
+ declare function evalExpr(expr: string, node: ComputeNode): Promise<unknown>;
81
108
  declare function resolve(node: ComputeNode, path: string): unknown;
82
- declare function registerFunction(name: string, fn: ComputeFn): void;
83
109
  /** Result of validateNode — ok: true means valid, ok: false has errors[]. */
84
110
  interface ValidationResult {
85
111
  ok: boolean;
86
112
  errors: string[];
87
113
  }
114
+ declare function validateNode(node: unknown): ValidationResult;
88
115
  /**
89
- * Validate a node against the LiveCards schema.
90
- * Lightweight structural check no external dependencies.
116
+ * Enrich sources with execution context for template interpolation and prompt rendering.
117
+ * Pure function: no side effects, returns new enriched sources array.
91
118
  *
92
- * @example
93
- * ```typescript
94
- * const result = CardCompute.validate(node);
95
- * if (!result.ok) console.error(result.errors);
96
- * ```
119
+ * @param sources - Array of source definitions
120
+ * @param context - Execution context containing requires, sourcesData, computed_values
121
+ * @returns New array of sources with _requires, _sourcesData, _computed_values attached
97
122
  */
98
- declare function validateNode(node: unknown): ValidationResult;
123
+ declare function enrichSources(sources: any[] | undefined, context: {
124
+ requires?: Record<string, any>;
125
+ sourcesData?: Record<string, any>;
126
+ computed_values?: Record<string, any>;
127
+ }): any[];
99
128
  declare const CardCompute: {
100
129
  run: typeof run;
101
130
  eval: typeof evalExpr;
102
131
  resolve: typeof resolve;
103
132
  validate: typeof validateNode;
104
- registerFunction: typeof registerFunction;
105
- readonly functions: Record<string, ComputeFn>;
133
+ enrichSources: typeof enrichSources;
106
134
  };
107
135
 
108
- export { CardCompute, type ComputeExpr, type ComputeFn, type ComputeNode, type EvalFn, type ValidationResult, CardCompute as default, validateLiveCardSchema };
136
+ export { CardCompute, type ComputeNode, type ComputeSource, type ComputeStep, type RunOptions, type ValidationResult, CardCompute as default, validateLiveCard, validateLiveCardDefinition, validateLiveCardRuntimeExpressions, validateLiveCardSchema };