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
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import addFormats from 'ajv-formats';
2
- import { existsSync, writeFileSync, appendFileSync, readFileSync } from 'fs';
3
- import { createHash } from 'crypto';
4
2
  import { exec, execFile } from 'child_process';
3
+ import jsonata2 from 'jsonata';
5
4
 
6
5
  var __create = Object.create;
7
6
  var __defProp = Object.defineProperty;
@@ -6414,6 +6413,814 @@ var require_ajv = __commonJS({
6414
6413
  }
6415
6414
  });
6416
6415
 
6416
+ // node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js
6417
+ var require_dynamicAnchor = __commonJS({
6418
+ "node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js"(exports$1) {
6419
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6420
+ exports$1.dynamicAnchor = void 0;
6421
+ var codegen_1 = require_codegen();
6422
+ var names_1 = require_names();
6423
+ var compile_1 = require_compile();
6424
+ var ref_1 = require_ref();
6425
+ var def = {
6426
+ keyword: "$dynamicAnchor",
6427
+ schemaType: "string",
6428
+ code: (cxt) => dynamicAnchor(cxt, cxt.schema)
6429
+ };
6430
+ function dynamicAnchor(cxt, anchor) {
6431
+ const { gen, it } = cxt;
6432
+ it.schemaEnv.root.dynamicAnchors[anchor] = true;
6433
+ const v = (0, codegen_1._)`${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`;
6434
+ const validate = it.errSchemaPath === "#" ? it.validateName : _getValidate(cxt);
6435
+ gen.if((0, codegen_1._)`!${v}`, () => gen.assign(v, validate));
6436
+ }
6437
+ exports$1.dynamicAnchor = dynamicAnchor;
6438
+ function _getValidate(cxt) {
6439
+ const { schemaEnv, schema, self } = cxt.it;
6440
+ const { root, baseId, localRefs, meta } = schemaEnv.root;
6441
+ const { schemaId } = self.opts;
6442
+ const sch = new compile_1.SchemaEnv({ schema, schemaId, root, baseId, localRefs, meta });
6443
+ compile_1.compileSchema.call(self, sch);
6444
+ return (0, ref_1.getValidate)(cxt, sch);
6445
+ }
6446
+ exports$1.default = def;
6447
+ }
6448
+ });
6449
+
6450
+ // node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js
6451
+ var require_dynamicRef = __commonJS({
6452
+ "node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js"(exports$1) {
6453
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6454
+ exports$1.dynamicRef = void 0;
6455
+ var codegen_1 = require_codegen();
6456
+ var names_1 = require_names();
6457
+ var ref_1 = require_ref();
6458
+ var def = {
6459
+ keyword: "$dynamicRef",
6460
+ schemaType: "string",
6461
+ code: (cxt) => dynamicRef(cxt, cxt.schema)
6462
+ };
6463
+ function dynamicRef(cxt, ref) {
6464
+ const { gen, keyword, it } = cxt;
6465
+ if (ref[0] !== "#")
6466
+ throw new Error(`"${keyword}" only supports hash fragment reference`);
6467
+ const anchor = ref.slice(1);
6468
+ if (it.allErrors) {
6469
+ _dynamicRef();
6470
+ } else {
6471
+ const valid = gen.let("valid", false);
6472
+ _dynamicRef(valid);
6473
+ cxt.ok(valid);
6474
+ }
6475
+ function _dynamicRef(valid) {
6476
+ if (it.schemaEnv.root.dynamicAnchors[anchor]) {
6477
+ const v = gen.let("_v", (0, codegen_1._)`${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`);
6478
+ gen.if(v, _callRef(v, valid), _callRef(it.validateName, valid));
6479
+ } else {
6480
+ _callRef(it.validateName, valid)();
6481
+ }
6482
+ }
6483
+ function _callRef(validate, valid) {
6484
+ return valid ? () => gen.block(() => {
6485
+ (0, ref_1.callRef)(cxt, validate);
6486
+ gen.let(valid, true);
6487
+ }) : () => (0, ref_1.callRef)(cxt, validate);
6488
+ }
6489
+ }
6490
+ exports$1.dynamicRef = dynamicRef;
6491
+ exports$1.default = def;
6492
+ }
6493
+ });
6494
+
6495
+ // node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js
6496
+ var require_recursiveAnchor = __commonJS({
6497
+ "node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js"(exports$1) {
6498
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6499
+ var dynamicAnchor_1 = require_dynamicAnchor();
6500
+ var util_1 = require_util();
6501
+ var def = {
6502
+ keyword: "$recursiveAnchor",
6503
+ schemaType: "boolean",
6504
+ code(cxt) {
6505
+ if (cxt.schema)
6506
+ (0, dynamicAnchor_1.dynamicAnchor)(cxt, "");
6507
+ else
6508
+ (0, util_1.checkStrictMode)(cxt.it, "$recursiveAnchor: false is ignored");
6509
+ }
6510
+ };
6511
+ exports$1.default = def;
6512
+ }
6513
+ });
6514
+
6515
+ // node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js
6516
+ var require_recursiveRef = __commonJS({
6517
+ "node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js"(exports$1) {
6518
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6519
+ var dynamicRef_1 = require_dynamicRef();
6520
+ var def = {
6521
+ keyword: "$recursiveRef",
6522
+ schemaType: "string",
6523
+ code: (cxt) => (0, dynamicRef_1.dynamicRef)(cxt, cxt.schema)
6524
+ };
6525
+ exports$1.default = def;
6526
+ }
6527
+ });
6528
+
6529
+ // node_modules/ajv/dist/vocabularies/dynamic/index.js
6530
+ var require_dynamic = __commonJS({
6531
+ "node_modules/ajv/dist/vocabularies/dynamic/index.js"(exports$1) {
6532
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6533
+ var dynamicAnchor_1 = require_dynamicAnchor();
6534
+ var dynamicRef_1 = require_dynamicRef();
6535
+ var recursiveAnchor_1 = require_recursiveAnchor();
6536
+ var recursiveRef_1 = require_recursiveRef();
6537
+ var dynamic = [dynamicAnchor_1.default, dynamicRef_1.default, recursiveAnchor_1.default, recursiveRef_1.default];
6538
+ exports$1.default = dynamic;
6539
+ }
6540
+ });
6541
+
6542
+ // node_modules/ajv/dist/vocabularies/validation/dependentRequired.js
6543
+ var require_dependentRequired = __commonJS({
6544
+ "node_modules/ajv/dist/vocabularies/validation/dependentRequired.js"(exports$1) {
6545
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6546
+ var dependencies_1 = require_dependencies();
6547
+ var def = {
6548
+ keyword: "dependentRequired",
6549
+ type: "object",
6550
+ schemaType: "object",
6551
+ error: dependencies_1.error,
6552
+ code: (cxt) => (0, dependencies_1.validatePropertyDeps)(cxt)
6553
+ };
6554
+ exports$1.default = def;
6555
+ }
6556
+ });
6557
+
6558
+ // node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js
6559
+ var require_dependentSchemas = __commonJS({
6560
+ "node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js"(exports$1) {
6561
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6562
+ var dependencies_1 = require_dependencies();
6563
+ var def = {
6564
+ keyword: "dependentSchemas",
6565
+ type: "object",
6566
+ schemaType: "object",
6567
+ code: (cxt) => (0, dependencies_1.validateSchemaDeps)(cxt)
6568
+ };
6569
+ exports$1.default = def;
6570
+ }
6571
+ });
6572
+
6573
+ // node_modules/ajv/dist/vocabularies/validation/limitContains.js
6574
+ var require_limitContains = __commonJS({
6575
+ "node_modules/ajv/dist/vocabularies/validation/limitContains.js"(exports$1) {
6576
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6577
+ var util_1 = require_util();
6578
+ var def = {
6579
+ keyword: ["maxContains", "minContains"],
6580
+ type: "array",
6581
+ schemaType: "number",
6582
+ code({ keyword, parentSchema, it }) {
6583
+ if (parentSchema.contains === void 0) {
6584
+ (0, util_1.checkStrictMode)(it, `"${keyword}" without "contains" is ignored`);
6585
+ }
6586
+ }
6587
+ };
6588
+ exports$1.default = def;
6589
+ }
6590
+ });
6591
+
6592
+ // node_modules/ajv/dist/vocabularies/next.js
6593
+ var require_next = __commonJS({
6594
+ "node_modules/ajv/dist/vocabularies/next.js"(exports$1) {
6595
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6596
+ var dependentRequired_1 = require_dependentRequired();
6597
+ var dependentSchemas_1 = require_dependentSchemas();
6598
+ var limitContains_1 = require_limitContains();
6599
+ var next2 = [dependentRequired_1.default, dependentSchemas_1.default, limitContains_1.default];
6600
+ exports$1.default = next2;
6601
+ }
6602
+ });
6603
+
6604
+ // node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js
6605
+ var require_unevaluatedProperties = __commonJS({
6606
+ "node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js"(exports$1) {
6607
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6608
+ var codegen_1 = require_codegen();
6609
+ var util_1 = require_util();
6610
+ var names_1 = require_names();
6611
+ var error = {
6612
+ message: "must NOT have unevaluated properties",
6613
+ params: ({ params }) => (0, codegen_1._)`{unevaluatedProperty: ${params.unevaluatedProperty}}`
6614
+ };
6615
+ var def = {
6616
+ keyword: "unevaluatedProperties",
6617
+ type: "object",
6618
+ schemaType: ["boolean", "object"],
6619
+ trackErrors: true,
6620
+ error,
6621
+ code(cxt) {
6622
+ const { gen, schema, data, errsCount, it } = cxt;
6623
+ if (!errsCount)
6624
+ throw new Error("ajv implementation error");
6625
+ const { allErrors, props } = it;
6626
+ if (props instanceof codegen_1.Name) {
6627
+ gen.if((0, codegen_1._)`${props} !== true`, () => gen.forIn("key", data, (key) => gen.if(unevaluatedDynamic(props, key), () => unevaluatedPropCode(key))));
6628
+ } else if (props !== true) {
6629
+ gen.forIn("key", data, (key) => props === void 0 ? unevaluatedPropCode(key) : gen.if(unevaluatedStatic(props, key), () => unevaluatedPropCode(key)));
6630
+ }
6631
+ it.props = true;
6632
+ cxt.ok((0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
6633
+ function unevaluatedPropCode(key) {
6634
+ if (schema === false) {
6635
+ cxt.setParams({ unevaluatedProperty: key });
6636
+ cxt.error();
6637
+ if (!allErrors)
6638
+ gen.break();
6639
+ return;
6640
+ }
6641
+ if (!(0, util_1.alwaysValidSchema)(it, schema)) {
6642
+ const valid = gen.name("valid");
6643
+ cxt.subschema({
6644
+ keyword: "unevaluatedProperties",
6645
+ dataProp: key,
6646
+ dataPropType: util_1.Type.Str
6647
+ }, valid);
6648
+ if (!allErrors)
6649
+ gen.if((0, codegen_1.not)(valid), () => gen.break());
6650
+ }
6651
+ }
6652
+ function unevaluatedDynamic(evaluatedProps, key) {
6653
+ return (0, codegen_1._)`!${evaluatedProps} || !${evaluatedProps}[${key}]`;
6654
+ }
6655
+ function unevaluatedStatic(evaluatedProps, key) {
6656
+ const ps = [];
6657
+ for (const p in evaluatedProps) {
6658
+ if (evaluatedProps[p] === true)
6659
+ ps.push((0, codegen_1._)`${key} !== ${p}`);
6660
+ }
6661
+ return (0, codegen_1.and)(...ps);
6662
+ }
6663
+ }
6664
+ };
6665
+ exports$1.default = def;
6666
+ }
6667
+ });
6668
+
6669
+ // node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js
6670
+ var require_unevaluatedItems = __commonJS({
6671
+ "node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js"(exports$1) {
6672
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6673
+ var codegen_1 = require_codegen();
6674
+ var util_1 = require_util();
6675
+ var error = {
6676
+ message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
6677
+ params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
6678
+ };
6679
+ var def = {
6680
+ keyword: "unevaluatedItems",
6681
+ type: "array",
6682
+ schemaType: ["boolean", "object"],
6683
+ error,
6684
+ code(cxt) {
6685
+ const { gen, schema, data, it } = cxt;
6686
+ const items = it.items || 0;
6687
+ if (items === true)
6688
+ return;
6689
+ const len = gen.const("len", (0, codegen_1._)`${data}.length`);
6690
+ if (schema === false) {
6691
+ cxt.setParams({ len: items });
6692
+ cxt.fail((0, codegen_1._)`${len} > ${items}`);
6693
+ } else if (typeof schema == "object" && !(0, util_1.alwaysValidSchema)(it, schema)) {
6694
+ const valid = gen.var("valid", (0, codegen_1._)`${len} <= ${items}`);
6695
+ gen.if((0, codegen_1.not)(valid), () => validateItems(valid, items));
6696
+ cxt.ok(valid);
6697
+ }
6698
+ it.items = true;
6699
+ function validateItems(valid, from) {
6700
+ gen.forRange("i", from, len, (i) => {
6701
+ cxt.subschema({ keyword: "unevaluatedItems", dataProp: i, dataPropType: util_1.Type.Num }, valid);
6702
+ if (!it.allErrors)
6703
+ gen.if((0, codegen_1.not)(valid), () => gen.break());
6704
+ });
6705
+ }
6706
+ }
6707
+ };
6708
+ exports$1.default = def;
6709
+ }
6710
+ });
6711
+
6712
+ // node_modules/ajv/dist/vocabularies/unevaluated/index.js
6713
+ var require_unevaluated = __commonJS({
6714
+ "node_modules/ajv/dist/vocabularies/unevaluated/index.js"(exports$1) {
6715
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6716
+ var unevaluatedProperties_1 = require_unevaluatedProperties();
6717
+ var unevaluatedItems_1 = require_unevaluatedItems();
6718
+ var unevaluated = [unevaluatedProperties_1.default, unevaluatedItems_1.default];
6719
+ exports$1.default = unevaluated;
6720
+ }
6721
+ });
6722
+
6723
+ // node_modules/ajv/dist/vocabularies/draft2020.js
6724
+ var require_draft2020 = __commonJS({
6725
+ "node_modules/ajv/dist/vocabularies/draft2020.js"(exports$1) {
6726
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6727
+ var core_1 = require_core2();
6728
+ var validation_1 = require_validation();
6729
+ var applicator_1 = require_applicator();
6730
+ var dynamic_1 = require_dynamic();
6731
+ var next_1 = require_next();
6732
+ var unevaluated_1 = require_unevaluated();
6733
+ var format_1 = require_format2();
6734
+ var metadata_1 = require_metadata();
6735
+ var draft2020Vocabularies = [
6736
+ dynamic_1.default,
6737
+ core_1.default,
6738
+ validation_1.default,
6739
+ (0, applicator_1.default)(true),
6740
+ format_1.default,
6741
+ metadata_1.metadataVocabulary,
6742
+ metadata_1.contentVocabulary,
6743
+ next_1.default,
6744
+ unevaluated_1.default
6745
+ ];
6746
+ exports$1.default = draft2020Vocabularies;
6747
+ }
6748
+ });
6749
+
6750
+ // node_modules/ajv/dist/refs/json-schema-2020-12/schema.json
6751
+ var require_schema = __commonJS({
6752
+ "node_modules/ajv/dist/refs/json-schema-2020-12/schema.json"(exports$1, module) {
6753
+ module.exports = {
6754
+ $schema: "https://json-schema.org/draft/2020-12/schema",
6755
+ $id: "https://json-schema.org/draft/2020-12/schema",
6756
+ $vocabulary: {
6757
+ "https://json-schema.org/draft/2020-12/vocab/core": true,
6758
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true,
6759
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
6760
+ "https://json-schema.org/draft/2020-12/vocab/validation": true,
6761
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
6762
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
6763
+ "https://json-schema.org/draft/2020-12/vocab/content": true
6764
+ },
6765
+ $dynamicAnchor: "meta",
6766
+ title: "Core and Validation specifications meta-schema",
6767
+ allOf: [
6768
+ { $ref: "meta/core" },
6769
+ { $ref: "meta/applicator" },
6770
+ { $ref: "meta/unevaluated" },
6771
+ { $ref: "meta/validation" },
6772
+ { $ref: "meta/meta-data" },
6773
+ { $ref: "meta/format-annotation" },
6774
+ { $ref: "meta/content" }
6775
+ ],
6776
+ type: ["object", "boolean"],
6777
+ $comment: "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
6778
+ properties: {
6779
+ definitions: {
6780
+ $comment: '"definitions" has been replaced by "$defs".',
6781
+ type: "object",
6782
+ additionalProperties: { $dynamicRef: "#meta" },
6783
+ deprecated: true,
6784
+ default: {}
6785
+ },
6786
+ dependencies: {
6787
+ $comment: '"dependencies" has been split and replaced by "dependentSchemas" and "dependentRequired" in order to serve their differing semantics.',
6788
+ type: "object",
6789
+ additionalProperties: {
6790
+ anyOf: [{ $dynamicRef: "#meta" }, { $ref: "meta/validation#/$defs/stringArray" }]
6791
+ },
6792
+ deprecated: true,
6793
+ default: {}
6794
+ },
6795
+ $recursiveAnchor: {
6796
+ $comment: '"$recursiveAnchor" has been replaced by "$dynamicAnchor".',
6797
+ $ref: "meta/core#/$defs/anchorString",
6798
+ deprecated: true
6799
+ },
6800
+ $recursiveRef: {
6801
+ $comment: '"$recursiveRef" has been replaced by "$dynamicRef".',
6802
+ $ref: "meta/core#/$defs/uriReferenceString",
6803
+ deprecated: true
6804
+ }
6805
+ }
6806
+ };
6807
+ }
6808
+ });
6809
+
6810
+ // node_modules/ajv/dist/refs/json-schema-2020-12/meta/applicator.json
6811
+ var require_applicator2 = __commonJS({
6812
+ "node_modules/ajv/dist/refs/json-schema-2020-12/meta/applicator.json"(exports$1, module) {
6813
+ module.exports = {
6814
+ $schema: "https://json-schema.org/draft/2020-12/schema",
6815
+ $id: "https://json-schema.org/draft/2020-12/meta/applicator",
6816
+ $vocabulary: {
6817
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true
6818
+ },
6819
+ $dynamicAnchor: "meta",
6820
+ title: "Applicator vocabulary meta-schema",
6821
+ type: ["object", "boolean"],
6822
+ properties: {
6823
+ prefixItems: { $ref: "#/$defs/schemaArray" },
6824
+ items: { $dynamicRef: "#meta" },
6825
+ contains: { $dynamicRef: "#meta" },
6826
+ additionalProperties: { $dynamicRef: "#meta" },
6827
+ properties: {
6828
+ type: "object",
6829
+ additionalProperties: { $dynamicRef: "#meta" },
6830
+ default: {}
6831
+ },
6832
+ patternProperties: {
6833
+ type: "object",
6834
+ additionalProperties: { $dynamicRef: "#meta" },
6835
+ propertyNames: { format: "regex" },
6836
+ default: {}
6837
+ },
6838
+ dependentSchemas: {
6839
+ type: "object",
6840
+ additionalProperties: { $dynamicRef: "#meta" },
6841
+ default: {}
6842
+ },
6843
+ propertyNames: { $dynamicRef: "#meta" },
6844
+ if: { $dynamicRef: "#meta" },
6845
+ then: { $dynamicRef: "#meta" },
6846
+ else: { $dynamicRef: "#meta" },
6847
+ allOf: { $ref: "#/$defs/schemaArray" },
6848
+ anyOf: { $ref: "#/$defs/schemaArray" },
6849
+ oneOf: { $ref: "#/$defs/schemaArray" },
6850
+ not: { $dynamicRef: "#meta" }
6851
+ },
6852
+ $defs: {
6853
+ schemaArray: {
6854
+ type: "array",
6855
+ minItems: 1,
6856
+ items: { $dynamicRef: "#meta" }
6857
+ }
6858
+ }
6859
+ };
6860
+ }
6861
+ });
6862
+
6863
+ // node_modules/ajv/dist/refs/json-schema-2020-12/meta/unevaluated.json
6864
+ var require_unevaluated2 = __commonJS({
6865
+ "node_modules/ajv/dist/refs/json-schema-2020-12/meta/unevaluated.json"(exports$1, module) {
6866
+ module.exports = {
6867
+ $schema: "https://json-schema.org/draft/2020-12/schema",
6868
+ $id: "https://json-schema.org/draft/2020-12/meta/unevaluated",
6869
+ $vocabulary: {
6870
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true
6871
+ },
6872
+ $dynamicAnchor: "meta",
6873
+ title: "Unevaluated applicator vocabulary meta-schema",
6874
+ type: ["object", "boolean"],
6875
+ properties: {
6876
+ unevaluatedItems: { $dynamicRef: "#meta" },
6877
+ unevaluatedProperties: { $dynamicRef: "#meta" }
6878
+ }
6879
+ };
6880
+ }
6881
+ });
6882
+
6883
+ // node_modules/ajv/dist/refs/json-schema-2020-12/meta/content.json
6884
+ var require_content = __commonJS({
6885
+ "node_modules/ajv/dist/refs/json-schema-2020-12/meta/content.json"(exports$1, module) {
6886
+ module.exports = {
6887
+ $schema: "https://json-schema.org/draft/2020-12/schema",
6888
+ $id: "https://json-schema.org/draft/2020-12/meta/content",
6889
+ $vocabulary: {
6890
+ "https://json-schema.org/draft/2020-12/vocab/content": true
6891
+ },
6892
+ $dynamicAnchor: "meta",
6893
+ title: "Content vocabulary meta-schema",
6894
+ type: ["object", "boolean"],
6895
+ properties: {
6896
+ contentEncoding: { type: "string" },
6897
+ contentMediaType: { type: "string" },
6898
+ contentSchema: { $dynamicRef: "#meta" }
6899
+ }
6900
+ };
6901
+ }
6902
+ });
6903
+
6904
+ // node_modules/ajv/dist/refs/json-schema-2020-12/meta/core.json
6905
+ var require_core3 = __commonJS({
6906
+ "node_modules/ajv/dist/refs/json-schema-2020-12/meta/core.json"(exports$1, module) {
6907
+ module.exports = {
6908
+ $schema: "https://json-schema.org/draft/2020-12/schema",
6909
+ $id: "https://json-schema.org/draft/2020-12/meta/core",
6910
+ $vocabulary: {
6911
+ "https://json-schema.org/draft/2020-12/vocab/core": true
6912
+ },
6913
+ $dynamicAnchor: "meta",
6914
+ title: "Core vocabulary meta-schema",
6915
+ type: ["object", "boolean"],
6916
+ properties: {
6917
+ $id: {
6918
+ $ref: "#/$defs/uriReferenceString",
6919
+ $comment: "Non-empty fragments not allowed.",
6920
+ pattern: "^[^#]*#?$"
6921
+ },
6922
+ $schema: { $ref: "#/$defs/uriString" },
6923
+ $ref: { $ref: "#/$defs/uriReferenceString" },
6924
+ $anchor: { $ref: "#/$defs/anchorString" },
6925
+ $dynamicRef: { $ref: "#/$defs/uriReferenceString" },
6926
+ $dynamicAnchor: { $ref: "#/$defs/anchorString" },
6927
+ $vocabulary: {
6928
+ type: "object",
6929
+ propertyNames: { $ref: "#/$defs/uriString" },
6930
+ additionalProperties: {
6931
+ type: "boolean"
6932
+ }
6933
+ },
6934
+ $comment: {
6935
+ type: "string"
6936
+ },
6937
+ $defs: {
6938
+ type: "object",
6939
+ additionalProperties: { $dynamicRef: "#meta" }
6940
+ }
6941
+ },
6942
+ $defs: {
6943
+ anchorString: {
6944
+ type: "string",
6945
+ pattern: "^[A-Za-z_][-A-Za-z0-9._]*$"
6946
+ },
6947
+ uriString: {
6948
+ type: "string",
6949
+ format: "uri"
6950
+ },
6951
+ uriReferenceString: {
6952
+ type: "string",
6953
+ format: "uri-reference"
6954
+ }
6955
+ }
6956
+ };
6957
+ }
6958
+ });
6959
+
6960
+ // node_modules/ajv/dist/refs/json-schema-2020-12/meta/format-annotation.json
6961
+ var require_format_annotation = __commonJS({
6962
+ "node_modules/ajv/dist/refs/json-schema-2020-12/meta/format-annotation.json"(exports$1, module) {
6963
+ module.exports = {
6964
+ $schema: "https://json-schema.org/draft/2020-12/schema",
6965
+ $id: "https://json-schema.org/draft/2020-12/meta/format-annotation",
6966
+ $vocabulary: {
6967
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true
6968
+ },
6969
+ $dynamicAnchor: "meta",
6970
+ title: "Format vocabulary meta-schema for annotation results",
6971
+ type: ["object", "boolean"],
6972
+ properties: {
6973
+ format: { type: "string" }
6974
+ }
6975
+ };
6976
+ }
6977
+ });
6978
+
6979
+ // node_modules/ajv/dist/refs/json-schema-2020-12/meta/meta-data.json
6980
+ var require_meta_data = __commonJS({
6981
+ "node_modules/ajv/dist/refs/json-schema-2020-12/meta/meta-data.json"(exports$1, module) {
6982
+ module.exports = {
6983
+ $schema: "https://json-schema.org/draft/2020-12/schema",
6984
+ $id: "https://json-schema.org/draft/2020-12/meta/meta-data",
6985
+ $vocabulary: {
6986
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true
6987
+ },
6988
+ $dynamicAnchor: "meta",
6989
+ title: "Meta-data vocabulary meta-schema",
6990
+ type: ["object", "boolean"],
6991
+ properties: {
6992
+ title: {
6993
+ type: "string"
6994
+ },
6995
+ description: {
6996
+ type: "string"
6997
+ },
6998
+ default: true,
6999
+ deprecated: {
7000
+ type: "boolean",
7001
+ default: false
7002
+ },
7003
+ readOnly: {
7004
+ type: "boolean",
7005
+ default: false
7006
+ },
7007
+ writeOnly: {
7008
+ type: "boolean",
7009
+ default: false
7010
+ },
7011
+ examples: {
7012
+ type: "array",
7013
+ items: true
7014
+ }
7015
+ }
7016
+ };
7017
+ }
7018
+ });
7019
+
7020
+ // node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.json
7021
+ var require_validation2 = __commonJS({
7022
+ "node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.json"(exports$1, module) {
7023
+ module.exports = {
7024
+ $schema: "https://json-schema.org/draft/2020-12/schema",
7025
+ $id: "https://json-schema.org/draft/2020-12/meta/validation",
7026
+ $vocabulary: {
7027
+ "https://json-schema.org/draft/2020-12/vocab/validation": true
7028
+ },
7029
+ $dynamicAnchor: "meta",
7030
+ title: "Validation vocabulary meta-schema",
7031
+ type: ["object", "boolean"],
7032
+ properties: {
7033
+ type: {
7034
+ anyOf: [
7035
+ { $ref: "#/$defs/simpleTypes" },
7036
+ {
7037
+ type: "array",
7038
+ items: { $ref: "#/$defs/simpleTypes" },
7039
+ minItems: 1,
7040
+ uniqueItems: true
7041
+ }
7042
+ ]
7043
+ },
7044
+ const: true,
7045
+ enum: {
7046
+ type: "array",
7047
+ items: true
7048
+ },
7049
+ multipleOf: {
7050
+ type: "number",
7051
+ exclusiveMinimum: 0
7052
+ },
7053
+ maximum: {
7054
+ type: "number"
7055
+ },
7056
+ exclusiveMaximum: {
7057
+ type: "number"
7058
+ },
7059
+ minimum: {
7060
+ type: "number"
7061
+ },
7062
+ exclusiveMinimum: {
7063
+ type: "number"
7064
+ },
7065
+ maxLength: { $ref: "#/$defs/nonNegativeInteger" },
7066
+ minLength: { $ref: "#/$defs/nonNegativeIntegerDefault0" },
7067
+ pattern: {
7068
+ type: "string",
7069
+ format: "regex"
7070
+ },
7071
+ maxItems: { $ref: "#/$defs/nonNegativeInteger" },
7072
+ minItems: { $ref: "#/$defs/nonNegativeIntegerDefault0" },
7073
+ uniqueItems: {
7074
+ type: "boolean",
7075
+ default: false
7076
+ },
7077
+ maxContains: { $ref: "#/$defs/nonNegativeInteger" },
7078
+ minContains: {
7079
+ $ref: "#/$defs/nonNegativeInteger",
7080
+ default: 1
7081
+ },
7082
+ maxProperties: { $ref: "#/$defs/nonNegativeInteger" },
7083
+ minProperties: { $ref: "#/$defs/nonNegativeIntegerDefault0" },
7084
+ required: { $ref: "#/$defs/stringArray" },
7085
+ dependentRequired: {
7086
+ type: "object",
7087
+ additionalProperties: {
7088
+ $ref: "#/$defs/stringArray"
7089
+ }
7090
+ }
7091
+ },
7092
+ $defs: {
7093
+ nonNegativeInteger: {
7094
+ type: "integer",
7095
+ minimum: 0
7096
+ },
7097
+ nonNegativeIntegerDefault0: {
7098
+ $ref: "#/$defs/nonNegativeInteger",
7099
+ default: 0
7100
+ },
7101
+ simpleTypes: {
7102
+ enum: ["array", "boolean", "integer", "null", "number", "object", "string"]
7103
+ },
7104
+ stringArray: {
7105
+ type: "array",
7106
+ items: { type: "string" },
7107
+ uniqueItems: true,
7108
+ default: []
7109
+ }
7110
+ }
7111
+ };
7112
+ }
7113
+ });
7114
+
7115
+ // node_modules/ajv/dist/refs/json-schema-2020-12/index.js
7116
+ var require_json_schema_2020_12 = __commonJS({
7117
+ "node_modules/ajv/dist/refs/json-schema-2020-12/index.js"(exports$1) {
7118
+ Object.defineProperty(exports$1, "__esModule", { value: true });
7119
+ var metaSchema = require_schema();
7120
+ var applicator = require_applicator2();
7121
+ var unevaluated = require_unevaluated2();
7122
+ var content = require_content();
7123
+ var core = require_core3();
7124
+ var format = require_format_annotation();
7125
+ var metadata = require_meta_data();
7126
+ var validation = require_validation2();
7127
+ var META_SUPPORT_DATA = ["/properties"];
7128
+ function addMetaSchema2020($data) {
7129
+ [
7130
+ metaSchema,
7131
+ applicator,
7132
+ unevaluated,
7133
+ content,
7134
+ core,
7135
+ with$data(this, format),
7136
+ metadata,
7137
+ with$data(this, validation)
7138
+ ].forEach((sch) => this.addMetaSchema(sch, void 0, false));
7139
+ return this;
7140
+ function with$data(ajv, sch) {
7141
+ return $data ? ajv.$dataMetaSchema(sch, META_SUPPORT_DATA) : sch;
7142
+ }
7143
+ }
7144
+ exports$1.default = addMetaSchema2020;
7145
+ }
7146
+ });
7147
+
7148
+ // node_modules/ajv/dist/2020.js
7149
+ var require__ = __commonJS({
7150
+ "node_modules/ajv/dist/2020.js"(exports$1, module) {
7151
+ Object.defineProperty(exports$1, "__esModule", { value: true });
7152
+ exports$1.MissingRefError = exports$1.ValidationError = exports$1.CodeGen = exports$1.Name = exports$1.nil = exports$1.stringify = exports$1.str = exports$1._ = exports$1.KeywordCxt = exports$1.Ajv2020 = void 0;
7153
+ var core_1 = require_core();
7154
+ var draft2020_1 = require_draft2020();
7155
+ var discriminator_1 = require_discriminator();
7156
+ var json_schema_2020_12_1 = require_json_schema_2020_12();
7157
+ var META_SCHEMA_ID = "https://json-schema.org/draft/2020-12/schema";
7158
+ var Ajv20202 = class extends core_1.default {
7159
+ constructor(opts = {}) {
7160
+ super({
7161
+ ...opts,
7162
+ dynamicRef: true,
7163
+ next: true,
7164
+ unevaluated: true
7165
+ });
7166
+ }
7167
+ _addVocabularies() {
7168
+ super._addVocabularies();
7169
+ draft2020_1.default.forEach((v) => this.addVocabulary(v));
7170
+ if (this.opts.discriminator)
7171
+ this.addKeyword(discriminator_1.default);
7172
+ }
7173
+ _addDefaultMetaSchema() {
7174
+ super._addDefaultMetaSchema();
7175
+ const { $data, meta } = this.opts;
7176
+ if (!meta)
7177
+ return;
7178
+ json_schema_2020_12_1.default.call(this, $data);
7179
+ this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
7180
+ }
7181
+ defaultMeta() {
7182
+ return this.opts.defaultMeta = super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : void 0);
7183
+ }
7184
+ };
7185
+ exports$1.Ajv2020 = Ajv20202;
7186
+ module.exports = exports$1 = Ajv20202;
7187
+ module.exports.Ajv2020 = Ajv20202;
7188
+ Object.defineProperty(exports$1, "__esModule", { value: true });
7189
+ exports$1.default = Ajv20202;
7190
+ var validate_1 = require_validate();
7191
+ Object.defineProperty(exports$1, "KeywordCxt", { enumerable: true, get: function() {
7192
+ return validate_1.KeywordCxt;
7193
+ } });
7194
+ var codegen_1 = require_codegen();
7195
+ Object.defineProperty(exports$1, "_", { enumerable: true, get: function() {
7196
+ return codegen_1._;
7197
+ } });
7198
+ Object.defineProperty(exports$1, "str", { enumerable: true, get: function() {
7199
+ return codegen_1.str;
7200
+ } });
7201
+ Object.defineProperty(exports$1, "stringify", { enumerable: true, get: function() {
7202
+ return codegen_1.stringify;
7203
+ } });
7204
+ Object.defineProperty(exports$1, "nil", { enumerable: true, get: function() {
7205
+ return codegen_1.nil;
7206
+ } });
7207
+ Object.defineProperty(exports$1, "Name", { enumerable: true, get: function() {
7208
+ return codegen_1.Name;
7209
+ } });
7210
+ Object.defineProperty(exports$1, "CodeGen", { enumerable: true, get: function() {
7211
+ return codegen_1.CodeGen;
7212
+ } });
7213
+ var validation_error_1 = require_validation_error();
7214
+ Object.defineProperty(exports$1, "ValidationError", { enumerable: true, get: function() {
7215
+ return validation_error_1.default;
7216
+ } });
7217
+ var ref_error_1 = require_ref_error();
7218
+ Object.defineProperty(exports$1, "MissingRefError", { enumerable: true, get: function() {
7219
+ return ref_error_1.default;
7220
+ } });
7221
+ }
7222
+ });
7223
+
6417
7224
  // src/step-machine/reducer.ts
6418
7225
  function applyStepResult(flow, state, stepName, stepResult) {
6419
7226
  const stepConfig = flow.steps[stepName];
@@ -6439,7 +7246,7 @@ function applyStepResult(flow, state, stepName, stepResult) {
6439
7246
  };
6440
7247
  }
6441
7248
  }
6442
- const nextStep = stepConfig.transitions[stepResult.result];
7249
+ const nextStep = stepConfig.failure_transitions?.[stepResult.result] ?? stepConfig.transitions[stepResult.result];
6443
7250
  if (!nextStep) {
6444
7251
  throw new Error(
6445
7252
  `No transition defined for result "${stepResult.result}" in step "${stepName}"`
@@ -6644,6 +7451,15 @@ var StepMachine = class {
6644
7451
  );
6645
7452
  }
6646
7453
  }
7454
+ if (stepConfig.failure_transitions) {
7455
+ for (const [result, target] of Object.entries(stepConfig.failure_transitions)) {
7456
+ if (!steps[target] && !terminal_states[target]) {
7457
+ throw new Error(
7458
+ `Step "${stepName}" failure_transition "${result}" points to unknown step "${target}"`
7459
+ );
7460
+ }
7461
+ }
7462
+ }
6647
7463
  }
6648
7464
  }
6649
7465
  on(eventType, listener) {
@@ -6873,6 +7689,9 @@ function validateStepFlowConfig(flow) {
6873
7689
  if (!step.transitions || typeof step.transitions !== "object") {
6874
7690
  errors.push(`Step "${stepName}" must have a "transitions" object`);
6875
7691
  }
7692
+ if (step.failure_transitions !== void 0 && typeof step.failure_transitions !== "object") {
7693
+ errors.push(`Step "${stepName}" failure_transitions must be an object when provided`);
7694
+ }
6876
7695
  }
6877
7696
  }
6878
7697
  if (!f.terminal_states || typeof f.terminal_states !== "object") {
@@ -6993,6 +7812,11 @@ var flow_schema_default = {
6993
7812
  additionalProperties: { type: "string" },
6994
7813
  minProperties: 1
6995
7814
  },
7815
+ failure_transitions: {
7816
+ type: "object",
7817
+ description: "Mapping of failure-like results (e.g. failure, timeout) -> next step name",
7818
+ additionalProperties: { type: "string" }
7819
+ },
6996
7820
  retry: {
6997
7821
  $ref: "#/definitions/retry_config"
6998
7822
  },
@@ -7931,8 +8755,8 @@ function apply(state, event, graph) {
7931
8755
  return applyInjectTokens(state, event.tokens);
7932
8756
  case "agent-action":
7933
8757
  return applyAgentAction(state, event.action, graph, event.config);
7934
- case "task-creation":
7935
- return applyTaskCreation(state, event.taskName, event.taskConfig);
8758
+ case "task-upsert":
8759
+ return applyTaskUpsert(state, event.taskName, event.taskConfig);
7936
8760
  default:
7937
8761
  return state;
7938
8762
  }
@@ -7989,7 +8813,7 @@ function applyAgentAction(state, action, graph, config) {
7989
8813
  return state;
7990
8814
  }
7991
8815
  }
7992
- function applyTaskCreation(state, taskName, taskConfig) {
8816
+ function applyTaskUpsert(state, taskName, taskConfig) {
7993
8817
  if (!taskName || !taskConfig || !Array.isArray(taskConfig.provides)) {
7994
8818
  return state;
7995
8819
  }
@@ -7997,7 +8821,7 @@ function applyTaskCreation(state, taskName, taskConfig) {
7997
8821
  ...state,
7998
8822
  tasks: {
7999
8823
  ...state.tasks,
8000
- [taskName]: createDefaultGraphEngineStore()
8824
+ [taskName]: state.tasks[taskName] ?? createDefaultGraphEngineStore()
8001
8825
  },
8002
8826
  lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
8003
8827
  };
@@ -9269,43 +10093,51 @@ function applyEvent(live, event) {
9269
10093
  if ("executionId" in event && event.executionId && event.executionId !== state.executionId) {
9270
10094
  return live;
9271
10095
  }
9272
- let newState;
9273
10096
  switch (event.type) {
10097
+ // --- Execution state transitions ---
9274
10098
  case "task-started":
9275
- newState = applyTaskStart(state, event.taskName);
9276
- break;
10099
+ return { config, state: applyTaskStart(state, event.taskName) };
9277
10100
  case "task-completed":
9278
- newState = applyTaskCompletion(state, config, event.taskName, event.result, event.dataHash, event.data);
9279
- break;
10101
+ return { config, state: applyTaskCompletion(state, config, event.taskName, event.result, event.dataHash, event.data) };
9280
10102
  case "task-failed":
9281
- newState = applyTaskFailure(state, config, event.taskName, event.error);
9282
- break;
10103
+ return { config, state: applyTaskFailure(state, config, event.taskName, event.error) };
9283
10104
  case "task-progress":
9284
- newState = applyTaskProgress(state, event.taskName, event.message, event.progress);
9285
- break;
10105
+ return { config, state: applyTaskProgress(state, event.taskName, event.message, event.progress) };
9286
10106
  case "task-restart":
9287
- newState = applyTaskRestart(state, event.taskName);
9288
- break;
10107
+ return { config, state: applyTaskRestart(state, event.taskName) };
9289
10108
  case "inject-tokens":
9290
- newState = {
9291
- ...state,
9292
- availableOutputs: [.../* @__PURE__ */ new Set([...state.availableOutputs, ...event.tokens])],
9293
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
10109
+ return {
10110
+ config,
10111
+ state: {
10112
+ ...state,
10113
+ availableOutputs: [.../* @__PURE__ */ new Set([...state.availableOutputs, ...event.tokens])],
10114
+ lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
10115
+ }
9294
10116
  };
9295
- break;
9296
10117
  case "agent-action":
9297
- newState = applyAgentAction2(state, event.action);
9298
- break;
10118
+ return { config, state: applyAgentAction2(state, event.action) };
10119
+ // --- Structural mutations ---
10120
+ case "task-upsert":
10121
+ return addNode(live, event.taskName, event.taskConfig);
10122
+ case "task-removal":
10123
+ return removeNode(live, event.taskName);
10124
+ case "node-requires-add":
10125
+ return addRequires(live, event.nodeName, event.tokens);
10126
+ case "node-requires-remove":
10127
+ return removeRequires(live, event.nodeName, event.tokens);
10128
+ case "node-provides-add":
10129
+ return addProvides(live, event.nodeName, event.tokens);
10130
+ case "node-provides-remove":
10131
+ return removeProvides(live, event.nodeName, event.tokens);
9299
10132
  default:
9300
10133
  return live;
9301
10134
  }
9302
- return { config, state: newState };
9303
10135
  }
9304
10136
  function applyEvents(live, events) {
9305
10137
  return events.reduce((current, event) => applyEvent(current, event), live);
9306
10138
  }
9307
10139
  function addNode(live, name, taskConfig) {
9308
- if (live.config.tasks[name]) return live;
10140
+ const exists = !!live.config.tasks[name];
9309
10141
  return {
9310
10142
  config: {
9311
10143
  ...live.config,
@@ -9313,7 +10145,10 @@ function addNode(live, name, taskConfig) {
9313
10145
  },
9314
10146
  state: {
9315
10147
  ...live.state,
9316
- tasks: { ...live.state.tasks, [name]: createDefaultGraphEngineStore3() },
10148
+ tasks: {
10149
+ ...live.state.tasks,
10150
+ [name]: exists ? live.state.tasks[name] : createDefaultGraphEngineStore3()
10151
+ },
9317
10152
  lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
9318
10153
  }
9319
10154
  };
@@ -10020,6 +10855,8 @@ function getDownstream(live, nodeName) {
10020
10855
  }));
10021
10856
  return { nodeName, nodes, tokens: [...tokenSet] };
10022
10857
  }
10858
+
10859
+ // src/continuous-event-graph/journal.ts
10023
10860
  var MemoryJournal = class {
10024
10861
  buffer = [];
10025
10862
  append(event) {
@@ -10034,39 +10871,11 @@ var MemoryJournal = class {
10034
10871
  return this.buffer.length;
10035
10872
  }
10036
10873
  };
10037
- var FileJournal = class {
10038
- constructor(path) {
10039
- this.path = path;
10040
- if (!existsSync(path)) {
10041
- writeFileSync(path, "", "utf-8");
10042
- }
10043
- }
10044
- path;
10045
- pending = 0;
10046
- append(event) {
10047
- appendFileSync(this.path, JSON.stringify(event) + "\n", "utf-8");
10048
- this.pending++;
10049
- }
10050
- drain() {
10051
- const content = readFileSync(this.path, "utf-8").trim();
10052
- writeFileSync(this.path, "", "utf-8");
10053
- this.pending = 0;
10054
- if (!content) return [];
10055
- return content.split("\n").map((line) => JSON.parse(line));
10056
- }
10057
- get size() {
10058
- try {
10059
- const content = readFileSync(this.path, "utf-8").trim();
10060
- if (!content) return 0;
10061
- return content.split("\n").length;
10062
- } catch {
10063
- return this.pending;
10064
- }
10065
- }
10066
- };
10874
+
10875
+ // src/continuous-event-graph/reactive.ts
10067
10876
  function computeDataHash(data) {
10068
10877
  const json = stableStringify(data);
10069
- return createHash("sha256").update(json).digest("hex").slice(0, 16);
10878
+ return fnv1a64Hex(json);
10070
10879
  }
10071
10880
  function stableStringify(value) {
10072
10881
  if (value === null || value === void 0 || typeof value !== "object") {
@@ -10079,28 +10888,65 @@ function stableStringify(value) {
10079
10888
  const keys = Object.keys(obj).sort();
10080
10889
  return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
10081
10890
  }
10891
+ function fnv1a64Hex(input) {
10892
+ let hash = 0xcbf29ce484222325n;
10893
+ const prime = 0x100000001b3n;
10894
+ const mod = 0xffffffffffffffffn;
10895
+ for (let i = 0; i < input.length; i++) {
10896
+ hash ^= BigInt(input.charCodeAt(i));
10897
+ hash = hash * prime & mod;
10898
+ }
10899
+ return hash.toString(16).padStart(16, "0");
10900
+ }
10901
+ function base64UrlEncode(input) {
10902
+ if (typeof Buffer !== "undefined") {
10903
+ return Buffer.from(input, "utf8").toString("base64url");
10904
+ }
10905
+ if (typeof btoa === "function") {
10906
+ const bytes = new TextEncoder().encode(input);
10907
+ let binary = "";
10908
+ for (const b of bytes) binary += String.fromCharCode(b);
10909
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
10910
+ }
10911
+ throw new Error("No base64 encoder available in this runtime");
10912
+ }
10913
+ function base64UrlDecode(input) {
10914
+ if (typeof Buffer !== "undefined") {
10915
+ return Buffer.from(input, "base64url").toString("utf8");
10916
+ }
10917
+ if (typeof atob === "function") {
10918
+ const base64 = input.replace(/-/g, "+").replace(/_/g, "/");
10919
+ const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
10920
+ const binary = atob(padded);
10921
+ const bytes = new Uint8Array(binary.length);
10922
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
10923
+ return new TextDecoder().decode(bytes);
10924
+ }
10925
+ throw new Error("No base64 decoder available in this runtime");
10926
+ }
10082
10927
  function encodeCallbackToken(taskName) {
10083
10928
  const payload = JSON.stringify({ t: taskName, n: Date.now().toString(36) + Math.random().toString(36).slice(2, 6) });
10084
- return Buffer.from(payload).toString("base64url");
10929
+ return base64UrlEncode(payload);
10085
10930
  }
10086
10931
  function decodeCallbackToken(token) {
10087
10932
  try {
10088
- const payload = JSON.parse(Buffer.from(token, "base64url").toString());
10933
+ const payload = JSON.parse(base64UrlDecode(token));
10089
10934
  if (typeof payload?.t === "string") return { taskName: payload.t };
10090
10935
  return null;
10091
10936
  } catch {
10092
10937
  return null;
10093
10938
  }
10094
10939
  }
10095
- function createReactiveGraph(config, options, executionId) {
10940
+ function createReactiveGraph(configOrLive, options, executionId) {
10096
10941
  const {
10097
10942
  handlers: initialHandlers,
10098
- journal = new MemoryJournal(),
10099
10943
  onDrain
10100
10944
  } = options;
10101
- let live = createLiveGraph(config, executionId);
10945
+ const inputQueue = new MemoryJournal();
10946
+ let live = "state" in configOrLive && "config" in configOrLive ? configOrLive : createLiveGraph(configOrLive, executionId);
10102
10947
  let disposed = false;
10103
10948
  const handlers = new Map(Object.entries(initialHandlers));
10949
+ const internalJournal = new MemoryJournal();
10104
10950
  let draining = false;
10105
10951
  let drainQueued = false;
10106
10952
  function drain() {
@@ -10120,7 +10966,9 @@ function createReactiveGraph(config, options, executionId) {
10120
10966
  }
10121
10967
  }
10122
10968
  function drainOnce() {
10123
- const events = journal.drain();
10969
+ const internalEvents = internalJournal.drain();
10970
+ const inputEvents = inputQueue.drain();
10971
+ const events = [...internalEvents, ...inputEvents];
10124
10972
  if (events.length > 0) {
10125
10973
  live = applyEvents(live, events);
10126
10974
  }
@@ -10131,6 +10979,26 @@ function createReactiveGraph(config, options, executionId) {
10131
10979
  for (const taskName of result.eligible) {
10132
10980
  dispatchTask(taskName);
10133
10981
  }
10982
+ for (const event of events) {
10983
+ if (event.type === "task-progress") {
10984
+ const { taskName, update } = event;
10985
+ const taskConfig = live.config.tasks[taskName];
10986
+ if (!taskConfig) continue;
10987
+ const taskState = live.state.tasks[taskName];
10988
+ if (!taskState || taskState.status !== "running") continue;
10989
+ const callbackToken = encodeCallbackToken(taskName);
10990
+ runPipeline(taskName, callbackToken, update).catch((error) => {
10991
+ if (disposed) return;
10992
+ internalJournal.append({
10993
+ type: "task-failed",
10994
+ taskName,
10995
+ error: error.message ?? String(error),
10996
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
10997
+ });
10998
+ drain();
10999
+ });
11000
+ }
11001
+ }
10134
11002
  }
10135
11003
  function resolveUpstreamState(taskName) {
10136
11004
  const taskConfig = live.config.tasks[taskName];
@@ -10152,7 +11020,7 @@ function createReactiveGraph(config, options, executionId) {
10152
11020
  }
10153
11021
  return state;
10154
11022
  }
10155
- async function runPipeline(taskName, callbackToken) {
11023
+ async function runPipeline(taskName, callbackToken, update) {
10156
11024
  const taskConfig = live.config.tasks[taskName];
10157
11025
  const handlerNames = taskConfig.taskHandlers ?? [];
10158
11026
  const upstreamState = resolveUpstreamState(taskName);
@@ -10166,7 +11034,8 @@ function createReactiveGraph(config, options, executionId) {
10166
11034
  state: upstreamState,
10167
11035
  taskState: live.state.tasks[taskName],
10168
11036
  config: taskConfig,
10169
- callbackToken
11037
+ callbackToken,
11038
+ update
10170
11039
  };
10171
11040
  const status = await handler(input);
10172
11041
  if (status === "task-initiate-failure") {
@@ -10180,15 +11049,16 @@ function createReactiveGraph(config, options, executionId) {
10180
11049
  if (!handlerNames || handlerNames.length === 0) {
10181
11050
  return;
10182
11051
  }
10183
- journal.append({
11052
+ internalJournal.append({
10184
11053
  type: "task-started",
10185
11054
  taskName,
10186
11055
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
10187
11056
  });
11057
+ drain();
10188
11058
  const callbackToken = encodeCallbackToken(taskName);
10189
11059
  runPipeline(taskName, callbackToken).catch((error) => {
10190
11060
  if (disposed) return;
10191
- journal.append({
11061
+ internalJournal.append({
10192
11062
  type: "task-failed",
10193
11063
  taskName,
10194
11064
  error: error.message ?? String(error),
@@ -10203,16 +11073,16 @@ function createReactiveGraph(config, options, executionId) {
10203
11073
  if (event.type === "task-completed" && event.data && !event.dataHash) {
10204
11074
  event = { ...event, dataHash: computeDataHash(event.data) };
10205
11075
  }
10206
- journal.append(event);
11076
+ inputQueue.append(event);
10207
11077
  drain();
10208
11078
  },
10209
11079
  pushAll(events) {
10210
11080
  if (disposed) return;
10211
11081
  for (const event of events) {
10212
11082
  if (event.type === "task-completed" && event.data && !event.dataHash) {
10213
- journal.append({ ...event, dataHash: computeDataHash(event.data) });
11083
+ inputQueue.append({ ...event, dataHash: computeDataHash(event.data) });
10214
11084
  } else {
10215
- journal.append(event);
11085
+ inputQueue.append(event);
10216
11086
  }
10217
11087
  }
10218
11088
  drain();
@@ -10224,7 +11094,7 @@ function createReactiveGraph(config, options, executionId) {
10224
11094
  const { taskName } = decoded;
10225
11095
  if (!live.config.tasks[taskName]) return;
10226
11096
  if (errors && errors.length > 0) {
10227
- journal.append({
11097
+ inputQueue.append({
10228
11098
  type: "task-failed",
10229
11099
  taskName,
10230
11100
  error: errors.join("; "),
@@ -10232,7 +11102,7 @@ function createReactiveGraph(config, options, executionId) {
10232
11102
  });
10233
11103
  } else {
10234
11104
  const dataHash = data && Object.keys(data).length > 0 ? computeDataHash(data) : void 0;
10235
- journal.append({
11105
+ inputQueue.append({
10236
11106
  type: "task-completed",
10237
11107
  taskName,
10238
11108
  data,
@@ -10244,31 +11114,33 @@ function createReactiveGraph(config, options, executionId) {
10244
11114
  },
10245
11115
  addNode(name, taskConfig) {
10246
11116
  if (disposed) return;
10247
- live = addNode(live, name, taskConfig);
11117
+ inputQueue.append({ type: "task-upsert", taskName: name, taskConfig, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
10248
11118
  drain();
10249
11119
  },
10250
11120
  removeNode(name) {
10251
11121
  if (disposed) return;
10252
- live = removeNode(live, name);
11122
+ inputQueue.append({ type: "task-removal", taskName: name, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
11123
+ drain();
10253
11124
  },
10254
11125
  addRequires(nodeName, tokens) {
10255
11126
  if (disposed) return;
10256
- live = addRequires(live, nodeName, tokens);
11127
+ inputQueue.append({ type: "node-requires-add", nodeName, tokens, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
10257
11128
  drain();
10258
11129
  },
10259
11130
  removeRequires(nodeName, tokens) {
10260
11131
  if (disposed) return;
10261
- live = removeRequires(live, nodeName, tokens);
11132
+ inputQueue.append({ type: "node-requires-remove", nodeName, tokens, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
10262
11133
  drain();
10263
11134
  },
10264
11135
  addProvides(nodeName, tokens) {
10265
11136
  if (disposed) return;
10266
- live = addProvides(live, nodeName, tokens);
11137
+ inputQueue.append({ type: "node-provides-add", nodeName, tokens, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
10267
11138
  drain();
10268
11139
  },
10269
11140
  removeProvides(nodeName, tokens) {
10270
11141
  if (disposed) return;
10271
- live = removeProvides(live, nodeName, tokens);
11142
+ inputQueue.append({ type: "node-provides-remove", nodeName, tokens, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
11143
+ drain();
10272
11144
  },
10273
11145
  registerHandler(name, fn) {
10274
11146
  handlers.set(name, fn);
@@ -10279,7 +11151,7 @@ function createReactiveGraph(config, options, executionId) {
10279
11151
  retrigger(taskName) {
10280
11152
  if (disposed) return;
10281
11153
  if (!live.config.tasks[taskName]) return;
10282
- journal.append({
11154
+ inputQueue.append({
10283
11155
  type: "task-restart",
10284
11156
  taskName,
10285
11157
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -10290,7 +11162,7 @@ function createReactiveGraph(config, options, executionId) {
10290
11162
  if (disposed) return;
10291
11163
  for (const name of taskNames) {
10292
11164
  if (!live.config.tasks[name]) continue;
10293
- journal.append({
11165
+ inputQueue.append({
10294
11166
  type: "task-restart",
10295
11167
  taskName: name,
10296
11168
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -10298,6 +11170,9 @@ function createReactiveGraph(config, options, executionId) {
10298
11170
  }
10299
11171
  drain();
10300
11172
  },
11173
+ snapshot() {
11174
+ return snapshot(live);
11175
+ },
10301
11176
  getState() {
10302
11177
  return live;
10303
11178
  },
@@ -10665,13 +11540,11 @@ function createNoopHandler(getResolve, staticData) {
10665
11540
  var live_cards_schema_default = {
10666
11541
  $schema: "http://json-schema.org/draft-07/schema#",
10667
11542
  $id: "https://nsreehari.github.io/boards/live-cards.schema.json",
10668
- title: "LiveCards Node Schema",
10669
- description: "Schema for Card and ExternalSource nodes in the LiveCards Board/Canvas engine",
10670
11543
  definitions: {
10671
11544
  bind_ref: {
10672
- description: "A state path reference, e.g. 'state.raw_quotes' or 'state.compute_vars.total'",
11545
+ description: "A card data path reference, e.g. 'card_data.raw_quotes' or 'requires.upstream'",
10673
11546
  type: "string",
10674
- pattern: "^state\\."
11547
+ pattern: "^(card_data|requires|fetched_sources|computed_values)(\\.|$)"
10675
11548
  },
10676
11549
  bind_or_literal: {
10677
11550
  description: "A literal value or a bind reference object",
@@ -10740,7 +11613,7 @@ var live_cards_schema_default = {
10740
11613
  ]
10741
11614
  },
10742
11615
  input: {
10743
- description: "state.path, literal, array of inputs, or nested compute_expr",
11616
+ description: "card_data.path, literal, array of inputs, or nested compute_expr",
10744
11617
  oneOf: [
10745
11618
  { type: "string" },
10746
11619
  { type: "number" },
@@ -10764,38 +11637,43 @@ var live_cards_schema_default = {
10764
11637
  tags: { type: "array", items: { type: "string" } }
10765
11638
  }
10766
11639
  },
10767
- data: {
11640
+ requires: {
11641
+ type: "array",
11642
+ items: { type: "string" },
11643
+ description: "IDs of upstream nodes this node depends on"
11644
+ },
11645
+ provides: {
11646
+ type: "array",
11647
+ items: {
11648
+ type: "object",
11649
+ required: ["bindTo", "src"],
11650
+ properties: {
11651
+ bindTo: { type: "string", description: "Token name published downstream" },
11652
+ src: { type: "string", description: "Path to read value from (card_data.*, requires.*, fetched_sources.*, computed_values.*)" }
11653
+ }
11654
+ },
11655
+ description: "Explicit bindings exposing computed or card_data values downstream as named tokens"
11656
+ },
11657
+ compute_step: {
11658
+ description: "A single ordered compute step: reads card_data.*/requires.*/computed_values.*, writes to computed_values[bindTo]",
10768
11659
  type: "object",
11660
+ required: ["bindTo", "expr"],
10769
11661
  properties: {
10770
- requires: {
10771
- type: "array",
10772
- items: { type: "string" },
10773
- description: "IDs of upstream nodes this node depends on"
10774
- },
10775
- provides: {
10776
- type: "object",
10777
- description: "Subset of state exposed downstream. Keys are published names, values are bind refs.",
10778
- additionalProperties: { $ref: "#/definitions/bind_or_literal" }
10779
- }
11662
+ bindTo: { type: "string", description: "Key in computed_values to write result" },
11663
+ expr: { type: "string", description: "JSONata expression evaluated against { card_data, requires, fetched_sources, computed_values }" }
10780
11664
  }
10781
11665
  },
10782
11666
  source_def: {
11667
+ description: "One source entry. The engine only cares about 'bindTo' (compute namespace key) and 'outputFile' (delivery signal). Every other property is yours \u2014 add whatever your task-executor needs: kind, url, headers, mailbox, channel, model, query, etc. The full object is passed verbatim as the --in JSON to the executor.",
10783
11668
  type: "object",
10784
- required: ["kind", "bindTo"],
11669
+ required: ["bindTo"],
11670
+ additionalProperties: true,
10785
11671
  properties: {
10786
- kind: { enum: ["api", "websocket", "static", "llm"] },
10787
- bindTo: { $ref: "#/definitions/bind_ref", description: "state path to write fetched data into" },
10788
- method: { enum: ["GET", "POST", "PUT", "DELETE"], default: "GET" },
10789
- url_template: { type: "string", description: "URL with {{var}} placeholders" },
10790
- headers: { type: "object", additionalProperties: { $ref: "#/definitions/bind_or_literal" } },
10791
- body_template: { type: "object", description: "Request body with {{var}} placeholders or bind refs" },
10792
- template_vars: {
10793
- type: "object",
10794
- additionalProperties: { $ref: "#/definitions/bind_or_literal" },
10795
- description: "Variables for url/body templates \u2014 static values or bind refs"
10796
- },
10797
- poll_interval: { type: "integer", minimum: 0, description: "Auto-refresh in seconds (0 = manual)" },
10798
- transform: { type: "string", description: "Dot-path to extract from response, e.g. 'data.items'" }
11672
+ bindTo: { type: "string", description: "Key under fetched_sources.* available in compute expressions" },
11673
+ outputFile: { type: "string", description: "Board-relative path the executor writes its JSON result to. Presence of this file signals delivery." },
11674
+ optionalForCompletionGating: { type: "boolean", default: false, description: "When true this source does not gate card completion. Default false when absent, so sources are completion-gating by default." },
11675
+ timeout: { type: "integer", minimum: 0, default: 12e4, description: "Executor/script timeout in ms. Default: 120 000 (2 min)." },
11676
+ script: { type: "string", description: "Legacy direct-run: shell command executed when no .task-executor is registered. stdout is captured as the result." }
10799
11677
  }
10800
11678
  },
10801
11679
  render_element: {
@@ -10819,19 +11697,17 @@ var live_cards_schema_default = {
10819
11697
  "text",
10820
11698
  "markdown",
10821
11699
  "custom",
10822
- "file-upload",
10823
- "chat",
10824
11700
  "actions"
10825
11701
  ]
10826
11702
  },
10827
11703
  label: { type: "string", description: "Heading above this element" },
10828
11704
  className: { type: "string", description: "Bootstrap grid class, e.g. 'col-12 col-md-6'" },
10829
- visible: { type: "string", description: "state path \u2014 element shown only if truthy" },
11705
+ visible: { type: "string", description: "card_data/requires/fetched_sources/computed_values path \u2014 element shown only if truthy" },
10830
11706
  data: {
10831
11707
  type: "object",
10832
11708
  properties: {
10833
- bind: { $ref: "#/definitions/bind_ref", description: "state path to read data from" },
10834
- writeTo: { $ref: "#/definitions/bind_ref", description: "state path for user input (form, filter, todo, notes)" },
11709
+ bind: { $ref: "#/definitions/bind_ref", description: "card_data/requires/fetched_sources/computed_values path to read data from" },
11710
+ writeTo: { $ref: "#/definitions/bind_ref", description: "card_data path for user input (form, filter, todo, notes)" },
10835
11711
  columns: { type: "array", items: { type: "string" }, description: "table: visible columns" },
10836
11712
  maxRows: { type: "integer", description: "table/list: max rows to display" },
10837
11713
  sortable: { type: "boolean", default: true, description: "table: enable click-to-sort" },
@@ -10864,7 +11740,7 @@ var live_cards_schema_default = {
10864
11740
  label: { type: "string" },
10865
11741
  style: { type: "string", description: "Bootstrap button variant, e.g. 'success', 'outline-danger'" },
10866
11742
  size: { type: "string", default: "sm" },
10867
- disabled: { oneOf: [{ type: "boolean" }, { type: "string", description: "state path \u2014 truthy = disabled" }] }
11743
+ disabled: { oneOf: [{ type: "boolean" }, { type: "string", description: "card_data/requires/fetched_sources/computed_values path \u2014 truthy = disabled" }] }
10868
11744
  }
10869
11745
  }
10870
11746
  }
@@ -10913,69 +11789,118 @@ var live_cards_schema_default = {
10913
11789
  }
10914
11790
  }
10915
11791
  },
10916
- oneOf: [
10917
- {
10918
- title: "Card",
10919
- description: "A renderable card node with view elements",
11792
+ title: "LiveCard",
11793
+ description: "A unified card node. Behavior depends on which sections are present (sources, compute, view, etc.)",
11794
+ type: "object",
11795
+ required: ["id"],
11796
+ additionalProperties: false,
11797
+ properties: {
11798
+ id: { type: "string" },
11799
+ requires: { $ref: "#/definitions/requires" },
11800
+ provides: { $ref: "#/definitions/provides" },
11801
+ meta: { $ref: "#/definitions/meta" },
11802
+ view: { $ref: "#/definitions/view" },
11803
+ card_data: {
10920
11804
  type: "object",
10921
- required: ["id", "type", "view", "state"],
10922
- additionalProperties: false,
11805
+ description: "Authored card data supplied in the card definition",
10923
11806
  properties: {
10924
- id: { type: "string" },
10925
- type: { const: "card" },
10926
- meta: { $ref: "#/definitions/meta" },
10927
- data: { $ref: "#/definitions/data" },
10928
- view: { $ref: "#/definitions/view" },
10929
- state: {
10930
- type: "object",
10931
- additionalProperties: true,
10932
- properties: {
10933
- status: { enum: ["fresh", "stale", "loading", "error"] },
10934
- lastRun: { type: "string", format: "date-time" },
10935
- error: { type: "string" }
11807
+ files: {
11808
+ type: "array",
11809
+ description: "Optional uploaded-file metadata maintained by host handlers. Stored name is normalized and serial-prefixed (for example 001-my_file.pdf).",
11810
+ items: {
11811
+ type: "object",
11812
+ required: ["name", "stored_name"],
11813
+ properties: {
11814
+ name: { type: "string", minLength: 1 },
11815
+ stored_name: {
11816
+ type: "string",
11817
+ minLength: 5,
11818
+ maxLength: 32,
11819
+ pattern: "^[0-9]{3,}-[a-z0-9._-]+$"
11820
+ },
11821
+ size: {
11822
+ oneOf: [
11823
+ { type: "integer", minimum: 0 },
11824
+ { type: "null" }
11825
+ ]
11826
+ },
11827
+ mime_type: { type: "string" },
11828
+ path: { type: "string", pattern: "^[^\\s]+/files/[0-9]{3,}-[a-z0-9._-]+$" },
11829
+ uploaded_at: { type: "string", format: "date-time" }
11830
+ },
11831
+ additionalProperties: false
10936
11832
  }
10937
- },
10938
- compute: {
10939
- type: "object",
10940
- description: "Derived state: key = state path to write, value = compute_expr",
10941
- additionalProperties: { $ref: "#/definitions/compute_expr" }
10942
11833
  }
10943
- }
11834
+ },
11835
+ additionalProperties: true
10944
11836
  },
10945
- {
10946
- title: "ExternalSource",
10947
- description: "A data-only node that fetches from external systems (no view)",
10948
- type: "object",
10949
- required: ["id", "type", "source", "state"],
10950
- additionalProperties: false,
10951
- properties: {
10952
- id: { type: "string" },
10953
- type: { const: "source" },
10954
- meta: { $ref: "#/definitions/meta" },
10955
- data: { $ref: "#/definitions/data" },
10956
- source: { $ref: "#/definitions/source_def" },
10957
- state: {
10958
- type: "object",
10959
- additionalProperties: true,
10960
- properties: {
10961
- status: { enum: ["fresh", "stale", "loading", "error"] },
10962
- lastRun: { type: "string", format: "date-time" },
10963
- error: { type: "string" }
10964
- }
10965
- },
10966
- compute: {
10967
- type: "object",
10968
- description: "Derived state: key = state path to write, value = compute_expr",
10969
- additionalProperties: { $ref: "#/definitions/compute_expr" }
10970
- }
10971
- }
11837
+ sources: {
11838
+ type: "array",
11839
+ description: "Source entries. Each entry is passed verbatim to the board's .task-executor (registered via init --task-executor) as the --in JSON file. The executor fetches/generates the data and writes JSON to --out. If no executor is registered, the built-in executor runs the entry's 'cli' command directly. Sources gate completion by default. Set optionalForCompletionGating: true for enrichment-only sources that should not block task-completed.",
11840
+ items: { $ref: "#/definitions/source_def" }
11841
+ },
11842
+ compute: {
11843
+ type: "array",
11844
+ description: "Ordered array of compute steps. Each reads card_data.*/requires.*/fetched_sources.*/computed_values.* and writes to ephemeral computed_values[bindTo].",
11845
+ items: { $ref: "#/definitions/compute_step" }
10972
11846
  }
10973
- ]
11847
+ }
10974
11848
  };
10975
11849
 
10976
11850
  // src/card-compute/schema-validator.ts
10977
11851
  var import_ajv3 = __toESM(require_ajv());
10978
11852
  var _compiled3 = null;
11853
+ var NAMESPACE_REFERENCE_RE = /\b(card_data|requires|fetched_sources|computed_values|sources)\b/g;
11854
+ var ROOT_PATH_NAMESPACE_RE = /^\s*(card_data|requires|fetched_sources|computed_values|sources)(\.|$)/;
11855
+ function referencedNamespaces(expression) {
11856
+ const namespaces = /* @__PURE__ */ new Set();
11857
+ let match;
11858
+ NAMESPACE_REFERENCE_RE.lastIndex = 0;
11859
+ while ((match = NAMESPACE_REFERENCE_RE.exec(expression)) !== null) {
11860
+ namespaces.add(match[1]);
11861
+ }
11862
+ return namespaces;
11863
+ }
11864
+ function parseRootPathNamespace(pathValue) {
11865
+ const match = ROOT_PATH_NAMESPACE_RE.exec(pathValue);
11866
+ return match ? match[1] : null;
11867
+ }
11868
+ function validateJsonataExprWithNamespaces(expr, path, allowedNamespaces, errors) {
11869
+ try {
11870
+ jsonata2(expr);
11871
+ } catch (err) {
11872
+ const message = err instanceof Error ? err.message : String(err);
11873
+ errors.push(`${path}: invalid JSONata expression (${message})`);
11874
+ return;
11875
+ }
11876
+ const usedNamespaces = referencedNamespaces(expr);
11877
+ for (const namespace of usedNamespaces) {
11878
+ if (!allowedNamespaces.has(namespace)) {
11879
+ errors.push(`${path}: disallowed namespace "${namespace}" in expression`);
11880
+ }
11881
+ }
11882
+ }
11883
+ function walkViewPathReferences(value, path, errors) {
11884
+ if (Array.isArray(value)) {
11885
+ value.forEach((entry, index) => {
11886
+ walkViewPathReferences(entry, `${path}/${index}`, errors);
11887
+ });
11888
+ return;
11889
+ }
11890
+ if (typeof value === "string") {
11891
+ const rootNamespace = parseRootPathNamespace(value);
11892
+ if (!rootNamespace) return;
11893
+ if (!(/* @__PURE__ */ new Set(["card_data", "requires", "fetched_sources", "computed_values"])).has(rootNamespace)) {
11894
+ errors.push(`${path}: disallowed namespace "${rootNamespace}" in view reference`);
11895
+ }
11896
+ return;
11897
+ }
11898
+ if (!value || typeof value !== "object") return;
11899
+ const record = value;
11900
+ for (const [key, next2] of Object.entries(record)) {
11901
+ walkViewPathReferences(next2, `${path}/${key}`, errors);
11902
+ }
11903
+ }
10979
11904
  function getValidator3() {
10980
11905
  if (_compiled3) return _compiled3;
10981
11906
  const ajv = new import_ajv3.default({ allErrors: true });
@@ -10993,6 +11918,42 @@ function validateLiveCardSchema(node) {
10993
11918
  });
10994
11919
  return { ok: false, errors };
10995
11920
  }
11921
+ function validateLiveCardRuntimeExpressions(node) {
11922
+ const errors = [];
11923
+ if (!node || typeof node !== "object" || Array.isArray(node)) {
11924
+ return { ok: true, errors: [] };
11925
+ }
11926
+ const asRecord = node;
11927
+ const compute = asRecord.compute;
11928
+ if (Array.isArray(compute)) {
11929
+ compute.forEach((step, i) => {
11930
+ if (!step || typeof step !== "object" || Array.isArray(step)) return;
11931
+ const expr = step.expr;
11932
+ if (typeof expr !== "string" || expr.trim().length === 0) return;
11933
+ validateJsonataExprWithNamespaces(
11934
+ expr,
11935
+ `/compute/${i}/expr`,
11936
+ /* @__PURE__ */ new Set(["card_data", "requires", "fetched_sources", "computed_values"]),
11937
+ errors
11938
+ );
11939
+ });
11940
+ }
11941
+ const view = asRecord.view;
11942
+ if (view && typeof view === "object" && !Array.isArray(view)) {
11943
+ walkViewPathReferences(view, "/view", errors);
11944
+ }
11945
+ return { ok: errors.length === 0, errors };
11946
+ }
11947
+ function validateLiveCard(node) {
11948
+ return validateLiveCardDefinition(node);
11949
+ }
11950
+ function validateLiveCardDefinition(node) {
11951
+ const schema = validateLiveCardSchema(node);
11952
+ if (!schema.ok) return schema;
11953
+ const runtime = validateLiveCardRuntimeExpressions(node);
11954
+ if (!runtime.ok) return { ok: false, errors: runtime.errors };
11955
+ return { ok: true, errors: [] };
11956
+ }
10996
11957
 
10997
11958
  // src/card-compute/index.ts
10998
11959
  function deepGet(obj, path) {
@@ -11014,288 +11975,43 @@ function deepSet(obj, path, value) {
11014
11975
  }
11015
11976
  cur[parts[parts.length - 1]] = value;
11016
11977
  }
11017
- var _fns = {};
11018
- _fns.sum = (input, _e, opts) => {
11019
- const a = Array.isArray(input) ? input : [];
11020
- return opts.field ? a.reduce((s, r) => s + (Number(r[opts.field]) || 0), 0) : a.reduce((s, v) => s + (Number(v) || 0), 0);
11021
- };
11022
- _fns.avg = (input, _e, opts) => {
11023
- const s = _fns.sum(input, _e, opts);
11024
- const n = Array.isArray(input) ? input.length : 1;
11025
- return n ? s / n : 0;
11026
- };
11027
- _fns.min = (input, _e, opts) => {
11028
- const a = Array.isArray(input) ? input : [];
11029
- const vals = opts.field ? a.map((r) => Number(r[opts.field])) : a.map(Number);
11030
- return vals.length ? Math.min(...vals) : 0;
11031
- };
11032
- _fns.max = (input, _e, opts) => {
11033
- const a = Array.isArray(input) ? input : [];
11034
- const vals = opts.field ? a.map((r) => Number(r[opts.field])) : a.map(Number);
11035
- return vals.length ? Math.max(...vals) : 0;
11036
- };
11037
- _fns.count = (input) => Array.isArray(input) ? input.length : input != null ? 1 : 0;
11038
- _fns.first = (input) => Array.isArray(input) ? input[0] : input;
11039
- _fns.last = (input) => Array.isArray(input) ? input[input.length - 1] : input;
11040
- _fns.add = (input) => {
11041
- const a = Array.isArray(input) ? input : [];
11042
- return a.reduce((s, v) => s + Number(v), 0);
11043
- };
11044
- _fns.sub = (input) => {
11045
- const a = Array.isArray(input) ? input : [];
11046
- return a.length >= 2 ? Number(a[0]) - Number(a[1]) : 0;
11047
- };
11048
- _fns.mul = (input) => {
11049
- const a = Array.isArray(input) ? input : [];
11050
- return a.reduce((s, v) => s * Number(v), 1);
11051
- };
11052
- _fns.div = (input) => {
11053
- const a = Array.isArray(input) ? input : [];
11054
- return a.length >= 2 && Number(a[1]) !== 0 ? Number(a[0]) / Number(a[1]) : 0;
11055
- };
11056
- _fns.round = (input, _e, opts) => {
11057
- const decimals = opts.decimals != null ? opts.decimals : 0;
11058
- const factor = Math.pow(10, decimals);
11059
- return Math.round(Number(input) * factor) / factor;
11060
- };
11061
- _fns.abs = (input) => Math.abs(Number(input));
11062
- _fns.mod = (input) => {
11063
- const a = Array.isArray(input) ? input : [];
11064
- return a.length >= 2 ? Number(a[0]) % Number(a[1]) : 0;
11065
- };
11066
- _fns.gt = (input) => {
11067
- const a = Array.isArray(input) ? input : [];
11068
- return a.length >= 2 && Number(a[0]) > Number(a[1]);
11069
- };
11070
- _fns.gte = (input) => {
11071
- const a = Array.isArray(input) ? input : [];
11072
- return a.length >= 2 && Number(a[0]) >= Number(a[1]);
11073
- };
11074
- _fns.lt = (input) => {
11075
- const a = Array.isArray(input) ? input : [];
11076
- return a.length >= 2 && Number(a[0]) < Number(a[1]);
11077
- };
11078
- _fns.lte = (input) => {
11079
- const a = Array.isArray(input) ? input : [];
11080
- return a.length >= 2 && Number(a[0]) <= Number(a[1]);
11081
- };
11082
- _fns.eq = (input) => {
11083
- const a = Array.isArray(input) ? input : [];
11084
- return a.length >= 2 && a[0] === a[1];
11085
- };
11086
- _fns.neq = (input) => {
11087
- const a = Array.isArray(input) ? input : [];
11088
- return a.length >= 2 && a[0] !== a[1];
11089
- };
11090
- _fns.and = (input) => {
11091
- const a = Array.isArray(input) ? input : [];
11092
- return a.every(Boolean);
11093
- };
11094
- _fns.or = (input) => {
11095
- const a = Array.isArray(input) ? input : [];
11096
- return a.some(Boolean);
11097
- };
11098
- _fns.not = (input) => !input;
11099
- _fns.concat = (input) => {
11100
- const a = Array.isArray(input) ? input : [];
11101
- return a.map((v) => v != null ? String(v) : "").join("");
11102
- };
11103
- _fns.upper = (input) => String(input || "").toUpperCase();
11104
- _fns.lower = (input) => String(input || "").toLowerCase();
11105
- _fns.template = (input, _e, opts) => {
11106
- let t = String(opts.format || "");
11107
- if (input && typeof input === "object" && !Array.isArray(input)) {
11108
- for (const k of Object.keys(input)) {
11109
- const v = input[k];
11110
- t = t.split("{{" + k + "}}").join(v != null ? String(v) : "");
11111
- }
11112
- }
11113
- return t;
11114
- };
11115
- _fns.join = (input, _e, opts) => {
11116
- const a = Array.isArray(input) ? input : [];
11117
- const sep = opts.separator != null ? String(opts.separator) : ", ";
11118
- return a.map((v) => v != null ? String(v) : "").join(sep);
11119
- };
11120
- _fns.split = (input, _e, opts) => {
11121
- const sep = opts.separator != null ? String(opts.separator) : ",";
11122
- return String(input || "").split(sep).map((s) => s.trim());
11123
- };
11124
- _fns.trim = (input) => String(input || "").trim();
11125
- _fns.pluck = (input, _e, opts) => Array.isArray(input) ? input.map((r) => r[opts.field]) : [];
11126
- _fns.filter = (input, _e, opts) => {
11127
- if (!Array.isArray(input)) return [];
11128
- if (opts.field) return input.filter((r) => !!r[opts.field]);
11129
- return input.filter(Boolean);
11130
- };
11131
- _fns.map = (input) => Array.isArray(input) ? input.slice() : [];
11132
- _fns.sort = (input, _e, opts) => {
11133
- const a = Array.isArray(input) ? input.slice() : [];
11134
- const f = opts.field;
11135
- const dir = opts.direction === "desc" ? -1 : 1;
11136
- if (f) return a.sort((x, y) => x[f] > y[f] ? dir : x[f] < y[f] ? -dir : 0);
11137
- return a.sort((x, y) => x > y ? dir : x < y ? -dir : 0);
11138
- };
11139
- _fns.slice = (input, _e, opts) => Array.isArray(input) ? input.slice(opts.start || 0, opts.end) : input;
11140
- _fns.flat = (input, _e, opts) => {
11141
- const depth = opts.depth != null ? opts.depth : 1;
11142
- return Array.isArray(input) ? input.flat(depth) : [input];
11143
- };
11144
- _fns.unique = (input) => {
11145
- if (!Array.isArray(input)) return [input];
11146
- const seen = /* @__PURE__ */ new Set();
11147
- return input.filter((v) => {
11148
- const key = typeof v === "object" ? JSON.stringify(v) : v;
11149
- if (seen.has(key)) return false;
11150
- seen.add(key);
11151
- return true;
11152
- });
11153
- };
11154
- _fns.group = (input, _e, opts) => {
11155
- const a = Array.isArray(input) ? input : [];
11156
- const g = {};
11157
- a.forEach((r) => {
11158
- const k = String(r[opts.field] || "");
11159
- if (!g[k]) g[k] = [];
11160
- g[k].push(r);
11161
- });
11162
- return g;
11163
- };
11164
- _fns.flatten_keys = (input) => {
11165
- if (!input || typeof input !== "object" || Array.isArray(input)) return [];
11166
- const result = [];
11167
- for (const k of Object.keys(input)) {
11168
- const vals = Array.isArray(input[k]) ? input[k] : [input[k]];
11169
- vals.forEach((v) => result.push({ key: k, value: v }));
11170
- }
11171
- return result;
11172
- };
11173
- _fns.entries = (input) => {
11174
- if (!input || typeof input !== "object" || Array.isArray(input)) return [];
11175
- return Object.keys(input).map((k) => ({ key: k, value: input[k] }));
11176
- };
11177
- _fns.from_entries = (input) => {
11178
- if (!Array.isArray(input)) return {};
11179
- const obj = {};
11180
- input.forEach((item) => {
11181
- if (item.key != null) obj[item.key] = item.value;
11182
- });
11183
- return obj;
11184
- };
11185
- _fns.length = (input) => {
11186
- if (Array.isArray(input)) return input.length;
11187
- if (typeof input === "string") return input.length;
11188
- if (input && typeof input === "object") return Object.keys(input).length;
11189
- return 0;
11190
- };
11191
- _fns.get = (input, _e, opts) => deepGet(input, opts.field || opts.path || "");
11192
- _fns.default = (input, _e, opts) => input != null ? input : opts.value;
11193
- _fns.coalesce = (input) => {
11194
- const a = Array.isArray(input) ? input : [];
11195
- for (let i = 0; i < a.length; i++) {
11196
- if (a[i] != null) return a[i];
11197
- }
11198
- return null;
11199
- };
11200
- _fns.now = () => (/* @__PURE__ */ new Date()).toISOString();
11201
- _fns.diff_days = (input) => {
11202
- const a = Array.isArray(input) ? input : [];
11203
- return a.length >= 2 ? Math.floor((new Date(a[0]).getTime() - new Date(a[1]).getTime()) / 864e5) : 0;
11204
- };
11205
- _fns.format_date = (input, _e, opts) => {
11206
- try {
11207
- const d = new Date(input);
11208
- if (opts.format === "iso") return d.toISOString();
11209
- if (opts.format === "date") return d.toLocaleDateString();
11210
- if (opts.format === "time") return d.toLocaleTimeString();
11211
- return d.toLocaleDateString();
11212
- } catch {
11213
- return String(input);
11214
- }
11215
- };
11216
- _fns.parse_date = (input) => {
11217
- try {
11218
- return new Date(input).toISOString();
11219
- } catch {
11220
- return null;
11221
- }
11222
- };
11223
- _fns.to_number = (input) => Number(input) || 0;
11224
- _fns.to_string = (input) => input != null ? String(input) : "";
11225
- _fns.to_bool = (input) => !!input;
11226
- _fns.type_of = (input) => Array.isArray(input) ? "array" : typeof input;
11227
- _fns.is_null = (input) => input == null;
11228
- _fns.is_empty = (input) => {
11229
- if (input == null) return true;
11230
- if (Array.isArray(input)) return input.length === 0;
11231
- if (typeof input === "string") return input.length === 0;
11232
- if (typeof input === "object") return Object.keys(input).length === 0;
11233
- return false;
11234
- };
11235
- var _customFns = {};
11236
- function evalExpr(expr, node) {
11237
- if (expr == null) return expr;
11238
- if (typeof expr !== "object" || Array.isArray(expr)) return expr;
11239
- const e = expr;
11240
- if (!e.fn) return expr;
11241
- let input = e.input;
11242
- if (typeof input === "string" && input.startsWith("state.")) {
11243
- input = deepGet(node, input);
11244
- } else if (Array.isArray(input)) {
11245
- input = input.map((v) => {
11246
- if (typeof v === "string" && v.startsWith("state.")) return deepGet(node, v);
11247
- if (v && typeof v === "object" && v.fn) return evalExpr(v, node);
11248
- return v;
11249
- });
11250
- } else if (input && typeof input === "object" && input.fn) {
11251
- input = evalExpr(input, node);
11252
- }
11253
- if (e.fn === "if") {
11254
- const cond = evalExpr(e.cond, node);
11255
- if (cond) {
11256
- return e.then && typeof e.then === "object" && e.then.fn ? evalExpr(e.then, node) : e.then;
11257
- } else {
11258
- return e.else && typeof e.else === "object" && e.else.fn ? evalExpr(e.else, node) : e.else;
11259
- }
11260
- }
11261
- if (e.fn === "filter" && Array.isArray(input) && e.where) {
11262
- return input.filter((item) => {
11263
- const tmp = { state: { ...node.state, $: item } };
11264
- return evalExpr(e.where, tmp);
11265
- });
11266
- }
11267
- if (e.fn === "map" && Array.isArray(input) && e.apply) {
11268
- return input.map((item) => {
11269
- const tmp = { state: { ...node.state, $: item } };
11270
- return evalExpr(e.apply, tmp);
11271
- });
11272
- }
11273
- const fn = _customFns[e.fn] || _fns[e.fn];
11274
- if (!fn) {
11275
- console.warn('CardCompute: unknown function "' + e.fn + '"');
11276
- return void 0;
11277
- }
11278
- return fn(input, evalExpr, e);
11279
- }
11280
- function run(node) {
11281
- if (!node || !node.compute) return node;
11282
- if (!node.state) node.state = {};
11283
- for (const key of Object.keys(node.compute)) {
11978
+ async function run(node, options) {
11979
+ if (!node?.compute?.length) return node;
11980
+ if (!node.card_data) node.card_data = {};
11981
+ node.computed_values = {};
11982
+ node._sourcesData = options?.sourcesData ?? {};
11983
+ const ctx = {
11984
+ card_data: node.card_data,
11985
+ requires: node.requires ?? {},
11986
+ fetched_sources: node._sourcesData,
11987
+ computed_values: node.computed_values
11988
+ };
11989
+ for (const step of node.compute) {
11284
11990
  try {
11285
- const val = evalExpr(node.compute[key], node);
11286
- deepSet(node.state, key, val);
11991
+ const val = await jsonata2(step.expr).evaluate(ctx);
11992
+ deepSet(node.computed_values, step.bindTo, val);
11993
+ ctx.computed_values = node.computed_values;
11287
11994
  } catch (err) {
11288
- console.error(`CardCompute.run error on "${node.id || "?"}.${key}":`, err);
11995
+ console.error(`CardCompute.run error on "${node.id ?? "?"}.${step.bindTo}":`, err);
11289
11996
  }
11290
11997
  }
11291
11998
  return node;
11292
11999
  }
12000
+ async function evalExpr(expr, node) {
12001
+ const ctx = {
12002
+ card_data: node.card_data ?? {},
12003
+ requires: node.requires ?? {},
12004
+ fetched_sources: node._sourcesData ?? {},
12005
+ computed_values: node.computed_values ?? {}
12006
+ };
12007
+ return jsonata2(expr).evaluate(ctx);
12008
+ }
11293
12009
  function resolve(node, path) {
12010
+ if (path.startsWith("fetched_sources.")) {
12011
+ return deepGet(node._sourcesData ?? {}, path.slice("fetched_sources.".length));
12012
+ }
11294
12013
  return deepGet(node, path);
11295
12014
  }
11296
- function registerFunction(name, fn) {
11297
- _customFns[name] = fn;
11298
- }
11299
12015
  var VALID_ELEMENT_KINDS = /* @__PURE__ */ new Set([
11300
12016
  "metric",
11301
12017
  "table",
@@ -11312,34 +12028,19 @@ var VALID_ELEMENT_KINDS = /* @__PURE__ */ new Set([
11312
12028
  "markdown",
11313
12029
  "custom"
11314
12030
  ]);
11315
- var VALID_SOURCE_KINDS = /* @__PURE__ */ new Set(["api", "websocket", "static", "llm"]);
11316
- var VALID_STATUSES = /* @__PURE__ */ new Set(["fresh", "stale", "loading", "error"]);
11317
- var CARD_ALLOWED_KEYS = /* @__PURE__ */ new Set(["id", "type", "meta", "data", "view", "state", "compute"]);
11318
- var SOURCE_ALLOWED_KEYS = /* @__PURE__ */ new Set(["id", "type", "meta", "data", "source", "state", "compute"]);
12031
+ var ALLOWED_KEYS = /* @__PURE__ */ new Set(["id", "meta", "requires", "provides", "view", "card_data", "compute", "sources"]);
11319
12032
  function validateNode(node) {
11320
12033
  const errors = [];
11321
12034
  if (!node || typeof node !== "object" || Array.isArray(node)) {
11322
12035
  return { ok: false, errors: ["Node must be a non-null object"] };
11323
12036
  }
11324
12037
  const n = node;
11325
- if (typeof n.id !== "string" || !n.id) {
11326
- errors.push("id: required, must be a non-empty string");
11327
- }
11328
- if (n.type !== "card" && n.type !== "source") {
11329
- errors.push('type: must be "card" or "source"');
11330
- return { ok: false, errors };
11331
- }
11332
- const allowed = n.type === "card" ? CARD_ALLOWED_KEYS : SOURCE_ALLOWED_KEYS;
12038
+ if (typeof n.id !== "string" || !n.id) errors.push("id: required, must be a non-empty string");
11333
12039
  for (const key of Object.keys(n)) {
11334
- if (!allowed.has(key)) errors.push(`Unknown top-level key: "${key}"`);
12040
+ if (!ALLOWED_KEYS.has(key)) errors.push(`Unknown top-level key: "${key}"`);
11335
12041
  }
11336
- if (n.state == null || typeof n.state !== "object" || Array.isArray(n.state)) {
11337
- errors.push("state: required, must be an object");
11338
- } else {
11339
- const state = n.state;
11340
- if (state.status != null && !VALID_STATUSES.has(state.status)) {
11341
- errors.push(`state.status: must be one of: ${[...VALID_STATUSES].join(", ")}`);
11342
- }
12042
+ if (n.card_data == null || typeof n.card_data !== "object" || Array.isArray(n.card_data)) {
12043
+ errors.push("card_data: required, must be an object");
11343
12044
  }
11344
12045
  if (n.meta != null) {
11345
12046
  if (typeof n.meta !== "object" || Array.isArray(n.meta)) {
@@ -11350,37 +12051,58 @@ function validateNode(node) {
11350
12051
  if (meta.tags != null && !Array.isArray(meta.tags)) errors.push("meta.tags: must be an array");
11351
12052
  }
11352
12053
  }
11353
- if (n.data != null) {
11354
- if (typeof n.data !== "object" || Array.isArray(n.data)) {
11355
- errors.push("data: must be an object");
12054
+ if (n.requires != null && !Array.isArray(n.requires)) errors.push("requires: must be an array of strings");
12055
+ if (n.provides != null) {
12056
+ if (!Array.isArray(n.provides)) {
12057
+ errors.push("provides: must be an array of { bindTo, src } bindings");
11356
12058
  } else {
11357
- const data = n.data;
11358
- if (data.requires != null && !Array.isArray(data.requires)) errors.push("data.requires: must be an array of strings");
11359
- if (data.provides != null && (typeof data.provides !== "object" || Array.isArray(data.provides))) errors.push("data.provides: must be an object");
12059
+ n.provides.forEach((p, i) => {
12060
+ if (!p || typeof p !== "object" || Array.isArray(p)) {
12061
+ errors.push(`provides[${i}]: must be an object with bindTo and src`);
12062
+ } else {
12063
+ const b = p;
12064
+ if (typeof b.bindTo !== "string" || !b.bindTo) errors.push(`provides[${i}]: missing required "bindTo" string`);
12065
+ if (typeof b.src !== "string" || !b.src) errors.push(`provides[${i}]: missing required "src" string`);
12066
+ }
12067
+ });
11360
12068
  }
11361
12069
  }
11362
12070
  if (n.compute != null) {
11363
- if (typeof n.compute !== "object" || Array.isArray(n.compute)) {
11364
- errors.push("compute: must be an object");
12071
+ if (!Array.isArray(n.compute)) {
12072
+ errors.push("compute: must be an array of compute steps");
12073
+ } else {
12074
+ n.compute.forEach((step, i) => {
12075
+ if (!step || typeof step !== "object" || Array.isArray(step)) {
12076
+ errors.push(`compute[${i}]: must be a compute step object`);
12077
+ } else {
12078
+ const s = step;
12079
+ if (typeof s.bindTo !== "string" || !s.bindTo) errors.push(`compute[${i}]: missing required "bindTo" property`);
12080
+ if (typeof s.expr !== "string" || !s.expr) errors.push(`compute[${i}]: missing required "expr" string (JSONata expression)`);
12081
+ }
12082
+ });
12083
+ }
12084
+ }
12085
+ if (n.sources != null) {
12086
+ if (!Array.isArray(n.sources)) {
12087
+ errors.push("sources: must be an array");
11365
12088
  } else {
11366
- for (const [key, expr] of Object.entries(n.compute)) {
11367
- if (!expr || typeof expr !== "object" || Array.isArray(expr)) {
11368
- errors.push(`compute.${key}: must be a compute expression object`);
11369
- } else if (!expr.fn) {
11370
- errors.push(`compute.${key}: missing required "fn" property`);
12089
+ n.sources.forEach((src, i) => {
12090
+ if (!src || typeof src !== "object" || Array.isArray(src)) {
12091
+ errors.push(`sources[${i}]: must be an object`);
11371
12092
  } else {
11372
- const fn = expr.fn;
11373
- if (!_fns[fn] && !_customFns[fn]) {
11374
- errors.push(`compute.${key}: unknown function "${fn}"`);
12093
+ const s = src;
12094
+ if (typeof s.bindTo !== "string" || !s.bindTo) errors.push(`sources[${i}]: missing required "bindTo" property`);
12095
+ if (s.outputFile != null && typeof s.outputFile !== "string") errors.push(`sources[${i}]: outputFile must be a string`);
12096
+ if (s.optionalForCompletionGating != null && typeof s.optionalForCompletionGating !== "boolean") {
12097
+ errors.push(`sources[${i}]: optionalForCompletionGating must be a boolean`);
11375
12098
  }
11376
12099
  }
11377
- }
12100
+ });
11378
12101
  }
11379
12102
  }
11380
- if (n.type === "card") {
11381
- if (n.source != null) errors.push('Card nodes must not have "source" \u2014 use type "source" instead');
11382
- if (n.view == null || typeof n.view !== "object" || Array.isArray(n.view)) {
11383
- errors.push("view: required for card nodes, must be an object");
12103
+ if (n.view != null) {
12104
+ if (typeof n.view !== "object" || Array.isArray(n.view)) {
12105
+ errors.push("view: must be an object");
11384
12106
  } else {
11385
12107
  const view = n.view;
11386
12108
  if (!Array.isArray(view.elements) || view.elements.length === 0) {
@@ -11401,44 +12123,27 @@ function validateNode(node) {
11401
12123
  }
11402
12124
  });
11403
12125
  }
11404
- if (view.layout != null && (typeof view.layout !== "object" || Array.isArray(view.layout))) {
11405
- errors.push("view.layout: must be an object");
11406
- }
11407
- if (view.features != null && (typeof view.features !== "object" || Array.isArray(view.features))) {
11408
- errors.push("view.features: must be an object");
11409
- }
11410
- }
11411
- }
11412
- if (n.type === "source") {
11413
- if (n.view != null) errors.push('Source nodes must not have "view" \u2014 use type "card" instead');
11414
- if (n.source == null || typeof n.source !== "object" || Array.isArray(n.source)) {
11415
- errors.push("source: required for source nodes, must be an object");
11416
- } else {
11417
- const src = n.source;
11418
- if (!src.kind || !VALID_SOURCE_KINDS.has(src.kind)) {
11419
- errors.push(`source.kind: required, must be one of: ${[...VALID_SOURCE_KINDS].join(", ")}`);
11420
- }
11421
- if (typeof src.bindTo !== "string" || !src.bindTo) {
11422
- errors.push("source.bindTo: required, must be a state path string");
11423
- } else if (!src.bindTo.startsWith("state.")) {
11424
- errors.push('source.bindTo: must start with "state."');
11425
- }
12126
+ if (view.layout != null && (typeof view.layout !== "object" || Array.isArray(view.layout))) errors.push("view.layout: must be an object");
12127
+ if (view.features != null && (typeof view.features !== "object" || Array.isArray(view.features))) errors.push("view.features: must be an object");
11426
12128
  }
11427
12129
  }
11428
12130
  return { ok: errors.length === 0, errors };
11429
12131
  }
12132
+ function enrichSources(sources, context) {
12133
+ if (!sources || sources.length === 0) return [];
12134
+ return sources.map((src) => ({
12135
+ ...src,
12136
+ _requires: context.requires ?? {},
12137
+ _sourcesData: context.sourcesData ?? {},
12138
+ _computed_values: context.computed_values ?? {}
12139
+ }));
12140
+ }
11430
12141
  var CardCompute = {
11431
12142
  run,
11432
12143
  eval: evalExpr,
11433
12144
  resolve,
11434
12145
  validate: validateNode,
11435
- registerFunction,
11436
- get functions() {
11437
- const all = {};
11438
- for (const k of Object.keys(_fns)) all[k] = _fns[k];
11439
- for (const k of Object.keys(_customFns)) all[k] = _customFns[k];
11440
- return all;
11441
- }
12146
+ enrichSources
11442
12147
  };
11443
12148
 
11444
12149
  // src/continuous-event-graph/live-cards-bridge.ts
@@ -11471,19 +12176,26 @@ function liveCardsToReactiveGraph(input, options = {}) {
11471
12176
  }
11472
12177
  const sharedState = options.sharedState ?? /* @__PURE__ */ new Map();
11473
12178
  const tasks = {};
12179
+ const allTokens = /* @__PURE__ */ new Set();
12180
+ const tokenToCardId = /* @__PURE__ */ new Map();
11474
12181
  for (const card of cards) {
11475
- const requires = card.data?.requires ?? [];
12182
+ for (const binding of card.provides ?? [{ bindTo: card.id, src: "card_data" }]) {
12183
+ allTokens.add(binding.bindTo);
12184
+ tokenToCardId.set(binding.bindTo, card.id);
12185
+ }
12186
+ }
12187
+ for (const card of cards) {
12188
+ const requires = card.requires ?? [];
11476
12189
  for (const req of requires) {
11477
- if (!cardMap.has(req)) {
11478
- throw new Error(`Card "${card.id}" requires "${req}" but no card with that ID exists`);
12190
+ if (!allTokens.has(req)) {
12191
+ throw new Error(`Card "${card.id}" requires "${req}" but no card provides that token`);
11479
12192
  }
11480
12193
  }
11481
12194
  tasks[card.id] = {
11482
12195
  requires: requires.length > 0 ? requires : void 0,
11483
- provides: [card.id],
12196
+ provides: (card.provides ?? [{ bindTo: card.id, src: "card_data" }]).map((p) => p.bindTo),
11484
12197
  taskHandlers: [card.id],
11485
- // each card has a named handler matching its ID
11486
- description: card.meta?.title ?? `${card.type}: ${card.id}`
12198
+ description: card.meta?.title ?? card.id
11487
12199
  };
11488
12200
  }
11489
12201
  const config = {
@@ -11502,10 +12214,10 @@ function liveCardsToReactiveGraph(input, options = {}) {
11502
12214
  graphRef.resolveCallback(token, data, errors);
11503
12215
  };
11504
12216
  for (const card of cards) {
11505
- if (card.type === "source") {
12217
+ if (card.sources && card.sources.length > 0) {
11506
12218
  handlers[card.id] = buildSourceHandler(card, sourceHandlers, defaultSourceHandler, sharedState, getResolve);
11507
12219
  } else {
11508
- handlers[card.id] = buildCardHandler(card, cardHandlers, sharedState, cardMap, getResolve);
12220
+ handlers[card.id] = buildCardHandler(card, cardHandlers, sharedState, cardMap, tokenToCardId, getResolve);
11509
12221
  }
11510
12222
  }
11511
12223
  const graph = createReactiveGraph(
@@ -11533,13 +12245,13 @@ function buildSourceHandler(card, sourceHandlers, defaultSourceHandler, sharedSt
11533
12245
  };
11534
12246
  }
11535
12247
  return async (input) => {
11536
- const state = { ...card.state };
11537
- sharedState.set(card.id, state);
11538
- getResolve()(input.callbackToken, state);
12248
+ const data = { ...card.card_data };
12249
+ sharedState.set(card.id, data);
12250
+ getResolve()(input.callbackToken, data);
11539
12251
  return "task-initiated";
11540
12252
  };
11541
12253
  }
11542
- function buildCardHandler(card, cardHandlers, sharedState, cardMap, getResolve) {
12254
+ function buildCardHandler(card, cardHandlers, sharedState, _cardMap, tokenToCardId, getResolve) {
11543
12255
  if (cardHandlers[card.id]) {
11544
12256
  const userHandler = cardHandlers[card.id];
11545
12257
  return async (input) => {
@@ -11547,46 +12259,273 @@ function buildCardHandler(card, cardHandlers, sharedState, cardMap, getResolve)
11547
12259
  };
11548
12260
  }
11549
12261
  return async (input) => {
12262
+ const requiresData = {};
12263
+ const requires = card.requires ?? [];
12264
+ for (const token of requires) {
12265
+ const producerId = tokenToCardId.get(token) ?? token;
12266
+ const upstreamState = sharedState.get(producerId);
12267
+ if (upstreamState) {
12268
+ requiresData[token] = upstreamState[token] ?? upstreamState;
12269
+ }
12270
+ }
11550
12271
  const computeNode = {
11551
12272
  id: card.id,
11552
- state: { ...card.state },
12273
+ card_data: { ...card.card_data },
12274
+ requires: requiresData,
11553
12275
  compute: card.compute
11554
12276
  };
11555
- const requires = card.data?.requires ?? [];
11556
- for (const upstreamId of requires) {
11557
- const upstreamState = sharedState.get(upstreamId);
11558
- if (upstreamState) {
11559
- computeNode.state[upstreamId] = upstreamState;
11560
- }
11561
- const upstreamCard = cardMap.get(upstreamId);
11562
- if (upstreamCard?.data?.provides && upstreamState) {
11563
- for (const [key, bindRef] of Object.entries(upstreamCard.data.provides)) {
11564
- if (typeof bindRef === "string" && bindRef.startsWith("state.")) {
11565
- const path = bindRef.slice(6);
11566
- const value = deepGet2(upstreamState, path);
11567
- if (value !== void 0) {
11568
- computeNode.state[key] = value;
11569
- }
11570
- }
11571
- }
12277
+ await CardCompute.run(computeNode);
12278
+ let resultData;
12279
+ if (card.provides && card.provides.length > 0) {
12280
+ resultData = {};
12281
+ for (const { bindTo, src } of card.provides) {
12282
+ resultData[bindTo] = CardCompute.resolve(computeNode, src);
11572
12283
  }
12284
+ } else {
12285
+ resultData = { ...computeNode.card_data, ...computeNode.computed_values };
11573
12286
  }
11574
- CardCompute.run(computeNode);
11575
- const resultState = { ...computeNode.state };
12287
+ const resultState = { ...computeNode.card_data, ...computeNode.computed_values };
11576
12288
  sharedState.set(card.id, resultState);
11577
- getResolve()(input.callbackToken, resultState);
12289
+ getResolve()(input.callbackToken, resultData);
11578
12290
  return "task-initiated";
11579
12291
  };
11580
12292
  }
11581
- function deepGet2(obj, path) {
11582
- if (!path || !obj) return void 0;
11583
- const parts = path.split(".");
11584
- let cur = obj;
11585
- for (const part of parts) {
11586
- if (cur == null) return void 0;
11587
- cur = cur[part];
12293
+
12294
+ // src/board-livegraph-runtime/index.ts
12295
+ function deepClone(value) {
12296
+ return JSON.parse(JSON.stringify(value));
12297
+ }
12298
+ function toTaskConfig(card) {
12299
+ const provides = card.provides && card.provides.length > 0 ? card.provides.map((p) => p.bindTo) : [card.id];
12300
+ return {
12301
+ requires: card.requires && card.requires.length > 0 ? [...card.requires] : void 0,
12302
+ provides,
12303
+ taskHandlers: [card.id],
12304
+ description: card.meta?.title ?? card.id
12305
+ };
12306
+ }
12307
+ function buildTokenProviders(cards) {
12308
+ const tokenToCardId = /* @__PURE__ */ new Map();
12309
+ for (const [cardId, card] of cards.entries()) {
12310
+ const bindings = card.provides && card.provides.length > 0 ? card.provides : [{ bindTo: cardId, src: "card_data" }];
12311
+ for (const binding of bindings) tokenToCardId.set(binding.bindTo, cardId);
11588
12312
  }
11589
- return cur;
12313
+ return tokenToCardId;
12314
+ }
12315
+ function validateRequires(cards, changedCardId) {
12316
+ const tokenProviders = buildTokenProviders(cards);
12317
+ const card = cards.get(changedCardId);
12318
+ if (!card) return;
12319
+ for (const req of card.requires ?? []) {
12320
+ if (!tokenProviders.has(req)) {
12321
+ throw new Error(`Card "${changedCardId}" requires token "${req}" but no card provides it`);
12322
+ }
12323
+ }
12324
+ }
12325
+ function createBoardLiveGraphRuntime(input, options = {}) {
12326
+ const boardMeta = Array.isArray(input) ? {} : {
12327
+ id: input.id,
12328
+ title: input.title,
12329
+ mode: input.mode,
12330
+ positions: input.positions,
12331
+ settings: input.settings
12332
+ };
12333
+ const initialCards = Array.isArray(input) ? input : input.nodes;
12334
+ const cards = /* @__PURE__ */ new Map();
12335
+ for (const card of initialCards) {
12336
+ if (cards.has(card.id)) throw new Error(`Duplicate card ID: "${card.id}"`);
12337
+ cards.set(card.id, deepClone(card));
12338
+ }
12339
+ const listeners = /* @__PURE__ */ new Set();
12340
+ const taskExecutor = options.taskExecutor;
12341
+ const sourceAdapters = options.sourceAdapters ?? {};
12342
+ const defaultSourceAdapter = options.defaultSourceAdapter;
12343
+ let graphRef = null;
12344
+ const notifyListeners = (events, graph2) => {
12345
+ const update = {
12346
+ events,
12347
+ graph: graph2,
12348
+ nodes: getRenderableNodes()
12349
+ };
12350
+ for (const listener of listeners) listener(update);
12351
+ };
12352
+ const makeHandler = (cardId) => {
12353
+ return async (inputArgs) => {
12354
+ const card = cards.get(cardId);
12355
+ if (!card) return "task-initiate-failure";
12356
+ const requiresData = {};
12357
+ for (const token of card.requires ?? []) {
12358
+ const upstream = inputArgs.state[token];
12359
+ if (!upstream || typeof upstream !== "object") continue;
12360
+ const providesData2 = upstream.provides_data;
12361
+ if (!providesData2 || typeof providesData2 !== "object") continue;
12362
+ if (!Object.prototype.hasOwnProperty.call(providesData2, token)) continue;
12363
+ requiresData[token] = providesData2[token];
12364
+ }
12365
+ const sourcesData = {};
12366
+ if (card.sources && card.sources.length > 0) {
12367
+ const adapter = sourceAdapters[cardId] ?? defaultSourceAdapter;
12368
+ const fetched = taskExecutor ? await taskExecutor({ card, input: inputArgs }) : adapter ? await adapter({ card, input: inputArgs }) : void 0;
12369
+ if (fetched && typeof fetched === "object") {
12370
+ for (const src of card.sources) {
12371
+ if (Object.prototype.hasOwnProperty.call(fetched, src.bindTo)) {
12372
+ sourcesData[src.bindTo] = fetched[src.bindTo];
12373
+ } else if (card.sources.length === 1) {
12374
+ sourcesData[src.bindTo] = fetched;
12375
+ }
12376
+ }
12377
+ }
12378
+ }
12379
+ const computeNode = {
12380
+ id: card.id,
12381
+ card_data: deepClone(card.card_data ?? {}),
12382
+ requires: requiresData,
12383
+ sources: card.sources,
12384
+ compute: card.compute
12385
+ };
12386
+ computeNode._sourcesData = sourcesData;
12387
+ if (computeNode.compute && computeNode.compute.length > 0) {
12388
+ await CardCompute.run(computeNode, { sourcesData });
12389
+ }
12390
+ const providesData = {};
12391
+ if (card.provides && card.provides.length > 0) {
12392
+ for (const { bindTo, src } of card.provides) {
12393
+ providesData[bindTo] = CardCompute.resolve(computeNode, src);
12394
+ }
12395
+ } else {
12396
+ providesData[card.id] = {
12397
+ ...computeNode.card_data ?? {},
12398
+ ...computeNode.computed_values ?? {},
12399
+ ...computeNode._sourcesData ?? {}
12400
+ };
12401
+ }
12402
+ const resultData = {
12403
+ provides_data: providesData,
12404
+ card_data: computeNode.card_data ?? {},
12405
+ computed_values: computeNode.computed_values ?? {},
12406
+ fetched_sources: sourcesData,
12407
+ requires: requiresData
12408
+ };
12409
+ graphRef?.resolveCallback(inputArgs.callbackToken, resultData);
12410
+ return "task-initiated";
12411
+ };
12412
+ };
12413
+ const tasks = {};
12414
+ const handlers = {};
12415
+ for (const [cardId, card] of cards.entries()) {
12416
+ validateRequires(cards, cardId);
12417
+ tasks[cardId] = toTaskConfig(card);
12418
+ handlers[cardId] = makeHandler(cardId);
12419
+ }
12420
+ const config = {
12421
+ id: boardMeta.id ?? `browser-board-${Date.now()}`,
12422
+ settings: {
12423
+ completion: "manual",
12424
+ execution_mode: "eligibility-mode",
12425
+ ...boardMeta.settings ?? {},
12426
+ ...options.graphSettings ?? {}
12427
+ },
12428
+ tasks
12429
+ };
12430
+ const userOnDrain = options.reactiveOptions?.onDrain;
12431
+ const graph = createReactiveGraph(
12432
+ config,
12433
+ {
12434
+ ...options.reactiveOptions ?? {},
12435
+ handlers,
12436
+ onDrain: (events, live, scheduleResult) => {
12437
+ userOnDrain?.(events, live, scheduleResult);
12438
+ notifyListeners(events, live);
12439
+ }
12440
+ },
12441
+ options.executionId
12442
+ );
12443
+ graphRef = graph;
12444
+ function getRenderableNodes() {
12445
+ const live = graph.getState();
12446
+ const out = [];
12447
+ for (const [cardId, baseCard] of cards.entries()) {
12448
+ const data = live.state.tasks[cardId]?.data;
12449
+ const runtimeState = live.state.tasks[cardId];
12450
+ const mergedCardData = {
12451
+ ...baseCard.card_data ?? {},
12452
+ ...data && typeof data.card_data === "object" ? data.card_data : {}
12453
+ };
12454
+ const cardStatus = runtimeState?.status === "running" ? "loading" : runtimeState?.status;
12455
+ const cardDataForView = {
12456
+ ...mergedCardData,
12457
+ ...cardStatus ? { status: cardStatus } : {},
12458
+ ...runtimeState?.lastUpdated ? { lastRun: runtimeState.lastUpdated } : {},
12459
+ ...runtimeState?.status === "failed" && runtimeState.error ? { error: runtimeState.error } : {}
12460
+ };
12461
+ out.push({
12462
+ id: cardId,
12463
+ card: deepClone(baseCard),
12464
+ card_data: cardDataForView,
12465
+ fetched_sources: data && typeof data.fetched_sources === "object" ? deepClone(data.fetched_sources) : {},
12466
+ requires: data && typeof data.requires === "object" ? deepClone(data.requires) : {},
12467
+ computed_values: data && typeof data.computed_values === "object" ? deepClone(data.computed_values) : {},
12468
+ runtime_state: runtimeState ? deepClone(runtimeState) : {}
12469
+ });
12470
+ }
12471
+ return out;
12472
+ }
12473
+ const runtime = {
12474
+ getGraph: () => graph,
12475
+ getState: () => graph.getState(),
12476
+ getSchedule: () => graph.getSchedule(),
12477
+ getNodes: () => getRenderableNodes(),
12478
+ getBoard: () => ({
12479
+ ...boardMeta,
12480
+ nodes: getRenderableNodes()
12481
+ }),
12482
+ subscribe(listener) {
12483
+ listeners.add(listener);
12484
+ listener({ events: [], graph: graph.getState(), nodes: getRenderableNodes() });
12485
+ return () => listeners.delete(listener);
12486
+ },
12487
+ addCard(card) {
12488
+ if (cards.has(card.id)) throw new Error(`Card "${card.id}" already exists`);
12489
+ cards.set(card.id, deepClone(card));
12490
+ validateRequires(cards, card.id);
12491
+ graph.registerHandler(card.id, makeHandler(card.id));
12492
+ graph.addNode(card.id, toTaskConfig(card));
12493
+ },
12494
+ upsertCard(card) {
12495
+ cards.set(card.id, deepClone(card));
12496
+ validateRequires(cards, card.id);
12497
+ graph.registerHandler(card.id, makeHandler(card.id));
12498
+ graph.addNode(card.id, toTaskConfig(card));
12499
+ },
12500
+ removeCard(cardId) {
12501
+ cards.delete(cardId);
12502
+ graph.unregisterHandler(cardId);
12503
+ graph.removeNode(cardId);
12504
+ },
12505
+ patchCardState(cardId, patch) {
12506
+ const card = cards.get(cardId);
12507
+ if (!card) throw new Error(`Card "${cardId}" not found`);
12508
+ card.card_data = { ...card.card_data ?? {}, ...patch };
12509
+ graph.retrigger(cardId);
12510
+ },
12511
+ retrigger(cardId) {
12512
+ graph.retrigger(cardId);
12513
+ },
12514
+ retriggerAll() {
12515
+ graph.retriggerAll(Array.from(cards.keys()));
12516
+ },
12517
+ push(event) {
12518
+ graph.push(event);
12519
+ },
12520
+ pushAll(events) {
12521
+ graph.pushAll(events);
12522
+ },
12523
+ dispose() {
12524
+ listeners.clear();
12525
+ graph.dispose();
12526
+ }
12527
+ };
12528
+ return runtime;
11590
12529
  }
11591
12530
 
11592
12531
  // src/inference/core.ts
@@ -11840,6 +12779,190 @@ function createHttpAdapter(opts) {
11840
12779
  };
11841
12780
  }
11842
12781
 
11843
- export { COMPLETION_STRATEGIES, CONFLICT_STRATEGIES, CardCompute, DEFAULTS, EXECUTION_MODES, EXECUTION_STATUS, FileJournal, FileStore, StepMachine as FlowEngine, LocalStorageStore, MemoryJournal, MemoryStore, StepMachine, TASK_STATUS, addDynamicTask, addNode, addProvides, addRequires, apply, applyAll, applyEvent, applyEvents, applyInferences, applyStepResult, batch, buildInferencePrompt, checkCircuitBreaker, computeAvailableOutputs, computeStepInput, createCallbackHandler, createCliAdapter, createDefaultGraphEngineStore, createStepMachine as createEngine, createFireAndForgetHandler, createHttpAdapter, createInitialExecutionState, createInitialState, createLiveGraph, createNoopHandler, createReactiveGraph, createScriptHandler, createShellHandler, createStepMachine, createWebhookHandler, detectStuckState, disableNode, drainTokens, enableNode, exportGraphConfig, exportGraphConfigToFile, extractReturnData, flowToMermaid, getAllTasks, getCandidateTasks, getDownstream, getMaxExecutions, getNode, getProvides, getRefreshStrategy, getRequires, getTask, getUnreachableNodes, getUnreachableTokens, getUpstream, graphToMermaid, hasTask, inferAndApply, inferCompletions, injectTokens, inspect, isExecutionComplete, isNonActiveTask, isRerunnable, isTaskCompleted, isTaskRunning, liveCardsToReactiveGraph, loadGraphConfig, loadStepFlow, mutateGraph, next, planExecution, removeNode, removeProvides, removeRequires, resetNode, resolveConfigTemplates, resolveVariables, restore, schedule, snapshot, validateFlowSchema, validateGraph, validateGraphConfig, validateGraphSchema, validateLiveCardSchema, validateLiveGraph, validateReactiveGraph, validateStepFlowConfig };
12782
+ // schema/board-status.schema.json
12783
+ var board_status_schema_default = {
12784
+ $schema: "https://json-schema.org/draft/2020-12/schema",
12785
+ $id: "https://yaml-flow.dev/schema/board-status.schema.json",
12786
+ title: "Board Status Object",
12787
+ type: "object",
12788
+ additionalProperties: false,
12789
+ required: ["schema_version", "meta", "summary", "cards"],
12790
+ properties: {
12791
+ schema_version: {
12792
+ type: "string",
12793
+ const: "v1"
12794
+ },
12795
+ meta: {
12796
+ type: "object",
12797
+ additionalProperties: false,
12798
+ required: ["board"],
12799
+ properties: {
12800
+ board: {
12801
+ type: "object",
12802
+ additionalProperties: false,
12803
+ required: ["path"],
12804
+ properties: {
12805
+ path: { type: "string" }
12806
+ }
12807
+ }
12808
+ }
12809
+ },
12810
+ summary: {
12811
+ type: "object",
12812
+ additionalProperties: false,
12813
+ required: ["card_count", "completed", "eligible", "pending", "blocked", "unresolved"],
12814
+ properties: {
12815
+ card_count: { type: "integer", minimum: 0 },
12816
+ completed: { type: "integer", minimum: 0 },
12817
+ eligible: { type: "integer", minimum: 0 },
12818
+ pending: { type: "integer", minimum: 0 },
12819
+ blocked: { type: "integer", minimum: 0 },
12820
+ unresolved: { type: "integer", minimum: 0 },
12821
+ failed: { type: "integer", minimum: 0 },
12822
+ in_progress: { type: "integer", minimum: 0 },
12823
+ orphan_cards: { type: "integer", minimum: 0 },
12824
+ topology: {
12825
+ type: "object",
12826
+ additionalProperties: false,
12827
+ required: ["edge_count", "max_fan_out_card", "max_fan_out"],
12828
+ properties: {
12829
+ edge_count: { type: "integer", minimum: 0 },
12830
+ max_fan_out_card: { type: ["string", "null"] },
12831
+ max_fan_out: { type: "integer", minimum: 0 }
12832
+ }
12833
+ }
12834
+ }
12835
+ },
12836
+ cards: {
12837
+ type: "array",
12838
+ items: {
12839
+ type: "object",
12840
+ additionalProperties: false,
12841
+ required: [
12842
+ "name",
12843
+ "status",
12844
+ "requires",
12845
+ "requires_satisfied",
12846
+ "requires_missing",
12847
+ "provides_declared",
12848
+ "provides_runtime",
12849
+ "blocked_by",
12850
+ "unblocks",
12851
+ "runtime"
12852
+ ],
12853
+ properties: {
12854
+ name: { type: "string" },
12855
+ status: { type: "string" },
12856
+ error: {
12857
+ type: "object",
12858
+ additionalProperties: false,
12859
+ required: ["message"],
12860
+ properties: {
12861
+ message: { type: "string" },
12862
+ code: { type: "string" },
12863
+ at: { type: ["string", "null"] },
12864
+ source: { type: "string" }
12865
+ }
12866
+ },
12867
+ requires: { type: "array", items: { type: "string" } },
12868
+ requires_satisfied: { type: "array", items: { type: "string" } },
12869
+ requires_missing: { type: "array", items: { type: "string" } },
12870
+ provides_declared: { type: "array", items: { type: "string" } },
12871
+ provides_runtime: { type: "array", items: { type: "string" } },
12872
+ blocked_by: { type: "array", items: { type: "string" } },
12873
+ unblocks: { type: "array", items: { type: "string" } },
12874
+ runtime: {
12875
+ type: "object",
12876
+ additionalProperties: false,
12877
+ required: [
12878
+ "attempt_count",
12879
+ "restart_count",
12880
+ "in_progress_since",
12881
+ "last_transition_at",
12882
+ "last_completed_at",
12883
+ "last_restarted_at",
12884
+ "status_age_ms"
12885
+ ],
12886
+ properties: {
12887
+ attempt_count: { type: "integer", minimum: 0 },
12888
+ restart_count: { type: "integer", minimum: 0 },
12889
+ in_progress_since: { type: ["string", "null"] },
12890
+ last_transition_at: { type: ["string", "null"] },
12891
+ last_completed_at: { type: ["string", "null"] },
12892
+ last_restarted_at: { type: ["string", "null"] },
12893
+ status_age_ms: { type: ["integer", "null"], minimum: 0 }
12894
+ }
12895
+ }
12896
+ }
12897
+ }
12898
+ }
12899
+ }
12900
+ };
12901
+
12902
+ // schema/card-runtime.schema.json
12903
+ var card_runtime_schema_default = {
12904
+ $schema: "https://json-schema.org/draft/2020-12/schema",
12905
+ $id: "https://yaml-flow.dev/schema/card-runtime.schema.json",
12906
+ title: "Card Runtime Computed Artifact",
12907
+ description: "Published per-card runtime artifact written to runtime-out/cards/<card-id>.computed.json. Contains only values produced by the compute step.",
12908
+ type: "object",
12909
+ required: ["schema_version", "card_id", "computed_values"],
12910
+ additionalProperties: false,
12911
+ properties: {
12912
+ schema_version: {
12913
+ type: "string",
12914
+ const: "v1",
12915
+ description: "Artifact schema version."
12916
+ },
12917
+ card_id: {
12918
+ type: "string",
12919
+ description: "The ID of the card this artifact belongs to."
12920
+ },
12921
+ computed_values: {
12922
+ type: "object",
12923
+ description: "Key/value map of outputs produced by the card's JSONata compute steps.",
12924
+ additionalProperties: true
12925
+ }
12926
+ }
12927
+ };
12928
+
12929
+ // src/runtime-artifacts/schema-validator.ts
12930
+ var import__ = __toESM(require__());
12931
+ var boardStatusValidator = null;
12932
+ var cardRuntimeValidator = null;
12933
+ function createAjv() {
12934
+ const ajv = new import__.default({ allErrors: true, strict: false });
12935
+ addFormats(ajv);
12936
+ return ajv;
12937
+ }
12938
+ function toValidationResult(validate) {
12939
+ const errors = (validate.errors ?? []).map((error) => {
12940
+ const instancePath = error.instancePath || "/";
12941
+ return `${instancePath}: ${error.message ?? "unknown error"}`;
12942
+ });
12943
+ return { ok: false, errors };
12944
+ }
12945
+ function getBoardStatusValidator() {
12946
+ if (boardStatusValidator) return boardStatusValidator;
12947
+ boardStatusValidator = createAjv().compile(board_status_schema_default);
12948
+ return boardStatusValidator;
12949
+ }
12950
+ function getCardRuntimeValidator() {
12951
+ if (cardRuntimeValidator) return cardRuntimeValidator;
12952
+ cardRuntimeValidator = createAjv().compile(card_runtime_schema_default);
12953
+ return cardRuntimeValidator;
12954
+ }
12955
+ function validateBoardStatusSchema(statusObject) {
12956
+ const validate = getBoardStatusValidator();
12957
+ if (validate(statusObject)) return { ok: true, errors: [] };
12958
+ return toValidationResult(validate);
12959
+ }
12960
+ function validateCardRuntimeSchema(cardRuntimeObject) {
12961
+ const validate = getCardRuntimeValidator();
12962
+ if (validate(cardRuntimeObject)) return { ok: true, errors: [] };
12963
+ return toValidationResult(validate);
12964
+ }
12965
+
12966
+ export { COMPLETION_STRATEGIES, CONFLICT_STRATEGIES, CardCompute, DEFAULTS, EXECUTION_MODES, EXECUTION_STATUS, FileStore, StepMachine as FlowEngine, LocalStorageStore, MemoryJournal, MemoryStore, StepMachine, TASK_STATUS, addDynamicTask, addNode, addProvides, addRequires, apply, applyAll, applyEvent, applyEvents, applyInferences, applyStepResult, batch, buildInferencePrompt, checkCircuitBreaker, computeAvailableOutputs, computeStepInput, createBoardLiveGraphRuntime, createCallbackHandler, createCliAdapter, createDefaultGraphEngineStore, createStepMachine as createEngine, createFireAndForgetHandler, createHttpAdapter, createInitialExecutionState, createInitialState, createLiveGraph, createNoopHandler, createReactiveGraph, createScriptHandler, createShellHandler, createStepMachine, createWebhookHandler, detectStuckState, disableNode, drainTokens, enableNode, exportGraphConfig, exportGraphConfigToFile, extractReturnData, flowToMermaid, getAllTasks, getCandidateTasks, getDownstream, getMaxExecutions, getNode, getProvides, getRefreshStrategy, getRequires, getTask, getUnreachableNodes, getUnreachableTokens, getUpstream, graphToMermaid, hasTask, inferAndApply, inferCompletions, injectTokens, inspect, isExecutionComplete, isNonActiveTask, isRerunnable, isTaskCompleted, isTaskRunning, liveCardsToReactiveGraph, loadGraphConfig, loadStepFlow, mutateGraph, next, planExecution, removeNode, removeProvides, removeRequires, resetNode, resolveConfigTemplates, resolveVariables, restore, schedule, snapshot, validateBoardStatusSchema, validateCardRuntimeSchema, validateFlowSchema, validateGraph, validateGraphConfig, validateGraphSchema, validateLiveCard, validateLiveCardDefinition, validateLiveCardRuntimeExpressions, validateLiveCardSchema, validateLiveGraph, validateReactiveGraph, validateStepFlowConfig };
11844
12967
  //# sourceMappingURL=index.js.map
11845
12968
  //# sourceMappingURL=index.js.map