yaml-flow 8.4.9 → 8.4.10

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.
@@ -1,10 +1,10 @@
1
1
  {
2
- "generatedAt": "2026-05-21T21:52:09.439Z",
2
+ "generatedAt": "2026-05-22T09:28:01.153Z",
3
3
  "algorithm": "sha256",
4
4
  "files": {
5
5
  "browser/board-livecards-localstorage.js": {
6
- "sha256": "sha256-4AH2ZoPJJ59BlrkKmESA/r4JLu4V7js69U0BmFYznyE=",
7
- "bytes": 100149
6
+ "sha256": "sha256-Z7WLU3e8tNUX61TyWwHrtSd5IW6ocguQJday2JnostE=",
7
+ "bytes": 100818
8
8
  },
9
9
  "browser/live-cards.schema.json": {
10
10
  "sha256": "sha256-9CUv3YSTpgq3k0Dsi8bs7bNUlGoBA1SGWMCBSZcbzys=",
@@ -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 n=e&&typeof e=="object"&&!Array.isArray(e)?e:{};return {schema_version:n.schema_version||"v1",card_id:typeof n.card_id=="string"?n.card_id:t,card_data:n.card_data&&typeof n.card_data=="object"&&!Array.isArray(n.card_data)?structuredClone(n.card_data):{},computed_values:n.computed_values&&typeof n.computed_values=="object"&&!Array.isArray(n.computed_values)?structuredClone(n.computed_values):{}}}function x(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 r=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(r.cards)?r.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 f=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,E]of Object.entries(y))c[C]=structuredClone(E);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:f,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(n=>x(t,n.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 ft(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function q(t,e,n){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=n(t,u),i=y[u];if(!i){m[u]=l;continue}let g=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:g};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 n=typeof e.includeCard=="function"?e.includeCard:(()=>true),h=typeof e.mapCard=="function"?e.mapCard:(u=>u),r=false,o=[],y={};for(let u of t.cardIds){let l=t.modelsById[u];if(!l){r=true;continue}if(!n(l,t)){r=true;continue}let i=h(l,t);if(!i||i.id!==u)throw new Error(`deriveBoardState: mapped card must preserve id "${u}"`);i!==l&&(r=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&&(r=true),!r&&o.length===t.cardIds.length?t:{payload:m,cardIds:o,modelsById:y}}function J(t,e,n,h){if(!t||!Array.isArray(e)||e.length===0)return t;let r=t.modelsById,o=t.cardIds,y=false,m=false,u={};for(let i of o){let g=r[i],s=g&&g.requires;if(s&&typeof s=="object")for(let f of Object.keys(s))(u[f]=u[f]||[]).push(i);}function l(){y||(r={...r},y=true);}for(let i of e)if(!(!i||!i.kind)){if(i.kind==="computed_values"){let g=i.cardId,s=r[g];if(!s)continue;let f=i.values||{};if(_(s.computed_values,f))continue;l(),r[g]={...s,computed_values:f},m=true;}else if(i.kind==="data_object"){let g=i.key,s=i.payload,f=u[g]||[];for(let k of f){let c=r[k];if(!c)continue;let w=c.requires||{};_(w[g],s)||(l(),r[k]={...c,requires:{...w,[g]:s}},m=true);}}else if(i.kind==="card_refreshed"){let g=i.cardId,s=null,f=r[g],k=i.card;if(f&&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:f.card_data,d=c.requires&&typeof c.requires=="object"&&!Array.isArray(c.requires)?c.requires:f.requires,S=c.computed_values&&typeof c.computed_values=="object"&&!Array.isArray(c.computed_values)?c.computed_values:f.computed_values,C=c.runtime_state&&typeof c.runtime_state=="object"&&!Array.isArray(c.runtime_state)?c.runtime_state:f.runtime_state;s={...f,card:k,card_data:w,requires:d,computed_values:S,runtime_state:C};}if(!s)try{let c=h();c&&(s=n(c,g));}catch{}if(!s||f&&_(f.card,s.card)&&_(f.card_data,s.card_data)&&_(f.requires,s.requires)&&_(f.computed_values,s.computed_values)&&_(f.runtime_state,s.runtime_state))continue;l(),r[g]=s,o.includes(g)||(o=[...o,g]),m=true;}else if(i.kind==="card_chats"){let g=i.cardId,s=r[g];if(!s)continue;let f=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:f,receiving:k,processing:c};if(_(s.card_chats,w))continue;l(),r[g]={...s,card_chats:w},m=true;}else if(i.kind==="chat_messages"){let g=i.cardId,s=r[g];if(!s)continue;let f=Array.isArray(i.messages)?i.messages:[],k=s.card_chats||{receiving:false,processing:false},c={messages:f,receiving:k.receiving,processing:!!k.processing};if(_(s.card_chats,c))continue;l(),r[g]={...s,card_chats:c},m=true;}else if(i.kind==="status"){let g=i.status?.cards??[];for(let s of g){let f=s?.name;if(!f||!r[f])continue;let k=r[f],c=ft(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(),r[f]={...k,card_data:w,runtime_state:d},m=true);}}}return m?{payload:t.payload,cardIds:o,modelsById:r}:t}function xe(t,e="/api/boards"){let n=e.replace(/\/$/,""),h=encodeURIComponent(t||"default"),r=`${n}/${h}`;return {initBoard:`${r}/init-board`,stream:`${r}/sse`,patchCard:o=>`${r}/cards/${encodeURIComponent(o)}`,cardAction:o=>`${r}/cards/${encodeURIComponent(o)}/actions`,cardFile:o=>`${r}/cards/${encodeURIComponent(o)}/files`,cardChats:o=>`${r}/cards/${encodeURIComponent(o)}/chats`,chatSubscribeSse:o=>`${r}/cards/${encodeURIComponent(o)}/chats/subscribe-sse`,chatUnsubscribeSse:o=>`${r}/cards/${encodeURIComponent(o)}/chats/unsubscribe-sse`}}function Ee(t="/api/board"){let e=t.replace(/\/$/,"");return {initBoard:`${e}/init-board`,stream:`${e}/sse`,patchCard:n=>`${e}/cards/${encodeURIComponent(n)}`,cardAction:n=>`${e}/cards/${encodeURIComponent(n)}/actions`,cardFile:n=>`${e}/cards/${encodeURIComponent(n)}/files`,cardChats:n=>`${e}/cards/${encodeURIComponent(n)}/chats`,chatSubscribeSse:n=>`${e}/cards/${encodeURIComponent(n)}/chats/subscribe-sse`,chatUnsubscribeSse:n=>`${e}/cards/${encodeURIComponent(n)}/chats/unsubscribe-sse`}}function gt(t){let e=t.getServerOrigin();if(!e||!t.boardId)return null;let n=t.boardPaths(t.boardId);return `${e}${n.initBoard.replace(/\/init-board$/,"")}`}async function Z(t){if(!t.file)return null;let e=t.boardPaths(t.boardId),n=t.inChat?`${e.cardFile(t.cardId)}?inChat=true`:e.cardFile(t.cardId),h=typeof t.file.name=="string"?t.file.name:"upload.bin",r=t.file.type||"application/octet-stream",o=await t.fetchServer(n,{method:"POST",headers:{"content-type":r,"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 ht(t){let{actionType:e}=t;if(e!=="chat-send"&&e!=="file-upload")return t.payload||{};let n={...t.payload||{}},h=Array.isArray(n.files)?n.files:[];if(!h.length)return n.files=[],n;let r=[];for(let o of h){let y=await Z({...t,file:o,inChat:e==="chat-send"});y&&r.push(y);}return n.files=e==="chat-send"?[]:r,n}async function mt(t){let e=t.boardPaths(t.boardId),n=await t.fetchServer(e.patchCard(t.cardId),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(t.patch||{})});if(!n.ok)throw new Error(`PATCH failed for ${t.cardId} (${n.status})`)}async function yt(t){let e=t.boardPaths(t.boardId),n=await ht(t),h=await t.fetchServer(e.cardAction(t.cardId),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({actionType:t.actionType,payload:n})});if(!h.ok)throw new Error(`${t.actionType==="refresh"?"Refresh":"Action"} failed for ${t.cardId} (${h.status})`);return {payload:n}}function Ie(t,e=null){return q(t,e,x)}function Be(t,e,n){return J(t,e,x,n)}function Oe(t,e){let n=new Set(e.map(String)),h=t.cardIds.filter(o=>n.has(o)),r={};for(let o of h)r[o]=t.modelsById[o];return {payload:t.payload,cardIds:h,modelsById:r}}function Pe(t,e){let n=e instanceof Set?e:new Set(e.map(String)),h=t.cardIds.filter(o=>!n.has(o)),r={};for(let o of h)r[o]=t.modelsById[o];return {payload:t.payload,cardIds:h,modelsById:r}}function kt(t){let e=t?.core,n=t?.engine??e?.engine;n&&typeof n.onServerSseEvent=="function"?n.onServerSseEvent():n&&typeof n.refreshOpenChatModal=="function"&&n.refreshOpenChatModal();}function St(){let t=globalThis.LiveCard;if(!t)throw new Error("LiveCard global not loaded \u2014 include live-cards.js before this script");return t}function vt(t){if(!t||typeof t!="object")throw new Error("options are required");let{fetchServer:e,boardPaths:n,getServerOrigin:h}=t;if(typeof e!="function")throw new Error("options.fetchServer is required");if(typeof n!="function")throw new Error("options.boardPaths is required");if(typeof h!="function")throw new Error("options.getServerOrigin is required");let r={current:null},o=new Set,y=null,m=null,u=null,l={},i={},g=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(r.current);}function f(){return r.current?r.current.payload:null}function k(a){return r.current=a,s(),r.current}function c(){let a=m;if(!a)throw new Error("Board runtime session is not bound to a board yet");let p=u??n(a);return u=p,{boardId:a,paths:p}}function w(a){let p=q(a,r.current,x);return k(p),p}function d(a,p){let b=q(a,p??r.current,x);return k(b),b}function S(a){return k(a)}function C(a){if(!r.current)return r.current;let p=J(r.current,a,x,f);return k(p),p}async function E(a,p,b){let{boardId:R}=c();return Z({fetchServer:e,boardPaths:n,boardId:R,cardId:a,file:p,inChat:b?.inChat})}async function M(a,p,b){let{boardId:R}=c();return p==="chat-send"&&await A(a),yt({fetchServer:e,boardPaths:n,boardId:R,cardId:a,actionType:p,payload:b})}function v(a,p){return i[a]=p,p.finally(()=>{i[a]===p&&delete i[a];})}async function A(a){let p=i[a];if(p){await p;return}l[a]||await K(a);}async function $(a,p){let{boardId:b}=c();await mt({fetchServer:e,boardPaths:n,boardId:b,cardId:a,patch:p});}async function K(a){let{paths:p}=c(),b=i[a];if(b){await b;return}if(l[a])return;l[a]=true;let R=(async()=>{await e(p.chatSubscribeSse(a),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:g})});})().catch(()=>{delete l[a];});await v(a,R);}async function tt(a){let{paths:p}=c(),b=i[a];if(b)try{await b;}catch{}delete l[a];try{await e(p.chatUnsubscribeSse(a),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:g})});}catch{}}function et(a){Object.keys(l).forEach(p=>{e(a.chatSubscribeSse(p),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:g})}).catch(()=>{});});}function V(a){let p=a;p?.kind==="notification-batch"&&Array.isArray(p.notifications)?C(p.notifications):p?.cardDefinitions&&w(p);}function rt(a){return m=String(a.boardId||"default"),u=n(m),a.state!==void 0?S(a.state??null):a.payload?d(a.payload,r.current):r.current}function nt(a){return V(a),r.current}function F(){y&&(y.close(),y=null);}async function st(a={}){let p=String(a.boardId||m||"default");m=p;let b=n(p);if(u=b,a.initialState!==void 0?S(a.initialState??null):a.initialPayload!==void 0&&d(a.initialPayload,r.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=!r.current,it=`${R}${b.stream}${b.stream.includes("?")?"&":"?"}clientId=${encodeURIComponent(g)}`,X=await new Promise((O,P)=>{let T=new EventSource(it);y=T;let D=false,j=I?setTimeout(()=>{D||P(new Error("SSE initial payload timeout (15s)"));},15e3):null;T.onopen=()=>{et(b),I||O(r.current?.payload??null);},T.onmessage=dt=>{try{let L=JSON.parse(dt.data||"{}");V(L),!D&&I&&(L?.cardDefinitions||U(L))&&(D=!0,j&&clearTimeout(j),O(L));}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 r.current}function at(a){return o.add(a),a(r.current),()=>{o.delete(a);}}function ot(){F(),Object.keys(l).forEach(a=>delete l[a]),u=null,m=null,o.clear(),r.current=null;}return {bootstrap:st,attachProvidedState:rt,applyServerUpdate:nt,seedStateFromPayload:d,seedState:S,applyNotificationBatch:C,replacePayload:w,subscribe:at,closeSse:F,isConnected:()=>y!=null,getState:()=>r.current,getPayload:f,getBoardId:()=>m,getClientId:()=>g,getSseClientId:()=>g,patchCardState:$,dispatchCardAction:M,uploadCardFile:E,subscribeCardChats:K,unsubscribeCardChats:tt,dispose:ot}}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,...n}=t,h=t.session&&"canvas"in t&&typeof t.canvas=="object"?t.canvas:{height:"72vh",overflow:"auto"},r=e.getState()?H(e.getState(),n):null,o=null,y=String(t.initialMode||"board"),m=new Set;function u(){for(let d of m)d(r);}function l(d){r=d?H(d,n):null,u(),o&&r&&(o.setState(()=>r),kt(o));}let i=e.subscribe(d=>{l(d);});function g(d){if(!r)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=n.boardPaths&&n.getServerOrigin&&e.getBoardId()?gt({boardPaths:n.boardPaths,getServerOrigin:n.getServerOrigin,boardId:e.getBoardId()}):null,E=St(),M=E.init({resolve:v=>r?.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.patchCardState(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=E.Board(M,S,{initialState:r,getNodeIds:v=>v.cardIds,selectNode:(v,A)=>v.modelsById[A],mode:y,canvas:h}),o}function s(d){return m.add(d),d(r),()=>{m.delete(d);}}function f(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:g,subscribe:s,getState:()=>r,getFullState:()=>e.getState(),getBoardId:()=>e.getBoardId(),getClientId:()=>e.getClientId(),getSseClientId:()=>e.getSseClientId(),patchCardState:(d,S)=>e.patchCardState(d,S),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:f,autoLayout:k,setDevMode:c,getCurrentMode:()=>y,dispose:w}}function De(t){let e=vt(t),n=Q({session:e,boardPaths:t.boardPaths,getServerOrigin:t.getServerOrigin});async function h(r){let o=String(r?.boardId||"default");return await e.bootstrap({boardId:o,taskExecutorPath:r?.taskExecutorPath}),n.mountBoard({rootElement:r.rootElement,mode:r.mode})}return {bootstrapBoard:h,dispose:()=>{n.dispose(),e.dispose();},setMode:r=>n.setMode(r),autoLayout:()=>n.autoLayout(),setDevMode:r=>n.setDevMode(r),getCurrentMode:()=>n.getCurrentMode(),getState:()=>e.getState(),getRuntimeSession:()=>e,createDerivedRuntime:(r={})=>Q({session:e,...r})}}exports.applyBoardNotifications=Be;exports.applyNotification=J;exports.buildBoardState=q;exports.buildFileUrlBase=gt;exports.createBoardRuntimeClient=De;exports.createBoardRuntimeSession=vt;exports.createDerivedBoardRuntime=Q;exports.defaultBoardPaths=xe;exports.deriveBoardState=H;exports.dispatchCardAction=yt;exports.patchCardState=mt;exports.pickBoardState=Oe;exports.prepareActionPayload=ht;exports.selectAllLiveCardModels=U;exports.selectLiveCardModel=x;exports.serverPayloadToBoardState=Ie;exports.singleBoardPaths=Ee;exports.subtractBoardState=Pe;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 x(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),f=structuredClone(h),i=pt(e,o[e]),a={...f.card_data&&typeof f.card_data=="object"&&!Array.isArray(f.card_data)?f.card_data:{},...i.card_data||{},status:W(u?.status),lastRun:u?.runtime?.last_transition_at??null};u?.error?.message&&(a.error=u.error.message);let p=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:a.status??"fresh",runtime:{last_transition_at:a.lastRun??null},error:a.error?{message:a.error}:null,blocked_by:[],requires_missing:[]},k=Array.isArray(f.requires)?f.requires:[],c={};for(let[C,E]of Object.entries(y))c[C]=structuredClone(E);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:f,card_data:a,requires:c,computed_values:i.computed_values,runtime_state:p,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=>x(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 f=r(t,u),i=y[u];if(!i){m[u]=f;continue}let g=f.card_chats!=null?B(i.card_chats,f.card_chats??null):i.card_chats??null,a={id:f.id,card:B(i.card,f.card),card_data:B(i.card_data,f.card_data),requires:B(i.requires,f.requires),computed_values:B(i.computed_values,f.computed_values),runtime_state:B(i.runtime_state,f.runtime_state),card_chats:g};m[u]=a.card===i.card&&a.card_data===i.card_data&&a.requires===i.requires&&a.computed_values===i.computed_values&&a.runtime_state===i.runtime_state&&a.card_chats===i.card_chats?i:a;}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 f=t.modelsById[u];if(!f){n=true;continue}if(!r(f,t)){n=true;continue}let i=h(f,t);if(!i||i.id!==u)throw new Error(`deriveBoardState: mapped card must preserve id "${u}"`);i!==f&&(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 g=n[i],a=g&&g.requires;if(a&&typeof a=="object")for(let p of Object.keys(a))(u[p]=u[p]||[]).push(i);}function f(){y||(n={...n},y=true);}for(let i of e)if(!(!i||!i.kind)){if(i.kind==="computed_values"){let g=i.cardId,a=n[g];if(!a)continue;let p=i.values||{};if(_(a.computed_values,p))continue;f(),n[g]={...a,computed_values:p},m=true;}else if(i.kind==="data_object"){let g=i.key,a=i.payload,p=u[g]||[];for(let k of p){let c=n[k];if(!c)continue;let w=c.requires||{};_(w[g],a)||(f(),n[k]={...c,requires:{...w,[g]:a}},m=true);}}else if(i.kind==="card_refreshed"){let g=i.cardId,a=null,p=n[g],k=i.card;if(p&&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:p.card_data,d=c.requires&&typeof c.requires=="object"&&!Array.isArray(c.requires)?c.requires:p.requires,S=c.computed_values&&typeof c.computed_values=="object"&&!Array.isArray(c.computed_values)?c.computed_values:p.computed_values,C=c.runtime_state&&typeof c.runtime_state=="object"&&!Array.isArray(c.runtime_state)?c.runtime_state:p.runtime_state;a={...p,card:k,card_data:w,requires:d,computed_values:S,runtime_state:C};}if(!a)try{let c=h();c&&(a=r(c,g));}catch{}if(!a||p&&_(p.card,a.card)&&_(p.card_data,a.card_data)&&_(p.requires,a.requires)&&_(p.computed_values,a.computed_values)&&_(p.runtime_state,a.runtime_state))continue;f(),n[g]=a,o.includes(g)||(o=[...o,g]),m=true;}else if(i.kind==="card_chats"){let g=i.cardId,a=n[g];if(!a)continue;let p=Array.isArray(i.messages)?i.messages:a.card_chats?.messages??[],k=typeof i.receiving=="boolean"?i.receiving:a.card_chats?.receiving??false,c=typeof i.processing=="boolean"?i.processing:a.card_chats?.processing??false,w={messages:p,receiving:k,processing:c};if(_(a.card_chats,w))continue;f(),n[g]={...a,card_chats:w},m=true;}else if(i.kind==="chat_messages"){let g=i.cardId,a=n[g];if(!a)continue;let p=Array.isArray(i.messages)?i.messages:[],k=a.card_chats||{receiving:false,processing:false},c={messages:p,receiving:k.receiving,processing:!!k.processing};if(_(a.card_chats,c))continue;f(),n[g]={...a,card_chats:c},m=true;}else if(i.kind==="status"){let g=i.status?.cards??[];for(let a of g){let p=a?.name;if(!p||!n[p])continue;let k=n[p],c=gt(a.status),w={...k.card_data||{},status:c,lastRun:a.runtime?.last_transition_at??null,...a.error?.message?{error:a.error.message}:{}};a.error?.message||delete w.error;let d={task_status:a.status??null,card_status:c,runtime:a.runtime?G(a.runtime):{},error:a.error?G(a.error):null,blocked_by:Array.isArray(a.blocked_by)?G(a.blocked_by):[],requires_missing:Array.isArray(a.requires_missing)?G(a.requires_missing):[]};_(k.card_data,w)&&_(k.runtime_state,d)||(f(),n[p]={...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,x)}function Pe(t,e,r){return J(t,e,x,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,f={},i={},g=globalThis.crypto&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():`lc-${Date.now()}-${Math.random().toString(36).slice(2)}`;function a(){for(let s of o)s(n.current);}function p(){return n.current?n.current.payload:null}function k(s){return n.current=s,a(),n.current}function c(){let s=m;if(!s)throw new Error("Board runtime session is not bound to a board yet");let l=u??r(s);return u=l,{boardId:s,paths:l}}function w(s){let l=q(s,n.current,x);return k(l),l}function d(s,l){let b=q(s,l??n.current,x);return k(b),b}function S(s){return k(s)}function C(s){if(!n.current)return n.current;let l=J(n.current,s,x,p);return k(l),l}async function E(s,l,b){let{boardId:R}=c();return Z({fetchServer:e,boardPaths:r,boardId:R,cardId:s,file:l,inChat:b?.inChat})}async function M(s,l,b){let{boardId:R}=c();return l==="chat-send"&&await A(s),St({fetchServer:e,boardPaths:r,boardId:R,cardId:s,actionType:l,payload:b})}function v(s,l){return i[s]=l,l.finally(()=>{i[s]===l&&delete i[s];})}async function A(s){let l=i[s];if(l){await l;return}f[s]||await K(s);}async function $(s,l){let{boardId:b}=c();await yt({fetchServer:e,boardPaths:r,boardId:b,cardId:s,patch:l});}async function tt(s){let{boardId:l}=c();await kt({fetchServer:e,boardPaths:r,boardId:l,cardId:s});}async function K(s){let{paths:l}=c(),b=i[s];if(b){await b;return}if(f[s])return;f[s]=true;let R=(async()=>{await e(l.chatSubscribeSse(s),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:g})});})().catch(()=>{delete f[s];});await v(s,R);}async function et(s){let{paths:l}=c(),b=i[s];if(b)try{await b;}catch{}delete f[s];try{await e(l.chatUnsubscribeSse(s),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:g})});}catch{}}function rt(s){Object.keys(f).forEach(l=>{e(s.chatSubscribeSse(l),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:g})}).catch(()=>{});});}function V(s){let l=s;l?.kind==="notification-batch"&&Array.isArray(l.notifications)?C(l.notifications):l?.cardDefinitions&&w(l);}function nt(s){return m=String(s.boardId||"default"),u=r(m),s.state!==void 0?S(s.state??null):s.payload?d(s.payload,n.current):n.current}function st(s){return V(s),n.current}function F(){y&&(y.close(),y=null);}async function at(s={}){let l=String(s.boardId||m||"default");m=l;let b=r(l);if(u=b,s.initialState!==void 0?S(s.initialState??null):s.initialPayload!==void 0&&d(s.initialPayload,n.current),s.skipInitBoard!==true){let O=typeof s.taskExecutorPath=="string"?s.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(g)}`,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 L=JSON.parse(ct.data||"{}");V(L),!D&&I&&(L?.cardDefinitions||U(L))&&(D=!0,j&&clearTimeout(j),O(L));}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(s){return o.add(s),s(n.current),()=>{o.delete(s);}}function it(){F(),Object.keys(f).forEach(s=>delete f[s]),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:p,getBoardId:()=>m,getClientId:()=>g,getSseClientId:()=>g,patchCardState:$,retriggerCard:tt,dispatchCardAction:M,uploadCardFile:E,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 f(d){n=d?H(d,r):null,u(),o&&n&&(o.setState(()=>n),vt(o));}let i=e.subscribe(d=>{f(d);});function g(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,E=bt(),M=E.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=E.Board(M,S,{initialState:n,getNodeIds:v=>v.cardIds,selectNode:(v,A)=>v.modelsById[A],mode:y,canvas:h}),o}function a(d){return m.add(d),d(n),()=>{m.delete(d);}}function p(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:g,subscribe:a,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:p,autoLayout:k,setDevMode:c,getCurrentMode:()=>y,dispose:w}}function Le(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=Le;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=x;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