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.
- package/README.md +81 -20
- package/board-live-cards-cli.js +37 -0
- package/browser/board-livegraph-runtime.js +1453 -0
- package/browser/board-livegraph-runtime.js.map +1 -0
- package/browser/card-compute.js +153 -433
- package/browser/live-cards.js +868 -115
- package/browser/live-cards.schema.json +90 -83
- package/dist/board-livegraph-runtime/index.cjs +1448 -0
- package/dist/board-livegraph-runtime/index.cjs.map +1 -0
- package/dist/board-livegraph-runtime/index.d.cts +101 -0
- package/dist/board-livegraph-runtime/index.d.ts +101 -0
- package/dist/board-livegraph-runtime/index.js +1441 -0
- package/dist/board-livegraph-runtime/index.js.map +1 -0
- package/dist/card-compute/index.cjs +266 -431
- package/dist/card-compute/index.cjs.map +1 -1
- package/dist/card-compute/index.d.cts +77 -49
- package/dist/card-compute/index.d.ts +77 -49
- package/dist/card-compute/index.js +263 -432
- package/dist/card-compute/index.js.map +1 -1
- package/dist/cli/board-live-cards-cli.cjs +2750 -0
- package/dist/cli/board-live-cards-cli.cjs.map +1 -0
- package/dist/cli/board-live-cards-cli.d.cts +205 -0
- package/dist/cli/board-live-cards-cli.d.ts +205 -0
- package/dist/cli/board-live-cards-cli.js +2702 -0
- package/dist/cli/board-live-cards-cli.js.map +1 -0
- package/dist/{constants-B2zqu10b.d.ts → constants-DuzE5n03.d.ts} +2 -2
- package/dist/{constants-DJZU1pwJ.d.cts → constants-ozjf1Ejw.d.cts} +2 -2
- package/dist/continuous-event-graph/index.cjs +258 -464
- package/dist/continuous-event-graph/index.cjs.map +1 -1
- package/dist/continuous-event-graph/index.d.cts +18 -358
- package/dist/continuous-event-graph/index.d.ts +18 -358
- package/dist/continuous-event-graph/index.js +255 -464
- package/dist/continuous-event-graph/index.js.map +1 -1
- package/dist/event-graph/index.cjs +4 -4
- package/dist/event-graph/index.cjs.map +1 -1
- package/dist/event-graph/index.d.cts +5 -5
- package/dist/event-graph/index.d.ts +5 -5
- package/dist/event-graph/index.js +4 -4
- package/dist/event-graph/index.js.map +1 -1
- package/dist/index.cjs +1684 -555
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +1678 -555
- package/dist/index.js.map +1 -1
- package/dist/inference/index.cjs +138 -19
- package/dist/inference/index.cjs.map +1 -1
- package/dist/inference/index.d.cts +2 -2
- package/dist/inference/index.d.ts +2 -2
- package/dist/inference/index.js +138 -19
- package/dist/inference/index.js.map +1 -1
- package/dist/journal-DRfJiheM.d.cts +28 -0
- package/dist/journal-NLYuqege.d.ts +28 -0
- package/dist/live-cards-bridge-Or7fdEJV.d.ts +316 -0
- package/dist/live-cards-bridge-vGJ6tMzN.d.cts +316 -0
- package/dist/schedule-CMcZe5Ny.d.ts +21 -0
- package/dist/schedule-CiucyCan.d.cts +21 -0
- package/dist/step-machine/index.cjs +18 -1
- package/dist/step-machine/index.cjs.map +1 -1
- package/dist/step-machine/index.d.cts +2 -2
- package/dist/step-machine/index.d.ts +2 -2
- package/dist/step-machine/index.js +18 -1
- package/dist/step-machine/index.js.map +1 -1
- package/dist/stores/file.d.cts +1 -1
- package/dist/stores/file.d.ts +1 -1
- package/dist/stores/index.d.cts +1 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/localStorage.d.cts +1 -1
- package/dist/stores/localStorage.d.ts +1 -1
- package/dist/stores/memory.d.cts +1 -1
- package/dist/stores/memory.d.ts +1 -1
- package/dist/{types-BwvgvlOO.d.cts → types-BzLD8bjb.d.cts} +1 -1
- package/dist/{types-ClRA8hzC.d.ts → types-C2eJ7DAV.d.ts} +1 -1
- package/dist/{types-DEj7OakX.d.cts → types-CMFSIjpc.d.cts} +39 -4
- package/dist/{types-DEj7OakX.d.ts → types-CMFSIjpc.d.ts} +39 -4
- package/dist/{types-FZ_eyErS.d.cts → types-ycun84cq.d.cts} +1 -0
- package/dist/{types-FZ_eyErS.d.ts → types-ycun84cq.d.ts} +1 -0
- package/dist/{validate-DEZ2Ymdb.d.ts → validate-DJQTQ6bP.d.ts} +1 -1
- package/dist/{validate-DqKTZg_o.d.cts → validate-ke92Cleg.d.cts} +1 -1
- package/examples/browser/boards/portfolio-tracker/cards/holdings-table.json +22 -0
- package/examples/browser/boards/portfolio-tracker/cards/portfolio-form.json +16 -0
- package/examples/browser/boards/portfolio-tracker/cards/portfolio-value.json +15 -0
- package/examples/browser/boards/portfolio-tracker/cards/price-fetch.json +15 -0
- package/examples/browser/boards/portfolio-tracker/fetch-prices.js +43 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-task-executor.cjs +96 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker.bat +7 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker.js +217 -0
- package/examples/browser/livecards-browser/index.html +41 -0
- package/examples/browser/{index.html → step-machine-browser/index.html} +53 -53
- package/examples/cli/step-machine-cli/portfolio-tracker/cards/holdings-table.json +22 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/cards/portfolio-form.json +43 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/cards/portfolio-value.json +15 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/cards/price-fetch.json +15 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/fetch-prices.js +48 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +58 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +27 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +25 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +29 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +27 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/status-cli.js +25 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +37 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +53 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +35 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +227 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.input.json +38 -0
- package/examples/cli/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +29 -0
- package/examples/cli/step-machine-demo/jsonata-init-board-cli.js +36 -0
- package/examples/cli/step-machine-demo/jsonata-init-board.flow.yaml +30 -0
- package/examples/cli/step-machine-demo/one-step-cli-only.flow.yaml +19 -0
- package/examples/cli/step-machine-demo/step-cli-echo-y.js +15 -0
- package/examples/cli/step-machine-demo/step2-double-cli.js +39 -0
- package/examples/cli/step-machine-demo/two-step-math-handlers.js +32 -0
- package/examples/cli/step-machine-demo/two-step-math.flow.yaml +31 -0
- package/examples/cli/step-machine-demo/two-step-mixed-handlers.js +24 -0
- package/examples/cli/step-machine-demo/two-step-mixed.flow.yaml +35 -0
- package/examples/example-board/board.yaml +23 -0
- package/examples/example-board/bootstrap_payload.json +1 -0
- package/examples/example-board/cards/card-chain-region-alert.json +39 -0
- package/examples/example-board/cards/card-chain-region-totals.json +26 -0
- package/examples/example-board/cards/card-chain-top-region.json +24 -0
- package/examples/example-board/cards/card-ex-actions.json +32 -0
- package/examples/example-board/cards/card-ex-chart.json +30 -0
- package/examples/example-board/cards/card-ex-filter.json +36 -0
- package/examples/example-board/cards/card-ex-filtered-by-preference.json +59 -0
- package/examples/example-board/cards/card-ex-form.json +91 -0
- package/examples/example-board/cards/card-ex-list.json +22 -0
- package/examples/example-board/cards/card-ex-markdown.json +17 -0
- package/examples/example-board/cards/card-ex-metric.json +19 -0
- package/examples/example-board/cards/card-ex-narrative.json +36 -0
- package/examples/example-board/cards/card-ex-source-http.json +28 -0
- package/examples/example-board/cards/card-ex-source.json +21 -0
- package/examples/example-board/cards/card-ex-status.json +35 -0
- package/examples/example-board/cards/card-ex-table.json +30 -0
- package/examples/example-board/cards/card-ex-todo.json +29 -0
- package/examples/example-board/demo-chat-handler.js +69 -0
- package/examples/example-board/demo-server.js +87 -0
- package/examples/example-board/demo-shell-browser.html +806 -0
- package/examples/example-board/demo-shell-with-server.html +280 -0
- package/examples/example-board/demo-shell.html +62 -0
- package/examples/example-board/demo-task-executor.js +255 -0
- package/examples/example-board/mock.db +15 -0
- package/examples/example-board/reusable-board-runtime-client.js +265 -0
- package/examples/example-board/reusable-runtime-artifacts-adapter.js +233 -0
- package/examples/example-board/reusable-server-runtime.js +1284 -0
- package/examples/index.html +799 -0
- package/examples/{batch → npm-libs/batch}/batch-step-machine.ts +1 -1
- package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/live-cards-board.ts +18 -18
- package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/live-portfolio-dashboard.ts +24 -24
- package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/portfolio-tracker.ts +1 -1
- package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/reactive-monitoring.ts +1 -1
- package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/reactive-pipeline.ts +1 -1
- package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/soc-incident-board.ts +1 -1
- package/examples/{continuous-event-graph → npm-libs/continuous-event-graph}/stock-dashboard.ts +1 -1
- package/examples/{event-graph → npm-libs/event-graph}/ci-cd-pipeline.ts +1 -1
- package/examples/{event-graph → npm-libs/event-graph}/executor-diamond.ts +1 -1
- package/examples/{event-graph → npm-libs/event-graph}/executor-pipeline.ts +1 -1
- package/examples/{event-graph → npm-libs/event-graph}/research-pipeline.ts +1 -1
- package/examples/{graph-of-graphs → npm-libs/graph-of-graphs}/multi-stage-etl.ts +1 -1
- package/examples/{graph-of-graphs → npm-libs/graph-of-graphs}/url-processing-pipeline.ts +1 -1
- package/examples/{inference → npm-libs/inference}/azure-deployment.ts +1 -1
- package/examples/{inference → npm-libs/inference}/copilot-cli.ts +1 -1
- package/examples/{inference → npm-libs/inference}/data-pipeline.ts +1 -1
- package/examples/{inference → npm-libs/inference}/pluggable-adapters.ts +1 -1
- package/examples/{node → npm-libs/node}/ai-conversation.ts +1 -1
- package/examples/{node → npm-libs/node}/simple-greeting.ts +2 -2
- package/examples/step-machine-cli/portfolio-tracker/cards/holdings-table.json +22 -0
- package/examples/step-machine-cli/portfolio-tracker/cards/portfolio-form.json +43 -0
- package/examples/step-machine-cli/portfolio-tracker/cards/portfolio-value.json +15 -0
- package/examples/step-machine-cli/portfolio-tracker/cards/price-fetch.json +15 -0
- package/examples/step-machine-cli/portfolio-tracker/fetch-prices.js +48 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +58 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +27 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +25 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +29 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +27 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/status-cli.js +25 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +37 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +53 -0
- package/examples/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +35 -0
- package/examples/step-machine-cli/portfolio-tracker/portfolio-tracker-task-executor.cjs +96 -0
- package/examples/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +227 -0
- package/examples/step-machine-cli/portfolio-tracker/portfolio-tracker.input.json +38 -0
- package/examples/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +29 -0
- package/package.json +27 -2
- package/schema/board-status.schema.json +118 -0
- package/schema/card-runtime.schema.json +25 -0
- package/schema/flow.schema.json +5 -0
- package/schema/live-cards.schema.json +90 -83
- package/step-machine-cli.js +674 -0
- package/browser/ingest-board.js +0 -296
- package/examples/ingest.js +0 -733
- /package/examples/{flows → npm-libs/flows}/ai-conversation.yaml +0 -0
- /package/examples/{flows → npm-libs/flows}/order-processing.yaml +0 -0
- /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 —
|
|
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.
|
|
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
|
-
*
|
|
37
|
-
* compute:
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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.
|
|
44
|
-
* // node.
|
|
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
|
|
48
|
-
interface
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
*
|
|
90
|
-
*
|
|
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
|
-
* @
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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
|
|
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
|
-
|
|
105
|
-
readonly functions: Record<string, ComputeFn>;
|
|
133
|
+
enrichSources: typeof enrichSources;
|
|
106
134
|
};
|
|
107
135
|
|
|
108
|
-
export { CardCompute, type
|
|
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 —
|
|
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.
|
|
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
|
-
*
|
|
37
|
-
* compute:
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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.
|
|
44
|
-
* // node.
|
|
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
|
|
48
|
-
interface
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
*
|
|
90
|
-
*
|
|
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
|
-
* @
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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
|
|
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
|
-
|
|
105
|
-
readonly functions: Record<string, ComputeFn>;
|
|
133
|
+
enrichSources: typeof enrichSources;
|
|
106
134
|
};
|
|
107
135
|
|
|
108
|
-
export { CardCompute, type
|
|
136
|
+
export { CardCompute, type ComputeNode, type ComputeSource, type ComputeStep, type RunOptions, type ValidationResult, CardCompute as default, validateLiveCard, validateLiveCardDefinition, validateLiveCardRuntimeExpressions, validateLiveCardSchema };
|