yaml-flow 6.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/board-live-cards-cli.js +4 -4
- package/browser/asset-integrity.json +3 -3
- package/browser/board-livecards-client.js +2 -0
- package/browser/board-livecards-client.js.map +1 -0
- package/browser/board-livecards-localstorage.js +10 -0
- package/browser/board-livecards-localstorage.js.map +1 -0
- package/browser/board-livegraph-engine.js +2 -2
- package/browser/board-livegraph-engine.js.map +1 -1
- package/browser/card-compute.js +28 -28
- package/browser/compute-jsonata.js +5 -0
- package/browser/compute-jsonata.js.map +1 -0
- package/browser/live-cards.js +264 -151
- package/card-store.js +4 -4
- package/dist/{board-live-cards-public-CltXYgaY.d.cts → board-live-cards-public-5n1-syA3.d.cts} +8 -5
- package/dist/{board-live-cards-public-f-E-FAyp.d.ts → board-live-cards-public-CK_J8uv0.d.ts} +8 -5
- package/dist/board-livegraph-runtime/index.cjs +2 -2
- package/dist/board-livegraph-runtime/index.cjs.map +1 -1
- package/dist/board-livegraph-runtime/index.d.cts +11 -9
- package/dist/board-livegraph-runtime/index.d.ts +11 -9
- package/dist/board-livegraph-runtime/index.js +2 -2
- package/dist/board-livegraph-runtime/index.js.map +1 -1
- package/dist/board-livegraph-runtime/jsonata-sync.cjs +37 -1
- package/dist/card-compute/index.cjs +4 -4
- package/dist/card-compute/index.cjs.map +1 -1
- package/dist/card-compute/index.d.cts +5 -1
- package/dist/card-compute/index.d.ts +5 -1
- package/dist/card-compute/index.js +4 -4
- package/dist/card-compute/index.js.map +1 -1
- package/dist/card-compute/jsonata-sync.cjs +37 -1
- package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs +2 -1
- package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs.map +1 -1
- package/dist/cli/browser-api/board-live-cards-browser-adapter.d.cts +27 -14
- package/dist/cli/browser-api/board-live-cards-browser-adapter.d.ts +27 -14
- package/dist/cli/browser-api/board-live-cards-browser-adapter.js +2 -1
- package/dist/cli/browser-api/board-live-cards-browser-adapter.js.map +1 -1
- package/dist/cli/browser-api/card-store-browser-api.cjs +1 -1
- package/dist/cli/browser-api/card-store-browser-api.cjs.map +1 -1
- package/dist/cli/browser-api/card-store-browser-api.js +1 -1
- package/dist/cli/browser-api/card-store-browser-api.js.map +1 -1
- package/dist/cli/browser-api/jsonata-sync.cjs +37 -1
- package/dist/cli/node/artifacts-store-cli.cjs +8 -8
- package/dist/cli/node/artifacts-store-cli.cjs.map +1 -1
- package/dist/cli/node/artifacts-store-cli.js +8 -8
- package/dist/cli/node/artifacts-store-cli.js.map +1 -1
- package/dist/cli/node/board-live-cards-cli.cjs +7 -7
- package/dist/cli/node/board-live-cards-cli.cjs.map +1 -1
- package/dist/cli/node/board-live-cards-cli.js +7 -7
- package/dist/cli/node/board-live-cards-cli.js.map +1 -1
- package/dist/cli/node/card-store-cli.cjs +5 -5
- package/dist/cli/node/card-store-cli.cjs.map +1 -1
- package/dist/cli/node/card-store-cli.js +5 -5
- package/dist/cli/node/card-store-cli.js.map +1 -1
- package/dist/cli/node/execution-adapter.cjs +3 -0
- package/dist/cli/node/execution-adapter.cjs.map +1 -0
- package/dist/cli/node/execution-adapter.d.cts +174 -0
- package/dist/cli/node/execution-adapter.d.ts +174 -0
- package/dist/cli/node/execution-adapter.js +3 -0
- package/dist/cli/node/execution-adapter.js.map +1 -0
- package/dist/cli/node/fs-board-adapter.cjs +7 -7
- package/dist/cli/node/fs-board-adapter.cjs.map +1 -1
- package/dist/cli/node/fs-board-adapter.d.cts +2 -2
- package/dist/cli/node/fs-board-adapter.d.ts +2 -2
- package/dist/cli/node/fs-board-adapter.js +7 -7
- package/dist/cli/node/fs-board-adapter.js.map +1 -1
- package/dist/cli/node/jsonata-sync.cjs +37 -1
- package/dist/cli/node/source-cli-task-executor.cjs +4 -4
- package/dist/cli/node/source-cli-task-executor.cjs.map +1 -1
- package/dist/cli/node/source-cli-task-executor.js +4 -4
- package/dist/cli/node/source-cli-task-executor.js.map +1 -1
- package/dist/continuous-event-graph/index.cjs +2 -2
- package/dist/continuous-event-graph/index.cjs.map +1 -1
- package/dist/continuous-event-graph/index.js +2 -2
- package/dist/continuous-event-graph/index.js.map +1 -1
- package/dist/continuous-event-graph/jsonata-sync.cjs +37 -1
- package/dist/execution-refs.cjs +2 -1
- package/dist/execution-refs.cjs.map +1 -1
- package/dist/execution-refs.d.cts +55 -12
- package/dist/execution-refs.d.ts +55 -12
- package/dist/execution-refs.js +2 -1
- package/dist/execution-refs.js.map +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/jsonata-sync.cjs +37 -1
- package/dist/server-runtime/index.cjs +9 -0
- package/dist/server-runtime/index.cjs.map +1 -0
- package/dist/server-runtime/index.d.cts +31 -0
- package/dist/server-runtime/index.d.ts +31 -0
- package/dist/server-runtime/index.js +9 -0
- package/dist/server-runtime/index.js.map +1 -0
- package/dist/server-runtime/jsonata-sync.cjs +7623 -0
- package/dist/step-machine-public/index.cjs +3 -0
- package/dist/step-machine-public/index.cjs.map +1 -0
- package/dist/step-machine-public/index.d.cts +166 -0
- package/dist/step-machine-public/index.d.ts +166 -0
- package/dist/step-machine-public/index.js +3 -0
- package/dist/step-machine-public/index.js.map +1 -0
- package/dist/step-machine-public/jsonata-sync.cjs +7623 -0
- package/dist/storage-refs.cjs +2 -2
- package/dist/storage-refs.cjs.map +1 -1
- package/dist/storage-refs.d.cts +6 -6
- package/dist/storage-refs.d.ts +6 -6
- package/dist/storage-refs.js +2 -2
- package/dist/storage-refs.js.map +1 -1
- package/dist/types-CU3DjTKL.d.cts +147 -0
- package/dist/types-HGDTWIun.d.ts +147 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-t4.js +9 -10
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-http-test.js +370 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-http-test.py +398 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-public.js +9 -10
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-server.js +300 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-server.py +617 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-sse-worker.js +48 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker.py +11 -10
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +19 -4
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +4 -8
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +6 -10
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/poll-status-cli.js +8 -16
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +2 -6
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +4 -8
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/status-cli.js +3 -7
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +4 -8
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +7 -16
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +2 -6
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/_board_pycli.py +13 -3
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/add-cards.py +2 -1
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/init-board.py +2 -1
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/poll-status.py +2 -1
- package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +20 -24
- package/examples/cli/step-machine-cli/portfolio-tracker/run-inline-python-demo-pycli.py +0 -3
- package/examples/cli/step-machine-demo/jsonata-init-board-cli.js +8 -13
- package/examples/cli/step-machine-demo/jsonata-init-board.flow.yaml +33 -9
- package/examples/cli/step-machine-demo/one-step-cli-only.flow.yaml +3 -1
- package/examples/cli/step-machine-demo/step2-double-cli.js +6 -12
- package/examples/cli/step-machine-demo/two-step-math.flow.yaml +66 -4
- package/examples/cli/step-machine-demo/two-step-mixed.flow.yaml +13 -5
- package/examples/example-board/agent-instructions.md +1 -1
- package/examples/example-board/cards/card-my-identity.json +30 -6
- package/examples/example-board/cards/card-portfolio-action.json +24 -6
- package/examples/example-board/cards/card-portfolio-intelligence.json +97 -0
- package/examples/example-board/cards/card-portfolio-risks.json +24 -6
- package/examples/example-board/cards/card-rebalance-impact.json +22 -6
- package/examples/example-board/cards/card-rebalance-sim.json +66 -15
- package/examples/example-board/cards/cardT-market-prices.json +80 -0
- package/examples/example-board/cards/{card-portfolio-value.json → cardT-portfolio-value.json} +38 -10
- package/examples/example-board/cards/cardT-portfolio.json +78 -0
- package/examples/example-board/demo-server-config.json +1 -1
- package/examples/example-board/demo-server.js +383 -69
- package/examples/example-board/demo-shell-localstorage.html +774 -0
- package/examples/example-board/demo-shell-with-server.html +18 -36
- package/examples/example-board/demo-shell.html +5 -4
- package/examples/example-board/demo-task-executor.js +213 -265
- package/package.json +15 -13
- package/step-machine-cli.js +43 -310
- package/board-livecards-server-runtime.js +0 -1513
- package/browser/board-livecards-runtime-client.js +0 -263
- package/dist/pycli/quickjs-board-runtime.global.js +0 -9
- package/dist/pycli/quickjs-board-runtime.global.js.map +0 -1
- package/dist/pycli/quickjs-step-machine-runtime.global.js +0 -5
- package/dist/pycli/quickjs-step-machine-runtime.global.js.map +0 -1
- package/examples/cli/step-machine-demo/two-step-math-handlers.js +0 -32
- package/examples/cli/step-machine-demo/two-step-mixed-handlers.js +0 -24
- package/examples/example-board/cards/card-market-prices.json +0 -56
- package/examples/example-board/cards/card-portfolio.json +0 -44
- package/examples/example-board/demo-shell-browser.html +0 -675
package/dist/storage-refs.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
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("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 R(){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 k(t){if(t.kind==="fs-path")return R();throw new Error(`Unsupported storage kind: "${t.kind}". Supported kinds: fs-path`)}function d(t){return y(t).value}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=d(e.whatToRun),{cmd:s,args:l}=w(r),u=g(e),f=[...l,"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=d(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=d(e.whatToRun),{cmd:s,args:l}=w(r),u=g(e),f=[...l,"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=d(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
2
|
const {request} = require(new URL('${t}').protocol === 'https:' ? 'https' : 'http');
|
|
3
3
|
const h = ${JSON.stringify({"Content-Type":"application/json","Content-Length":Buffer.byteLength(n)})};
|
|
4
4
|
const u = new URL('${t}');
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
req.on('error', e => { process.stderr.write(e.message); process.exit(1); });
|
|
7
7
|
req.write(${JSON.stringify(n)});
|
|
8
8
|
req.end();
|
|
9
|
-
`,e=child_process.spawnSync(process.execPath,["-e",
|
|
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=k;exports.parseRef=y;exports.reportComplete=b;exports.reportFailed=v;exports.serializeRef=h;//# sourceMappingURL=storage-refs.cjs.map
|
|
10
10
|
//# sourceMappingURL=storage-refs.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/node/public-storage-adapter.ts"],"names":["parseRef","s","inner","idx","serializeRef","ref","createFsPathBlobStorage","key","i","content","c","blobStorageForRef","_parseWhatToRun","whatToRun","_notifyChannelFromVia","via","candidate","_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":"mfA8CO,SAASA,CAAAA,CAASC,CAAAA,CAAyB,CAChD,GAAI,CAACA,CAAAA,CAAE,UAAA,CAAW,IAAI,CAAA,CAAG,MAAM,IAAI,KAAA,CAAM,CAAA,6CAAA,EAAgDA,CAAC,CAAA,CAAE,CAAA,CAC5F,IAAMC,CAAAA,CAAQD,CAAAA,CAAE,MAAM,CAAC,CAAA,CACjBE,CAAAA,CAAMD,CAAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,CAC9B,GAAIC,CAAAA,GAAQ,EAAA,CAAI,MAAM,IAAI,KAAA,CAAM,CAAA,6CAAA,EAAgDF,CAAC,CAAA,CAAE,EACnF,OAAO,CAAE,IAAA,CAAMC,CAAAA,CAAM,KAAA,CAAM,CAAA,CAAGC,CAAG,CAAA,CAAG,KAAA,CAAOD,CAAAA,CAAM,KAAA,CAAMC,CAAAA,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,EAA2CrB,CAAAA,CAAI,QAAQ,CAAA,CAAA,CAAG,CAC5E,CAGA,SAASsB,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: ::kind::value\n * - parseRef() parse a ::kind::value string\n * - serializeRef() produce a ::kind::value 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 (::kind::value) into a KindValueRef. */\nexport function parseRef(s: string): KindValueRef {\n if (!s.startsWith('::')) throw new Error(`Invalid ref format (expected ::kind::value): ${s}`);\n const inner = s.slice(2);\n const idx = inner.indexOf('::');\n if (idx === -1) throw new Error(`Invalid ref format (expected ::kind::value): ${s}`);\n return { kind: inner.slice(0, idx), value: inner.slice(idx + 2) };\n}\n\n/** Serialize a KindValueRef to the wire format: ::kind::value */\nexport function serializeRef(ref: KindValueRef): string {\n return `::${ref.kind}::${ref.value}`;\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 ::kind::value wire form (e.g. ::fs-path::/path/to/cli.js). */\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 ::kind::value wire string.\n * Falls back to the raw string if it isn’t in ::kind::value 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
|
+
{"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":"mfA8CO,SAASA,CAAAA,CAASC,CAAAA,CAAyB,CAChD,GAAI,CAACA,CAAAA,CAAE,UAAA,CAA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AAA,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. */\nexport function parseRef(s: string): KindValueRef {\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 */\nfunction _parseWhatToRun(whatToRun: string): string {\n return parseRef(whatToRun).value;\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"]}
|
package/dist/storage-refs.d.cts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* Zero dependencies on the rest of yaml-flow.
|
|
6
6
|
*
|
|
7
7
|
* Provides:
|
|
8
|
-
* - KindValueRef wire format:
|
|
9
|
-
* - parseRef() parse a
|
|
10
|
-
* - serializeRef() produce a
|
|
8
|
+
* - KindValueRef wire format: b64:<base64url(json)>
|
|
9
|
+
* - parseRef() parse a b64:<base64url(json)> string
|
|
10
|
+
* - serializeRef() produce a b64:<base64url(json)> string
|
|
11
11
|
* - BlobStorage read/write interface
|
|
12
12
|
* - blobStorageForRef resolve a ref to its BlobStorage backend
|
|
13
13
|
* - ExecutionRef portable invocation descriptor (inlined, stays standalone)
|
|
@@ -33,9 +33,9 @@ interface KindValueRef {
|
|
|
33
33
|
readonly kind: string;
|
|
34
34
|
readonly value: string;
|
|
35
35
|
}
|
|
36
|
-
/** Parse a wire-format ref string (
|
|
36
|
+
/** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef. */
|
|
37
37
|
declare function parseRef(s: string): KindValueRef;
|
|
38
|
-
/** Serialize a KindValueRef to the wire format:
|
|
38
|
+
/** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */
|
|
39
39
|
declare function serializeRef(ref: KindValueRef): string;
|
|
40
40
|
interface BlobStorage {
|
|
41
41
|
/** Returns content string, or null if not found. */
|
|
@@ -62,7 +62,7 @@ interface ExecutionRef {
|
|
|
62
62
|
meta?: string;
|
|
63
63
|
/** Transport / runtime kind. */
|
|
64
64
|
howToRun: 'local-node' | 'local-python' | 'local-process' | 'http:post' | 'http:get' | 'built-in';
|
|
65
|
-
/** Address of the target in
|
|
65
|
+
/** Address of the target in b64:<base64url(json)> wire form. */
|
|
66
66
|
whatToRun: string;
|
|
67
67
|
/** Opaque executor config stored with the ref. */
|
|
68
68
|
extra?: Record<string, unknown>;
|
package/dist/storage-refs.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* Zero dependencies on the rest of yaml-flow.
|
|
6
6
|
*
|
|
7
7
|
* Provides:
|
|
8
|
-
* - KindValueRef wire format:
|
|
9
|
-
* - parseRef() parse a
|
|
10
|
-
* - serializeRef() produce a
|
|
8
|
+
* - KindValueRef wire format: b64:<base64url(json)>
|
|
9
|
+
* - parseRef() parse a b64:<base64url(json)> string
|
|
10
|
+
* - serializeRef() produce a b64:<base64url(json)> string
|
|
11
11
|
* - BlobStorage read/write interface
|
|
12
12
|
* - blobStorageForRef resolve a ref to its BlobStorage backend
|
|
13
13
|
* - ExecutionRef portable invocation descriptor (inlined, stays standalone)
|
|
@@ -33,9 +33,9 @@ interface KindValueRef {
|
|
|
33
33
|
readonly kind: string;
|
|
34
34
|
readonly value: string;
|
|
35
35
|
}
|
|
36
|
-
/** Parse a wire-format ref string (
|
|
36
|
+
/** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef. */
|
|
37
37
|
declare function parseRef(s: string): KindValueRef;
|
|
38
|
-
/** Serialize a KindValueRef to the wire format:
|
|
38
|
+
/** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */
|
|
39
39
|
declare function serializeRef(ref: KindValueRef): string;
|
|
40
40
|
interface BlobStorage {
|
|
41
41
|
/** Returns content string, or null if not found. */
|
|
@@ -62,7 +62,7 @@ interface ExecutionRef {
|
|
|
62
62
|
meta?: string;
|
|
63
63
|
/** Transport / runtime kind. */
|
|
64
64
|
howToRun: 'local-node' | 'local-python' | 'local-process' | 'http:post' | 'http:get' | 'built-in';
|
|
65
|
-
/** Address of the target in
|
|
65
|
+
/** Address of the target in b64:<base64url(json)> wire form. */
|
|
66
66
|
whatToRun: string;
|
|
67
67
|
/** Opaque executor config stored with the ref. */
|
|
68
68
|
extra?: Record<string, unknown>;
|
package/dist/storage-refs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as i from'fs';import*as c from'path';import {spawnSync}from'child_process';function
|
|
1
|
+
import*as i from'fs';import*as c from'path';import {spawnSync}from'child_process';function y(t){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 R(){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 k(t){if(t.kind==="fs-path")return R();throw new Error(`Unsupported storage kind: "${t.kind}". Supported kinds: fs-path`)}function d(t){return y(t).value}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=d(e.whatToRun),{cmd:s,args:l}=w(r),u=g(e),f=[...l,"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=d(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=d(e.whatToRun),{cmd:s,args:l}=w(r),u=g(e),f=[...l,"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=d(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
2
|
const {request} = require(new URL('${t}').protocol === 'https:' ? 'https' : 'http');
|
|
3
3
|
const h = ${JSON.stringify({"Content-Type":"application/json","Content-Length":Buffer.byteLength(n)})};
|
|
4
4
|
const u = new URL('${t}');
|
|
@@ -6,5 +6,5 @@ import*as i from'fs';import*as c from'path';import {spawnSync}from'child_process
|
|
|
6
6
|
req.on('error', e => { process.stderr.write(e.message); process.exit(1); });
|
|
7
7
|
req.write(${JSON.stringify(n)});
|
|
8
8
|
req.end();
|
|
9
|
-
`,e=spawnSync(process.execPath,["-e",
|
|
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{k as blobStorageForRef,y as parseRef,b as reportComplete,v as reportFailed,h as serializeRef};//# sourceMappingURL=storage-refs.js.map
|
|
10
10
|
//# sourceMappingURL=storage-refs.js.map
|
package/dist/storage-refs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/node/public-storage-adapter.ts"],"names":["parseRef","s","inner","idx","serializeRef","ref","createFsPathBlobStorage","key","content","blobStorageForRef","_parseWhatToRun","whatToRun","_notifyChannelFromVia","via","candidate","_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":"kFA8CO,SAASA,CAAAA,CAASC,CAAAA,CAAyB,CAChD,GAAI,CAACA,CAAAA,CAAE,UAAA,CAAW,IAAI,CAAA,CAAG,MAAM,IAAI,KAAA,CAAM,CAAA,6CAAA,EAAgDA,CAAC,CAAA,CAAE,CAAA,CAC5F,IAAMC,CAAAA,CAAQD,CAAAA,CAAE,MAAM,CAAC,CAAA,CACjBE,CAAAA,CAAMD,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AgBG,CAAAA,CAAI,SAAS,CAAA,CACnCqB,CAAAA,CAAO,IAAA,CAAK,SAAA,CAAU,CAAE,MAAA,CAAQ,QAAA,CAAU,MAAA,CAAAG,CAAAA,CAAQ,KAAA,CAAAX,CAAM,CAAC,CAAA,CAC/DS,CAAAA,CAAcF,CAAAA,CAAKC,CAAI,EACvB,MACF,CACA,MAAM,IAAI,KAAA,CAAM,CAAA,wCAAA,EAA2CrB,CAAAA,CAAI,QAAQ,CAAA,CAAA,CAAG,CAC5E,CAGA,SAASsB,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,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: ::kind::value\n * - parseRef() parse a ::kind::value string\n * - serializeRef() produce a ::kind::value 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 (::kind::value) into a KindValueRef. */\nexport function parseRef(s: string): KindValueRef {\n if (!s.startsWith('::')) throw new Error(`Invalid ref format (expected ::kind::value): ${s}`);\n const inner = s.slice(2);\n const idx = inner.indexOf('::');\n if (idx === -1) throw new Error(`Invalid ref format (expected ::kind::value): ${s}`);\n return { kind: inner.slice(0, idx), value: inner.slice(idx + 2) };\n}\n\n/** Serialize a KindValueRef to the wire format: ::kind::value */\nexport function serializeRef(ref: KindValueRef): string {\n return `::${ref.kind}::${ref.value}`;\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 ::kind::value wire form (e.g. ::fs-path::/path/to/cli.js). */\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 ::kind::value wire string.\n * Falls back to the raw string if it isn’t in ::kind::value 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
|
+
{"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":"kFA8CO,SAASA,CAAAA,CAASC,CAAAA,CAAyB,CAChD,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,OAAA,CAAQ,IAAA,CAAM,GAAG,CAAA,CAAI,IAAI,MAAA,CAAA,CAAQ,CAAA,CAAKA,CAAAA,CAAQ,MAAA,CAAS,GAAM,CAAC,CAAA,CACpGE,CAAAA,CACJ,GAAI,CACFA,CAAAA,CAAU,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,IAAA,CAAKD,CAAAA,CAAQ,QAAQ,CAAA,CAAE,SAAS,MAAM,CAAC,EACrE,CAAA,KAAQ,CACN,MAAM,IAAI,KAAA,CAAM,CAAA,+CAAA,EAAkDF,CAAC,CAAA,CAAE,CACvE,CACA,GAAI,CAACG,CAAAA,EAAW,OAAOA,CAAAA,EAAY,SACjC,MAAM,IAAI,KAAA,CAAM,CAAA,8CAAA,EAAiDH,CAAC,CAAA,CAAE,CAAA,CAEtE,IAAMI,CAAAA,CAAYD,EAClB,GAAI,OAAOC,CAAAA,CAAU,IAAA,EAAS,QAAA,EAAY,OAAOA,CAAAA,CAAU,KAAA,EAAU,SACnE,MAAM,IAAI,KAAA,CAAM,CAAA,6DAAA,EAAgEJ,CAAC,CAAA,CAAE,CAAA,CAErF,OAAO,CAAE,KAAMI,CAAAA,CAAU,IAAA,CAAM,KAAA,CAAOA,CAAAA,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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,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. */\nexport function parseRef(s: string): KindValueRef {\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 */\nfunction _parseWhatToRun(whatToRun: string): string {\n return parseRef(whatToRun).value;\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,147 @@
|
|
|
1
|
+
import { e as KindValueRef, B as BoardPlatformAdapter, d as CommandResult } from './board-live-cards-public-5n1-syA3.cjs';
|
|
2
|
+
import { ExecutionRef } from './execution-refs.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* server-runtime/types.ts
|
|
6
|
+
*
|
|
7
|
+
* Platform-free adapter interfaces for the board server runtime.
|
|
8
|
+
*
|
|
9
|
+
* The runtime (index.ts) imports ONLY this file and board-live-cards-public
|
|
10
|
+
* for its dependencies — no node:fs, node:net, node:child_process, etc.
|
|
11
|
+
*
|
|
12
|
+
* Hosts (demo-server, Azure Function, Firebase Function) provide implementations
|
|
13
|
+
* of these interfaces when constructing the runtime.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface InvocationAdapter {
|
|
17
|
+
/**
|
|
18
|
+
* Fire-and-forget invocation of an ExecutionRef with args.
|
|
19
|
+
* Used for chat-handler dispatch, and potentially task-executor / inference-adapter.
|
|
20
|
+
* Returns a promise that resolves when the invocation is dispatched (not completed).
|
|
21
|
+
*/
|
|
22
|
+
invoke(ref: ExecutionRef, args: Record<string, unknown>): Promise<{
|
|
23
|
+
dispatched: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Optional synchronous describe call — asks the target to identify itself.
|
|
28
|
+
* Used for pre-init validation (e.g. confirming a chat-handler reports kind='chat-handler').
|
|
29
|
+
* Hosts that pre-register capabilities at deploy time may omit this.
|
|
30
|
+
*/
|
|
31
|
+
describe?(ref: ExecutionRef): Promise<DescribeEnvelope | null>;
|
|
32
|
+
}
|
|
33
|
+
interface NotificationTransport {
|
|
34
|
+
/**
|
|
35
|
+
* Start listening for events on a notification endpoint identified by a kind-ref.
|
|
36
|
+
* The ref kind determines the transport mechanism:
|
|
37
|
+
* ::named-pipe::/tmp/board-x.sock
|
|
38
|
+
* ::firestore-watch::collections/board-x/notifications
|
|
39
|
+
* ::signalr::https://x.service.signalr.net/hub/board-x
|
|
40
|
+
* onEvent is called with parsed JSON notification objects.
|
|
41
|
+
* Returns a teardown function.
|
|
42
|
+
*/
|
|
43
|
+
subscribe(ref: KindValueRef, onEvent: (event: unknown) => void): Promise<() => void>;
|
|
44
|
+
}
|
|
45
|
+
interface DescribeEnvelope {
|
|
46
|
+
name: string;
|
|
47
|
+
kind: 'task-executor' | 'chat-handler' | 'inference-adapter';
|
|
48
|
+
protocolVersion: string;
|
|
49
|
+
supports?: string[];
|
|
50
|
+
}
|
|
51
|
+
interface RuntimeLogger {
|
|
52
|
+
info(msg: string, ...args: unknown[]): void;
|
|
53
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
54
|
+
error(msg: string, ...args: unknown[]): void;
|
|
55
|
+
}
|
|
56
|
+
interface BoardContextConfig {
|
|
57
|
+
label: string;
|
|
58
|
+
boardAdapter: BoardPlatformAdapter;
|
|
59
|
+
/** Optional separate adapter for file/chat blob storage (defaults to boardAdapter) */
|
|
60
|
+
artifactsAdapter?: BoardPlatformAdapter;
|
|
61
|
+
baseRef: KindValueRef;
|
|
62
|
+
cardStoreRef: string;
|
|
63
|
+
outputsStoreRef: string;
|
|
64
|
+
/** Notification endpoint ref — e.g. ::named-pipe::<path> or ::firestore-watch::<path> */
|
|
65
|
+
notifyRef?: KindValueRef;
|
|
66
|
+
taskExecutorRef?: ExecutionRef;
|
|
67
|
+
chatHandlerRef?: ExecutionRef;
|
|
68
|
+
inferenceAdapterRef?: ExecutionRef;
|
|
69
|
+
}
|
|
70
|
+
interface SingleBoardRuntimeOptions {
|
|
71
|
+
apiBasePath?: string;
|
|
72
|
+
corsHeaders?: Record<string, string>;
|
|
73
|
+
boardId?: string;
|
|
74
|
+
/** One or more board layers composing this board surface (e.g. base cards + admin cards). */
|
|
75
|
+
boards: BoardContextConfig[];
|
|
76
|
+
invocationAdapter: InvocationAdapter;
|
|
77
|
+
notificationTransport?: NotificationTransport;
|
|
78
|
+
logger?: RuntimeLogger;
|
|
79
|
+
serverUrl?: string;
|
|
80
|
+
/** Extra host-specific fields baked into execution ref extras */
|
|
81
|
+
executionExtra?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
interface MultiBoardRuntimeOptions {
|
|
84
|
+
apiBasePath?: string;
|
|
85
|
+
corsHeaders?: Record<string, string>;
|
|
86
|
+
/** Artifacts store for multi-board registry metadata */
|
|
87
|
+
serverMetaStore: {
|
|
88
|
+
getText(key: string): string | null;
|
|
89
|
+
putText(key: string, text: string): void;
|
|
90
|
+
};
|
|
91
|
+
/** Factory that creates a single-board runtime for a given board config */
|
|
92
|
+
boardRuntimeFactory: (boardId: string, entry: Record<string, unknown>) => SingleBoardRuntime;
|
|
93
|
+
logger?: RuntimeLogger;
|
|
94
|
+
}
|
|
95
|
+
interface SingleBoardRuntime {
|
|
96
|
+
readonly apiBasePath: string;
|
|
97
|
+
readonly corsHeaders: Record<string, string>;
|
|
98
|
+
handleRuntimeApi(req: RuntimeRequest, res: RuntimeResponse, parsedUrl: URL): Promise<boolean>;
|
|
99
|
+
buildPublishedRuntimePayload(): unknown;
|
|
100
|
+
clearChatRecords(cardId: string): void;
|
|
101
|
+
/** Report that a source fetch completed. Token is the source callback token; ref is the blob ref (b64:<base64url(json)>). */
|
|
102
|
+
reportSourceFetched(token: string, ref: string): CommandResult;
|
|
103
|
+
/** Report that a source fetch failed. Token is the source callback token. */
|
|
104
|
+
reportSourceFetchFailure(token: string, reason: string): CommandResult;
|
|
105
|
+
/** Exposed card store — host calls cardStore.set({body: cards}) to seed definitions. */
|
|
106
|
+
readonly cardStore: {
|
|
107
|
+
get(input: {
|
|
108
|
+
params?: {
|
|
109
|
+
id?: string;
|
|
110
|
+
};
|
|
111
|
+
}): {
|
|
112
|
+
status: string;
|
|
113
|
+
data?: {
|
|
114
|
+
cards?: Array<Record<string, unknown>>;
|
|
115
|
+
};
|
|
116
|
+
error?: string;
|
|
117
|
+
};
|
|
118
|
+
set(input: {
|
|
119
|
+
body: unknown;
|
|
120
|
+
}): {
|
|
121
|
+
status: string;
|
|
122
|
+
error?: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
interface MultiBoardRuntime {
|
|
127
|
+
readonly apiBasePath: string;
|
|
128
|
+
readonly corsHeaders: Record<string, string>;
|
|
129
|
+
handleApi(req: RuntimeRequest, res: RuntimeResponse, parsedUrl: URL): Promise<boolean>;
|
|
130
|
+
requireBoardService(boardId: string): {
|
|
131
|
+
service: SingleBoardRuntime;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
interface RuntimeRequest {
|
|
135
|
+
method?: string;
|
|
136
|
+
url?: string;
|
|
137
|
+
headers: Record<string, string | string[] | undefined>;
|
|
138
|
+
on(event: string, listener: (...args: unknown[]) => void): void;
|
|
139
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Buffer | Uint8Array>;
|
|
140
|
+
}
|
|
141
|
+
interface RuntimeResponse {
|
|
142
|
+
writeHead(statusCode: number, headers?: Record<string, string | number>): void;
|
|
143
|
+
write(data: string | Buffer): boolean;
|
|
144
|
+
end(data?: string | Buffer): void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type { BoardContextConfig as B, DescribeEnvelope as D, InvocationAdapter as I, MultiBoardRuntimeOptions as M, NotificationTransport as N, RuntimeLogger as R, SingleBoardRuntimeOptions as S, MultiBoardRuntime as a, SingleBoardRuntime as b, RuntimeRequest as c, RuntimeResponse as d };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { e as KindValueRef, B as BoardPlatformAdapter, d as CommandResult } from './board-live-cards-public-CK_J8uv0.js';
|
|
2
|
+
import { ExecutionRef } from './execution-refs.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* server-runtime/types.ts
|
|
6
|
+
*
|
|
7
|
+
* Platform-free adapter interfaces for the board server runtime.
|
|
8
|
+
*
|
|
9
|
+
* The runtime (index.ts) imports ONLY this file and board-live-cards-public
|
|
10
|
+
* for its dependencies — no node:fs, node:net, node:child_process, etc.
|
|
11
|
+
*
|
|
12
|
+
* Hosts (demo-server, Azure Function, Firebase Function) provide implementations
|
|
13
|
+
* of these interfaces when constructing the runtime.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface InvocationAdapter {
|
|
17
|
+
/**
|
|
18
|
+
* Fire-and-forget invocation of an ExecutionRef with args.
|
|
19
|
+
* Used for chat-handler dispatch, and potentially task-executor / inference-adapter.
|
|
20
|
+
* Returns a promise that resolves when the invocation is dispatched (not completed).
|
|
21
|
+
*/
|
|
22
|
+
invoke(ref: ExecutionRef, args: Record<string, unknown>): Promise<{
|
|
23
|
+
dispatched: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Optional synchronous describe call — asks the target to identify itself.
|
|
28
|
+
* Used for pre-init validation (e.g. confirming a chat-handler reports kind='chat-handler').
|
|
29
|
+
* Hosts that pre-register capabilities at deploy time may omit this.
|
|
30
|
+
*/
|
|
31
|
+
describe?(ref: ExecutionRef): Promise<DescribeEnvelope | null>;
|
|
32
|
+
}
|
|
33
|
+
interface NotificationTransport {
|
|
34
|
+
/**
|
|
35
|
+
* Start listening for events on a notification endpoint identified by a kind-ref.
|
|
36
|
+
* The ref kind determines the transport mechanism:
|
|
37
|
+
* ::named-pipe::/tmp/board-x.sock
|
|
38
|
+
* ::firestore-watch::collections/board-x/notifications
|
|
39
|
+
* ::signalr::https://x.service.signalr.net/hub/board-x
|
|
40
|
+
* onEvent is called with parsed JSON notification objects.
|
|
41
|
+
* Returns a teardown function.
|
|
42
|
+
*/
|
|
43
|
+
subscribe(ref: KindValueRef, onEvent: (event: unknown) => void): Promise<() => void>;
|
|
44
|
+
}
|
|
45
|
+
interface DescribeEnvelope {
|
|
46
|
+
name: string;
|
|
47
|
+
kind: 'task-executor' | 'chat-handler' | 'inference-adapter';
|
|
48
|
+
protocolVersion: string;
|
|
49
|
+
supports?: string[];
|
|
50
|
+
}
|
|
51
|
+
interface RuntimeLogger {
|
|
52
|
+
info(msg: string, ...args: unknown[]): void;
|
|
53
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
54
|
+
error(msg: string, ...args: unknown[]): void;
|
|
55
|
+
}
|
|
56
|
+
interface BoardContextConfig {
|
|
57
|
+
label: string;
|
|
58
|
+
boardAdapter: BoardPlatformAdapter;
|
|
59
|
+
/** Optional separate adapter for file/chat blob storage (defaults to boardAdapter) */
|
|
60
|
+
artifactsAdapter?: BoardPlatformAdapter;
|
|
61
|
+
baseRef: KindValueRef;
|
|
62
|
+
cardStoreRef: string;
|
|
63
|
+
outputsStoreRef: string;
|
|
64
|
+
/** Notification endpoint ref — e.g. ::named-pipe::<path> or ::firestore-watch::<path> */
|
|
65
|
+
notifyRef?: KindValueRef;
|
|
66
|
+
taskExecutorRef?: ExecutionRef;
|
|
67
|
+
chatHandlerRef?: ExecutionRef;
|
|
68
|
+
inferenceAdapterRef?: ExecutionRef;
|
|
69
|
+
}
|
|
70
|
+
interface SingleBoardRuntimeOptions {
|
|
71
|
+
apiBasePath?: string;
|
|
72
|
+
corsHeaders?: Record<string, string>;
|
|
73
|
+
boardId?: string;
|
|
74
|
+
/** One or more board layers composing this board surface (e.g. base cards + admin cards). */
|
|
75
|
+
boards: BoardContextConfig[];
|
|
76
|
+
invocationAdapter: InvocationAdapter;
|
|
77
|
+
notificationTransport?: NotificationTransport;
|
|
78
|
+
logger?: RuntimeLogger;
|
|
79
|
+
serverUrl?: string;
|
|
80
|
+
/** Extra host-specific fields baked into execution ref extras */
|
|
81
|
+
executionExtra?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
interface MultiBoardRuntimeOptions {
|
|
84
|
+
apiBasePath?: string;
|
|
85
|
+
corsHeaders?: Record<string, string>;
|
|
86
|
+
/** Artifacts store for multi-board registry metadata */
|
|
87
|
+
serverMetaStore: {
|
|
88
|
+
getText(key: string): string | null;
|
|
89
|
+
putText(key: string, text: string): void;
|
|
90
|
+
};
|
|
91
|
+
/** Factory that creates a single-board runtime for a given board config */
|
|
92
|
+
boardRuntimeFactory: (boardId: string, entry: Record<string, unknown>) => SingleBoardRuntime;
|
|
93
|
+
logger?: RuntimeLogger;
|
|
94
|
+
}
|
|
95
|
+
interface SingleBoardRuntime {
|
|
96
|
+
readonly apiBasePath: string;
|
|
97
|
+
readonly corsHeaders: Record<string, string>;
|
|
98
|
+
handleRuntimeApi(req: RuntimeRequest, res: RuntimeResponse, parsedUrl: URL): Promise<boolean>;
|
|
99
|
+
buildPublishedRuntimePayload(): unknown;
|
|
100
|
+
clearChatRecords(cardId: string): void;
|
|
101
|
+
/** Report that a source fetch completed. Token is the source callback token; ref is the blob ref (b64:<base64url(json)>). */
|
|
102
|
+
reportSourceFetched(token: string, ref: string): CommandResult;
|
|
103
|
+
/** Report that a source fetch failed. Token is the source callback token. */
|
|
104
|
+
reportSourceFetchFailure(token: string, reason: string): CommandResult;
|
|
105
|
+
/** Exposed card store — host calls cardStore.set({body: cards}) to seed definitions. */
|
|
106
|
+
readonly cardStore: {
|
|
107
|
+
get(input: {
|
|
108
|
+
params?: {
|
|
109
|
+
id?: string;
|
|
110
|
+
};
|
|
111
|
+
}): {
|
|
112
|
+
status: string;
|
|
113
|
+
data?: {
|
|
114
|
+
cards?: Array<Record<string, unknown>>;
|
|
115
|
+
};
|
|
116
|
+
error?: string;
|
|
117
|
+
};
|
|
118
|
+
set(input: {
|
|
119
|
+
body: unknown;
|
|
120
|
+
}): {
|
|
121
|
+
status: string;
|
|
122
|
+
error?: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
interface MultiBoardRuntime {
|
|
127
|
+
readonly apiBasePath: string;
|
|
128
|
+
readonly corsHeaders: Record<string, string>;
|
|
129
|
+
handleApi(req: RuntimeRequest, res: RuntimeResponse, parsedUrl: URL): Promise<boolean>;
|
|
130
|
+
requireBoardService(boardId: string): {
|
|
131
|
+
service: SingleBoardRuntime;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
interface RuntimeRequest {
|
|
135
|
+
method?: string;
|
|
136
|
+
url?: string;
|
|
137
|
+
headers: Record<string, string | string[] | undefined>;
|
|
138
|
+
on(event: string, listener: (...args: unknown[]) => void): void;
|
|
139
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Buffer | Uint8Array>;
|
|
140
|
+
}
|
|
141
|
+
interface RuntimeResponse {
|
|
142
|
+
writeHead(statusCode: number, headers?: Record<string, string | number>): void;
|
|
143
|
+
write(data: string | Buffer): boolean;
|
|
144
|
+
end(data?: string | Buffer): void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type { BoardContextConfig as B, DescribeEnvelope as D, InvocationAdapter as I, MultiBoardRuntimeOptions as M, NotificationTransport as N, RuntimeLogger as R, SingleBoardRuntimeOptions as S, MultiBoardRuntime as a, SingleBoardRuntime as b, RuntimeRequest as c, RuntimeResponse as d };
|