yaml-flow 8.2.1 → 8.2.2
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,2 +1,2 @@
|
|
|
1
|
-
var BoardLiveCardsClient=(function(exports){'use strict';function Y(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function ot(t,n){let a=n&&typeof n=="object"&&!Array.isArray(n)?n:{};return {schema_version:a.schema_version||"v1",card_id:typeof a.card_id=="string"?a.card_id:t,card_data:a.card_data&&typeof a.card_data=="object"&&!Array.isArray(a.card_data)?structuredClone(a.card_data):{},computed_values:a.computed_values&&typeof a.computed_values=="object"&&!Array.isArray(a.computed_values)?structuredClone(a.computed_values):{}}}function G(t,n){if(!t||typeof t!="object")throw new Error("payload must be an object");if(!n)throw new Error("cardId is required");let S=(Array.isArray(t.cardDefinitions)?t.cardDefinitions:[]).find(R=>R.id===n);if(!S)throw new Error(`cardDefinitions has no entry with id ${n}`);let c=t.statusSnapshot&&typeof t.statusSnapshot=="object"?t.statusSnapshot:{},s=t.cardRuntimeById&&typeof t.cardRuntimeById=="object"?t.cardRuntimeById:{},p=t.dataObjectsByToken&&typeof t.dataObjectsByToken=="object"?t.dataObjectsByToken:{},o=(Array.isArray(c.cards)?c.cards:[]).find(R=>R.name===n),u=structuredClone(S),r=ot(n,s[n]),e={...u.card_data&&typeof u.card_data=="object"&&!Array.isArray(u.card_data)?u.card_data:{},...r.card_data||{},status:Y(o?.status),lastRun:o?.runtime?.last_transition_at??null};o?.error?.message&&(e.error=o.error.message);let l=o?{task_status:o.status??null,card_status:Y(o.status),runtime:structuredClone(o.runtime??{}),error:o.error?structuredClone(o.error):null,blocked_by:Array.isArray(o.blocked_by)?structuredClone(o.blocked_by):[],requires_missing:Array.isArray(o.requires_missing)?structuredClone(o.requires_missing):[]}:{task_status:null,card_status:e.status??"fresh",runtime:{last_transition_at:e.lastRun??null},error:e.error?{message:e.error}:null,blocked_by:[],requires_missing:[]},h=Array.isArray(u.requires)?u.requires:[],i={};for(let[R,$]of Object.entries(p))i[R]=structuredClone($);for(let R of h)Object.prototype.hasOwnProperty.call(i,R)||(i[R]=null);let _=(t.cardChatsByCardId&&typeof t.cardChatsByCardId=="object"?t.cardChatsByCardId:{})[n],P=_?{messages:Array.isArray(_.messages)?_.messages:[],receiving:!!_.receiving,processing:!!_.processing}:null;return {id:n,card:u,card_data:e,requires:i,computed_values:r.computed_values,runtime_state:l,card_chats:P}}function H(t){if(!t||typeof t!="object")throw new Error("payload must be an object");return (Array.isArray(t.cardDefinitions)?t.cardDefinitions:[]).map(a=>G(t,a.id))}function M(t){return JSON.parse(JSON.stringify(t))}function N(t,n){if(t===n)return t;try{if(JSON.stringify(t)===JSON.stringify(n))return t}catch{}return n}function T(t,n){if(t===n)return true;try{return JSON.stringify(t)===JSON.stringify(n)}catch{return false}}function it(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function J(t,n,a){let S=t,s=(S&&Array.isArray(S.cardDefinitions)?S.cardDefinitions:[]).map(o=>o.id),p=n&&n.modelsById||{},y={};for(let o of s){let u=a(t,o),r=p[o];if(!r){y[o]=u;continue}let g=u.card_chats!=null?N(r.card_chats,u.card_chats??null):r.card_chats??null,e={id:u.id,card:N(r.card,u.card),card_data:N(r.card_data,u.card_data),requires:N(r.requires,u.requires),computed_values:N(r.computed_values,u.computed_values),runtime_state:N(r.runtime_state,u.runtime_state),card_chats:g};y[o]=e.card===r.card&&e.card_data===r.card_data&&e.requires===r.requires&&e.computed_values===r.computed_values&&e.runtime_state===r.runtime_state&&e.card_chats===r.card_chats?r:e;}return {payload:t,cardIds:s,modelsById:y}}function ct(t,n={}){if(!t)return t;let a=typeof n.includeCard=="function"?n.includeCard:(()=>true),S=typeof n.mapCard=="function"?n.mapCard:(o=>o),c=false,s=[],p={};for(let o of t.cardIds){let u=t.modelsById[o];if(!u){c=true;continue}if(!a(u,t)){c=true;continue}let r=S(u,t);if(!r||r.id!==o)throw new Error(`deriveBoardState: mapped card must preserve id "${o}"`);r!==u&&(c=true),s.push(o),p[o]=r;}let y=typeof n.mapPayload=="function"?n.mapPayload(t.payload,{sourceState:t,cardIds:s,modelsById:p}):t.payload;return y!==t.payload&&(c=true),!c&&s.length===t.cardIds.length?t:{payload:y,cardIds:s,modelsById:p}}function K(t,n,a,S){if(!t||!Array.isArray(n)||n.length===0)return t;let c=t.modelsById,s=t.cardIds,p=false,y=false,o={};for(let r of s){let g=c[r],e=g&&g.requires;if(e&&typeof e=="object")for(let l of Object.keys(e))(o[l]=o[l]||[]).push(r);}function u(){p||(c={...c},p=true);}for(let r of n)if(!(!r||!r.kind)){if(r.kind==="computed_values"){let g=r.cardId,e=c[g];if(!e)continue;let l=r.values||{};if(T(e.computed_values,l))continue;u(),c[g]={...e,computed_values:l},y=true;}else if(r.kind==="data_object"){let g=r.key,e=r.payload,l=o[g]||[];for(let h of l){let i=c[h];if(!i)continue;let w=i.requires||{};T(w[g],e)||(u(),c[h]={...i,requires:{...w,[g]:e}},y=true);}}else if(r.kind==="card_refreshed"){let g=r.cardId,e=null,l=c[g],h=r.card;if(l&&h&&typeof h=="object"&&!Array.isArray(h)){let i=h,w=i.card_data&&typeof i.card_data=="object"&&!Array.isArray(i.card_data)?i.card_data:l.card_data,_=i.requires&&typeof i.requires=="object"&&!Array.isArray(i.requires)?i.requires:l.requires,P=i.computed_values&&typeof i.computed_values=="object"&&!Array.isArray(i.computed_values)?i.computed_values:l.computed_values,R=i.runtime_state&&typeof i.runtime_state=="object"&&!Array.isArray(i.runtime_state)?i.runtime_state:l.runtime_state;e={...l,card:h,card_data:w,requires:_,computed_values:P,runtime_state:R};}if(!e)try{let i=S();i&&(e=a(i,g));}catch{}if(!e||l&&T(l.card,e.card)&&T(l.card_data,e.card_data)&&T(l.requires,e.requires)&&T(l.computed_values,e.computed_values)&&T(l.runtime_state,e.runtime_state))continue;u(),c[g]=e,s.includes(g)||(s=[...s,g]),y=true;}else if(r.kind==="card_chats"){let g=r.cardId,e=c[g];if(!e)continue;let l=Array.isArray(r.messages)?r.messages:e.card_chats?.messages??[],h=typeof r.receiving=="boolean"?r.receiving:e.card_chats?.receiving??false,i=typeof r.processing=="boolean"?r.processing:e.card_chats?.processing??false,w={messages:l,receiving:h,processing:i};if(T(e.card_chats,w))continue;u(),c[g]={...e,card_chats:w},y=true;}else if(r.kind==="chat_messages"){let g=r.cardId,e=c[g];if(!e)continue;let l=Array.isArray(r.messages)?r.messages:[],h=e.card_chats||{receiving:false,processing:false},i={messages:l,receiving:h.receiving,processing:!!h.processing};if(T(e.card_chats,i))continue;u(),c[g]={...e,card_chats:i},y=true;}else if(r.kind==="status"){let g=r.status?.cards??[];for(let e of g){let l=e?.name;if(!l||!c[l])continue;let h=c[l],i=it(e.status),w={...h.card_data||{},status:i,lastRun:e.runtime?.last_transition_at??null,...e.error?.message?{error:e.error.message}:{}};e.error?.message||delete w.error;let _={task_status:e.status??null,card_status:i,runtime:e.runtime?M(e.runtime):{},error:e.error?M(e.error):null,blocked_by:Array.isArray(e.blocked_by)?M(e.blocked_by):[],requires_missing:Array.isArray(e.requires_missing)?M(e.requires_missing):[]};T(h.card_data,w)&&T(h.runtime_state,_)||(u(),c[l]={...h,card_data:w,runtime_state:_},y=true);}}}return y?{payload:t.payload,cardIds:s,modelsById:c}:t}function he(t,n="/api/boards"){let a=n.replace(/\/$/,""),S=encodeURIComponent(t||"default"),c=`${a}/${S}`;return {initBoard:`${c}/init-board`,stream:`${c}/sse`,patchCard:s=>`${c}/cards/${encodeURIComponent(s)}`,cardAction:s=>`${c}/cards/${encodeURIComponent(s)}/actions`,cardFile:s=>`${c}/cards/${encodeURIComponent(s)}/files`,cardChats:s=>`${c}/cards/${encodeURIComponent(s)}/chats`,chatSubscribeSse:s=>`${c}/cards/${encodeURIComponent(s)}/chats/subscribe-sse`,chatUnsubscribeSse:s=>`${c}/cards/${encodeURIComponent(s)}/chats/unsubscribe-sse`}}function ye(t="/api/board"){let n=t.replace(/\/$/,"");return {initBoard:`${n}/init-board`,stream:`${n}/sse`,patchCard:a=>`${n}/cards/${encodeURIComponent(a)}`,cardAction:a=>`${n}/cards/${encodeURIComponent(a)}/actions`,cardFile:a=>`${n}/cards/${encodeURIComponent(a)}/files`,cardChats:a=>`${n}/cards/${encodeURIComponent(a)}/chats`,chatSubscribeSse:a=>`${n}/cards/${encodeURIComponent(a)}/chats/subscribe-sse`,chatUnsubscribeSse:a=>`${n}/cards/${encodeURIComponent(a)}/chats/unsubscribe-sse`}}function ke(t){if(!t||typeof t!="object")throw new Error("options are required");let{fetchServer:n,boardPaths:a,getServerOrigin:S}=t;if(typeof n!="function")throw new Error("options.fetchServer is required");if(typeof a!="function")throw new Error("options.boardPaths is required");if(typeof S!="function")throw new Error("options.getServerOrigin is required");let c=t.canvas&&typeof t.canvas=="object"?t.canvas:{height:"72vh",overflow:"auto"},s={current:null},p=null,y=null,o=String(t.initialMode||"board"),u={},r=globalThis.crypto&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():`lc-${Date.now()}-${Math.random().toString(36).slice(2)}`;function e(){return s.current?s.current.payload:null}function h(d,f,b){if(!p||!s.current)return;p.setState(C=>{let k=K(C,[{kind:"card_chats",cardId:d,messages:f,receiving:b}],G,e);return s.current=k,k});let A=p&&p.engine;A&&typeof A.onServerSseEvent=="function"&&A.onServerSseEvent();}async function i(d,f){u[d]=true,h(d,s.current?.modelsById[d]?.card_chats?.messages??[],true);try{await n(f.chatSubscribeSse(d),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:r})});}catch{}}async function w(d,f){delete u[d];try{await n(f.chatUnsubscribeSse(d),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:r})});}catch{}}function _(d){Object.keys(u).forEach(f=>{n(d.chatSubscribeSse(f),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:r})}).catch(()=>{});});}async function P(d,f,b,A){if(!b)return null;let C=A?.inChat===true,k=typeof b.name=="string"?b.name:"upload.bin",L=b.type||"application/octet-stream",O=a(d),I=C?`${O.cardFile(f)}?inChat=true`:O.cardFile(f),j=await n(I,{method:"POST",headers:{"content-type":L,"x-file-name":encodeURIComponent(k)},body:b});if(!j.ok){let U=await j.text();throw new Error(`Upload failed (${j.status}): ${U||"unknown error"}`)}return (await j.json())?.file??null}async function R(d,f,b,A){if(b!=="chat-send"&&b!=="file-upload")return A||{};let C={...A||{}},k=Array.isArray(C.files)?C.files:[];if(!k.length)return C.files=[],C;let L=[];for(let O of k){let I=await P(d,f,O,{inChat:b==="chat-send"});I&&L.push(I);}return C.files=b==="chat-send"?[]:L,C}async function $(d){let f=String(d?.boardId||"default"),b=typeof d?.taskExecutorPath=="string"?d.taskExecutorPath.trim():"",A=String(d?.mode||o||"board"),C=d?.rootElement;if(!C)throw new Error("bootstrapBoard requires params.rootElement");let k=a(f);let L=b?`${k.initBoard}?taskExecutorPath=${encodeURIComponent(b)}`:k.initBoard,O=await n(L);if(!O.ok)throw new Error(`Server init-board failed (${O.status}).`);let I=S();if(!I)throw new Error("Server origin not resolved before SSE start");let j=await new Promise((m,v)=>{let E=`${I}${k.stream}${k.stream.includes("?")?"&":"?"}clientId=${encodeURIComponent(r)}`,x=new EventSource(E);y=x;let D=false,V=setTimeout(()=>{D||v(new Error("SSE initial payload timeout (15s)"));},15e3);x.onmessage=rt=>{try{let F=JSON.parse(rt.data||"{}");!D&&(F?.cardDefinitions||H(F))&&(D=!0,clearTimeout(V),m(F));}catch{}},x.onerror=()=>{D||(clearTimeout(V),v(new Error("SSE connection failed during bootstrap")));};});if(!H(j))throw new Error("SSE payload missing published runtime artifacts");s.current=J(j,null,G);let B=globalThis.LiveCard;if(!B)throw new Error("LiveCard global not loaded \u2014 include live-cards.js before this script");let U=B.init({resolve:m=>s.current?.modelsById[m],chartLib:globalThis.Chart??null,markdown:globalThis.marked?m=>globalThis.marked.parse(m):null,sanitize:globalThis.DOMPurify?m=>globalThis.DOMPurify.sanitize(m):null,onPatchState:async(m,v)=>{await n(k.patchCard(m),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(v||{})});},onRefresh:async m=>{await n(k.patchCard(m),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({})});},onAction:async(m,v,E)=>{let x=await R(f,m,v,E);await n(k.cardAction(m),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({actionType:v,payload:x||{}})});},startReceivingChats:m=>{i(m,k);},stopReceivingChats:m=>{w(m,k),h(m,s.current?.modelsById[m]?.card_chats?.messages??[],false);}});return C.innerHTML="",p=B.Board(U,C,{initialState:s.current,getNodeIds:m=>m.cardIds,selectNode:(m,v)=>m.modelsById[v],mode:A,canvas:c}),o=A,y.onopen=()=>{_(k);},y.onmessage=m=>{try{let v=JSON.parse(m.data||"{}");if(v?.kind==="notification-batch"&&Array.isArray(v.notifications))p&&p.setState(x=>{let D=K(x,v.notifications,G,e);return s.current=D,D});else if(v?.cardDefinitions){let x=J(v,s.current,G);s.current=x,p&&p.setState(()=>x);}let E=p&&p.engine;E&&typeof E.onServerSseEvent=="function"?E.onServerSseEvent():E&&typeof E.refreshOpenChatModal=="function"&&E.refreshOpenChatModal();}catch(v){console.warn("Bad SSE payload",v);}},p}function W(){y&&(y.close(),y=null),Object.keys(u).forEach(d=>delete u[d]),p=null,s.current=null;}function Q(d){o=String(d||"board");let f=p&&p.core;f&&typeof f.setMode=="function"&&f.setMode(o);}function Z(){if(!p)return;o="canvas";let d=p.core;d&&typeof d.setMode=="function"&&d.setMode("canvas"),d&&typeof d.autoLayout=="function"&&d.autoLayout();}function tt(d){let f=p&&p.core;f&&typeof f.setDevMode=="function"&&f.setDevMode(!!d);}function et(){return o}return {bootstrapBoard:$,dispose:W,setMode:Q,autoLayout:Z,setDevMode:tt,getCurrentMode:et}}exports.applyNotification=K;exports.buildBoardState=J;exports.createBoardRuntimeClient=ke;exports.defaultBoardPaths=he;exports.deriveBoardState=ct;exports.selectAllLiveCardModels=H;exports.selectLiveCardModel=G;exports.singleBoardPaths=ye;return exports;})({});//# sourceMappingURL=board-livecards-client.js.map
|
|
1
|
+
var BoardLiveCardsClient=(function(exports){'use strict';function Y(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function ot(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 B(t,e){if(!t||typeof t!="object")throw new Error("payload must be an object");if(!e)throw new Error("cardId is required");let g=(Array.isArray(t.cardDefinitions)?t.cardDefinitions:[]).find(R=>R.id===e);if(!g)throw new Error(`cardDefinitions has no entry with id ${e}`);let o=t.statusSnapshot&&typeof t.statusSnapshot=="object"?t.statusSnapshot:{},s=t.cardRuntimeById&&typeof t.cardRuntimeById=="object"?t.cardRuntimeById:{},l=t.dataObjectsByToken&&typeof t.dataObjectsByToken=="object"?t.dataObjectsByToken:{},i=(Array.isArray(o.cards)?o.cards:[]).find(R=>R.name===e),u=structuredClone(g),a=ot(e,s[e]),r={...u.card_data&&typeof u.card_data=="object"&&!Array.isArray(u.card_data)?u.card_data:{},...a.card_data||{},status:Y(i?.status),lastRun:i?.runtime?.last_transition_at??null};i?.error?.message&&(r.error=i.error.message);let p=i?{task_status:i.status??null,card_status:Y(i.status),runtime:structuredClone(i.runtime??{}),error:i.error?structuredClone(i.error):null,blocked_by:Array.isArray(i.blocked_by)?structuredClone(i.blocked_by):[],requires_missing:Array.isArray(i.requires_missing)?structuredClone(i.requires_missing):[]}:{task_status:null,card_status:r.status??"fresh",runtime:{last_transition_at:r.lastRun??null},error:r.error?{message:r.error}:null,blocked_by:[],requires_missing:[]},k=Array.isArray(u.requires)?u.requires:[],d={};for(let[R,$]of Object.entries(l))d[R]=structuredClone($);for(let R of k)Object.prototype.hasOwnProperty.call(d,R)||(d[R]=null);let _=(t.cardChatsByCardId&&typeof t.cardChatsByCardId=="object"?t.cardChatsByCardId:{})[e],G=_?{messages:Array.isArray(_.messages)?_.messages:[],receiving:!!_.receiving,processing:!!_.processing}:null;return {id:e,card:u,card_data:r,requires:d,computed_values:a.computed_values,runtime_state:p,card_chats:G}}function H(t){if(!t||typeof t!="object")throw new Error("payload must be an object");return (Array.isArray(t.cardDefinitions)?t.cardDefinitions:[]).map(n=>B(t,n.id))}function M(t){return JSON.parse(JSON.stringify(t))}function L(t,e){if(t===e)return t;try{if(JSON.stringify(t)===JSON.stringify(e))return t}catch{}return e}function T(t,e){if(t===e)return true;try{return JSON.stringify(t)===JSON.stringify(e)}catch{return false}}function it(t){return t==="running"||t==="in-progress"?"loading":t==="failed"?"error":"fresh"}function J(t,e,n){let g=t,s=(g&&Array.isArray(g.cardDefinitions)?g.cardDefinitions:[]).map(i=>i.id),l=e&&e.modelsById||{},y={};for(let i of s){let u=n(t,i),a=l[i];if(!a){y[i]=u;continue}let h=u.card_chats!=null?L(a.card_chats,u.card_chats??null):a.card_chats??null,r={id:u.id,card:L(a.card,u.card),card_data:L(a.card_data,u.card_data),requires:L(a.requires,u.requires),computed_values:L(a.computed_values,u.computed_values),runtime_state:L(a.runtime_state,u.runtime_state),card_chats:h};y[i]=r.card===a.card&&r.card_data===a.card_data&&r.requires===a.requires&&r.computed_values===a.computed_values&&r.runtime_state===a.runtime_state&&r.card_chats===a.card_chats?a:r;}return {payload:t,cardIds:s,modelsById:y}}function dt(t,e={}){if(!t)return t;let n=typeof e.includeCard=="function"?e.includeCard:(()=>true),g=typeof e.mapCard=="function"?e.mapCard:(i=>i),o=false,s=[],l={};for(let i of t.cardIds){let u=t.modelsById[i];if(!u){o=true;continue}if(!n(u,t)){o=true;continue}let a=g(u,t);if(!a||a.id!==i)throw new Error(`deriveBoardState: mapped card must preserve id "${i}"`);a!==u&&(o=true),s.push(i),l[i]=a;}let y=typeof e.mapPayload=="function"?e.mapPayload(t.payload,{sourceState:t,cardIds:s,modelsById:l}):t.payload;return y!==t.payload&&(o=true),!o&&s.length===t.cardIds.length?t:{payload:y,cardIds:s,modelsById:l}}function K(t,e,n,g){if(!t||!Array.isArray(e)||e.length===0)return t;let o=t.modelsById,s=t.cardIds,l=false,y=false,i={};for(let a of s){let h=o[a],r=h&&h.requires;if(r&&typeof r=="object")for(let p of Object.keys(r))(i[p]=i[p]||[]).push(a);}function u(){l||(o={...o},l=true);}for(let a of e)if(!(!a||!a.kind)){if(a.kind==="computed_values"){let h=a.cardId,r=o[h];if(!r)continue;let p=a.values||{};if(T(r.computed_values,p))continue;u(),o[h]={...r,computed_values:p},y=true;}else if(a.kind==="data_object"){let h=a.key,r=a.payload,p=i[h]||[];for(let k of p){let d=o[k];if(!d)continue;let w=d.requires||{};T(w[h],r)||(u(),o[k]={...d,requires:{...w,[h]:r}},y=true);}}else if(a.kind==="card_refreshed"){let h=a.cardId,r=null,p=o[h],k=a.card;if(p&&k&&typeof k=="object"&&!Array.isArray(k)){let d=k,w=d.card_data&&typeof d.card_data=="object"&&!Array.isArray(d.card_data)?d.card_data:p.card_data,_=d.requires&&typeof d.requires=="object"&&!Array.isArray(d.requires)?d.requires:p.requires,G=d.computed_values&&typeof d.computed_values=="object"&&!Array.isArray(d.computed_values)?d.computed_values:p.computed_values,R=d.runtime_state&&typeof d.runtime_state=="object"&&!Array.isArray(d.runtime_state)?d.runtime_state:p.runtime_state;r={...p,card:k,card_data:w,requires:_,computed_values:G,runtime_state:R};}if(!r)try{let d=g();d&&(r=n(d,h));}catch{}if(!r||p&&T(p.card,r.card)&&T(p.card_data,r.card_data)&&T(p.requires,r.requires)&&T(p.computed_values,r.computed_values)&&T(p.runtime_state,r.runtime_state))continue;u(),o[h]=r,s.includes(h)||(s=[...s,h]),y=true;}else if(a.kind==="card_chats"){let h=a.cardId,r=o[h];if(!r)continue;let p=Array.isArray(a.messages)?a.messages:r.card_chats?.messages??[],k=typeof a.receiving=="boolean"?a.receiving:r.card_chats?.receiving??false,d=typeof a.processing=="boolean"?a.processing:r.card_chats?.processing??false,w={messages:p,receiving:k,processing:d};if(T(r.card_chats,w))continue;u(),o[h]={...r,card_chats:w},y=true;}else if(a.kind==="chat_messages"){let h=a.cardId,r=o[h];if(!r)continue;let p=Array.isArray(a.messages)?a.messages:[],k=r.card_chats||{receiving:false,processing:false},d={messages:p,receiving:k.receiving,processing:!!k.processing};if(T(r.card_chats,d))continue;u(),o[h]={...r,card_chats:d},y=true;}else if(a.kind==="status"){let h=a.status?.cards??[];for(let r of h){let p=r?.name;if(!p||!o[p])continue;let k=o[p],d=it(r.status),w={...k.card_data||{},status:d,lastRun:r.runtime?.last_transition_at??null,...r.error?.message?{error:r.error.message}:{}};r.error?.message||delete w.error;let _={task_status:r.status??null,card_status:d,runtime:r.runtime?M(r.runtime):{},error:r.error?M(r.error):null,blocked_by:Array.isArray(r.blocked_by)?M(r.blocked_by):[],requires_missing:Array.isArray(r.requires_missing)?M(r.requires_missing):[]};T(k.card_data,w)&&T(k.runtime_state,_)||(u(),o[p]={...k,card_data:w,runtime_state:_},y=true);}}}return y?{payload:t.payload,cardIds:s,modelsById:o}:t}function ke(t,e="/api/boards"){let n=e.replace(/\/$/,""),g=encodeURIComponent(t||"default"),o=`${n}/${g}`;return {initBoard:`${o}/init-board`,stream:`${o}/sse`,patchCard:s=>`${o}/cards/${encodeURIComponent(s)}`,cardAction:s=>`${o}/cards/${encodeURIComponent(s)}/actions`,cardFile:s=>`${o}/cards/${encodeURIComponent(s)}/files`,cardChats:s=>`${o}/cards/${encodeURIComponent(s)}/chats`,chatSubscribeSse:s=>`${o}/cards/${encodeURIComponent(s)}/chats/subscribe-sse`,chatUnsubscribeSse:s=>`${o}/cards/${encodeURIComponent(s)}/chats/unsubscribe-sse`}}function ve(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 Se(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 ct(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),g=typeof t.file.name=="string"?t.file.name:"upload.bin",o=t.file.type||"application/octet-stream",s=await t.fetchServer(n,{method:"POST",headers:{"content-type":o,"x-file-name":encodeURIComponent(g)},body:t.file});if(!s.ok){let y=await s.text();throw new Error(`Upload failed for ${t.cardId} (${s.status})${y?": "+y:""}`)}return (await s.json())?.file??null}async function ut(t){let{actionType:e}=t;if(e!=="chat-send"&&e!=="file-upload")return t.payload||{};let n={...t.payload||{}},g=Array.isArray(n.files)?n.files:[];if(!g.length)return n.files=[],n;let o=[];for(let s of g){let l=await ct({...t,file:s,inChat:e==="chat-send"});l&&o.push(l);}return n.files=e==="chat-send"?[]:o,n}async function be(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 we(t){let e=t.boardPaths(t.boardId),n=await ut(t),g=await t.fetchServer(e.cardAction(t.cardId),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({actionType:t.actionType,payload:n})});if(!g.ok)throw new Error(`${t.actionType==="refresh"?"Refresh":"Action"} failed for ${t.cardId} (${g.status})`);return {payload:n}}function Ce(t,e){let n=new Set(e.map(String)),g=t.cardIds.filter(s=>n.has(s)),o={};for(let s of g)o[s]=t.modelsById[s];return {payload:t.payload,cardIds:g,modelsById:o}}function _e(t,e){let n=e instanceof Set?e:new Set(e.map(String)),g=t.cardIds.filter(s=>!n.has(s)),o={};for(let s of g)o[s]=t.modelsById[s];return {payload:t.payload,cardIds:g,modelsById:o}}function Re(t){if(!t||typeof t!="object")throw new Error("options are required");let{fetchServer:e,boardPaths:n,getServerOrigin:g}=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 g!="function")throw new Error("options.getServerOrigin is required");let o=t.canvas&&typeof t.canvas=="object"?t.canvas:{height:"72vh",overflow:"auto"},s={current:null},l=null,y=null,i=String(t.initialMode||"board"),u={},a=globalThis.crypto&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():`lc-${Date.now()}-${Math.random().toString(36).slice(2)}`;function r(){return s.current?s.current.payload:null}function k(c,f,b){if(!l||!s.current)return;l.setState(C=>{let v=K(C,[{kind:"card_chats",cardId:c,messages:f,receiving:b}],B,r);return s.current=v,v});let A=l&&l.engine;A&&typeof A.onServerSseEvent=="function"&&A.onServerSseEvent();}async function d(c,f){u[c]=true,k(c,s.current?.modelsById[c]?.card_chats?.messages??[],true);try{await e(f.chatSubscribeSse(c),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:a})});}catch{}}async function w(c,f){delete u[c];try{await e(f.chatUnsubscribeSse(c),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:a})});}catch{}}function _(c){Object.keys(u).forEach(f=>{e(c.chatSubscribeSse(f),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({clientId:a})}).catch(()=>{});});}async function G(c,f,b,A){if(!b)return null;let C=A?.inChat===true,v=typeof b.name=="string"?b.name:"upload.bin",D=b.type||"application/octet-stream",I=n(c),O=C?`${I.cardFile(f)}?inChat=true`:I.cardFile(f),P=await e(O,{method:"POST",headers:{"content-type":D,"x-file-name":encodeURIComponent(v)},body:b});if(!P.ok){let F=await P.text();throw new Error(`Upload failed (${P.status}): ${F||"unknown error"}`)}return (await P.json())?.file??null}async function R(c,f,b,A){if(b!=="chat-send"&&b!=="file-upload")return A||{};let C={...A||{}},v=Array.isArray(C.files)?C.files:[];if(!v.length)return C.files=[],C;let D=[];for(let I of v){let O=await G(c,f,I,{inChat:b==="chat-send"});O&&D.push(O);}return C.files=b==="chat-send"?[]:D,C}async function $(c){let f=String(c?.boardId||"default"),b=typeof c?.taskExecutorPath=="string"?c.taskExecutorPath.trim():"",A=String(c?.mode||i||"board"),C=c?.rootElement;if(!C)throw new Error("bootstrapBoard requires params.rootElement");let v=n(f);let D=b?`${v.initBoard}?taskExecutorPath=${encodeURIComponent(b)}`:v.initBoard,I=await e(D);if(!I.ok)throw new Error(`Server init-board failed (${I.status}).`);let O=g();if(!O)throw new Error("Server origin not resolved before SSE start");let P=await new Promise((m,S)=>{let E=`${O}${v.stream}${v.stream.includes("?")?"&":"?"}clientId=${encodeURIComponent(a)}`,x=new EventSource(E);y=x;let j=false,V=setTimeout(()=>{j||S(new Error("SSE initial payload timeout (15s)"));},15e3);x.onmessage=rt=>{try{let U=JSON.parse(rt.data||"{}");!j&&(U?.cardDefinitions||H(U))&&(j=!0,clearTimeout(V),m(U));}catch{}},x.onerror=()=>{j||(clearTimeout(V),S(new Error("SSE connection failed during bootstrap")));};});if(!H(P))throw new Error("SSE payload missing published runtime artifacts");s.current=J(P,null,B);let N=globalThis.LiveCard;if(!N)throw new Error("LiveCard global not loaded \u2014 include live-cards.js before this script");let F=N.init({resolve:m=>s.current?.modelsById[m],chartLib:globalThis.Chart??null,markdown:globalThis.marked?m=>globalThis.marked.parse(m):null,sanitize:globalThis.DOMPurify?m=>globalThis.DOMPurify.sanitize(m):null,onPatchState:async(m,S)=>{await e(v.patchCard(m),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(S||{})});},onRefresh:async m=>{await e(v.patchCard(m),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({})});},onAction:async(m,S,E)=>{let x=await R(f,m,S,E);await e(v.cardAction(m),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({actionType:S,payload:x||{}})});},startReceivingChats:m=>{d(m,v);},stopReceivingChats:m=>{w(m,v),k(m,s.current?.modelsById[m]?.card_chats?.messages??[],false);}});return C.innerHTML="",l=N.Board(F,C,{initialState:s.current,getNodeIds:m=>m.cardIds,selectNode:(m,S)=>m.modelsById[S],mode:A,canvas:o}),i=A,y.onopen=()=>{_(v);},y.onmessage=m=>{try{let S=JSON.parse(m.data||"{}");if(S?.kind==="notification-batch"&&Array.isArray(S.notifications))l&&l.setState(x=>{let j=K(x,S.notifications,B,r);return s.current=j,j});else if(S?.cardDefinitions){let x=J(S,s.current,B);s.current=x,l&&l.setState(()=>x);}let E=l&&l.engine;E&&typeof E.onServerSseEvent=="function"?E.onServerSseEvent():E&&typeof E.refreshOpenChatModal=="function"&&E.refreshOpenChatModal();}catch(S){console.warn("Bad SSE payload",S);}},l}function W(){y&&(y.close(),y=null),Object.keys(u).forEach(c=>delete u[c]),l=null,s.current=null;}function Q(c){i=String(c||"board");let f=l&&l.core;f&&typeof f.setMode=="function"&&f.setMode(i);}function Z(){if(!l)return;i="canvas";let c=l.core;c&&typeof c.setMode=="function"&&c.setMode("canvas"),c&&typeof c.autoLayout=="function"&&c.autoLayout();}function tt(c){let f=l&&l.core;f&&typeof f.setDevMode=="function"&&f.setDevMode(!!c);}function et(){return i}return {bootstrapBoard:$,dispose:W,setMode:Q,autoLayout:Z,setDevMode:tt,getCurrentMode:et}}exports.applyNotification=K;exports.buildBoardState=J;exports.buildFileUrlBase=Se;exports.createBoardRuntimeClient=Re;exports.defaultBoardPaths=ke;exports.deriveBoardState=dt;exports.dispatchCardAction=we;exports.patchCardState=be;exports.pickBoardState=Ce;exports.prepareActionPayload=ut;exports.selectAllLiveCardModels=H;exports.selectLiveCardModel=B;exports.singleBoardPaths=ve;exports.subtractBoardState=_e;exports.uploadCardFile=ct;return exports;})({});//# sourceMappingURL=board-livecards-client.js.map
|
|
2
2
|
//# sourceMappingURL=board-livecards-client.js.map
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
|
20
20
|
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
|
|
21
21
|
<script src="https://cdn.jsdelivr.net/npm/leader-line/leader-line.min.js"></script>
|
|
22
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.
|
|
23
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.
|
|
22
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.2/browser/live-cards.js"></script>
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.2/browser/board-livecards-client.js"></script>
|
|
24
24
|
</head>
|
|
25
25
|
<body class="bg-light">
|
|
26
26
|
<div class="container-fluid py-3">
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
<title>Example Board Demo (LocalStorage Runtime)</title>
|
|
7
7
|
<link rel="icon" type="image/svg+xml" href="../../browser/favicon.svg" />
|
|
8
8
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
|
|
9
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.
|
|
9
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.2/browser/compute-jsonata.js"></script>
|
|
10
10
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
11
11
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
|
12
12
|
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
|
|
13
13
|
<script src="https://cdn.jsdelivr.net/npm/leader-line/leader-line.min.js"></script>
|
|
14
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.
|
|
15
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.
|
|
14
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.2/browser/live-cards.js"></script>
|
|
15
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.2.2/browser/board-livecards-localstorage.js"></script>
|
|
16
16
|
</head>
|
|
17
17
|
<body class="bg-light">
|
|
18
18
|
<div class="container-fluid py-3">
|