yaml-flow 8.4.25 → 8.5.1

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 (52) hide show
  1. package/browser/asset-integrity.json +3 -3
  2. package/browser/board-livecards-client.js +1 -1
  3. package/cli/browser-api/board-live-cards-browser-adapter.d.ts +1 -1
  4. package/cli/browser-api/board-live-cards-browser-adapter.js +1 -1
  5. package/cli/bundled/board-live-cards-cli.mjs +14 -14
  6. package/cli/bundled/chat-store-cli.mjs +13 -13
  7. package/cli/{types-juH2nFpz.d.ts → types-H3EMBPY2.d.ts} +10 -4
  8. package/examples/board/demo-shell-with-server.html +2 -2
  9. package/examples/board/doc.html +2 -2
  10. package/examples/board/server/README-mcp-api.md +680 -0
  11. package/examples/board/server/board-server.js +4 -0
  12. package/examples/board/server/chat-flow/copilot-chat/assistant.js +4 -2
  13. package/examples/board/server/chat-flow/flow-steps.json +9 -8
  14. package/examples/board/test/server-http-mcp-test.js +1148 -0
  15. package/examples/board/test/server-http-test.js +7 -7
  16. package/examples/board-local/demo-shell-localstorage.html +3 -3
  17. package/lib/artifacts-store-public.d.cts +1 -1
  18. package/lib/artifacts-store-public.d.ts +1 -1
  19. package/lib/board-live-cards-mcp.cjs +2 -0
  20. package/lib/board-live-cards-mcp.d.cts +296 -0
  21. package/lib/board-live-cards-mcp.d.ts +296 -0
  22. package/lib/board-live-cards-mcp.js +2 -0
  23. package/lib/board-live-cards-node.cjs +14 -14
  24. package/lib/board-live-cards-node.d.cts +8 -6
  25. package/lib/board-live-cards-node.d.ts +8 -6
  26. package/lib/board-live-cards-node.js +14 -14
  27. package/lib/{board-live-cards-public-B4RcYPC_.d.cts → board-live-cards-public-B13InXhC.d.cts} +8 -3
  28. package/lib/{board-live-cards-public-ydXuA4zh.d.ts → board-live-cards-public-BGS22cMb.d.ts} +8 -3
  29. package/lib/board-live-cards-public.cjs +1 -1
  30. package/lib/board-live-cards-public.d.cts +1 -1
  31. package/lib/board-live-cards-public.d.ts +1 -1
  32. package/lib/board-live-cards-public.js +1 -1
  33. package/lib/board-live-cards-server-runtime.cjs +5 -4
  34. package/lib/board-live-cards-server-runtime.d.cts +3 -3
  35. package/lib/board-live-cards-server-runtime.d.ts +3 -3
  36. package/lib/board-live-cards-server-runtime.js +5 -4
  37. package/lib/card-store-public.d.cts +1 -1
  38. package/lib/card-store-public.d.ts +1 -1
  39. package/lib/{chat-storage-lib-B1wU27y3.d.cts → chat-storage-lib-0imhRX3l.d.cts} +2 -1
  40. package/lib/{chat-storage-lib-DsF4kPon.d.ts → chat-storage-lib-CJn7a6OH.d.ts} +2 -1
  41. package/lib/chat-store-public.cjs +1 -1
  42. package/lib/chat-store-public.d.cts +7 -2
  43. package/lib/chat-store-public.d.ts +7 -2
  44. package/lib/chat-store-public.js +1 -1
  45. package/lib/server-runtime/index.cjs +5 -4
  46. package/lib/server-runtime/index.d.cts +4 -4
  47. package/lib/server-runtime/index.d.ts +4 -4
  48. package/lib/server-runtime/index.js +5 -4
  49. package/lib/{types-DwPRb-PY.d.ts → types-30R357js.d.ts} +3 -2
  50. package/lib/{types-BpfMamGs.d.cts → types-CIgsh56O.d.cts} +3 -2
  51. package/package.json +10 -2
  52. package/browser/board-livecards-localstorage.js +0 -10
@@ -1,10 +1,10 @@
1
1
  {
2
- "generatedAt": "2026-05-26T13:38:53.635Z",
2
+ "generatedAt": "2026-05-28T17:55:28.807Z",
3
3
  "algorithm": "sha256",
4
4
  "files": {
5
5
  "browser/board-livecards-localstorage.js": {
6
- "sha256": "sha256-zQx5C1Q/oUCZ6/JvWt8s28M8Gz/XGxiPPQw3sq5k6PQ=",
7
- "bytes": 106017
6
+ "sha256": "sha256-u7dL4cNzKLbP4R5Ff04ErNcpwPFEm/N3O5WjakWtlDY=",
7
+ "bytes": 143933
8
8
  },
9
9
  "browser/live-cards.schema.json": {
10
10
  "sha256": "sha256-F5nfqDzZ5L3p0lLTMxGt4YtMa2sVzdNPh8sbQ8OiXHE=",
@@ -1,2 +1,2 @@
1
- var BoardLiveCardsClient=(function(exports){'use strict';function W(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function pt(t,e){let r=e&&typeof e=="object"&&!Array.isArray(e)?e:{};return {schema_version:r.schema_version||"v1",card_id:typeof r.card_id=="string"?r.card_id:t,card_data:r.card_data&&typeof r.card_data=="object"&&!Array.isArray(r.card_data)?structuredClone(r.card_data):{},computed_values:r.computed_values&&typeof r.computed_values=="object"&&!Array.isArray(r.computed_values)?structuredClone(r.computed_values):{}}}function E(t,e){if(!t||typeof t!="object")throw new Error("payload must be an object");if(!e)throw new Error("cardId is required");let h=(Array.isArray(t.cardDefinitions)?t.cardDefinitions:[]).find(C=>C.id===e);if(!h)throw new Error(`cardDefinitions has no entry with id ${e}`);let n=t.statusSnapshot&&typeof t.statusSnapshot=="object"?t.statusSnapshot:{},o=t.cardRuntimeById&&typeof t.cardRuntimeById=="object"?t.cardRuntimeById:{},y=t.dataObjectsByToken&&typeof t.dataObjectsByToken=="object"?t.dataObjectsByToken:{},u=(Array.isArray(n.cards)?n.cards:[]).find(C=>C.name===e),l=structuredClone(h),i=pt(e,o[e]),s={...l.card_data&&typeof l.card_data=="object"&&!Array.isArray(l.card_data)?l.card_data:{},...i.card_data||{},status:W(u?.status),lastRun:u?.runtime?.last_transition_at??null};u?.error?.message&&(s.error=u.error.message);let g=u?{task_status:u.status??null,card_status:W(u.status),runtime:structuredClone(u.runtime??{}),error:u.error?structuredClone(u.error):null,blocked_by:Array.isArray(u.blocked_by)?structuredClone(u.blocked_by):[],requires_missing:Array.isArray(u.requires_missing)?structuredClone(u.requires_missing):[]}:{task_status:null,card_status:s.status??"fresh",runtime:{last_transition_at:s.lastRun??null},error:s.error?{message:s.error}:null,blocked_by:[],requires_missing:[]},k=Array.isArray(l.requires)?l.requires:[],c={};for(let[C,x]of Object.entries(y))c[C]=structuredClone(x);for(let C of k)Object.prototype.hasOwnProperty.call(c,C)||(c[C]=null);let d=(t.cardChatsByCardId&&typeof t.cardChatsByCardId=="object"?t.cardChatsByCardId:{})[e],S=d?{messages:Array.isArray(d.messages)?d.messages:[],receiving:!!d.receiving,processing:!!d.processing}:null;return {id:e,card:l,card_data:s,requires:c,computed_values:i.computed_values,runtime_state:g,card_chats:S}}function U(t){if(!t||typeof t!="object")throw new Error("payload must be an object");return (Array.isArray(t.cardDefinitions)?t.cardDefinitions:[]).map(r=>E(t,r.id))}function G(t){return JSON.parse(JSON.stringify(t))}function B(t,e){if(t===e)return t;try{if(JSON.stringify(t)===JSON.stringify(e))return t}catch{}return e}function _(t,e){if(t===e)return true;try{return JSON.stringify(t)===JSON.stringify(e)}catch{return false}}function gt(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function q(t,e,r){let h=t,o=(h&&Array.isArray(h.cardDefinitions)?h.cardDefinitions:[]).map(u=>u.id),y=e&&e.modelsById||{},m={};for(let u of o){let l=r(t,u),i=y[u];if(!i){m[u]=l;continue}let p=l.card_chats!=null?B(i.card_chats,l.card_chats??null):i.card_chats??null,s={id:l.id,card:B(i.card,l.card),card_data:B(i.card_data,l.card_data),requires:B(i.requires,l.requires),computed_values:B(i.computed_values,l.computed_values),runtime_state:B(i.runtime_state,l.runtime_state),card_chats:p};m[u]=s.card===i.card&&s.card_data===i.card_data&&s.requires===i.requires&&s.computed_values===i.computed_values&&s.runtime_state===i.runtime_state&&s.card_chats===i.card_chats?i:s;}return {payload:t,cardIds:o,modelsById:m}}function H(t,e={}){if(!t)return t;let r=typeof e.includeCard=="function"?e.includeCard:(()=>true),h=typeof e.mapCard=="function"?e.mapCard:(u=>u),n=false,o=[],y={};for(let u of t.cardIds){let l=t.modelsById[u];if(!l){n=true;continue}if(!r(l,t)){n=true;continue}let i=h(l,t);if(!i||i.id!==u)throw new Error(`deriveBoardState: mapped card must preserve id "${u}"`);i!==l&&(n=true),o.push(u),y[u]=i;}let m=typeof e.mapPayload=="function"?e.mapPayload(t.payload,{sourceState:t,cardIds:o,modelsById:y}):t.payload;return m!==t.payload&&(n=true),!n&&o.length===t.cardIds.length?t:{payload:m,cardIds:o,modelsById:y}}function J(t,e,r,h){if(!t||!Array.isArray(e)||e.length===0)return t;let n=t.modelsById,o=t.cardIds,y=false,m=false,u={};for(let i of o){let p=n[i],s=p&&p.requires;if(s&&typeof s=="object")for(let g of Object.keys(s))(u[g]=u[g]||[]).push(i);}function l(){y||(n={...n},y=true);}for(let i of e)if(!(!i||!i.kind)){if(i.kind==="computed_values"){let p=i.cardId,s=n[p];if(!s)continue;let g=i.values||{};if(_(s.computed_values,g))continue;l(),n[p]={...s,computed_values:g},m=true;}else if(i.kind==="data_object"){let p=i.key,s=i.payload,g=u[p]||[];for(let k of g){let c=n[k];if(!c)continue;let w=c.requires||{};_(w[p],s)||(l(),n[k]={...c,requires:{...w,[p]:s}},m=true);}}else if(i.kind==="card_refreshed"){let p=i.cardId,s=null,g=n[p],k=i.card;if(g&&k&&typeof k=="object"&&!Array.isArray(k)){let c=k,w=c.card_data&&typeof c.card_data=="object"&&!Array.isArray(c.card_data)?c.card_data:g.card_data,d=c.requires&&typeof c.requires=="object"&&!Array.isArray(c.requires)?c.requires:g.requires,S=c.computed_values&&typeof c.computed_values=="object"&&!Array.isArray(c.computed_values)?c.computed_values:g.computed_values,C=c.runtime_state&&typeof c.runtime_state=="object"&&!Array.isArray(c.runtime_state)?c.runtime_state:g.runtime_state;s={...g,card:k,card_data:w,requires:d,computed_values:S,runtime_state:C};}if(!s)try{let c=h();c&&(s=r(c,p));}catch{}if(!s||g&&_(g.card,s.card)&&_(g.card_data,s.card_data)&&_(g.requires,s.requires)&&_(g.computed_values,s.computed_values)&&_(g.runtime_state,s.runtime_state))continue;l(),n[p]=s,o.includes(p)||(o=[...o,p]),m=true;}else if(i.kind==="card_removed"){let p=i.cardId;if(!n[p])continue;l(),delete n[p],o=o.filter(s=>s!==p),m=true;}else if(i.kind==="card_chats"){let p=i.cardId,s=n[p];if(!s)continue;let g=Array.isArray(i.messages)?i.messages:s.card_chats?.messages??[],k=typeof i.receiving=="boolean"?i.receiving:s.card_chats?.receiving??false,c=typeof i.processing=="boolean"?i.processing:s.card_chats?.processing??false,w={messages:g,receiving:k,processing:c};if(_(s.card_chats,w))continue;l(),n[p]={...s,card_chats:w},m=true;}else if(i.kind==="chat_messages"){let p=i.cardId,s=n[p];if(!s)continue;let g=Array.isArray(i.messages)?i.messages:[],k=s.card_chats||{receiving:false,processing:false},c={messages:g,receiving:k.receiving,processing:!!k.processing};if(_(s.card_chats,c))continue;l(),n[p]={...s,card_chats:c},m=true;}else if(i.kind==="status"){let p=i.status?.cards??[];for(let s of p){let g=s?.name;if(!g||!n[g])continue;let k=n[g],c=gt(s.status),w={...k.card_data||{},status:c,lastRun:s.runtime?.last_transition_at??null,...s.error?.message?{error:s.error.message}:{}};s.error?.message||delete w.error;let d={task_status:s.status??null,card_status:c,runtime:s.runtime?G(s.runtime):{},error:s.error?G(s.error):null,blocked_by:Array.isArray(s.blocked_by)?G(s.blocked_by):[],requires_missing:Array.isArray(s.requires_missing)?G(s.requires_missing):[]};_(k.card_data,w)&&_(k.runtime_state,d)||(l(),n[g]={...k,card_data:w,runtime_state:d},m=true);}}}return m?{payload:t.payload,cardIds:o,modelsById:n}:t}function Ie(t,e="/api/boards"){let r=e.replace(/\/$/,""),h=encodeURIComponent(t||"default"),n=`${r}/${h}`;return {initBoard:`${n}/init-board`,stream:`${n}/sse`,patchCard:o=>`${n}/cards/${encodeURIComponent(o)}`,retriggerCard:o=>`${n}/cards/${encodeURIComponent(o)}/retrigger`,cardAction:o=>`${n}/cards/${encodeURIComponent(o)}/actions`,cardFile:o=>`${n}/cards/${encodeURIComponent(o)}/files`,cardChats:o=>`${n}/cards/${encodeURIComponent(o)}/chats`,chatSubscribeSse:o=>`${n}/cards/${encodeURIComponent(o)}/chats/subscribe-sse`,chatUnsubscribeSse:o=>`${n}/cards/${encodeURIComponent(o)}/chats/unsubscribe-sse`}}function Be(t="/api/board"){let e=t.replace(/\/$/,"");return {initBoard:`${e}/init-board`,stream:`${e}/sse`,patchCard:r=>`${e}/cards/${encodeURIComponent(r)}`,retriggerCard:r=>`${e}/cards/${encodeURIComponent(r)}/retrigger`,cardAction:r=>`${e}/cards/${encodeURIComponent(r)}/actions`,cardFile:r=>`${e}/cards/${encodeURIComponent(r)}/files`,cardChats:r=>`${e}/cards/${encodeURIComponent(r)}/chats`,chatSubscribeSse:r=>`${e}/cards/${encodeURIComponent(r)}/chats/subscribe-sse`,chatUnsubscribeSse:r=>`${e}/cards/${encodeURIComponent(r)}/chats/unsubscribe-sse`}}function ht(t){let e=t.getServerOrigin();if(!e||!t.boardId)return null;let r=t.boardPaths(t.boardId);return `${e}${r.initBoard.replace(/\/init-board$/,"")}`}async function Z(t){if(!t.file)return null;let e=t.boardPaths(t.boardId),r=t.inChat?`${e.cardFile(t.cardId)}?inChat=true`:e.cardFile(t.cardId),h=typeof t.file.name=="string"?t.file.name:"upload.bin",n=t.file.type||"application/octet-stream",o=await t.fetchServer(r,{method:"POST",headers:{"content-type":n,"x-file-name":encodeURIComponent(h)},body:t.file});if(!o.ok){let m=await o.text();throw new Error(`Upload failed for ${t.cardId} (${o.status})${m?": "+m:""}`)}return (await o.json())?.file??null}async function mt(t){let{actionType:e}=t;if(e!=="chat-send"&&e!=="file-upload")return t.payload||{};let r={...t.payload||{}},h=Array.isArray(r.files)?r.files:[];if(!h.length)return r.files=[],r;let n=[];for(let o of h){let y=await Z({...t,file:o,inChat:e==="chat-send"});y&&n.push(y);}return r.files=e==="chat-send"?[]:n,r}async function yt(t){let e=t.boardPaths(t.boardId),r=await t.fetchServer(e.patchCard(t.cardId),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(t.patch||{})});if(!r.ok)throw new Error(`PATCH failed for ${t.cardId} (${r.status})`)}async function kt(t){let e=t.boardPaths(t.boardId),r=await t.fetchServer(e.retriggerCard(t.cardId),{method:"POST"});if(!r.ok)throw new Error(`retrigger failed for ${t.cardId} (${r.status})`)}async function St(t){let e=t.boardPaths(t.boardId),r=await mt(t),h=await t.fetchServer(e.cardAction(t.cardId),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({actionType:t.actionType,payload:r})});if(!h.ok)throw new Error(`${t.actionType==="refresh"?"Refresh":"Action"} failed for ${t.cardId} (${h.status})`);return {payload:r}}function Oe(t,e=null){return q(t,e,E)}function Pe(t,e,r){return J(t,e,E,r)}function De(t,e){let r=new Set(e.map(String)),h=t.cardIds.filter(o=>r.has(o)),n={};for(let o of h)n[o]=t.modelsById[o];return {payload:t.payload,cardIds:h,modelsById:n}}function je(t,e){let r=e instanceof Set?e:new Set(e.map(String)),h=t.cardIds.filter(o=>!r.has(o)),n={};for(let o of h)n[o]=t.modelsById[o];return {payload:t.payload,cardIds:h,modelsById:n}}function vt(t){let e=t?.core,r=t?.engine??e?.engine;r&&typeof r.onServerSseEvent=="function"?r.onServerSseEvent():r&&typeof r.refreshOpenChatModal=="function"&&r.refreshOpenChatModal();}function bt(){let t=globalThis.LiveCard;if(!t)throw new Error("LiveCard global not loaded \u2014 include live-cards.js before this script");return t}function Ct(t){if(!t||typeof t!="object")throw new Error("options are required");let{fetchServer:e,boardPaths:r,getServerOrigin:h}=t;if(typeof e!="function")throw new Error("options.fetchServer is required");if(typeof r!="function")throw new Error("options.boardPaths is required");if(typeof h!="function")throw new Error("options.getServerOrigin is required");let n={current:null},o=new Set,y=null,m=null,u=null,l={},i={},p=globalThis.crypto&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():`lc-${Date.now()}-${Math.random().toString(36).slice(2)}`;function s(){for(let a of o)a(n.current);}function g(){return n.current?n.current.payload:null}function k(a){return n.current=a,s(),n.current}function c(){let a=m;if(!a)throw new Error("Board runtime session is not bound to a board yet");let f=u??r(a);return u=f,{boardId:a,paths:f}}function w(a){let f=q(a,n.current,E);return k(f),f}function d(a,f){let b=q(a,f??n.current,E);return k(b),b}function S(a){return k(a)}function C(a){if(!n.current)return n.current;let f=J(n.current,a,E,g);return k(f),f}async function x(a,f,b){let{boardId:R}=c();return Z({fetchServer:e,boardPaths:r,boardId:R,cardId:a,file:f,inChat:b?.inChat})}async function M(a,f,b){let{boardId:R}=c();return f==="chat-send"&&await A(a),St({fetchServer:e,boardPaths:r,boardId:R,cardId:a,actionType:f,payload:b})}function v(a,f){return i[a]=f,f.finally(()=>{i[a]===f&&delete i[a];})}async function A(a){let f=i[a];if(f){await f;return}l[a]||await K(a);}async function $(a,f){let{boardId:b}=c();await yt({fetchServer:e,boardPaths:r,boardId:b,cardId:a,patch:f});}async function tt(a){let{boardId:f}=c();await kt({fetchServer:e,boardPaths:r,boardId:f,cardId:a});}async function K(a){let{paths:f}=c(),b=i[a];if(b){await b;return}if(l[a])return;l[a]=true;let R=(async()=>{await e(f.chatSubscribeSse(a),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:p})});})().catch(()=>{delete l[a];});await v(a,R);}async function et(a){let{paths:f}=c(),b=i[a];if(b)try{await b;}catch{}delete l[a];try{await e(f.chatUnsubscribeSse(a),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:p})});}catch{}}function rt(a){Object.keys(l).forEach(f=>{e(a.chatSubscribeSse(f),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:p})}).catch(()=>{});});}function V(a){let f=a;f?.kind==="notification-batch"&&Array.isArray(f.notifications)?C(f.notifications):f?.cardDefinitions&&w(f);}function nt(a){return m=String(a.boardId||"default"),u=r(m),a.state!==void 0?S(a.state??null):a.payload?d(a.payload,n.current):n.current}function st(a){return V(a),n.current}function F(){y&&(y.close(),y=null);}async function at(a={}){let f=String(a.boardId||m||"default");m=f;let b=r(f);if(u=b,a.initialState!==void 0?S(a.initialState??null):a.initialPayload!==void 0&&d(a.initialPayload,n.current),a.skipInitBoard!==true){let O=typeof a.taskExecutorPath=="string"?a.taskExecutorPath.trim():"",P=O?`${b.initBoard}?taskExecutorPath=${encodeURIComponent(O)}`:b.initBoard,T=await e(P);if(!T.ok)throw new Error(`Server init-board failed (${T.status}).`)}let R=h();if(!R)throw new Error("Server origin not resolved before SSE start");F();let I=!n.current,dt=`${R}${b.stream}${b.stream.includes("?")?"&":"?"}clientId=${encodeURIComponent(p)}`,X=await new Promise((O,P)=>{let T=new EventSource(dt);y=T;let D=false,j=I?setTimeout(()=>{D||P(new Error("SSE initial payload timeout (15s)"));},15e3):null;T.onopen=()=>{rt(b),I||O(n.current?.payload??null);},T.onmessage=ct=>{try{let N=JSON.parse(ct.data||"{}");V(N),!D&&I&&(N?.cardDefinitions||U(N))&&(D=!0,j&&clearTimeout(j),O(N));}catch{if(!I)return}},T.onerror=()=>{I&&!D&&(j&&clearTimeout(j),P(new Error("SSE connection failed during bootstrap")));};});if(I){if(!U(X))throw new Error("SSE payload missing published runtime artifacts");w(X);}return n.current}function ot(a){return o.add(a),a(n.current),()=>{o.delete(a);}}function it(){F(),Object.keys(l).forEach(a=>delete l[a]),u=null,m=null,o.clear(),n.current=null;}return {bootstrap:at,attachProvidedState:nt,applyServerUpdate:st,seedStateFromPayload:d,seedState:S,applyNotificationBatch:C,replacePayload:w,subscribe:ot,closeSse:F,isConnected:()=>y!=null,getState:()=>n.current,getPayload:g,getBoardId:()=>m,getClientId:()=>p,getSseClientId:()=>p,patchCardState:$,retriggerCard:tt,dispatchCardAction:M,uploadCardFile:x,subscribeCardChats:K,unsubscribeCardChats:et,dispose:it}}function Q(t){if(!t||typeof t!="object")throw new Error("options are required");if(!t.session)throw new Error("options.session is required");let{session:e,...r}=t,h=t.session&&"canvas"in t&&typeof t.canvas=="object"?t.canvas:{height:"72vh",overflow:"auto"},n=e.getState()?H(e.getState(),r):null,o=null,y=String(t.initialMode||"board"),m=new Set;function u(){for(let d of m)d(n);}function l(d){n=d?H(d,r):null,u(),o&&n&&(o.setState(()=>n),vt(o));}let i=e.subscribe(d=>{l(d);});function p(d){if(!n)throw new Error("Derived board runtime has no state to mount");let S=d?.rootElement;if(!S)throw new Error("mountBoard requires params.rootElement");y=String(d?.mode||y||"board");let C=r.boardPaths&&r.getServerOrigin&&e.getBoardId()?ht({boardPaths:r.boardPaths,getServerOrigin:r.getServerOrigin,boardId:e.getBoardId()}):null,x=bt(),M=x.init({resolve:v=>n?.modelsById[v],chartLib:globalThis.Chart??null,markdown:globalThis.marked?v=>globalThis.marked.parse(v):null,sanitize:globalThis.DOMPurify?v=>globalThis.DOMPurify.sanitize(v):null,onPatchState:(v,A)=>e.patchCardState(v,A),onRefresh:v=>e.retriggerCard(v),onAction:(v,A,$)=>e.dispatchCardAction(v,A,$).then(()=>{}),startReceivingChats:v=>{e.subscribeCardChats(v);},stopReceivingChats:v=>{e.unsubscribeCardChats(v);},fileUrlBase:C||void 0});return S.innerHTML="",o=x.Board(M,S,{initialState:n,getNodeIds:v=>v.cardIds,selectNode:(v,A)=>v.modelsById[A],mode:y,canvas:h}),o}function s(d){return m.add(d),d(n),()=>{m.delete(d);}}function g(d){y=String(d||"board");let S=o&&o.core;S&&typeof S.setMode=="function"&&S.setMode(y);}function k(){if(!o)return;y="canvas";let d=o.core;d&&typeof d.setMode=="function"&&d.setMode("canvas"),d&&typeof d.autoLayout=="function"&&d.autoLayout();}function c(d){let S=o&&o.core;S&&typeof S.setDevMode=="function"&&S.setDevMode(!!d);}function w(){i(),m.clear(),o=null;}return {mountBoard:p,subscribe:s,getState:()=>n,getFullState:()=>e.getState(),getBoardId:()=>e.getBoardId(),getClientId:()=>e.getClientId(),getSseClientId:()=>e.getSseClientId(),patchCardState:(d,S)=>e.patchCardState(d,S),retriggerCard:d=>e.retriggerCard(d),dispatchCardAction:(d,S,C)=>e.dispatchCardAction(d,S,C),uploadCardFile:(d,S,C)=>e.uploadCardFile(d,S,C),subscribeCardChats:d=>e.subscribeCardChats(d),unsubscribeCardChats:d=>e.unsubscribeCardChats(d),setMode:g,autoLayout:k,setDevMode:c,getCurrentMode:()=>y,dispose:w}}function Ne(t){let e=Ct(t),r=Q({session:e,boardPaths:t.boardPaths,getServerOrigin:t.getServerOrigin});async function h(n){let o=String(n?.boardId||"default");return await e.bootstrap({boardId:o,taskExecutorPath:n?.taskExecutorPath}),r.mountBoard({rootElement:n.rootElement,mode:n.mode})}return {bootstrapBoard:h,dispose:()=>{r.dispose(),e.dispose();},setMode:n=>r.setMode(n),autoLayout:()=>r.autoLayout(),setDevMode:n=>r.setDevMode(n),getCurrentMode:()=>r.getCurrentMode(),getState:()=>e.getState(),getRuntimeSession:()=>e,createDerivedRuntime:(n={})=>Q({session:e,...n})}}exports.applyBoardNotifications=Pe;exports.applyNotification=J;exports.buildBoardState=q;exports.buildFileUrlBase=ht;exports.createBoardRuntimeClient=Ne;exports.createBoardRuntimeSession=Ct;exports.createDerivedBoardRuntime=Q;exports.defaultBoardPaths=Ie;exports.deriveBoardState=H;exports.dispatchCardAction=St;exports.patchCardState=yt;exports.pickBoardState=De;exports.prepareActionPayload=mt;exports.retriggerCard=kt;exports.selectAllLiveCardModels=U;exports.selectLiveCardModel=E;exports.serverPayloadToBoardState=Oe;exports.singleBoardPaths=Be;exports.subtractBoardState=je;exports.uploadCardFile=Z;return exports;})({});//# sourceMappingURL=board-livecards-client.js.map
1
+ var BoardLiveCardsClient=(function(exports){'use strict';function W(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function pt(t,e){let r=e&&typeof e=="object"&&!Array.isArray(e)?e:{};return {schema_version:r.schema_version||"v1",card_id:typeof r.card_id=="string"?r.card_id:t,card_data:r.card_data&&typeof r.card_data=="object"&&!Array.isArray(r.card_data)?structuredClone(r.card_data):{},computed_values:r.computed_values&&typeof r.computed_values=="object"&&!Array.isArray(r.computed_values)?structuredClone(r.computed_values):{}}}function E(t,e){if(!t||typeof t!="object")throw new Error("payload must be an object");if(!e)throw new Error("cardId is required");let m=(Array.isArray(t.cardDefinitions)?t.cardDefinitions:[]).find(C=>C.id===e);if(!m)throw new Error(`cardDefinitions has no entry with id ${e}`);let n=t.statusSnapshot&&typeof t.statusSnapshot=="object"?t.statusSnapshot:{},o=t.cardRuntimeById&&typeof t.cardRuntimeById=="object"?t.cardRuntimeById:{},y=t.dataObjectsByToken&&typeof t.dataObjectsByToken=="object"?t.dataObjectsByToken:{},u=(Array.isArray(n.cards)?n.cards:[]).find(C=>C.name===e),l=structuredClone(m),i=pt(e,o[e]),s={...l.card_data&&typeof l.card_data=="object"&&!Array.isArray(l.card_data)?l.card_data:{},...i.card_data||{},status:W(u?.status),lastRun:u?.runtime?.last_transition_at??null};u?.error?.message&&(s.error=u.error.message);let g=u?{task_status:u.status??null,card_status:W(u.status),runtime:structuredClone(u.runtime??{}),error:u.error?structuredClone(u.error):null,blocked_by:Array.isArray(u.blocked_by)?structuredClone(u.blocked_by):[],requires_missing:Array.isArray(u.requires_missing)?structuredClone(u.requires_missing):[]}:{task_status:null,card_status:s.status??"fresh",runtime:{last_transition_at:s.lastRun??null},error:s.error?{message:s.error}:null,blocked_by:[],requires_missing:[]},k=Array.isArray(l.requires)?l.requires:[],c={};for(let[C,x]of Object.entries(y))c[C]=structuredClone(x);for(let C of k)Object.prototype.hasOwnProperty.call(c,C)||(c[C]=null);let d=(t.cardChatsByCardId&&typeof t.cardChatsByCardId=="object"?t.cardChatsByCardId:{})[e],S=d?{messages:Array.isArray(d.messages)?d.messages:[],receiving:!!d.receiving,processing:!!d.processing}:null;return {id:e,card:l,card_data:s,requires:c,computed_values:i.computed_values,runtime_state:g,card_chats:S}}function U(t){if(!t||typeof t!="object")throw new Error("payload must be an object");return (Array.isArray(t.cardDefinitions)?t.cardDefinitions:[]).map(r=>E(t,r.id))}function G(t){return JSON.parse(JSON.stringify(t))}function B(t,e){if(t===e)return t;try{if(JSON.stringify(t)===JSON.stringify(e))return t}catch{}return e}function _(t,e){if(t===e)return true;try{return JSON.stringify(t)===JSON.stringify(e)}catch{return false}}function gt(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function q(t,e,r){let m=t,o=(m&&Array.isArray(m.cardDefinitions)?m.cardDefinitions:[]).map(u=>u.id),y=e&&e.modelsById||{},h={};for(let u of o){let l=r(t,u),i=y[u];if(!i){h[u]=l;continue}let p=l.card_chats!=null?B(i.card_chats,l.card_chats??null):i.card_chats??null,s={id:l.id,card:B(i.card,l.card),card_data:B(i.card_data,l.card_data),requires:B(i.requires,l.requires),computed_values:B(i.computed_values,l.computed_values),runtime_state:B(i.runtime_state,l.runtime_state),card_chats:p};h[u]=s.card===i.card&&s.card_data===i.card_data&&s.requires===i.requires&&s.computed_values===i.computed_values&&s.runtime_state===i.runtime_state&&s.card_chats===i.card_chats?i:s;}return {payload:t,cardIds:o,modelsById:h}}function H(t,e={}){if(!t)return t;let r=typeof e.includeCard=="function"?e.includeCard:(()=>true),m=typeof e.mapCard=="function"?e.mapCard:(u=>u),n=false,o=[],y={};for(let u of t.cardIds){let l=t.modelsById[u];if(!l){n=true;continue}if(!r(l,t)){n=true;continue}let i=m(l,t);if(!i||i.id!==u)throw new Error(`deriveBoardState: mapped card must preserve id "${u}"`);i!==l&&(n=true),o.push(u),y[u]=i;}let h=typeof e.mapPayload=="function"?e.mapPayload(t.payload,{sourceState:t,cardIds:o,modelsById:y}):t.payload;return h!==t.payload&&(n=true),!n&&o.length===t.cardIds.length?t:{payload:h,cardIds:o,modelsById:y}}function J(t,e,r,m){if(!t||!Array.isArray(e)||e.length===0)return t;let n=t.modelsById,o=t.cardIds,y=false,h=false,u={};for(let i of o){let p=n[i],s=p&&p.requires;if(s&&typeof s=="object")for(let g of Object.keys(s))(u[g]=u[g]||[]).push(i);}function l(){y||(n={...n},y=true);}for(let i of e)if(!(!i||!i.kind)){if(i.kind==="computed_values"){let p=i.cardId,s=n[p];if(!s)continue;let g=i.values||{};if(_(s.computed_values,g))continue;l(),n[p]={...s,computed_values:g},h=true;}else if(i.kind==="data_object"){let p=i.key,s=i.payload,g=u[p]||[];for(let k of g){let c=n[k];if(!c)continue;let w=c.requires||{};_(w[p],s)||(l(),n[k]={...c,requires:{...w,[p]:s}},h=true);}}else if(i.kind==="card_refreshed"){let p=i.cardId,s=null,g=n[p],k=i.card;if(g&&k&&typeof k=="object"&&!Array.isArray(k)){let c=k,w=c.card_data&&typeof c.card_data=="object"&&!Array.isArray(c.card_data)?c.card_data:g.card_data,d=c.requires&&typeof c.requires=="object"&&!Array.isArray(c.requires)?c.requires:g.requires,S=c.computed_values&&typeof c.computed_values=="object"&&!Array.isArray(c.computed_values)?c.computed_values:g.computed_values,C=c.runtime_state&&typeof c.runtime_state=="object"&&!Array.isArray(c.runtime_state)?c.runtime_state:g.runtime_state;s={...g,card:k,card_data:w,requires:d,computed_values:S,runtime_state:C};}if(!s)try{let c=m();c&&(s=r(c,p));}catch{}if(!s||g&&_(g.card,s.card)&&_(g.card_data,s.card_data)&&_(g.requires,s.requires)&&_(g.computed_values,s.computed_values)&&_(g.runtime_state,s.runtime_state))continue;l(),n[p]=s,o.includes(p)||(o=[...o,p]),h=true;}else if(i.kind==="card_removed"){let p=i.cardId;if(!n[p])continue;l(),delete n[p],o=o.filter(s=>s!==p),h=true;}else if(i.kind==="card_chats"){let p=i.cardId,s=n[p];if(!s)continue;let g=Array.isArray(i.messages)?i.messages:s.card_chats?.messages??[],k=typeof i.receiving=="boolean"?i.receiving:s.card_chats?.receiving??false,c=typeof i.processing=="boolean"?i.processing:s.card_chats?.processing??false,w={messages:g,receiving:k,processing:c};if(_(s.card_chats,w))continue;l(),n[p]={...s,card_chats:w},h=true;}else if(i.kind==="chat_messages"){let p=i.cardId,s=n[p];if(!s)continue;let g=Array.isArray(i.messages)?i.messages:[],k=s.card_chats||{receiving:false,processing:false},c={messages:g,receiving:k.receiving,processing:!!k.processing};if(_(s.card_chats,c))continue;l(),n[p]={...s,card_chats:c},h=true;}else if(i.kind==="status"){let p=i.status?.cards??[];for(let s of p){let g=s?.name;if(!g||!n[g])continue;let k=n[g],c=gt(s.status),w={...k.card_data||{},status:c,lastRun:s.runtime?.last_transition_at??null,...s.error?.message?{error:s.error.message}:{}};s.error?.message||delete w.error;let d={task_status:s.status??null,card_status:c,runtime:s.runtime?G(s.runtime):{},error:s.error?G(s.error):null,blocked_by:Array.isArray(s.blocked_by)?G(s.blocked_by):[],requires_missing:Array.isArray(s.requires_missing)?G(s.requires_missing):[]};_(k.card_data,w)&&_(k.runtime_state,d)||(l(),n[g]={...k,card_data:w,runtime_state:d},h=true);}}}return h?{payload:t.payload,cardIds:o,modelsById:n}:t}function Ie(t,e="/api/boards"){let r=e.replace(/\/$/,""),m=encodeURIComponent(t||"default"),n=`${r}/${m}`;return {initBoard:`${n}/init-board`,stream:`${n}/sse`,patchCard:o=>`${n}/cards/${encodeURIComponent(o)}`,retriggerCard:o=>`${n}/cards/${encodeURIComponent(o)}/retrigger`,cardAction:o=>`${n}/cards/${encodeURIComponent(o)}/actions`,cardFile:o=>`${n}/cards/${encodeURIComponent(o)}/files`,cardChats:o=>`${n}/cards/${encodeURIComponent(o)}/chats`,chatSubscribeSse:o=>`${n}/cards/${encodeURIComponent(o)}/chats/subscribe-sse`,chatUnsubscribeSse:o=>`${n}/cards/${encodeURIComponent(o)}/chats/unsubscribe-sse`}}function Be(t="/api/board"){let e=t.replace(/\/$/,"");return {initBoard:`${e}/init-board`,stream:`${e}/sse`,patchCard:r=>`${e}/cards/${encodeURIComponent(r)}`,retriggerCard:r=>`${e}/cards/${encodeURIComponent(r)}/retrigger`,cardAction:r=>`${e}/cards/${encodeURIComponent(r)}/actions`,cardFile:r=>`${e}/cards/${encodeURIComponent(r)}/files`,cardChats:r=>`${e}/cards/${encodeURIComponent(r)}/chats`,chatSubscribeSse:r=>`${e}/cards/${encodeURIComponent(r)}/chats/subscribe-sse`,chatUnsubscribeSse:r=>`${e}/cards/${encodeURIComponent(r)}/chats/unsubscribe-sse`}}function ht(t){let e=t.getServerOrigin();if(!e||!t.boardId)return null;let r=t.boardPaths(t.boardId);return `${e}${r.initBoard.replace(/\/init-board$/,"")}`}async function Z(t){if(!t.file)return null;let e=t.boardPaths(t.boardId),r=typeof t.turnId=="string"&&t.turnId!=="",m=t.inChat?`${e.cardFile(t.cardId)}?inChat=true${r?`&turn-id=${encodeURIComponent(t.turnId)}`:""}`:e.cardFile(t.cardId),n=typeof t.file.name=="string"?t.file.name:"upload.bin",o=t.file.type||"application/octet-stream",y=await t.fetchServer(m,{method:"POST",headers:{"content-type":o,"x-file-name":encodeURIComponent(n)},body:t.file});if(!y.ok){let u=await y.text();throw new Error(`Upload failed for ${t.cardId} (${y.status})${u?": "+u:""}`)}return (await y.json())?.file??null}async function mt(t){let{actionType:e}=t;if(e!=="chat-send"&&e!=="file-upload")return t.payload||{};let r={...t.payload||{}},m=typeof r["turn-id"]=="string"?String(r["turn-id"]):typeof r.turnId=="string"?String(r.turnId):typeof r.turn=="string"?String(r.turn):"",n=Array.isArray(r.files)?r.files:[];if(!n.length)return r.files=[],r;let o=[];for(let y of n){let h=await Z({...t,file:y,inChat:e==="chat-send",turnId:e==="chat-send"?m:void 0});h&&o.push(h);}return r.files=e==="chat-send"?[]:o,r}async function yt(t){let e=t.boardPaths(t.boardId),r=await t.fetchServer(e.patchCard(t.cardId),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(t.patch||{})});if(!r.ok)throw new Error(`PATCH failed for ${t.cardId} (${r.status})`)}async function kt(t){let e=t.boardPaths(t.boardId),r=await t.fetchServer(e.retriggerCard(t.cardId),{method:"POST"});if(!r.ok)throw new Error(`retrigger failed for ${t.cardId} (${r.status})`)}async function St(t){let e=t.boardPaths(t.boardId),r=await mt(t),m=await t.fetchServer(e.cardAction(t.cardId),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({actionType:t.actionType,payload:r})});if(!m.ok)throw new Error(`${t.actionType==="refresh"?"Refresh":"Action"} failed for ${t.cardId} (${m.status})`);return {payload:r}}function Oe(t,e=null){return q(t,e,E)}function Pe(t,e,r){return J(t,e,E,r)}function De(t,e){let r=new Set(e.map(String)),m=t.cardIds.filter(o=>r.has(o)),n={};for(let o of m)n[o]=t.modelsById[o];return {payload:t.payload,cardIds:m,modelsById:n}}function je(t,e){let r=e instanceof Set?e:new Set(e.map(String)),m=t.cardIds.filter(o=>!r.has(o)),n={};for(let o of m)n[o]=t.modelsById[o];return {payload:t.payload,cardIds:m,modelsById:n}}function vt(t){let e=t?.core,r=t?.engine??e?.engine;r&&typeof r.onServerSseEvent=="function"?r.onServerSseEvent():r&&typeof r.refreshOpenChatModal=="function"&&r.refreshOpenChatModal();}function bt(){let t=globalThis.LiveCard;if(!t)throw new Error("LiveCard global not loaded \u2014 include live-cards.js before this script");return t}function Ct(t){if(!t||typeof t!="object")throw new Error("options are required");let{fetchServer:e,boardPaths:r,getServerOrigin:m}=t;if(typeof e!="function")throw new Error("options.fetchServer is required");if(typeof r!="function")throw new Error("options.boardPaths is required");if(typeof m!="function")throw new Error("options.getServerOrigin is required");let n={current:null},o=new Set,y=null,h=null,u=null,l={},i={},p=globalThis.crypto&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():`lc-${Date.now()}-${Math.random().toString(36).slice(2)}`;function s(){for(let a of o)a(n.current);}function g(){return n.current?n.current.payload:null}function k(a){return n.current=a,s(),n.current}function c(){let a=h;if(!a)throw new Error("Board runtime session is not bound to a board yet");let f=u??r(a);return u=f,{boardId:a,paths:f}}function w(a){let f=q(a,n.current,E);return k(f),f}function d(a,f){let v=q(a,f??n.current,E);return k(v),v}function S(a){return k(a)}function C(a){if(!n.current)return n.current;let f=J(n.current,a,E,g);return k(f),f}async function x(a,f,v){let{boardId:R}=c();return Z({fetchServer:e,boardPaths:r,boardId:R,cardId:a,file:f,inChat:v?.inChat,turnId:v?.turnId})}async function M(a,f,v){let{boardId:R}=c();return f==="chat-send"&&await A(a),St({fetchServer:e,boardPaths:r,boardId:R,cardId:a,actionType:f,payload:v})}function b(a,f){return i[a]=f,f.finally(()=>{i[a]===f&&delete i[a];})}async function A(a){let f=i[a];if(f){await f;return}l[a]||await K(a);}async function $(a,f){let{boardId:v}=c();await yt({fetchServer:e,boardPaths:r,boardId:v,cardId:a,patch:f});}async function tt(a){let{boardId:f}=c();await kt({fetchServer:e,boardPaths:r,boardId:f,cardId:a});}async function K(a){let{paths:f}=c(),v=i[a];if(v){await v;return}if(l[a])return;l[a]=true;let R=(async()=>{await e(f.chatSubscribeSse(a),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:p})});})().catch(()=>{delete l[a];});await b(a,R);}async function et(a){let{paths:f}=c(),v=i[a];if(v)try{await v;}catch{}delete l[a];try{await e(f.chatUnsubscribeSse(a),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:p})});}catch{}}function rt(a){Object.keys(l).forEach(f=>{e(a.chatSubscribeSse(f),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:p})}).catch(()=>{});});}function V(a){let f=a;f?.kind==="notification-batch"&&Array.isArray(f.notifications)?C(f.notifications):f?.cardDefinitions&&w(f);}function nt(a){return h=String(a.boardId||"default"),u=r(h),a.state!==void 0?S(a.state??null):a.payload?d(a.payload,n.current):n.current}function st(a){return V(a),n.current}function F(){y&&(y.close(),y=null);}async function at(a={}){let f=String(a.boardId||h||"default");h=f;let v=r(f);if(u=v,a.initialState!==void 0?S(a.initialState??null):a.initialPayload!==void 0&&d(a.initialPayload,n.current),a.skipInitBoard!==true){let O=typeof a.taskExecutorPath=="string"?a.taskExecutorPath.trim():"",P=O?`${v.initBoard}?taskExecutorPath=${encodeURIComponent(O)}`:v.initBoard,T=await e(P);if(!T.ok)throw new Error(`Server init-board failed (${T.status}).`)}let R=m();if(!R)throw new Error("Server origin not resolved before SSE start");F();let I=!n.current,dt=`${R}${v.stream}${v.stream.includes("?")?"&":"?"}clientId=${encodeURIComponent(p)}`,X=await new Promise((O,P)=>{let T=new EventSource(dt);y=T;let D=false,j=I?setTimeout(()=>{D||P(new Error("SSE initial payload timeout (15s)"));},15e3):null;T.onopen=()=>{rt(v),I||O(n.current?.payload??null);},T.onmessage=ct=>{try{let N=JSON.parse(ct.data||"{}");V(N),!D&&I&&(N?.cardDefinitions||U(N))&&(D=!0,j&&clearTimeout(j),O(N));}catch{if(!I)return}},T.onerror=()=>{I&&!D&&(j&&clearTimeout(j),P(new Error("SSE connection failed during bootstrap")));};});if(I){if(!U(X))throw new Error("SSE payload missing published runtime artifacts");w(X);}return n.current}function ot(a){return o.add(a),a(n.current),()=>{o.delete(a);}}function it(){F(),Object.keys(l).forEach(a=>delete l[a]),u=null,h=null,o.clear(),n.current=null;}return {bootstrap:at,attachProvidedState:nt,applyServerUpdate:st,seedStateFromPayload:d,seedState:S,applyNotificationBatch:C,replacePayload:w,subscribe:ot,closeSse:F,isConnected:()=>y!=null,getState:()=>n.current,getPayload:g,getBoardId:()=>h,getClientId:()=>p,getSseClientId:()=>p,patchCardState:$,retriggerCard:tt,dispatchCardAction:M,uploadCardFile:x,subscribeCardChats:K,unsubscribeCardChats:et,dispose:it}}function Q(t){if(!t||typeof t!="object")throw new Error("options are required");if(!t.session)throw new Error("options.session is required");let{session:e,...r}=t,m=t.session&&"canvas"in t&&typeof t.canvas=="object"?t.canvas:{height:"72vh",overflow:"auto"},n=e.getState()?H(e.getState(),r):null,o=null,y=String(t.initialMode||"board"),h=new Set;function u(){for(let d of h)d(n);}function l(d){n=d?H(d,r):null,u(),o&&n&&(o.setState(()=>n),vt(o));}let i=e.subscribe(d=>{l(d);});function p(d){if(!n)throw new Error("Derived board runtime has no state to mount");let S=d?.rootElement;if(!S)throw new Error("mountBoard requires params.rootElement");y=String(d?.mode||y||"board");let C=r.boardPaths&&r.getServerOrigin&&e.getBoardId()?ht({boardPaths:r.boardPaths,getServerOrigin:r.getServerOrigin,boardId:e.getBoardId()}):null,x=bt(),M=x.init({resolve:b=>n?.modelsById[b],chartLib:globalThis.Chart??null,markdown:globalThis.marked?b=>globalThis.marked.parse(b):null,sanitize:globalThis.DOMPurify?b=>globalThis.DOMPurify.sanitize(b):null,onPatchState:(b,A)=>e.patchCardState(b,A),onRefresh:b=>e.retriggerCard(b),onAction:(b,A,$)=>e.dispatchCardAction(b,A,$).then(()=>{}),startReceivingChats:b=>{e.subscribeCardChats(b);},stopReceivingChats:b=>{e.unsubscribeCardChats(b);},fileUrlBase:C||void 0});return S.innerHTML="",o=x.Board(M,S,{initialState:n,getNodeIds:b=>b.cardIds,selectNode:(b,A)=>b.modelsById[A],mode:y,canvas:m}),o}function s(d){return h.add(d),d(n),()=>{h.delete(d);}}function g(d){y=String(d||"board");let S=o&&o.core;S&&typeof S.setMode=="function"&&S.setMode(y);}function k(){if(!o)return;y="canvas";let d=o.core;d&&typeof d.setMode=="function"&&d.setMode("canvas"),d&&typeof d.autoLayout=="function"&&d.autoLayout();}function c(d){let S=o&&o.core;S&&typeof S.setDevMode=="function"&&S.setDevMode(!!d);}function w(){i(),h.clear(),o=null;}return {mountBoard:p,subscribe:s,getState:()=>n,getFullState:()=>e.getState(),getBoardId:()=>e.getBoardId(),getClientId:()=>e.getClientId(),getSseClientId:()=>e.getSseClientId(),patchCardState:(d,S)=>e.patchCardState(d,S),retriggerCard:d=>e.retriggerCard(d),dispatchCardAction:(d,S,C)=>e.dispatchCardAction(d,S,C),uploadCardFile:(d,S,C)=>e.uploadCardFile(d,S,C),subscribeCardChats:d=>e.subscribeCardChats(d),unsubscribeCardChats:d=>e.unsubscribeCardChats(d),setMode:g,autoLayout:k,setDevMode:c,getCurrentMode:()=>y,dispose:w}}function Ne(t){let e=Ct(t),r=Q({session:e,boardPaths:t.boardPaths,getServerOrigin:t.getServerOrigin});async function m(n){let o=String(n?.boardId||"default");return await e.bootstrap({boardId:o,taskExecutorPath:n?.taskExecutorPath}),r.mountBoard({rootElement:n.rootElement,mode:n.mode})}return {bootstrapBoard:m,dispose:()=>{r.dispose(),e.dispose();},setMode:n=>r.setMode(n),autoLayout:()=>r.autoLayout(),setDevMode:n=>r.setDevMode(n),getCurrentMode:()=>r.getCurrentMode(),getState:()=>e.getState(),getRuntimeSession:()=>e,createDerivedRuntime:(n={})=>Q({session:e,...n})}}exports.applyBoardNotifications=Pe;exports.applyNotification=J;exports.buildBoardState=q;exports.buildFileUrlBase=ht;exports.createBoardRuntimeClient=Ne;exports.createBoardRuntimeSession=Ct;exports.createDerivedBoardRuntime=Q;exports.defaultBoardPaths=Ie;exports.deriveBoardState=H;exports.dispatchCardAction=St;exports.patchCardState=yt;exports.pickBoardState=De;exports.prepareActionPayload=mt;exports.retriggerCard=kt;exports.selectAllLiveCardModels=U;exports.selectLiveCardModel=E;exports.serverPayloadToBoardState=Oe;exports.singleBoardPaths=Be;exports.subtractBoardState=je;exports.uploadCardFile=Z;return exports;})({});//# sourceMappingURL=board-livecards-client.js.map
2
2
  //# sourceMappingURL=board-livecards-client.js.map
@@ -1,4 +1,4 @@
1
- import { B as BoardPlatformAdapter, N as NotificationTransport, C as ChatStorage } from '../types-juH2nFpz.js';
1
+ import { B as BoardPlatformAdapter, N as NotificationTransport, C as ChatStorage } from '../types-H3EMBPY2.js';
2
2
  import { E as ExecutionRef } from '../execution-interface-BCIhu1gO.js';
3
3
  import '../board-live-cards-lib-COi4bSpk.js';
4
4
 
@@ -1,4 +1,4 @@
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 V=":scratch-marker",H=":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}${V}`,g=`${t}${H}`,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
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:[],turn:typeof e.turn=="string"?e.turn:"",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=[],i=""){return t(s).append({role:l,text:r,files:o,turn:i,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 V=":scratch-marker",H=":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}${V}`,g=`${t}${H}`,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
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:",K=":archive:blob:";function U(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
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=U(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=U(o),u=R(`${t}${K}${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}${K}`,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
4
4
  //# sourceMappingURL=board-live-cards-browser-adapter.js.map