yaml-flow 5.4.2 → 7.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 (252) hide show
  1. package/board-live-cards-cli.js +6 -6
  2. package/browser/asset-integrity.json +10 -0
  3. package/browser/board-livecards-client.js +2 -0
  4. package/browser/board-livecards-client.js.map +1 -0
  5. package/browser/board-livecards-localstorage.js +10 -0
  6. package/browser/board-livecards-localstorage.js.map +1 -0
  7. package/browser/board-livegraph-engine.js +2 -1676
  8. package/browser/board-livegraph-engine.js.map +1 -1
  9. package/browser/card-compute.js +28 -28
  10. package/browser/compute-jsonata.js +5 -0
  11. package/browser/compute-jsonata.js.map +1 -0
  12. package/browser/live-cards.js +561 -129
  13. package/browser/live-cards.schema.json +418 -132
  14. package/card-store.js +37 -0
  15. package/dist/batch/index.cjs +1 -108
  16. package/dist/batch/index.cjs.map +1 -1
  17. package/dist/batch/index.js +1 -106
  18. package/dist/batch/index.js.map +1 -1
  19. package/dist/board-live-cards-lib-Bg6EvCo5.d.cts +136 -0
  20. package/dist/board-live-cards-lib-jM2uYG1v.d.ts +136 -0
  21. package/dist/board-live-cards-public-CW5074xr.d.cts +318 -0
  22. package/dist/board-live-cards-public-hnZo0mAf.d.ts +318 -0
  23. package/dist/board-livegraph-runtime/index.cjs +2 -1671
  24. package/dist/board-livegraph-runtime/index.cjs.map +1 -1
  25. package/dist/board-livegraph-runtime/index.d.cts +12 -11
  26. package/dist/board-livegraph-runtime/index.d.ts +12 -11
  27. package/dist/board-livegraph-runtime/index.js +2 -1662
  28. package/dist/board-livegraph-runtime/index.js.map +1 -1
  29. package/dist/board-livegraph-runtime/jsonata-sync.cjs +7623 -0
  30. package/dist/card-compute/index.cjs +9 -7159
  31. package/dist/card-compute/index.cjs.map +1 -1
  32. package/dist/card-compute/index.d.cts +27 -1
  33. package/dist/card-compute/index.d.ts +27 -1
  34. package/dist/card-compute/index.js +9 -7145
  35. package/dist/card-compute/index.js.map +1 -1
  36. package/dist/card-compute/jsonata-sync.cjs +7623 -0
  37. package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs +3 -0
  38. package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs.map +1 -0
  39. package/dist/cli/browser-api/board-live-cards-browser-adapter.d.cts +37 -0
  40. package/dist/cli/browser-api/board-live-cards-browser-adapter.d.ts +37 -0
  41. package/dist/cli/browser-api/board-live-cards-browser-adapter.js +3 -0
  42. package/dist/cli/browser-api/board-live-cards-browser-adapter.js.map +1 -0
  43. package/dist/cli/browser-api/card-store-browser-api.cjs +2 -0
  44. package/dist/cli/browser-api/card-store-browser-api.cjs.map +1 -0
  45. package/dist/cli/browser-api/card-store-browser-api.d.cts +26 -0
  46. package/dist/cli/browser-api/card-store-browser-api.d.ts +26 -0
  47. package/dist/cli/browser-api/card-store-browser-api.js +2 -0
  48. package/dist/cli/browser-api/card-store-browser-api.js.map +1 -0
  49. package/dist/cli/browser-api/jsonata-sync.cjs +7623 -0
  50. package/dist/cli/node/artifacts-store-cli.cjs +11 -0
  51. package/dist/cli/node/artifacts-store-cli.cjs.map +1 -0
  52. package/dist/cli/node/artifacts-store-cli.d.cts +8 -0
  53. package/dist/cli/node/artifacts-store-cli.d.ts +8 -0
  54. package/dist/cli/node/artifacts-store-cli.js +11 -0
  55. package/dist/cli/node/artifacts-store-cli.js.map +1 -0
  56. package/dist/cli/node/board-live-cards-cli.cjs +15 -0
  57. package/dist/cli/node/board-live-cards-cli.cjs.map +1 -0
  58. package/dist/cli/node/board-live-cards-cli.d.cts +20 -0
  59. package/dist/cli/node/board-live-cards-cli.d.ts +20 -0
  60. package/dist/cli/node/board-live-cards-cli.js +15 -0
  61. package/dist/cli/node/board-live-cards-cli.js.map +1 -0
  62. package/dist/cli/node/card-store-cli.cjs +8 -0
  63. package/dist/cli/node/card-store-cli.cjs.map +1 -0
  64. package/dist/cli/node/card-store-cli.d.cts +15 -0
  65. package/dist/cli/node/card-store-cli.d.ts +15 -0
  66. package/dist/cli/node/card-store-cli.js +8 -0
  67. package/dist/cli/node/card-store-cli.js.map +1 -0
  68. package/dist/cli/node/execution-adapter.cjs +3 -0
  69. package/dist/cli/node/execution-adapter.cjs.map +1 -0
  70. package/dist/cli/node/execution-adapter.d.cts +174 -0
  71. package/dist/cli/node/execution-adapter.d.ts +174 -0
  72. package/dist/cli/node/execution-adapter.js +3 -0
  73. package/dist/cli/node/execution-adapter.js.map +1 -0
  74. package/dist/cli/node/fs-board-adapter.cjs +14 -0
  75. package/dist/cli/node/fs-board-adapter.cjs.map +1 -0
  76. package/dist/cli/node/fs-board-adapter.d.cts +204 -0
  77. package/dist/cli/node/fs-board-adapter.d.ts +204 -0
  78. package/dist/cli/node/fs-board-adapter.js +14 -0
  79. package/dist/cli/node/fs-board-adapter.js.map +1 -0
  80. package/dist/cli/node/jsonata-sync.cjs +7623 -0
  81. package/dist/cli/node/source-cli-task-executor.cjs +11 -0
  82. package/dist/cli/node/source-cli-task-executor.cjs.map +1 -0
  83. package/dist/cli/node/source-cli-task-executor.d.cts +1 -0
  84. package/dist/cli/node/source-cli-task-executor.d.ts +1 -0
  85. package/dist/cli/node/source-cli-task-executor.js +11 -0
  86. package/dist/cli/node/source-cli-task-executor.js.map +1 -0
  87. package/dist/config/index.cjs +1 -79
  88. package/dist/config/index.cjs.map +1 -1
  89. package/dist/config/index.js +1 -76
  90. package/dist/config/index.js.map +1 -1
  91. package/dist/continuous-event-graph/index.cjs +2 -2129
  92. package/dist/continuous-event-graph/index.cjs.map +1 -1
  93. package/dist/continuous-event-graph/index.d.cts +81 -5
  94. package/dist/continuous-event-graph/index.d.ts +81 -5
  95. package/dist/continuous-event-graph/index.js +2 -2088
  96. package/dist/continuous-event-graph/index.js.map +1 -1
  97. package/dist/continuous-event-graph/jsonata-sync.cjs +7623 -0
  98. package/dist/event-graph/index.cjs +22 -8292
  99. package/dist/event-graph/index.cjs.map +1 -1
  100. package/dist/event-graph/index.js +22 -8237
  101. package/dist/event-graph/index.js.map +1 -1
  102. package/dist/execution-refs.cjs +3 -0
  103. package/dist/execution-refs.cjs.map +1 -0
  104. package/dist/execution-refs.d.cts +260 -0
  105. package/dist/execution-refs.d.ts +260 -0
  106. package/dist/execution-refs.js +3 -0
  107. package/dist/execution-refs.js.map +1 -0
  108. package/dist/index.cjs +29 -13221
  109. package/dist/index.cjs.map +1 -1
  110. package/dist/index.d.cts +2 -4
  111. package/dist/index.d.ts +2 -4
  112. package/dist/index.js +29 -13112
  113. package/dist/index.js.map +1 -1
  114. package/dist/inference/index.cjs +5 -617
  115. package/dist/inference/index.cjs.map +1 -1
  116. package/dist/inference/index.js +5 -610
  117. package/dist/inference/index.js.map +1 -1
  118. package/dist/jsonata-sync.cjs +7623 -0
  119. package/dist/{live-cards-bridge-x5XREkXm.d.cts → live-cards-bridge-BXbVTsna.d.cts} +27 -4
  120. package/dist/{live-cards-bridge-EQjytzI_.d.ts → live-cards-bridge-Ds28XR15.d.ts} +27 -4
  121. package/dist/server-runtime/index.cjs +9 -0
  122. package/dist/server-runtime/index.cjs.map +1 -0
  123. package/dist/server-runtime/index.d.cts +31 -0
  124. package/dist/server-runtime/index.d.ts +31 -0
  125. package/dist/server-runtime/index.js +9 -0
  126. package/dist/server-runtime/index.js.map +1 -0
  127. package/dist/server-runtime/jsonata-sync.cjs +7623 -0
  128. package/dist/step-machine/index.cjs +11 -7129
  129. package/dist/step-machine/index.cjs.map +1 -1
  130. package/dist/step-machine/index.js +11 -7113
  131. package/dist/step-machine/index.js.map +1 -1
  132. package/dist/step-machine-public/index.cjs +2 -0
  133. package/dist/step-machine-public/index.cjs.map +1 -0
  134. package/dist/step-machine-public/index.d.cts +159 -0
  135. package/dist/step-machine-public/index.d.ts +159 -0
  136. package/dist/step-machine-public/index.js +2 -0
  137. package/dist/step-machine-public/index.js.map +1 -0
  138. package/dist/step-machine-public/jsonata-sync.cjs +7623 -0
  139. package/dist/storage-refs.cjs +10 -0
  140. package/dist/storage-refs.cjs.map +1 -0
  141. package/dist/storage-refs.d.cts +93 -0
  142. package/dist/storage-refs.d.ts +93 -0
  143. package/dist/storage-refs.js +10 -0
  144. package/dist/storage-refs.js.map +1 -0
  145. package/dist/stores/file.cjs +1 -114
  146. package/dist/stores/file.cjs.map +1 -1
  147. package/dist/stores/file.js +1 -112
  148. package/dist/stores/file.js.map +1 -1
  149. package/dist/stores/index.cjs +1 -231
  150. package/dist/stores/index.cjs.map +1 -1
  151. package/dist/stores/index.js +1 -227
  152. package/dist/stores/index.js.map +1 -1
  153. package/dist/stores/localStorage.cjs +1 -76
  154. package/dist/stores/localStorage.cjs.map +1 -1
  155. package/dist/stores/localStorage.js +1 -74
  156. package/dist/stores/localStorage.js.map +1 -1
  157. package/dist/stores/memory.cjs +1 -47
  158. package/dist/stores/memory.cjs.map +1 -1
  159. package/dist/stores/memory.js +1 -45
  160. package/dist/stores/memory.js.map +1 -1
  161. package/dist/types-B1ZRa4aI.d.ts +147 -0
  162. package/dist/types-BxEFcVK9.d.cts +147 -0
  163. package/examples/browser/boards/portfolio-tracker/portfolio-t4.js +291 -0
  164. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-fetch-prices.js +218 -0
  165. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-fetch-prices.py +201 -0
  166. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-http-test.js +357 -0
  167. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-inference-adapter.js +25 -16
  168. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-public.js +552 -0
  169. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-server.js +300 -0
  170. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-server.py +617 -0
  171. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-sse-worker.js +48 -0
  172. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.py +366 -0
  173. package/examples/cli/step-machine-cli/portfolio-tracker/--base-ref/.runtime-out +1 -0
  174. package/examples/cli/step-machine-cli/portfolio-tracker/--base-ref/board-graph.json +32 -0
  175. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +70 -3
  176. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +16 -11
  177. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +9 -8
  178. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/poll-status-cli.js +49 -0
  179. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +2 -6
  180. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +4 -8
  181. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/status-cli.js +3 -7
  182. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +9 -8
  183. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +12 -17
  184. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +2 -6
  185. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/_board_pycli.py +107 -0
  186. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/add-cards.py +51 -0
  187. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/init-board.py +45 -0
  188. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/poll-status.py +71 -0
  189. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/reset-board-dir.py +36 -0
  190. package/examples/cli/step-machine-cli/portfolio-tracker/inline-python-demo.flow.yaml +26 -0
  191. package/examples/cli/step-machine-cli/portfolio-tracker/inline-python-handlers.py +39 -0
  192. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker-pycli.flow.yaml +80 -0
  193. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +36 -187
  194. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.input.json +40 -34
  195. package/examples/cli/step-machine-cli/portfolio-tracker/run-inline-python-demo-pycli.py +43 -0
  196. package/examples/cli/step-machine-cli/portfolio-tracker/run-portfolio-tracker-pycli.py +77 -0
  197. package/examples/cli/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +1 -2
  198. package/examples/cli/step-machine-demo/jsonata-init-board-cli.js +8 -13
  199. package/examples/cli/step-machine-demo/jsonata-init-board.flow.yaml +33 -9
  200. package/examples/cli/step-machine-demo/one-step-cli-only.flow.yaml +3 -1
  201. package/examples/cli/step-machine-demo/step2-double-cli.js +6 -12
  202. package/examples/cli/step-machine-demo/two-step-math.flow.yaml +66 -4
  203. package/examples/cli/step-machine-demo/two-step-mixed.flow.yaml +13 -5
  204. package/examples/example-board/agent-instructions.md +11 -5
  205. package/examples/example-board/cards/_index.json +47 -0
  206. package/examples/example-board/cards/card-market-prices.json +33 -9
  207. package/examples/example-board/cards/card-my-identity.json +30 -6
  208. package/examples/example-board/cards/card-portfolio-action.json +24 -6
  209. package/examples/example-board/cards/card-portfolio-intelligence.json +97 -0
  210. package/examples/example-board/cards/card-portfolio-risks.json +24 -6
  211. package/examples/example-board/cards/card-portfolio-value.json +38 -10
  212. package/examples/example-board/cards/card-portfolio.json +57 -13
  213. package/examples/example-board/cards/card-rebalance-impact.json +22 -6
  214. package/examples/example-board/cards/card-rebalance-sim.json +66 -15
  215. package/examples/example-board/demo-chat-handler.js +14 -4
  216. package/examples/example-board/demo-server-config.json +1 -0
  217. package/examples/example-board/demo-server.js +366 -68
  218. package/examples/example-board/demo-shell-localstorage.html +774 -0
  219. package/examples/example-board/demo-shell-with-server.html +20 -37
  220. package/examples/example-board/demo-shell.html +5 -4
  221. package/examples/example-board/demo-task-executor.js +273 -275
  222. package/examples/index.html +0 -14
  223. package/examples/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +0 -1
  224. package/examples/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +1 -2
  225. package/package.json +46 -8
  226. package/schema/live-cards.schema.json +418 -132
  227. package/step-machine-cli.js +43 -310
  228. package/board-livecards-server-runtime.js +0 -1574
  229. package/browser/board-livecards-runtime-client.js +0 -263
  230. package/dist/cli/board-live-cards-cli.cjs +0 -10650
  231. package/dist/cli/board-live-cards-cli.cjs.map +0 -1
  232. package/dist/cli/board-live-cards-cli.d.cts +0 -179
  233. package/dist/cli/board-live-cards-cli.d.ts +0 -179
  234. package/dist/cli/board-live-cards-cli.js +0 -10598
  235. package/dist/cli/board-live-cards-cli.js.map +0 -1
  236. package/dist/journal-9HEgs7dU.d.ts +0 -28
  237. package/dist/journal-B-JCfQnh.d.cts +0 -28
  238. package/dist/schedule-Cszq9LYY.d.ts +0 -21
  239. package/dist/schedule-qWNL0RQh.d.cts +0 -21
  240. package/examples/browser/boards/portfolio-tracker/cards/holdings-table.json +0 -22
  241. package/examples/browser/boards/portfolio-tracker/cards/portfolio-form.json +0 -16
  242. package/examples/browser/boards/portfolio-tracker/cards/portfolio-risk-assessment.json +0 -28
  243. package/examples/browser/boards/portfolio-tracker/cards/portfolio-value.json +0 -15
  244. package/examples/browser/boards/portfolio-tracker/cards/price-fetch.json +0 -15
  245. package/examples/browser/boards/portfolio-tracker/cards/rebalancing-strategy.json +0 -28
  246. package/examples/browser/boards/portfolio-tracker/fetch-prices.js +0 -43
  247. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-task-executor.cjs +0 -96
  248. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.bat +0 -7
  249. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.js +0 -351
  250. package/examples/cli/step-machine-demo/two-step-math-handlers.js +0 -32
  251. package/examples/cli/step-machine-demo/two-step-mixed-handlers.js +0 -24
  252. package/examples/example-board/demo-shell-browser.html +0 -674
@@ -0,0 +1,10 @@
1
+ 'use strict';var i=require('fs'),c=require('path'),child_process=require('child_process');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var i__namespace=/*#__PURE__*/_interopNamespace(i);var c__namespace=/*#__PURE__*/_interopNamespace(c);function y(t){if(t.startsWith("::fs-path::"))return {kind:"fs-path",value:t.slice(11)};if(!t.startsWith("b64:"))throw new Error(`Invalid ref format (expected b64:<base64url(json)>): ${t}`);let n=t.slice(4),o=n.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-n.length%4)%4),e;try{e=JSON.parse(Buffer.from(o,"base64").toString("utf8"));}catch{throw new Error(`Invalid ref format (malformed base64url/json): ${t}`)}if(!e||typeof e!="object")throw new Error(`Invalid ref format (expected object payload): ${t}`);let r=e;if(typeof r.kind!="string"||typeof r.value!="string")throw new Error(`Invalid ref format (payload must contain string kind/value): ${t}`);return {kind:r.kind,value:r.value}}function h(t){return `b64:${Buffer.from(JSON.stringify(t),"utf8").toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}`}function k(){return {read(t){if(!i__namespace.existsSync(t))return null;try{return i__namespace.readFileSync(t,"utf-8")}catch{return null}},write(t,n){i__namespace.mkdirSync(c__namespace.dirname(t),{recursive:true}),i__namespace.writeFileSync(t,n,"utf-8");}}}function R(t){if(t.kind==="fs-path")return k();throw new Error(`Unsupported storage kind: "${t.kind}". Supported kinds: fs-path`)}function l(t){try{return y(t).value}catch{return t}}function g(t){let n=t.extra?.notifyChannel;return typeof n=="string"&&n.length>0?n:void 0}function w(t){if(!t.endsWith(".ts"))return {cmd:process.execPath,args:[t]};let n=c__namespace.dirname(t),o=[];for(let r=1;r<=5;r++){let s=c__namespace.join(n,...Array(r).fill(".."),"node_modules");o.push(c__namespace.join(s,"tsx","dist","cli.mjs")),o.push(c__namespace.join(s,".bin","tsx"));}let e=o.find(r=>i__namespace.existsSync(r));return e?{cmd:process.execPath,args:[e,t]}:{cmd:"npx",args:["tsx",t]}}function b(t,n){let{token:o,via:e}=t;if(e.howToRun==="local-node"||e.howToRun==="local-process"){let r=l(e.whatToRun),{cmd:s,args:d}=w(r),u=g(e),f=[...d,"source-data-fetched","--ref",h(n),"--token",o,...u?["--notify-channel",u]:[]],a=child_process.spawnSync(s,f,{encoding:"utf-8",windowsHide:true});if(a.status!==0)throw new Error(`reportComplete: board CLI exited ${a.status}: ${a.stderr?.trim()}`);return}if(e.howToRun==="http:post"){let r=l(e.whatToRun),s=JSON.stringify({status:"complete",ref:h(n),token:o});m(r,s);return}throw new Error(`reportComplete: unsupported via.howToRun "${e.howToRun}"`)}function v(t,n){let{token:o,via:e}=t;if(e.howToRun==="local-node"||e.howToRun==="local-process"){let r=l(e.whatToRun),{cmd:s,args:d}=w(r),u=g(e),f=[...d,"source-data-fetch-failure","--token",o,"--reason",n,...u?["--notify-channel",u]:[]],a=child_process.spawnSync(s,f,{encoding:"utf-8",windowsHide:true});if(a.status!==0)throw new Error(`reportFailed: board CLI exited ${a.status}: ${a.stderr?.trim()}`);return}if(e.howToRun==="http:post"){let r=l(e.whatToRun),s=JSON.stringify({status:"failed",reason:n,token:o});m(r,s);return}throw new Error(`reportFailed: unsupported via.howToRun "${e.howToRun}"`)}function m(t,n){let o=`
2
+ const {request} = require(new URL('${t}').protocol === 'https:' ? 'https' : 'http');
3
+ const h = ${JSON.stringify({"Content-Type":"application/json","Content-Length":Buffer.byteLength(n)})};
4
+ const u = new URL('${t}');
5
+ const req = request({hostname:u.hostname,port:u.port,path:u.pathname+u.search,method:'POST',headers:h});
6
+ req.on('error', e => { process.stderr.write(e.message); process.exit(1); });
7
+ req.write(${JSON.stringify(n)});
8
+ req.end();
9
+ `,e=child_process.spawnSync(process.execPath,["-e",o],{encoding:"utf-8",windowsHide:true});if(e.status!==0)throw new Error(`http-post failed: ${e.stderr?.trim()}`)}exports.blobStorageForRef=R;exports.parseRef=y;exports.reportComplete=b;exports.reportFailed=v;exports.serializeRef=h;//# sourceMappingURL=storage-refs.cjs.map
10
+ //# sourceMappingURL=storage-refs.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli/node/public-storage-adapter.ts"],"names":["parseRef","s","payload","padded","decoded","candidate","serializeRef","ref","createFsPathBlobStorage","key","i","content","c","blobStorageForRef","_parseWhatToRun","whatToRun","_notifyChannelFromVia","via","_resolveLocalNodeInvocation","scriptPath","dir","candidates","up","base","tsx","p","reportComplete","callback","outRef","token","cmd","args","notifyChannel","callbackArgs","result","spawnSync","url","body","_httpPostSync","reportFailed","reason","script"],"mappings":"mfA+CO,SAASA,CAAAA,CAASC,CAAAA,CAAyB,CAEhD,GAAIA,EAAE,UAAA,CAAW,aAAa,CAAA,CAC5B,OAAO,CAAE,IAAA,CAAM,SAAA,CAAW,KAAA,CAAOA,CAAAA,CAAE,MAAM,EAAoB,CAAE,CAAA,CAEjE,GAAI,CAACA,CAAAA,CAAE,UAAA,CAAW,MAAM,CAAA,CAAG,MAAM,IAAI,KAAA,CAAM,CAAA,qDAAA,EAAwDA,CAAC,CAAA,CAAE,CAAA,CACtG,IAAMC,CAAAA,CAAUD,EAAE,KAAA,CAAM,CAAC,CAAA,CACnBE,CAAAA,CAASD,EAAQ,OAAA,CAAQ,IAAA,CAAM,GAAG,CAAA,CAAE,QAAQ,IAAA,CAAM,GAAG,CAAA,CAAI,GAAA,CAAI,QAAQ,CAAA,CAAKA,CAAAA,CAAQ,MAAA,CAAS,CAAA,EAAM,CAAC,CAAA,CACpGE,CAAAA,CACJ,GAAI,CACFA,EAAU,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,IAAA,CAAKD,EAAQ,QAAQ,CAAA,CAAE,QAAA,CAAS,MAAM,CAAC,EACrE,CAAA,KAAQ,CACN,MAAM,IAAI,KAAA,CAAM,CAAA,+CAAA,EAAkDF,CAAC,EAAE,CACvE,CACA,GAAI,CAACG,GAAW,OAAOA,CAAAA,EAAY,QAAA,CACjC,MAAM,IAAI,KAAA,CAAM,CAAA,8CAAA,EAAiDH,CAAC,CAAA,CAAE,EAEtE,IAAMI,CAAAA,CAAYD,CAAAA,CAClB,GAAI,OAAOC,CAAAA,CAAU,IAAA,EAAS,QAAA,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EAAI,QAAQ,CAAA,CAAA,CAAG,CAC5E,CAGA,SAASqB,CAAAA,CAAcF,CAAAA,CAAaC,CAAAA,CAAoB,CACtD,IAAMI,CAAAA,CAAS;AAAA,uCAAA,EACwBL,CAAG,CAAA;AAAA,cAAA,EAC5B,IAAA,CAAK,SAAA,CAAU,CAAE,cAAA,CAAgB,kBAAA,CAAoB,gBAAA,CAAkB,MAAA,CAAO,UAAA,CAAWC,CAAI,CAAE,CAAC,CAAC,CAAA;AAAA,uBAAA,EACxFD,CAAG,CAAA;AAAA;AAAA;AAAA,cAAA,EAGZ,IAAA,CAAK,SAAA,CAAUC,CAAI,CAAC,CAAA;AAAA;AAAA,EAAA,CAAA,CAG5BH,CAAAA,CAASC,uBAAAA,CAAU,OAAA,CAAQ,QAAA,CAAU,CAAC,IAAA,CAAMM,CAAM,CAAA,CAAG,CAAE,QAAA,CAAU,OAAA,CAAS,WAAA,CAAa,IAAK,CAAC,CAAA,CACnG,GAAIP,CAAAA,CAAO,MAAA,GAAW,CAAA,CAAG,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqBA,CAAAA,CAAO,MAAA,EAAQ,IAAA,EAAM,CAAA,CAAE,CACvF","file":"storage-refs.cjs","sourcesContent":["/**\n * public-storage-adapter.ts\n *\n * Standalone file — copy this to your task-executor project.\n * Zero dependencies on the rest of yaml-flow.\n *\n * Provides:\n * - KindValueRef wire format: b64:<base64url(json)>\n * - parseRef() parse a b64:<base64url(json)> string\n * - serializeRef() produce a b64:<base64url(json)> string\n * - BlobStorage read/write interface\n * - blobStorageForRef resolve a ref to its BlobStorage backend\n * - ExecutionRef portable invocation descriptor (inlined, stays standalone)\n * - TaskCallback how to report task completion back to the board\n * - reportComplete() call from executor on success\n * - reportFailed() call from executor on failure\n *\n * Supported storage kinds:\n * fs-path — ref.value is an absolute file path; reads/writes via node:fs\n *\n * Supported callback transports (via ExecutionRef.howToRun):\n * local-node — invoke board CLI as a child Node process\n * http:post — HTTP POST to a board endpoint\n *\n * Usage:\n * import { parseRef, blobStorageForRef, reportComplete, reportFailed } from './public-storage-adapter.js';\n *\n * const { source_def, callback } = JSON.parse(blobStorageForRef(inRef).read(inRef.value));\n * // ... do work, write to outRef ...\n * reportComplete(callback, outRef);\n */\n\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { spawnSync } from 'node:child_process';\n\n// ============================================================================\n// KindValueRef\n// ============================================================================\n\nexport interface KindValueRef {\n readonly kind: string;\n readonly value: string;\n}\n\n/** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef.\n * Also accepts the legacy ::fs-path::<path> format for backward compatibility. */\nexport function parseRef(s: string): KindValueRef {\n // Legacy format: ::fs-path::<path>\n if (s.startsWith('::fs-path::')) {\n return { kind: 'fs-path', value: s.slice('::fs-path::'.length) };\n }\n if (!s.startsWith('b64:')) throw new Error(`Invalid ref format (expected b64:<base64url(json)>): ${s}`);\n const payload = s.slice(4);\n const padded = payload.replace(/-/g, '+').replace(/_/g, '/') + '='.repeat((4 - (payload.length % 4)) % 4);\n let decoded: unknown;\n try {\n decoded = JSON.parse(Buffer.from(padded, 'base64').toString('utf8'));\n } catch {\n throw new Error(`Invalid ref format (malformed base64url/json): ${s}`);\n }\n if (!decoded || typeof decoded !== 'object') {\n throw new Error(`Invalid ref format (expected object payload): ${s}`);\n }\n const candidate = decoded as { kind?: unknown; value?: unknown };\n if (typeof candidate.kind !== 'string' || typeof candidate.value !== 'string') {\n throw new Error(`Invalid ref format (payload must contain string kind/value): ${s}`);\n }\n return { kind: candidate.kind, value: candidate.value };\n}\n\n/** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */\nexport function serializeRef(ref: KindValueRef): string {\n return `b64:${Buffer.from(JSON.stringify(ref), 'utf8').toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/g, '')}`;\n}\n\n// ============================================================================\n// BlobStorage\n// ============================================================================\n\nexport interface BlobStorage {\n /** Returns content string, or null if not found. */\n read(key: string): string | null;\n /** Write content at key. */\n write(key: string, content: string): void;\n}\n\n// ============================================================================\n// fs-path backend — key IS the absolute file path\n// ============================================================================\n\nfunction createFsPathBlobStorage(): BlobStorage {\n return {\n read(key: string): string | null {\n if (!fs.existsSync(key)) return null;\n try { return fs.readFileSync(key, 'utf-8'); } catch { return null; }\n },\n write(key: string, content: string): void {\n fs.mkdirSync(path.dirname(key), { recursive: true });\n fs.writeFileSync(key, content, 'utf-8');\n },\n };\n}\n\n// ============================================================================\n// blobStorageForRef\n// ============================================================================\n\n/**\n * Resolve a KindValueRef to its BlobStorage backend.\n * Throws a clear error for unrecognised kinds.\n */\nexport function blobStorageForRef(ref: KindValueRef): BlobStorage {\n switch (ref.kind) {\n case 'fs-path': return createFsPathBlobStorage();\n default: throw new Error(`Unsupported storage kind: \"${ref.kind}\". Supported kinds: fs-path`);\n }\n}\n\n// ============================================================================\n// TaskCallback — how a task-executor reports results back to the board\n// ============================================================================\n\n/**\n * Portable invocation descriptor for the board CLI back-channel.\n * Inlined here so this file stays standalone (zero deps on yaml-flow internals).\n * Shape matches ExecutionRef in execution-interface.ts — keep in sync.\n *\n * Supported howToRun values for TaskCallback.via:\n * local-node — invoke board CLI as: node [tsx?] <whatToRun.value> <cmd> [...argv]\n * http:post — POST to <whatToRun.value> with a JSON body\n */\nexport interface ExecutionRef {\n /** Optional human-readable label. Not used for dispatch. */\n meta?: string;\n /** Transport / runtime kind. */\n howToRun: 'local-node' | 'local-python' | 'local-process' | 'http:post' | 'http:get' | 'built-in';\n /** Address of the target in b64:<base64url(json)> wire form. */\n whatToRun: string;\n /** Opaque executor config stored with the ref. */\n extra?: Record<string, unknown>;\n}\n\n/**\n * Describes how the board wants to receive task completion callbacks.\n * Baked into the inRef payload as { source_def, callback }.\n * The executor treats `token` as opaque and passes it back unchanged.\n */\nexport interface TaskCallback {\n /** Opaque routing token — generated by the board, passed back unchanged. */\n token: string;\n /** Delivery mechanism — an ExecutionRef pointing at the board CLI or endpoint. */\n via: ExecutionRef;\n}\n\n/**\n * Extract the path/url value from a whatToRun b64:<base64url(json)> wire string.\n * Falls back to the raw string if it isn’t in b64:<base64url(json)> form.\n */\nfunction _parseWhatToRun(whatToRun: string): string {\n try { return parseRef(whatToRun).value; } catch { return whatToRun; }\n}\n\nfunction _notifyChannelFromVia(via: ExecutionRef): string | undefined {\n const candidate = via.extra?.['notifyChannel'];\n return typeof candidate === 'string' && candidate.length > 0 ? candidate : undefined;\n}\n\n/**\n * Resolve the Node invocation for a local board CLI script.\n * If the path ends in .ts (dev mode), attempts to locate tsx alongside it;\n * otherwise assumes it’s a compiled .js and invokes directly with node.\n */\nfunction _resolveLocalNodeInvocation(scriptPath: string): { cmd: string; args: string[] } {\n if (!scriptPath.endsWith('.ts')) {\n return { cmd: process.execPath, args: [scriptPath] };\n }\n // Dev path: look for tsx in node_modules relative to the script's package root.\n // The .ts file may be at src/cli/node/<file>.ts — walk up until we find node_modules/tsx.\n const dir = path.dirname(scriptPath);\n const candidates: string[] = [];\n for (let up = 1; up <= 5; up++) {\n const base = path.join(dir, ...Array(up).fill('..'), 'node_modules');\n candidates.push(path.join(base, 'tsx', 'dist', 'cli.mjs'));\n candidates.push(path.join(base, '.bin', 'tsx'));\n }\n const tsx = candidates.find(p => fs.existsSync(p));\n if (tsx) return { cmd: process.execPath, args: [tsx, scriptPath] };\n return { cmd: 'npx', args: ['tsx', scriptPath] };\n}\n\n/**\n * Report successful task completion back to the board.\n * Call this from a task-executor after writing the result to outRef.\n */\nexport function reportComplete(callback: TaskCallback, outRef: KindValueRef): void {\n const { token, via } = callback;\n if (via.howToRun === 'local-node' || via.howToRun === 'local-process') {\n const scriptPath = _parseWhatToRun(via.whatToRun);\n const { cmd, args } = _resolveLocalNodeInvocation(scriptPath);\n const notifyChannel = _notifyChannelFromVia(via);\n const callbackArgs = [\n ...args,\n 'source-data-fetched',\n '--ref', serializeRef(outRef),\n '--token', token,\n ...(notifyChannel ? ['--notify-channel', notifyChannel] : []),\n ];\n const result = spawnSync(cmd, callbackArgs, { encoding: 'utf-8', windowsHide: true });\n if (result.status !== 0) {\n throw new Error(`reportComplete: board CLI exited ${result.status}: ${result.stderr?.trim()}`);\n }\n return;\n }\n if (via.howToRun === 'http:post') {\n const url = _parseWhatToRun(via.whatToRun);\n const body = JSON.stringify({ status: 'complete', ref: serializeRef(outRef), token });\n _httpPostSync(url, body);\n return;\n }\n throw new Error(`reportComplete: unsupported via.howToRun \"${via.howToRun}\"`);\n}\n\n/**\n * Report task failure back to the board.\n * Call this from a task-executor instead of writing to outRef.\n */\nexport function reportFailed(callback: TaskCallback, reason: string): void {\n const { token, via } = callback;\n if (via.howToRun === 'local-node' || via.howToRun === 'local-process') {\n const scriptPath = _parseWhatToRun(via.whatToRun);\n const { cmd, args } = _resolveLocalNodeInvocation(scriptPath);\n const notifyChannel = _notifyChannelFromVia(via);\n const callbackArgs = [\n ...args,\n 'source-data-fetch-failure',\n '--token', token,\n '--reason', reason,\n ...(notifyChannel ? ['--notify-channel', notifyChannel] : []),\n ];\n const result = spawnSync(cmd, callbackArgs, { encoding: 'utf-8', windowsHide: true });\n if (result.status !== 0) {\n throw new Error(`reportFailed: board CLI exited ${result.status}: ${result.stderr?.trim()}`);\n }\n return;\n }\n if (via.howToRun === 'http:post') {\n const url = _parseWhatToRun(via.whatToRun);\n const body = JSON.stringify({ status: 'failed', reason, token });\n _httpPostSync(url, body);\n return;\n }\n throw new Error(`reportFailed: unsupported via.howToRun \"${via.howToRun}\"`);\n}\n\n/** Synchronous HTTP POST using a child node process (keeps this file free of async). */\nfunction _httpPostSync(url: string, body: string): void {\n const script = `\n const {request} = require(new URL('${url}').protocol === 'https:' ? 'https' : 'http');\n const h = ${JSON.stringify({ 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) })};\n const u = new URL('${url}');\n const req = request({hostname:u.hostname,port:u.port,path:u.pathname+u.search,method:'POST',headers:h});\n req.on('error', e => { process.stderr.write(e.message); process.exit(1); });\n req.write(${JSON.stringify(body)});\n req.end();\n `;\n const result = spawnSync(process.execPath, ['-e', script], { encoding: 'utf-8', windowsHide: true });\n if (result.status !== 0) throw new Error(`http-post failed: ${result.stderr?.trim()}`);\n}\n"]}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * public-storage-adapter.ts
3
+ *
4
+ * Standalone file — copy this to your task-executor project.
5
+ * Zero dependencies on the rest of yaml-flow.
6
+ *
7
+ * Provides:
8
+ * - KindValueRef wire format: b64:<base64url(json)>
9
+ * - parseRef() parse a b64:<base64url(json)> string
10
+ * - serializeRef() produce a b64:<base64url(json)> string
11
+ * - BlobStorage read/write interface
12
+ * - blobStorageForRef resolve a ref to its BlobStorage backend
13
+ * - ExecutionRef portable invocation descriptor (inlined, stays standalone)
14
+ * - TaskCallback how to report task completion back to the board
15
+ * - reportComplete() call from executor on success
16
+ * - reportFailed() call from executor on failure
17
+ *
18
+ * Supported storage kinds:
19
+ * fs-path — ref.value is an absolute file path; reads/writes via node:fs
20
+ *
21
+ * Supported callback transports (via ExecutionRef.howToRun):
22
+ * local-node — invoke board CLI as a child Node process
23
+ * http:post — HTTP POST to a board endpoint
24
+ *
25
+ * Usage:
26
+ * import { parseRef, blobStorageForRef, reportComplete, reportFailed } from './public-storage-adapter.js';
27
+ *
28
+ * const { source_def, callback } = JSON.parse(blobStorageForRef(inRef).read(inRef.value));
29
+ * // ... do work, write to outRef ...
30
+ * reportComplete(callback, outRef);
31
+ */
32
+ interface KindValueRef {
33
+ readonly kind: string;
34
+ readonly value: string;
35
+ }
36
+ /** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef.
37
+ * Also accepts the legacy ::fs-path::<path> format for backward compatibility. */
38
+ declare function parseRef(s: string): KindValueRef;
39
+ /** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */
40
+ declare function serializeRef(ref: KindValueRef): string;
41
+ interface BlobStorage {
42
+ /** Returns content string, or null if not found. */
43
+ read(key: string): string | null;
44
+ /** Write content at key. */
45
+ write(key: string, content: string): void;
46
+ }
47
+ /**
48
+ * Resolve a KindValueRef to its BlobStorage backend.
49
+ * Throws a clear error for unrecognised kinds.
50
+ */
51
+ declare function blobStorageForRef(ref: KindValueRef): BlobStorage;
52
+ /**
53
+ * Portable invocation descriptor for the board CLI back-channel.
54
+ * Inlined here so this file stays standalone (zero deps on yaml-flow internals).
55
+ * Shape matches ExecutionRef in execution-interface.ts — keep in sync.
56
+ *
57
+ * Supported howToRun values for TaskCallback.via:
58
+ * local-node — invoke board CLI as: node [tsx?] <whatToRun.value> <cmd> [...argv]
59
+ * http:post — POST to <whatToRun.value> with a JSON body
60
+ */
61
+ interface ExecutionRef {
62
+ /** Optional human-readable label. Not used for dispatch. */
63
+ meta?: string;
64
+ /** Transport / runtime kind. */
65
+ howToRun: 'local-node' | 'local-python' | 'local-process' | 'http:post' | 'http:get' | 'built-in';
66
+ /** Address of the target in b64:<base64url(json)> wire form. */
67
+ whatToRun: string;
68
+ /** Opaque executor config stored with the ref. */
69
+ extra?: Record<string, unknown>;
70
+ }
71
+ /**
72
+ * Describes how the board wants to receive task completion callbacks.
73
+ * Baked into the inRef payload as { source_def, callback }.
74
+ * The executor treats `token` as opaque and passes it back unchanged.
75
+ */
76
+ interface TaskCallback {
77
+ /** Opaque routing token — generated by the board, passed back unchanged. */
78
+ token: string;
79
+ /** Delivery mechanism — an ExecutionRef pointing at the board CLI or endpoint. */
80
+ via: ExecutionRef;
81
+ }
82
+ /**
83
+ * Report successful task completion back to the board.
84
+ * Call this from a task-executor after writing the result to outRef.
85
+ */
86
+ declare function reportComplete(callback: TaskCallback, outRef: KindValueRef): void;
87
+ /**
88
+ * Report task failure back to the board.
89
+ * Call this from a task-executor instead of writing to outRef.
90
+ */
91
+ declare function reportFailed(callback: TaskCallback, reason: string): void;
92
+
93
+ export { type BlobStorage, type ExecutionRef, type KindValueRef, type TaskCallback, blobStorageForRef, parseRef, reportComplete, reportFailed, serializeRef };
@@ -0,0 +1,93 @@
1
+ /**
2
+ * public-storage-adapter.ts
3
+ *
4
+ * Standalone file — copy this to your task-executor project.
5
+ * Zero dependencies on the rest of yaml-flow.
6
+ *
7
+ * Provides:
8
+ * - KindValueRef wire format: b64:<base64url(json)>
9
+ * - parseRef() parse a b64:<base64url(json)> string
10
+ * - serializeRef() produce a b64:<base64url(json)> string
11
+ * - BlobStorage read/write interface
12
+ * - blobStorageForRef resolve a ref to its BlobStorage backend
13
+ * - ExecutionRef portable invocation descriptor (inlined, stays standalone)
14
+ * - TaskCallback how to report task completion back to the board
15
+ * - reportComplete() call from executor on success
16
+ * - reportFailed() call from executor on failure
17
+ *
18
+ * Supported storage kinds:
19
+ * fs-path — ref.value is an absolute file path; reads/writes via node:fs
20
+ *
21
+ * Supported callback transports (via ExecutionRef.howToRun):
22
+ * local-node — invoke board CLI as a child Node process
23
+ * http:post — HTTP POST to a board endpoint
24
+ *
25
+ * Usage:
26
+ * import { parseRef, blobStorageForRef, reportComplete, reportFailed } from './public-storage-adapter.js';
27
+ *
28
+ * const { source_def, callback } = JSON.parse(blobStorageForRef(inRef).read(inRef.value));
29
+ * // ... do work, write to outRef ...
30
+ * reportComplete(callback, outRef);
31
+ */
32
+ interface KindValueRef {
33
+ readonly kind: string;
34
+ readonly value: string;
35
+ }
36
+ /** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef.
37
+ * Also accepts the legacy ::fs-path::<path> format for backward compatibility. */
38
+ declare function parseRef(s: string): KindValueRef;
39
+ /** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */
40
+ declare function serializeRef(ref: KindValueRef): string;
41
+ interface BlobStorage {
42
+ /** Returns content string, or null if not found. */
43
+ read(key: string): string | null;
44
+ /** Write content at key. */
45
+ write(key: string, content: string): void;
46
+ }
47
+ /**
48
+ * Resolve a KindValueRef to its BlobStorage backend.
49
+ * Throws a clear error for unrecognised kinds.
50
+ */
51
+ declare function blobStorageForRef(ref: KindValueRef): BlobStorage;
52
+ /**
53
+ * Portable invocation descriptor for the board CLI back-channel.
54
+ * Inlined here so this file stays standalone (zero deps on yaml-flow internals).
55
+ * Shape matches ExecutionRef in execution-interface.ts — keep in sync.
56
+ *
57
+ * Supported howToRun values for TaskCallback.via:
58
+ * local-node — invoke board CLI as: node [tsx?] <whatToRun.value> <cmd> [...argv]
59
+ * http:post — POST to <whatToRun.value> with a JSON body
60
+ */
61
+ interface ExecutionRef {
62
+ /** Optional human-readable label. Not used for dispatch. */
63
+ meta?: string;
64
+ /** Transport / runtime kind. */
65
+ howToRun: 'local-node' | 'local-python' | 'local-process' | 'http:post' | 'http:get' | 'built-in';
66
+ /** Address of the target in b64:<base64url(json)> wire form. */
67
+ whatToRun: string;
68
+ /** Opaque executor config stored with the ref. */
69
+ extra?: Record<string, unknown>;
70
+ }
71
+ /**
72
+ * Describes how the board wants to receive task completion callbacks.
73
+ * Baked into the inRef payload as { source_def, callback }.
74
+ * The executor treats `token` as opaque and passes it back unchanged.
75
+ */
76
+ interface TaskCallback {
77
+ /** Opaque routing token — generated by the board, passed back unchanged. */
78
+ token: string;
79
+ /** Delivery mechanism — an ExecutionRef pointing at the board CLI or endpoint. */
80
+ via: ExecutionRef;
81
+ }
82
+ /**
83
+ * Report successful task completion back to the board.
84
+ * Call this from a task-executor after writing the result to outRef.
85
+ */
86
+ declare function reportComplete(callback: TaskCallback, outRef: KindValueRef): void;
87
+ /**
88
+ * Report task failure back to the board.
89
+ * Call this from a task-executor instead of writing to outRef.
90
+ */
91
+ declare function reportFailed(callback: TaskCallback, reason: string): void;
92
+
93
+ export { type BlobStorage, type ExecutionRef, type KindValueRef, type TaskCallback, blobStorageForRef, parseRef, reportComplete, reportFailed, serializeRef };
@@ -0,0 +1,10 @@
1
+ import*as i from'fs';import*as c from'path';import {spawnSync}from'child_process';function y(t){if(t.startsWith("::fs-path::"))return {kind:"fs-path",value:t.slice(11)};if(!t.startsWith("b64:"))throw new Error(`Invalid ref format (expected b64:<base64url(json)>): ${t}`);let n=t.slice(4),o=n.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-n.length%4)%4),e;try{e=JSON.parse(Buffer.from(o,"base64").toString("utf8"));}catch{throw new Error(`Invalid ref format (malformed base64url/json): ${t}`)}if(!e||typeof e!="object")throw new Error(`Invalid ref format (expected object payload): ${t}`);let r=e;if(typeof r.kind!="string"||typeof r.value!="string")throw new Error(`Invalid ref format (payload must contain string kind/value): ${t}`);return {kind:r.kind,value:r.value}}function h(t){return `b64:${Buffer.from(JSON.stringify(t),"utf8").toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}`}function k(){return {read(t){if(!i.existsSync(t))return null;try{return i.readFileSync(t,"utf-8")}catch{return null}},write(t,n){i.mkdirSync(c.dirname(t),{recursive:true}),i.writeFileSync(t,n,"utf-8");}}}function R(t){if(t.kind==="fs-path")return k();throw new Error(`Unsupported storage kind: "${t.kind}". Supported kinds: fs-path`)}function l(t){try{return y(t).value}catch{return t}}function g(t){let n=t.extra?.notifyChannel;return typeof n=="string"&&n.length>0?n:void 0}function w(t){if(!t.endsWith(".ts"))return {cmd:process.execPath,args:[t]};let n=c.dirname(t),o=[];for(let r=1;r<=5;r++){let s=c.join(n,...Array(r).fill(".."),"node_modules");o.push(c.join(s,"tsx","dist","cli.mjs")),o.push(c.join(s,".bin","tsx"));}let e=o.find(r=>i.existsSync(r));return e?{cmd:process.execPath,args:[e,t]}:{cmd:"npx",args:["tsx",t]}}function b(t,n){let{token:o,via:e}=t;if(e.howToRun==="local-node"||e.howToRun==="local-process"){let r=l(e.whatToRun),{cmd:s,args:d}=w(r),u=g(e),f=[...d,"source-data-fetched","--ref",h(n),"--token",o,...u?["--notify-channel",u]:[]],a=spawnSync(s,f,{encoding:"utf-8",windowsHide:true});if(a.status!==0)throw new Error(`reportComplete: board CLI exited ${a.status}: ${a.stderr?.trim()}`);return}if(e.howToRun==="http:post"){let r=l(e.whatToRun),s=JSON.stringify({status:"complete",ref:h(n),token:o});m(r,s);return}throw new Error(`reportComplete: unsupported via.howToRun "${e.howToRun}"`)}function v(t,n){let{token:o,via:e}=t;if(e.howToRun==="local-node"||e.howToRun==="local-process"){let r=l(e.whatToRun),{cmd:s,args:d}=w(r),u=g(e),f=[...d,"source-data-fetch-failure","--token",o,"--reason",n,...u?["--notify-channel",u]:[]],a=spawnSync(s,f,{encoding:"utf-8",windowsHide:true});if(a.status!==0)throw new Error(`reportFailed: board CLI exited ${a.status}: ${a.stderr?.trim()}`);return}if(e.howToRun==="http:post"){let r=l(e.whatToRun),s=JSON.stringify({status:"failed",reason:n,token:o});m(r,s);return}throw new Error(`reportFailed: unsupported via.howToRun "${e.howToRun}"`)}function m(t,n){let o=`
2
+ const {request} = require(new URL('${t}').protocol === 'https:' ? 'https' : 'http');
3
+ const h = ${JSON.stringify({"Content-Type":"application/json","Content-Length":Buffer.byteLength(n)})};
4
+ const u = new URL('${t}');
5
+ const req = request({hostname:u.hostname,port:u.port,path:u.pathname+u.search,method:'POST',headers:h});
6
+ req.on('error', e => { process.stderr.write(e.message); process.exit(1); });
7
+ req.write(${JSON.stringify(n)});
8
+ req.end();
9
+ `,e=spawnSync(process.execPath,["-e",o],{encoding:"utf-8",windowsHide:true});if(e.status!==0)throw new Error(`http-post failed: ${e.stderr?.trim()}`)}export{R as blobStorageForRef,y as parseRef,b as reportComplete,v as reportFailed,h as serializeRef};//# sourceMappingURL=storage-refs.js.map
10
+ //# sourceMappingURL=storage-refs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli/node/public-storage-adapter.ts"],"names":["parseRef","s","payload","padded","decoded","candidate","serializeRef","ref","createFsPathBlobStorage","key","content","blobStorageForRef","_parseWhatToRun","whatToRun","_notifyChannelFromVia","via","_resolveLocalNodeInvocation","scriptPath","dir","candidates","up","base","tsx","p","reportComplete","callback","outRef","token","cmd","args","notifyChannel","callbackArgs","result","spawnSync","url","body","_httpPostSync","reportFailed","reason","script"],"mappings":"kFA+CO,SAASA,CAAAA,CAASC,CAAAA,CAAyB,CAEhD,GAAIA,EAAE,UAAA,CAAW,aAAa,CAAA,CAC5B,OA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AAA,EAGZ,IAAA,CAAK,SAAA,CAAUC,CAAI,CAAC,CAAA;AAAA;AAAA,EAAA,CAAA,CAG5BH,CAAAA,CAASC,SAAAA,CAAU,OAAA,CAAQ,QAAA,CAAU,CAAC,IAAA,CAAMM,CAAM,CAAA,CAAG,CAAE,QAAA,CAAU,OAAA,CAAS,WAAA,CAAa,IAAK,CAAC,CAAA,CACnG,GAAIP,CAAAA,CAAO,MAAA,GAAW,CAAA,CAAG,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqBA,CAAAA,CAAO,MAAA,EAAQ,IAAA,EAAM,CAAA,CAAE,CACvF","file":"storage-refs.js","sourcesContent":["/**\n * public-storage-adapter.ts\n *\n * Standalone file — copy this to your task-executor project.\n * Zero dependencies on the rest of yaml-flow.\n *\n * Provides:\n * - KindValueRef wire format: b64:<base64url(json)>\n * - parseRef() parse a b64:<base64url(json)> string\n * - serializeRef() produce a b64:<base64url(json)> string\n * - BlobStorage read/write interface\n * - blobStorageForRef resolve a ref to its BlobStorage backend\n * - ExecutionRef portable invocation descriptor (inlined, stays standalone)\n * - TaskCallback how to report task completion back to the board\n * - reportComplete() call from executor on success\n * - reportFailed() call from executor on failure\n *\n * Supported storage kinds:\n * fs-path — ref.value is an absolute file path; reads/writes via node:fs\n *\n * Supported callback transports (via ExecutionRef.howToRun):\n * local-node — invoke board CLI as a child Node process\n * http:post — HTTP POST to a board endpoint\n *\n * Usage:\n * import { parseRef, blobStorageForRef, reportComplete, reportFailed } from './public-storage-adapter.js';\n *\n * const { source_def, callback } = JSON.parse(blobStorageForRef(inRef).read(inRef.value));\n * // ... do work, write to outRef ...\n * reportComplete(callback, outRef);\n */\n\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { spawnSync } from 'node:child_process';\n\n// ============================================================================\n// KindValueRef\n// ============================================================================\n\nexport interface KindValueRef {\n readonly kind: string;\n readonly value: string;\n}\n\n/** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef.\n * Also accepts the legacy ::fs-path::<path> format for backward compatibility. */\nexport function parseRef(s: string): KindValueRef {\n // Legacy format: ::fs-path::<path>\n if (s.startsWith('::fs-path::')) {\n return { kind: 'fs-path', value: s.slice('::fs-path::'.length) };\n }\n if (!s.startsWith('b64:')) throw new Error(`Invalid ref format (expected b64:<base64url(json)>): ${s}`);\n const payload = s.slice(4);\n const padded = payload.replace(/-/g, '+').replace(/_/g, '/') + '='.repeat((4 - (payload.length % 4)) % 4);\n let decoded: unknown;\n try {\n decoded = JSON.parse(Buffer.from(padded, 'base64').toString('utf8'));\n } catch {\n throw new Error(`Invalid ref format (malformed base64url/json): ${s}`);\n }\n if (!decoded || typeof decoded !== 'object') {\n throw new Error(`Invalid ref format (expected object payload): ${s}`);\n }\n const candidate = decoded as { kind?: unknown; value?: unknown };\n if (typeof candidate.kind !== 'string' || typeof candidate.value !== 'string') {\n throw new Error(`Invalid ref format (payload must contain string kind/value): ${s}`);\n }\n return { kind: candidate.kind, value: candidate.value };\n}\n\n/** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */\nexport function serializeRef(ref: KindValueRef): string {\n return `b64:${Buffer.from(JSON.stringify(ref), 'utf8').toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/g, '')}`;\n}\n\n// ============================================================================\n// BlobStorage\n// ============================================================================\n\nexport interface BlobStorage {\n /** Returns content string, or null if not found. */\n read(key: string): string | null;\n /** Write content at key. */\n write(key: string, content: string): void;\n}\n\n// ============================================================================\n// fs-path backend — key IS the absolute file path\n// ============================================================================\n\nfunction createFsPathBlobStorage(): BlobStorage {\n return {\n read(key: string): string | null {\n if (!fs.existsSync(key)) return null;\n try { return fs.readFileSync(key, 'utf-8'); } catch { return null; }\n },\n write(key: string, content: string): void {\n fs.mkdirSync(path.dirname(key), { recursive: true });\n fs.writeFileSync(key, content, 'utf-8');\n },\n };\n}\n\n// ============================================================================\n// blobStorageForRef\n// ============================================================================\n\n/**\n * Resolve a KindValueRef to its BlobStorage backend.\n * Throws a clear error for unrecognised kinds.\n */\nexport function blobStorageForRef(ref: KindValueRef): BlobStorage {\n switch (ref.kind) {\n case 'fs-path': return createFsPathBlobStorage();\n default: throw new Error(`Unsupported storage kind: \"${ref.kind}\". Supported kinds: fs-path`);\n }\n}\n\n// ============================================================================\n// TaskCallback — how a task-executor reports results back to the board\n// ============================================================================\n\n/**\n * Portable invocation descriptor for the board CLI back-channel.\n * Inlined here so this file stays standalone (zero deps on yaml-flow internals).\n * Shape matches ExecutionRef in execution-interface.ts — keep in sync.\n *\n * Supported howToRun values for TaskCallback.via:\n * local-node — invoke board CLI as: node [tsx?] <whatToRun.value> <cmd> [...argv]\n * http:post — POST to <whatToRun.value> with a JSON body\n */\nexport interface ExecutionRef {\n /** Optional human-readable label. Not used for dispatch. */\n meta?: string;\n /** Transport / runtime kind. */\n howToRun: 'local-node' | 'local-python' | 'local-process' | 'http:post' | 'http:get' | 'built-in';\n /** Address of the target in b64:<base64url(json)> wire form. */\n whatToRun: string;\n /** Opaque executor config stored with the ref. */\n extra?: Record<string, unknown>;\n}\n\n/**\n * Describes how the board wants to receive task completion callbacks.\n * Baked into the inRef payload as { source_def, callback }.\n * The executor treats `token` as opaque and passes it back unchanged.\n */\nexport interface TaskCallback {\n /** Opaque routing token — generated by the board, passed back unchanged. */\n token: string;\n /** Delivery mechanism — an ExecutionRef pointing at the board CLI or endpoint. */\n via: ExecutionRef;\n}\n\n/**\n * Extract the path/url value from a whatToRun b64:<base64url(json)> wire string.\n * Falls back to the raw string if it isn’t in b64:<base64url(json)> form.\n */\nfunction _parseWhatToRun(whatToRun: string): string {\n try { return parseRef(whatToRun).value; } catch { return whatToRun; }\n}\n\nfunction _notifyChannelFromVia(via: ExecutionRef): string | undefined {\n const candidate = via.extra?.['notifyChannel'];\n return typeof candidate === 'string' && candidate.length > 0 ? candidate : undefined;\n}\n\n/**\n * Resolve the Node invocation for a local board CLI script.\n * If the path ends in .ts (dev mode), attempts to locate tsx alongside it;\n * otherwise assumes it’s a compiled .js and invokes directly with node.\n */\nfunction _resolveLocalNodeInvocation(scriptPath: string): { cmd: string; args: string[] } {\n if (!scriptPath.endsWith('.ts')) {\n return { cmd: process.execPath, args: [scriptPath] };\n }\n // Dev path: look for tsx in node_modules relative to the script's package root.\n // The .ts file may be at src/cli/node/<file>.ts — walk up until we find node_modules/tsx.\n const dir = path.dirname(scriptPath);\n const candidates: string[] = [];\n for (let up = 1; up <= 5; up++) {\n const base = path.join(dir, ...Array(up).fill('..'), 'node_modules');\n candidates.push(path.join(base, 'tsx', 'dist', 'cli.mjs'));\n candidates.push(path.join(base, '.bin', 'tsx'));\n }\n const tsx = candidates.find(p => fs.existsSync(p));\n if (tsx) return { cmd: process.execPath, args: [tsx, scriptPath] };\n return { cmd: 'npx', args: ['tsx', scriptPath] };\n}\n\n/**\n * Report successful task completion back to the board.\n * Call this from a task-executor after writing the result to outRef.\n */\nexport function reportComplete(callback: TaskCallback, outRef: KindValueRef): void {\n const { token, via } = callback;\n if (via.howToRun === 'local-node' || via.howToRun === 'local-process') {\n const scriptPath = _parseWhatToRun(via.whatToRun);\n const { cmd, args } = _resolveLocalNodeInvocation(scriptPath);\n const notifyChannel = _notifyChannelFromVia(via);\n const callbackArgs = [\n ...args,\n 'source-data-fetched',\n '--ref', serializeRef(outRef),\n '--token', token,\n ...(notifyChannel ? ['--notify-channel', notifyChannel] : []),\n ];\n const result = spawnSync(cmd, callbackArgs, { encoding: 'utf-8', windowsHide: true });\n if (result.status !== 0) {\n throw new Error(`reportComplete: board CLI exited ${result.status}: ${result.stderr?.trim()}`);\n }\n return;\n }\n if (via.howToRun === 'http:post') {\n const url = _parseWhatToRun(via.whatToRun);\n const body = JSON.stringify({ status: 'complete', ref: serializeRef(outRef), token });\n _httpPostSync(url, body);\n return;\n }\n throw new Error(`reportComplete: unsupported via.howToRun \"${via.howToRun}\"`);\n}\n\n/**\n * Report task failure back to the board.\n * Call this from a task-executor instead of writing to outRef.\n */\nexport function reportFailed(callback: TaskCallback, reason: string): void {\n const { token, via } = callback;\n if (via.howToRun === 'local-node' || via.howToRun === 'local-process') {\n const scriptPath = _parseWhatToRun(via.whatToRun);\n const { cmd, args } = _resolveLocalNodeInvocation(scriptPath);\n const notifyChannel = _notifyChannelFromVia(via);\n const callbackArgs = [\n ...args,\n 'source-data-fetch-failure',\n '--token', token,\n '--reason', reason,\n ...(notifyChannel ? ['--notify-channel', notifyChannel] : []),\n ];\n const result = spawnSync(cmd, callbackArgs, { encoding: 'utf-8', windowsHide: true });\n if (result.status !== 0) {\n throw new Error(`reportFailed: board CLI exited ${result.status}: ${result.stderr?.trim()}`);\n }\n return;\n }\n if (via.howToRun === 'http:post') {\n const url = _parseWhatToRun(via.whatToRun);\n const body = JSON.stringify({ status: 'failed', reason, token });\n _httpPostSync(url, body);\n return;\n }\n throw new Error(`reportFailed: unsupported via.howToRun \"${via.howToRun}\"`);\n}\n\n/** Synchronous HTTP POST using a child node process (keeps this file free of async). */\nfunction _httpPostSync(url: string, body: string): void {\n const script = `\n const {request} = require(new URL('${url}').protocol === 'https:' ? 'https' : 'http');\n const h = ${JSON.stringify({ 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) })};\n const u = new URL('${url}');\n const req = request({hostname:u.hostname,port:u.port,path:u.pathname+u.search,method:'POST',headers:h});\n req.on('error', e => { process.stderr.write(e.message); process.exit(1); });\n req.write(${JSON.stringify(body)});\n req.end();\n `;\n const result = spawnSync(process.execPath, ['-e', script], { encoding: 'utf-8', windowsHide: true });\n if (result.status !== 0) throw new Error(`http-post failed: ${result.stderr?.trim()}`);\n}\n"]}
@@ -1,115 +1,2 @@
1
- 'use strict';
2
-
3
- // src/stores/file.ts
4
- var FileStore = class {
5
- directory;
6
- fs = null;
7
- path = null;
8
- constructor(options) {
9
- this.directory = options.directory;
10
- }
11
- async ensureModules() {
12
- if (!this.fs || !this.path) {
13
- this.fs = await import('fs/promises');
14
- this.path = await import('path');
15
- await this.fs.mkdir(this.directory, { recursive: true });
16
- }
17
- }
18
- runPath(runId) {
19
- return this.path.join(this.directory, `${runId}.run.json`);
20
- }
21
- dataPath(runId) {
22
- return this.path.join(this.directory, `${runId}.data.json`);
23
- }
24
- async saveRunState(runId, state) {
25
- await this.ensureModules();
26
- await this.fs.writeFile(
27
- this.runPath(runId),
28
- JSON.stringify(state, null, 2),
29
- "utf-8"
30
- );
31
- }
32
- async loadRunState(runId) {
33
- await this.ensureModules();
34
- try {
35
- const raw = await this.fs.readFile(this.runPath(runId), "utf-8");
36
- return JSON.parse(raw);
37
- } catch (err) {
38
- if (err.code === "ENOENT") {
39
- return null;
40
- }
41
- throw err;
42
- }
43
- }
44
- async deleteRunState(runId) {
45
- await this.ensureModules();
46
- try {
47
- await this.fs.unlink(this.runPath(runId));
48
- } catch (err) {
49
- if (err.code !== "ENOENT") throw err;
50
- }
51
- try {
52
- await this.fs.unlink(this.dataPath(runId));
53
- } catch (err) {
54
- if (err.code !== "ENOENT") throw err;
55
- }
56
- }
57
- async setData(runId, key, value) {
58
- await this.ensureModules();
59
- const allData = await this.getAllData(runId);
60
- allData[key] = value;
61
- await this.fs.writeFile(
62
- this.dataPath(runId),
63
- JSON.stringify(allData, null, 2),
64
- "utf-8"
65
- );
66
- }
67
- async getData(runId, key) {
68
- const allData = await this.getAllData(runId);
69
- return allData[key];
70
- }
71
- async getAllData(runId) {
72
- await this.ensureModules();
73
- try {
74
- const raw = await this.fs.readFile(this.dataPath(runId), "utf-8");
75
- return JSON.parse(raw);
76
- } catch (err) {
77
- if (err.code === "ENOENT") {
78
- return {};
79
- }
80
- throw err;
81
- }
82
- }
83
- async clearData(runId) {
84
- await this.ensureModules();
85
- try {
86
- await this.fs.unlink(this.dataPath(runId));
87
- } catch (err) {
88
- if (err.code !== "ENOENT") throw err;
89
- }
90
- }
91
- async listRuns() {
92
- await this.ensureModules();
93
- try {
94
- const files = await this.fs.readdir(this.directory);
95
- return files.filter((f) => f.endsWith(".run.json")).map((f) => f.replace(".run.json", ""));
96
- } catch (err) {
97
- if (err.code === "ENOENT") {
98
- return [];
99
- }
100
- throw err;
101
- }
102
- }
103
- /**
104
- * Clear all flow data from directory
105
- */
106
- async clearAll() {
107
- await this.ensureModules();
108
- const runs = await this.listRuns();
109
- await Promise.all(runs.map((runId) => this.deleteRunState(runId)));
110
- }
111
- };
112
-
113
- exports.FileStore = FileStore;
114
- //# sourceMappingURL=file.cjs.map
1
+ 'use strict';var a=class{directory;fs=null;path=null;constructor(i){this.directory=i.directory;}async ensureModules(){(!this.fs||!this.path)&&(this.fs=await import('fs/promises'),this.path=await import('path'),await this.fs.mkdir(this.directory,{recursive:true}));}runPath(i){return this.path.join(this.directory,`${i}.run.json`)}dataPath(i){return this.path.join(this.directory,`${i}.data.json`)}async saveRunState(i,t){await this.ensureModules(),await this.fs.writeFile(this.runPath(i),JSON.stringify(t,null,2),"utf-8");}async loadRunState(i){await this.ensureModules();try{let t=await this.fs.readFile(this.runPath(i),"utf-8");return JSON.parse(t)}catch(t){if(t.code==="ENOENT")return null;throw t}}async deleteRunState(i){await this.ensureModules();try{await this.fs.unlink(this.runPath(i));}catch(t){if(t.code!=="ENOENT")throw t}try{await this.fs.unlink(this.dataPath(i));}catch(t){if(t.code!=="ENOENT")throw t}}async setData(i,t,r){await this.ensureModules();let e=await this.getAllData(i);e[t]=r,await this.fs.writeFile(this.dataPath(i),JSON.stringify(e,null,2),"utf-8");}async getData(i,t){return (await this.getAllData(i))[t]}async getAllData(i){await this.ensureModules();try{let t=await this.fs.readFile(this.dataPath(i),"utf-8");return JSON.parse(t)}catch(t){if(t.code==="ENOENT")return {};throw t}}async clearData(i){await this.ensureModules();try{await this.fs.unlink(this.dataPath(i));}catch(t){if(t.code!=="ENOENT")throw t}}async listRuns(){await this.ensureModules();try{return (await this.fs.readdir(this.directory)).filter(t=>t.endsWith(".run.json")).map(t=>t.replace(".run.json",""))}catch(i){if(i.code==="ENOENT")return [];throw i}}async clearAll(){await this.ensureModules();let i=await this.listRuns();await Promise.all(i.map(t=>this.de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,SAAS,CAAA;AACnD,MAAA,OAAO,KAAA,CACJ,MAAA,CAAO,CAAA,CAAA,KAAK,CAAA,CAAE,SAAS,WAAW,CAAC,CAAA,CACnC,GAAA,CAAI,CAAA,CAAA,KAAK,CAAA,CAAE,OAAA,CAAQ,WAAA,EAAa,EAAE,CAAC,CAAA;AAAA,IACxC,SAAS,GAAA,EAAc;AACrB,MAAA,IAAK,GAAA,CAA8B,SAAS,QAAA,EAAU;AACpD,QAAA,OAAO,EAAC;AAAA,MACV;AACA,MAAA,MAAM,GAAA;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAA,GAA0B;AAC9B,IAAA,MAAM,KAAK,aAAA,EAAc;AACzB,IAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,QAAA,EAAS;AACjC,IAAA,MAAM,OAAA,CAAQ,IAAI,IAAA,CAAK,GAAA,CAAI,WAAS,IAAA,CAAK,cAAA,CAAe,KAAK,CAAC,CAAC,CAAA;AAAA,EACjE;AACF","file":"file.cjs","sourcesContent":["/**\n * yaml-flow - File Store\n * \n * File-system based store for Node.js environments.\n * Stores each run as a JSON file in the specified directory.\n */\n\nimport type { StepMachineStore, StepMachineState } from '../step-machine/types.js';\n\nexport interface FileStoreOptions {\n /** Directory path for storing flow data */\n directory: string;\n}\n\nexport class FileStore implements StepMachineStore {\n private directory: string;\n private fs: typeof import('fs/promises') | null = null;\n private path: typeof import('path') | null = null;\n\n constructor(options: FileStoreOptions) {\n this.directory = options.directory;\n }\n\n private async ensureModules(): Promise<void> {\n if (!this.fs || !this.path) {\n // Dynamic import for Node.js modules\n this.fs = await import('fs/promises');\n this.path = await import('path');\n \n // Ensure directory exists\n await this.fs.mkdir(this.directory, { recursive: true });\n }\n }\n\n private runPath(runId: string): string {\n return this.path!.join(this.directory, `${runId}.run.json`);\n }\n\n private dataPath(runId: string): string {\n return this.path!.join(this.directory, `${runId}.data.json`);\n }\n\n async saveRunState(runId: string, state: StepMachineState): Promise<void> {\n await this.ensureModules();\n await this.fs!.writeFile(\n this.runPath(runId),\n JSON.stringify(state, null, 2),\n 'utf-8'\n );\n }\n\n async loadRunState(runId: string): Promise<StepMachineState | null> {\n await this.ensureModules();\n try {\n const raw = await this.fs!.readFile(this.runPath(runId), 'utf-8');\n return JSON.parse(raw);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n return null;\n }\n throw err;\n }\n }\n\n async deleteRunState(runId: string): Promise<void> {\n await this.ensureModules();\n try {\n await this.fs!.unlink(this.runPath(runId));\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;\n }\n try {\n await this.fs!.unlink(this.dataPath(runId));\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;\n }\n }\n\n async setData(runId: string, key: string, value: unknown): Promise<void> {\n await this.ensureModules();\n const allData = await this.getAllData(runId);\n allData[key] = value;\n await this.fs!.writeFile(\n this.dataPath(runId),\n JSON.stringify(allData, null, 2),\n 'utf-8'\n );\n }\n\n async getData(runId: string, key: string): Promise<unknown> {\n const allData = await this.getAllData(runId);\n return allData[key];\n }\n\n async getAllData(runId: string): Promise<Record<string, unknown>> {\n await this.ensureModules();\n try {\n const raw = await this.fs!.readFile(this.dataPath(runId), 'utf-8');\n return JSON.parse(raw);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n return {};\n }\n throw err;\n }\n }\n\n async clearData(runId: string): Promise<void> {\n await this.ensureModules();\n try {\n await this.fs!.unlink(this.dataPath(runId));\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;\n }\n }\n\n async listRuns(): Promise<string[]> {\n await this.ensureModules();\n try {\n const files = await this.fs!.readdir(this.directory);\n return files\n .filter(f => f.endsWith('.run.json'))\n .map(f => f.replace('.run.json', ''));\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n return [];\n }\n throw err;\n }\n }\n\n /**\n * Clear all flow data from directory\n */\n async clearAll(): Promise<void> {\n await this.ensureModules();\n const runs = await this.listRuns();\n await Promise.all(runs.map(runId => this.deleteRunState(runId)));\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/stores/file.ts"],"names":["FileStore","options","runId","state","raw","err","key","value","allData","f","runs"],"mappings":"aAcO,IAAMA,CAAAA,CAAN,KAA4C,CACzC,SAAA,CACA,GAA0C,IAAA,CAC1C,IAAA,CAAqC,KAE7C,WAAA,CAAYC,CAAAA,CAA2B,CACrC,IAAA,CAAK,SAAA,CAAYA,EAAQ,UAC3B,CAEA,MAAc,aAAA,EAA+B,CAAA,CACvC,CAAC,IAAA,CAAK,EAAA,EAAM,CAAC,IAAA,CAAK,IAAA,IAEpB,KAAK,EAAA,CAAK,aAAa,aAAa,CAAA,CACpC,KAAK,IAAA,CAAO,aAAa,MAAM,CAAA,CAG/B,MAAM,IAAA,CAAK,EAAA,CAAG,MAAM,IAAA,CAAK,SAAA,CAAW,CAAE,SAAA,CAAW,IAAK,CAAC,GAE3D,CAEQ,OAAA,CAAQC,EAAuB,CACrC,OAAO,KAAK,IAAA,CAAM,IAAA,CAAK,KAAK,SAAA,CAAW,CAAA,EAAGA,CAAK,CAAA,SAAA,CAAW,CAC5D,CAEQ,QAAA,CAASA,CAAAA,CAAuB,CACtC,OAAO,IAAA,CAAK,KAAM,IAAA,CAAK,IAAA,CAAK,UAAW,CAAA,EAAGA,CAAK,YAAY,CAC7D,CAEA,MAAM,YAAA,CAAaA,CAAAA,CAAeC,EAAwC,CACxE,MAAM,KAAK,aAAA,EAAc,CACzB,MAAM,IAAA,CAAK,EAAA,CAAI,UACb,IAAA,CAAK,OAAA,CAAQD,CAAK,CAAA,CAClB,IAAA,CAAK,SAAA,CAAUC,EAAO,IAAA,CAAM,CAAC,EAC7B,OACF,EACF,CAEA,MAAM,YAAA,CAAaD,EAAiD,CAClE,MAAM,KAAK,aAAA,EAAc,CACzB,GAAI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IAAME,CAAAA,CAAM,MAAM,IAAA,CAAK,EAAA,CAAI,SAAS,IAAA,CAAK,QAAA,CAASF,CAAK,CAAA,CAAG,OAAO,EACjE,OAAO,IAAA,CAAK,MAAME,CAAG,CACvB,OAASC,CAAAA,CAAc,CACrB,GAAKA,CAAAA,CAA8B,IAAA,GAAS,SAC1C,OAAO,GAET,MAAMA,CACR,CACF,CAEA,MAAM,SAAA,CAAUH,CAAAA,CAA8B,CAC5C,MAAM,KAAK,aAAA,EAAc,CACzB,GAAI,CACF,MAAM,KAAK,EAAA,CAAI,MAAA,CAAO,KAAK,QAAA,CAASA,CAAK,CAAC,EAC5C,CAAA,MAASG,EAAc,CACrB,GAAKA,EAA8B,IAAA,GAAS,QAAA,CAAU,MAAMA,CAC9D,CACF,CAEA,MAAM,QAAA,EAA8B,CAClC,MAAM,IAAA,CAAK,eAAc,CACzB,GAAI,CAEF,OAAA,CADc,MAAM,KAAK,EAAA,CAAI,OAAA,CAAQ,KAAK,SAAS,CAAA,EAEhD,OAAOI,CAAAA,EAAKA,CAAAA,CAAE,QAAA,CAAS,WAAW,CAAC,CAAA,CACnC,IAAIA,CAAAA,EAAKA,CAAAA,CAAE,QAAQ,WAAA,CAAa,EAAE,CAAC,CACxC,CAAA,MAASJ,EAAc,CACrB,GAAKA,EAA8B,IAAA,GAAS,QAAA,CAC1C,OAAO,EAAC,CAEV,MAAMA,CACR,CACF,CAKA,MAAM,QAAA,EAA0B,CAC9B,MAAM,IAAA,CAAK,eAAc,CACzB,IAAMK,EAAO,MAAM,IAAA,CAAK,UAAS,CACjC,MAAM,QAAQ,GAAA,CAAIA,CAAAA,CAAK,IAAIR,CAAAA,EAAS,IAAA,CAAK,eAAeA,CAAK,CAAC,CAAC,EACjE,CACF","file":"file.cjs","sourcesContent":["/**\n * yaml-flow - File Store\n * \n * File-system based store for Node.js environments.\n * Stores each run as a JSON file in the specified directory.\n */\n\nimport type { StepMachineStore, StepMachineState } from '../step-machine/types.js';\n\nexport interface FileStoreOptions {\n /** Directory path for storing flow data */\n directory: string;\n}\n\nexport class FileStore implements StepMachineStore {\n private directory: string;\n private fs: typeof import('fs/promises') | null = null;\n private path: typeof import('path') | null = null;\n\n constructor(options: FileStoreOptions) {\n this.directory = options.directory;\n }\n\n private async ensureModules(): Promise<void> {\n if (!this.fs || !this.path) {\n // Dynamic import for Node.js modules\n this.fs = await import('fs/promises');\n this.path = await import('path');\n \n // Ensure directory exists\n await this.fs.mkdir(this.directory, { recursive: true });\n }\n }\n\n private runPath(runId: string): string {\n return this.path!.join(this.directory, `${runId}.run.json`);\n }\n\n private dataPath(runId: string): string {\n return this.path!.join(this.directory, `${runId}.data.json`);\n }\n\n async saveRunState(runId: string, state: StepMachineState): Promise<void> {\n await this.ensureModules();\n await this.fs!.writeFile(\n this.runPath(runId),\n JSON.stringify(state, null, 2),\n 'utf-8'\n );\n }\n\n async loadRunState(runId: string): Promise<StepMachineState | null> {\n await this.ensureModules();\n try {\n const raw = await this.fs!.readFile(this.runPath(runId), 'utf-8');\n return JSON.parse(raw);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n return null;\n }\n throw err;\n }\n }\n\n async deleteRunState(runId: string): Promise<void> {\n await this.ensureModules();\n try {\n await this.fs!.unlink(this.runPath(runId));\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;\n }\n try {\n await this.fs!.unlink(this.dataPath(runId));\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;\n }\n }\n\n async setData(runId: string, key: string, value: unknown): Promise<void> {\n await this.ensureModules();\n const allData = await this.getAllData(runId);\n allData[key] = value;\n await this.fs!.writeFile(\n this.dataPath(runId),\n JSON.stringify(allData, null, 2),\n 'utf-8'\n );\n }\n\n async getData(runId: string, key: string): Promise<unknown> {\n const allData = await this.getAllData(runId);\n return allData[key];\n }\n\n async getAllData(runId: string): Promise<Record<string, unknown>> {\n await this.ensureModules();\n try {\n const raw = await this.fs!.readFile(this.dataPath(runId), 'utf-8');\n return JSON.parse(raw);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n return {};\n }\n throw err;\n }\n }\n\n async clearData(runId: string): Promise<void> {\n await this.ensureModules();\n try {\n await this.fs!.unlink(this.dataPath(runId));\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;\n }\n }\n\n async listRuns(): Promise<string[]> {\n await this.ensureModules();\n try {\n const files = await this.fs!.readdir(this.directory);\n return files\n .filter(f => f.endsWith('.run.json'))\n .map(f => f.replace('.run.json', ''));\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n return [];\n }\n throw err;\n }\n }\n\n /**\n * Clear all flow data from directory\n */\n async clearAll(): Promise<void> {\n await this.ensureModules();\n const runs = await this.listRuns();\n await Promise.all(runs.map(runId => this.deleteRunState(runId)));\n }\n}\n"]}
@@ -1,113 +1,2 @@
1
- // src/stores/file.ts
2
- var FileStore = class {
3
- directory;
4
- fs = null;
5
- path = null;
6
- constructor(options) {
7
- this.directory = options.directory;
8
- }
9
- async ensureModules() {
10
- if (!this.fs || !this.path) {
11
- this.fs = await import('fs/promises');
12
- this.path = await import('path');
13
- await this.fs.mkdir(this.directory, { recursive: true });
14
- }
15
- }
16
- runPath(runId) {
17
- return this.path.join(this.directory, `${runId}.run.json`);
18
- }
19
- dataPath(runId) {
20
- return this.path.join(this.directory, `${runId}.data.json`);
21
- }
22
- async saveRunState(runId, state) {
23
- await this.ensureModules();
24
- await this.fs.writeFile(
25
- this.runPath(runId),
26
- JSON.stringify(state, null, 2),
27
- "utf-8"
28
- );
29
- }
30
- async loadRunState(runId) {
31
- await this.ensureModules();
32
- try {
33
- const raw = await this.fs.readFile(this.runPath(runId), "utf-8");
34
- return JSON.parse(raw);
35
- } catch (err) {
36
- if (err.code === "ENOENT") {
37
- return null;
38
- }
39
- throw err;
40
- }
41
- }
42
- async deleteRunState(runId) {
43
- await this.ensureModules();
44
- try {
45
- await this.fs.unlink(this.runPath(runId));
46
- } catch (err) {
47
- if (err.code !== "ENOENT") throw err;
48
- }
49
- try {
50
- await this.fs.unlink(this.dataPath(runId));
51
- } catch (err) {
52
- if (err.code !== "ENOENT") throw err;
53
- }
54
- }
55
- async setData(runId, key, value) {
56
- await this.ensureModules();
57
- const allData = await this.getAllData(runId);
58
- allData[key] = value;
59
- await this.fs.writeFile(
60
- this.dataPath(runId),
61
- JSON.stringify(allData, null, 2),
62
- "utf-8"
63
- );
64
- }
65
- async getData(runId, key) {
66
- const allData = await this.getAllData(runId);
67
- return allData[key];
68
- }
69
- async getAllData(runId) {
70
- await this.ensureModules();
71
- try {
72
- const raw = await this.fs.readFile(this.dataPath(runId), "utf-8");
73
- return JSON.parse(raw);
74
- } catch (err) {
75
- if (err.code === "ENOENT") {
76
- return {};
77
- }
78
- throw err;
79
- }
80
- }
81
- async clearData(runId) {
82
- await this.ensureModules();
83
- try {
84
- await this.fs.unlink(this.dataPath(runId));
85
- } catch (err) {
86
- if (err.code !== "ENOENT") throw err;
87
- }
88
- }
89
- async listRuns() {
90
- await this.ensureModules();
91
- try {
92
- const files = await this.fs.readdir(this.directory);
93
- return files.filter((f) => f.endsWith(".run.json")).map((f) => f.replace(".run.json", ""));
94
- } catch (err) {
95
- if (err.code === "ENOENT") {
96
- return [];
97
- }
98
- throw err;
99
- }
100
- }
101
- /**
102
- * Clear all flow data from directory
103
- */
104
- async clearAll() {
105
- await this.ensureModules();
106
- const runs = await this.listRuns();
107
- await Promise.all(runs.map((runId) => this.deleteRunState(runId)));
108
- }
109
- };
110
-
111
- export { FileStore };
112
- //# sourceMappingURL=file.js.map
1
+ var a=class{directory;fs=null;path=null;constructor(i){this.directory=i.directory;}async ensureModules(){(!this.fs||!this.path)&&(this.fs=await import('fs/promises'),this.path=await import('path'),await this.fs.mkdir(this.directory,{recursive:true}));}runPath(i){return this.path.join(this.directory,`${i}.run.json`)}dataPath(i){return this.path.join(this.directory,`${i}.data.json`)}async saveRunState(i,t){await this.ensureModules(),await this.fs.writeFile(this.runPath(i),JSON.stringify(t,null,2),"utf-8");}async loadRunState(i){await this.ensureModules();try{let t=await this.fs.readFile(this.runPath(i),"utf-8");return JSON.parse(t)}catch(t){if(t.code==="ENOENT")return null;throw t}}async deleteRunState(i){await this.ensureModules();try{await this.fs.unlink(this.runPath(i));}catch(t){if(t.code!=="ENOENT")throw t}try{await this.fs.unlink(this.dataPath(i));}catch(t){if(t.code!=="ENOENT")throw t}}async setData(i,t,r){await this.ensureModules();let e=await this.getAllData(i);e[t]=r,await this.fs.writeFile(this.dataPath(i),JSON.stringify(e,null,2),"utf-8");}async getData(i,t){return (await this.getAllData(i))[t]}async getAllData(i){await this.ensureModules();try{let t=await this.fs.readFile(this.dataPath(i),"utf-8");return JSON.parse(t)}catch(t){if(t.code==="ENOENT")return {};throw t}}async clearData(i){await this.ensureModules();try{await this.fs.unlink(this.dataPath(i));}catch(t){if(t.code!=="ENOENT")throw t}}async listRuns(){await this.ensureModules();try{return (await this.fs.readdir(this.directory)).filter(t=>t.endsWith(".run.json")).map(t=>t.replace(".run.json",""))}catch(i){if(i.code==="ENOENT")return [];throw i}}async clearAll(){await this.ensureModules();let i=await this.listRuns();await Promise.all(i.map(t=>this.deleteRunState(t)));}};export{a as FileStore};//# sourceMappingURL=file.js.map
113
2
  //# sourceMappingURL=file.js.map