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