yaml-flow 7.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.
Files changed (86) hide show
  1. package/browser/asset-integrity.json +1 -1
  2. package/browser/board-livecards-client.js +1 -1
  3. package/browser/board-livecards-client.js.map +1 -1
  4. package/browser/board-livecards-localstorage.js +5 -5
  5. package/browser/board-livecards-localstorage.js.map +1 -1
  6. package/browser/live-cards.js +3 -1
  7. package/dist/{board-live-cards-public-CW5074xr.d.cts → board-live-cards-public-5n1-syA3.d.cts} +1 -2
  8. package/dist/{board-live-cards-public-hnZo0mAf.d.ts → board-live-cards-public-CK_J8uv0.d.ts} +1 -2
  9. package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs +2 -2
  10. package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs.map +1 -1
  11. package/dist/cli/browser-api/board-live-cards-browser-adapter.d.cts +2 -2
  12. package/dist/cli/browser-api/board-live-cards-browser-adapter.d.ts +2 -2
  13. package/dist/cli/browser-api/board-live-cards-browser-adapter.js +2 -2
  14. package/dist/cli/browser-api/board-live-cards-browser-adapter.js.map +1 -1
  15. package/dist/cli/browser-api/card-store-browser-api.cjs.map +1 -1
  16. package/dist/cli/browser-api/card-store-browser-api.js.map +1 -1
  17. package/dist/cli/node/artifacts-store-cli.cjs +5 -5
  18. package/dist/cli/node/artifacts-store-cli.cjs.map +1 -1
  19. package/dist/cli/node/artifacts-store-cli.js +5 -5
  20. package/dist/cli/node/artifacts-store-cli.js.map +1 -1
  21. package/dist/cli/node/board-live-cards-cli.cjs +7 -7
  22. package/dist/cli/node/board-live-cards-cli.cjs.map +1 -1
  23. package/dist/cli/node/board-live-cards-cli.js +7 -7
  24. package/dist/cli/node/board-live-cards-cli.js.map +1 -1
  25. package/dist/cli/node/card-store-cli.cjs +4 -4
  26. package/dist/cli/node/card-store-cli.cjs.map +1 -1
  27. package/dist/cli/node/card-store-cli.js +4 -4
  28. package/dist/cli/node/card-store-cli.js.map +1 -1
  29. package/dist/cli/node/execution-adapter.cjs +1 -1
  30. package/dist/cli/node/execution-adapter.cjs.map +1 -1
  31. package/dist/cli/node/execution-adapter.js +1 -1
  32. package/dist/cli/node/execution-adapter.js.map +1 -1
  33. package/dist/cli/node/fs-board-adapter.cjs +7 -7
  34. package/dist/cli/node/fs-board-adapter.cjs.map +1 -1
  35. package/dist/cli/node/fs-board-adapter.d.cts +2 -2
  36. package/dist/cli/node/fs-board-adapter.d.ts +2 -2
  37. package/dist/cli/node/fs-board-adapter.js +7 -7
  38. package/dist/cli/node/fs-board-adapter.js.map +1 -1
  39. package/dist/cli/node/source-cli-task-executor.cjs +2 -2
  40. package/dist/cli/node/source-cli-task-executor.cjs.map +1 -1
  41. package/dist/cli/node/source-cli-task-executor.js +2 -2
  42. package/dist/cli/node/source-cli-task-executor.js.map +1 -1
  43. package/dist/execution-refs.cjs +2 -2
  44. package/dist/execution-refs.cjs.map +1 -1
  45. package/dist/execution-refs.d.cts +9 -4
  46. package/dist/execution-refs.d.ts +9 -4
  47. package/dist/execution-refs.js +2 -2
  48. package/dist/execution-refs.js.map +1 -1
  49. package/dist/server-runtime/index.cjs +4 -4
  50. package/dist/server-runtime/index.cjs.map +1 -1
  51. package/dist/server-runtime/index.d.cts +3 -3
  52. package/dist/server-runtime/index.d.ts +3 -3
  53. package/dist/server-runtime/index.js +4 -4
  54. package/dist/server-runtime/index.js.map +1 -1
  55. package/dist/step-machine-public/index.cjs +2 -1
  56. package/dist/step-machine-public/index.cjs.map +1 -1
  57. package/dist/step-machine-public/index.d.cts +7 -0
  58. package/dist/step-machine-public/index.d.ts +7 -0
  59. package/dist/step-machine-public/index.js +2 -1
  60. package/dist/step-machine-public/index.js.map +1 -1
  61. package/dist/storage-refs.cjs +2 -2
  62. package/dist/storage-refs.cjs.map +1 -1
  63. package/dist/storage-refs.d.cts +1 -2
  64. package/dist/storage-refs.d.ts +1 -2
  65. package/dist/storage-refs.js +2 -2
  66. package/dist/storage-refs.js.map +1 -1
  67. package/dist/{types-BxEFcVK9.d.cts → types-CU3DjTKL.d.cts} +1 -1
  68. package/dist/{types-B1ZRa4aI.d.ts → types-HGDTWIun.d.ts} +1 -1
  69. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-http-test.js +13 -0
  70. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-http-test.py +398 -0
  71. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +4 -4
  72. package/examples/cli/step-machine-demo/jsonata-init-board.flow.yaml +1 -1
  73. package/examples/cli/step-machine-demo/one-step-cli-only.flow.yaml +1 -1
  74. package/examples/cli/step-machine-demo/two-step-mixed.flow.yaml +1 -1
  75. package/examples/example-board/agent-instructions.md +1 -1
  76. package/examples/example-board/cards/{card-market-prices.json → cardT-market-prices.json} +2 -2
  77. package/examples/example-board/cards/{card-portfolio.json → cardT-portfolio.json} +3 -13
  78. package/examples/example-board/demo-server-config.json +1 -1
  79. package/examples/example-board/demo-server.js +48 -25
  80. package/examples/example-board/demo-shell-localstorage.html +3 -3
  81. package/examples/example-board/demo-shell-with-server.html +2 -2
  82. package/examples/example-board/demo-task-executor.js +4 -8
  83. package/package.json +2 -2
  84. package/step-machine-cli.js +1 -1
  85. package/examples/example-board/cards/_index.json +0 -47
  86. /package/examples/example-board/cards/{card-portfolio-value.json → cardT-portfolio-value.json} +0 -0
@@ -1 +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,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,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"]}
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,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,CAAU,KAAM,CACxD,CAGO,SAASC,EAAaC,CAAAA,CAA2B,CACtD,OAAO,CAAA,IAAA,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C5B,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. */\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"]}
@@ -33,8 +33,7 @@ interface KindValueRef {
33
33
  readonly kind: string;
34
34
  readonly value: string;
35
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. */
36
+ /** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef. */
38
37
  declare function parseRef(s: string): KindValueRef;
39
38
  /** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */
40
39
  declare function serializeRef(ref: KindValueRef): string;
@@ -33,8 +33,7 @@ interface KindValueRef {
33
33
  readonly kind: string;
34
34
  readonly value: string;
35
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. */
36
+ /** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef. */
38
37
  declare function parseRef(s: string): KindValueRef;
39
38
  /** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */
40
39
  declare function serializeRef(ref: KindValueRef): string;
@@ -1,4 +1,4 @@
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=`
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",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
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
@@ -1 +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","re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A,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.\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
+ {"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,CAAU,KAAM,CAC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AAA,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"]}
@@ -1,4 +1,4 @@
1
- import { e as KindValueRef, B as BoardPlatformAdapter, d as CommandResult } from './board-live-cards-public-CW5074xr.cjs';
1
+ import { e as KindValueRef, B as BoardPlatformAdapter, d as CommandResult } from './board-live-cards-public-5n1-syA3.cjs';
2
2
  import { ExecutionRef } from './execution-refs.cjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { e as KindValueRef, B as BoardPlatformAdapter, d as CommandResult } from './board-live-cards-public-hnZo0mAf.js';
1
+ import { e as KindValueRef, B as BoardPlatformAdapter, d as CommandResult } from './board-live-cards-public-CK_J8uv0.js';
2
2
  import { ExecutionRef } from './execution-refs.js';
3
3
 
4
4
  /**
@@ -59,6 +59,8 @@ const NS = {
59
59
  statusGeneration: 0, // bumped on every status notification received
60
60
  dataObjects: {}, // token → payload (e.g. 'prices' → { AAPL: 142.5, ... })
61
61
  computedValues: {}, // cardId → values (e.g. 'holdings-table' → { table: { rows: [...] } })
62
+ cardRefreshedCount: 0, // total card_refreshed notifications seen
63
+ cardRefreshedByCardId: {},// cardId → count
62
64
  };
63
65
 
64
66
  // Apply a parsed SSE frame into NS (called from worker message handler)
@@ -92,6 +94,11 @@ function applyFrame(payload) {
92
94
  NS.dataObjects[n.key] = n.payload;
93
95
  } else if (n.kind === 'computed_values' && n.cardId) {
94
96
  NS.computedValues[n.cardId] = n.values;
97
+ } else if (n.kind === 'card_refreshed') {
98
+ NS.cardRefreshedCount++;
99
+ if (typeof n.cardId === 'string' && n.cardId) {
100
+ NS.cardRefreshedByCardId[n.cardId] = (NS.cardRefreshedByCardId[n.cardId] || 0) + 1;
101
+ }
95
102
  }
96
103
  }
97
104
  }
@@ -276,6 +283,7 @@ function applyFrame(payload) {
276
283
 
277
284
  // ── T2a: Add GOOG to holdings ────────────────────────────────────────────────
278
285
  console.log('\n=== T2a: Update holdings — add GOOG ===');
286
+ const t2CardRefreshedBefore = NS.cardRefreshedCount;
279
287
  const t2Patch = await httpPatch(
280
288
  `${BASE}/cards/portfolio-form`,
281
289
  makeHoldingsPatch({ AAPL: 50, MSFT: 30, GOOG: 100 }),
@@ -289,6 +297,11 @@ function applyFrame(payload) {
289
297
  console.log(`[T2b] completed — ${JSON.stringify(t2Summary)}`);
290
298
 
291
299
  const t2Prices = await waitForPriceSymbols(['AAPL', 'GOOG', 'MSFT'], 30_000, 'T2b prices');
300
+ const t2CardRefreshedAfter = NS.cardRefreshedCount;
301
+ assert(
302
+ t2CardRefreshedAfter > t2CardRefreshedBefore,
303
+ `T2b: expected at least one card_refreshed notification after PATCH (before=${t2CardRefreshedBefore}, after=${t2CardRefreshedAfter})`,
304
+ );
292
305
  const t2Table = NS.computedValues['holdings-table']?.table;
293
306
  assert(Array.isArray(t2Table?.rows) && t2Table.rows.length === 3, `T2b: expected 3 rows, got ${t2Table?.rows?.length}`);
294
307
  const t2Total = NS.computedValues['portfolio-value']?.totalValue;