yaml-flow 8.2.5 → 8.4.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 (93) hide show
  1. package/browser/asset-integrity.json +3 -3
  2. package/browser/board-livecards-client.js +1 -1
  3. package/browser/board-livecards-localstorage.js +6 -4
  4. package/browser/live-cards.js +19 -25
  5. package/cli/{board-live-cards-lib-Iq_XAC09.d.ts → board-live-cards-lib-tjYsPt5U.d.ts} +1 -1
  6. package/cli/browser-api/board-live-cards-browser-adapter.d.ts +3 -3
  7. package/cli/browser-api/board-live-cards-browser-adapter.js +3 -2
  8. package/cli/browser-api/card-store-browser-api.d.ts +1 -1
  9. package/cli/browser-api/card-store-browser-api.js +1 -1
  10. package/cli/{execution-interface-ftO1W7Po.d.ts → execution-interface-DCFBy4L8.d.ts} +151 -2
  11. package/cli/node/artifacts-store-cli.js +5 -5
  12. package/cli/node/batch-runner-cli.d.ts +3 -0
  13. package/cli/node/batch-runner-cli.js +2 -1
  14. package/cli/node/board-live-cards-cli.js +14 -8
  15. package/cli/node/card-store-cli.js +6 -6
  16. package/cli/node/chat-store-cli.d.ts +23 -0
  17. package/cli/node/chat-store-cli.js +8 -0
  18. package/cli/node/execution-adapter.d.ts +4 -2
  19. package/cli/node/execution-adapter.js +2 -2
  20. package/cli/node/fs-board-adapter.d.ts +75 -75
  21. package/cli/node/fs-board-adapter.js +14 -10
  22. package/cli/node/source-cli-task-executor.js +4 -4
  23. package/cli/node/step-machine-cli.js +3 -3
  24. package/cli/{types--rXGWbSR.d.ts → types-Dc2VRMUw.d.ts} +27 -124
  25. package/examples/board/demo-shell-with-server.html +3 -196
  26. package/examples/board/doc.html +465 -0
  27. package/examples/board/server/board-server.js +30 -82
  28. package/examples/board/server/board-worker/source_def_flows.json +2 -2
  29. package/examples/board/server/chat-flow/copilot-chat/assistant.js +44 -185
  30. package/examples/board/server/chat-flow/copilot-chat/copilot_wrapper.bat +157 -0
  31. package/examples/board/server/chat-flow/copilot-chat/copilot_wrapper_helper.ps1 +190 -0
  32. package/examples/board/server/chat-flow/flow-steps.json +122 -56
  33. package/examples/board/test/server-http-test.js +252 -220
  34. package/examples/board-local/demo-shell-localstorage.html +3 -3
  35. package/lib/{artifacts-store-lib-public-GD4H-fFp.d.ts → artifacts-store-lib-454TAuov.d.ts} +2 -32
  36. package/lib/{artifacts-store-lib-public-C5UL5tyG.d.cts → artifacts-store-lib-zsGFbBV8.d.cts} +2 -32
  37. package/lib/artifacts-store-public.d.cts +34 -3
  38. package/lib/artifacts-store-public.d.ts +34 -3
  39. package/lib/board-live-cards-node.cjs +14 -10
  40. package/lib/board-live-cards-node.d.cts +42 -21
  41. package/lib/board-live-cards-node.d.ts +42 -21
  42. package/lib/board-live-cards-node.js +14 -10
  43. package/lib/{board-live-cards-public-BLXbcBNk.d.cts → board-live-cards-public-BM6jCEIa.d.cts} +25 -5
  44. package/lib/{board-live-cards-public-BZaNb2mi.d.ts → board-live-cards-public-Bz07XKRK.d.ts} +25 -5
  45. package/lib/board-live-cards-public.cjs +2 -2
  46. package/lib/board-live-cards-public.d.cts +2 -2
  47. package/lib/board-live-cards-public.d.ts +2 -2
  48. package/lib/board-live-cards-public.js +2 -2
  49. package/lib/board-live-cards-server-runtime.cjs +4 -4
  50. package/lib/board-live-cards-server-runtime.d.cts +5 -3
  51. package/lib/board-live-cards-server-runtime.d.ts +5 -3
  52. package/lib/board-live-cards-server-runtime.js +4 -4
  53. package/lib/board-worker-adapter.cjs +2 -2
  54. package/lib/board-worker-adapter.js +2 -2
  55. package/lib/card-store-public.d.cts +2 -2
  56. package/lib/card-store-public.d.ts +2 -2
  57. package/lib/chat-storage-lib-DGaKrjVe.d.ts +53 -0
  58. package/lib/chat-storage-lib-OX0Q_Ttf.d.cts +53 -0
  59. package/lib/chat-store-public.cjs +2 -0
  60. package/lib/chat-store-public.d.cts +128 -0
  61. package/lib/chat-store-public.d.ts +128 -0
  62. package/lib/chat-store-public.js +2 -0
  63. package/lib/execution-refs.cjs +1 -1
  64. package/lib/execution-refs.d.cts +10 -1
  65. package/lib/execution-refs.d.ts +10 -1
  66. package/lib/execution-refs.js +1 -1
  67. package/lib/index.d.cts +1 -1
  68. package/lib/index.d.ts +1 -1
  69. package/lib/server-runtime/index.cjs +4 -4
  70. package/lib/server-runtime/index.d.cts +6 -4
  71. package/lib/server-runtime/index.d.ts +6 -4
  72. package/lib/server-runtime/index.js +4 -4
  73. package/lib/step-machine-public/index.cjs +3 -3
  74. package/lib/step-machine-public/index.d.cts +1 -1
  75. package/lib/step-machine-public/index.d.ts +1 -1
  76. package/lib/step-machine-public/index.js +3 -3
  77. package/lib/{storage-interface-B6ecOulj.d.ts → storage-interface-B-7pDHwD.d.cts} +36 -1
  78. package/lib/{storage-interface-B6ecOulj.d.cts → storage-interface-B-7pDHwD.d.ts} +36 -1
  79. package/lib/stores/index.d.cts +1 -1
  80. package/lib/stores/index.d.ts +1 -1
  81. package/lib/stores/kv.d.cts +1 -1
  82. package/lib/stores/kv.d.ts +1 -1
  83. package/lib/{types-D-xVWPdY.d.ts → types-Cn0b8G-i.d.ts} +16 -65
  84. package/lib/{types-Bztd1KoK.d.cts → types-Dszjwfud.d.cts} +16 -65
  85. package/package.json +8 -2
  86. package/examples/board/.board-ws/cards/store/_index.json +0 -17
  87. package/examples/board/.board-ws/cards/store/card-market-prices.json +0 -80
  88. package/examples/board/.board-ws/cards/store/card-portfolio-value.json +0 -90
  89. package/examples/board/.board-ws/cards/store/card-portfolio.json +0 -78
  90. package/examples/board/server/chat-flow/chat-clear-processing.js +0 -41
  91. package/examples/board/server/chat-flow/chat-open-turn.js +0 -144
  92. package/examples/board/server/chat-flow/chat-write-assistant.js +0 -44
  93. package/examples/board/server/chat-flow/echo-probe/assistant.js +0 -28
@@ -318,4 +318,4 @@ interface BoardStatusObject {
318
318
  }
319
319
  declare const EMPTY_CONFIG: GraphConfig;
320
320
 
321
- export { BOARD_GRAPH_KEY as B, type CardAdminStore as C, EMPTY_CONFIG as E, type JournalStorageAdapter as J, type LiveCard as L, type OutputStoreEvent as O, SNAPSHOT_SCHEMA_VERSION_V1 as S, type BoardStatusObject as a, createCardStore as c };
321
+ export { type BoardStatusObject as B, type CardAdminStore as C, EMPTY_CONFIG as E, type JournalStorageAdapter as J, type LiveCard as L, type OutputStoreEvent as O, SNAPSHOT_SCHEMA_VERSION_V1 as S, BOARD_GRAPH_KEY as a, createCardStore as c };
@@ -1,6 +1,6 @@
1
- import { B as BoardPlatformAdapter, N as NotificationTransport, C as ChatStorage } from '../types--rXGWbSR.js';
2
- import { E as ExecutionRef } from '../execution-interface-ftO1W7Po.js';
3
- import '../board-live-cards-lib-Iq_XAC09.js';
1
+ import { B as BoardPlatformAdapter, N as NotificationTransport, C as ChatStorage } from '../types-Dc2VRMUw.js';
2
+ import { E as ExecutionRef } from '../execution-interface-DCFBy4L8.js';
3
+ import '../board-live-cards-lib-tjYsPt5U.js';
4
4
 
5
5
  declare function createLocalStorageChatStorage(namespace: string): ChatStorage;
6
6
  interface InMemoryBus {
@@ -1,3 +1,4 @@
1
- var p="b64:";function T(t){let r=new TextEncoder().encode(t),i=globalThis.Buffer,o;if(i)o=i.from(r).toString("base64");else if(typeof btoa=="function"){let n="";for(let a of r)n+=String.fromCharCode(a);o=btoa(n);}else throw new Error("No base64 encoder available in this runtime");return o.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function B(t){let r=t.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-t.length%4)%4),i=globalThis.Buffer;if(i)return i.from(r,"base64").toString("utf8");if(typeof atob=="function"){let o=atob(r),n=new Uint8Array(o.length);for(let a=0;a<o.length;a+=1)n[a]=o.charCodeAt(a);return new TextDecoder().decode(n)}throw new Error("No base64 decoder available in this runtime")}function g(t){return `${p}${T(JSON.stringify(t))}`}function d(t){if(!t.startsWith(p))throw new Error(`Invalid ref format (expected ${p}<base64url(json)>): ${t}`);let r;try{r=JSON.parse(B(t.slice(p.length)));}catch{throw new Error(`Invalid ref format (malformed base64url/json): ${t}`)}if(!r||typeof r!="object")throw new Error(`Invalid ref format (expected object payload): ${t}`);let i=r;if(typeof i.kind!="string"||typeof i.value!="string")throw new Error(`Invalid ref format (payload must contain string kind/value): ${t}`);return {kind:i.kind,value:i.value}}function S(t){return String(t).replace(/[^a-zA-Z0-9_-]/g,"_")}function k(t){let r=t.payload??{};return {id:t.id,role:typeof r.role=="string"?r.role:"system",text:typeof r.text=="string"?r.text:"",files:Array.isArray(r.files)?r.files:[],updated_at:typeof r.updated_at=="string"?r.updated_at:""}}function v(t,r){let i=n=>`chats/${S(n)}/processing`,o=n=>`chats/${S(n)}/config`;return {append(n,a,e,l=[]){return t(n).append({role:a,text:e,files:l,updated_at:new Date().toISOString()}).id},readAll(n){return t(n).readAll().map(k)},readAfter(n,a){let e=t(n).readAfter(a);return {records:e.entries.map(k),cursor:e.newCursor}},clear(n){t(n).clear?.();},setProcessing(n,a){a?r.write(i(n),true):r.delete(i(n));},isProcessing(n){return r.read(i(n))===true},getConfig(n){return r.read(o(n))??{}},setConfig(n,a){let e=r.read(o(n))??{};r.write(o(n),{...e,...a});}}}function w(t){if(t==null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return `[${t.map(w).join(",")}]`;let r=t;return `{${Object.keys(r).sort().map(o=>`${JSON.stringify(o)}:${w(r[o])}`).join(",")}}`}function y(t,r){let i=r>>>0;for(let o=0;o<t.length;o++)i^=t.charCodeAt(o),i=Math.imul(i,16777619)>>>0;return i}function x(t){let r=w(t),i=y(r,2166136261),o=y(r,3735928559),n=y(r,19088743),a=y(r,4277009102);return [i,o,n,a].map(e=>e.toString(16).padStart(8,"0")).join("")}function m(t){function r(a){return `${t}:blob:${a}`}let i=new TextEncoder;function o(a){if(typeof btoa=="function"){let e="";for(let l=0;l<a.length;l++)e+=String.fromCharCode(a[l]);return btoa(e)}return ""}function n(a){if(typeof atob=="function"){let e=atob(a),l=new Uint8Array(e.length);for(let s=0;s<e.length;s++)l[s]=e.charCodeAt(s);return l}return new Uint8Array}return {read(a){return globalThis.localStorage.getItem(r(a))},write(a,e){globalThis.localStorage.setItem(r(a),e);},exists(a){return globalThis.localStorage.getItem(r(a))!==null},remove(a){globalThis.localStorage.removeItem(r(a));},readBytes(a){let e=globalThis.localStorage.getItem(r(a));if(e===null)return null;try{let l=JSON.parse(e);if(l&&l.__kind==="bytes-b64"&&typeof l.data=="string")return n(l.data)}catch{}return i.encode(e)},writeBytes(a,e){let l=JSON.stringify({__kind:"bytes-b64",data:o(e)});globalThis.localStorage.setItem(r(a),l);},listKeys(a){let e=r(a??""),l=[];for(let s=0;s<globalThis.localStorage.length;s++){let c=globalThis.localStorage.key(s);c&&c.startsWith(e)&&l.push(c.slice(r("").length));}return l.sort()},stat(a){let e=globalThis.localStorage.getItem(r(a));if(e===null)return null;let l=i.encode(e).byteLength;try{let s=JSON.parse(e);s&&s.__kind==="bytes-b64"&&typeof s.data=="string"&&(l=n(s.data).byteLength);}catch{}return {key:a,size:l}}}}function h(t){function r(i){return `${t}:kv:${i}`}return {read(i){let o=globalThis.localStorage.getItem(r(i));if(o===null)return null;try{return JSON.parse(o)}catch{return null}},write(i,o){globalThis.localStorage.setItem(r(i),JSON.stringify(o));},delete(i){globalThis.localStorage.removeItem(r(i));},listKeys(i){let o=r(i??""),n=[];for(let a=0;a<globalThis.localStorage.length;a++){let e=globalThis.localStorage.key(a);e!==null&&e.startsWith(o)&&n.push(e.slice(r("").length));}return n}}}function C(t){function r(){let o=globalThis.localStorage.getItem(t);if(!o)return [];try{return JSON.parse(o)}catch{return []}}function i(o){globalThis.localStorage.setItem(t,JSON.stringify(o));}return {readAllEntries(){return r()},appendEntry(o){let n=r();n.push(o),i(n);},generateId(){return globalThis.crypto.randomUUID()}}}function $(){let t=false;return {tryAcquire(){return t?null:(t=true,()=>{t=false;})}}}function E(t){return String(t).replace(/[^a-zA-Z0-9_-]/g,"_")}function j(t){function r(){let o=globalThis.localStorage.getItem(t);if(!o)return [];try{return JSON.parse(o)}catch{return []}}function i(o){globalThis.localStorage.setItem(t,JSON.stringify(o));}return {append(o){let n={id:globalThis.crypto.randomUUID(),payload:o},a=r();return a.push(n),i(a),n},readAll(){return r()},readAfter(o){let n=r();if(!o)return {entries:n,newCursor:n.length>0?n[n.length-1].id:null};let a=n.findIndex(l=>l.id===o),e=a===-1?n:n.slice(a+1);return {entries:e,newCursor:e.length>0?e[e.length-1].id:o}},clear(){globalThis.localStorage.removeItem(t);}}}function L(t){return v(r=>j(`${t}:chat:journal:${E(r)}`),h(`${t}:chat`))}var R=new Map;function A(t){let r=R.get(t);if(!r){let i=new Set;r={publish(o){for(let n of i)n(o);},subscribe(o){return i.add(o),()=>{i.delete(o);}}},R.set(t,r);}return r}function M(){return {async subscribe(t,r){return t.kind!=="in-memory-bus"?(console.warn(`[in-memory-transport] unsupported kind: ${t.kind}`),()=>{}):A(t.value).subscribe(o=>{let n=o;if(n&&n.kind==="notification-batch"&&Array.isArray(n.notifications)){for(let a of n.notifications)r(a);return}r(o);})}}}function V(t,r){let i=r?.callbackBaseUrl?{meta:"board-live-cards",howToRun:"http:post",whatToRun:r.callbackBaseUrl}:{meta:"board-live-cards",howToRun:"in-browser",whatToRun:g({kind:"in-browser",value:t})},o=new Map,n=new Map,a=$();return {kvStorage:e=>h(`${t}:${e}`),blobStorage:e=>m(e?`${t}:${e}`:t),journalAdapter:()=>C(`${t}:journal`),lock:a,selfRef:i,async dispatchExecution(e,l){if(e.howToRun==="http:post")try{let s=e.whatToRun,c=typeof s=="object"?s.value:d(s).value,u=await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});return u.ok?{dispatched:!0}:{dispatched:!1,error:`HTTP ${u.status}: ${u.statusText}`}}catch(s){return {dispatched:false,error:s instanceof Error?s.message:String(s)}}if(e.howToRun==="http:get")try{let s=e.whatToRun,c=typeof s=="object"?s.value:d(s).value,u=new URLSearchParams(Object.entries(l).filter(([,f])=>f!=null).map(([f,I])=>[f,String(I)])),J=`${c}?${u.toString()}`,b=await fetch(J);return b.ok?{dispatched:!0}:{dispatched:!1,error:`HTTP ${b.status}: ${b.statusText}`}}catch(s){return {dispatched:false,error:s instanceof Error?s.message:String(s)}}if(e.howToRun==="in-browser"){let s=e.whatToRun,c=typeof s=="object"?s.value:d(s).value,u=o.get(c);return u?u(e,l):{dispatched:false,error:`No in-browser handler registered for: ${c}`}}return {dispatched:false,error:`Browser adapter: unsupported dispatch kind (got: ${e.howToRun})`}},resolveBlob(e){if(e.kind==="in-memory"){let c=n.get(e.value);if(c==null)throw new Error(`resolveBlob: in-memory blob not found: ${g(e)}`);return c}let s=m(t).read(e.value);if(s===null)throw new Error(`resolveBlob: blob not found: ${g(e)}`);return s},hashFn:x,genId:()=>globalThis.crypto.randomUUID().replace(/-/g,""),kvStorageForRef:e=>h(d(e).value),publishBoardChangeNotifications(e){if(!r?.notifyChannel||e.length===0)return;A(r.notifyChannel).publish({kind:"notification-batch",notifications:e});},onWarn:r?.onWarn,registerHandler(e,l){o.set(e,l);},writeMemoryBlob(e,l){return n.set(e,l),g({kind:"in-memory",value:e})}}}
2
- export{V as createBrowserBoardPlatformAdapter,M as createInMemoryNotificationTransport,L as createLocalStorageChatStorage,A as getInMemoryNotificationBus};//# sourceMappingURL=board-live-cards-browser-adapter.js.map
1
+ var A="b64:";function D(t){let e=new TextEncoder().encode(t),g=globalThis.Buffer,a;if(g)a=g.from(e).toString("base64");else if(typeof btoa=="function"){let s="";for(let l of e)s+=String.fromCharCode(l);a=btoa(s);}else throw new Error("No base64 encoder available in this runtime");return a.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function W(t){let e=t.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-t.length%4)%4),g=globalThis.Buffer;if(g)return g.from(e,"base64").toString("utf8");if(typeof atob=="function"){let a=atob(e),s=new Uint8Array(a.length);for(let l=0;l<a.length;l+=1)s[l]=a.charCodeAt(l);return new TextDecoder().decode(s)}throw new Error("No base64 decoder available in this runtime")}function v(t){return `${A}${D(JSON.stringify(t))}`}function k(t){if(!t.startsWith(A))throw new Error(`Invalid ref format (expected ${A}<base64url(json)>): ${t}`);let e;try{e=JSON.parse(W(t.slice(A.length)));}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 g=e;if(typeof g.kind!="string"||typeof g.value!="string")throw new Error(`Invalid ref format (payload must contain string kind/value): ${t}`);return {kind:g.kind,value:g.value}}function E(t){return String(t).replace(/[^a-zA-Z0-9_-]/g,"_")}function L(t){let e=t.payload??{};return {id:t.id,role:typeof e.role=="string"?e.role:"system",text:typeof e.text=="string"?e.text:"",files:Array.isArray(e.files)?e.files:[],updated_at:typeof e.updated_at=="string"?e.updated_at:""}}function M(t,e){let g=s=>`chats/${E(s)}/processing`,a=s=>`chats/${E(s)}/config`;return {append(s,l,r,o=[]){return t(s).append({role:l,text:r,files:o,updated_at:new Date().toISOString()}).id},readAll(s){return t(s).readAll().map(L)},readAfter(s,l){let r=t(s).readAfter(l);return {records:r.entries.map(L),cursor:r.newCursor}},clear(s){t(s).clear?.();},setProcessing(s,l){l?e.write(g(s),true):e.delete(g(s));},isProcessing(s){return e.read(g(s))===true},getConfig(s){return e.read(a(s))??{}},setConfig(s,l){let r=e.read(a(s))??{};e.write(a(s),{...r,...l});}}}function $(t){if(t==null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return `[${t.map($).join(",")}]`;let e=t;return `{${Object.keys(e).sort().map(a=>`${JSON.stringify(a)}:${$(e[a])}`).join(",")}}`}function I(t,e){let g=e>>>0;for(let a=0;a<t.length;a++)g^=t.charCodeAt(a),g=Math.imul(g,16777619)>>>0;return g}function O(t){let e=$(t),g=I(e,2166136261),a=I(e,3735928559),s=I(e,19088743),l=I(e,4277009102);return [g,a,s,l].map(r=>r.toString(16).padStart(8,"0")).join("")}function R(t){function e(l){return `${t}:blob:${l}`}let g=new TextEncoder;function a(l){if(typeof btoa=="function"){let r="";for(let o=0;o<l.length;o++)r+=String.fromCharCode(l[o]);return btoa(r)}return ""}function s(l){if(typeof atob=="function"){let r=atob(l),o=new Uint8Array(r.length);for(let i=0;i<r.length;i++)o[i]=r.charCodeAt(i);return o}return new Uint8Array}return {read(l){return globalThis.localStorage.getItem(e(l))},write(l,r){globalThis.localStorage.setItem(e(l),r);},exists(l){return globalThis.localStorage.getItem(e(l))!==null},remove(l){globalThis.localStorage.removeItem(e(l));},readBytes(l){let r=globalThis.localStorage.getItem(e(l));if(r===null)return null;try{let o=JSON.parse(r);if(o&&o.__kind==="bytes-b64"&&typeof o.data=="string")return s(o.data)}catch{}return g.encode(r)},writeBytes(l,r){let o=JSON.stringify({__kind:"bytes-b64",data:a(r)});globalThis.localStorage.setItem(e(l),o);},listKeys(l){let r=e(l??""),o=[];for(let i=0;i<globalThis.localStorage.length;i++){let u=globalThis.localStorage.key(i);u&&u.startsWith(r)&&o.push(u.slice(e("").length));}return o.sort()},stat(l){let r=globalThis.localStorage.getItem(e(l));if(r===null)return null;let o=g.encode(r).byteLength;try{let i=JSON.parse(r);i&&i.__kind==="bytes-b64"&&typeof i.data=="string"&&(o=s(i.data).byteLength);}catch{}return {key:l,size:o}}}}var H=":scratch-marker",V=":scratch-config",T=":scratch:",z=1440*60*1e3,X=720*60*1e3,q=200;function N(t,e){if(!t)return e;let g=t.replace(/[^A-Za-z0-9._-]/g,"_");return g.length>0?g:e}function B(t){let e=`${t}${H}`,g=`${t}${V}`,a=n=>`${t}${T}${n}`,s=n=>`${t}${T}${n}:__ts`,l=globalThis.localStorage.getItem(e)===null;if(l)try{globalThis.localStorage.setItem(e,`scratch-store
2
+ ${new Date().toISOString()}`);}catch{}function r(){let n=globalThis.localStorage.getItem(g);if(n===null)return {};try{let c=JSON.parse(n);return c&&typeof c=="object"&&!Array.isArray(c)?c:{}}catch{return {}}}function o(n){try{globalThis.localStorage.setItem(g,JSON.stringify(n));}catch{}}if(l){let n=r();typeof n["retention.lastSweepAt"]!="number"&&(n["retention.lastSweepAt"]=Date.now(),o(n));}function i(){if(globalThis.localStorage.getItem(e)===null)return;let n=r(),c=typeof n["retention.maxAgeMs"]=="number"?n["retention.maxAgeMs"]:z,f=typeof n["retention.sweepIntervalMs"]=="number"?n["retention.sweepIntervalMs"]:X;if(c<=0||f<=0)return;let h=typeof n["retention.lastSweepAt"]=="number"?n["retention.lastSweepAt"]:0,y=Date.now();if(y-h<f)return;n["retention.lastSweepAt"]=y,o(n);let p=y,S=`${t}${T}`,b=[];for(let m=0;m<globalThis.localStorage.length;m++){let w=globalThis.localStorage.key(m);w&&w.startsWith(S)&&!w.endsWith(":__ts")&&b.push(w);}for(let m of b){if(Date.now()-p>q)break;let w=globalThis.localStorage.getItem(`${m}:__ts`),C=w===null?0:Number(w);if(Number.isFinite(C)&&C>0&&y-C>c){try{globalThis.localStorage.removeItem(m);}catch{}try{globalThis.localStorage.removeItem(`${m}:__ts`);}catch{}}}}function u(n,c){let f=N(n,"scratch"),h=N(c,".json"),y=h.startsWith(".")?h:`.${h}`,p=Math.random().toString(36).slice(2,10);return `${f}-${Date.now()}-${p}${y}`}function d(n,c){globalThis.localStorage.setItem(a(n),c),globalThis.localStorage.setItem(s(n),String(Date.now()));}return {read(n){return globalThis.localStorage.getItem(a(n))},write(n,c){d(n,c);try{i();}catch{}},exists(n){return globalThis.localStorage.getItem(a(n))!==null},remove(n){try{globalThis.localStorage.removeItem(a(n));}catch{}try{globalThis.localStorage.removeItem(s(n));}catch{}},readBytes(n){let c=globalThis.localStorage.getItem(a(n));return c===null?null:new TextEncoder().encode(c)},writeBytes(n,c){let f="";for(let h=0;h<c.length;h++)f+=String.fromCharCode(c[h]);d(n,f);try{i();}catch{}},stat(n){let c=globalThis.localStorage.getItem(a(n));if(c===null)return null;let f=globalThis.localStorage.getItem(s(n)),h=f===null?null:Number(f);return {key:n,size:new TextEncoder().encode(c).byteLength,updatedAt:h!==null&&Number.isFinite(h)?new Date(h).toISOString():void 0}},listKeys(n){let c=`${t}${T}`,f=[];for(let h=0;h<globalThis.localStorage.length;h++){let y=globalThis.localStorage.key(h);if(y&&y.startsWith(c)&&!y.endsWith(":__ts")){let p=y.slice(c.length);(!n||p.startsWith(n))&&f.push(p);}}return f.sort()},getUniqueKey(n,c){return u(n,c)},create(n,c,f){let h=u(c,f);d(h,n);try{i();}catch{}return h},keyRef(n){return {kind:"local-storage-scratch",value:n,extra:{prefix:t}}},config:{get(n){return r()[n]??null},set(n,c){let f=r();c==null?delete f[n]:f[n]=c,o(f);}}}}var G=":archive-marker",Z=":archive-config",_=":archive:stream:",U=":archive:blob:";function K(t){let e=t.replace(/[^A-Za-z0-9._-]/g,"_");if(!e)throw new Error("Archive segment name cannot be empty after sanitization");return e}function J(t){let e=`${t}${G}`,g=`${t}${Z}`,a=o=>`${t}${_}${o}`;if(globalThis.localStorage.getItem(e)===null)try{globalThis.localStorage.setItem(e,`archive-store
3
+ ${new Date().toISOString()}`);}catch{}function s(){let o=globalThis.localStorage.getItem(g);if(o===null)return {};try{let i=JSON.parse(o);return i&&typeof i=="object"&&!Array.isArray(i)?i:{}}catch{return {}}}function l(o){try{globalThis.localStorage.setItem(g,JSON.stringify(o));}catch{}}function r(){if(globalThis.localStorage.getItem(e)===null)return;let o=s(),i=typeof o["retention.maxAgeMs"]=="number"?o["retention.maxAgeMs"]:0,u=typeof o["retention.sweepIntervalMs"]=="number"?o["retention.sweepIntervalMs"]:0;if(i<=0||u<=0)return;let d=typeof o["retention.lastSweepAt"]=="number"?o["retention.lastSweepAt"]:0,n=Date.now();if(n-d<u)return;o["retention.lastSweepAt"]=n,l(o);let c=`${t}${_}`;for(let f=0;f<globalThis.localStorage.length;f++){let h=globalThis.localStorage.key(f);if(!h||!h.startsWith(c))continue;let y=globalThis.localStorage.getItem(h);if(y)try{let p=JSON.parse(y),S=p.filter(b=>typeof b.__ts!="number"||n-b.__ts<=i);S.length!==p.length&&globalThis.localStorage.setItem(h,JSON.stringify(S));}catch{}}}return {stream(o){let i=K(o),u=a(i);function d(){let c=globalThis.localStorage.getItem(u);if(!c)return [];try{return JSON.parse(c)}catch{return []}}function n(c){try{globalThis.localStorage.setItem(u,JSON.stringify(c));}catch{}}return {append(c){let f={id:globalThis.crypto.randomUUID(),payload:c,__ts:Date.now()},h=d();h.push(f),n(h);try{r();}catch{}return {id:f.id,payload:f.payload}},readAll(){return d().map(c=>({id:c.id,payload:c.payload}))},readAfter(c){let f=d();if(!c){let S=f.map(b=>({id:b.id,payload:b.payload}));return {entries:S,newCursor:S.length>0?S[S.length-1].id:null}}let h=f.findIndex(S=>S.id===c),p=(h===-1?f:f.slice(h+1)).map(S=>({id:S.id,payload:S.payload}));return {entries:p,newCursor:p.length>0?p[p.length-1].id:c}},clear(){try{globalThis.localStorage.removeItem(u);}catch{}}}},blob(o){let i=K(o),u=R(`${t}${U}${i}`);return {read:d=>u.read(d),write:(d,n)=>{u.write(d,n);try{r();}catch{}},exists:d=>u.exists(d),remove:d=>u.remove(d),readBytes:u.readBytes?d=>u.readBytes(d):void 0,writeBytes:u.writeBytes?(d,n)=>{u.writeBytes(d,n);try{r();}catch{}}:void 0,listKeys:d=>u.listKeys(d),stat:u.stat?d=>u.stat(d):void 0}},listStreams(o){let i=`${t}${_}`,u=[];for(let d=0;d<globalThis.localStorage.length;d++){let n=globalThis.localStorage.key(d);if(!n||!n.startsWith(i))continue;let c=n.slice(i.length);(!o||c.startsWith(o))&&u.push(c);}return u.sort()},listBlobs(o){let i=`${t}${U}`,u=new Set;for(let d=0;d<globalThis.localStorage.length;d++){let n=globalThis.localStorage.key(d);if(!n||!n.startsWith(i))continue;let c=n.slice(i.length),f=c.indexOf(":"),h=f===-1?c:c.slice(0,f);(!o||h.startsWith(o))&&u.add(h);}return Array.from(u).sort()},config:{get(o){return s()[o]??null},set(o,i){let u=s();i==null?delete u[o]:u[o]=i,l(u);}}}}function x(t){function e(g){return `${t}:kv:${g}`}return {read(g){let a=globalThis.localStorage.getItem(e(g));if(a===null)return null;try{return JSON.parse(a)}catch{return null}},write(g,a){globalThis.localStorage.setItem(e(g),JSON.stringify(a));},delete(g){globalThis.localStorage.removeItem(e(g));},listKeys(g){let a=e(g??""),s=[];for(let l=0;l<globalThis.localStorage.length;l++){let r=globalThis.localStorage.key(l);r!==null&&r.startsWith(a)&&s.push(r.slice(e("").length));}return s}}}function j(t){function e(){let a=globalThis.localStorage.getItem(t);if(!a)return [];try{return JSON.parse(a)}catch{return []}}function g(a){globalThis.localStorage.setItem(t,JSON.stringify(a));}return {readAllEntries(){return e()},appendEntry(a){let s=e();s.push(a),g(s);},generateId(){return globalThis.crypto.randomUUID()}}}function Y(){let t=false;return {tryAcquire(){return t?null:(t=true,()=>{t=false;})}}}function Q(t){return String(t).replace(/[^a-zA-Z0-9_-]/g,"_")}function tt(t){function e(){let a=globalThis.localStorage.getItem(t);if(!a)return [];try{return JSON.parse(a)}catch{return []}}function g(a){globalThis.localStorage.setItem(t,JSON.stringify(a));}return {append(a){let s={id:globalThis.crypto.randomUUID(),payload:a},l=e();return l.push(s),g(l),s},readAll(){return e()},readAfter(a){let s=e();if(!a)return {entries:s,newCursor:s.length>0?s[s.length-1].id:null};let l=s.findIndex(o=>o.id===a),r=l===-1?s:s.slice(l+1);return {entries:r,newCursor:r.length>0?r[r.length-1].id:a}},clear(){globalThis.localStorage.removeItem(t);}}}function it(t){return M(e=>tt(`${t}:chat:journal:${Q(e)}`),x(`${t}:chat`))}var P=new Map;function F(t){let e=P.get(t);if(!e){let g=new Set;e={publish(a){for(let s of g)s(a);},subscribe(a){return g.add(a),()=>{g.delete(a);}}},P.set(t,e);}return e}function lt(){return {async subscribe(t,e){return t.kind!=="in-memory-bus"?(console.warn(`[in-memory-transport] unsupported kind: ${t.kind}`),()=>{}):F(t.value).subscribe(a=>{let s=a;if(s&&s.kind==="notification-batch"&&Array.isArray(s.notifications)){for(let l of s.notifications)e(l);return}e(a);})}}}function ct(t,e){let g=e?.callbackBaseUrl?{meta:"board-live-cards",howToRun:"http:post",whatToRun:e.callbackBaseUrl}:{meta:"board-live-cards",howToRun:"in-browser",whatToRun:v({kind:"in-browser",value:t})},a=new Map,s=new Map,l=Y();return {kvStorage:r=>x(`${t}:${r}`),blobStorage:r=>R(r?`${t}:${r}`:t),scratchStorage:()=>B(`${t}:scratch`),scratchStorageForRef:r=>B(k(r).value),archiveFactory:()=>J(`${t}:archive`),archiveFactoryForRef:r=>J(k(r).value),journalAdapter:()=>j(`${t}:journal`),lock:l,selfRef:g,async dispatchExecution(r,o){if(r.howToRun==="http:post")try{let i=r.whatToRun,u=typeof i=="object"?i.value:k(i).value,d=await fetch(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});return d.ok?{dispatched:!0}:{dispatched:!1,error:`HTTP ${d.status}: ${d.statusText}`}}catch(i){return {dispatched:false,error:i instanceof Error?i.message:String(i)}}if(r.howToRun==="http:get")try{let i=r.whatToRun,u=typeof i=="object"?i.value:k(i).value,d=new URLSearchParams(Object.entries(o).filter(([,f])=>f!=null).map(([f,h])=>[f,String(h)])),n=`${u}?${d.toString()}`,c=await fetch(n);return c.ok?{dispatched:!0}:{dispatched:!1,error:`HTTP ${c.status}: ${c.statusText}`}}catch(i){return {dispatched:false,error:i instanceof Error?i.message:String(i)}}if(r.howToRun==="in-browser"){let i=r.whatToRun,u=typeof i=="object"?i.value:k(i).value,d=a.get(u);return d?d(r,o):{dispatched:false,error:`No in-browser handler registered for: ${u}`}}return {dispatched:false,error:`Browser adapter: unsupported dispatch kind (got: ${r.howToRun})`}},resolveBlob(r){if(r.kind==="in-memory"){let u=s.get(r.value);if(u==null)throw new Error(`resolveBlob: in-memory blob not found: ${v(r)}`);return u}let i=R(t).read(r.value);if(i===null)throw new Error(`resolveBlob: blob not found: ${v(r)}`);return i},hashFn:O,genId:()=>globalThis.crypto.randomUUID().replace(/-/g,""),kvStorageForRef:r=>x(k(r).value),publishBoardChangeNotifications(r){if(!e?.notifyChannel||r.length===0)return;F(e.notifyChannel).publish({kind:"notification-batch",notifications:r});},onWarn:e?.onWarn,registerHandler(r,o){a.set(r,o);},writeMemoryBlob(r,o){return s.set(r,o),v({kind:"in-memory",value:r})}}}export{ct as createBrowserBoardPlatformAdapter,lt as createInMemoryNotificationTransport,it as createLocalStorageChatStorage,F as getInMemoryNotificationBus};//# sourceMappingURL=board-live-cards-browser-adapter.js.map
3
4
  //# sourceMappingURL=board-live-cards-browser-adapter.js.map
@@ -1,4 +1,4 @@
1
- import { L as LiveCard } from '../board-live-cards-lib-Iq_XAC09.js';
1
+ import { L as LiveCard } from '../board-live-cards-lib-tjYsPt5U.js';
2
2
 
3
3
  /**
4
4
  * card-store-browser-api.ts
@@ -1,2 +1,2 @@
1
- import {createRequire}from'module';import'ajv-formats';var x=createRequire(import.meta.url);x("./jsonata-sync.cjs");var v=createRequire(import.meta.url);v("./jsonata-sync.cjs");function y(n,o){function e(){return n.readIndex()??{}}function r(t,s,i){let a=String(s||"").split(".").filter(Boolean);if(a.length===0)return i&&typeof i=="object"&&!Array.isArray(i)?i:{value:i};let u={...t},c=u;for(let d=0;d<a.length-1;d++){let l=a[d],f=c[l],m=f&&typeof f=="object"&&!Array.isArray(f)?{...f}:{};c[l]=m,c=m;}return c[a[a.length-1]]=i,u}return {readCard(t){let s=e()[t];return !s||!n.cardExists(s.key)?null:n.readCard(s.key)},readCardKey(t){return e()[t]?.key??null},readAllCards(){let t=[];for(let[s,i]of Object.entries(e())){if(!n.cardExists(i.key))continue;let a=n.readCard(i.key);a?t.push(a):o?.(`[card-store] could not read card "${s}" at key "${i.key}"`);}return t},readChecksumIndex(){let t={};for(let[s,i]of Object.entries(e()))t[s]=i.checksum;return t},changedSince(t){let s=e(),i=[];for(let[a,u]of Object.entries(s))t[a]!==u.checksum&&i.push(a);for(let a of Object.keys(t))s[a]||i.push(a);return i},validateUpsert(t,s){let i=e(),a=i[t],u=Object.entries(i).find(([,c])=>c.key===s);return a&&a.key!==s?{ok:false,error:`Card id "${t}" is already mapped to key "${a.key}", cannot remap to "${s}"`}:u&&u[0]!==t?{ok:false,error:`Key "${s}" is already mapped to card id "${u[0]}", cannot remap to "${t}"`}:{ok:true}},writeCard(t,s,i){let a=e(),u=i??a[t]?.key??n.defaultCardKey(t),c=n.writeCard(u,s);a[t]={key:u,checksum:c,updatedAt:new Date().toISOString()},n.writeIndex(a);},patchCard(t,s,i){let a=e(),u=a[t];if(!u||!n.cardExists(u.key))throw new Error(`card "${t}" not found`);let c=n.readCard(u.key);if(!c||typeof c!="object"||Array.isArray(c))throw new Error(`card "${t}" is not patchable`);let d=r(c,s,i),l=n.writeCard(u.key,d);a[t]={key:u.key,checksum:l,updatedAt:new Date().toISOString()},n.writeIndex(a);},removeCard(t){let s=e();s[t]&&(delete s[t],n.writeIndex(s));},readIndex(){return e()}}}function g(n){if(n==null||typeof n!="object")return JSON.stringify(n);if(Array.isArray(n))return `[${n.map(g).join(",")}]`;let o=n;return `{${Object.keys(o).sort().map(r=>`${JSON.stringify(r)}:${g(o[r])}`).join(",")}}`}function p(n,o){let e=o>>>0;for(let r=0;r<n.length;r++)e^=n.charCodeAt(r),e=Math.imul(e,16777619)>>>0;return e}function E(n){let o=g(n),e=p(o,2166136261),r=p(o,3735928559),t=p(o,19088743),s=p(o,4277009102);return [e,r,t,s].map(i=>i.toString(16).padStart(8,"0")).join("")}function T(n){function o(e){return `${n}:kv:${e}`}return {read(e){let r=globalThis.localStorage.getItem(o(e));if(r===null)return null;try{return JSON.parse(r)}catch{return null}},write(e,r){globalThis.localStorage.setItem(o(e),JSON.stringify(r));},delete(e){globalThis.localStorage.removeItem(o(e));},listKeys(e){let r=o(e??""),t=[];for(let s=0;s<globalThis.localStorage.length;s++){let i=globalThis.localStorage.key(s);i!==null&&i.startsWith(r)&&t.push(i.slice(o("").length));}return t}}}function h(n,o){let e={...n};for(let[r,t]of Object.entries(o))t!==null&&typeof t=="object"&&!Array.isArray(t)&&e[r]!==null&&typeof e[r]=="object"&&!Array.isArray(e[r])?e[r]=h(e[r],t):e[r]=t;return e}function k(n,o,e){if(o.length===0)return n;let[r,...t]=o;if(t.length===0)return {...n,[r]:e};let s=n[r]!==null&&typeof n[r]=="object"&&!Array.isArray(n[r])?n[r]:{};return {...n,[r]:k(s,t,e)}}function _(n){let o=T(n);return {read:e=>o.read(e),get(e,r){let t=o.read(e);if(t===null)return null;let s=t;for(let i of r.split(".").filter(Boolean)){if(s===null||typeof s!="object"||Array.isArray(s))return null;s=s[i]??null;}return s??null},write:(e,r)=>o.write(e,r),delete:e=>o.delete(e),listKeys:e=>o.listKeys(e),shallowMerge(e,r){let t=o.read(e)??{};o.write(e,{...t,...r});},deepMerge(e,r){let t=o.read(e)??{};o.write(e,h(t,r));},patch(e,r,t){let s=o.read(e)??{},i=r.split(".").filter(Boolean);o.write(e,k(s,i,t));}}}function S(n){let o=_(n);return {readIndex(){return o.read("_index")},writeIndex(e){o.write("_index",e);},readCard(e){return o.read(e)},writeCard(e,r){return o.write(e,r),E(r)},cardExists(e){return o.read(e)!==null},defaultCardKey(e){return e}}}function he(n){let o=S(n),e=y(o);return {getCard(r){return e.readCard(r)},getAllCards(){return e.readAllCards()},upsertCard(r){let t=o.defaultCardKey(r.id);e.writeCard(r.id,r,t);},removeCard(r){e.removeCard(r);}}}export{he as createBrowserCardStoreApi};//# sourceMappingURL=card-store-browser-api.js.map
1
+ import {createRequire}from'module';import'ajv-formats';var R=createRequire(import.meta.url);R("./jsonata-sync.cjs");var x=createRequire(import.meta.url);x("./jsonata-sync.cjs");function y(n,o){function e(){return n.readIndex()??{}}function r(t,s,i){let a=String(s||"").split(".").filter(Boolean);if(a.length===0)return i&&typeof i=="object"&&!Array.isArray(i)?i:{value:i};let u={...t},c=u;for(let d=0;d<a.length-1;d++){let l=a[d],g=c[l],m=g&&typeof g=="object"&&!Array.isArray(g)?{...g}:{};c[l]=m,c=m;}return c[a[a.length-1]]=i,u}return {readCard(t){let s=e()[t];return !s||!n.cardExists(s.key)?null:n.readCard(s.key)},readCardKey(t){return e()[t]?.key??null},readAllCards(){let t=[];for(let[s,i]of Object.entries(e())){if(!n.cardExists(i.key))continue;let a=n.readCard(i.key);a?t.push(a):o?.(`[card-store] could not read card "${s}" at key "${i.key}"`);}return t},readChecksumIndex(){let t={};for(let[s,i]of Object.entries(e()))t[s]=i.checksum;return t},changedSince(t){let s=e(),i=[];for(let[a,u]of Object.entries(s))t[a]!==u.checksum&&i.push(a);for(let a of Object.keys(t))s[a]||i.push(a);return i},validateUpsert(t,s){let i=e(),a=i[t],u=Object.entries(i).find(([,c])=>c.key===s);return a&&a.key!==s?{ok:false,error:`Card id "${t}" is already mapped to key "${a.key}", cannot remap to "${s}"`}:u&&u[0]!==t?{ok:false,error:`Key "${s}" is already mapped to card id "${u[0]}", cannot remap to "${t}"`}:{ok:true}},writeCard(t,s,i){let a=e(),u=i??a[t]?.key??n.defaultCardKey(t),c=n.writeCard(u,s);a[t]={key:u,checksum:c,updatedAt:new Date().toISOString()},n.writeIndex(a);},patchCard(t,s,i){let a=e(),u=a[t];if(!u||!n.cardExists(u.key))throw new Error(`card "${t}" not found`);let c=n.readCard(u.key);if(!c||typeof c!="object"||Array.isArray(c))throw new Error(`card "${t}" is not patchable`);let d=r(c,s,i),l=n.writeCard(u.key,d);a[t]={key:u.key,checksum:l,updatedAt:new Date().toISOString()},n.writeIndex(a);},removeCard(t){let s=e();s[t]&&(delete s[t],n.writeIndex(s));},readIndex(){return e()}}}function p(n){if(n==null||typeof n!="object")return JSON.stringify(n);if(Array.isArray(n))return `[${n.map(p).join(",")}]`;let o=n;return `{${Object.keys(o).sort().map(r=>`${JSON.stringify(r)}:${p(o[r])}`).join(",")}}`}function f(n,o){let e=o>>>0;for(let r=0;r<n.length;r++)e^=n.charCodeAt(r),e=Math.imul(e,16777619)>>>0;return e}function _(n){let o=p(n),e=f(o,2166136261),r=f(o,3735928559),t=f(o,19088743),s=f(o,4277009102);return [e,r,t,s].map(i=>i.toString(16).padStart(8,"0")).join("")}function T(n){function o(e){return `${n}:kv:${e}`}return {read(e){let r=globalThis.localStorage.getItem(o(e));if(r===null)return null;try{return JSON.parse(r)}catch{return null}},write(e,r){globalThis.localStorage.setItem(o(e),JSON.stringify(r));},delete(e){globalThis.localStorage.removeItem(o(e));},listKeys(e){let r=o(e??""),t=[];for(let s=0;s<globalThis.localStorage.length;s++){let i=globalThis.localStorage.key(s);i!==null&&i.startsWith(r)&&t.push(i.slice(o("").length));}return t}}}function h(n,o){let e={...n};for(let[r,t]of Object.entries(o))t!==null&&typeof t=="object"&&!Array.isArray(t)&&e[r]!==null&&typeof e[r]=="object"&&!Array.isArray(e[r])?e[r]=h(e[r],t):e[r]=t;return e}function S(n,o,e){if(o.length===0)return n;let[r,...t]=o;if(t.length===0)return {...n,[r]:e};let s=n[r]!==null&&typeof n[r]=="object"&&!Array.isArray(n[r])?n[r]:{};return {...n,[r]:S(s,t,e)}}function A(n){let o=T(n);return {read:e=>o.read(e),get(e,r){let t=o.read(e);if(t===null)return null;let s=t;for(let i of r.split(".").filter(Boolean)){if(s===null||typeof s!="object"||Array.isArray(s))return null;s=s[i]??null;}return s??null},write:(e,r)=>o.write(e,r),delete:e=>o.delete(e),listKeys:e=>o.listKeys(e),shallowMerge(e,r){let t=o.read(e)??{};o.write(e,{...t,...r});},deepMerge(e,r){let t=o.read(e)??{};o.write(e,h(t,r));},patch(e,r,t){let s=o.read(e)??{},i=r.split(".").filter(Boolean);o.write(e,S(s,i,t));}}}function k(n){let o=A(n);return {readIndex(){return o.read("_index")},writeIndex(e){o.write("_index",e);},readCard(e){return o.read(e)},writeCard(e,r){return o.write(e,r),_(r)},cardExists(e){return o.read(e)!==null},defaultCardKey(e){return e}}}function ke(n){let o=k(n),e=y(o);return {getCard(r){return e.readCard(r)},getAllCards(){return e.readAllCards()},upsertCard(r){let t=o.defaultCardKey(r.id);e.writeCard(r.id,r,t);},removeCard(r){e.removeCard(r);}}}export{ke as createBrowserCardStoreApi};//# sourceMappingURL=card-store-browser-api.js.map
2
2
  //# sourceMappingURL=card-store-browser-api.js.map
@@ -1,3 +1,143 @@
1
+ /**
2
+ * storage-interface.ts
3
+ *
4
+ * Three minimal storage primitives that together cover all persistence needs
5
+ * of the board-live-cards system. Any backend (Node fs, CosmosDB, Azure Blob,
6
+ * browser localStorage, in-memory test double) implements these three interfaces.
7
+ *
8
+ * The pure-logic stores in board-live-cards-all-stores.ts depend only on these
9
+ * interfaces — never on Node built-ins.
10
+ *
11
+ * Blob — raw string content at a logical, backend-neutral key
12
+ * Journal — append-only log with cursor-based reads
13
+ * KV — key-value store with list/delete
14
+ *
15
+ * Mapping to existing storage adapters:
16
+ *
17
+ * CardStorageAdapter
18
+ * inventory (cardId → { blobRef, checksum, fileMetadata? }) → KV
19
+ * card JSON files → Blob
20
+ * source output files → Blob
21
+ *
22
+ * JournalStorageAdapter → Journal (board-journal.jsonl)
23
+ *
24
+ * ExecutionRequestStore → KV (keyed by journalId, via createFsKvStorage)
25
+ *
26
+ * StateSnapshotStorageAdapter
27
+ * board-graph.json (packed single JSON, written atomically) → Blob
28
+ * per-card sidecars (cards/<id>/runtime, fetched-sources-manifest) → KV
29
+ */
30
+ interface BlobStat {
31
+ key: string;
32
+ size: number;
33
+ updatedAt?: string;
34
+ contentType?: string;
35
+ }
36
+ interface BlobStorage {
37
+ /** Returns raw content string, or null if the blob does not exist. */
38
+ read(key: string): string | null;
39
+ /** Write content at key. Implementations should be atomic (write-rename). */
40
+ write(key: string, content: string): void;
41
+ /** Returns true if a blob exists at key. */
42
+ exists(key: string): boolean;
43
+ /** Delete the blob at key. No-op if it does not exist. */
44
+ remove(key: string): void;
45
+ /** Optional binary read for file-like artifacts. */
46
+ readBytes?(key: string): Uint8Array | null;
47
+ /** Optional binary write for file-like artifacts. */
48
+ writeBytes?(key: string, content: Uint8Array): void;
49
+ /** List all keys that start with the given prefix. */
50
+ listKeys(prefix?: string): string[];
51
+ /** Optional metadata lookup. */
52
+ stat?(key: string): BlobStat | null;
53
+ }
54
+ interface KindValueRef {
55
+ readonly kind: string;
56
+ readonly value: string;
57
+ }
58
+ /** Serialize a KindValueRef to the wire format: b64:<base64url(json)> */
59
+ declare function serializeRef(ref: KindValueRef): string;
60
+ /** Parse a wire-format ref string (b64:<base64url(json)>) into a KindValueRef. */
61
+ declare function parseRef(s: string): KindValueRef;
62
+ interface JournalEntry {
63
+ id: string;
64
+ payload: unknown;
65
+ }
66
+ interface JournalReadResult {
67
+ entries: JournalEntry[];
68
+ /** The id of the last entry returned, suitable for use as the next cursor. */
69
+ newCursor: string | null;
70
+ }
71
+ interface JournalStorage {
72
+ /** Append an entry. The storage layer assigns the id. */
73
+ append(payload: unknown): JournalEntry;
74
+ /** Read ALL entries (for index rebuilds, full replay). */
75
+ readAll(): JournalEntry[];
76
+ /**
77
+ * Read entries appended after the given cursor id.
78
+ * If cursor is null/empty, returns all entries from the beginning.
79
+ */
80
+ readAfter(cursor: string | null): JournalReadResult;
81
+ /** Truncate all entries. Optional — not all backends support it. */
82
+ clear?(): void;
83
+ }
84
+ interface KVStorage {
85
+ /** Returns the stored value, or null if the key does not exist. */
86
+ read(key: string): unknown | null;
87
+ /** Write value at key. Overwrites any existing value. */
88
+ write(key: string, value: unknown): void;
89
+ /** Delete the key. No-op if it does not exist. */
90
+ delete(key: string): void;
91
+ /**
92
+ * List all keys, optionally filtered to those starting with prefix.
93
+ * Order is implementation-defined.
94
+ */
95
+ listKeys(prefix?: string): string[];
96
+ }
97
+ interface ScratchStorage extends BlobStorage {
98
+ /**
99
+ * Allocate a new unique key. Does NOT create any underlying object — caller
100
+ * must write to it (e.g. via a spawned child) before it has content.
101
+ * prefix and suffix are sanitized; both are optional.
102
+ */
103
+ getUniqueKey(prefix?: string, suffix?: string): string;
104
+ /**
105
+ * Allocate a new unique key AND write data at it atomically. Returns the
106
+ * new key. Counts as a write for sweep-trigger purposes.
107
+ */
108
+ create(data: string, prefix?: string, suffix?: string): string;
109
+ /** Resolve a key to a transport-neutral ref (e.g. for child-process handoff). */
110
+ keyRef(key: string): KindValueRef;
111
+ /** Backend-agnostic config bag (used for retention policy and similar knobs). */
112
+ config: {
113
+ get(k: string): unknown;
114
+ set(k: string, v: unknown): void;
115
+ };
116
+ }
117
+ interface ArchiveFactory {
118
+ /** Open (or create) a named append-only stream rooted inside the archive. */
119
+ stream(name: string): JournalStorage;
120
+ /** Open (or create) a named blob namespace rooted inside the archive. */
121
+ blob(name: string): BlobStorage;
122
+ /** List all stream names present in the archive. */
123
+ listStreams(prefix?: string): string[];
124
+ /** List all blob namespace names present in the archive. */
125
+ listBlobs(prefix?: string): string[];
126
+ /** Backend-agnostic config bag (retention knobs and similar). */
127
+ config: {
128
+ get(k: string): unknown;
129
+ set(k: string, v: unknown): void;
130
+ };
131
+ }
132
+ interface AtomicRelayLock {
133
+ /**
134
+ * Attempt to acquire the lock without blocking.
135
+ * Returns a `release` function if successful, or `null` if the lock is
136
+ * already held by another actor (relay: that actor will complete the work).
137
+ */
138
+ tryAcquire(): (() => void) | null;
139
+ }
140
+
1
141
  /**
2
142
  * execution-interface.ts
3
143
  *
@@ -77,6 +217,13 @@
77
217
  * whatToRun: 'b64:<base64url({"kind":"fs-path","value":"/path/to/my-executor.js"})>',
78
218
  * };
79
219
  *
220
+ * // Packaged yaml-flow CLI entrypoint resolved by the Node adapter:
221
+ * const yamlFlowCli: ExecutionRef = {
222
+ * meta: 'chat-handler',
223
+ * howToRun: 'local-node',
224
+ * whatToRun: 'b64:<base64url({"kind":"yaml-flow-cli","value":"chat-store-cli.js"})>',
225
+ * };
226
+ *
80
227
  * // Azure Function task executor with custom arg mapping:
81
228
  * const azureFn: ExecutionRef = {
82
229
  * meta: 'task-executor',
@@ -204,7 +351,9 @@ interface ExecutionRef {
204
351
  * Address of the artifact to run. Two valid forms:
205
352
  * - string: must be KindValueRef wire form `b64:<base64url(json)>` (programmatically generated via serializeRef)
206
353
  * - object: `{ kind: string; value: string }` plain object (human-authored flow files — normalized by the handler factory)
207
- * @example 'b64:<base64url({"kind":"fs-path","value":"/dist/cli/source-cli-task-executor.js"})>'
354
+ * Prefer `kind: 'yaml-flow-cli'` when targeting a packaged public yaml-flow CLI entrypoint.
355
+ * Use `kind: 'fs-path'` for external scripts or non-packaged local executables.
356
+ * @example 'b64:<base64url({"kind":"yaml-flow-cli","value":"chat-store-cli.js"})>'
208
357
  * @example { kind: 'http-url', value: '/api/workiq/ask' }
209
358
  * @example { kind: 'fs-path', value: './my-handler.js' }
210
359
  */
@@ -283,4 +432,4 @@ declare function serializeExecutionRef(ref: ExecutionRef): string;
283
432
  */
284
433
  declare function parseExecutionRef(s: string): ExecutionRef;
285
434
 
286
- export { type ArgsMassaging as A, type ExecutionRef as E, type ExecutionResult as a, executionRefFromScriptPath as e, parseExecutionRef as p, serializeExecutionRef as s };
435
+ export { type ArgsMassaging as A, type BlobStorage as B, type ExecutionRef as E, type JournalStorage as J, type KindValueRef as K, type ScratchStorage as S, type ExecutionResult as a, type KVStorage as b, type ArchiveFactory as c, type AtomicRelayLock as d, executionRefFromScriptPath as e, parseRef as f, serializeRef as g, parseExecutionRef as p, serializeExecutionRef as s };
@@ -1,11 +1,11 @@
1
- import*as c from'fs';import*as d from'path';import {randomUUID}from'crypto';import'proper-lockfile';import*as j from'os';import'net';import'url';import'child_process';var S="b64:";function $(n){let s=n.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-n.length%4)%4),r=globalThis.Buffer;if(r)return r.from(s,"base64").toString("utf8");if(typeof atob=="function"){let i=atob(s),e=new Uint8Array(i.length);for(let t=0;t<i.length;t+=1)e[t]=i.charCodeAt(t);return new TextDecoder().decode(e)}throw new Error("No base64 decoder available in this runtime")}function k(n){if(!n.startsWith(S))throw new Error(`Invalid ref format (expected ${S}<base64url(json)>): ${n}`);let s;try{s=JSON.parse($(n.slice(S.length)));}catch{throw new Error(`Invalid ref format (malformed base64url/json): ${n}`)}if(!s||typeof s!="object")throw new Error(`Invalid ref format (expected object payload): ${n}`);let r=s;if(typeof r.kind!="string"||typeof r.value!="string")throw new Error(`Invalid ref format (payload must contain string kind/value): ${n}`);return {kind:r.kind,value:r.value}}function v(n,s){if(process.platform!=="win32"){c.renameSync(n,s);return}let r=[10,20,40,80,160];for(let i=0;i<=r.length;i++)try{c.renameSync(n,s);return}catch(e){let t=e.code;if((t==="EPERM"||t==="EBUSY")&&i<r.length){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,r[i]);continue}throw e}}function A(n){function s(e){return d.join(n,...e.split("/"))}function r(e){return d.relative(n,e).replace(/\\/g,"/")}function i(e,t){if(c.existsSync(e))for(let a of c.readdirSync(e,{withFileTypes:true})){let o=d.join(e,a.name);if(a.isDirectory()){i(o,t);continue}a.isFile()&&t.push(r(o));}}return {read(e){let t=s(e);if(!c.existsSync(t))return null;try{return c.readFileSync(t,"utf-8")}catch{return null}},write(e,t){let a=s(e),o=`${a}.${process.pid}.${randomUUID()}.tmp`;c.mkdirSync(d.dirname(a),{recursive:true}),c.writeFileSync(o,t,"utf-8"),v(o,a);},exists(e){return c.existsSync(s(e))},remove(e){let t=s(e);try{c.existsSync(t)&&c.unlinkSync(t);}catch{}},readBytes(e){let t=s(e);if(!c.existsSync(t))return null;try{return new Uint8Array(c.readFileSync(t))}catch{return null}},writeBytes(e,t){let a=s(e),o=`${a}.${process.pid}.${randomUUID()}.tmp`;c.mkdirSync(d.dirname(a),{recursive:true}),c.writeFileSync(o,Buffer.from(t)),v(o,a);},listKeys(e){let t=[];i(n,t);let a=t.sort();return e?a.filter(o=>o.startsWith(e)):a},stat(e){let t=s(e);if(!c.existsSync(t))return null;try{let a=c.statSync(t);return {key:e,size:Number(a.size||0),updatedAt:new Date(a.mtimeMs).toISOString()}}catch{return null}}}}function C(){return new Date().toISOString()}function R(n){return new TextEncoder().encode(n).byteLength}function _(n){return n?{key:n.key,size:n.size,updatedAt:n.updatedAt,contentType:n.contentType}:null}function F(n){function s(r){let i=n.stat?_(n.stat(r)):null;if(i)return i;if(!n.exists(r))return null;let e=n.read(r);return e===null?{key:r}:{key:r,size:R(e)}}return {exists(r){return n.exists(r)},putText(r,i,e="text/plain; charset=utf-8"){n.write(r,i);let t=s(r)??{key:r};return t.contentType=e,t.updatedAt=t.updatedAt??C(),t.size=t.size??R(i),t},putBytes(r,i,e="application/octet-stream"){if(n.writeBytes)n.writeBytes(r,i);else {let a=JSON.stringify({__kind:"bytes-array",data:[...i]});n.write(r,a);}let t=s(r)??{key:r};return t.contentType=e,t.updatedAt=t.updatedAt??C(),t.size=t.size??i.byteLength,t},getText(r){let i=n.read(r);if(i===null){if(!n.readBytes)return null;let e=n.readBytes(r);return e===null?null:Buffer.from(e).toString("utf-8")}try{let e=JSON.parse(i);if(e&&e.__kind==="bytes-array"&&Array.isArray(e.data))return new TextDecoder("utf-8").decode(new Uint8Array(e.data))}catch{}return i},getBytes(r){if(n.readBytes){let e=n.readBytes(r);if(e!==null)return e}let i=n.read(r);if(i===null)return null;try{let e=JSON.parse(i);if(e&&e.__kind==="bytes-array"&&Array.isArray(e.data))return new Uint8Array(e.data)}catch{}return new TextEncoder().encode(i)},head:s,list(r=""){return n.listKeys(r).map(i=>s(i)??{key:i}).sort((i,e)=>i.key.localeCompare(e.key))},remove(r){n.remove(r);}}}function E(n){function s(e){return {status:"success",data:e}}function r(e){return {status:"fail",error:e}}function i(e){return {status:"error",error:e instanceof Error?e.message:String(e)}}return {list(e){try{let t=e.params?.prefix??"";return s({artifacts:n.list(t)})}catch(t){return i(t)}},head(e){try{let t=e.params?.key;return t?s({artifact:n.head(t)}):r("head requires params.key")}catch(t){return i(t)}},put(e){try{let t=e.params?.key,a=e.params?.contentType;if(!t)return r("put requires params.key");let o=e.body;if(typeof o=="string")return s({artifact:n.putText(t,o,a)});if(o&&typeof o=="object"&&typeof o.text=="string")return s({artifact:n.putText(t,o.text,a)});if(o&&typeof o=="object"&&Array.isArray(o.bytes)){let f=o.bytes,u=new Uint8Array(f.map(l=>Math.max(0,Math.min(255,Number(l)||0))));return s({artifact:n.putBytes(t,u,a)})}return r("put requires body as string, {text}, or {bytes:number[]}")}catch(t){return i(t)}},get(e){try{let t=e.params?.key,a=e.params?.as??"base64";if(!t)return r("get requires params.key");let o=n.head(t);if(!o)return r(`artifact "${t}" not found`);if(a==="text"){let u=n.getText(t);return u===null?r(`artifact "${t}" not found`):s({key:t,contentType:o.contentType,size:o.size,text:u})}let f=n.getBytes(t);return f===null?r(`artifact "${t}" not found`):s({key:t,contentType:o.contentType,size:o.size,bytes:[...f]})}catch(t){return i(t)}},del(e){try{let t=e.params?.key;return t?(n.remove(t),s({ok:!0})):r("del requires params.key")}catch(t){return i(t)}}}}function w(...n){return d.resolve(...n)}d.join(j.tmpdir(),".board-live-cards-git-bash-cache.json");function y(n,s,r){let i=n.indexOf(s),e=i!==-1?n[i+1]:void 0;if(!e)throw new Error(`Missing ${s}
2
- Usage: ${r}`);return e}function m(n,s){let r=n.indexOf(s);return r!==-1?n[r+1]:void 0}async function T(){let n=[];for await(let s of process.stdin)n.push(Buffer.isBuffer(s)?s:Buffer.from(s));return new Uint8Array(Buffer.concat(n))}var B=["artifacts-store \u2014 generic artifact CRUD on a blob-backed store",""," artifacts-store put --store-ref <ref> --key <key> [--file <path> | --text <text>] [--content-type <mime>]"," artifacts-store get --store-ref <ref> --key <key> [--out <path>] [--as text|bytes]"," artifacts-store head --store-ref <ref> --key <key>"," artifacts-store list --store-ref <ref> [--prefix <prefix>]"," artifacts-store del --store-ref <ref> --key <key>"].join(`
3
- `);async function L(n){let s=n[0],r=n.slice(1);if(!s||s==="help"||s==="--help"||s==="-h"){console.error(B);return}let i=y(r,"--store-ref",`artifacts-store ${s} --store-ref <b64-ref>`),e=k(i).value,t=E(F(A(e)));if(s==="put"){let a=y(r,"--key","artifacts-store put --store-ref <ref> --key <key>"),o=m(r,"--content-type"),f=m(r,"--file"),u=m(r,"--text"),l;if(f)l={bytes:[...new Uint8Array(c.readFileSync(f))]};else if(typeof u=="string")l={text:u};else if(!process.stdin.isTTY)l={bytes:[...await T()]};else throw new Error("put requires --file, --text, or stdin bytes");let p=t.put({params:{key:a,...o?{contentType:o}:{}},body:l});if(p.status!=="success")throw new Error(p.error||"put failed");process.stdout.write(JSON.stringify(p.data,null,2)+`
4
- `);return}if(s==="get"){let a=y(r,"--key","artifacts-store get --store-ref <ref> --key <key>"),o=(m(r,"--as")||"bytes").toLowerCase(),f=m(r,"--out"),u=t.get({params:{key:a,as:o}});if(u.status!=="success")throw new Error(u.error||"get failed");if(o==="text"){let p=u.data.text??"";f?c.writeFileSync(f,p,"utf-8"):process.stdout.write(p);return}let l=new Uint8Array(u.data.bytes??[]);f?c.writeFileSync(f,Buffer.from(l)):process.stdout.write(JSON.stringify({...u.data,bytes:void 0,byteLength:l.byteLength},null,2)+`
1
+ import*as c from'fs';import*as d from'path';import {randomUUID}from'crypto';import'proper-lockfile';import*as E from'os';import'net';import'url';import'child_process';var w="b64:";function B(n){let s=n.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-n.length%4)%4),r=globalThis.Buffer;if(r)return r.from(s,"base64").toString("utf8");if(typeof atob=="function"){let i=atob(s),e=new Uint8Array(i.length);for(let t=0;t<i.length;t+=1)e[t]=i.charCodeAt(t);return new TextDecoder().decode(e)}throw new Error("No base64 decoder available in this runtime")}function k(n){if(!n.startsWith(w))throw new Error(`Invalid ref format (expected ${w}<base64url(json)>): ${n}`);let s;try{s=JSON.parse(B(n.slice(w.length)));}catch{throw new Error(`Invalid ref format (malformed base64url/json): ${n}`)}if(!s||typeof s!="object")throw new Error(`Invalid ref format (expected object payload): ${n}`);let r=s;if(typeof r.kind!="string"||typeof r.value!="string")throw new Error(`Invalid ref format (payload must contain string kind/value): ${n}`);return {kind:r.kind,value:r.value}}function A(n,s){if(process.platform!=="win32"){c.renameSync(n,s);return}let r=[10,20,40,80,160];for(let i=0;i<=r.length;i++)try{c.renameSync(n,s);return}catch(e){let t=e.code;if((t==="EPERM"||t==="EBUSY")&&i<r.length){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,r[i]);continue}throw e}}function v(n){function s(e){return d.join(n,...e.split("/"))}function r(e){return d.relative(n,e).replace(/\\/g,"/")}function i(e,t){if(c.existsSync(e))for(let a of c.readdirSync(e,{withFileTypes:true})){let o=d.join(e,a.name);if(a.isDirectory()){i(o,t);continue}a.isFile()&&t.push(r(o));}}return {read(e){let t=s(e);if(!c.existsSync(t))return null;try{return c.readFileSync(t,"utf-8")}catch{return null}},write(e,t){let a=s(e),o=`${a}.${process.pid}.${randomUUID()}.tmp`;c.mkdirSync(d.dirname(a),{recursive:true}),c.writeFileSync(o,t,"utf-8"),A(o,a);},exists(e){return c.existsSync(s(e))},remove(e){let t=s(e);try{c.existsSync(t)&&c.unlinkSync(t);}catch{}},readBytes(e){let t=s(e);if(!c.existsSync(t))return null;try{return new Uint8Array(c.readFileSync(t))}catch{return null}},writeBytes(e,t){let a=s(e),o=`${a}.${process.pid}.${randomUUID()}.tmp`;c.mkdirSync(d.dirname(a),{recursive:true}),c.writeFileSync(o,Buffer.from(t)),A(o,a);},listKeys(e){let t=[];i(n,t);let a=t.sort();return e?a.filter(o=>o.startsWith(e)):a},stat(e){let t=s(e);if(!c.existsSync(t))return null;try{let a=c.statSync(t);return {key:e,size:Number(a.size||0),updatedAt:new Date(a.mtimeMs).toISOString()}}catch{return null}}}}function C(){return new Date().toISOString()}function R(n){return new TextEncoder().encode(n).byteLength}function $(n){return n?{key:n.key,size:n.size,updatedAt:n.updatedAt,contentType:n.contentType}:null}function F(n){function s(r){let i=n.stat?$(n.stat(r)):null;if(i)return i;if(!n.exists(r))return null;let e=n.read(r);return e===null?{key:r}:{key:r,size:R(e)}}return {exists(r){return n.exists(r)},putText(r,i,e="text/plain; charset=utf-8"){n.write(r,i);let t=s(r)??{key:r};return t.contentType=e,t.updatedAt=t.updatedAt??C(),t.size=t.size??R(i),t},putBytes(r,i,e="application/octet-stream"){if(n.writeBytes)n.writeBytes(r,i);else {let a=JSON.stringify({__kind:"bytes-array",data:[...i]});n.write(r,a);}let t=s(r)??{key:r};return t.contentType=e,t.updatedAt=t.updatedAt??C(),t.size=t.size??i.byteLength,t},getText(r){let i=n.read(r);if(i===null){if(!n.readBytes)return null;let e=n.readBytes(r);return e===null?null:Buffer.from(e).toString("utf-8")}try{let e=JSON.parse(i);if(e&&e.__kind==="bytes-array"&&Array.isArray(e.data))return new TextDecoder("utf-8").decode(new Uint8Array(e.data))}catch{}return i},getBytes(r){if(n.readBytes){let e=n.readBytes(r);if(e!==null)return e}let i=n.read(r);if(i===null)return null;try{let e=JSON.parse(i);if(e&&e.__kind==="bytes-array"&&Array.isArray(e.data))return new Uint8Array(e.data)}catch{}return new TextEncoder().encode(i)},head:s,list(r=""){return n.listKeys(r).map(i=>s(i)??{key:i}).sort((i,e)=>i.key.localeCompare(e.key))},remove(r){n.remove(r);}}}function _(n){function s(e){return {status:"success",data:e}}function r(e){return {status:"fail",error:e}}function i(e){return {status:"error",error:e instanceof Error?e.message:String(e)}}return {list(e){try{let t=e.params?.prefix??"";return s({artifacts:n.list(t)})}catch(t){return i(t)}},head(e){try{let t=e.params?.key;return t?s({artifact:n.head(t)}):r("head requires params.key")}catch(t){return i(t)}},put(e){try{let t=e.params?.key,a=e.params?.contentType;if(!t)return r("put requires params.key");let o=e.body;if(typeof o=="string")return s({artifact:n.putText(t,o,a)});if(o&&typeof o=="object"&&typeof o.text=="string")return s({artifact:n.putText(t,o.text,a)});if(o&&typeof o=="object"&&Array.isArray(o.bytes)){let f=o.bytes,u=new Uint8Array(f.map(l=>Math.max(0,Math.min(255,Number(l)||0))));return s({artifact:n.putBytes(t,u,a)})}return r("put requires body as string, {text}, or {bytes:number[]}")}catch(t){return i(t)}},get(e){try{let t=e.params?.key,a=e.params?.as??"base64";if(!t)return r("get requires params.key");let o=n.head(t);if(!o)return r(`artifact "${t}" not found`);if(a==="text"){let u=n.getText(t);return u===null?r(`artifact "${t}" not found`):s({key:t,contentType:o.contentType,size:o.size,text:u})}let f=n.getBytes(t);return f===null?r(`artifact "${t}" not found`):s({key:t,contentType:o.contentType,size:o.size,bytes:[...f]})}catch(t){return i(t)}},del(e){try{let t=e.params?.key;return t?(n.remove(t),s({ok:!0})):r("del requires params.key")}catch(t){return i(t)}}}}function x(...n){return d.resolve(...n)}d.join(E.tmpdir(),".board-live-cards-git-bash-cache.json");function y(n,s,r){let i=n.indexOf(s),e=i!==-1?n[i+1]:void 0;if(!e)throw new Error(`Missing ${s}
2
+ Usage: ${r}`);return e}function m(n,s){let r=n.indexOf(s);return r!==-1?n[r+1]:void 0}async function T(){let n=[];for await(let s of process.stdin)n.push(Buffer.isBuffer(s)?s:Buffer.from(s));return new Uint8Array(Buffer.concat(n))}var j=["artifacts-store \u2014 generic artifact CRUD on a blob-backed store",""," artifacts-store put --store-ref <ref> --key <key> [--file <path> | --text <text>] [--content-type <mime>]"," artifacts-store get --store-ref <ref> --key <key> [--out <path>] [--as text|bytes]"," artifacts-store head --store-ref <ref> --key <key>"," artifacts-store list --store-ref <ref> [--prefix <prefix>]"," artifacts-store del --store-ref <ref> --key <key>"].join(`
3
+ `);async function L(n){let s=n[0],r=n.slice(1);if(!s||s==="help"||s==="--help"||s==="-h"){console.error(j);return}let i=y(r,"--store-ref",`artifacts-store ${s} --store-ref <b64-ref>`),e=k(i).value,t=_(F(v(e)));if(s==="put"){let a=y(r,"--key","artifacts-store put --store-ref <ref> --key <key>"),o=m(r,"--content-type"),f=m(r,"--file"),u=m(r,"--text"),l;if(f)l={bytes:[...new Uint8Array(c.readFileSync(f))]};else if(typeof u=="string")l={text:u};else if(!process.stdin.isTTY)l={bytes:[...await T()]};else throw new Error("put requires --file, --text, or stdin bytes");let g=t.put({params:{key:a,...o?{contentType:o}:{}},body:l});if(g.status!=="success")throw new Error(g.error||"put failed");process.stdout.write(JSON.stringify(g.data,null,2)+`
4
+ `);return}if(s==="get"){let a=y(r,"--key","artifacts-store get --store-ref <ref> --key <key>"),o=(m(r,"--as")||"bytes").toLowerCase(),f=m(r,"--out"),u=t.get({params:{key:a,as:o}});if(u.status!=="success")throw new Error(u.error||"get failed");if(o==="text"){let g=u.data.text??"";f?c.writeFileSync(f,g,"utf-8"):process.stdout.write(g);return}let l=new Uint8Array(u.data.bytes??[]);f?c.writeFileSync(f,Buffer.from(l)):process.stdout.write(JSON.stringify({...u.data,bytes:void 0,byteLength:l.byteLength},null,2)+`
5
5
  `);return}if(s==="head"){let a=y(r,"--key","artifacts-store head --store-ref <ref> --key <key>"),o=t.head({params:{key:a}});if(o.status!=="success")throw new Error(o.error||"head failed");process.stdout.write(JSON.stringify(o.data,null,2)+`
6
6
  `);return}if(s==="list"){let a=m(r,"--prefix")||"",o=t.list({params:a?{prefix:a}:{}});if(o.status!=="success")throw new Error(o.error||"list failed");process.stdout.write(JSON.stringify(o.data,null,2)+`
7
7
  `);return}if(s==="del"||s==="delete"||s==="rm"){let a=y(r,"--key","artifacts-store del --store-ref <ref> --key <key>"),o=t.del({params:{key:a}});if(o.status!=="success")throw new Error(o.error||"del failed");process.stdout.write(JSON.stringify(o.data,null,2)+`
8
8
  `);return}throw new Error(`Unknown command "${s}"
9
9
 
10
- ${B}`)}var O=process.argv[1]&&w(process.argv[1])===w(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"));O&&L(process.argv.slice(2)).catch(n=>{let s=n instanceof Error?n.message:String(n);console.error(s),process.exit(1);});export{L as cli};//# sourceMappingURL=artifacts-store-cli.js.map
10
+ ${j}`)}var O=process.argv[1]&&x(process.argv[1])===x(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"));O&&L(process.argv.slice(2)).catch(n=>{let s=n instanceof Error?n.message:String(n);console.error(s),process.exit(1);});export{L as cli};//# sourceMappingURL=artifacts-store-cli.js.map
11
11
  //# sourceMappingURL=artifacts-store-cli.js.map
@@ -1 +1,4 @@
1
1
  #!/usr/bin/env node
2
+ declare function cli(args: any): Promise<void>;
3
+
4
+ export { cli };
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import*as h from'fs';import*as s from'path';import {fileURLToPath}from'url';import {spawnSync}from'child_process';var u=s.dirname(fileURLToPath(import.meta.url)),m=s.join(u,"..","..","..","src","cli","node","batch-runner-cli.ts"),S=s.join(u,"..","..","..","node_modules","tsx","dist","cli.mjs");if(h.existsSync(m)){let e=spawnSync(process.execPath,[S,m,...process.argv.slice(2)],{stdio:"inherit",shell:false,windowsHide:true});e.error&&(console.error(`[batch-runner-cli] Failed to launch dev fallback: ${e.error.message}`),process.exit(1)),process.exit(e.status??0);}var v=s.join(u,"..","..","lib","index.js"),E=s.join(u,"..","..","lib","step-machine-public","index.js"),A=s.join(u,"..","..","lib","batch","index.js"),O=s.join(u,"execution-adapter.js"),{loadStepFlow:J,createStepMachine:M,MemoryStore:N}=await import(p(v).href),{buildStepHandlersForFlow:P}=await import(p(E).href),{batch:R}=await import(p(A).href),{invokeRefSync:$}=await import(p(O).href);function p(e){let r=s.resolve(e).replace(/\\/g,"/");return new URL(`file:///${r.startsWith("/")?r.slice(1):r}`)}async function F(){let e=process.argv.slice(2),r=k(e);(r.help||e.length===0)&&(U(),process.exit(e.length===0?1:0));let{flowArg:i,itemsArg:o,concurrency:t}=r;if(!i)throw new Error("[batch-runner-cli] Flow path is required.");if(!o)throw new Error("[batch-runner-cli] --items <json-file-or-inline> is required.");let c=d(i),a=s.dirname(c),w=I(o),f=await J(c),l=await R(w,{concurrency:t,processor:async(n,W)=>{let b=P(f,{invoke:(y,g)=>$(T(y),g,{cliDir:a,cwd:a})});return M(f,b,{store:new N}).run(n)},onProgress:n=>{process.stderr.write(`\r[batch] ${n.completed+n.failed}/${n.total} (${n.percent}%) \u2014 ${n.active} active`);}});process.stderr.write("\r"+" ".repeat(80)+"\r"),console.log(JSON.stringify({completed:l.completed,failed:l.failed,total:l.total,durationMs:l.durationMs,items:l.items.map(n=>({index:n.index,status:n.status,durationMs:n.durationMs,...n.status==="completed"?{intent:n.result?.intent,data:n.result?.data}:{error:n.error?.message}}))},null,2)),l.failed>0&&process.exit(1);}function k(e){let r={},i=[],o=false;for(let t=0;t<e.length;t++){let c=e[t];if(c==="-h"||c==="--help"){o=true;continue}if(c==="--items"){let a=e[t+1];if(!a||a.startsWith("--"))throw new Error("[batch-runner-cli] Missing value for --items.");r["--items"]=a,t++;continue}if(c==="--concurrency"){let a=e[t+1];if(!a||a.startsWith("--"))throw new Error("[batch-runner-cli] Missing value for --concurrency.");r["--concurrency"]=a,t++;continue}if(c.startsWith("--"))throw new Error(`[batch-runner-cli] Unknown flag: ${c}`);i.push(c);}return {help:o,flowArg:i[0],itemsArg:r["--items"],concurrency:r["--concurrency"]?parseInt(r["--concurrency"],10):5}}function d(e){return s.isAbsolute(e)?e:s.resolve(process.cwd(),e)}function I(e){let r=d(e),i;h.existsSync(r)?i=h.readFileSync(r,"utf-8"):i=e;let o;try{o=JSON.parse(i);}catch(t){let c=t instanceof Error?t.message:String(t);throw new Error(`[batch-runner-cli] Failed to parse items JSON: ${c}`)}if(!Array.isArray(o))throw new Error("[batch-runner-cli] Items must be a JSON array of objects.");for(let t=0;t<o.length;t++)if(!o[t]||typeof o[t]!="object"||Array.isArray(o[t]))throw new Error(`[batch-runner-cli] Item at index ${t} is not a JSON object.`);return o}function T(e){if(!e||typeof e!="object"||typeof e.whatToRun!="string"||!e.whatToRun.startsWith("b64:"))return e;try{let r=e.whatToRun.slice(4),i=r+"=".repeat((4-r.length%4)%4),o=Buffer.from(i.replace(/-/g,"+").replace(/_/g,"/"),"base64").toString("utf8"),t=JSON.parse(o);return !t||typeof t!="object"||typeof t.value!="string"?e:{...e,whatToRun:t}}catch{return e}}function U(){console.error("Usage: batch-runner-cli <step-flow.yaml> --items <items.json> [--concurrency <n>]"),console.error(""),console.error("Run a step-machine flow for each item in a JSON array, with concurrency control."),console.error(""),console.error("Options:"),console.error(" --items <path|json> JSON file or inline JSON array of input objects"),console.error(" --concurrency <n> Max concurrent flows (default: 5)"),console.error(" -h, --help Show this help"),console.error(""),console.error("Example:"),console.error(" batch-runner-cli flow.yaml --items items.json --concurrency 3"),console.error(` batch-runner-cli flow.yaml --items '[{"a":1,"b":2},{"a":3,"b":4}]'`);}F().catch(e=>{let r=e instanceof Error?e.stack??e.message:String(e);console.error(r),process.exit(1);});//# sourceMappingURL=batch-runner-cli.js.map
2
+ import*as f from'fs';import*as i from'path';import {fileURLToPath}from'url';import*as y from'os';import'net';import'child_process';import'crypto';function m(...e){return i.resolve(...e)}i.join(y.tmpdir(),".board-live-cards-git-bash-cache.json");var p=i.dirname(fileURLToPath(import.meta.url)),E=i.join(p,"..","..","lib","index.js"),A=i.join(p,"..","..","lib","step-machine-public","index.js"),P=i.join(p,"..","..","lib","batch","index.js"),R=i.join(p,"execution-adapter.js"),{loadStepFlow:$,createStepMachine:C,MemoryStore:B}=await import(g(E).href),{buildStepHandlersForFlow:O}=await import(g(A).href),{batch:J}=await import(g(P).href),{invokeRefSync:M}=await import(g(R).href);function g(e){let n=i.resolve(e).replace(/\\/g,"/");return new URL(`file:///${n.startsWith("/")?n.slice(1):n}`)}async function F(e){let n=I(e);(n.help||e.length===0)&&(T(),process.exit(e.length===0?1:0));let{flowArg:a,itemsArg:r,concurrency:t}=n;if(!a)throw new Error("[batch-runner-cli] Flow path is required.");if(!r)throw new Error("[batch-runner-cli] --items <json-file-or-inline> is required.");let s=w(a),c=i.dirname(s),x=L(r),h=await $(s),l=await J(x,{concurrency:t,processor:async(o,_)=>{let v=O(h,{invoke:(b,S)=>M(U(b),S,{cliDir:c,cwd:c})});return C(h,v,{store:new B}).run(o)},onProgress:o=>{process.stderr.write(`\r[batch] ${o.completed+o.failed}/${o.total} (${o.percent}%) \u2014 ${o.active} active`);}});process.stderr.write("\r"+" ".repeat(80)+"\r"),console.log(JSON.stringify({completed:l.completed,failed:l.failed,total:l.total,durationMs:l.durationMs,items:l.items.map(o=>({index:o.index,status:o.status,durationMs:o.durationMs,...o.status==="completed"?{intent:o.result?.intent,data:o.result?.data}:{error:o.error?.message}}))},null,2)),l.failed>0&&process.exit(1);}function I(e){let n={},a=[],r=false;for(let t=0;t<e.length;t++){let s=e[t];if(s==="-h"||s==="--help"){r=true;continue}if(s==="--items"){let c=e[t+1];if(!c||c.startsWith("--"))throw new Error("[batch-runner-cli] Missing value for --items.");n["--items"]=c,t++;continue}if(s==="--concurrency"){let c=e[t+1];if(!c||c.startsWith("--"))throw new Error("[batch-runner-cli] Missing value for --concurrency.");n["--concurrency"]=c,t++;continue}if(s.startsWith("--"))throw new Error(`[batch-runner-cli] Unknown flag: ${s}`);a.push(s);}return {help:r,flowArg:a[0],itemsArg:n["--items"],concurrency:n["--concurrency"]?parseInt(n["--concurrency"],10):5}}function w(e){return i.isAbsolute(e)?e:i.resolve(process.cwd(),e)}function L(e){let n=w(e),a;f.existsSync(n)?a=f.readFileSync(n,"utf-8"):a=e;let r;try{r=JSON.parse(a);}catch(t){let s=t instanceof Error?t.message:String(t);throw new Error(`[batch-runner-cli] Failed to parse items JSON: ${s}`)}if(!Array.isArray(r))throw new Error("[batch-runner-cli] Items must be a JSON array of objects.");for(let t=0;t<r.length;t++)if(!r[t]||typeof r[t]!="object"||Array.isArray(r[t]))throw new Error(`[batch-runner-cli] Item at index ${t} is not a JSON object.`);return r}function U(e){if(!e||typeof e!="object"||typeof e.whatToRun!="string"||!e.whatToRun.startsWith("b64:"))return e;try{let n=e.whatToRun.slice(4),a=n+"=".repeat((4-n.length%4)%4),r=Buffer.from(a.replace(/-/g,"+").replace(/_/g,"/"),"base64").toString("utf8"),t=JSON.parse(r);return !t||typeof t!="object"||typeof t.value!="string"?e:{...e,whatToRun:t}}catch{return e}}function T(){console.error("Usage: batch-runner-cli <step-flow.yaml> --items <items.json> [--concurrency <n>]"),console.error(""),console.error("Run a step-machine flow for each item in a JSON array, with concurrency control."),console.error(""),console.error("Options:"),console.error(" --items <path|json> JSON file or inline JSON array of input objects"),console.error(" --concurrency <n> Max concurrent flows (default: 5)"),console.error(" -h, --help Show this help"),console.error(""),console.error("Example:"),console.error(" batch-runner-cli flow.yaml --items items.json --concurrency 3"),console.error(` batch-runner-cli flow.yaml --items '[{"a":1,"b":2},{"a":3,"b":4}]'`);}var N=process.argv[1]&&m(process.argv[1])===m(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"));N&&F(process.argv.slice(2)).catch(e=>{let n=e instanceof Error?e.stack??e.message:String(e);console.error(n),process.exit(1);});
3
+ export{F as cli};//# sourceMappingURL=batch-runner-cli.js.map
3
4
  //# sourceMappingURL=batch-runner-cli.js.map