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
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { f as GraphEvent, T as TaskConfig, e as GraphEngineStore, G as GraphConfig } from './types-CMFSIjpc.js';
|
|
2
|
+
import { b as LiveGraphSnapshot, L as LiveGraph, S as ScheduleResult } from './types-C2eJ7DAV.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Continuous Event Graph — Reactive Layer
|
|
6
|
+
*
|
|
7
|
+
* Push-based, self-sustaining execution wrapper.
|
|
8
|
+
*
|
|
9
|
+
* Pattern:
|
|
10
|
+
* 1. Register handlers for tasks
|
|
11
|
+
* 2. Push an event (or inject tokens)
|
|
12
|
+
* 3. The graph drives itself: drain journal → applyEvents → schedule → dispatch → repeat
|
|
13
|
+
*
|
|
14
|
+
* No daemon, no polling. Each handler callback appends to the journal,
|
|
15
|
+
* which triggers a drain cycle that may dispatch the next wave.
|
|
16
|
+
*
|
|
17
|
+
* Dispatch failures, retries, and timeouts are managed internally
|
|
18
|
+
* without touching the core engine types.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Deterministic hash of a data payload.
|
|
23
|
+
* Recursively-sorted JSON → stable 64-bit hex.
|
|
24
|
+
* Used to auto-compute dataHash when the handler doesn't provide one.
|
|
25
|
+
* Exported so handler authors can pre-compute or test hashes.
|
|
26
|
+
*/
|
|
27
|
+
declare function computeDataHash(data: Record<string, unknown>): string;
|
|
28
|
+
/**
|
|
29
|
+
* Input passed to a task handler function.
|
|
30
|
+
*
|
|
31
|
+
* The reactive layer resolves upstream data from `requires` into `state`,
|
|
32
|
+
* and provides this task's own engine store as `taskState`.
|
|
33
|
+
* Handlers push output data back via `graph.resolveCallback(callbackToken, data)`.
|
|
34
|
+
*/
|
|
35
|
+
interface TaskHandlerInput {
|
|
36
|
+
/** This task's node ID (task name) */
|
|
37
|
+
nodeId: string;
|
|
38
|
+
/**
|
|
39
|
+
* Upstream dependency data, keyed by require token name.
|
|
40
|
+
* Only tokens from this task's `requires` are present.
|
|
41
|
+
* Value is the producing task's `data` field (or undefined if not yet available).
|
|
42
|
+
*/
|
|
43
|
+
state: Readonly<Record<string, Record<string, unknown> | undefined>>;
|
|
44
|
+
/**
|
|
45
|
+
* This task's own GraphEngineStore — includes status, data, executionCount, etc.
|
|
46
|
+
*/
|
|
47
|
+
taskState: Readonly<GraphEngineStore>;
|
|
48
|
+
/** This task's config */
|
|
49
|
+
config: Readonly<TaskConfig>;
|
|
50
|
+
/**
|
|
51
|
+
* Opaque callback token encoding this task's identity.
|
|
52
|
+
* Pass this to `graph.resolveCallback(callbackToken, data)` to complete the task.
|
|
53
|
+
* Can be serialized and sent to external systems (webhooks, other scripts,
|
|
54
|
+
* message queues) — any process with this token can push data back.
|
|
55
|
+
*/
|
|
56
|
+
callbackToken: string;
|
|
57
|
+
/**
|
|
58
|
+
* Present only on task-progress re-invocations (source delivery / failure).
|
|
59
|
+
* Contains the update payload from the task-progress event.
|
|
60
|
+
* e.g. { bindTo: 'prices', fetchedAt: '...', dest: 'prices.json' }
|
|
61
|
+
* or { bindTo: 'prices', failure: true, reason: 'timeout' }
|
|
62
|
+
*/
|
|
63
|
+
update?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Handler return value — initiation status only.
|
|
67
|
+
* - `'task-initiated'` — async work started successfully; data will arrive via resolveCallback
|
|
68
|
+
* - `'task-initiate-failure'` — failed to start (bad config, connection refused, etc.)
|
|
69
|
+
*/
|
|
70
|
+
type TaskHandlerReturn = 'task-initiated' | 'task-initiate-failure';
|
|
71
|
+
/**
|
|
72
|
+
* A named task handler function.
|
|
73
|
+
* Registered in the handler registry, referenced by name in `taskConfig.taskHandlers`.
|
|
74
|
+
*
|
|
75
|
+
* The handler's job is to **initiate** async work, not await it.
|
|
76
|
+
*
|
|
77
|
+
* Flow:
|
|
78
|
+
* 1. Handler receives `callbackToken` + upstream `state`
|
|
79
|
+
* 2. Handler kicks off background work (internal, external script, webhook, etc.)
|
|
80
|
+
* — passes `callbackToken` to the background work
|
|
81
|
+
* 3. Handler returns `'task-initiated'` immediately
|
|
82
|
+
* 4. Background work runs independently — when done, it calls
|
|
83
|
+
* `graph.resolveCallback(callbackToken, data)` for success, or
|
|
84
|
+
* `graph.resolveCallback(callbackToken, {}, ['error msg'])` for failure
|
|
85
|
+
* 5. resolveCallback completes the task → data-changed cascade fires
|
|
86
|
+
*
|
|
87
|
+
* The callbackToken is opaque — pass it to the background work so it can
|
|
88
|
+
* call back. Works across processes, scripts, webhooks, message queues.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const fetchYahoo: TaskHandlerFn = async ({ state, callbackToken }) => {
|
|
93
|
+
* const symbols = state['portfolio-form']?.holdings?.map(h => h.symbol) ?? [];
|
|
94
|
+
* // Kick off background work — do NOT await
|
|
95
|
+
* fetch(`https://api.yahoo.com/prices?s=${symbols.join(',')}`)
|
|
96
|
+
* .then(res => res.json())
|
|
97
|
+
* .then(prices => graph.resolveCallback(callbackToken, { prices }))
|
|
98
|
+
* .catch(err => graph.resolveCallback(callbackToken, {}, [err.message]));
|
|
99
|
+
* // Return immediately — background work will resolveCallback when done
|
|
100
|
+
* return 'task-initiated';
|
|
101
|
+
* };
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
type TaskHandlerFn = (input: TaskHandlerInput) => Promise<TaskHandlerReturn>;
|
|
105
|
+
interface ReactiveGraphOptions {
|
|
106
|
+
/** Named handler registry — handler name → handler function */
|
|
107
|
+
handlers: Record<string, TaskHandlerFn>;
|
|
108
|
+
/** Called after each drain cycle — for observability */
|
|
109
|
+
onDrain?: (events: GraphEvent[], live: LiveGraph, scheduleResult: ScheduleResult) => void;
|
|
110
|
+
}
|
|
111
|
+
interface ReactiveGraph {
|
|
112
|
+
/** Push an event into the graph via journal. Triggers drain → schedule → dispatch. */
|
|
113
|
+
push(event: GraphEvent): void;
|
|
114
|
+
/** Push multiple events via journal. Single drain cycle after all are journaled. */
|
|
115
|
+
pushAll(events: GraphEvent[]): void;
|
|
116
|
+
/**
|
|
117
|
+
* Resolve a callback token — complete (or fail) a task after initiation.
|
|
118
|
+
* Journals task-completed or task-failed, then drains.
|
|
119
|
+
* Gracefully ignores invalid tokens or tokens for tasks no longer in the graph.
|
|
120
|
+
*/
|
|
121
|
+
resolveCallback(callbackToken: string, data: Record<string, unknown>, errors?: string[]): void;
|
|
122
|
+
/** Add a node to the graph. Journals a task-upsert event, then drains. */
|
|
123
|
+
addNode(name: string, taskConfig: TaskConfig): void;
|
|
124
|
+
/** Remove a node from the graph. Journals a task-removal event, then drains. */
|
|
125
|
+
removeNode(name: string): void;
|
|
126
|
+
/** Add required tokens to an existing node. Journals event, then drains. */
|
|
127
|
+
addRequires(nodeName: string, tokens: string[]): void;
|
|
128
|
+
/** Remove required tokens from an existing node. Journals event, then drains. */
|
|
129
|
+
removeRequires(nodeName: string, tokens: string[]): void;
|
|
130
|
+
/** Add provided tokens to an existing node. Journals event, then drains. */
|
|
131
|
+
addProvides(nodeName: string, tokens: string[]): void;
|
|
132
|
+
/** Remove provided tokens from an existing node. Journals event, then drains. */
|
|
133
|
+
removeProvides(nodeName: string, tokens: string[]): void;
|
|
134
|
+
/** Register a named handler in the registry. */
|
|
135
|
+
registerHandler(name: string, fn: TaskHandlerFn): void;
|
|
136
|
+
/** Unregister a named handler from the registry. */
|
|
137
|
+
unregisterHandler(name: string): void;
|
|
138
|
+
/**
|
|
139
|
+
* Re-trigger a task: journals a task-restart event, then drains.
|
|
140
|
+
* data-changed cascade handles downstream automatically.
|
|
141
|
+
*/
|
|
142
|
+
retrigger(taskName: string): void;
|
|
143
|
+
/** Re-trigger multiple tasks via journal. */
|
|
144
|
+
retriggerAll(taskNames: string[]): void;
|
|
145
|
+
/**
|
|
146
|
+
* Serialize current state to a JSON-safe snapshot.
|
|
147
|
+
* Caller is responsible for writing to disk/DB/etc.
|
|
148
|
+
* Restore via: `createReactiveGraph(restore(snapshotData), options)`
|
|
149
|
+
*/
|
|
150
|
+
snapshot(): LiveGraphSnapshot;
|
|
151
|
+
/** Read-only snapshot of current LiveGraph state. */
|
|
152
|
+
getState(): LiveGraph;
|
|
153
|
+
/** Current schedule projection. */
|
|
154
|
+
getSchedule(): ScheduleResult;
|
|
155
|
+
/** Stop accepting events. */
|
|
156
|
+
dispose(): void;
|
|
157
|
+
}
|
|
158
|
+
declare function createReactiveGraph(configOrLive: GraphConfig | LiveGraph, options: ReactiveGraphOptions, executionId?: string): ReactiveGraph;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Live Cards → Reactive Graph
|
|
162
|
+
*
|
|
163
|
+
* Takes an array of live card JSONs (card / source nodes) and produces
|
|
164
|
+
* a fully wired ReactiveGraph where:
|
|
165
|
+
*
|
|
166
|
+
* - Each card becomes a task in the graph
|
|
167
|
+
* - card.requires → task.requires (upstream card IDs as tokens)
|
|
168
|
+
* - Each card produces a token equal to its own ID
|
|
169
|
+
* - Card-type nodes: handler runs CardCompute.run() on a clone of the card,
|
|
170
|
+
* returns the computed state as data (auto-hashed by the reactive layer)
|
|
171
|
+
* - Source-type nodes: handler uses the source definition to fetch data,
|
|
172
|
+
* or falls back to a user-provided handler / noop
|
|
173
|
+
*
|
|
174
|
+
* The reactive graph auto-computes dataHash on every handler result,
|
|
175
|
+
* so `data-changed` refresh strategy works out of the box.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { liveCardsToReactiveGraph } from 'yaml-flow/continuous-event-graph';
|
|
180
|
+
*
|
|
181
|
+
* const cards = [
|
|
182
|
+
* { id: 'prices', sources: [{ kind: 'api', bindTo: 'raw' }], state: {} },
|
|
183
|
+
* { id: 'dashboard', requires: ['prices'], state: {}, compute: [{ bindTo: 'total', fn: 'sum', ... }], view: { ... } },
|
|
184
|
+
* ];
|
|
185
|
+
*
|
|
186
|
+
* const rg = liveCardsToReactiveGraph(cards, {
|
|
187
|
+
* sourceHandlers: {
|
|
188
|
+
* prices: async () => ({ data: { raw: await fetchPrices() } }),
|
|
189
|
+
* },
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* // One push → the whole board computes itself
|
|
193
|
+
* rg.push({ type: 'inject-tokens', tokens: [], timestamp: new Date().toISOString() });
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Minimal live card shape accepted by this utility.
|
|
199
|
+
* Unified card — no type field. Behavior from sections present.
|
|
200
|
+
*/
|
|
201
|
+
/** A provides binding: maps a token name to a source path in the card's data namespace. */
|
|
202
|
+
interface ProvidesBinding {
|
|
203
|
+
bindTo: string;
|
|
204
|
+
src: string;
|
|
205
|
+
}
|
|
206
|
+
interface LiveCard {
|
|
207
|
+
id: string;
|
|
208
|
+
requires?: string[];
|
|
209
|
+
provides?: ProvidesBinding[];
|
|
210
|
+
meta?: {
|
|
211
|
+
title?: string;
|
|
212
|
+
tags?: string[];
|
|
213
|
+
};
|
|
214
|
+
card_data?: Record<string, unknown>;
|
|
215
|
+
compute?: {
|
|
216
|
+
bindTo: string;
|
|
217
|
+
fn: string;
|
|
218
|
+
[key: string]: unknown;
|
|
219
|
+
}[];
|
|
220
|
+
sources?: {
|
|
221
|
+
cli?: string;
|
|
222
|
+
bindTo: string;
|
|
223
|
+
kind?: 'api' | 'websocket' | 'static' | 'llm';
|
|
224
|
+
[key: string]: unknown;
|
|
225
|
+
}[];
|
|
226
|
+
optionalSources?: {
|
|
227
|
+
cli?: string;
|
|
228
|
+
bindTo: string;
|
|
229
|
+
kind?: 'api' | 'websocket' | 'static' | 'llm';
|
|
230
|
+
[key: string]: unknown;
|
|
231
|
+
}[];
|
|
232
|
+
view?: Record<string, unknown>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* A Board is a named container of live card nodes.
|
|
236
|
+
* Matches the shape used by LiveCard.Board() in browser/live-cards.js:
|
|
237
|
+
* LiveCard.Board(engine, el, { nodes, positions?, mode, canvas, ... })
|
|
238
|
+
*
|
|
239
|
+
* The `nodes` array contains the card/source JSON objects.
|
|
240
|
+
* Board-level metadata (id, title, settings) is carried through to the
|
|
241
|
+
* generated GraphConfig.
|
|
242
|
+
*/
|
|
243
|
+
interface LiveBoard {
|
|
244
|
+
/** Board identifier */
|
|
245
|
+
id?: string;
|
|
246
|
+
/** Human-readable title */
|
|
247
|
+
title?: string;
|
|
248
|
+
/** The card/source nodes on this board */
|
|
249
|
+
nodes: LiveCard[];
|
|
250
|
+
/** Board display mode (informational — not used by the reactive graph) */
|
|
251
|
+
mode?: 'board' | 'canvas';
|
|
252
|
+
/** Canvas positions keyed by node ID (informational — not used) */
|
|
253
|
+
positions?: Record<string, {
|
|
254
|
+
x?: number;
|
|
255
|
+
y?: number;
|
|
256
|
+
w?: number;
|
|
257
|
+
h?: number;
|
|
258
|
+
}>;
|
|
259
|
+
/** Board-level settings forwarded to GraphConfig.settings */
|
|
260
|
+
settings?: Partial<GraphConfig['settings']>;
|
|
261
|
+
}
|
|
262
|
+
interface LiveCardsToReactiveOptions {
|
|
263
|
+
/** Custom handlers for source nodes (keyed by card ID). */
|
|
264
|
+
sourceHandlers?: Record<string, TaskHandlerFn>;
|
|
265
|
+
/**
|
|
266
|
+
* Default handler factory for source nodes without an explicit handler.
|
|
267
|
+
* Called once per source card during graph construction.
|
|
268
|
+
* If not provided, source nodes without explicit handlers get a noop handler
|
|
269
|
+
* that returns the card's current state.
|
|
270
|
+
*/
|
|
271
|
+
defaultSourceHandler?: (card: LiveCard) => TaskHandlerFn;
|
|
272
|
+
/**
|
|
273
|
+
* Custom handlers for card nodes (keyed by card ID).
|
|
274
|
+
* Overrides the default CardCompute.run() behavior.
|
|
275
|
+
*/
|
|
276
|
+
cardHandlers?: Record<string, TaskHandlerFn>;
|
|
277
|
+
/**
|
|
278
|
+
* If provided, upstream card state is injected into downstream cards
|
|
279
|
+
* before running compute. The key is the upstream card ID and the value
|
|
280
|
+
* is the upstream card's latest state.
|
|
281
|
+
*/
|
|
282
|
+
sharedState?: Map<string, Record<string, unknown>>;
|
|
283
|
+
/** Override reactive graph options (journal, callbacks, etc.) */
|
|
284
|
+
reactiveOptions?: Partial<Omit<ReactiveGraphOptions, 'handlers'>>;
|
|
285
|
+
/** Graph-level settings overrides */
|
|
286
|
+
graphSettings?: Partial<GraphConfig['settings']>;
|
|
287
|
+
/** Execution ID for the reactive graph */
|
|
288
|
+
executionId?: string;
|
|
289
|
+
}
|
|
290
|
+
interface LiveCardsToReactiveResult {
|
|
291
|
+
/** The fully wired reactive graph — ready to push events into. */
|
|
292
|
+
graph: ReactiveGraph;
|
|
293
|
+
/** The generated GraphConfig (for inspection/serialization). */
|
|
294
|
+
config: GraphConfig;
|
|
295
|
+
/** The handler map (for use with validateReactiveGraph). */
|
|
296
|
+
handlers: Record<string, TaskHandlerFn>;
|
|
297
|
+
/** Card lookup by ID (original references). */
|
|
298
|
+
cards: Map<string, LiveCard>;
|
|
299
|
+
/**
|
|
300
|
+
* Shared state map: cardId → latest computed state.
|
|
301
|
+
* Updated automatically by built-in handlers after each task completes.
|
|
302
|
+
* Custom cardHandlers/sourceHandlers can also read upstream data directly
|
|
303
|
+
* from the engine: graph.getState().state.tasks[cardId].data
|
|
304
|
+
*/
|
|
305
|
+
sharedState: Map<string, Record<string, unknown>>;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Convert live card JSONs or a Board into a fully wired ReactiveGraph.
|
|
309
|
+
*
|
|
310
|
+
* Overloads:
|
|
311
|
+
* liveCardsToReactiveGraph(cards[], options?) — from a flat array of cards
|
|
312
|
+
* liveCardsToReactiveGraph(board, options?) — from a LiveBoard object
|
|
313
|
+
*/
|
|
314
|
+
declare function liveCardsToReactiveGraph(input: LiveCard[] | LiveBoard, options?: LiveCardsToReactiveOptions): LiveCardsToReactiveResult;
|
|
315
|
+
|
|
316
|
+
export { type LiveBoard as L, type ReactiveGraph as R, type TaskHandlerFn as T, type LiveCard as a, type LiveCardsToReactiveOptions as b, type LiveCardsToReactiveResult as c, type ReactiveGraphOptions as d, type TaskHandlerInput as e, type TaskHandlerReturn as f, createReactiveGraph as g, computeDataHash as h, liveCardsToReactiveGraph as l };
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { f as GraphEvent, T as TaskConfig, e as GraphEngineStore, G as GraphConfig } from './types-CMFSIjpc.cjs';
|
|
2
|
+
import { b as LiveGraphSnapshot, L as LiveGraph, S as ScheduleResult } from './types-BzLD8bjb.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Continuous Event Graph — Reactive Layer
|
|
6
|
+
*
|
|
7
|
+
* Push-based, self-sustaining execution wrapper.
|
|
8
|
+
*
|
|
9
|
+
* Pattern:
|
|
10
|
+
* 1. Register handlers for tasks
|
|
11
|
+
* 2. Push an event (or inject tokens)
|
|
12
|
+
* 3. The graph drives itself: drain journal → applyEvents → schedule → dispatch → repeat
|
|
13
|
+
*
|
|
14
|
+
* No daemon, no polling. Each handler callback appends to the journal,
|
|
15
|
+
* which triggers a drain cycle that may dispatch the next wave.
|
|
16
|
+
*
|
|
17
|
+
* Dispatch failures, retries, and timeouts are managed internally
|
|
18
|
+
* without touching the core engine types.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Deterministic hash of a data payload.
|
|
23
|
+
* Recursively-sorted JSON → stable 64-bit hex.
|
|
24
|
+
* Used to auto-compute dataHash when the handler doesn't provide one.
|
|
25
|
+
* Exported so handler authors can pre-compute or test hashes.
|
|
26
|
+
*/
|
|
27
|
+
declare function computeDataHash(data: Record<string, unknown>): string;
|
|
28
|
+
/**
|
|
29
|
+
* Input passed to a task handler function.
|
|
30
|
+
*
|
|
31
|
+
* The reactive layer resolves upstream data from `requires` into `state`,
|
|
32
|
+
* and provides this task's own engine store as `taskState`.
|
|
33
|
+
* Handlers push output data back via `graph.resolveCallback(callbackToken, data)`.
|
|
34
|
+
*/
|
|
35
|
+
interface TaskHandlerInput {
|
|
36
|
+
/** This task's node ID (task name) */
|
|
37
|
+
nodeId: string;
|
|
38
|
+
/**
|
|
39
|
+
* Upstream dependency data, keyed by require token name.
|
|
40
|
+
* Only tokens from this task's `requires` are present.
|
|
41
|
+
* Value is the producing task's `data` field (or undefined if not yet available).
|
|
42
|
+
*/
|
|
43
|
+
state: Readonly<Record<string, Record<string, unknown> | undefined>>;
|
|
44
|
+
/**
|
|
45
|
+
* This task's own GraphEngineStore — includes status, data, executionCount, etc.
|
|
46
|
+
*/
|
|
47
|
+
taskState: Readonly<GraphEngineStore>;
|
|
48
|
+
/** This task's config */
|
|
49
|
+
config: Readonly<TaskConfig>;
|
|
50
|
+
/**
|
|
51
|
+
* Opaque callback token encoding this task's identity.
|
|
52
|
+
* Pass this to `graph.resolveCallback(callbackToken, data)` to complete the task.
|
|
53
|
+
* Can be serialized and sent to external systems (webhooks, other scripts,
|
|
54
|
+
* message queues) — any process with this token can push data back.
|
|
55
|
+
*/
|
|
56
|
+
callbackToken: string;
|
|
57
|
+
/**
|
|
58
|
+
* Present only on task-progress re-invocations (source delivery / failure).
|
|
59
|
+
* Contains the update payload from the task-progress event.
|
|
60
|
+
* e.g. { bindTo: 'prices', fetchedAt: '...', dest: 'prices.json' }
|
|
61
|
+
* or { bindTo: 'prices', failure: true, reason: 'timeout' }
|
|
62
|
+
*/
|
|
63
|
+
update?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Handler return value — initiation status only.
|
|
67
|
+
* - `'task-initiated'` — async work started successfully; data will arrive via resolveCallback
|
|
68
|
+
* - `'task-initiate-failure'` — failed to start (bad config, connection refused, etc.)
|
|
69
|
+
*/
|
|
70
|
+
type TaskHandlerReturn = 'task-initiated' | 'task-initiate-failure';
|
|
71
|
+
/**
|
|
72
|
+
* A named task handler function.
|
|
73
|
+
* Registered in the handler registry, referenced by name in `taskConfig.taskHandlers`.
|
|
74
|
+
*
|
|
75
|
+
* The handler's job is to **initiate** async work, not await it.
|
|
76
|
+
*
|
|
77
|
+
* Flow:
|
|
78
|
+
* 1. Handler receives `callbackToken` + upstream `state`
|
|
79
|
+
* 2. Handler kicks off background work (internal, external script, webhook, etc.)
|
|
80
|
+
* — passes `callbackToken` to the background work
|
|
81
|
+
* 3. Handler returns `'task-initiated'` immediately
|
|
82
|
+
* 4. Background work runs independently — when done, it calls
|
|
83
|
+
* `graph.resolveCallback(callbackToken, data)` for success, or
|
|
84
|
+
* `graph.resolveCallback(callbackToken, {}, ['error msg'])` for failure
|
|
85
|
+
* 5. resolveCallback completes the task → data-changed cascade fires
|
|
86
|
+
*
|
|
87
|
+
* The callbackToken is opaque — pass it to the background work so it can
|
|
88
|
+
* call back. Works across processes, scripts, webhooks, message queues.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const fetchYahoo: TaskHandlerFn = async ({ state, callbackToken }) => {
|
|
93
|
+
* const symbols = state['portfolio-form']?.holdings?.map(h => h.symbol) ?? [];
|
|
94
|
+
* // Kick off background work — do NOT await
|
|
95
|
+
* fetch(`https://api.yahoo.com/prices?s=${symbols.join(',')}`)
|
|
96
|
+
* .then(res => res.json())
|
|
97
|
+
* .then(prices => graph.resolveCallback(callbackToken, { prices }))
|
|
98
|
+
* .catch(err => graph.resolveCallback(callbackToken, {}, [err.message]));
|
|
99
|
+
* // Return immediately — background work will resolveCallback when done
|
|
100
|
+
* return 'task-initiated';
|
|
101
|
+
* };
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
type TaskHandlerFn = (input: TaskHandlerInput) => Promise<TaskHandlerReturn>;
|
|
105
|
+
interface ReactiveGraphOptions {
|
|
106
|
+
/** Named handler registry — handler name → handler function */
|
|
107
|
+
handlers: Record<string, TaskHandlerFn>;
|
|
108
|
+
/** Called after each drain cycle — for observability */
|
|
109
|
+
onDrain?: (events: GraphEvent[], live: LiveGraph, scheduleResult: ScheduleResult) => void;
|
|
110
|
+
}
|
|
111
|
+
interface ReactiveGraph {
|
|
112
|
+
/** Push an event into the graph via journal. Triggers drain → schedule → dispatch. */
|
|
113
|
+
push(event: GraphEvent): void;
|
|
114
|
+
/** Push multiple events via journal. Single drain cycle after all are journaled. */
|
|
115
|
+
pushAll(events: GraphEvent[]): void;
|
|
116
|
+
/**
|
|
117
|
+
* Resolve a callback token — complete (or fail) a task after initiation.
|
|
118
|
+
* Journals task-completed or task-failed, then drains.
|
|
119
|
+
* Gracefully ignores invalid tokens or tokens for tasks no longer in the graph.
|
|
120
|
+
*/
|
|
121
|
+
resolveCallback(callbackToken: string, data: Record<string, unknown>, errors?: string[]): void;
|
|
122
|
+
/** Add a node to the graph. Journals a task-upsert event, then drains. */
|
|
123
|
+
addNode(name: string, taskConfig: TaskConfig): void;
|
|
124
|
+
/** Remove a node from the graph. Journals a task-removal event, then drains. */
|
|
125
|
+
removeNode(name: string): void;
|
|
126
|
+
/** Add required tokens to an existing node. Journals event, then drains. */
|
|
127
|
+
addRequires(nodeName: string, tokens: string[]): void;
|
|
128
|
+
/** Remove required tokens from an existing node. Journals event, then drains. */
|
|
129
|
+
removeRequires(nodeName: string, tokens: string[]): void;
|
|
130
|
+
/** Add provided tokens to an existing node. Journals event, then drains. */
|
|
131
|
+
addProvides(nodeName: string, tokens: string[]): void;
|
|
132
|
+
/** Remove provided tokens from an existing node. Journals event, then drains. */
|
|
133
|
+
removeProvides(nodeName: string, tokens: string[]): void;
|
|
134
|
+
/** Register a named handler in the registry. */
|
|
135
|
+
registerHandler(name: string, fn: TaskHandlerFn): void;
|
|
136
|
+
/** Unregister a named handler from the registry. */
|
|
137
|
+
unregisterHandler(name: string): void;
|
|
138
|
+
/**
|
|
139
|
+
* Re-trigger a task: journals a task-restart event, then drains.
|
|
140
|
+
* data-changed cascade handles downstream automatically.
|
|
141
|
+
*/
|
|
142
|
+
retrigger(taskName: string): void;
|
|
143
|
+
/** Re-trigger multiple tasks via journal. */
|
|
144
|
+
retriggerAll(taskNames: string[]): void;
|
|
145
|
+
/**
|
|
146
|
+
* Serialize current state to a JSON-safe snapshot.
|
|
147
|
+
* Caller is responsible for writing to disk/DB/etc.
|
|
148
|
+
* Restore via: `createReactiveGraph(restore(snapshotData), options)`
|
|
149
|
+
*/
|
|
150
|
+
snapshot(): LiveGraphSnapshot;
|
|
151
|
+
/** Read-only snapshot of current LiveGraph state. */
|
|
152
|
+
getState(): LiveGraph;
|
|
153
|
+
/** Current schedule projection. */
|
|
154
|
+
getSchedule(): ScheduleResult;
|
|
155
|
+
/** Stop accepting events. */
|
|
156
|
+
dispose(): void;
|
|
157
|
+
}
|
|
158
|
+
declare function createReactiveGraph(configOrLive: GraphConfig | LiveGraph, options: ReactiveGraphOptions, executionId?: string): ReactiveGraph;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Live Cards → Reactive Graph
|
|
162
|
+
*
|
|
163
|
+
* Takes an array of live card JSONs (card / source nodes) and produces
|
|
164
|
+
* a fully wired ReactiveGraph where:
|
|
165
|
+
*
|
|
166
|
+
* - Each card becomes a task in the graph
|
|
167
|
+
* - card.requires → task.requires (upstream card IDs as tokens)
|
|
168
|
+
* - Each card produces a token equal to its own ID
|
|
169
|
+
* - Card-type nodes: handler runs CardCompute.run() on a clone of the card,
|
|
170
|
+
* returns the computed state as data (auto-hashed by the reactive layer)
|
|
171
|
+
* - Source-type nodes: handler uses the source definition to fetch data,
|
|
172
|
+
* or falls back to a user-provided handler / noop
|
|
173
|
+
*
|
|
174
|
+
* The reactive graph auto-computes dataHash on every handler result,
|
|
175
|
+
* so `data-changed` refresh strategy works out of the box.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { liveCardsToReactiveGraph } from 'yaml-flow/continuous-event-graph';
|
|
180
|
+
*
|
|
181
|
+
* const cards = [
|
|
182
|
+
* { id: 'prices', sources: [{ kind: 'api', bindTo: 'raw' }], state: {} },
|
|
183
|
+
* { id: 'dashboard', requires: ['prices'], state: {}, compute: [{ bindTo: 'total', fn: 'sum', ... }], view: { ... } },
|
|
184
|
+
* ];
|
|
185
|
+
*
|
|
186
|
+
* const rg = liveCardsToReactiveGraph(cards, {
|
|
187
|
+
* sourceHandlers: {
|
|
188
|
+
* prices: async () => ({ data: { raw: await fetchPrices() } }),
|
|
189
|
+
* },
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* // One push → the whole board computes itself
|
|
193
|
+
* rg.push({ type: 'inject-tokens', tokens: [], timestamp: new Date().toISOString() });
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Minimal live card shape accepted by this utility.
|
|
199
|
+
* Unified card — no type field. Behavior from sections present.
|
|
200
|
+
*/
|
|
201
|
+
/** A provides binding: maps a token name to a source path in the card's data namespace. */
|
|
202
|
+
interface ProvidesBinding {
|
|
203
|
+
bindTo: string;
|
|
204
|
+
src: string;
|
|
205
|
+
}
|
|
206
|
+
interface LiveCard {
|
|
207
|
+
id: string;
|
|
208
|
+
requires?: string[];
|
|
209
|
+
provides?: ProvidesBinding[];
|
|
210
|
+
meta?: {
|
|
211
|
+
title?: string;
|
|
212
|
+
tags?: string[];
|
|
213
|
+
};
|
|
214
|
+
card_data?: Record<string, unknown>;
|
|
215
|
+
compute?: {
|
|
216
|
+
bindTo: string;
|
|
217
|
+
fn: string;
|
|
218
|
+
[key: string]: unknown;
|
|
219
|
+
}[];
|
|
220
|
+
sources?: {
|
|
221
|
+
cli?: string;
|
|
222
|
+
bindTo: string;
|
|
223
|
+
kind?: 'api' | 'websocket' | 'static' | 'llm';
|
|
224
|
+
[key: string]: unknown;
|
|
225
|
+
}[];
|
|
226
|
+
optionalSources?: {
|
|
227
|
+
cli?: string;
|
|
228
|
+
bindTo: string;
|
|
229
|
+
kind?: 'api' | 'websocket' | 'static' | 'llm';
|
|
230
|
+
[key: string]: unknown;
|
|
231
|
+
}[];
|
|
232
|
+
view?: Record<string, unknown>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* A Board is a named container of live card nodes.
|
|
236
|
+
* Matches the shape used by LiveCard.Board() in browser/live-cards.js:
|
|
237
|
+
* LiveCard.Board(engine, el, { nodes, positions?, mode, canvas, ... })
|
|
238
|
+
*
|
|
239
|
+
* The `nodes` array contains the card/source JSON objects.
|
|
240
|
+
* Board-level metadata (id, title, settings) is carried through to the
|
|
241
|
+
* generated GraphConfig.
|
|
242
|
+
*/
|
|
243
|
+
interface LiveBoard {
|
|
244
|
+
/** Board identifier */
|
|
245
|
+
id?: string;
|
|
246
|
+
/** Human-readable title */
|
|
247
|
+
title?: string;
|
|
248
|
+
/** The card/source nodes on this board */
|
|
249
|
+
nodes: LiveCard[];
|
|
250
|
+
/** Board display mode (informational — not used by the reactive graph) */
|
|
251
|
+
mode?: 'board' | 'canvas';
|
|
252
|
+
/** Canvas positions keyed by node ID (informational — not used) */
|
|
253
|
+
positions?: Record<string, {
|
|
254
|
+
x?: number;
|
|
255
|
+
y?: number;
|
|
256
|
+
w?: number;
|
|
257
|
+
h?: number;
|
|
258
|
+
}>;
|
|
259
|
+
/** Board-level settings forwarded to GraphConfig.settings */
|
|
260
|
+
settings?: Partial<GraphConfig['settings']>;
|
|
261
|
+
}
|
|
262
|
+
interface LiveCardsToReactiveOptions {
|
|
263
|
+
/** Custom handlers for source nodes (keyed by card ID). */
|
|
264
|
+
sourceHandlers?: Record<string, TaskHandlerFn>;
|
|
265
|
+
/**
|
|
266
|
+
* Default handler factory for source nodes without an explicit handler.
|
|
267
|
+
* Called once per source card during graph construction.
|
|
268
|
+
* If not provided, source nodes without explicit handlers get a noop handler
|
|
269
|
+
* that returns the card's current state.
|
|
270
|
+
*/
|
|
271
|
+
defaultSourceHandler?: (card: LiveCard) => TaskHandlerFn;
|
|
272
|
+
/**
|
|
273
|
+
* Custom handlers for card nodes (keyed by card ID).
|
|
274
|
+
* Overrides the default CardCompute.run() behavior.
|
|
275
|
+
*/
|
|
276
|
+
cardHandlers?: Record<string, TaskHandlerFn>;
|
|
277
|
+
/**
|
|
278
|
+
* If provided, upstream card state is injected into downstream cards
|
|
279
|
+
* before running compute. The key is the upstream card ID and the value
|
|
280
|
+
* is the upstream card's latest state.
|
|
281
|
+
*/
|
|
282
|
+
sharedState?: Map<string, Record<string, unknown>>;
|
|
283
|
+
/** Override reactive graph options (journal, callbacks, etc.) */
|
|
284
|
+
reactiveOptions?: Partial<Omit<ReactiveGraphOptions, 'handlers'>>;
|
|
285
|
+
/** Graph-level settings overrides */
|
|
286
|
+
graphSettings?: Partial<GraphConfig['settings']>;
|
|
287
|
+
/** Execution ID for the reactive graph */
|
|
288
|
+
executionId?: string;
|
|
289
|
+
}
|
|
290
|
+
interface LiveCardsToReactiveResult {
|
|
291
|
+
/** The fully wired reactive graph — ready to push events into. */
|
|
292
|
+
graph: ReactiveGraph;
|
|
293
|
+
/** The generated GraphConfig (for inspection/serialization). */
|
|
294
|
+
config: GraphConfig;
|
|
295
|
+
/** The handler map (for use with validateReactiveGraph). */
|
|
296
|
+
handlers: Record<string, TaskHandlerFn>;
|
|
297
|
+
/** Card lookup by ID (original references). */
|
|
298
|
+
cards: Map<string, LiveCard>;
|
|
299
|
+
/**
|
|
300
|
+
* Shared state map: cardId → latest computed state.
|
|
301
|
+
* Updated automatically by built-in handlers after each task completes.
|
|
302
|
+
* Custom cardHandlers/sourceHandlers can also read upstream data directly
|
|
303
|
+
* from the engine: graph.getState().state.tasks[cardId].data
|
|
304
|
+
*/
|
|
305
|
+
sharedState: Map<string, Record<string, unknown>>;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Convert live card JSONs or a Board into a fully wired ReactiveGraph.
|
|
309
|
+
*
|
|
310
|
+
* Overloads:
|
|
311
|
+
* liveCardsToReactiveGraph(cards[], options?) — from a flat array of cards
|
|
312
|
+
* liveCardsToReactiveGraph(board, options?) — from a LiveBoard object
|
|
313
|
+
*/
|
|
314
|
+
declare function liveCardsToReactiveGraph(input: LiveCard[] | LiveBoard, options?: LiveCardsToReactiveOptions): LiveCardsToReactiveResult;
|
|
315
|
+
|
|
316
|
+
export { type LiveBoard as L, type ReactiveGraph as R, type TaskHandlerFn as T, type LiveCard as a, type LiveCardsToReactiveOptions as b, type LiveCardsToReactiveResult as c, type ReactiveGraphOptions as d, type TaskHandlerInput as e, type TaskHandlerReturn as f, createReactiveGraph as g, computeDataHash as h, liveCardsToReactiveGraph as l };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { L as LiveGraph, S as ScheduleResult } from './types-C2eJ7DAV.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Continuous Event Graph — Schedule
|
|
5
|
+
*
|
|
6
|
+
* Pure read-only projection: LiveGraph → ScheduleResult
|
|
7
|
+
*
|
|
8
|
+
* Classifies every non-terminal task into one of:
|
|
9
|
+
* - eligible: all requires satisfied, ready to dispatch
|
|
10
|
+
* - pending: requires not yet met, but a viable producer exists (normal waiting)
|
|
11
|
+
* - unresolved: requires not met, NO task in the graph can produce them (caller's problem)
|
|
12
|
+
* - blocked: requires not met because the producing task FAILED (caller's problem)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Compute the scheduling status of every task in the live graph.
|
|
17
|
+
* Pure function — no side effects.
|
|
18
|
+
*/
|
|
19
|
+
declare function schedule(live: LiveGraph): ScheduleResult;
|
|
20
|
+
|
|
21
|
+
export { schedule as s };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { L as LiveGraph, S as ScheduleResult } from './types-BzLD8bjb.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Continuous Event Graph — Schedule
|
|
5
|
+
*
|
|
6
|
+
* Pure read-only projection: LiveGraph → ScheduleResult
|
|
7
|
+
*
|
|
8
|
+
* Classifies every non-terminal task into one of:
|
|
9
|
+
* - eligible: all requires satisfied, ready to dispatch
|
|
10
|
+
* - pending: requires not yet met, but a viable producer exists (normal waiting)
|
|
11
|
+
* - unresolved: requires not met, NO task in the graph can produce them (caller's problem)
|
|
12
|
+
* - blocked: requires not met because the producing task FAILED (caller's problem)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Compute the scheduling status of every task in the live graph.
|
|
17
|
+
* Pure function — no side effects.
|
|
18
|
+
*/
|
|
19
|
+
declare function schedule(live: LiveGraph): ScheduleResult;
|
|
20
|
+
|
|
21
|
+
export { schedule as s };
|