ccdeck 3.29.1 → 3.29.3
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.
- package/dist/web/assets/{BrowserWatchModal-C-TkzDPi.js → BrowserWatchModal-RXK8WXaU.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-FKBbTozZ.js → UsageHistoryModal-Dk5zag6g.js} +1 -1
- package/dist/web/assets/{index-7mOqoJ3Y.js → index-C7djiYSc.js} +7 -7
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/release-notes.json +2 -1
- package/src/server/deck-prefs.mjs +18 -0
- package/src/server/index.mjs +12 -2
|
@@ -87,9 +87,9 @@ They add up to ${n(t.sum)}, more than the ${n(t.total)} above: what a session co
|
|
|
87
87
|
last 5h: ${Bt(y.window5h.totalTokens)} tokens · ${y.window5h.sessionCount} session${y.window5h.sessionCount!==1?"s":""}`:""}`,children:[Bt(y.window7d.totalTokens)," tokens · ",y.window7d.sessionCount," session",y.window7d.sessionCount!==1?"s":""," (7d)"]})]}),W&&o.jsx("div",{className:"uh-range up-period",role:"toolbar","aria-orientation":"horizontal","aria-label":"Period","aria-busy":F||void 0,onKeyDown:ke=>{var Fe;const Re=$.current.indexOf(ke.target);if(Re<0)return;const ze=n8(ke.key,Re);ze!==null&&(ke.preventDefault(),(Fe=$.current[ze])==null||Fe.focus())},children:Ef.map((ke,Re)=>o.jsx("button",{type:"button",ref:ze=>{$.current[Re]=ze},tabIndex:I===ke.key?0:-1,"aria-pressed":I===ke.key,"data-pending":I===ke.key&&F?"":void 0,title:I===ke.key&&F?`Reading ${ke.noun} from the transcripts on this machine…`:ke.hint,className:"uh-range-btn",onClick:()=>O(ke.key),children:ke.label},ke.key))}),W&&o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:F?`Reading ${_S(I,I)}…`:""}),Pe>0?o.jsxs(o.Fragment,{children:[Ge&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:`up-total${ge}`,title:W?void 0:bS,children:[o.jsx("span",{className:"up-total-value",children:ut(Be)}),o.jsx("span",{className:"up-total-label",children:W?le:Pq})]}),Ie.showCostBar&&o.jsx(Ab,{cost:j})]}),o.jsxs("div",{className:`up-tokens-row${ge}`,title:W?void 0:bS,children:[o.jsxs("span",{className:"up-tok",children:[o.jsx("span",{className:"up-k",children:"in"}),Bt(Te)]}),o.jsxs("span",{className:"up-tok",children:[o.jsx("span",{className:"up-k",children:"out"}),Bt(st)]}),Ie.cacheReadTokens>0&&o.jsxs("span",{className:"up-tok",children:[o.jsx("span",{className:"up-k",children:"cache r"}),Bt(de)]}),Ie.cacheCreateTokens>0&&o.jsxs("span",{className:"up-tok",children:[o.jsx("span",{className:"up-k",children:"cache c"}),Bt(ue)]}),!Ge&&o.jsx("span",{className:"up-tok up-scope",children:Dq})]}),(W?U.length:se.length)>0&&o.jsxs("section",{className:`up-section${ge}`,children:[o.jsx("h3",{className:"up-section-title",children:"By model"}),o.jsxs("table",{className:"up-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Model"}),o.jsx("th",{children:"Tokens"}),o.jsx("th",{children:"Cost"})]})}),o.jsx("tbody",{children:W?U.map(ke=>o.jsxs("tr",{children:[o.jsx("td",{className:"up-model-name",title:ke.model,children:so(ke.model)}),o.jsx("td",{className:"up-num",children:Bt(ke.tokens)}),ke.cost>0?o.jsx("td",{className:"up-num up-cost-val",children:ut(ke.cost)}):o.jsx("td",{className:"up-num up-unpriced",children:Cl})]},ke.model)):se.map(ke=>o.jsxs("tr",{children:[o.jsx("td",{className:"up-model-name",title:ke.model===C0?"no model reported yet":ke.model,children:ke.model===C0?"unknown":so(ke.model)}),o.jsx("td",{className:"up-num",children:Bt(ke.inputTokens+ke.outputTokens)}),ke.priced?o.jsx("td",{className:"up-num up-cost-val",children:ut(ke.cost.total)}):o.jsx("td",{className:"up-num up-unpriced",children:Cl})]},ke.model))})]})]}),W&&Y.length===0&&z.tokens>0&&o.jsxs("section",{className:"up-section",children:[o.jsx("h3",{className:"up-section-title",children:"By session"}),o.jsxs("div",{className:"up-hint",children:["No session is dated ",le," yet — ccusage dates sessions in UTC, and the totals above are your local day."]})]}),(W?Y.length:be.length)>0&&(()=>{const ke=W?Y.length:be.length;return o.jsxs("section",{className:`up-section${ge}`,children:[o.jsx("h3",{className:"up-section-title",children:o.jsxs("button",{type:"button",className:"up-disclose","aria-expanded":H,"aria-controls":"up-sessions",title:H?"Hide the per-session breakdown":`Show the per-session breakdown — ${ke} session${ke===1?"":"s"}`,onClick:()=>q(Re=>!Re),children:["By session",W&&o.jsxs("span",{className:"up-section-age",title:i8(le,ie,ut),children:["active ",le]}),o.jsx("svg",{className:"up-chev",width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M2.2 3.6 5 6.4 7.8 3.6"})})]})}),o.jsxs("div",{className:"up-sessions",id:"up-sessions",hidden:!H,children:[W&&Y.map(Re=>{const ze=re.get(Re.sessionId);return o.jsxs("div",{className:"up-session-row",children:[ze?o.jsxs(o.Fragment,{children:[o.jsx("span",{className:`sl-dot state-${ze}`,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:Wl(ze)})]}):o.jsx("span",{className:"sl-dot up-dot-past","aria-hidden":!0}),o.jsx("span",{className:`up-session-label${Re.label?"":" up-session-id"}`,title:Re.label?`${Re.label}
|
|
88
88
|
${Re.sessionId}`:Re.sessionId,children:Re.label??Re.sessionId.slice(0,8)}),o.jsx("span",{className:"up-session-tokens",children:Bt(Re.tokens)}),Re.cost>0?o.jsx("span",{className:"up-session-cost",title:Re.models.join(", ")||void 0,children:ut(Re.cost)}):o.jsx("span",{className:"up-session-cost up-unpriced",children:Cl})]},Re.sessionId)}),!W&&be.map(Re=>o.jsxs("div",{className:"up-session-row",children:[o.jsx("span",{className:`sl-dot state-${Re.state}`,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:Wl(Re.state)}),o.jsx("span",{className:"up-session-label",children:Re.label}),o.jsx("span",{className:"up-session-tokens",children:Bt(Re.inputTokens+Re.outputTokens)}),Re.cost>0?o.jsxs("span",{className:"up-session-cost",title:Re.unpricedTokens>0?`${Bt(Re.unpricedTokens)} tokens in this session are on an unpriced model, so this is a floor`:void 0,children:[ut(Re.cost),Re.unpricedTokens>0?"+":""]}):o.jsx("span",{className:"up-session-cost up-unpriced",children:Cl})]},Re.sessionId))]})]})})(),Le&&o.jsxs("div",{className:"up-hint",children:["“",Cl,"” means this build holds no published rate for that model — those tokens are counted above and their dollars are not."]})]}):o.jsx("div",{className:"up-empty",children:W?o.jsxs(o.Fragment,{children:["No usage ",le,".",o.jsx("br",{}),"Try a longer period."]}):o.jsxs(o.Fragment,{children:["No usage data yet.",o.jsx("br",{}),"Start a Claude Code or Codex session."]})})]})}function Nm(e){return e<9.95?e.toFixed(1):String(Math.round(e))}function Mb(e){const t=Number.isFinite(e)?Math.max(0,e):0;return t<50?{value:"0",unit:"KB/s"}:t<999500?{value:Nm(t/1e3),unit:"KB/s"}:t<9995e5?{value:Nm(t/1e6),unit:"MB/s"}:{value:Nm(t/1e9),unit:"GB/s"}}function Rf(e){const t=Number.isFinite(e)?Math.max(0,e):0;return t<999.5?{value:String(Math.round(t)),unit:"ms"}:{value:(t/1e3).toFixed(1),unit:"s"}}function Tu(e){return e.unit?e.unit==="%"||e.unit==="°C"?`${e.value}${e.unit}`:`${e.value} ${e.unit}`:e.value}function Sm(e,t){return t==="B/s"?Mb(e):t==="ms"?Rf(e):{value:String(e),unit:t==="C"?"°C":t}}const cn={l:30,r:6,t:6,b:2},Ga={l:0,r:0,t:2,b:1},Af=104,_8=64;function ms(e,t=100,n=Af,r=cn){const s=n-r.t-r.b;return r.t+s*(1-Math.max(0,Math.min(t,e))/t)}function $M(e,t,n,r=100,s=Af,l=cn){if(!e.length)return"";const c=e[e.length-1].t-e[0].t,u=h=>{const m=t-l.l-l.r;return l.l+(c>0?m*(h-e[0].t)/c:m/2)};let f="",p=null;for(const h of e){const m=p&&h.t-p.t<=n*2?"L":"M";f+=`${m}${u(h.t).toFixed(1)} ${ms(h.v,r,s,l).toFixed(1)}`,p=h}return f}function OM(e,t,n,r=100,s=Af,l=cn){if(e.length<2)return"";const c=s-l.b,u=e[e.length-1].t-e[0].t,f=t-l.l-l.r,p=v=>l.l+(u>0?f*(v-e[0].t)/u:f/2);let h="",m=[];const y=()=>{if(m.length>=2){let v=`M${p(m[0].t).toFixed(1)} ${c}`;for(const S of m)v+=`L${p(S.t).toFixed(1)} ${ms(S.v,r,s,l).toFixed(1)}`;h+=`${v}L${p(m[m.length-1].t).toFixed(1)} ${c}Z`}m=[]};for(const v of e)m.length&&v.t-m[m.length-1].t>n*2&&y(),m.push(v);return y(),h}function E8(e){return e.length?{now:e[e.length-1].v,peak:e.reduce((t,n)=>Math.max(t,n.v),e[0].v)}:{now:null,peak:null}}function LM(e,t,n){return n!=null&&e>=n?"hot":t!=null&&e>=t?"warn":""}function C8(e,t,n=r=>ei(r)){const r=e.filter(c=>c.v>0);if(!e.length)return null;if(!r.length)return"never held back";const s=r.length*(t/6e4),l=r[r.length-1];return`held back for ${s===1?"1 minute":`${s} minutes`}, last at ${n(l.t)}`}function ei(e){const t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function Ib(e,t){const n=Math.max(0,Math.floor((t-e)/6e4));if(n<1)return"less than a minute";if(n<60)return`${n} minute${n===1?"":"s"}`;const r=Math.floor(n/60),s=n%60;return s?`${r}h ${s}m`:`${r}h`}function T8({group:e,title:t,onClose:n}){const r=pn(n),[s,l]=w.useState(null);w.useEffect(()=>{let p=!0;const h=async()=>{try{const y=await fetch(`/api/system/history?group=${e}`);if(!y.ok)return;const v=await y.json();p&&(v!=null&&v.ok)&&l(v)}catch{}};h();const m=window.setInterval(h,2e4);return()=>{p=!1,window.clearInterval(m)}},[e]);const c=(s==null?void 0:s.series)??[],[u,f]=w.useMemo(()=>{let p=1/0,h=0;for(const m of c)m.points.length&&(p=Math.min(p,m.points[0].t),h=Math.max(h,m.points[m.points.length-1].t));return[Number.isFinite(p)?Math.max(p,(s==null?void 0:s.sinceMs)??0):(s==null?void 0:s.sinceMs)??0,h]},[c,s==null?void 0:s.sinceMs]);return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:r,className:"modal hist-modal",onClick:p=>p.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"hist-modal-title",children:[o.jsxs("div",{className:"modal-head",children:[o.jsx("span",{className:"modal-title",id:"hist-modal-title",children:t}),s&&u>0&&o.jsxs("span",{className:"hist-since",children:["since ",ei(u)," · ",Ib(u,f||Date.now())]}),o.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]}),o.jsx("div",{className:"hist-body",children:s==null?o.jsx("p",{className:"hist-empty",children:"Reading…"}):c.length===0?o.jsx("p",{className:"hist-empty",children:"Nothing has been measured yet."}):c.map(p=>o.jsx(R8,{series:p,stepMs:s.stepMs},p.label))})]})}),document.body)}function R8({series:e,stepMs:t}){const n=w.useRef(null),[r,s]=w.useState(560),[l,c]=w.useState(null);w.useEffect(()=>{const q=n.current;if(!q||typeof ResizeObserver>"u")return;const $=new ResizeObserver(([V])=>s(Math.max(160,V.contentRect.width)));return $.observe(q),()=>$.disconnect()},[]);const{points:u,unit:f,warnAt:p,critAt:h,label:m,top:y,restsAtZero:v,changes:S}=e,b=v?_8:Af,{now:_,peak:k}=E8(u),j=_!=null?Sm(_,f):null,E=k!=null?Sm(k,f):null,C=m==="Throttling"?C8(u,t):null,R=l!=null?u[l]:null,I=u.length>1?u[u.length-1].t-u[0].t:0,O=q=>{const $=r-cn.l-cn.r;return cn.l+(I>0?$*(q-u[0].t)/I:$/2)},H=q=>{if(u.length<2)return;const $=q.currentTarget.getBoundingClientRect(),V=(q.clientX-$.left-cn.l)/Math.max(1,$.width-cn.l-cn.r),ne=u[0].t+I*Math.max(0,Math.min(1,V));let ee=0;for(let M=1;M<u.length;M++)Math.abs(u[M].t-ne)<Math.abs(u[ee].t-ne)&&(ee=M);c(ee)};return o.jsxs("section",{className:"hist-series","aria-label":`${m} history`,children:[o.jsxs("div",{className:"hist-head",children:[o.jsx("span",{className:"hist-label",children:m}),o.jsxs("span",{className:"hist-stats",children:[j&&o.jsxs(o.Fragment,{children:[o.jsx("b",{children:j.value}),o.jsxs("span",{children:[j.unit," now"]})]}),k!=null&&E&&o.jsxs(o.Fragment,{children:[o.jsx("b",{className:LM(k,p,h),children:E.value}),o.jsxs("span",{children:[E.unit," peak"]})]})]})]}),o.jsx("div",{className:"hist-plot",ref:n,children:o.jsxs("svg",{className:"hist-chart",width:"100%",height:b,viewBox:`0 0 ${r} ${b}`,preserveAspectRatio:"none",role:"img","aria-label":j==null||E==null?`${m}: nothing measured yet`:`${m}: ${Tu(j)} now, peak ${Tu(E)}, over ${Ib(u[0].t,u[u.length-1].t)}`,onPointerMove:H,onPointerLeave:()=>c(null),children:[[["warn",p],["hot",h]].map(([q,$])=>$==null||$>y?null:o.jsxs("g",{children:[o.jsx("line",{className:`hist-rule ${q}`,x1:cn.l,x2:r-cn.r,y1:ms($,y,b),y2:ms($,y,b)}),o.jsx("text",{className:`hist-rule-tag ${q}`,x:2,y:ms($,y,b)+3,children:$})]},q)),o.jsx("line",{className:"hist-floor",x1:cn.l,x2:r-cn.r,y1:b-cn.b,y2:b-cn.b}),(S??[]).filter(q=>q.from!=null&&u.length>1&&q.t>=u[0].t&&q.t<=u[u.length-1].t).map(q=>o.jsx("line",{className:"hist-mark",x1:O(q.t),x2:O(q.t),y1:cn.t,y2:b-cn.b},q.t)),o.jsx("path",{className:"hist-area",d:OM(u,r,t,y,b)}),o.jsx("path",{className:"hist-line",d:$M(u,r,t,y,b)}),u.length===1&&o.jsx("circle",{className:"hist-dot",cx:O(u[0].t),cy:ms(u[0].v,y,b),r:3}),R&&o.jsxs("g",{children:[o.jsx("line",{className:"hist-cross",x1:O(R.t),x2:O(R.t),y1:cn.t,y2:b-cn.b}),o.jsx("circle",{className:"hist-dot",cx:O(R.t),cy:ms(R.v,y,b),r:3})]})]})}),o.jsx("div",{className:"hist-axis",children:R?o.jsxs("span",{className:"hist-at",children:[ei(R.t)," — ",(()=>{const q=Sm(R.v,f);return o.jsxs(o.Fragment,{children:[o.jsx("b",{children:q.value}),q.unit==="%"||q.unit==="°C"||!q.unit?q.unit:` ${q.unit}`]})})()]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{children:u.length?ei(u[0].t):""}),o.jsx("span",{children:u.length?ei(u[u.length-1].t):""})]})}),C&&o.jsx("div",{className:"hist-note",children:C}),S==null?void 0:S.slice(-3).map(q=>o.jsx("div",{className:"hist-note hist-route",children:q.from==null?`Since ${ei(q.t)} — ${q.label}`:`${ei(q.t)} — ${q.label.charAt(0).toUpperCase()+q.label.slice(1)}`},q.t))]})}function A8(e,t,n){if(n<=0||Nf(e))return{kind:"pass"};const r=t>=0&&t<n?t:-1;switch(e.key){case"ArrowDown":return{kind:"focus",index:r===-1?0:(r+1)%n};case"ArrowUp":return{kind:"focus",index:r===-1?n-1:(r-1+n)%n};case"Home":return{kind:"focus",index:0};case"End":return{kind:"focus",index:n-1};default:return{kind:"pass"}}}const Ja=4,fs=8;function $b(e,t,n){const r=n.width-fs-(e.right+Ja),s=e.left-Ja-fs,l=t.width<=r||r>=s?"right":"left",c=l==="right"?e.right+Ja:e.left-Ja-t.width,u=n.height-fs*2,f=t.height<=u,p=f?t.height:Math.max(0,u);return{top:Math.max(fs,Math.min(e.top,n.height-fs-p)),left:Math.max(fs,c),side:l,maxHeight:f?null:p}}function M8(e,t,n){const r=n.height-fs-(e.bottom+Ja),s=e.top-Ja-fs,l=t.height<=r||r>=s?"below":"above",c=l==="below"?r:s,u=t.height<=c,f=u?t.height:Math.max(0,c),p=l==="below"?e.bottom+Ja:e.top-Ja-f,h=Math.max(fs,Math.min(e.right-t.width,n.width-fs-t.width));return{top:Math.max(fs,p),left:h,side:l,maxHeight:u?null:f}}const PM='[role="menuitem"]';function TS(e){return e?Array.from(e.querySelectorAll(PM)).filter(t=>!t.disabled):[]}function M0({anchorId:e,boundaryId:t,id:n,className:r,role:s,labelledBy:l,start:c="first",onClose:u,children:f}){const p=w.useRef(u);p.current=u;const h=pn(()=>{var b;(b=document.getElementById(e))==null||b.focus(),p.current()},{popover:!0}),m=w.useCallback(()=>{var C;const b=h.current;if(!b)return;const _=document.getElementById(e);if(!_){p.current();return}const k=_.getBoundingClientRect(),j=t?(C=document.getElementById(t))==null?void 0:C.getBoundingClientRect():null;if(j&&(k.bottom<=j.top||k.top>=j.bottom)){b.contains(document.activeElement)&&_.focus({preventScroll:!0}),p.current();return}b.style.maxHeight="";const E=M8(k,{width:b.offsetWidth,height:b.offsetHeight},{width:window.innerWidth,height:window.innerHeight});b.style.top=`${E.top}px`,b.style.left=`${E.left}px`,b.style.maxHeight=E.maxHeight==null?"":`${E.maxHeight}px`,b.dataset.side=E.side},[e,t,h]);w.useLayoutEffect(()=>{m()}),w.useEffect(()=>{const b=_=>{var k;(k=h.current)!=null&&k.contains(_.target)||m()};return window.addEventListener("scroll",b,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",m)}},[m,h]),w.useEffect(()=>{const b=_=>{var j,E;const k=_.target;!k||(j=h.current)!=null&&j.contains(k)||(E=document.getElementById(e))!=null&&E.contains(k)||p.current()};return window.addEventListener("pointerdown",b,!0),()=>window.removeEventListener("pointerdown",b,!0)},[e,h]),w.useEffect(()=>{var _;if(s!=="menu")return;const b=TS(h.current);(_=c==="last"?b[b.length-1]:b[0])==null||_.focus()},[]);const y=b=>{var _;if(s==="menu"&&b.key==="Tab"){b.stopPropagation(),(_=document.getElementById(e))==null||_.focus(),b.shiftKey&&b.preventDefault(),p.current();return}if(s==="menu"){const k=TS(h.current),j=A8(b,k.indexOf(document.activeElement),k.length);j.kind==="focus"&&(b.preventDefault(),k[j.index].focus())}b.key.length===1&&b.stopPropagation()},v=b=>{b.target.closest("button, input, select, textarea, code")||b.preventDefault()},S=b=>{if(s!=="menu"||b.pointerType==="touch")return;const _=b.target.closest(PM);_&&!_.disabled&&document.activeElement!==_&&_.focus({preventScroll:!0})};return Mn.createPortal(o.jsx("div",{ref:h,id:n,className:`anchored-popover${r?` ${r}`:""}`,role:s,"aria-labelledby":l,onKeyDown:y,onMouseDown:v,onPointerMove:S,children:f}),document.body)}const I8="thermal:Throttling";function $8(e){var n,r,s,l;const t={};e.cpu!=null&&(t["cpu:all"]=e.cpu),(n=e.perCore)!=null&&n.length&&(t["cpu:busiest"]=Math.max(...e.perCore)),e.memory&&(t["mem:physical"]=e.memory.usedPct),e.swap&&e.swap.total>0&&(t["mem:swap"]=Math.round(e.swap.used/e.swap.total*1e3)/10),(r=e.loadavg)!=null&&r.length&&(t["load:1m"]=e.loadavg[0]);for(const c of((s=e.thermal)==null?void 0:s.celsius)??[])t[`thermal:${c.label}`]=c.celsius;return(l=e.thermal)!=null&&l.throttle&&(t[I8]=Math.max(0,100-e.thermal.throttle.speedLimit)),t}function mu(e,t){return t==="B/s"?Tu(Mb(e)):t==="ms"?Tu(Rf(e)):t==="C"?`${Math.round(e)}°`:t==="%"?`${Math.round(e)}%`:e.toFixed(2)}function wh(e,t){return t==="B/s"||t==="ms"||!Number.isInteger(e)?mu(e,t):t==="C"?`${e}°`:t==="%"?`${e}%`:`${e}`}const RS=["cores","memory","load","thermal"],Qo=116,Ls=24,O8=60,L8=6e4;function P8(e){return e.points.length?e.restsAtZero?e.points.some(t=>t.v>0):!0:!1}function D8(e){return e.unit==="C"?`${e.label} temp`:e.key==="mem:physical"?"Physical RAM":e.key==="mem:swap"?`${e.label} memory`:e.label}function F8(e,t=O8){return e.points.length<=t?e:{...e,points:e.points.slice(-t)}}function q8({sys:e}){const[t,n]=w.useState({});w.useEffect(()=>{let c=!0;const u=async()=>{const p=await Promise.all(RS.map(async h=>{try{const m=await fetch(`/api/system/history?group=${h}`);return m.ok?[h,await m.json()]:[h,null]}catch{return[h,null]}}));c&&n(h=>{const m={...h};for(const[y,v]of p)v!=null&&v.ok&&(m[y]=v);return m})};u();const f=setInterval(()=>void u(),L8);return()=>{c=!1,clearInterval(f)}},[]);const r=w.useMemo(()=>$8(e),[e]),s=w.useMemo(()=>RS.flatMap(c=>{const u=t[c];return u?u.series.filter(P8).map(f=>({series:F8(f),stepMs:u.stepMs})):[]}),[t]),l=w.useMemo(()=>{let c=1/0,u=-1/0;for(const{series:f}of s){const p=f.points;p.length&&(c=Math.min(c,p[0].t),u=Math.max(u,p[p.length-1].t))}return Number.isFinite(c)?Ib(c,u):"less than a minute"},[s]);return Object.keys(r).length?o.jsx("div",{className:"pl-strip",role:"group","aria-label":`This machine, over the last ${l}`,children:s.map(({series:c,stepMs:u})=>o.jsx(B8,{series:c,stepMs:u,now:r[c.key],span:l},c.key))}):null}function B8({series:e,stepMs:t,now:n,span:r}){var v;const{points:s,top:l,unit:c,warnAt:u,critAt:f}=e,p=D8(e),h=n??((v=s[s.length-1])==null?void 0:v.v),m=h==null?"":LM(h,u,f),y=Math.max(...s.map(S=>S.v));return o.jsxs("div",{className:`pl-cell${m?` ${m}`:""}`,title:[`${p} · peak ${mu(y,c)} over the last ${r}`,u!=null?`over ${wh(u,c)} is uncomfortable`:"",f!=null?`over ${wh(f,c)} the machine acts`:""].filter(Boolean).join(" · "),children:[o.jsxs("div",{className:"pl-cell-head",children:[o.jsx("span",{className:"pl-cell-label",children:p}),o.jsx("span",{className:"pl-cell-now",children:h==null?"—":mu(h,c)})]}),o.jsxs("svg",{className:"pl-spark",width:Qo,height:Ls,viewBox:`0 0 ${Qo} ${Ls}`,preserveAspectRatio:"none","aria-hidden":!0,children:[o.jsx("line",{className:"pl-spark-floor",x1:0,x2:Qo,y1:Ls-Ga.b,y2:Ls-Ga.b}),o.jsx("path",{className:"pl-spark-area",d:OM(s,Qo,t,l,Ls,Ga)}),u!=null&&o.jsx("line",{className:"pl-rule warn",x1:0,x2:Qo,y1:ms(u,l,Ls,Ga),y2:ms(u,l,Ls,Ga)}),f!=null&&o.jsx("line",{className:"pl-rule hot",x1:0,x2:Qo,y1:ms(f,l,Ls,Ga),y2:ms(f,l,Ls,Ga)}),o.jsx("path",{className:"pl-spark-line",d:$M(s,Qo,t,l,Ls,Ga)})]}),o.jsxs("span",{className:"vis-hidden",children:["peak ",mu(y,c)," over the last ",r,u!=null&&`, uncomfortable over ${wh(u,c)}`,f!=null&&`, the machine acts over ${wh(f,c)}`]})]})}const z8={key:"cpu",dir:"desc"};function U8(e,t){return e.key===t?{...e,dir:e.dir==="asc"?"desc":"asc"}:{key:t,dir:t==="name"||t==="user"?"asc":"desc"}}function H8(e,t){const n=t.dir==="asc"?1:-1,r=l=>t.key==="cpu"?l.cpu:t.key==="mem"?l.mem:t.key==="rss"?l.rssBytes:t.key==="threads"?l.threads:l.uptimeSec,s=(l,c)=>{if(t.key==="name")return n*l.name.localeCompare(c.name,void 0,{sensitivity:"base"});if(t.key==="user"){const p=l.user??"",h=c.user??"";return!p||!h?p===h?0:p?-1:1:n*p.localeCompare(h,void 0,{sensitivity:"base"})}const u=r(l),f=r(c);return u==null||f==null?u==null?f==null?0:1:-1:n*(u-f)};return[...e].sort((l,c)=>s(l,c)||(c.cpu??-1)-(l.cpu??-1)||c.mem-l.mem||l.pid-c.pid)}function W8(e,t){return e.key!==t?"none":e.dir==="asc"?"ascending":"descending"}const V8=4e3;function G8(){const[e,t]=w.useState(null);return w.useEffect(()=>{let n=!0;const r=async()=>{if(document.visibilityState!=="hidden")try{const l=await fetch("/api/system/processes?detail=1");if(!l.ok)return;const c=await l.json();n&&(c!=null&&c.ok)&&t({procs:c.procs??[],total:c.total??0})}catch{}};r();const s=window.setInterval(r,V8);return()=>{n=!1,window.clearInterval(s)}},[]),e}function K8(e){if(e==null||!Number.isFinite(e)||e<0)return"—";if(e<1024)return`${Math.round(e)} B`;const t=["KB","MB","GB","TB"];let n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n>=100?n.toFixed(0):n.toFixed(1)} ${t[r]}`}function Y8(e){return e==null||!Number.isFinite(e)||e<0?"—":e<60?`${Math.floor(e)}s`:e<3600?`${Math.floor(e/60)}m`:e<86400?`${Math.floor(e/3600)}h`:`${Math.floor(e/86400)}d`}function X8({sys:e,onClose:t}){const n=pn(t),[r,s]=w.useState(z8),l=G8(),c=l?H8(l.procs,r):null;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:o.jsxs("div",{ref:n,className:"modal pl-modal",onClick:u=>u.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"pl-modal-title",children:[o.jsxs("div",{className:"modal-head",children:[o.jsx("span",{className:"modal-title",id:"pl-modal-title",children:"Busiest processes"}),l&&o.jsxs("span",{className:"pl-count",children:[c.length," of ",l.total," running"]}),o.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]}),o.jsxs("div",{className:"pl-split",children:[o.jsx("div",{className:"pl-body",children:c==null?o.jsx("p",{className:"pl-empty",children:"Reading the process list…"}):c.length===0?o.jsx("p",{className:"pl-empty",children:"Could not read the process list on this platform."}):o.jsxs("table",{className:"sd-procs pl-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx(xl,{col:"cpu",label:"cpu",sort:r,onSort:s}),o.jsx(xl,{col:"rss",label:"memory",note:"Resident set size, which is what ps and Task Manager report; macOS Activity Monitor shows a different figure.",sort:r,onSort:s}),o.jsx(xl,{col:"threads",label:"threads",sort:r,onSort:s}),o.jsx(xl,{col:"uptime",label:"up",sort:r,onSort:s}),o.jsx(xl,{col:"user",label:"user",sort:r,onSort:s}),o.jsx("th",{scope:"col",className:"pl-pid-h",children:"pid"}),o.jsx(xl,{col:"name",label:"process",note:"Command lines have anything secret-shaped removed, which is a filter and not a guarantee.",sort:r,onSort:s})]})}),o.jsx("tbody",{children:c.map(u=>o.jsxs("tr",{children:[o.jsx("td",{className:"sd-num",children:u.cpu==null?"—":u.cpu.toFixed(0)}),o.jsx("td",{className:"sd-num sd-dim",title:`${u.mem.toFixed(1)}% of installed memory`,children:K8(u.rssBytes)}),o.jsx("td",{className:"sd-num sd-dim",children:u.threads??"—"}),o.jsx("td",{className:"sd-num sd-dim",children:Y8(u.uptimeSec)}),o.jsx("td",{className:"sd-dim pl-user",children:u.user??"—"}),o.jsx("td",{className:"sd-num sd-dim pl-pid",children:u.pid}),o.jsxs("td",{className:"pl-name",children:[u.name,u.cmd&&o.jsxs("span",{className:"pl-cmd",title:u.cmd,children:[" ",u.cmd]})]})]},u.pid))})]})}),o.jsx(q8,{sys:e})]})]})}),document.body)}function xl({col:e,label:t,note:n,sort:r,onSort:s}){const l=W8(r,e);return o.jsx("th",{scope:"col","aria-sort":l,children:o.jsxs("button",{type:"button",className:"sd-sort",title:n?`Sort by ${t}
|
|
89
89
|
|
|
90
|
-
${n}`:`Sort by ${t}`,onClick:()=>s(U8(r,e)),children:[t,o.jsx("span",{className:"sd-sort-dir","aria-hidden":!0,children:l==="none"?"":l==="ascending"?"↑":"↓"})]})})}const Z8=3e3;function Q8(e,t,n){return e>=n?"hot":e>=t?"warn":"calm"}function J8(e,t,n=Date.now()){const r=Math.max(0,Math.min(100,100-e));return{pct:r,value:`${r}%`,tone:r===0?"calm":r>=30?"hot":"warn",note:r>0?`CPU held to ${e}% of full speed to cool down`:t?`at full speed · held to ${100-t.peak}% ${eB(t.lastMs,n)}`:"running at full speed, and never held back"}}function eB(e,t=Date.now()){const n=Math.max(0,Math.floor((t-e)/6e4));if(n<2)return"just now";if(n<60)return`${n} minutes ago`;const r=Math.floor(n/60);return r===1?"an hour ago":`${r} hours ago`}function ru(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${Math.round(e/1024**2)} MB`:`${Math.round(e/1024)} KB`}function tB(e){const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h`:n>0?`${n}h ${r}m`:`${r}m`}function nB(e){var n,r,s;const t=(r=(n=e.thermal)==null?void 0:n.throttle)==null?void 0:r.speedLimit;return t!=null&&t<100?`throttled to ${t}% of full speed`:e.memory&&e.memory.usedPct>=90?`physical memory ${Math.round(e.memory.usedPct)}% full`:(s=e.network)!=null&&s.api&&e.network.api.ms==null?"the Claude API is not answering":null}function rB(){const[e,t]=w.useState(null),n=w.useRef(null);return w.useEffect(()=>{let r=!0;const s=async()=>{if(document.visibilityState!=="hidden")try{const f=await fetch("/api/system");if(!f.ok)return;const p=await f.json();r&&(p!=null&&p.ok)&&t(p)}catch{}},l=()=>{n.current==null&&(s(),n.current=window.setInterval(s,Z8))},c=()=>{n.current!=null&&(window.clearInterval(n.current),n.current=null)},u=()=>{if(document.visibilityState==="hidden"){c();return}l(),s()};return l(),document.addEventListener("visibilitychange",u),()=>{r=!1,c(),document.removeEventListener("visibilitychange",u)}},[]),e}function AS({usageOpen:e,leaving:t,sub:n,flag:r,onClose:s,children:l}){return o.jsxs("aside",{className:`sysdetail${e?" shifted":""}${t?" leaving":""}`,id:"system-panel","aria-labelledby":"sd-title",children:[o.jsxs("div",{className:"sd-top",children:[o.jsxs("div",{className:"sd-head",children:[o.jsx("h2",{className:"sd-title",id:"sd-title",children:"This machine"}),n&&o.jsx("span",{className:"sd-sub",children:n}),o.jsx("button",{type:"button",className:"glyph-btn sd-close",onClick:s,"aria-label":"Close",title:"Close",children:"×"})]}),r&&o.jsx("p",{className:"sd-flag",children:r})]}),l]})}function sB({usageOpen:e,leaving:t,onClose:n}){const r=rB();if(!r||r.cpu==null||!r.memory)return o.jsx(AS,{usageOpen:e,leaving:t,onClose:n,children:o.jsx("div",{className:"sd-note",children:"reading this machine…"})});const{memory:s,swap:l,perCore:c,loadavg:u,cores:f,uptimeSec:p,platform:h,thermal:m,network:y,cpu:v}=r;return o.jsxs(AS,{usageOpen:e,leaving:t,sub:`up ${tB(p)} · ${f} cores`,flag:nB(r),onClose:n,children:[o.jsx(aB,{cpu:v,perCore:c,loadavg:u,cores:f}),o.jsx(oB,{memory:s,swap:l,platform:h}),y&&o.jsx(iB,{network:y}),o.jsx(uB,{thermal:m}),o.jsx(dB,{sys:r})]})}function aB({cpu:e,perCore:t,loadavg:n,cores:r}){const s=!!t&&t.length>0;return!s&&!n?null:o.jsxs("div",{className:"sd-section sd-cpu",role:"group","aria-label":"CPU",children:[s&&o.jsx(Ru,{group:"cores",title:"Core history",action:"Show core history",label:"CPU",value:e==null?null:`${Math.round(e)}%`,children:o.jsx("div",{className:"sd-cores",role:"img","aria-label":`${t.length} logical cores, busiest at ${Math.round(Math.max(...t))}%`,children:t.map((l,c)=>o.jsx("span",{className:"sd-core",title:`logical core ${c+1} · ${l}% busy`,children:o.jsx("span",{className:"sd-core-fill",style:{transform:`scaleY(${Math.max(2,l)/100})`}})},c))})}),n&&o.jsxs(Ru,{group:"load",title:"Load history",action:"Show load history",label:"Load average",hint:"the queue for the cores, counted in tasks rather than as a share of them",children:[o.jsx("div",{className:"sd-figs",title:"The queue for this machine's cores, averaged over one, five and fifteen minutes. A count of tasks, not a share of the CPU.",children:n.map((l,c)=>o.jsx(I0,{value:l.toFixed(2),cap:["1m","5m","15m"][c]},c))}),n[0]>r&&o.jsx("div",{className:"sd-note",children:`${(n[0]/r).toFixed(1)}× more work queued than cores to run it`})]})]})}function oB({memory:e,swap:t,platform:n}){const r=e.total-e.available,s=n==="win32"?"Commit":"Swap",l=t&&t.total>0?t.used/t.total*100:0;return o.jsx("div",{className:"sd-section",role:"group","aria-label":"Memory",children:o.jsxs(Ru,{group:"memory",title:"Memory history",action:"Show memory history",label:"Memory",children:[o.jsx(ef,{label:"Physical",value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:ru(r)})," of ",ru(e.total)]}),pct:e.usedPct,tone:e.usedPct>=90?"warn":"calm",note:`${ru(e.available)} available`}),t&&t.total>0&&o.jsx(ef,{label:s,value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:ru(t.used)})," of ",ru(t.total)]}),pct:l,tone:l>=90?"warn":"calm"})]})})}function iB({network:e}){const{down:t,up:n,api:r,route:s}=e,[l,c]=w.useState(!1),u=r&&r.ms!=null?Rf(r.ms):null,f=t!=null&&n!=null;return o.jsxs("div",{className:"sd-section",role:"group","aria-label":"Network",children:[o.jsxs(Ru,{group:"network",title:"Network history",action:"Show network history",label:"Network",children:[(f||u)&&o.jsxs("div",{className:"sd-figs sd-figs-named",children:[f&&[["Download",t],["Upload",n]].map(([p,h])=>{const m=Mb(h);return o.jsx(I0,{value:m.value,unit:m.unit,cap:p},p)}),u&&o.jsx(I0,{value:u.value,unit:u.unit,cap:"Claude API"})]}),!f&&o.jsx("div",{className:"sd-note",children:"measuring…"}),r&&r.ms==null&&o.jsx("div",{className:"sd-note sd-note-warn",children:"Can’t reach Claude"})]}),s&&o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",className:"sd-detail",id:"sd-conn","aria-expanded":l,"aria-haspopup":"dialog",onClick:()=>c(p=>!p),children:["Connection details",s.relay&&o.jsx("span",{className:"sd-route-relay",children:" · relayed"}),o.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),l&&o.jsx(cB,{route:s,api:r,onClose:()=>c(!1)})]})]})}function I0({value:e,unit:t,cap:n}){return t?o.jsxs("span",{className:"sd-fig",children:[o.jsx("span",{className:"sd-fig-cap",children:n}),o.jsxs("span",{className:"sd-fig-read",children:[o.jsx("b",{children:e})," ",o.jsx("span",{className:"sd-fig-unit",children:t})]})]}):o.jsxs("span",{className:"sd-fig",children:[o.jsx("b",{children:e}),o.jsx("span",{className:"sd-fig-cap",children:n})]})}function lB(e){return e.kind==="tailscale-exit"?e.node?`Tailscale exit node ${e.node}`:"a Tailscale exit node":e.kind==="tailscale"?"Tailscale":`${e.name?`${e.name} `:""}VPN${e.iface?` (${e.iface})`:""}`}function cB({route:e,api:t,onClose:n}){return o.jsxs(M0,{anchorId:"sd-conn",boundaryId:"system-panel",id:"sd-conn-pop",className:"sd-pop",role:"dialog",labelledBy:"sd-conn-title",onClose:n,children:[o.jsx("p",{className:"sd-pop-title",id:"sd-conn-title",children:"Connection"}),o.jsxs("dl",{className:"sd-pop-rows",children:[o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:e.to==="claude"?"Traffic to Claude":"Internet traffic"}),o.jsxs("dd",{children:["through ",lB(e)]})]}),e.relay&&o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Relay"}),o.jsxs("dd",{children:[o.jsx("span",{className:"sd-route-relay",children:e.relay})," — not a direct path, so every packet carries one more round trip than it has to"]})]}),t&&o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Round trip"}),o.jsx("dd",{children:t.ms==null?`${t.host} did not answer`:`${Tu(Rf(t.ms))} to open a connection to ${t.host}`})]}),o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Throughput"}),o.jsx("dd",{children:"every interface on this machine, not this path alone"})]})]})]})}function Ru({group:e,title:t,action:n,label:r,value:s,hint:l,children:c}){const[u,f]=w.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",className:"sd-open",onClick:()=>f(!0),title:n,"aria-label":s==null?n:`${n}, now ${s}`,"aria-describedby":l?`sd-hint-${e}`:void 0,children:[o.jsxs("div",{className:"sd-h","aria-hidden":!0,children:[r," ",o.jsx("i",{className:"sd-row-more",children:"›"}),s!=null&&o.jsx("span",{className:"sd-h-val",children:s})]}),c]}),l&&o.jsx("span",{id:`sd-hint-${e}`,className:"vis-hidden",children:l}),u&&o.jsx(T8,{group:e,title:t,onClose:()=>f(!1)})]})}function uB({thermal:e}){if(!e)return null;const t=e.throttle?J8(e.throttle.speedLimit,e.heldBack):null;return o.jsx("div",{className:"sd-section",role:"group","aria-label":"Thermal",children:o.jsxs(Ru,{group:"thermal",title:"Thermal history",action:"Show thermal history",label:"Thermal",children:[e.celsius.map(n=>o.jsx(ef,{label:n.label,value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:n.celsius})," °C"]}),pct:n.celsius/n.critAt*100,mark:n.warnAt/n.critAt*100,tone:Q8(n.celsius,n.warnAt,n.critAt),title:`bar runs 0–${n.critAt} °C · amber from ${n.warnAt} °C, red at ${n.critAt} °C`,trackLabel:`${n.celsius} °C on a bar that runs to ${n.critAt} °C, amber from ${n.warnAt} °C`},n.label)),t&&o.jsx(ef,{label:"Throttling",value:o.jsx("b",{children:t.value}),pct:t.pct,tone:t.tone,note:t.note})]})})}function dB({sys:e}){const[t,n]=w.useState(!1);return o.jsxs("div",{className:"sd-section sd-door-section",children:[o.jsx("button",{type:"button",className:"sd-open sd-door",onClick:()=>n(!0),"aria-label":"Show every process the deck is watching",children:o.jsxs("span",{className:"sd-door-plate",children:[o.jsxs("span",{className:"sd-door-name",children:["Busiest processes",o.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),o.jsx("span",{className:"sd-door-sub",children:"every process, with its command line"})]})}),t&&o.jsx(X8,{sys:e,onClose:()=>n(!1)})]})}function ef({label:e,value:t,pct:n,tone:r="calm",note:s,mark:l,title:c,trackLabel:u}){return o.jsxs("div",{className:"sd-row",title:c,children:[o.jsxs("div",{className:"sd-row-head",children:[o.jsx("span",{className:"sd-row-label",children:e}),o.jsx("span",{className:"sd-row-val",children:t})]}),o.jsxs("span",{className:"sd-track",role:u?"img":void 0,"aria-label":u,children:[o.jsx("span",{className:`sd-fill${r==="calm"?"":` ${r}`}`,style:{transform:`scaleX(${n<=0?0:Math.max(1,Math.min(100,n))/100})`}}),l!=null&&l>0&&l<100&&o.jsx("span",{className:"sd-mark",style:{left:`${l}%`},"aria-hidden":!0})]}),s&&o.jsx("div",{className:"sd-note",children:s})]})}function MS(e){return{inputTokens:e.i,outputTokens:e.o,cacheReadTokens:e.cr,cacheCreateTokens:e.cc,cacheCreate1hTokens:e.c1h,cacheCreate5mTokens:e.c5m}}function IS(e){let t=0;for(const n of Object.values(e))t+=n.i+n.o+n.cr+n.cc;return t}function hB(e,t,n,r=Date.now()){const s=n.size>0,l=new Map;for(const[E,C]of n){const R=E.indexOf("|"),I=E.slice(0,R),O=E.slice(R+1),H=ri(C.usage,O,r).total,q=H>0?C.cost/H:1;let $=l.get(I);$||($=new Map,l.set(I,$)),$.set(O,q)}const c=(E,C)=>{const R=l.get(E);return(R==null?void 0:R.get(C))??(R==null?void 0:R.get(Ql(C)))??1},u=(E,C)=>{let R=0;for(const[I,O]of Object.entries(E))R+=ri(MS(O),I,r).total*c(C,I);return R},f=new Map,p=[];for(const E of e){const C=new Map;let R=0;for(const I of E.projects){const O=u(I.models,E.day);C.set(I.path,(C.get(I.path)??0)+O),R+=O;let H=f.get(I.path);H||(H={path:I.path,cost:0,tokens:0},f.set(I.path,H)),H.cost+=O,H.tokens+=IS(I.models)}p.push({day:E.day,total:R,byPath:C})}const h=[...f.values()].sort((E,C)=>C.cost-E.cost||C.tokens-E.tokens),m=h.reduce((E,C)=>E+C.cost,0),y=h.reduce((E,C)=>E+C.tokens,0);let v=0,S=0;for(const E of n.values())v+=E.cost;for(const[E,C]of n)S+=ri(C.usage,E.slice(E.indexOf("|")+1),r).total;const b=S>0?v/S:1,_=t?IS(t):0;let k=0;if(t)for(const[E,C]of Object.entries(t))k+=ri(MS(C),E,r).total*b;const j=k>0||_>0?{cost:k,tokens:_}:null;return{projects:h,totalCost:m,totalTokens:y,perDay:p,unattributed:j,reconciled:s}}function DM(e){return/^[A-Za-z]:[\\/]$/.test(e)?e:e.replace(/[\\/]+$/,"")}function jm(e){const t=DM(e).replace(/\\/g,"/");return/^[A-Za-z]:\//.test(t)?t.toLowerCase():t}function $S(e){if(!e)return e;const t=DM(e),n=t.match(/^\/(?:Users|home)\/[^/]+(\/.*)?$/);if(n)return`~${n[1]??""}`;const r=t.replace(/\\/g,"/").match(/^[A-Za-z]:\/Users\/[^/]+(\/.*)?$/i);return r?`~${r[1]??""}`:t.replace(/\\/g,"/")}function fB(e,t){const n=jm(e);let r;for(const s of t){const l=jm(s.path);!l||l===n||!n.startsWith(`${l}/`)||(!r||jm(r.path).length<l.length)&&(r=s)}return r==null?void 0:r.label}function $0(e){return e===0?"all time":e===1?"today":`the last ${e} days`}function pB(e){return e===1?"No work attributed to this account yet today.":`No work attributed to this account in ${$0(e)}.`}function mB(e){return e===1?7:e===7?30:e===30?0:null}function gB(e,t){return e!==1&&t>0}const yB=[{days:1,label:"Today"},{days:7,label:"7d"},{days:30,label:"30d"},{days:0,label:"All"}],bl=["var(--usage-blue)","var(--usage-green)","var(--usage-amber)","var(--usage-purple)","var(--usage-indigo)","var(--usage-red)","var(--usage-orange)","var(--usage-zinc)"],wB="var(--usage-zinc)",_m=6,vB=1600;function OS(e){return`${e.getFullYear()}${String(e.getMonth()+1).padStart(2,"0")}${String(e.getDate()).padStart(2,"0")}`}function xB(e){const t=ut(e),n=/^\$(\d{4,})$/.exec(t);return n?`$${Number(n[1]).toLocaleString("en-US")}`:t}function LS(e,t){if(t<=0||e<=0)return"0%";const n=e/t*100;return n<.01?"<0.01%":n<1?`${n.toFixed(2)}%`:n<10?`${n.toFixed(1)}%`:`${Math.round(n)}%`}function bB(e){const t=/^\d{4}-(\d{2})-(\d{2})$/.exec(e);return t?`${Number(t[1])}/${Number(t[2])}`:e}function kB(e){const t=Math.max(1,Math.ceil(e/6));return n=>n===0||n===e-1||n%t===0}function Em(e){if(!e)return"";try{return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return""}}function NB({num:e,name:t,onClose:n}){const[r,s]=w.useState(1),[l,c]=w.useState(null),[u,f]=w.useState(r),[p,h]=w.useState(null),[m,y]=w.useState(null),[v,S]=w.useState(()=>new Set),[b,_]=w.useState(!0),[k,j]=w.useState(null),[E,C]=w.useState(null),R=w.useRef(void 0),I=w.useRef(!0);w.useEffect(()=>()=>{I.current=!1,window.clearTimeout(R.current)},[]);const O=w.useRef(null),H=pn(n,{focusRef:O}),q=w.useRef(0);w.useEffect(()=>{const D=++q.current;_(!0),j(null),y(null),S(new Set);const P=r===0?60:r,B=OS(new Date(Date.now()-(P-1)*864e5)),W=OS(new Date),F=fetch(`/api/account-projects?num=${e}&days=${r}`,{credentials:"same-origin"}).then(re=>re.ok?re.json():Promise.reject(new Error(`HTTP ${re.status}`))),G=fetch(`/api/ccusage?since=${B}&until=${W}`,{credentials:"same-origin"}).then(re=>re.ok?re.json():null).catch(()=>null);Promise.all([F,G]).then(([re,U])=>{if(D!==q.current)return;c(re),f(r);const Y=U;h(Y&&Y.ok!==!1?Y:null),_(!1)}).catch(re=>{D===q.current&&(j(re.message||"Could not load"),c(null),_(!1))})},[e,r]);const $=w.useMemo(()=>{const D=Date.now();if(!l)return null;const P=ue=>typeof ue=="number"&&Number.isFinite(ue)?ue:0,B=new Map;if(p){const ue=Array.isArray(p.days)?p.days:[];for(const se of ue){const be=typeof se.period=="string"?se.period:"",Le=Array.isArray(se.modelBreakdowns)?se.modelBreakdowns:[];for(const ce of Le){const pe=typeof ce.modelName=="string"?ce.modelName:"";if(!be||!/claude/i.test(pe))continue;const Ae=`${be}|${pe}`,fe=B.get(Ae),Se=fe?fe.usage:{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreateTokens:0,cacheCreate1hTokens:0,cacheCreate5mTokens:0};Se.inputTokens+=P(ce.inputTokens),Se.outputTokens+=P(ce.outputTokens),Se.cacheReadTokens+=P(ce.cacheReadTokens),Se.cacheCreateTokens+=P(ce.cacheCreationTokens),fe?fe.cost+=P(ce.cost):B.set(Ae,{cost:P(ce.cost),usage:Se})}}}const W=hB(l.daily??[],l.unattributed,B,D),F=ue=>ue.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||ue||"(unknown)",G=new Map;for(const ue of W.projects)G.set(F(ue.path),(G.get(F(ue.path))??0)+1);const re=ue=>{const se=F(ue);if((G.get(se)??0)<=1)return se;const be=ue.replace(/[\\/]+$/,"").split(/[\\/]/).slice(-2,-1)[0];return be?`${be}/${se}`:se},U=W.projects.map(ue=>({path:ue.path,label:re(ue.path)})),Y=ue=>({path:ue.path,label:re(ue.path),parentLabel:fB(ue.path,U),cost:ue.cost,tokens:ue.tokens}),z=bl[_m%bl.length],ie=new Map,le=[],ge=W.projects.slice(0,_m),Ne=W.projects.slice(_m);ge.forEach((ue,se)=>{ie.set(ue.path,bl[se%bl.length]),le.push({key:ue.path,...Y(ue),color:bl[se%bl.length]})}),Ne.length&&le.push({key:"__other__",label:`Other · ${Ne.length} project${Ne.length>1?"s":""}`,cost:Ne.reduce((ue,se)=>ue+se.cost,0),tokens:Ne.reduce((ue,se)=>ue+se.tokens,0),color:z,muted:!0,members:Ne.map(Y)});const Ie=W.totalCost,Ge=W.totalTokens,Pe=Ie>0?"cost":"tokens",Be=Pe==="cost"?Ie:Ge,Te=le.map(ue=>ue.color),st=W.perDay.map(ue=>{const se=new Map;for(const[be,Le]of ue.byPath){const ce=ie.get(be)??z;se.set(ce,(se.get(ce)??0)+Le)}return{day:ue.day,total:ue.total,costByColor:se}}),de=st.reduce((ue,se)=>Math.max(ue,se.total),0);return{rows:le,totalCost:Ie,totalTokens:Ge,basis:Pe,denom:Be,un:W.unattributed,reconciled:W.reconciled,chart:st,maxDay:de,colorOrder:Te}},[l,p]),V=(D,P)=>{hi(D).then(B=>{I.current&&(window.clearTimeout(R.current),C({path:D,label:P,ok:B}),R.current=window.setTimeout(()=>{I.current&&C(null)},vB))})},ne=D=>E!=null&&E.ok&&E.path===D?"Copied":"Copy",ee=l!=null&&l.trackedSince?`Tracked since ${Em(l.trackedSince)}`:"Tracking starts with this version",M=$0(u),Z=mB(u),K=b&&!!l;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:H,className:"modal ap-proj-modal",onClick:D=>D.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ap-proj-title ap-proj-sub",children:[o.jsxs("header",{className:"ap-proj-head",children:[o.jsxs("div",{className:"ap-proj-titlewrap",children:[o.jsx("div",{className:"ap-proj-title",id:"ap-proj-title",children:"Projects"}),o.jsx("div",{className:"ap-proj-sub",id:"ap-proj-sub",title:t,children:t})]}),o.jsx("div",{className:"uh-range",role:"group","aria-label":"Range",children:yB.map(D=>o.jsx("button",{type:"button",className:"uh-range-btn","aria-pressed":r===D.days,onClick:()=>s(D.days),children:D.label},D.days))}),o.jsx("button",{ref:O,className:"glyph-btn ap-proj-close",onClick:n,"aria-label":"Close",children:"×"})]}),o.jsxs("div",{className:`ap-proj-body${K?" refreshing":""}`,"aria-busy":b,children:[b&&!l&&o.jsx("div",{className:"ap-proj-state",children:"Loading…"}),!b&&k&&o.jsxs("div",{className:"ap-proj-state ap-proj-error",children:["Couldn’t load this report: ",k]}),!k&&$&&o.jsx(o.Fragment,{children:$.rows.length===0?o.jsxs("div",{className:"ap-proj-state",children:[pB(u),Z!=null&&o.jsx("div",{className:"ap-proj-widen-wrap",children:o.jsxs("button",{type:"button",className:"ap-proj-copy",onClick:()=>s(Z),children:["Show ",$0(Z)]})}),o.jsxs("div",{className:"ap-proj-note",children:[ee,". Only work from this version onward can be tied to an account."]})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"ap-proj-bar",role:"img","aria-label":`Share of ${ut($.totalCost)} across ${$.rows.length} projects`,children:$.rows.map(D=>{const P=$.basis==="cost"?D.cost:D.tokens,B=$.denom>0?P/$.denom*100:0;return B<=0?null:o.jsx("span",{className:"ap-proj-seg",style:{width:`${B}%`,background:D.color},title:`${D.label} · ${ut(D.cost)} · ${LS(D.cost,$.totalCost)}${D.tokens?` · ${Bt(D.tokens)} tokens`:""}`},D.key)})}),o.jsxs("div",{className:"ap-proj-totals",children:[o.jsx("span",{className:"ap-proj-total-cost",children:ut($.totalCost)}),o.jsxs("span",{className:"ap-proj-total-tok",children:[Bt($.totalTokens)," tokens"]}),o.jsxs("span",{className:"ap-proj-total-win",children:["· ",M]})]}),gB(u,$.chart.length)&&o.jsxs("div",{className:"ap-proj-days",children:[o.jsxs("div",{className:"ap-proj-days-cap",children:["By day",$.chart.length>1?" · click a bar":""]}),o.jsx("div",{className:"ap-proj-days-plot",role:"img","aria-label":`Spend across ${$.chart.length} day${$.chart.length>1?"s":""}`,children:$.chart.map(D=>{const P=$.maxDay>0?D.total/$.maxDay*100:0,B=m===D.day,W=$.rows.map(G=>({label:G.label,c:D.costByColor.get(G.color)??0})).filter(G=>G.c>0),F=`${Em(Date.parse(`${D.day}T00:00:00`))}, ${ut(D.total)}. ${W.map(G=>`${G.label} ${ut(G.c)}`).join(", ")}`;return o.jsx("button",{type:"button",className:`ap-proj-day${B?" selected":""}`,"aria-pressed":B,"aria-label":F,title:`${D.day} · ${ut(D.total)}`,onClick:()=>y(G=>G===D.day?null:D.day),children:o.jsx("span",{className:"ap-proj-col",style:{height:`${P}%`},children:$.colorOrder.map((G,re)=>{const U=D.costByColor.get(G)??0;return U<=0||D.total<=0?null:o.jsx("span",{className:"ap-proj-colseg",style:{height:`${U/D.total*100}%`,background:G}},re)})})},D.day)})}),(()=>{const D=kB($.chart.length);return o.jsx("div",{className:"ap-proj-days-axis","aria-hidden":"true",children:$.chart.map((P,B)=>o.jsx("div",{className:"ap-proj-axis-cell",children:D(B)?bB(P.day):""},P.day))})})(),(()=>{const D=m?$.chart.find(B=>B.day===m):null;if(!D)return null;const P=$.rows.map(B=>({r:B,c:D.costByColor.get(B.color)??0})).filter(B=>B.c>0);return o.jsxs("div",{className:"ap-proj-day-detail",children:[o.jsxs("div",{className:"ap-proj-day-detail-head",children:[o.jsx("span",{children:Em(Date.parse(`${D.day}T00:00:00`))}),o.jsx("span",{className:"ap-proj-day-detail-total",children:ut(D.total)})]}),P.map(({r:B,c:W})=>o.jsxs("div",{className:"ap-proj-day-detail-row",children:[o.jsx("span",{className:"ap-proj-dot",style:{background:B.color},"aria-hidden":"true"}),o.jsx("span",{className:"ap-proj-day-detail-name",children:B.label}),o.jsx("span",{className:"ap-proj-day-detail-cost",children:ut(W)})]},B.key))]})})()]}),o.jsx("ul",{className:"ap-proj-list",children:$.rows.map((D,P)=>{const B=$.basis==="cost"?D.cost:D.tokens,W=$.denom>0?B/$.denom*100:0,F=v.has(D.key),G=`ap-proj-details-${P}`,re=F&&(!!D.path||!!D.members),U=D.members?`${F?"Hide":"Show"} the ${D.members.length} project${D.members.length>1?"s":""} folded into Other`:`${F?"Hide":"Show"} location for ${D.label}`;return o.jsxs("li",{className:`ap-proj-row${D.muted?" muted":""}${F?" expanded":""}`,children:[o.jsx("span",{className:"ap-proj-dot",style:{background:D.color},"aria-hidden":"true"}),o.jsxs("span",{className:"ap-proj-name",children:[D.label,D.parentLabel&&o.jsxs("span",{className:"ap-proj-parent",children:[" · in ",D.parentLabel]})]}),o.jsx("span",{className:"ap-proj-track",title:`${LS(D.cost,$.totalCost)} of tracked cost`,children:o.jsx("span",{className:"ap-proj-fill",style:{width:`${W}%`,background:D.color}})}),o.jsx("span",{className:"ap-proj-cost",children:ut(D.cost)}),o.jsx("span",{className:"ap-proj-tok",children:Bt(D.tokens)}),o.jsx("button",{type:"button",className:"glyph-btn ap-proj-info","aria-expanded":F,"aria-controls":re?G:void 0,"aria-label":U,onClick:()=>S(Y=>{const z=new Set(Y);return z.has(D.key)?z.delete(D.key):z.add(D.key),z}),children:"ⓘ"}),F&&D.path&&o.jsxs("div",{className:"ap-proj-details",id:G,children:[o.jsx("code",{className:"ap-proj-path",children:$S(D.path)}),o.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${ne(D.path)} location for ${D.label}`,onClick:()=>V(D.path,D.label),children:ne(D.path)})]}),F&&D.members&&o.jsx("div",{className:"ap-proj-details ap-proj-other-members",id:G,children:D.members.map(Y=>o.jsxs("div",{className:"ap-proj-other-member",children:[o.jsxs("div",{className:"ap-proj-other-name",children:[Y.label,Y.parentLabel&&o.jsxs("span",{className:"ap-proj-parent",children:[" · in ",Y.parentLabel]})]}),o.jsx("code",{className:"ap-proj-path",children:$S(Y.path)}),o.jsx("span",{className:"ap-proj-cost",children:ut(Y.cost)}),o.jsx("span",{className:"ap-proj-tok",children:Bt(Y.tokens)}),o.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${ne(Y.path)} location for ${Y.label}`,onClick:()=>V(Y.path,Y.label),children:ne(Y.path)})]},Y.path))})]},D.key)})}),$.un&&o.jsxs("div",{className:"ap-proj-unattributed",children:[o.jsx("span",{className:"ap-proj-dot",style:{background:wB},"aria-hidden":"true"}),o.jsxs("div",{className:"ap-proj-un-labels",children:[o.jsx("span",{className:"ap-proj-un-title",children:"Unattributed usage"}),o.jsx("span",{className:"ap-proj-un-tag",children:"Excluded from the project totals"})]}),o.jsx("span",{className:"ap-proj-un-cost",children:xB($.un.cost)}),o.jsx("span",{className:"ap-proj-un-tok",children:Bt($.un.tokens)}),o.jsx("div",{className:"ap-proj-note",children:"Work no account could be tied to — from before tracking, or a gap."})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:E&&(E.ok?`Copied the location of ${E.label}`:`Could not copy the location of ${E.label} — select it and copy it by hand`)}),o.jsxs("div",{className:"ap-proj-foot",children:[$.reconciled?"Dollars from ccusage · split by activity":"Dollars estimated · ccusage unavailable"," · ",ee]})]})})]})]})}),document.body)}const PS=18,SB=1100,kl=(e,t)=>{const n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)},jB=Array.from({length:PS},(e,t)=>{const n=-72+144*t/(PS-1)+(kl(t,1)-.5)*9,r=(n-90)*(Math.PI/180),s=(54+32*Math.cos(n*Math.PI/180))*(.74+kl(t,2)*.52);return{dx:Math.cos(r)*s,dy:Math.sin(r)*s,rot:(t%2?1:-1)*(100+kl(t,3)*260),delay:Math.round(kl(t,4)*90),dur:760+Math.round(kl(t,5)*260),scale:.8+kl(t,6)*.45,hue:t%4,round:t%3===0}});function DS({anchor:e}){var s;const[t,n]=w.useState(null),r=typeof window<"u"&&((s=window.matchMedia)==null?void 0:s.call(window,"(prefers-reduced-motion: reduce)").matches);return w.useEffect(()=>{if(r)return;const l=e.current;if(!l)return;const c=l.getBoundingClientRect();n({x:c.left+c.width/2,y:c.top+c.height/2});const u=window.setTimeout(()=>n(null),SB);return()=>window.clearTimeout(u)},[e,r]),r||!t?null:Mn.createPortal(o.jsx("div",{className:"confetti",style:{left:`${t.x}px`,top:`${t.y}px`},"aria-hidden":!0,children:jB.map((l,c)=>o.jsx("span",{className:`confetti-bit${l.round?" round":""}`,"data-hue":l.hue,style:{"--dx":`${l.dx.toFixed(1)}px`,"--dy":`${l.dy.toFixed(1)}px`,"--rot":`${l.rot}deg`,"--s":l.scale.toFixed(2),animationDelay:`${l.delay}ms`,animationDuration:`${l.dur}ms, ${l.dur}ms`}},c))}),document.body)}const FM=new Set(["awaiting_url","awaiting_code","registering"]);function _B(e){return e!=null&&FM.has(e)}function qM(e){return e!=null&&e!=="done"&&!FM.has(e)}const EB="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",CB="the sign-in did not complete";function TB({state:e,serverError:t,localError:n}){const r=e==="idle";return{title:r?"Sign-in ended":"Sign-in failed",message:n||t||(r?EB:CB)}}function RB({restored:e,activeAccount:t}){if(e!==!1)return null;const n=(t==null?void 0:t.email)||((t==null?void 0:t.num)!=null?`account ${t.num}`:null);return n?`This machine is now signed in as ${n} — the account you were using could not be put back. Switch back from the accounts panel.`:"The account you were using could not be put back — check which account this machine is signed in as from the accounts panel."}function AB({started:e,state:t}){return!e||t==="done"?null:{action:"login-cancel"}}const MB="done";function IB(){let e=!1;return{shouldAnnounce(t){return t!==MB?(e=!1,!1):e?!1:(e=!0,!0)}}}function Ob(e,t){return t&&Object.hasOwn(e,t)?e[t]:void 0}const $B={already_running:"a sign-in is already in progress",no_url:"the claude CLI did not offer a sign-in link — is it installed?",not_waiting:"that sign-in is no longer waiting for a code",not_prompted:"the CLI has not asked for a code yet",code_rejected:"that code was not accepted — copy it again from the browser",no_verdict:"the claude CLI has not answered — try the code again",empty_code:"paste the code from the browser first",login_failed:"the code was not accepted",no_identity:"signed in, but the CLI still reports nobody logged in",add_failed:"signed in, but claude-swap could not record the account",not_a_share:"that does not look like a shared account — it should start with ccdeck2:",corrupt:"that share is incomplete — copy the whole thing",wrong_version:`that share was made by a newer ${dn}`,expired:"that share has expired — make a new one",import_failed:"claude-swap refused the import",unreadable_export:"claude-swap wrote something this deck could not read — try again, and upgrade it if this repeats",mixed_versions:"claude-swap changed format part-way through — try again",nothing_to_share:"none of those accounts could be exported",too_many:"that is more accounts than one share can carry",not_in_bundle:"that account is not in this share",bad_value:"an alias can only use letters, numbers, spaces, dots, dashes and underscores, up to 64 characters, and cannot start with a dash",bad_email:"that does not look like an email address — it cannot contain spaces or start with a dash"},OB={no_cswap:"claude-swap could not be run — it is not on this deck's PATH. Set AGENTS_DECK_CSWAP to its full path",timeout:"claude-swap took too long and was stopped — try again",switch_failed:"claude-swap refused the switch",bad_account:"that is not an account claude-swap has",unknown_setting:"claude-swap has no such setting",out_of_range:"that value is outside what the setting allows",bad_value:"claude-swap does not accept that value",set_failed:"claude-swap refused the change",command_failed:"claude-swap refused the command"},Lb=`claude-swap could not read the login keychain — start ${dn} from a Terminal window rather than a background service`,FS={unreadable_here:{short:"Keychain locked on this Mac",long:`${Lb}.`},no_credentials_here:{short:"no stored login here",long:"claude-swap still holds no login for it here."},relogin_required_here:{short:"login expired",long:"the imported login was rejected — sign in again on a deck where it still works."},unverified_here:{short:"not checked",long:"claude-swap could not confirm whether this Mac can read it."}};function tf(e){return e&&Object.hasOwn(FS,e)?FS[e]:null}const BM={401:"this deck did not accept the page as its own, so nothing was changed",403:"this deck refused a change from this address — open it on the address the deck prints, not through a proxy"};function O0(e,t,n){const r=n==null?null:BM[n];if(r)return r;if((e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test(Au(e)))return Lb;const s=Ob(OB,e==null?void 0:e.reason);return s||(e==null?void 0:e.reason)||t}function Au(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const LB={no_install:"ccusage is not installed, and AGENTS_DECK_NO_INSTALL=1 forbids fetching it — unset that variable and restart the deck, or install ccusage yourself so it is on this deck's PATH",bad_override:"AGENTS_DECK_CCUSAGE names a file that is not there — correct it to the full path of your ccusage, or unset it to let the deck find its own",timeout:"ccusage took more than 90 seconds and was stopped — a narrower range usually finishes",bad_output:"ccusage ran but printed no usage data — try again, and run ccusage daily --json in a terminal if it keeps happening",run_failed:"ccusage could not report usage — try again",bad_range:"that date range is not a YYYYMMDD date — reopen the modal and pick one of the presets",unreachable:"the deck did not answer — check it is still running, then try again"},PB="ccusage could not be started — npx is not on this deck's PATH. Install Node's npm/npx, or put ccusage on PATH yourself";function DB(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}const FB="ccusage could not be started — the deck launched npx and Node could not load the npm script it points at. An older deck asked cmd.exe for a bare npx.cmd, which made the shim look for that script under the deck's working directory instead of beside itself; update the deck and reopen this modal",qB="ccusage could not be started — the copy npx fetched will not load: Node could not resolve a file inside it. That copy is in npx's own cache, which the deck never rewrites, so clear it with `npm cache clean --force` and reopen this modal",BB=e=>/\b(?:ERR_)?MODULE_NOT_FOUND\b|cannot find (?:module|package)/i.test(e),zB=/node_modules[\\/]npm[\\/]bin[\\/]|\bnpm-prefix\.js\b|\bnp[mx][-.][\w.-]*cli\.js\b/i,UB=/[\\/]_npx[\\/]/i,HB=`the copy of ccusage ${dn} installed for itself`;function WB(e){const t=String((e==null?void 0:e.install)??"").replace(/\s+/g," ").trim();return t.length>240?`${t.slice(0,239)}…`:t}function GX(e,t){const n=VB(e,t),r=WB(e);switch(e==null?void 0:e.stage){case"npx":return r?`ccusage failed on both of its paths. The managed install failed first — ${r} — and the deck then fell back to npx, where ${su(n)}`:`there is no managed copy of ccusage on this machine, and the npx fallback failed: ${su(n)}`;case"managed":return`${HB} failed to run: ${su(n)}`;case"path":return e.bin?`the ccusage this deck found at ${e.bin} failed to run: ${su(n)}`:`the ccusage this deck found on your PATH failed to run: ${su(n)}`;default:return n}}const su=e=>/^[A-Z][a-z]/.test(e)?e[0].toLowerCase()+e.slice(1):e;function VB(e,t){const n=Au(e);if(BB(n)){if(UB.test(n))return qB;if(zB.test(n))return FB}if(DB(n))return PB;const r=Ob(LB,e==null?void 0:e.reason);return r||(e==null?void 0:e.reason)||t}function Al(e,t,n){const r=n==null?null:BM[n];if(r)return r;if(e!=null&&e.detail)return e.detail;if(e!=null&&e.error&&qM(e.state))return e.error;const s=Ob($B,e==null?void 0:e.reason);return s||(e!=null&&e.error?e.error:(e==null?void 0:e.reason)||t)}function GB(e,t,n){if(n<=0||Nf(e))return{kind:"pass"};const r=t>=0&&t<n?t:-1;switch(e.key){case"ArrowRight":return{kind:"select",index:r===-1?0:(r+1)%n};case"ArrowLeft":return{kind:"select",index:r===-1?n-1:(r-1+n)%n};case"Home":return{kind:"select",index:0};case"End":return{kind:"select",index:n-1};default:return{kind:"pass"}}}function zM(e,t){const n=Math.round(e/1e3)-t;return n<=0?{text:"expired",tone:"gone"}:n<60?{text:`expires in ${n}s`,tone:"soon"}:{text:`expires in ${Math.round(n/60)}m`,tone:"ok"}}function KB(e){const t=new Map;for(const n of e){const r=(n.email??"").trim().toLowerCase();r&&t.set(r,(t.get(r)??0)+1)}return e.map(n=>{const r=(n.email??"").trim(),s=n.alias||r||`account ${n.num}`,l=[];return n.alias&&r&&l.push(r),r&&(t.get(r.toLowerCase())??0)>1&&l.push(n.org||`slot ${n.num}`),{num:n.num,label:s,sub:l.length?l.join(" · "):null}})}function YB(e,t){return e.filter(n=>!t.includes(n.num)).map(n=>n.num)}function XB(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function ZB(e){return e.length?{action:"share",accounts:[...e]}:null}function QB(e){return e<=0?"Nothing picked yet.":e===1?"1 account — its sign-in token will be on your clipboard.":`${e} accounts — ${e} sign-in tokens will be on your clipboard.`}function L0(e){return`${e.email}|${e.org??""}`}function JB(e,t,n){return e&&e.map(r=>L0(r)===t?n:r)}function ez(e){switch(e){case"imported":return"imported";case"healed":return"dead token replaced";case"updated":return"updated";case"present":return"already here";default:return"not imported"}}function tz(e){const t=e.length;if(!t)return"Nothing to import.";const n=h=>e.filter(m=>m.state===h).length,r=[],s=n("imported");s&&r.push(`${s} of ${t} imported`);const l=n("healed");l&&r.push(`${l} had a dead token replaced`);const c=n("updated");c&&r.push(`${c} updated`);const u=n("present");u&&r.push(`${u} already here`);const f=n("failed");f&&r.push(`${f} did not arrive`);const p=[...new Set(e.map(h=>{var m;return(m=tf(h.check))==null?void 0:m.short}).filter(h=>!!h))];return`${r.join(", ")}${p.length?`, ${p.join(", ")}`:""}.`}const nz=1500,vh=[{id:"login",label:"Sign in"},{id:"paste",label:"Paste a share"}],qS="aa-panel",BS=e=>`aa-tab-${e}`;async function au(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const P0=ve.forwardRef((e,t)=>o.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:t,children:[o.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),o.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));P0.displayName="SuccessMark";function rz({onClose:e,onChanged:t}){const[n,r]=w.useState("login"),[s,l]=w.useState(null),[c,u]=w.useState(""),[f,p]=w.useState(""),[h,m]=w.useState(!1),[y,v]=w.useState(null),[S,b]=w.useState(null),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useRef(""),R=w.useRef(!1),I=w.useRef(!1),O=w.useRef(null),H=w.useRef(null),q=w.useRef(null),$=w.useRef(null),V=w.useRef([]),ne=w.useRef(!1),ee=w.useCallback(()=>{const z=AB({started:R.current,state:s==null?void 0:s.state});z&&au(z).catch(()=>{}),e()},[e,s==null?void 0:s.state]),M=pn(ee,{focusRef:q}),Z=w.useCallback(async()=>{if(!Ps(I.current))return;I.current=!0,m(!0),v(null),R.current=!0;const z=await au({action:"login"}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"could not start the sign-in"));return}l(z)},[]);w.useEffect(()=>{if(!_B(s==null?void 0:s.state))return;const z=window.setInterval(async()=>{try{const ie=await fetch("/api/claude-accounts/login");ie.ok&&l(await ie.json())}catch{}},nz);return()=>window.clearInterval(z)},[s]);const K=w.useRef(t);K.current=t;const D=w.useState(IB)[0];w.useEffect(()=>{var z;(s==null?void 0:s.state)==="awaiting_code"&&((z=O.current)==null||z.focus()),D.shouldAnnounce(s==null?void 0:s.state)&&K.current()},[s==null?void 0:s.state,D]),w.useEffect(()=>{var z;n==="paste"&&!ne.current&&((z=H.current)==null||z.focus()),ne.current=!1},[n]);const P=w.useCallback(z=>{var le;const ie=GB(z,vh.findIndex(ge=>ge.id===n),vh.length);ie.kind!=="pass"&&(z.preventDefault(),ne.current=!0,r(vh[ie.index].id),(le=V.current[ie.index])==null||le.focus())},[n]),B=w.useCallback(async()=>{var ie;if(!Ps(I.current))return;I.current=!0,m(!0),v(null);const z=await au({action:"login-code",code:c}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"the code was not accepted")),z!=null&&z.state&&l(z),(ie=O.current)==null||ie.select();return}u(""),l(z)},[c,s]),W=w.useCallback(async()=>{if(!Ps(I.current))return;I.current=!0,m(!0),v(null);const z=await au({action:"import",blob:f}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"the import failed"));return}C.current=f,p(""),E(null),b(z.results??[]),t()},[f,t]),F=w.useCallback(async z=>{const ie=L0(z);if(!Ps(I.current)||!C.current)return;I.current=!0,m(!0),k(ie),E(null);const le=await au({action:"import",blob:C.current,force:!0,only:{email:z.email,org:z.org??""}}).catch(()=>null);if(I.current=!1,m(!1),k(null),!(le!=null&&le.ok)){E({key:ie,text:Al(le,"that account could not be updated")});return}const ge=(le.results??[])[0];ge&&b(Ne=>JB(Ne,ie,ge)),t()},[t]),G=(s==null?void 0:s.state)==="done"?s.account:null,re=RB({restored:s==null?void 0:s.restored,activeAccount:s==null?void 0:s.activeAccount}),U=qM(s==null?void 0:s.state)||!!(y&&R.current&&!h),Y=TB({state:s==null?void 0:s.state,serverError:s==null?void 0:s.error,localError:y});return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:ee,role:"presentation",children:o.jsxs("div",{ref:M,className:"modal aa-modal",onClick:z=>z.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{className:"aa-tabs",role:"tablist","aria-label":"How to add the account",onKeyDown:P,children:vh.map((z,ie)=>o.jsx("button",{type:"button",role:"tab",id:BS(z.id),ref:le=>{V.current[ie]=le},"aria-selected":n===z.id,"aria-controls":qS,tabIndex:n===z.id?0:-1,className:`aa-tab${n===z.id?" on":""}`,onClick:()=>{ne.current=!1,r(z.id)},children:z.label},z.id))})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:ee,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsx("section",{className:"modal-body aa-body",id:qS,role:"tabpanel","aria-labelledby":BS(n),children:n==="login"?G?o.jsxs("div",{className:"aa-done",children:[o.jsx(P0,{ref:$}),o.jsx(DS,{anchor:$}),o.jsx("h4",{children:G.added?`Account ${G.num} added`:"Credentials refreshed"}),o.jsxs("p",{className:"aa-note",children:[o.jsx("strong",{children:G.email}),G.added?re?" is in the rotation.":" is in the rotation. The account you were using is still active.":" was already managed, so its stored credentials were replaced."]}),re?o.jsx("p",{className:"aa-note aa-warn",role:"status",children:re}):null,o.jsx("button",{type:"button",className:"btn primary",onClick:ee,children:"Done"})]}):(s==null?void 0:s.state)==="awaiting_code"||(s==null?void 0:s.state)==="registering"?o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"1 · Approve in the browser"}),o.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),o.jsx("a",{className:"aa-link",href:s.url??"#",target:"_blank",rel:"noreferrer noopener",children:s.url})]}),o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"2 · Paste a code, if the page shows one"}),o.jsx("p",{className:"aa-note",children:"It usually finishes on its own — if the page says you are all set, there is nothing to do here."}),o.jsxs("div",{className:"aa-field",children:[o.jsx("input",{ref:O,type:"text",value:c,onChange:z=>u(z.target.value),onKeyDown:z=>{z.key==="Enter"&&c.trim()&&!h&&B()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:s.state==="registering"}),o.jsx("button",{type:"button",className:"btn primary",...Qa(h,!c.trim()||s.state==="registering"),onClick:B,children:s.state==="registering"?"registering…":"Continue"})]}),(y||s.error)&&o.jsx("p",{className:"aa-err",children:y??s.error}),o.jsx("p",{className:"aa-note",children:"The code goes straight to the claude CLI on this machine. It is never stored or sent anywhere else."})]})]}):U?o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:Y.title}),o.jsx("p",{className:"aa-err",children:Y.message}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{R.current=!1,l(null),v(null),Z()},children:"Try again"})]}):h||R.current?o.jsx("div",{className:"aa-step",children:o.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):o.jsxs("div",{className:"aa-step aa-primer",children:[o.jsx("h4",{children:"Sign in to Anthropic"}),o.jsx("p",{className:"aa-note",children:"Opens a browser tab where you approve the sign-in. It normally completes by itself; only if the page hands you a code does it need pasting back here. claude-swap records the account when it completes, and the account you are using now stays active."}),o.jsx("div",{className:"aa-actions",children:o.jsx("button",{type:"button",ref:q,className:"btn primary",onClick:Z,children:"Open the sign-in page"})})]}):S?(()=>{const z=S.filter(le=>le.state==="imported").length,ie=S.some(le=>tf(le.check));return o.jsxs("div",{className:"aa-done",children:[!ie&&o.jsx(P0,{ref:$}),z>0&&!ie&&o.jsx(DS,{anchor:$}),o.jsx("h4",{children:tz(S)}),S.length>0&&o.jsx("ul",{className:"aa-results",children:S.map(le=>{const ge=L0(le),Ne=tf(le.check);return o.jsxs("li",{className:`aa-result ${le.state}`,children:[o.jsx("span",{className:"aa-result-who",children:le.email||(le.num?`slot ${le.num}`:"an account")}),o.jsx("span",{className:"aa-result-what",children:ez(le.state)}),le.state==="present"&&o.jsx("button",{type:"button",className:"aa-result-fix","aria-busy":_===ge,title:`Overwrite the stored login for ${le.email} with the one in this share. Do this when that account has stopped working here; if it works, leave it.`,onClick:()=>F(le),children:_===ge?"updating…":"update anyway"}),Ne&&o.jsx("span",{className:"aa-result-err",children:Ne.long}),(j==null?void 0:j.key)===ge&&o.jsx("span",{className:"aa-result-err",children:j.text})]},ge)})}),o.jsxs("p",{className:"aa-note",children:["Nothing changed on the deck you copied this from. An account already here is left as it is, unless its stored login was dead or you pressed",o.jsx("strong",{children:" update anyway"}),"."]}),o.jsxs("div",{className:"aa-actions",children:[o.jsx("button",{type:"button",className:"btn primary",onClick:ee,children:"Done"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{C.current="",E(null),b(null)},children:"Import another"})]})]})})():o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"Paste an account shared from another deck"}),o.jsxs("div",{className:"aa-field",children:[o.jsx("input",{ref:H,type:"text",value:f,onChange:z=>p(z.target.value),onKeyDown:z=>{z.key==="Enter"&&f.trim()&&!h&&W()},placeholder:"ccdeck2:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),o.jsx("button",{type:"button",className:"btn primary",...Qa(h,!f.trim()),onClick:W,children:h?"importing…":"Import"})]}),y&&o.jsx("p",{className:"aa-err",children:y}),o.jsxs("p",{className:"aa-note",children:["Use ",o.jsx("strong",{children:"share"})," on one account in the other deck, or ",o.jsx("strong",{children:"↗"})," above its list to send several at once. A share carries a live login for every account in it and expires ten minutes after it is made."]})]})})]})}),document.body)}const sz=6;function az(e,t){const n=e.filter(u=>u.ready);if(t.armed&&e.length>0&&n.length===0)return{text:"Auto-switch has nowhere to go",tone:"bad",free:null};const r=n.length===e.length?`${e.length} ready`:n.length===0?e.length===1?"not ready":`none of ${e.length} ready`:`${n.length} of ${e.length} ready`,s=n.length?"ok":"idle",l=t.strained&&!t.armed?oz(n):null,c=[r];return l!=null&&c.push(`${l}% free`),c.push(t.armed?`auto ${t.threshold??"on"}${t.threshold?"%":""}`:"auto off"),{text:c.join(" · "),tone:s,free:l}}function oz(e){const t=e.map(n=>n.headroom).filter(n=>typeof n=="number");return t.length?Math.max(...t):null}function iz(e){const t=[...e].sort((s,l)=>{if(s.ready!==l.ready)return s.ready?-1:1;if(!s.ready)return s.name.localeCompare(l.name);const c=s.headroom,u=l.headroom;return c==null&&u==null?s.name.localeCompare(l.name):c==null?1:u==null?-1:u-c}),n=t.slice(0,sz),r=t.length-n.length;return{title:e.some(s=>s.ready)?"Where you could switch":"Nothing to switch to",shown:n,rest:r>0?`and ${r} more`:null}}function UM({title:e,steps:t,finish:n,aside:r,onClose:s}){const l=w.useRef(null),c=pn(s,{focusRef:l}),[u,f]=w.useState(0),p=u===t.length-1,h=t[u],m=S=>f(Math.max(0,Math.min(t.length-1,S))),y=S=>{S.key!=="ArrowRight"&&S.key!=="ArrowLeft"||(S.preventDefault(),S.stopPropagation(),m(S.key==="ArrowRight"?u+1:u-1))},v=()=>{if(!p){m(u+1);return}n?n.act():s()};return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:s,role:"presentation",children:o.jsxs("div",{ref:c,className:"modal guide",onClick:S=>S.stopPropagation(),onKeyDown:y,role:"dialog","aria-modal":"true","aria-labelledby":"guide-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{id:"guide-title",className:"modal-tool-name",children:e}),o.jsxs("span",{className:"modal-tool-id",children:[u+1," / ",t.length]})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:s,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsx("div",{className:"guide-stage",children:h.art},u),o.jsx("p",{className:"guide-line","aria-live":"polite",children:h.line}),o.jsx("p",{className:"guide-tip",children:h.tip??""}),o.jsxs("div",{className:"guide-foot",children:[o.jsx("div",{className:"guide-dots",children:t.map((S,b)=>o.jsx("button",{type:"button",className:"glyph-btn guide-dot","aria-label":`Step ${b+1} of ${t.length}`,"aria-current":b===u?"step":void 0,onClick:()=>m(b)},b))}),p&&r&&o.jsx("button",{type:"button",className:"ap-lan-word guide-aside",onClick:r.act,children:r.label}),u>0&&o.jsx("button",{type:"button",className:"btn",onClick:()=>m(u-1),children:"Back"}),o.jsx("button",{ref:l,type:"button",className:"btn primary",onClick:v,children:p?(n==null?void 0:n.label)??"Done":"Next"})]})]})]})}),document.body)}const D0={ok:"ga-ok",warn:"ga-warn",accent:"ga-accent",flight:"ga-flight"};function Br({children:e}){return o.jsx("svg",{className:"guide-art",viewBox:"0 0 440 200","aria-hidden":!0,focusable:"false",children:e})}function qr({x:e,y:t=34,w:n=176,h:r=132,label:s}){return o.jsxs(o.Fragment,{children:[s&&o.jsx("text",{x:e+2,y:t-9,className:"ga-cap",children:s}),o.jsx("rect",{x:e,y:t,width:n,height:r,rx:10,className:"ga-screen"})]})}function ys({x:e,y:t,email:n,state:r,tone:s,bars:l}){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{cx:e+3,cy:t-4,r:3,className:D0[s]}),o.jsx("text",{x:e+12,y:t,className:"ga-t ga-mono",children:n}),o.jsx("text",{x:e+12,y:t+16,className:`ga-s ${D0[s]}`,children:r}),l==null?void 0:l.map((c,u)=>o.jsxs("g",{children:[o.jsx("text",{x:e,y:t+40+u*18,className:"ga-s",children:u?"7d":"5h"}),o.jsx("rect",{x:e+22,y:t+35+u*18,width:96,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:e+22,y:t+35+u*18,width:96*c/100,height:4,rx:2,className:"ga-accent"}),o.jsxs("text",{x:e+148,y:t+40+u*18,className:"ga-s ga-accent",textAnchor:"end",children:[c,"%"]})]},u))]})}function HM({x:e,y:t,on:n}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:30,height:18,rx:9,className:n?"ga-switch-on":"ga-switch"}),o.jsx("circle",{cx:n?e+21:e+9,cy:t+9,r:6,className:n?"ga-knob-on":"ga-knob"})]})}function xh({x:e,y:t,name:n,here:r=!0}){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{cx:e+3,cy:t-4,r:3,className:r?"ga-ok":"ga-dim"}),o.jsx("text",{x:e+12,y:t,className:r?"ga-t":"ga-s",children:n})]})}function zS({x:e,y:t,on:n}){return n?o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:12,height:12,rx:3,className:"ga-accent"}),o.jsx("path",{d:`M${e+3} ${t+6.2}l2.3 2.3 4-4.6`,className:"ga-tick"})]}):o.jsx("rect",{x:e+.5,y:t+.5,width:11,height:11,rx:3,className:"ga-box"})}function US({x:e,y:t,d:n}){return o.jsx("path",{d:n,transform:`translate(${e} ${t})`,className:"ga-glyph"})}function Pb({x:e,y:t}){return o.jsx("path",{d:`M${e} ${t}l0 13 3.4-3 2.4 5.2 2-.9-2.4-5.1 4.6-.2z`,className:"ga-pointer"})}function Db(){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{r:9,className:"ga-key-bed"}),o.jsxs("g",{transform:"translate(-6 -6) scale(0.857)",className:"ga-key",children:[o.jsx("circle",{cx:4.6,cy:7,r:2.6}),o.jsx("path",{d:"M7.2 7h5.2M10.6 7v2.2M12.4 7v1.6"})]})]})}function Ml({x:e,y:t,w:n,title:r,sub:s,tone:l}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:n,height:40,rx:8,className:"ga-screen"}),o.jsx("rect",{x:e+6,y:t+10,width:3,height:20,rx:1.5,className:D0[l]}),o.jsx("text",{x:e+16,y:t+17,className:"ga-t ga-strong",children:r}),o.jsx("text",{x:e+16,y:t+31,className:"ga-s",children:s})]})}function Pl({x:e,y:t,label:n,live:r}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:46,height:20,rx:10,className:r?"ga-chip-live":"ga-chip"}),o.jsx("text",{x:e+23,y:t+14,className:"ga-s ga-mono",textAnchor:"middle",children:n})]})}function nf({x:e,y:t}){return o.jsxs(o.Fragment,{children:[o.jsx("text",{x:e,y:t,className:"ga-cap",children:"LOCAL NETWORK"}),o.jsx(HM,{x:e+118,y:t-13,on:!0})]})}function lz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:14,width:206,height:172,rx:10,className:"ga-screen"}),o.jsx("text",{x:28,y:38,className:"ga-t ga-strong",children:"Sessions"}),o.jsx("text",{x:206,y:38,className:"ga-s ga-warn",textAnchor:"end",children:"1 waiting"}),o.jsx("rect",{x:20,y:50,width:194,height:42,rx:6,className:"ga-bed-warn"}),o.jsx("circle",{cx:33,cy:64,r:7,className:"ga-ring-warn ga-ping"}),o.jsx("circle",{cx:33,cy:64,r:3.5,className:"ga-warn"}),o.jsx("text",{x:44,y:68,className:"ga-t",children:"api-server"}),o.jsx("text",{x:44,y:83,className:"ga-s ga-warn",children:"waiting 6m · Bash"}),o.jsx("circle",{cx:33,cy:108,r:3.5,className:"ga-flight"}),o.jsx("text",{x:44,y:112,className:"ga-t",children:"docs-site"}),o.jsx("text",{x:44,y:127,className:"ga-s",children:"running · 12 tools"}),o.jsx("circle",{cx:33,cy:150,r:3.5,className:"ga-ok"}),o.jsx("text",{x:44,y:154,className:"ga-t",children:"billing"}),o.jsx("text",{x:44,y:169,className:"ga-s",children:"done · $0.84"}),o.jsx("path",{d:"M216 71C234 71 230 100 244 100",className:"ga-arc"}),o.jsx("path",{d:"M239 96l5 4-5 4",className:"ga-arrow"}),o.jsx("rect",{x:248,y:44,width:178,height:112,rx:10,className:"ga-screen"}),o.jsx("text",{x:262,y:64,className:"ga-cap",children:"API-SERVER"}),o.jsx("line",{x1:248,y1:74,x2:426,y2:74,className:"ga-line"}),o.jsx("text",{x:262,y:96,className:"ga-s ga-mono",children:"Bash(npm test)"}),o.jsx("text",{x:262,y:116,className:"ga-t ga-mono ga-warn",children:"Allow this command?"}),o.jsx("text",{x:262,y:136,className:"ga-s ga-mono",children:"> 1. Yes 2. No"})]})}function cz(){return o.jsxs(Br,{children:[o.jsx("path",{d:"M136 100C166 100 166 38 196 38",className:"ga-edge ga-flow"}),o.jsx("path",{d:"M136 100H196",className:"ga-edge ga-flow"}),o.jsx("path",{d:"M136 100C166 100 166 162 196 162",className:"ga-edge-done"}),o.jsx("path",{d:"M308 38H326M308 100H326",className:"ga-edge"}),o.jsx(Ml,{x:20,y:80,w:116,title:"main",sub:"Opus 5 · 9 tools",tone:"accent"}),o.jsx(Ml,{x:196,y:18,w:112,title:"explore",sub:"Haiku · 14 tools",tone:"flight"}),o.jsx(Ml,{x:196,y:80,w:112,title:"tests",sub:"Sonnet · 6 tools",tone:"flight"}),o.jsx(Ml,{x:196,y:142,w:112,title:"review",sub:"done · 38s",tone:"ok"}),o.jsx(Pl,{x:326,y:28,label:"Read"}),o.jsx(Pl,{x:380,y:28,label:"Grep",live:!0}),o.jsx(Pl,{x:326,y:90,label:"Bash",live:!0})]})}function HS({x:e,y:t,label:n,pct:r,note:s}){return o.jsxs(o.Fragment,{children:[o.jsx("text",{x:e,y:t,className:"ga-s",children:n}),o.jsxs("text",{x:e+194,y:t,className:"ga-s ga-accent",textAnchor:"end",children:[r,"%"]}),o.jsx("rect",{x:e,y:t+7,width:194,height:5,rx:2.5,className:"ga-track"}),o.jsx("rect",{x:e,y:t+7,width:194*r/100,height:5,rx:2.5,className:"ga-accent"}),o.jsx("text",{x:e,y:t+26,className:"ga-s",children:s})]})}function uz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:30,width:172,height:140,rx:10,className:"ga-screen"}),o.jsx("text",{x:30,y:56,className:"ga-cap",children:"THIS SESSION"}),o.jsx("text",{x:30,y:98,className:"ga-big",children:"$3.66"}),o.jsx("text",{x:30,y:122,className:"ga-s",children:"Opus 5 · 1.2M tokens"}),o.jsx("text",{x:30,y:150,className:"ga-s",children:"$21.40 today"}),o.jsx("rect",{x:200,y:30,width:226,height:140,rx:10,className:"ga-screen"}),o.jsx("text",{x:216,y:56,className:"ga-cap",children:"CLAUDE QUOTA"}),o.jsx(HS,{x:216,y:80,label:"5-hour window",pct:24,note:"resets in 53m"}),o.jsx(HS,{x:216,y:124,label:"7-day window",pct:61,note:"resets in 4d"})]})}function dz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:40,width:172,height:120,rx:10,className:"ga-canvas"}),o.jsx(Ml,{x:30,y:80,w:140,title:"tests",sub:"Sonnet 5 · 6 tools",tone:"flight"}),o.jsx(Pb,{x:156,y:106}),o.jsx("path",{d:"M170 92C186 92 184 60 200 60",className:"ga-arc"}),o.jsx("path",{d:"M195 56l5 4-5 4",className:"ga-arrow"}),o.jsx(qr,{x:200,y:22,w:226,h:160}),o.jsx("text",{x:214,y:46,className:"ga-t ga-strong",children:"tests"}),o.jsx("text",{x:412,y:46,className:"ga-s",textAnchor:"end",children:"Sonnet 5 · 38s"}),o.jsx("line",{x1:200,y1:56,x2:426,y2:56,className:"ga-line"}),o.jsx("text",{x:214,y:76,className:"ga-cap",children:"PROMPT"}),o.jsx("text",{x:214,y:92,className:"ga-t",children:"Run the suite and fix what fails"}),o.jsx("text",{x:214,y:116,className:"ga-cap",children:"TOOLS · 6"}),o.jsx(Pl,{x:214,y:122,label:"Read"}),o.jsx(Pl,{x:266,y:122,label:"Edit"}),o.jsx(Pl,{x:318,y:122,label:"Bash",live:!0}),o.jsx("text",{x:214,y:164,className:"ga-cap",children:"TOKENS"}),o.jsx("text",{x:214,y:178,className:"ga-s ga-mono",children:"41k in · 2.1k out · $0.12"})]})}function hz(){const e=[18,24,28,14,22,26,30,16,24,28,20,26];return o.jsxs(Br,{children:[o.jsx(qr,{x:14,y:20,w:412,h:160}),o.jsx("text",{x:28,y:44,className:"ga-t ga-strong",children:"This machine"}),o.jsx("text",{x:412,y:44,className:"ga-s",textAnchor:"end",children:"12 cores · up 10d"}),o.jsx("line",{x1:14,y1:56,x2:426,y2:56,className:"ga-line"}),o.jsx("text",{x:28,y:76,className:"ga-cap",children:"CORES"}),e.map((t,n)=>o.jsxs("g",{children:[o.jsx("rect",{x:28+n*15,y:82,width:10,height:30,rx:2,className:"ga-track"}),o.jsx("rect",{x:28+n*15,y:112-t,width:10,height:t,rx:2,className:"ga-accent"})]},n)),o.jsx("text",{x:28,y:136,className:"ga-cap",children:"MEMORY"}),o.jsx("rect",{x:28,y:143,width:178,height:5,rx:2.5,className:"ga-track"}),o.jsx("rect",{x:28,y:143,width:105,height:5,rx:2.5,className:"ga-accent"}),o.jsx("text",{x:28,y:165,className:"ga-s",children:"18.9 GB of 32.0 GB"}),o.jsx("text",{x:240,y:76,className:"ga-cap",children:"THERMAL"}),o.jsx("text",{x:240,y:100,className:"ga-big",children:"66 °C"}),o.jsx("text",{x:240,y:118,className:"ga-s ga-ok",children:"running at full speed"}),o.jsx("text",{x:240,y:142,className:"ga-cap",children:"BUSIEST PROCESSES"}),o.jsx("text",{x:240,y:160,className:"ga-s ga-mono",children:"node · claude"}),o.jsx("text",{x:412,y:160,className:"ga-s ga-mono",textAnchor:"end",children:"38%"}),o.jsx("text",{x:240,y:176,className:"ga-s ga-mono",children:"esbuild"}),o.jsx("text",{x:412,y:176,className:"ga-s ga-mono",textAnchor:"end",children:"21%"})]})}function fz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:40,width:188,height:120,rx:10,className:"ga-screen"}),o.jsx("text",{x:28,y:60,className:"ga-cap",children:"~/MY-PROJECT"}),o.jsx("line",{x1:14,y1:70,x2:202,y2:70,className:"ga-line"}),o.jsxs("text",{x:28,y:100,className:"ga-t ga-mono",children:[o.jsx("tspan",{className:"ga-accent",children:"$"})," claude"]}),o.jsx("rect",{x:86,y:90,width:7,height:13,className:"ga-caret ga-blink"}),o.jsx("text",{x:28,y:130,className:"ga-s ga-mono",children:"or: codex"}),o.jsx("path",{d:"M210 100H238",className:"ga-arc"}),o.jsx("path",{d:"M233 95l6 5-6 5",className:"ga-arrow"}),o.jsx("rect",{x:250,y:40,width:176,height:120,rx:10,className:"ga-canvas"}),o.jsx("g",{className:"ga-pop",children:o.jsx(Ml,{x:278,y:80,w:120,title:"my-project",sub:"Opus 5 · live",tone:"accent"})})]})}function pz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,y:16,w:232,h:170}),o.jsx("text",{x:28,y:40,className:"ga-t ga-strong",children:"Claude accounts"}),o.jsx(US,{x:196,y:33,d:"M7 2.2v9.6M2.2 7h9.6"}),o.jsx(US,{x:220,y:33,d:"M3.3 10.7L10.7 3.3M5.2 3.3h5.5v5.5"}),o.jsx("line",{x1:14,y1:52,x2:246,y2:52,className:"ga-line"}),o.jsx(ys,{x:28,y:74,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("rect",{x:190,y:62,width:44,height:18,rx:9,className:"ga-accent"}),o.jsx("text",{x:212,y:74,className:"ga-s ga-on-accent",textAnchor:"middle",children:"active"}),o.jsx("line",{x1:14,y1:140,x2:246,y2:140,className:"ga-line"}),o.jsx(ys,{x:28,y:160,email:"personal@me.dev",state:"signed in",tone:"ok"}),o.jsx("rect",{x:188,y:148,width:46,height:18,rx:9,className:"ga-chip"}),o.jsx("text",{x:211,y:160,className:"ga-s",textAnchor:"middle",children:"switch"}),o.jsx(Pb,{x:221,y:161}),o.jsx("path",{d:"M250 40C270 40 262 78 282 78",className:"ga-arc"}),o.jsx("path",{d:"M277 74l5 4-5 4",className:"ga-arrow"}),o.jsx(qr,{x:282,y:62,w:144,h:64,label:"ANOTHER MACHINE"}),o.jsx("g",{className:"ga-pop",children:o.jsx(ys,{x:296,y:92,email:"work@team.dev",state:"shared here",tone:"ok"})})]})}function mz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(nf,{x:28,y:60}),o.jsx("g",{className:"ga-swap-out",children:o.jsx(ys,{x:28,y:98,email:"work@team.dev",state:"login expired",tone:"warn"})}),o.jsx("g",{className:"ga-swap-in",children:o.jsx(ys,{x:28,y:98,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(nf,{x:264,y:60}),o.jsx(ys,{x:264,y:98,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("path",{d:"M246 120C234 80 206 80 194 120",className:"ga-arc"}),o.jsx("g",{className:"ga-travel ga-travel-low",transform:"translate(220 90)",children:o.jsx(Db,{})})]})}const gz=[{art:o.jsx(lz,{}),line:"Sessions waiting on you top the session list, longest wait first.",tip:"A tone and a system notification when one stops to ask. The speaker in the topbar."},{art:o.jsx(cz,{}),line:"Every agent and subagent is a node. Tool calls light up as they run."},{art:o.jsx(dz,{}),line:"Double-click any node: its prompt, every tool call, tokens and timing."},{art:o.jsx(uz,{}),line:"What each session costs, and how much quota is left."},{art:o.jsx(hz,{}),line:"Cores, memory and heat while the agents run, and what is hogging them."},{art:o.jsx(pz,{}),line:"Several Claude accounts: switch, add one, share one to another machine."},{art:o.jsx(mz,{}),line:"Your machines repair each other's expired logins over the local network.",tip:"Open it from the row at the foot of the Claude accounts panel."},{art:o.jsx(fz,{}),line:"Run claude or codex in any folder. It shows up here on its own."}];function yz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(ys,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"}),o.jsx("rect",{x:40,y:94,width:86,height:20,rx:10,className:"ga-pill-warn"}),o.jsx("text",{x:83,y:108,className:"ga-s ga-warn",textAnchor:"middle",children:"sign in again"}),o.jsx("line",{x1:198,y1:100,x2:242,y2:100,className:"ga-off"}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(ys,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]})]})}function wz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(nf,{x:28,y:60}),o.jsx(xh,{x:28,y:92,name:"Ana's MacBook"}),o.jsx(xh,{x:28,y:114,name:"Dorin's PC"}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(nf,{x:264,y:60}),o.jsx(xh,{x:264,y:92,name:"Your MacBook"}),o.jsx(xh,{x:264,y:114,name:"Dorin's PC"}),o.jsx("line",{x1:196,y1:100,x2:244,y2:100,className:"ga-arc"}),o.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping"}),o.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping ga-ping-2"}),o.jsx("circle",{cx:220,cy:100,r:3,className:"ga-accent"})]})}function vz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:90,y:18,width:260,height:164,rx:10,className:"ga-screen"}),o.jsx("text",{x:106,y:42,className:"ga-t ga-strong",children:"This deck on the network"}),o.jsx("line",{x1:90,y1:54,x2:350,y2:54,className:"ga-line"}),o.jsx("text",{x:106,y:76,className:"ga-cap",children:"SHARE THESE ACCOUNTS"}),o.jsx(zS,{x:106,y:88,on:!0}),o.jsx("text",{x:126,y:98,className:"ga-t ga-mono",children:"work@team.dev"}),o.jsx(zS,{x:106,y:112}),o.jsx("text",{x:126,y:122,className:"ga-s ga-mono",children:"personal@me.dev"}),o.jsx("text",{x:106,y:150,className:"ga-cap",children:"PAIRING"}),o.jsx("text",{x:106,y:168,className:"ga-s",children:"Say yes to every deck that asks"}),o.jsx(HM,{x:304,y:157,on:!0}),o.jsx(Pb,{x:115,y:97})]})}function xz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx("g",{className:"ga-swap-out",children:o.jsx(ys,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"})}),o.jsx("g",{className:"ga-swap-in",children:o.jsx(ys,{x:28,y:64,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(ys,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("path",{d:"M246 96C234 56 206 56 194 96",className:"ga-arc"}),o.jsx("g",{className:"ga-travel",transform:"translate(220 66)",children:o.jsx(Db,{})})]})}const bz=[{art:o.jsx(yz,{}),line:"A login can expire on one machine while it still works on another."},{art:o.jsx(wz,{}),line:"Both decks are on. They find each other and ask to pair.",tip:"Not showing up? The + in the section reaches a machine by address or invite."},{art:o.jsx(vz,{}),line:"Tick which logins this machine may hand out. Nothing is shared until you do."},{art:o.jsx(xz,{}),line:"An expired login is copied from a paired machine within a minute."}];function kz(){return o.jsxs("svg",{className:"guide-art",viewBox:"0 0 232 60","aria-hidden":!0,focusable:"false",children:[o.jsx("rect",{x:1,y:14,width:78,height:42,rx:7,className:"ga-screen"}),o.jsx("circle",{cx:13,cy:29,r:3,className:"ga-warn"}),o.jsx("rect",{x:21,y:27,width:46,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:13,y:39,width:40,height:3,rx:1.5,className:"ga-track"}),o.jsx("rect",{x:153,y:14,width:78,height:42,rx:7,className:"ga-screen"}),o.jsx("circle",{cx:165,cy:29,r:3,className:"ga-ok"}),o.jsx("rect",{x:173,y:27,width:46,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:165,y:39,width:40,height:3,rx:1.5,className:"ga-accent"}),o.jsx("path",{d:"M150 36C138 6 94 6 82 36",className:"ga-arc"}),o.jsx("g",{transform:"translate(116 13)",children:o.jsx(Db,{})})]})}const Nz={panel:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it behind the + above, where an address can be typed too.",dialog:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it below, or type their address."},Sz=1600;function WM({reach:e,where:t}){const[n,r]=w.useState(!1),s=w.useRef(!0);w.useEffect(()=>()=>{s.current=!1},[]);const l=(e==null?void 0:e.steps)??[],c=w.useCallback(async()=>{await hi(l.join(`
|
|
90
|
+
${n}`:`Sort by ${t}`,onClick:()=>s(U8(r,e)),children:[t,o.jsx("span",{className:"sd-sort-dir","aria-hidden":!0,children:l==="none"?"":l==="ascending"?"↑":"↓"})]})})}const Z8=3e3;function Q8(e,t,n){return e>=n?"hot":e>=t?"warn":"calm"}function J8(e,t,n=Date.now()){const r=Math.max(0,Math.min(100,100-e));return{pct:r,value:`${r}%`,tone:r===0?"calm":r>=30?"hot":"warn",note:r>0?`CPU held to ${e}% of full speed to cool down`:t?`at full speed · held to ${100-t.peak}% ${eB(t.lastMs,n)}`:"running at full speed, and never held back"}}function eB(e,t=Date.now()){const n=Math.max(0,Math.floor((t-e)/6e4));if(n<2)return"just now";if(n<60)return`${n} minutes ago`;const r=Math.floor(n/60);return r===1?"an hour ago":`${r} hours ago`}function ru(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${Math.round(e/1024**2)} MB`:`${Math.round(e/1024)} KB`}function tB(e){const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h`:n>0?`${n}h ${r}m`:`${r}m`}function nB(e){var n,r,s;const t=(r=(n=e.thermal)==null?void 0:n.throttle)==null?void 0:r.speedLimit;return t!=null&&t<100?`throttled to ${t}% of full speed`:e.memory&&e.memory.usedPct>=90?`physical memory ${Math.round(e.memory.usedPct)}% full`:(s=e.network)!=null&&s.api&&e.network.api.ms==null?"the Claude API is not answering":null}function rB(){const[e,t]=w.useState(null),n=w.useRef(null);return w.useEffect(()=>{let r=!0;const s=async()=>{if(document.visibilityState!=="hidden")try{const f=await fetch("/api/system");if(!f.ok)return;const p=await f.json();r&&(p!=null&&p.ok)&&t(p)}catch{}},l=()=>{n.current==null&&(s(),n.current=window.setInterval(s,Z8))},c=()=>{n.current!=null&&(window.clearInterval(n.current),n.current=null)},u=()=>{if(document.visibilityState==="hidden"){c();return}l(),s()};return l(),document.addEventListener("visibilitychange",u),()=>{r=!1,c(),document.removeEventListener("visibilitychange",u)}},[]),e}function AS({usageOpen:e,leaving:t,sub:n,flag:r,onClose:s,children:l}){return o.jsxs("aside",{className:`sysdetail${e?" shifted":""}${t?" leaving":""}`,id:"system-panel","aria-labelledby":"sd-title",children:[o.jsxs("div",{className:"sd-top",children:[o.jsxs("div",{className:"sd-head",children:[o.jsx("h2",{className:"sd-title",id:"sd-title",children:"This machine"}),n&&o.jsx("span",{className:"sd-sub",children:n}),o.jsx("button",{type:"button",className:"glyph-btn sd-close",onClick:s,"aria-label":"Close",title:"Close",children:"×"})]}),r&&o.jsx("p",{className:"sd-flag",children:r})]}),l]})}function sB({usageOpen:e,leaving:t,onClose:n}){const r=rB();if(!r||r.cpu==null||!r.memory)return o.jsx(AS,{usageOpen:e,leaving:t,onClose:n,children:o.jsx("div",{className:"sd-note",children:"reading this machine…"})});const{memory:s,swap:l,perCore:c,loadavg:u,cores:f,uptimeSec:p,platform:h,thermal:m,network:y,cpu:v}=r;return o.jsxs(AS,{usageOpen:e,leaving:t,sub:`up ${tB(p)} · ${f} cores`,flag:nB(r),onClose:n,children:[o.jsx(aB,{cpu:v,perCore:c,loadavg:u,cores:f}),o.jsx(oB,{memory:s,swap:l,platform:h}),y&&o.jsx(iB,{network:y}),o.jsx(uB,{thermal:m}),o.jsx(dB,{sys:r})]})}function aB({cpu:e,perCore:t,loadavg:n,cores:r}){const s=!!t&&t.length>0;return!s&&!n?null:o.jsxs("div",{className:"sd-section sd-cpu",role:"group","aria-label":"CPU",children:[s&&o.jsx(Ru,{group:"cores",title:"Core history",action:"Show core history",label:"CPU",value:e==null?null:`${Math.round(e)}%`,children:o.jsx("div",{className:"sd-cores",role:"img","aria-label":`${t.length} logical cores, busiest at ${Math.round(Math.max(...t))}%`,children:t.map((l,c)=>o.jsx("span",{className:"sd-core",title:`logical core ${c+1} · ${l}% busy`,children:o.jsx("span",{className:"sd-core-fill",style:{transform:`scaleY(${Math.max(2,l)/100})`}})},c))})}),n&&o.jsxs(Ru,{group:"load",title:"Load history",action:"Show load history",label:"Load average",hint:"the queue for the cores, counted in tasks rather than as a share of them",children:[o.jsx("div",{className:"sd-figs",title:"The queue for this machine's cores, averaged over one, five and fifteen minutes. A count of tasks, not a share of the CPU.",children:n.map((l,c)=>o.jsx(I0,{value:l.toFixed(2),cap:["1m","5m","15m"][c]},c))}),n[0]>r&&o.jsx("div",{className:"sd-note",children:`${(n[0]/r).toFixed(1)}× more work queued than cores to run it`})]})]})}function oB({memory:e,swap:t,platform:n}){const r=e.total-e.available,s=n==="win32"?"Commit":"Swap",l=t&&t.total>0?t.used/t.total*100:0;return o.jsx("div",{className:"sd-section",role:"group","aria-label":"Memory",children:o.jsxs(Ru,{group:"memory",title:"Memory history",action:"Show memory history",label:"Memory",children:[o.jsx(ef,{label:"Physical",value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:ru(r)})," of ",ru(e.total)]}),pct:e.usedPct,tone:e.usedPct>=90?"warn":"calm",note:`${ru(e.available)} available`}),t&&t.total>0&&o.jsx(ef,{label:s,value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:ru(t.used)})," of ",ru(t.total)]}),pct:l,tone:l>=90?"warn":"calm"})]})})}function iB({network:e}){const{down:t,up:n,api:r,route:s}=e,[l,c]=w.useState(!1),u=r&&r.ms!=null?Rf(r.ms):null,f=t!=null&&n!=null;return o.jsxs("div",{className:"sd-section",role:"group","aria-label":"Network",children:[o.jsxs(Ru,{group:"network",title:"Network history",action:"Show network history",label:"Network",children:[(f||u)&&o.jsxs("div",{className:"sd-figs sd-figs-named",children:[f&&[["Download",t],["Upload",n]].map(([p,h])=>{const m=Mb(h);return o.jsx(I0,{value:m.value,unit:m.unit,cap:p},p)}),u&&o.jsx(I0,{value:u.value,unit:u.unit,cap:"Claude API"})]}),!f&&o.jsx("div",{className:"sd-note",children:"measuring…"}),r&&r.ms==null&&o.jsx("div",{className:"sd-note sd-note-warn",children:"Can’t reach Claude"})]}),s&&o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",className:"sd-detail",id:"sd-conn","aria-expanded":l,"aria-haspopup":"dialog",onClick:()=>c(p=>!p),children:["Connection details",s.relay&&o.jsx("span",{className:"sd-route-relay",children:" · relayed"}),o.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),l&&o.jsx(cB,{route:s,api:r,onClose:()=>c(!1)})]})]})}function I0({value:e,unit:t,cap:n}){return t?o.jsxs("span",{className:"sd-fig",children:[o.jsx("span",{className:"sd-fig-cap",children:n}),o.jsxs("span",{className:"sd-fig-read",children:[o.jsx("b",{children:e})," ",o.jsx("span",{className:"sd-fig-unit",children:t})]})]}):o.jsxs("span",{className:"sd-fig",children:[o.jsx("b",{children:e}),o.jsx("span",{className:"sd-fig-cap",children:n})]})}function lB(e){return e.kind==="tailscale-exit"?e.node?`Tailscale exit node ${e.node}`:"a Tailscale exit node":e.kind==="tailscale"?"Tailscale":`${e.name?`${e.name} `:""}VPN${e.iface?` (${e.iface})`:""}`}function cB({route:e,api:t,onClose:n}){return o.jsxs(M0,{anchorId:"sd-conn",boundaryId:"system-panel",id:"sd-conn-pop",className:"sd-pop",role:"dialog",labelledBy:"sd-conn-title",onClose:n,children:[o.jsx("p",{className:"sd-pop-title",id:"sd-conn-title",children:"Connection"}),o.jsxs("dl",{className:"sd-pop-rows",children:[o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:e.to==="claude"?"Traffic to Claude":"Internet traffic"}),o.jsxs("dd",{children:["through ",lB(e)]})]}),e.relay&&o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Relay"}),o.jsxs("dd",{children:[o.jsx("span",{className:"sd-route-relay",children:e.relay})," — not a direct path, so every packet carries one more round trip than it has to"]})]}),t&&o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Round trip"}),o.jsx("dd",{children:t.ms==null?`${t.host} did not answer`:`${Tu(Rf(t.ms))} to open a connection to ${t.host}`})]}),o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Throughput"}),o.jsx("dd",{children:"every interface on this machine, not this path alone"})]})]})]})}function Ru({group:e,title:t,action:n,label:r,value:s,hint:l,children:c}){const[u,f]=w.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",className:"sd-open",onClick:()=>f(!0),title:n,"aria-label":s==null?n:`${n}, now ${s}`,"aria-describedby":l?`sd-hint-${e}`:void 0,children:[o.jsxs("div",{className:"sd-h","aria-hidden":!0,children:[r," ",o.jsx("i",{className:"sd-row-more",children:"›"}),s!=null&&o.jsx("span",{className:"sd-h-val",children:s})]}),c]}),l&&o.jsx("span",{id:`sd-hint-${e}`,className:"vis-hidden",children:l}),u&&o.jsx(T8,{group:e,title:t,onClose:()=>f(!1)})]})}function uB({thermal:e}){if(!e)return null;const t=e.throttle?J8(e.throttle.speedLimit,e.heldBack):null;return o.jsx("div",{className:"sd-section",role:"group","aria-label":"Thermal",children:o.jsxs(Ru,{group:"thermal",title:"Thermal history",action:"Show thermal history",label:"Thermal",children:[e.celsius.map(n=>o.jsx(ef,{label:n.label,value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:n.celsius})," °C"]}),pct:n.celsius/n.critAt*100,mark:n.warnAt/n.critAt*100,tone:Q8(n.celsius,n.warnAt,n.critAt),title:`bar runs 0–${n.critAt} °C · amber from ${n.warnAt} °C, red at ${n.critAt} °C`,trackLabel:`${n.celsius} °C on a bar that runs to ${n.critAt} °C, amber from ${n.warnAt} °C`},n.label)),t&&o.jsx(ef,{label:"Throttling",value:o.jsx("b",{children:t.value}),pct:t.pct,tone:t.tone,note:t.note})]})})}function dB({sys:e}){const[t,n]=w.useState(!1);return o.jsxs("div",{className:"sd-section sd-door-section",children:[o.jsx("button",{type:"button",className:"sd-open sd-door",onClick:()=>n(!0),"aria-label":"Show every process the deck is watching",children:o.jsxs("span",{className:"sd-door-plate",children:[o.jsxs("span",{className:"sd-door-name",children:["Busiest processes",o.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),o.jsx("span",{className:"sd-door-sub",children:"every process, with its command line"})]})}),t&&o.jsx(X8,{sys:e,onClose:()=>n(!1)})]})}function ef({label:e,value:t,pct:n,tone:r="calm",note:s,mark:l,title:c,trackLabel:u}){return o.jsxs("div",{className:"sd-row",title:c,children:[o.jsxs("div",{className:"sd-row-head",children:[o.jsx("span",{className:"sd-row-label",children:e}),o.jsx("span",{className:"sd-row-val",children:t})]}),o.jsxs("span",{className:"sd-track",role:u?"img":void 0,"aria-label":u,children:[o.jsx("span",{className:`sd-fill${r==="calm"?"":` ${r}`}`,style:{transform:`scaleX(${n<=0?0:Math.max(1,Math.min(100,n))/100})`}}),l!=null&&l>0&&l<100&&o.jsx("span",{className:"sd-mark",style:{left:`${l}%`},"aria-hidden":!0})]}),s&&o.jsx("div",{className:"sd-note",children:s})]})}function MS(e){return{inputTokens:e.i,outputTokens:e.o,cacheReadTokens:e.cr,cacheCreateTokens:e.cc,cacheCreate1hTokens:e.c1h,cacheCreate5mTokens:e.c5m}}function IS(e){let t=0;for(const n of Object.values(e))t+=n.i+n.o+n.cr+n.cc;return t}function hB(e,t,n,r=Date.now()){const s=n.size>0,l=new Map;for(const[E,C]of n){const R=E.indexOf("|"),I=E.slice(0,R),O=E.slice(R+1),H=ri(C.usage,O,r).total,q=H>0?C.cost/H:1;let $=l.get(I);$||($=new Map,l.set(I,$)),$.set(O,q)}const c=(E,C)=>{const R=l.get(E);return(R==null?void 0:R.get(C))??(R==null?void 0:R.get(Ql(C)))??1},u=(E,C)=>{let R=0;for(const[I,O]of Object.entries(E))R+=ri(MS(O),I,r).total*c(C,I);return R},f=new Map,p=[];for(const E of e){const C=new Map;let R=0;for(const I of E.projects){const O=u(I.models,E.day);C.set(I.path,(C.get(I.path)??0)+O),R+=O;let H=f.get(I.path);H||(H={path:I.path,cost:0,tokens:0},f.set(I.path,H)),H.cost+=O,H.tokens+=IS(I.models)}p.push({day:E.day,total:R,byPath:C})}const h=[...f.values()].sort((E,C)=>C.cost-E.cost||C.tokens-E.tokens),m=h.reduce((E,C)=>E+C.cost,0),y=h.reduce((E,C)=>E+C.tokens,0);let v=0,S=0;for(const E of n.values())v+=E.cost;for(const[E,C]of n)S+=ri(C.usage,E.slice(E.indexOf("|")+1),r).total;const b=S>0?v/S:1,_=t?IS(t):0;let k=0;if(t)for(const[E,C]of Object.entries(t))k+=ri(MS(C),E,r).total*b;const j=k>0||_>0?{cost:k,tokens:_}:null;return{projects:h,totalCost:m,totalTokens:y,perDay:p,unattributed:j,reconciled:s}}function DM(e){return/^[A-Za-z]:[\\/]$/.test(e)?e:e.replace(/[\\/]+$/,"")}function jm(e){const t=DM(e).replace(/\\/g,"/");return/^[A-Za-z]:\//.test(t)?t.toLowerCase():t}function $S(e){if(!e)return e;const t=DM(e),n=t.match(/^\/(?:Users|home)\/[^/]+(\/.*)?$/);if(n)return`~${n[1]??""}`;const r=t.replace(/\\/g,"/").match(/^[A-Za-z]:\/Users\/[^/]+(\/.*)?$/i);return r?`~${r[1]??""}`:t.replace(/\\/g,"/")}function fB(e,t){const n=jm(e);let r;for(const s of t){const l=jm(s.path);!l||l===n||!n.startsWith(`${l}/`)||(!r||jm(r.path).length<l.length)&&(r=s)}return r==null?void 0:r.label}function $0(e){return e===0?"all time":e===1?"today":`the last ${e} days`}function pB(e){return e===1?"No work attributed to this account yet today.":`No work attributed to this account in ${$0(e)}.`}function mB(e){return e===1?7:e===7?30:e===30?0:null}function gB(e,t){return e!==1&&t>0}const yB=[{days:1,label:"Today"},{days:7,label:"7d"},{days:30,label:"30d"},{days:0,label:"All"}],bl=["var(--usage-blue)","var(--usage-green)","var(--usage-amber)","var(--usage-purple)","var(--usage-indigo)","var(--usage-red)","var(--usage-orange)","var(--usage-zinc)"],wB="var(--usage-zinc)",_m=6,vB=1600;function OS(e){return`${e.getFullYear()}${String(e.getMonth()+1).padStart(2,"0")}${String(e.getDate()).padStart(2,"0")}`}function xB(e){const t=ut(e),n=/^\$(\d{4,})$/.exec(t);return n?`$${Number(n[1]).toLocaleString("en-US")}`:t}function LS(e,t){if(t<=0||e<=0)return"0%";const n=e/t*100;return n<.01?"<0.01%":n<1?`${n.toFixed(2)}%`:n<10?`${n.toFixed(1)}%`:`${Math.round(n)}%`}function bB(e){const t=/^\d{4}-(\d{2})-(\d{2})$/.exec(e);return t?`${Number(t[1])}/${Number(t[2])}`:e}function kB(e){const t=Math.max(1,Math.ceil(e/6));return n=>n===0||n===e-1||n%t===0}function Em(e){if(!e)return"";try{return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return""}}function NB({num:e,name:t,onClose:n}){const[r,s]=w.useState(1),[l,c]=w.useState(null),[u,f]=w.useState(r),[p,h]=w.useState(null),[m,y]=w.useState(null),[v,S]=w.useState(()=>new Set),[b,_]=w.useState(!0),[k,j]=w.useState(null),[E,C]=w.useState(null),R=w.useRef(void 0),I=w.useRef(!0);w.useEffect(()=>()=>{I.current=!1,window.clearTimeout(R.current)},[]);const O=w.useRef(null),H=pn(n,{focusRef:O}),q=w.useRef(0);w.useEffect(()=>{const D=++q.current;_(!0),j(null),y(null),S(new Set);const P=r===0?60:r,B=OS(new Date(Date.now()-(P-1)*864e5)),W=OS(new Date),F=fetch(`/api/account-projects?num=${e}&days=${r}`,{credentials:"same-origin"}).then(re=>re.ok?re.json():Promise.reject(new Error(`HTTP ${re.status}`))),G=fetch(`/api/ccusage?since=${B}&until=${W}`,{credentials:"same-origin"}).then(re=>re.ok?re.json():null).catch(()=>null);Promise.all([F,G]).then(([re,U])=>{if(D!==q.current)return;c(re),f(r);const Y=U;h(Y&&Y.ok!==!1?Y:null),_(!1)}).catch(re=>{D===q.current&&(j(re.message||"Could not load"),c(null),_(!1))})},[e,r]);const $=w.useMemo(()=>{const D=Date.now();if(!l)return null;const P=ue=>typeof ue=="number"&&Number.isFinite(ue)?ue:0,B=new Map;if(p){const ue=Array.isArray(p.days)?p.days:[];for(const se of ue){const be=typeof se.period=="string"?se.period:"",Le=Array.isArray(se.modelBreakdowns)?se.modelBreakdowns:[];for(const ce of Le){const pe=typeof ce.modelName=="string"?ce.modelName:"";if(!be||!/claude/i.test(pe))continue;const Ae=`${be}|${pe}`,fe=B.get(Ae),Se=fe?fe.usage:{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreateTokens:0,cacheCreate1hTokens:0,cacheCreate5mTokens:0};Se.inputTokens+=P(ce.inputTokens),Se.outputTokens+=P(ce.outputTokens),Se.cacheReadTokens+=P(ce.cacheReadTokens),Se.cacheCreateTokens+=P(ce.cacheCreationTokens),fe?fe.cost+=P(ce.cost):B.set(Ae,{cost:P(ce.cost),usage:Se})}}}const W=hB(l.daily??[],l.unattributed,B,D),F=ue=>ue.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||ue||"(unknown)",G=new Map;for(const ue of W.projects)G.set(F(ue.path),(G.get(F(ue.path))??0)+1);const re=ue=>{const se=F(ue);if((G.get(se)??0)<=1)return se;const be=ue.replace(/[\\/]+$/,"").split(/[\\/]/).slice(-2,-1)[0];return be?`${be}/${se}`:se},U=W.projects.map(ue=>({path:ue.path,label:re(ue.path)})),Y=ue=>({path:ue.path,label:re(ue.path),parentLabel:fB(ue.path,U),cost:ue.cost,tokens:ue.tokens}),z=bl[_m%bl.length],ie=new Map,le=[],ge=W.projects.slice(0,_m),Ne=W.projects.slice(_m);ge.forEach((ue,se)=>{ie.set(ue.path,bl[se%bl.length]),le.push({key:ue.path,...Y(ue),color:bl[se%bl.length]})}),Ne.length&&le.push({key:"__other__",label:`Other · ${Ne.length} project${Ne.length>1?"s":""}`,cost:Ne.reduce((ue,se)=>ue+se.cost,0),tokens:Ne.reduce((ue,se)=>ue+se.tokens,0),color:z,muted:!0,members:Ne.map(Y)});const Ie=W.totalCost,Ge=W.totalTokens,Pe=Ie>0?"cost":"tokens",Be=Pe==="cost"?Ie:Ge,Te=le.map(ue=>ue.color),st=W.perDay.map(ue=>{const se=new Map;for(const[be,Le]of ue.byPath){const ce=ie.get(be)??z;se.set(ce,(se.get(ce)??0)+Le)}return{day:ue.day,total:ue.total,costByColor:se}}),de=st.reduce((ue,se)=>Math.max(ue,se.total),0);return{rows:le,totalCost:Ie,totalTokens:Ge,basis:Pe,denom:Be,un:W.unattributed,reconciled:W.reconciled,chart:st,maxDay:de,colorOrder:Te}},[l,p]),V=(D,P)=>{hi(D).then(B=>{I.current&&(window.clearTimeout(R.current),C({path:D,label:P,ok:B}),R.current=window.setTimeout(()=>{I.current&&C(null)},vB))})},ne=D=>E!=null&&E.ok&&E.path===D?"Copied":"Copy",ee=l!=null&&l.trackedSince?`Tracked since ${Em(l.trackedSince)}`:"Tracking starts with this version",M=$0(u),Z=mB(u),K=b&&!!l;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:H,className:"modal ap-proj-modal",onClick:D=>D.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ap-proj-title ap-proj-sub",children:[o.jsxs("header",{className:"ap-proj-head",children:[o.jsxs("div",{className:"ap-proj-titlewrap",children:[o.jsx("div",{className:"ap-proj-title",id:"ap-proj-title",children:"Projects"}),o.jsx("div",{className:"ap-proj-sub",id:"ap-proj-sub",title:t,children:t})]}),o.jsx("div",{className:"uh-range",role:"group","aria-label":"Range",children:yB.map(D=>o.jsx("button",{type:"button",className:"uh-range-btn","aria-pressed":r===D.days,onClick:()=>s(D.days),children:D.label},D.days))}),o.jsx("button",{ref:O,className:"glyph-btn ap-proj-close",onClick:n,"aria-label":"Close",children:"×"})]}),o.jsxs("div",{className:`ap-proj-body${K?" refreshing":""}`,"aria-busy":b,children:[b&&!l&&o.jsx("div",{className:"ap-proj-state",children:"Loading…"}),!b&&k&&o.jsxs("div",{className:"ap-proj-state ap-proj-error",children:["Couldn’t load this report: ",k]}),!k&&$&&o.jsx(o.Fragment,{children:$.rows.length===0?o.jsxs("div",{className:"ap-proj-state",children:[pB(u),Z!=null&&o.jsx("div",{className:"ap-proj-widen-wrap",children:o.jsxs("button",{type:"button",className:"ap-proj-copy",onClick:()=>s(Z),children:["Show ",$0(Z)]})}),o.jsxs("div",{className:"ap-proj-note",children:[ee,". Only work from this version onward can be tied to an account."]})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"ap-proj-bar",role:"img","aria-label":`Share of ${ut($.totalCost)} across ${$.rows.length} projects`,children:$.rows.map(D=>{const P=$.basis==="cost"?D.cost:D.tokens,B=$.denom>0?P/$.denom*100:0;return B<=0?null:o.jsx("span",{className:"ap-proj-seg",style:{width:`${B}%`,background:D.color},title:`${D.label} · ${ut(D.cost)} · ${LS(D.cost,$.totalCost)}${D.tokens?` · ${Bt(D.tokens)} tokens`:""}`},D.key)})}),o.jsxs("div",{className:"ap-proj-totals",children:[o.jsx("span",{className:"ap-proj-total-cost",children:ut($.totalCost)}),o.jsxs("span",{className:"ap-proj-total-tok",children:[Bt($.totalTokens)," tokens"]}),o.jsxs("span",{className:"ap-proj-total-win",children:["· ",M]})]}),gB(u,$.chart.length)&&o.jsxs("div",{className:"ap-proj-days",children:[o.jsxs("div",{className:"ap-proj-days-cap",children:["By day",$.chart.length>1?" · click a bar":""]}),o.jsx("div",{className:"ap-proj-days-plot",role:"img","aria-label":`Spend across ${$.chart.length} day${$.chart.length>1?"s":""}`,children:$.chart.map(D=>{const P=$.maxDay>0?D.total/$.maxDay*100:0,B=m===D.day,W=$.rows.map(G=>({label:G.label,c:D.costByColor.get(G.color)??0})).filter(G=>G.c>0),F=`${Em(Date.parse(`${D.day}T00:00:00`))}, ${ut(D.total)}. ${W.map(G=>`${G.label} ${ut(G.c)}`).join(", ")}`;return o.jsx("button",{type:"button",className:`ap-proj-day${B?" selected":""}`,"aria-pressed":B,"aria-label":F,title:`${D.day} · ${ut(D.total)}`,onClick:()=>y(G=>G===D.day?null:D.day),children:o.jsx("span",{className:"ap-proj-col",style:{height:`${P}%`},children:$.colorOrder.map((G,re)=>{const U=D.costByColor.get(G)??0;return U<=0||D.total<=0?null:o.jsx("span",{className:"ap-proj-colseg",style:{height:`${U/D.total*100}%`,background:G}},re)})})},D.day)})}),(()=>{const D=kB($.chart.length);return o.jsx("div",{className:"ap-proj-days-axis","aria-hidden":"true",children:$.chart.map((P,B)=>o.jsx("div",{className:"ap-proj-axis-cell",children:D(B)?bB(P.day):""},P.day))})})(),(()=>{const D=m?$.chart.find(B=>B.day===m):null;if(!D)return null;const P=$.rows.map(B=>({r:B,c:D.costByColor.get(B.color)??0})).filter(B=>B.c>0);return o.jsxs("div",{className:"ap-proj-day-detail",children:[o.jsxs("div",{className:"ap-proj-day-detail-head",children:[o.jsx("span",{children:Em(Date.parse(`${D.day}T00:00:00`))}),o.jsx("span",{className:"ap-proj-day-detail-total",children:ut(D.total)})]}),P.map(({r:B,c:W})=>o.jsxs("div",{className:"ap-proj-day-detail-row",children:[o.jsx("span",{className:"ap-proj-dot",style:{background:B.color},"aria-hidden":"true"}),o.jsx("span",{className:"ap-proj-day-detail-name",children:B.label}),o.jsx("span",{className:"ap-proj-day-detail-cost",children:ut(W)})]},B.key))]})})()]}),o.jsx("ul",{className:"ap-proj-list",children:$.rows.map((D,P)=>{const B=$.basis==="cost"?D.cost:D.tokens,W=$.denom>0?B/$.denom*100:0,F=v.has(D.key),G=`ap-proj-details-${P}`,re=F&&(!!D.path||!!D.members),U=D.members?`${F?"Hide":"Show"} the ${D.members.length} project${D.members.length>1?"s":""} folded into Other`:`${F?"Hide":"Show"} location for ${D.label}`;return o.jsxs("li",{className:`ap-proj-row${D.muted?" muted":""}${F?" expanded":""}`,children:[o.jsx("span",{className:"ap-proj-dot",style:{background:D.color},"aria-hidden":"true"}),o.jsxs("span",{className:"ap-proj-name",children:[D.label,D.parentLabel&&o.jsxs("span",{className:"ap-proj-parent",children:[" · in ",D.parentLabel]})]}),o.jsx("span",{className:"ap-proj-track",title:`${LS(D.cost,$.totalCost)} of tracked cost`,children:o.jsx("span",{className:"ap-proj-fill",style:{width:`${W}%`,background:D.color}})}),o.jsx("span",{className:"ap-proj-cost",children:ut(D.cost)}),o.jsx("span",{className:"ap-proj-tok",children:Bt(D.tokens)}),o.jsx("button",{type:"button",className:"glyph-btn ap-proj-info","aria-expanded":F,"aria-controls":re?G:void 0,"aria-label":U,onClick:()=>S(Y=>{const z=new Set(Y);return z.has(D.key)?z.delete(D.key):z.add(D.key),z}),children:"ⓘ"}),F&&D.path&&o.jsxs("div",{className:"ap-proj-details",id:G,children:[o.jsx("code",{className:"ap-proj-path",children:$S(D.path)}),o.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${ne(D.path)} location for ${D.label}`,onClick:()=>V(D.path,D.label),children:ne(D.path)})]}),F&&D.members&&o.jsx("div",{className:"ap-proj-details ap-proj-other-members",id:G,children:D.members.map(Y=>o.jsxs("div",{className:"ap-proj-other-member",children:[o.jsxs("div",{className:"ap-proj-other-name",children:[Y.label,Y.parentLabel&&o.jsxs("span",{className:"ap-proj-parent",children:[" · in ",Y.parentLabel]})]}),o.jsx("code",{className:"ap-proj-path",children:$S(Y.path)}),o.jsx("span",{className:"ap-proj-cost",children:ut(Y.cost)}),o.jsx("span",{className:"ap-proj-tok",children:Bt(Y.tokens)}),o.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${ne(Y.path)} location for ${Y.label}`,onClick:()=>V(Y.path,Y.label),children:ne(Y.path)})]},Y.path))})]},D.key)})}),$.un&&o.jsxs("div",{className:"ap-proj-unattributed",children:[o.jsx("span",{className:"ap-proj-dot",style:{background:wB},"aria-hidden":"true"}),o.jsxs("div",{className:"ap-proj-un-labels",children:[o.jsx("span",{className:"ap-proj-un-title",children:"Unattributed usage"}),o.jsx("span",{className:"ap-proj-un-tag",children:"Excluded from the project totals"})]}),o.jsx("span",{className:"ap-proj-un-cost",children:xB($.un.cost)}),o.jsx("span",{className:"ap-proj-un-tok",children:Bt($.un.tokens)}),o.jsx("div",{className:"ap-proj-note",children:"Work no account could be tied to — from before tracking, or a gap."})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:E&&(E.ok?`Copied the location of ${E.label}`:`Could not copy the location of ${E.label} — select it and copy it by hand`)}),o.jsxs("div",{className:"ap-proj-foot",children:[$.reconciled?"Dollars from ccusage · split by activity":"Dollars estimated · ccusage unavailable"," · ",ee]})]})})]})]})}),document.body)}const PS=18,SB=1100,kl=(e,t)=>{const n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)},jB=Array.from({length:PS},(e,t)=>{const n=-72+144*t/(PS-1)+(kl(t,1)-.5)*9,r=(n-90)*(Math.PI/180),s=(54+32*Math.cos(n*Math.PI/180))*(.74+kl(t,2)*.52);return{dx:Math.cos(r)*s,dy:Math.sin(r)*s,rot:(t%2?1:-1)*(100+kl(t,3)*260),delay:Math.round(kl(t,4)*90),dur:760+Math.round(kl(t,5)*260),scale:.8+kl(t,6)*.45,hue:t%4,round:t%3===0}});function DS({anchor:e}){var s;const[t,n]=w.useState(null),r=typeof window<"u"&&((s=window.matchMedia)==null?void 0:s.call(window,"(prefers-reduced-motion: reduce)").matches);return w.useEffect(()=>{if(r)return;const l=e.current;if(!l)return;const c=l.getBoundingClientRect();n({x:c.left+c.width/2,y:c.top+c.height/2});const u=window.setTimeout(()=>n(null),SB);return()=>window.clearTimeout(u)},[e,r]),r||!t?null:Mn.createPortal(o.jsx("div",{className:"confetti",style:{left:`${t.x}px`,top:`${t.y}px`},"aria-hidden":!0,children:jB.map((l,c)=>o.jsx("span",{className:`confetti-bit${l.round?" round":""}`,"data-hue":l.hue,style:{"--dx":`${l.dx.toFixed(1)}px`,"--dy":`${l.dy.toFixed(1)}px`,"--rot":`${l.rot}deg`,"--s":l.scale.toFixed(2),animationDelay:`${l.delay}ms`,animationDuration:`${l.dur}ms, ${l.dur}ms`}},c))}),document.body)}const FM=new Set(["awaiting_url","awaiting_code","registering"]);function _B(e){return e!=null&&FM.has(e)}function qM(e){return e!=null&&e!=="done"&&!FM.has(e)}const EB="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",CB="the sign-in did not complete";function TB({state:e,serverError:t,localError:n}){const r=e==="idle";return{title:r?"Sign-in ended":"Sign-in failed",message:n||t||(r?EB:CB)}}function RB({restored:e,activeAccount:t}){if(e!==!1)return null;const n=(t==null?void 0:t.email)||((t==null?void 0:t.num)!=null?`account ${t.num}`:null);return n?`This machine is now signed in as ${n} — the account you were using could not be put back. Switch back from the accounts panel.`:"The account you were using could not be put back — check which account this machine is signed in as from the accounts panel."}function AB({started:e,state:t}){return!e||t==="done"?null:{action:"login-cancel"}}const MB="done";function IB(){let e=!1;return{shouldAnnounce(t){return t!==MB?(e=!1,!1):e?!1:(e=!0,!0)}}}function Ob(e,t){return t&&Object.hasOwn(e,t)?e[t]:void 0}const $B={already_running:"a sign-in is already in progress",no_url:"the claude CLI did not offer a sign-in link — is it installed?",not_waiting:"that sign-in is no longer waiting for a code",not_prompted:"the CLI has not asked for a code yet",code_rejected:"that code was not accepted — copy it again from the browser",no_verdict:"the claude CLI has not answered — try the code again",empty_code:"paste the code from the browser first",login_failed:"the code was not accepted",no_identity:"signed in, but the CLI still reports nobody logged in",add_failed:"signed in, but claude-swap could not record the account",not_a_share:"that does not look like a shared account — it should start with ccdeck2:",corrupt:"that share is incomplete — copy the whole thing",wrong_version:`that share was made by a newer ${dn}`,expired:"that share has expired — make a new one",import_failed:"claude-swap refused the import",unreadable_export:"claude-swap wrote something this deck could not read — try again, and upgrade it if this repeats",mixed_versions:"claude-swap changed format part-way through — try again",nothing_to_share:"none of those accounts could be exported",too_many:"that is more accounts than one share can carry",not_in_bundle:"that account is not in this share",bad_value:"an alias can only use letters, numbers, spaces, dots, dashes and underscores, up to 64 characters, and cannot start with a dash",bad_email:"that does not look like an email address — it cannot contain spaces or start with a dash"},OB={no_cswap:"claude-swap could not be run — it is not on this deck's PATH. Set AGENTS_DECK_CSWAP to its full path",timeout:"claude-swap took too long and was stopped — try again",switch_failed:"claude-swap refused the switch",bad_account:"that is not an account claude-swap has",unknown_setting:"claude-swap has no such setting",out_of_range:"that value is outside what the setting allows",bad_value:"claude-swap does not accept that value",set_failed:"claude-swap refused the change",command_failed:"claude-swap refused the command"},Lb=`claude-swap could not read the login keychain — start ${dn} from a Terminal window rather than a background service`,FS={unreadable_here:{short:"Keychain locked on this Mac",long:`${Lb}.`},no_credentials_here:{short:"no stored login here",long:"claude-swap still holds no login for it here."},relogin_required_here:{short:"login expired",long:"the imported login was rejected — sign in again on a deck where it still works."},unverified_here:{short:"not checked",long:"claude-swap could not confirm whether this Mac can read it."}};function tf(e){return e&&Object.hasOwn(FS,e)?FS[e]:null}const BM={401:"this deck did not accept the page as its own, so nothing was changed",403:"this deck refused a change from this address — open it on the address the deck prints, not through a proxy"};function O0(e,t,n){const r=n==null?null:BM[n];if(r)return r;if((e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test(Au(e)))return Lb;const s=Ob(OB,e==null?void 0:e.reason);return s||(e==null?void 0:e.reason)||t}function Au(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const LB={no_install:"ccusage is not installed, and AGENTS_DECK_NO_INSTALL=1 forbids fetching it — unset that variable and restart the deck, or install ccusage yourself so it is on this deck's PATH",bad_override:"AGENTS_DECK_CCUSAGE names a file that is not there — correct it to the full path of your ccusage, or unset it to let the deck find its own",timeout:"ccusage took more than 90 seconds and was stopped — a narrower range usually finishes",bad_output:"ccusage ran but printed no usage data — try again, and run ccusage daily --json in a terminal if it keeps happening",run_failed:"ccusage could not report usage — try again",bad_range:"that date range is not a YYYYMMDD date — reopen the modal and pick one of the presets",unreachable:"the deck did not answer — check it is still running, then try again"},PB="ccusage could not be started — npx is not on this deck's PATH. Install Node's npm/npx, or put ccusage on PATH yourself";function DB(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}const FB="ccusage could not be started — the deck launched npx and Node could not load the npm script it points at. An older deck asked cmd.exe for a bare npx.cmd, which made the shim look for that script under the deck's working directory instead of beside itself; update the deck and reopen this modal",qB="ccusage could not be started — the copy npx fetched will not load: Node could not resolve a file inside it. That copy is in npx's own cache, which the deck never rewrites, so clear it with `npm cache clean --force` and reopen this modal",BB=e=>/\b(?:ERR_)?MODULE_NOT_FOUND\b|cannot find (?:module|package)/i.test(e),zB=/node_modules[\\/]npm[\\/]bin[\\/]|\bnpm-prefix\.js\b|\bnp[mx][-.][\w.-]*cli\.js\b/i,UB=/[\\/]_npx[\\/]/i,HB=`the copy of ccusage ${dn} installed for itself`;function WB(e){const t=String((e==null?void 0:e.install)??"").replace(/\s+/g," ").trim();return t.length>240?`${t.slice(0,239)}…`:t}function KX(e,t){const n=VB(e,t),r=WB(e);switch(e==null?void 0:e.stage){case"npx":return r?`ccusage failed on both of its paths. The managed install failed first — ${r} — and the deck then fell back to npx, where ${su(n)}`:`there is no managed copy of ccusage on this machine, and the npx fallback failed: ${su(n)}`;case"managed":return`${HB} failed to run: ${su(n)}`;case"path":return e.bin?`the ccusage this deck found at ${e.bin} failed to run: ${su(n)}`:`the ccusage this deck found on your PATH failed to run: ${su(n)}`;default:return n}}const su=e=>/^[A-Z][a-z]/.test(e)?e[0].toLowerCase()+e.slice(1):e;function VB(e,t){const n=Au(e);if(BB(n)){if(UB.test(n))return qB;if(zB.test(n))return FB}if(DB(n))return PB;const r=Ob(LB,e==null?void 0:e.reason);return r||(e==null?void 0:e.reason)||t}function Al(e,t,n){const r=n==null?null:BM[n];if(r)return r;if(e!=null&&e.detail)return e.detail;if(e!=null&&e.error&&qM(e.state))return e.error;const s=Ob($B,e==null?void 0:e.reason);return s||(e!=null&&e.error?e.error:(e==null?void 0:e.reason)||t)}function GB(e,t,n){if(n<=0||Nf(e))return{kind:"pass"};const r=t>=0&&t<n?t:-1;switch(e.key){case"ArrowRight":return{kind:"select",index:r===-1?0:(r+1)%n};case"ArrowLeft":return{kind:"select",index:r===-1?n-1:(r-1+n)%n};case"Home":return{kind:"select",index:0};case"End":return{kind:"select",index:n-1};default:return{kind:"pass"}}}function zM(e,t){const n=Math.round(e/1e3)-t;return n<=0?{text:"expired",tone:"gone"}:n<60?{text:`expires in ${n}s`,tone:"soon"}:{text:`expires in ${Math.round(n/60)}m`,tone:"ok"}}function KB(e){const t=new Map;for(const n of e){const r=(n.email??"").trim().toLowerCase();r&&t.set(r,(t.get(r)??0)+1)}return e.map(n=>{const r=(n.email??"").trim(),s=n.alias||r||`account ${n.num}`,l=[];return n.alias&&r&&l.push(r),r&&(t.get(r.toLowerCase())??0)>1&&l.push(n.org||`slot ${n.num}`),{num:n.num,label:s,sub:l.length?l.join(" · "):null}})}function YB(e,t){return e.filter(n=>!t.includes(n.num)).map(n=>n.num)}function XB(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function ZB(e){return e.length?{action:"share",accounts:[...e]}:null}function QB(e){return e<=0?"Nothing picked yet.":e===1?"1 account — its sign-in token will be on your clipboard.":`${e} accounts — ${e} sign-in tokens will be on your clipboard.`}function L0(e){return`${e.email}|${e.org??""}`}function JB(e,t,n){return e&&e.map(r=>L0(r)===t?n:r)}function ez(e){switch(e){case"imported":return"imported";case"healed":return"dead token replaced";case"updated":return"updated";case"present":return"already here";default:return"not imported"}}function tz(e){const t=e.length;if(!t)return"Nothing to import.";const n=h=>e.filter(m=>m.state===h).length,r=[],s=n("imported");s&&r.push(`${s} of ${t} imported`);const l=n("healed");l&&r.push(`${l} had a dead token replaced`);const c=n("updated");c&&r.push(`${c} updated`);const u=n("present");u&&r.push(`${u} already here`);const f=n("failed");f&&r.push(`${f} did not arrive`);const p=[...new Set(e.map(h=>{var m;return(m=tf(h.check))==null?void 0:m.short}).filter(h=>!!h))];return`${r.join(", ")}${p.length?`, ${p.join(", ")}`:""}.`}const nz=1500,vh=[{id:"login",label:"Sign in"},{id:"paste",label:"Paste a share"}],qS="aa-panel",BS=e=>`aa-tab-${e}`;async function au(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const P0=ve.forwardRef((e,t)=>o.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:t,children:[o.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),o.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));P0.displayName="SuccessMark";function rz({onClose:e,onChanged:t}){const[n,r]=w.useState("login"),[s,l]=w.useState(null),[c,u]=w.useState(""),[f,p]=w.useState(""),[h,m]=w.useState(!1),[y,v]=w.useState(null),[S,b]=w.useState(null),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useRef(""),R=w.useRef(!1),I=w.useRef(!1),O=w.useRef(null),H=w.useRef(null),q=w.useRef(null),$=w.useRef(null),V=w.useRef([]),ne=w.useRef(!1),ee=w.useCallback(()=>{const z=AB({started:R.current,state:s==null?void 0:s.state});z&&au(z).catch(()=>{}),e()},[e,s==null?void 0:s.state]),M=pn(ee,{focusRef:q}),Z=w.useCallback(async()=>{if(!Ps(I.current))return;I.current=!0,m(!0),v(null),R.current=!0;const z=await au({action:"login"}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"could not start the sign-in"));return}l(z)},[]);w.useEffect(()=>{if(!_B(s==null?void 0:s.state))return;const z=window.setInterval(async()=>{try{const ie=await fetch("/api/claude-accounts/login");ie.ok&&l(await ie.json())}catch{}},nz);return()=>window.clearInterval(z)},[s]);const K=w.useRef(t);K.current=t;const D=w.useState(IB)[0];w.useEffect(()=>{var z;(s==null?void 0:s.state)==="awaiting_code"&&((z=O.current)==null||z.focus()),D.shouldAnnounce(s==null?void 0:s.state)&&K.current()},[s==null?void 0:s.state,D]),w.useEffect(()=>{var z;n==="paste"&&!ne.current&&((z=H.current)==null||z.focus()),ne.current=!1},[n]);const P=w.useCallback(z=>{var le;const ie=GB(z,vh.findIndex(ge=>ge.id===n),vh.length);ie.kind!=="pass"&&(z.preventDefault(),ne.current=!0,r(vh[ie.index].id),(le=V.current[ie.index])==null||le.focus())},[n]),B=w.useCallback(async()=>{var ie;if(!Ps(I.current))return;I.current=!0,m(!0),v(null);const z=await au({action:"login-code",code:c}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"the code was not accepted")),z!=null&&z.state&&l(z),(ie=O.current)==null||ie.select();return}u(""),l(z)},[c,s]),W=w.useCallback(async()=>{if(!Ps(I.current))return;I.current=!0,m(!0),v(null);const z=await au({action:"import",blob:f}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"the import failed"));return}C.current=f,p(""),E(null),b(z.results??[]),t()},[f,t]),F=w.useCallback(async z=>{const ie=L0(z);if(!Ps(I.current)||!C.current)return;I.current=!0,m(!0),k(ie),E(null);const le=await au({action:"import",blob:C.current,force:!0,only:{email:z.email,org:z.org??""}}).catch(()=>null);if(I.current=!1,m(!1),k(null),!(le!=null&&le.ok)){E({key:ie,text:Al(le,"that account could not be updated")});return}const ge=(le.results??[])[0];ge&&b(Ne=>JB(Ne,ie,ge)),t()},[t]),G=(s==null?void 0:s.state)==="done"?s.account:null,re=RB({restored:s==null?void 0:s.restored,activeAccount:s==null?void 0:s.activeAccount}),U=qM(s==null?void 0:s.state)||!!(y&&R.current&&!h),Y=TB({state:s==null?void 0:s.state,serverError:s==null?void 0:s.error,localError:y});return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:ee,role:"presentation",children:o.jsxs("div",{ref:M,className:"modal aa-modal",onClick:z=>z.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{className:"aa-tabs",role:"tablist","aria-label":"How to add the account",onKeyDown:P,children:vh.map((z,ie)=>o.jsx("button",{type:"button",role:"tab",id:BS(z.id),ref:le=>{V.current[ie]=le},"aria-selected":n===z.id,"aria-controls":qS,tabIndex:n===z.id?0:-1,className:`aa-tab${n===z.id?" on":""}`,onClick:()=>{ne.current=!1,r(z.id)},children:z.label},z.id))})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:ee,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsx("section",{className:"modal-body aa-body",id:qS,role:"tabpanel","aria-labelledby":BS(n),children:n==="login"?G?o.jsxs("div",{className:"aa-done",children:[o.jsx(P0,{ref:$}),o.jsx(DS,{anchor:$}),o.jsx("h4",{children:G.added?`Account ${G.num} added`:"Credentials refreshed"}),o.jsxs("p",{className:"aa-note",children:[o.jsx("strong",{children:G.email}),G.added?re?" is in the rotation.":" is in the rotation. The account you were using is still active.":" was already managed, so its stored credentials were replaced."]}),re?o.jsx("p",{className:"aa-note aa-warn",role:"status",children:re}):null,o.jsx("button",{type:"button",className:"btn primary",onClick:ee,children:"Done"})]}):(s==null?void 0:s.state)==="awaiting_code"||(s==null?void 0:s.state)==="registering"?o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"1 · Approve in the browser"}),o.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),o.jsx("a",{className:"aa-link",href:s.url??"#",target:"_blank",rel:"noreferrer noopener",children:s.url})]}),o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"2 · Paste a code, if the page shows one"}),o.jsx("p",{className:"aa-note",children:"It usually finishes on its own — if the page says you are all set, there is nothing to do here."}),o.jsxs("div",{className:"aa-field",children:[o.jsx("input",{ref:O,type:"text",value:c,onChange:z=>u(z.target.value),onKeyDown:z=>{z.key==="Enter"&&c.trim()&&!h&&B()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:s.state==="registering"}),o.jsx("button",{type:"button",className:"btn primary",...Qa(h,!c.trim()||s.state==="registering"),onClick:B,children:s.state==="registering"?"registering…":"Continue"})]}),(y||s.error)&&o.jsx("p",{className:"aa-err",children:y??s.error}),o.jsx("p",{className:"aa-note",children:"The code goes straight to the claude CLI on this machine. It is never stored or sent anywhere else."})]})]}):U?o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:Y.title}),o.jsx("p",{className:"aa-err",children:Y.message}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{R.current=!1,l(null),v(null),Z()},children:"Try again"})]}):h||R.current?o.jsx("div",{className:"aa-step",children:o.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):o.jsxs("div",{className:"aa-step aa-primer",children:[o.jsx("h4",{children:"Sign in to Anthropic"}),o.jsx("p",{className:"aa-note",children:"Opens a browser tab where you approve the sign-in. It normally completes by itself; only if the page hands you a code does it need pasting back here. claude-swap records the account when it completes, and the account you are using now stays active."}),o.jsx("div",{className:"aa-actions",children:o.jsx("button",{type:"button",ref:q,className:"btn primary",onClick:Z,children:"Open the sign-in page"})})]}):S?(()=>{const z=S.filter(le=>le.state==="imported").length,ie=S.some(le=>tf(le.check));return o.jsxs("div",{className:"aa-done",children:[!ie&&o.jsx(P0,{ref:$}),z>0&&!ie&&o.jsx(DS,{anchor:$}),o.jsx("h4",{children:tz(S)}),S.length>0&&o.jsx("ul",{className:"aa-results",children:S.map(le=>{const ge=L0(le),Ne=tf(le.check);return o.jsxs("li",{className:`aa-result ${le.state}`,children:[o.jsx("span",{className:"aa-result-who",children:le.email||(le.num?`slot ${le.num}`:"an account")}),o.jsx("span",{className:"aa-result-what",children:ez(le.state)}),le.state==="present"&&o.jsx("button",{type:"button",className:"aa-result-fix","aria-busy":_===ge,title:`Overwrite the stored login for ${le.email} with the one in this share. Do this when that account has stopped working here; if it works, leave it.`,onClick:()=>F(le),children:_===ge?"updating…":"update anyway"}),Ne&&o.jsx("span",{className:"aa-result-err",children:Ne.long}),(j==null?void 0:j.key)===ge&&o.jsx("span",{className:"aa-result-err",children:j.text})]},ge)})}),o.jsxs("p",{className:"aa-note",children:["Nothing changed on the deck you copied this from. An account already here is left as it is, unless its stored login was dead or you pressed",o.jsx("strong",{children:" update anyway"}),"."]}),o.jsxs("div",{className:"aa-actions",children:[o.jsx("button",{type:"button",className:"btn primary",onClick:ee,children:"Done"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{C.current="",E(null),b(null)},children:"Import another"})]})]})})():o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"Paste an account shared from another deck"}),o.jsxs("div",{className:"aa-field",children:[o.jsx("input",{ref:H,type:"text",value:f,onChange:z=>p(z.target.value),onKeyDown:z=>{z.key==="Enter"&&f.trim()&&!h&&W()},placeholder:"ccdeck2:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),o.jsx("button",{type:"button",className:"btn primary",...Qa(h,!f.trim()),onClick:W,children:h?"importing…":"Import"})]}),y&&o.jsx("p",{className:"aa-err",children:y}),o.jsxs("p",{className:"aa-note",children:["Use ",o.jsx("strong",{children:"share"})," on one account in the other deck, or ",o.jsx("strong",{children:"↗"})," above its list to send several at once. A share carries a live login for every account in it and expires ten minutes after it is made."]})]})})]})}),document.body)}const sz=6;function az(e,t){const n=e.filter(u=>u.ready);if(t.armed&&e.length>0&&n.length===0)return{text:"Auto-switch has nowhere to go",tone:"bad",free:null};const r=n.length===e.length?`${e.length} ready`:n.length===0?e.length===1?"not ready":`none of ${e.length} ready`:`${n.length} of ${e.length} ready`,s=n.length?"ok":"idle",l=t.strained&&!t.armed?oz(n):null,c=[r];return l!=null&&c.push(`${l}% free`),c.push(t.armed?`auto ${t.threshold??"on"}${t.threshold?"%":""}`:"auto off"),{text:c.join(" · "),tone:s,free:l}}function oz(e){const t=e.map(n=>n.headroom).filter(n=>typeof n=="number");return t.length?Math.max(...t):null}function iz(e){const t=[...e].sort((s,l)=>{if(s.ready!==l.ready)return s.ready?-1:1;if(!s.ready)return s.name.localeCompare(l.name);const c=s.headroom,u=l.headroom;return c==null&&u==null?s.name.localeCompare(l.name):c==null?1:u==null?-1:u-c}),n=t.slice(0,sz),r=t.length-n.length;return{title:e.some(s=>s.ready)?"Where you could switch":"Nothing to switch to",shown:n,rest:r>0?`and ${r} more`:null}}function UM({title:e,steps:t,finish:n,aside:r,onClose:s}){const l=w.useRef(null),c=pn(s,{focusRef:l}),[u,f]=w.useState(0),p=u===t.length-1,h=t[u],m=S=>f(Math.max(0,Math.min(t.length-1,S))),y=S=>{S.key!=="ArrowRight"&&S.key!=="ArrowLeft"||(S.preventDefault(),S.stopPropagation(),m(S.key==="ArrowRight"?u+1:u-1))},v=()=>{if(!p){m(u+1);return}n?n.act():s()};return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:s,role:"presentation",children:o.jsxs("div",{ref:c,className:"modal guide",onClick:S=>S.stopPropagation(),onKeyDown:y,role:"dialog","aria-modal":"true","aria-labelledby":"guide-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{id:"guide-title",className:"modal-tool-name",children:e}),o.jsxs("span",{className:"modal-tool-id",children:[u+1," / ",t.length]})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:s,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsx("div",{className:"guide-stage",children:h.art},u),o.jsx("p",{className:"guide-line","aria-live":"polite",children:h.line}),o.jsx("p",{className:"guide-tip",children:h.tip??""}),o.jsxs("div",{className:"guide-foot",children:[o.jsx("div",{className:"guide-dots",children:t.map((S,b)=>o.jsx("button",{type:"button",className:"glyph-btn guide-dot","aria-label":`Step ${b+1} of ${t.length}`,"aria-current":b===u?"step":void 0,onClick:()=>m(b)},b))}),p&&r&&o.jsx("button",{type:"button",className:"ap-lan-word guide-aside",onClick:r.act,children:r.label}),u>0&&o.jsx("button",{type:"button",className:"btn",onClick:()=>m(u-1),children:"Back"}),o.jsx("button",{ref:l,type:"button",className:"btn primary",onClick:v,children:p?(n==null?void 0:n.label)??"Done":"Next"})]})]})]})}),document.body)}const D0={ok:"ga-ok",warn:"ga-warn",accent:"ga-accent",flight:"ga-flight"};function Br({children:e}){return o.jsx("svg",{className:"guide-art",viewBox:"0 0 440 200","aria-hidden":!0,focusable:"false",children:e})}function qr({x:e,y:t=34,w:n=176,h:r=132,label:s}){return o.jsxs(o.Fragment,{children:[s&&o.jsx("text",{x:e+2,y:t-9,className:"ga-cap",children:s}),o.jsx("rect",{x:e,y:t,width:n,height:r,rx:10,className:"ga-screen"})]})}function ys({x:e,y:t,email:n,state:r,tone:s,bars:l}){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{cx:e+3,cy:t-4,r:3,className:D0[s]}),o.jsx("text",{x:e+12,y:t,className:"ga-t ga-mono",children:n}),o.jsx("text",{x:e+12,y:t+16,className:`ga-s ${D0[s]}`,children:r}),l==null?void 0:l.map((c,u)=>o.jsxs("g",{children:[o.jsx("text",{x:e,y:t+40+u*18,className:"ga-s",children:u?"7d":"5h"}),o.jsx("rect",{x:e+22,y:t+35+u*18,width:96,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:e+22,y:t+35+u*18,width:96*c/100,height:4,rx:2,className:"ga-accent"}),o.jsxs("text",{x:e+148,y:t+40+u*18,className:"ga-s ga-accent",textAnchor:"end",children:[c,"%"]})]},u))]})}function HM({x:e,y:t,on:n}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:30,height:18,rx:9,className:n?"ga-switch-on":"ga-switch"}),o.jsx("circle",{cx:n?e+21:e+9,cy:t+9,r:6,className:n?"ga-knob-on":"ga-knob"})]})}function xh({x:e,y:t,name:n,here:r=!0}){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{cx:e+3,cy:t-4,r:3,className:r?"ga-ok":"ga-dim"}),o.jsx("text",{x:e+12,y:t,className:r?"ga-t":"ga-s",children:n})]})}function zS({x:e,y:t,on:n}){return n?o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:12,height:12,rx:3,className:"ga-accent"}),o.jsx("path",{d:`M${e+3} ${t+6.2}l2.3 2.3 4-4.6`,className:"ga-tick"})]}):o.jsx("rect",{x:e+.5,y:t+.5,width:11,height:11,rx:3,className:"ga-box"})}function US({x:e,y:t,d:n}){return o.jsx("path",{d:n,transform:`translate(${e} ${t})`,className:"ga-glyph"})}function Pb({x:e,y:t}){return o.jsx("path",{d:`M${e} ${t}l0 13 3.4-3 2.4 5.2 2-.9-2.4-5.1 4.6-.2z`,className:"ga-pointer"})}function Db(){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{r:9,className:"ga-key-bed"}),o.jsxs("g",{transform:"translate(-6 -6) scale(0.857)",className:"ga-key",children:[o.jsx("circle",{cx:4.6,cy:7,r:2.6}),o.jsx("path",{d:"M7.2 7h5.2M10.6 7v2.2M12.4 7v1.6"})]})]})}function Ml({x:e,y:t,w:n,title:r,sub:s,tone:l}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:n,height:40,rx:8,className:"ga-screen"}),o.jsx("rect",{x:e+6,y:t+10,width:3,height:20,rx:1.5,className:D0[l]}),o.jsx("text",{x:e+16,y:t+17,className:"ga-t ga-strong",children:r}),o.jsx("text",{x:e+16,y:t+31,className:"ga-s",children:s})]})}function Pl({x:e,y:t,label:n,live:r}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:46,height:20,rx:10,className:r?"ga-chip-live":"ga-chip"}),o.jsx("text",{x:e+23,y:t+14,className:"ga-s ga-mono",textAnchor:"middle",children:n})]})}function nf({x:e,y:t}){return o.jsxs(o.Fragment,{children:[o.jsx("text",{x:e,y:t,className:"ga-cap",children:"LOCAL NETWORK"}),o.jsx(HM,{x:e+118,y:t-13,on:!0})]})}function lz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:14,width:206,height:172,rx:10,className:"ga-screen"}),o.jsx("text",{x:28,y:38,className:"ga-t ga-strong",children:"Sessions"}),o.jsx("text",{x:206,y:38,className:"ga-s ga-warn",textAnchor:"end",children:"1 waiting"}),o.jsx("rect",{x:20,y:50,width:194,height:42,rx:6,className:"ga-bed-warn"}),o.jsx("circle",{cx:33,cy:64,r:7,className:"ga-ring-warn ga-ping"}),o.jsx("circle",{cx:33,cy:64,r:3.5,className:"ga-warn"}),o.jsx("text",{x:44,y:68,className:"ga-t",children:"api-server"}),o.jsx("text",{x:44,y:83,className:"ga-s ga-warn",children:"waiting 6m · Bash"}),o.jsx("circle",{cx:33,cy:108,r:3.5,className:"ga-flight"}),o.jsx("text",{x:44,y:112,className:"ga-t",children:"docs-site"}),o.jsx("text",{x:44,y:127,className:"ga-s",children:"running · 12 tools"}),o.jsx("circle",{cx:33,cy:150,r:3.5,className:"ga-ok"}),o.jsx("text",{x:44,y:154,className:"ga-t",children:"billing"}),o.jsx("text",{x:44,y:169,className:"ga-s",children:"done · $0.84"}),o.jsx("path",{d:"M216 71C234 71 230 100 244 100",className:"ga-arc"}),o.jsx("path",{d:"M239 96l5 4-5 4",className:"ga-arrow"}),o.jsx("rect",{x:248,y:44,width:178,height:112,rx:10,className:"ga-screen"}),o.jsx("text",{x:262,y:64,className:"ga-cap",children:"API-SERVER"}),o.jsx("line",{x1:248,y1:74,x2:426,y2:74,className:"ga-line"}),o.jsx("text",{x:262,y:96,className:"ga-s ga-mono",children:"Bash(npm test)"}),o.jsx("text",{x:262,y:116,className:"ga-t ga-mono ga-warn",children:"Allow this command?"}),o.jsx("text",{x:262,y:136,className:"ga-s ga-mono",children:"> 1. Yes 2. No"})]})}function cz(){return o.jsxs(Br,{children:[o.jsx("path",{d:"M136 100C166 100 166 38 196 38",className:"ga-edge ga-flow"}),o.jsx("path",{d:"M136 100H196",className:"ga-edge ga-flow"}),o.jsx("path",{d:"M136 100C166 100 166 162 196 162",className:"ga-edge-done"}),o.jsx("path",{d:"M308 38H326M308 100H326",className:"ga-edge"}),o.jsx(Ml,{x:20,y:80,w:116,title:"main",sub:"Opus 5 · 9 tools",tone:"accent"}),o.jsx(Ml,{x:196,y:18,w:112,title:"explore",sub:"Haiku · 14 tools",tone:"flight"}),o.jsx(Ml,{x:196,y:80,w:112,title:"tests",sub:"Sonnet · 6 tools",tone:"flight"}),o.jsx(Ml,{x:196,y:142,w:112,title:"review",sub:"done · 38s",tone:"ok"}),o.jsx(Pl,{x:326,y:28,label:"Read"}),o.jsx(Pl,{x:380,y:28,label:"Grep",live:!0}),o.jsx(Pl,{x:326,y:90,label:"Bash",live:!0})]})}function HS({x:e,y:t,label:n,pct:r,note:s}){return o.jsxs(o.Fragment,{children:[o.jsx("text",{x:e,y:t,className:"ga-s",children:n}),o.jsxs("text",{x:e+194,y:t,className:"ga-s ga-accent",textAnchor:"end",children:[r,"%"]}),o.jsx("rect",{x:e,y:t+7,width:194,height:5,rx:2.5,className:"ga-track"}),o.jsx("rect",{x:e,y:t+7,width:194*r/100,height:5,rx:2.5,className:"ga-accent"}),o.jsx("text",{x:e,y:t+26,className:"ga-s",children:s})]})}function uz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:30,width:172,height:140,rx:10,className:"ga-screen"}),o.jsx("text",{x:30,y:56,className:"ga-cap",children:"THIS SESSION"}),o.jsx("text",{x:30,y:98,className:"ga-big",children:"$3.66"}),o.jsx("text",{x:30,y:122,className:"ga-s",children:"Opus 5 · 1.2M tokens"}),o.jsx("text",{x:30,y:150,className:"ga-s",children:"$21.40 today"}),o.jsx("rect",{x:200,y:30,width:226,height:140,rx:10,className:"ga-screen"}),o.jsx("text",{x:216,y:56,className:"ga-cap",children:"CLAUDE QUOTA"}),o.jsx(HS,{x:216,y:80,label:"5-hour window",pct:24,note:"resets in 53m"}),o.jsx(HS,{x:216,y:124,label:"7-day window",pct:61,note:"resets in 4d"})]})}function dz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:40,width:172,height:120,rx:10,className:"ga-canvas"}),o.jsx(Ml,{x:30,y:80,w:140,title:"tests",sub:"Sonnet 5 · 6 tools",tone:"flight"}),o.jsx(Pb,{x:156,y:106}),o.jsx("path",{d:"M170 92C186 92 184 60 200 60",className:"ga-arc"}),o.jsx("path",{d:"M195 56l5 4-5 4",className:"ga-arrow"}),o.jsx(qr,{x:200,y:22,w:226,h:160}),o.jsx("text",{x:214,y:46,className:"ga-t ga-strong",children:"tests"}),o.jsx("text",{x:412,y:46,className:"ga-s",textAnchor:"end",children:"Sonnet 5 · 38s"}),o.jsx("line",{x1:200,y1:56,x2:426,y2:56,className:"ga-line"}),o.jsx("text",{x:214,y:76,className:"ga-cap",children:"PROMPT"}),o.jsx("text",{x:214,y:92,className:"ga-t",children:"Run the suite and fix what fails"}),o.jsx("text",{x:214,y:116,className:"ga-cap",children:"TOOLS · 6"}),o.jsx(Pl,{x:214,y:122,label:"Read"}),o.jsx(Pl,{x:266,y:122,label:"Edit"}),o.jsx(Pl,{x:318,y:122,label:"Bash",live:!0}),o.jsx("text",{x:214,y:164,className:"ga-cap",children:"TOKENS"}),o.jsx("text",{x:214,y:178,className:"ga-s ga-mono",children:"41k in · 2.1k out · $0.12"})]})}function hz(){const e=[18,24,28,14,22,26,30,16,24,28,20,26];return o.jsxs(Br,{children:[o.jsx(qr,{x:14,y:20,w:412,h:160}),o.jsx("text",{x:28,y:44,className:"ga-t ga-strong",children:"This machine"}),o.jsx("text",{x:412,y:44,className:"ga-s",textAnchor:"end",children:"12 cores · up 10d"}),o.jsx("line",{x1:14,y1:56,x2:426,y2:56,className:"ga-line"}),o.jsx("text",{x:28,y:76,className:"ga-cap",children:"CORES"}),e.map((t,n)=>o.jsxs("g",{children:[o.jsx("rect",{x:28+n*15,y:82,width:10,height:30,rx:2,className:"ga-track"}),o.jsx("rect",{x:28+n*15,y:112-t,width:10,height:t,rx:2,className:"ga-accent"})]},n)),o.jsx("text",{x:28,y:136,className:"ga-cap",children:"MEMORY"}),o.jsx("rect",{x:28,y:143,width:178,height:5,rx:2.5,className:"ga-track"}),o.jsx("rect",{x:28,y:143,width:105,height:5,rx:2.5,className:"ga-accent"}),o.jsx("text",{x:28,y:165,className:"ga-s",children:"18.9 GB of 32.0 GB"}),o.jsx("text",{x:240,y:76,className:"ga-cap",children:"THERMAL"}),o.jsx("text",{x:240,y:100,className:"ga-big",children:"66 °C"}),o.jsx("text",{x:240,y:118,className:"ga-s ga-ok",children:"running at full speed"}),o.jsx("text",{x:240,y:142,className:"ga-cap",children:"BUSIEST PROCESSES"}),o.jsx("text",{x:240,y:160,className:"ga-s ga-mono",children:"node · claude"}),o.jsx("text",{x:412,y:160,className:"ga-s ga-mono",textAnchor:"end",children:"38%"}),o.jsx("text",{x:240,y:176,className:"ga-s ga-mono",children:"esbuild"}),o.jsx("text",{x:412,y:176,className:"ga-s ga-mono",textAnchor:"end",children:"21%"})]})}function fz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:40,width:188,height:120,rx:10,className:"ga-screen"}),o.jsx("text",{x:28,y:60,className:"ga-cap",children:"~/MY-PROJECT"}),o.jsx("line",{x1:14,y1:70,x2:202,y2:70,className:"ga-line"}),o.jsxs("text",{x:28,y:100,className:"ga-t ga-mono",children:[o.jsx("tspan",{className:"ga-accent",children:"$"})," claude"]}),o.jsx("rect",{x:86,y:90,width:7,height:13,className:"ga-caret ga-blink"}),o.jsx("text",{x:28,y:130,className:"ga-s ga-mono",children:"or: codex"}),o.jsx("path",{d:"M210 100H238",className:"ga-arc"}),o.jsx("path",{d:"M233 95l6 5-6 5",className:"ga-arrow"}),o.jsx("rect",{x:250,y:40,width:176,height:120,rx:10,className:"ga-canvas"}),o.jsx("g",{className:"ga-pop",children:o.jsx(Ml,{x:278,y:80,w:120,title:"my-project",sub:"Opus 5 · live",tone:"accent"})})]})}function pz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,y:16,w:232,h:170}),o.jsx("text",{x:28,y:40,className:"ga-t ga-strong",children:"Claude accounts"}),o.jsx(US,{x:196,y:33,d:"M7 2.2v9.6M2.2 7h9.6"}),o.jsx(US,{x:220,y:33,d:"M3.3 10.7L10.7 3.3M5.2 3.3h5.5v5.5"}),o.jsx("line",{x1:14,y1:52,x2:246,y2:52,className:"ga-line"}),o.jsx(ys,{x:28,y:74,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("rect",{x:190,y:62,width:44,height:18,rx:9,className:"ga-accent"}),o.jsx("text",{x:212,y:74,className:"ga-s ga-on-accent",textAnchor:"middle",children:"active"}),o.jsx("line",{x1:14,y1:140,x2:246,y2:140,className:"ga-line"}),o.jsx(ys,{x:28,y:160,email:"personal@me.dev",state:"signed in",tone:"ok"}),o.jsx("rect",{x:188,y:148,width:46,height:18,rx:9,className:"ga-chip"}),o.jsx("text",{x:211,y:160,className:"ga-s",textAnchor:"middle",children:"switch"}),o.jsx(Pb,{x:221,y:161}),o.jsx("path",{d:"M250 40C270 40 262 78 282 78",className:"ga-arc"}),o.jsx("path",{d:"M277 74l5 4-5 4",className:"ga-arrow"}),o.jsx(qr,{x:282,y:62,w:144,h:64,label:"ANOTHER MACHINE"}),o.jsx("g",{className:"ga-pop",children:o.jsx(ys,{x:296,y:92,email:"work@team.dev",state:"shared here",tone:"ok"})})]})}function mz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(nf,{x:28,y:60}),o.jsx("g",{className:"ga-swap-out",children:o.jsx(ys,{x:28,y:98,email:"work@team.dev",state:"login expired",tone:"warn"})}),o.jsx("g",{className:"ga-swap-in",children:o.jsx(ys,{x:28,y:98,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(nf,{x:264,y:60}),o.jsx(ys,{x:264,y:98,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("path",{d:"M246 120C234 80 206 80 194 120",className:"ga-arc"}),o.jsx("g",{className:"ga-travel ga-travel-low",transform:"translate(220 90)",children:o.jsx(Db,{})})]})}const gz=[{art:o.jsx(lz,{}),line:"Sessions waiting on you top the session list, longest wait first.",tip:"A tone and a system notification when one stops to ask. The speaker in the topbar."},{art:o.jsx(cz,{}),line:"Every agent and subagent is a node. Tool calls light up as they run."},{art:o.jsx(dz,{}),line:"Double-click any node: its prompt, every tool call, tokens and timing."},{art:o.jsx(uz,{}),line:"What each session costs, and how much quota is left."},{art:o.jsx(hz,{}),line:"Cores, memory and heat while the agents run, and what is hogging them."},{art:o.jsx(pz,{}),line:"Several Claude accounts: switch, add one, share one to another machine."},{art:o.jsx(mz,{}),line:"Your machines repair each other's expired logins over the local network.",tip:"Open it from the row at the foot of the Claude accounts panel."},{art:o.jsx(fz,{}),line:"Run claude or codex in any folder. It shows up here on its own."}];function yz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(ys,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"}),o.jsx("rect",{x:40,y:94,width:86,height:20,rx:10,className:"ga-pill-warn"}),o.jsx("text",{x:83,y:108,className:"ga-s ga-warn",textAnchor:"middle",children:"sign in again"}),o.jsx("line",{x1:198,y1:100,x2:242,y2:100,className:"ga-off"}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(ys,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]})]})}function wz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(nf,{x:28,y:60}),o.jsx(xh,{x:28,y:92,name:"Ana's MacBook"}),o.jsx(xh,{x:28,y:114,name:"Dorin's PC"}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(nf,{x:264,y:60}),o.jsx(xh,{x:264,y:92,name:"Your MacBook"}),o.jsx(xh,{x:264,y:114,name:"Dorin's PC"}),o.jsx("line",{x1:196,y1:100,x2:244,y2:100,className:"ga-arc"}),o.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping"}),o.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping ga-ping-2"}),o.jsx("circle",{cx:220,cy:100,r:3,className:"ga-accent"})]})}function vz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:90,y:18,width:260,height:164,rx:10,className:"ga-screen"}),o.jsx("text",{x:106,y:42,className:"ga-t ga-strong",children:"This deck on the network"}),o.jsx("line",{x1:90,y1:54,x2:350,y2:54,className:"ga-line"}),o.jsx("text",{x:106,y:76,className:"ga-cap",children:"SHARE THESE ACCOUNTS"}),o.jsx(zS,{x:106,y:88,on:!0}),o.jsx("text",{x:126,y:98,className:"ga-t ga-mono",children:"work@team.dev"}),o.jsx(zS,{x:106,y:112}),o.jsx("text",{x:126,y:122,className:"ga-s ga-mono",children:"personal@me.dev"}),o.jsx("text",{x:106,y:150,className:"ga-cap",children:"PAIRING"}),o.jsx("text",{x:106,y:168,className:"ga-s",children:"Say yes to every deck that asks"}),o.jsx(HM,{x:304,y:157,on:!0}),o.jsx(Pb,{x:115,y:97})]})}function xz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx("g",{className:"ga-swap-out",children:o.jsx(ys,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"})}),o.jsx("g",{className:"ga-swap-in",children:o.jsx(ys,{x:28,y:64,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(ys,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("path",{d:"M246 96C234 56 206 56 194 96",className:"ga-arc"}),o.jsx("g",{className:"ga-travel",transform:"translate(220 66)",children:o.jsx(Db,{})})]})}const bz=[{art:o.jsx(yz,{}),line:"A login can expire on one machine while it still works on another."},{art:o.jsx(wz,{}),line:"Both decks are on. They find each other and ask to pair.",tip:"Not showing up? The + in the section reaches a machine by address or invite."},{art:o.jsx(vz,{}),line:"Tick which logins this machine may hand out. Nothing is shared until you do."},{art:o.jsx(xz,{}),line:"An expired login is copied from a paired machine within a minute."}];function kz(){return o.jsxs("svg",{className:"guide-art",viewBox:"0 0 232 60","aria-hidden":!0,focusable:"false",children:[o.jsx("rect",{x:1,y:14,width:78,height:42,rx:7,className:"ga-screen"}),o.jsx("circle",{cx:13,cy:29,r:3,className:"ga-warn"}),o.jsx("rect",{x:21,y:27,width:46,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:13,y:39,width:40,height:3,rx:1.5,className:"ga-track"}),o.jsx("rect",{x:153,y:14,width:78,height:42,rx:7,className:"ga-screen"}),o.jsx("circle",{cx:165,cy:29,r:3,className:"ga-ok"}),o.jsx("rect",{x:173,y:27,width:46,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:165,y:39,width:40,height:3,rx:1.5,className:"ga-accent"}),o.jsx("path",{d:"M150 36C138 6 94 6 82 36",className:"ga-arc"}),o.jsx("g",{transform:"translate(116 13)",children:o.jsx(Db,{})})]})}const Nz={panel:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it behind the + above, where an address can be typed too.",dialog:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it below, or type their address."},Sz=1600;function WM({reach:e,where:t}){const[n,r]=w.useState(!1),s=w.useRef(!0);w.useEffect(()=>()=>{s.current=!1},[]);const l=(e==null?void 0:e.steps)??[],c=w.useCallback(async()=>{await hi(l.join(`
|
|
91
91
|
`))&&s.current&&(r(!0),window.setTimeout(()=>{s.current&&r(!1)},Sz))},[l]);if(!(e!=null&&e.blocked))return null;const u=e.shell==="sh";return o.jsxs("div",{className:"ap-lan-reach",children:[o.jsx("p",{className:"lan-warn",children:e.text}),o.jsx("p",{className:"lan-note",children:Nz[t]}),l.length>0&&o.jsxs("details",{className:"ap-lan-reach-fix",children:[o.jsx("summary",{children:"or let them find this deck on their own"}),o.jsxs("p",{className:"lan-note",children:[u?o.jsx(o.Fragment,{children:"Run this in a terminal on this machine, then restart the deck."}):o.jsxs(o.Fragment,{children:["Run this in PowerShell ",o.jsx("strong",{children:"as Administrator"}),", then restart the deck."]}),e.category==="Public"&&o.jsx(o.Fragment,{children:" The first line marks this network as a home or office one — leave it out on a network you do not trust."}),e.unsure&&o.jsxs(o.Fragment,{children:[" ",e.unsure]})]}),o.jsx("pre",{className:"ap-lan-cmd",children:o.jsx("code",{children:l.join(`
|
|
92
|
-
`)})}),o.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>void c(),title:u?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:n?"copied":"copy command"})]})]})}async function Cm(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const jz={not_an_invite:"That is not an invite — paste the whole line they sent you.",expired:"That invite has run out. Ask them for a fresh one.",not_running:"This deck is not on the network yet. Turn Local network on, then try again."},_z={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function WS(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||un(n,t)}function Ez({status:e,manual:t,startWith:n,onClose:r,onChanged:s}){const l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),f=e.pairingMode==="invite",p=pn(r,{focusRef:f?c:l}),[h,m]=w.useState(""),[y,v]=w.useState(""),[S,b]=w.useState(null),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(null),[I,O]=w.useState(()=>Date.now());w.useEffect(()=>{const re=window.setInterval(()=>O(Date.now()),1e3);return()=>window.clearInterval(re)},[]);const H=w.useRef(!0);w.useEffect(()=>()=>{H.current=!1},[]);const q=w.useRef(null),$=w.useCallback(re=>Tf(q.current)?(q.current=re,E(re),!0):!1,[]),V=w.useCallback(()=>{q.current=null,H.current&&E(null)},[]),ne=re=>{const U=ao(j,re);return{disabled:U.disabled,"aria-busy":U.busy}},ee=re=>(S==null?void 0:S.field)===re?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},M=re=>b(U=>U&&U.field===re?null:U),Z=w.useCallback(async()=>{if(f)return;const re=zz(h);if(!re){b({text:Cz(h),field:"addr"});return}const U=`${re.addr}:${re.port}`,Y=e.peers.find(z=>z.addr===re.addr&&z.port===re.port&&z.paired);if(Y){b({text:`Already paired with ${Y.name} at that address.`,field:"addr"});return}if(t.includes(U)){b({text:"This deck already calls that address.",field:"addr"});return}if($("add"))try{const z=await Cm("/api/prefs",{lan:{manual:[...t,U]}});if(!H.current)return;z!=null&&z.ok?(b(null),m(""),s(),r()):b({text:un("add that address",z),field:"addr"})}catch{H.current&&b({text:un("add that address",null),field:"addr"})}finally{V()}},[h,f,t,e.peers,s,r,$,V]),K=w.useCallback(async re=>{if(!$(`invite:${re}`))return;const U=re==="make"?"make an invite":"cancel that invite";try{const Y=await Cm("/api/lan/invite",{action:re});if(!H.current)return;Y!=null&&Y.ok?(b(null),k(null),s()):b({text:WS(_z,Y,U)})}catch{H.current&&b({text:un(U,null)})}finally{V()}},[s,$,V]),D=w.useCallback(async()=>{const re=y.trim();if(!(!re||!$("join"))){R(null);try{const U=await Cm("/api/lan/invite",{action:"join",token:re});if(!H.current)return;U!=null&&U.ok?(v(""),b(null),s(),r()):(U==null?void 0:U.reason)==="unreachable"&&Array.isArray(U.tried)&&U.tried.length?(R(U.tried),b(null)):(R(null),b({text:WS(jz,U,"use that invite"),field:"join"}))}catch{H.current&&b({text:un("use that invite",null),field:"join"})}finally{V()}}},[y,s,r,$,V]),P=w.useCallback(async(re,U)=>{try{await navigator.clipboard.writeText(re),k(U),window.setTimeout(()=>{H.current&&k(Y=>Y===U?null:Y)},1600)}catch{b({text:"Could not copy it — select the text and copy it by hand."})}},[]),B=e.invite&&e.invite.expiresAt>I?e.invite:null,W=w.useRef(!1);w.useEffect(()=>{n!=="invite"||W.current||B||(W.current=!0,K("make"))},[n,B,K]);const F=w.useRef(!1);w.useEffect(()=>{var re;n!=="invite"||F.current||!B||(F.current=!0,(re=u.current)==null||re.focus())},[n,B]);const G=e.port!=null?(e.addrs??[]).map(re=>`${re}:${e.port}`):[];return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:o.jsxs("div",{ref:p,className:"modal lan-add",onClick:re=>re.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{className:"glyph-btn",onClick:r,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[S&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:S.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>b(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsx(WM,{reach:e.reach,where:"dialog"}),f&&o.jsx("div",{className:"modal-section",children:o.jsx("p",{className:"lan-note",children:"Adding by address is off while this deck pairs only by invite."})}),!f&&o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"By address"}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("input",{ref:l,className:"ap-manage-input ap-lan-input","aria-label":"Another deck's address",value:h,placeholder:"192.168.1.5:54340",spellCheck:!1,...ee("addr"),onChange:re=>{m(re.target.value),M("addr")},onKeyDown:re=>{re.key==="Enter"&&Z()}}),h.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("add"),onClick:()=>void Z(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),o.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&G.length>0&&o.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",G.map((re,U)=>o.jsxs("span",{children:[U>0&&" or ",o.jsx("code",{className:"ap-lan-code",children:re})]},re)),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...ne("copy:mine"),onClick:()=>void P(G.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:_==="mine"?"copied":"copy"})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsxs("h3",{className:"lan-h",children:["With an invite",!B&&o.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...ne("invite:make"),onClick:()=>void K("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:j==="invite:make"?"making…":"make one to send"})]}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("input",{ref:c,className:"ap-manage-input ap-lan-input","aria-label":"An invite you were sent",value:y,placeholder:"paste one you were sent",spellCheck:!1,...ee("join"),onChange:re=>{v(re.target.value),R(null),M("join")},onKeyDown:re=>{re.key==="Enter"&&D()}}),y.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("join"),onClick:()=>void D(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:j==="join"?"joining…":"join"})]}),o.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),C&&o.jsxs("div",{className:"ap-lan-tried",children:[o.jsx("span",{className:"lan-note",children:"Nothing answered at any address in that invite. Check that deck is running with its Local network switch on."}),C.map(re=>o.jsxs("span",{className:"ap-lan-tried-row",children:[o.jsx("code",{className:"ap-lan-code",children:re.addr}),o.jsx("span",{className:"ap-lan-bad",children:re.why})]},re.addr))]}),B&&o.jsxs("div",{className:"ap-lan-invite",children:[o.jsxs("div",{className:"ap-lan-invite-head",children:[o.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),o.jsxs("span",{className:"ap-lan-invite-left",id:"lan-invite-left",children:[Wz(B.expiresAt,I)," left"]})]}),o.jsx("code",{className:"ap-lan-token",children:B.token}),o.jsxs("div",{className:"ap-lan-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",ref:u,...ne("copy:invite"),"aria-label":_==="invite"?"Invite copied":"Copy invite","aria-describedby":"lan-invite-left",onClick:()=>void P(B.token,"invite"),title:"Copy it, and send it however you already talk to them",children:_==="invite"?"copied":"copy"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("invite:withdraw"),onClick:()=>void K("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),o.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function Cz(e){const t=(e??"").trim();if(t==="")return"Type an address and a port, like 192.168.1.5:54340.";if(!t.startsWith("[")&&(t.match(/:/g)??[]).length>1)return"Too many colons to split. Use that deck's IPv4 address or its name, like 192.168.1.5:54340.";if(!t.includes(":"))return`Add the port too, like ${t}:54340.`;const n=t.slice(t.lastIndexOf(":")+1).trim();return n===""?"That is missing its port — try 192.168.1.5:54340.":/^\d+$/.test(n)?`A port runs from 1 to 65535, and this one is ${n}.`:`A port is a number, and this one is "${n}".`}const Tz=1e3;function Rz(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),r=qs(e,t);return`${n} · ${r==="now"?"just now":r}`}function VS(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function Az(){return o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),o.jsx("path",{d:"M8.4 3.6l2 2"})]})}function GS(){return o.jsxs("svg",{className:"lan-machine",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),o.jsx("path",{d:"M1 13h14"})]})}function bh({dir:e,gate:t=!1}){const n=t?12:8;return o.jsx("svg",{className:"lan-chev","data-dir":e,"data-gate":t||void 0,width:n,height:"8",viewBox:`0 0 ${n} 8`,fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:e==="out"?"M2.8 1L6 4 2.8 7":t?"M1 1v6M9.6 1L6.4 4l3.2 3":"M5.2 1L2 4l3.2 3"})})}const Mz={works:"works here",expired:"expired here",missing:"not on this deck",unavailable:"cannot share here"},Iz={works:"works there",broken:"broken there",unavailable:"cannot share there",unknown:"not offered by that deck"};function $z(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${Mz[e.here]}, ${Iz[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function Oz({row:e,source:t,status:n,accounts:r,now:s,busy:l,onClose:c,onRename:u,onCheck:f,onVerb:p,onSettings:h,onInvite:m,twins:y=[],onUnpair:v}){var Ot,zt,Xt,Dt,rn;const S=w.useRef(null),b=pn(c,{focusRef:S}),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(!1),I=w.useRef(0),[O,H]=w.useState(null),[q,$]=w.useState(!1),[V,ne]=w.useState(0),ee=w.useRef(null),M=w.useRef(!0);w.useEffect(()=>()=>{M.current=!1},[]);const Z=_!=null;w.useEffect(()=>{var je;Z&&((je=ee.current)==null||je.select())},[Z]),w.useEffect(()=>{if(!C)return;const je=window.setTimeout(()=>R(!1),4e3);return()=>window.clearTimeout(je)},[C]),w.useEffect(()=>{if(!O)return;const je=window.setTimeout(()=>H(null),4e3);return()=>window.clearTimeout(je)},[O]);const K=je=>{const xt=ao(l,je);return{disabled:xt.disabled,"aria-busy":xt.busy}},D=async je=>{const xt=await je();return M.current&&E(xt),xt==null},{peer:P,stranger:B}=t,W=e.kind==="paired",F=e.self??e.name,G=e.kind!=="dialling",re=e.kind==="dialling"?null:e.fp,U=P?P.addr?`${P.addr}:${P.port}`:"":B?B.port?`${B.addr}:${B.port}`:B.addr:e.addr,Y=(P==null?void 0:P.about)??null,z=((Ot=n.about)==null?void 0:Ot.version)??null,ie=async je=>{const xt=je.trim()===F?"":je;await D(()=>u(xt))&&k(null)},le=async()=>{if(re)try{if(await navigator.clipboard.writeText(re),!M.current)return;$(!0),window.setTimeout(()=>{M.current&&$(!1)},1600)}catch{M.current&&E("Could not copy it — select the fingerprint and copy it by hand.")}},ge=W?P!=null&&P.waiting?P.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":P!=null&&P.offers?"not said — it runs an older version":"not reached yet":"shown once paired",Ne=VS(n.about),Ie=VS(Y),Ge=Y!=null&&Y.version&&z?eU(Y.version,z):null,Pe=P?qb(P.last,s):null,Be=P&&((zt=P.last)!=null&&zt.error)?Bz({error:P.last.error,host:P.addr,port:P.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(je=>!je.manual&&je.addr).map(je=>({fp:je.fp,name:je.name,addr:je.addr,port:je.port,at:je.lastSeen??0}))],s):null,Te=(Xt=P==null?void 0:P.last)!=null&&Xt.error&&Pe&&Pe.text!==P.last.error?P.last.error:null,st=((Dt=P==null?void 0:P.last)==null?void 0:Dt.done)??[],de=!!Pe&&!!Te&&!e.quiet&&e.state.startsWith(Pe.text),ue=W||e.kind==="dialling",se=((P==null?void 0:P.via)??e.via)==="tailscale",be=P?P.waiting?null:P.manual?se?"added by its Tailscale address":"added by address":se?"over Tailscale":"on this network":e.kind==="nearby"?se?"heard over Tailscale":"heard on this network":se?"asked this deck to pair, over Tailscale":"asked this deck to pair",Le=e.tone==="bad"?"bad":W?e.here?"up":"down":"loose",ce=l===`check:${e.fp}`,pe=(P==null?void 0:P.offers)??null,Ae=Le==="up"?(pe==null?void 0:pe.current)??null:null,fe=Ae&&"key"in Ae?Ae.key:null,Se=!!Ae&&"hidden"in Ae,Ye=!!Ae&&"other"in Ae,qe=W?nU((pe==null?void 0:pe.accounts)??null,r,n.shared??[],fe):[],ke=qe.filter(je=>je.in==null&&je.out==="cut"),Re=qe.some(je=>je.in!=null),ze=qe.some(je=>je.out!=null),Fe=new Map(st.map(je=>[je.email,je])),We=st.filter(je=>!qe.some(xt=>xt.email===je.email)),rt=W?pe?pe.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:P!=null&&P.waiting?"What that deck offers is not known yet. A deck that calls in says so each time it calls — one on an older version never does.":(rn=P==null?void 0:P.last)!=null&&rn.error?"What that deck offers is not known — the last attempt to ask it did not get through.":"Nobody has asked that deck what it offers yet. The next round asks it.":null,dt=pe&&(P!=null&&P.last)&&P.last.at-pe.at>Tz?qs(pe.at,s):null,ct=[];W&&(P!=null&&P.pairedAt)?ct.push({label:"Paired",value:Rz(P.pairedAt,s),tone:"meta"}):e.kind==="declined"&&B&&ct.push({label:"Paired",value:`no · you said no ${Bb(B.at,s)}`,tone:"meta"}),ct.push({label:"Fingerprint",value:re?o.jsxs("span",{className:"lan-fp",children:[o.jsx("code",{className:"ap-lan-code",children:re}),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void le(),"aria-label":q?"Fingerprint copied":"Copy the fingerprint",children:q?"copied":"copy"})]}):"not known — nothing has answered there",tone:re?void 0:"quiet"});const yt=y.length?[{row:e,peer:P??null},...y]:[];return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:o.jsxs("div",{ref:b,className:"modal lan-peer","data-tone":e.tone,onClick:je=>je.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[o.jsxs("header",{className:"modal-head lan-peer-head",children:[o.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("div",{className:"lan-peer-id",children:[Z?o.jsxs("form",{className:"lan-peer-edit",onSubmit:je=>{je.preventDefault(),ie(_??"")},children:[o.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),o.jsx("input",{ref:ee,className:"ap-manage-input lan-peer-input",value:_??"",maxLength:48,placeholder:F,"aria-label":"Name for this deck, shown on this deck only",onChange:je=>k(je.target.value)}),o.jsx("button",{type:"submit",className:"ap-manage-btn",...K(`alias:${e.fp}`),children:"save"}),o.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>k(null),children:"cancel"})]}):o.jsxs("span",{className:"lan-peer-title",children:[o.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),G&&o.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",onClick:()=>{E(null),k(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:o.jsx(Az,{})})]}),o.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&o.jsxs(o.Fragment,{children:["calls itself ",o.jsx("span",{className:"lan-peer-self",children:e.self}),Z&&o.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...K(`alias:${e.fp}`),onClick:()=>void ie(""),children:"use this name"}),o.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&o.jsx("span",{"aria-hidden":!0,children:" · "})]}),o.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{ref:S,type:"button",className:"glyph-btn",onClick:c,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body lan-peer-body",children:[j&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:j}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>E(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsxs("div",{className:"lan-map","data-link":Le,"data-asking":ce||void 0,"data-bus":qe.length>0||void 0,children:[o.jsxs("div",{className:"lan-ends",children:[o.jsxs("p",{className:"lan-end",children:[o.jsx("span",{className:"lan-end-name",children:"This deck"}),Ne&&o.jsx("span",{className:"lan-end-runs",children:Ne}),W&&n.shareActive===!1&&o.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),o.jsxs("p",{className:"lan-end","data-side":"there",children:[o.jsx("span",{className:"lan-end-name",children:e.name}),e.kind!=="dialling"&&o.jsxs("span",{className:"lan-end-runs",children:[Ie??(Y?"not said":ge),Ge?` · ${Ge<0?"older":"newer"}`:null]}),Se&&o.jsx("span",{className:"lan-end-note",children:"current account hidden"}),Ye&&o.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),o.jsxs("div",{className:"lan-link",children:[o.jsx(GS,{}),o.jsxs("span",{className:"lan-span",children:[o.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[o.jsx("i",{className:"lan-glint","data-dir":"out"}),o.jsx("i",{className:"lan-glint","data-dir":"in"})]}),o.jsx("span",{className:"lan-link-label",children:U?o.jsx("code",{className:"ap-lan-code",children:U}):"none here — it calls this deck"})]}),o.jsx(GS,{}),(U&&be||ue)&&o.jsxs("p",{className:"lan-link-sub",children:[U&&be,U&&be&&ue&&" · ",ue&&(Pe?de?o.jsx("code",{className:"ap-lan-code",children:Te}):o.jsx("span",{className:"lan-round","data-tone":Pe.tone,children:Pe.text.replace(/ · now$/," · just now")}):"not asked yet"),ue&&Te&&!de&&o.jsx("code",{className:"lan-fact-raw",children:Te})]}),We.length>0&&o.jsx("ul",{className:"lan-done",children:We.map(je=>{const xt=F0(je);return o.jsxs("li",{"data-ok":je.ok&&!xt,children:[je.email," ",o.jsxs("span",{className:"lan-done-what",children:[je.ok?"arrived":"did not arrive",xt&&` — ${xt.long}`]})]},`${je.email}:${je.action}`)})}),Be&&o.jsx("p",{className:"lan-note lan-link-note",children:Be}),(P==null?void 0:P.waiting)&&o.jsx("p",{className:"lan-note lan-link-note",children:e.hint}),(Pe==null?void 0:Pe.hint)&&o.jsx("p",{className:"lan-note lan-link-note",children:Pe.hint})]}),qe.length>0&&o.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${e.name}`,children:qe.map((je,xt)=>{const bt=Fe.get(je.email),_n=bt?F0(bt):null,Ut=je.out==="live"||je.in!=null&&je.in!=="cut";return o.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":je.tone,"data-draw":je.in&&je.out?"both":je.in?"in":"out","data-used-there":je.usedThere||void 0,style:{"--i":xt},children:[o.jsx("i",{className:"lan-pip","data-end":"here","data-state":je.here,"aria-hidden":!0}),o.jsxs("span",{className:"lan-track",children:[o.jsxs("span",{className:"lan-wire","data-flow":Ut?"live":"cut","aria-hidden":!0,children:[(je.in==="live"||je.in==="wait")&&o.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":je.in}),je.out==="live"&&o.jsx("i",{className:"lan-glint","data-dir":"out"})]}),je.in&&je.in!=="cut"&&o.jsx(bh,{dir:"in",gate:je.in==="blocked"}),je.out==="live"&&o.jsx(bh,{dir:"out"}),o.jsx("span",{className:"lan-lane-email",children:je.email})]}),o.jsx("i",{className:"lan-pip","data-end":"there","data-state":je.there,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:$z(je)}),(je.caption||bt)&&o.jsxs("span",{className:"lan-lane-note",children:[je.caption,je.caption&&bt&&" · ",bt&&o.jsxs("span",{className:"lan-lane-done","data-ok":bt.ok&&!_n,children:[bt.ok?"arrived last round":"did not arrive last round",_n&&` — ${_n.long}`]})]})]},je.key)})},V),W&&o.jsxs(o.Fragment,{children:[ke.length>0&&o.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",ke.length===1?ke[0].email:"the expired ones"," until you sign in again here."]}),rt&&o.jsx("p",{className:"lan-empty",children:rt}),dt&&o.jsxs("p",{className:"lan-stale",children:["As of ",dt==="now"?"just now":dt,", when it last answered."]}),o.jsxs("div",{className:"lan-legend",children:[Re&&o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:o.jsx(bh,{dir:"in"})}),"from ",e.name]}),ze?o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:o.jsx(bh,{dir:"out"})}),"from this deck, to every paired deck"]}):o.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),o.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:h,"aria-label":"Change what this deck offers",children:"change"})]})]})]}),o.jsx("dl",{className:"lan-facts",children:ct.map(je=>o.jsxs("div",{className:"lan-fact","data-tone":je.tone,children:[o.jsx("dt",{children:je.label}),o.jsx("dd",{children:je.value})]},je.label))}),yt.length>1&&o.jsxs("div",{className:"modal-section",children:[o.jsxs("h3",{className:"lan-h",children:[yt.length," decks on this machine"]}),o.jsx("ul",{className:"lan-twins",role:"list",children:yt.map((je,xt)=>{var Lt,Zt,In,Hr;const bt=(Lt=je.peer)!=null&&Lt.addr?`${je.peer.addr}:${je.peer.port}`:je.row.addr,_n=bt||je.row.fp,Ut=(Zt=je.peer)!=null&&Zt.pairedAt?qs(je.peer.pairedAt,s):null,Vn=[(Hr=(In=je.peer)==null?void 0:In.about)!=null&&Hr.version?`runs ${je.peer.about.version}`:null,Ut?`paired ${Ut==="now"?"just now":Ut}`:null,je.row.state].filter(Boolean).join(" · "),Vt=je.row.fp;return o.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":je.row.tone,children:[o.jsx("i",{className:je.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),bt?o.jsx("code",{className:"ap-lan-code lan-twin-at",children:bt}):o.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),o.jsx("code",{className:"ap-lan-code lan-twin-fp",children:Vt}),xt>0&&v&&o.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${O===Vt?" armed":""}`,...K(`unpair:${Vt}`),onKeyDown:xe=>{xe.repeat&&xe.preventDefault()},onClick:()=>{const xe=Date.now(),lr=Cu({armedFor:O,target:Vt,armedAt:I.current,now:xe,gapMs:Mu});if(lr==="arm"){H(Vt),I.current=xe;return}lr!=="ignore"&&(H(null),D(()=>v(Vt)))},"aria-label":O===Vt?`Confirm unpairing ${_n}`:`Unpair ${_n}`,title:O===Vt?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this one of the machine's decks",children:l===`unpair:${Vt}`?"unpairing…":O===Vt?"confirm":"unpair"}),o.jsx("span",{className:"lan-twin-meta",children:xt===0?`${Vn} · shown above`:Vn})]},Vt)})})]})]}),o.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&o.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),W&&!(P!=null&&P.waiting)&&o.jsx("button",{type:"button",className:"btn",...K(`check:${e.fp}`),onClick:()=>void D(f).then(je=>{je&&M.current&&ne(xt=>xt+1)}),title:"Ask this deck now instead of waiting for the next round",children:l===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&o.jsx("button",{type:"button",className:`btn danger lan-peer-verb${C?" armed":""}`,...K(`unpair:${e.fp}`),onKeyDown:je=>{je.repeat&&je.preventDefault()},onClick:()=>{const je=Date.now(),xt=Cu({armedFor:C?e.fp:null,target:e.fp,armedAt:I.current,now:je,gapMs:Mu});if(xt==="arm"){R(!0),I.current=je;return}xt!=="ignore"&&(R(!1),D(p))},"aria-label":C?`Confirm unpairing ${e.name}`:`Unpair ${e.name}`,title:C?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:l===`unpair:${e.fp}`?"Unpairing…":C?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&n.pairingMode!=="invite"&&o.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...K(`accept:${e.fp}`),onClick:()=>void D(p),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:l===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&o.jsx("button",{type:"button",className:"btn lan-peer-verb",...K(`drop:${e.fp}`),onClick:()=>void D(p),title:"Stop trying this address. Nothing was ever paired here.",children:l===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&n.pairingMode!=="invite"&&o.jsx("button",{type:"button",className:"btn lan-peer-verb",...K(`allow:${e.fp}`),onClick:()=>void D(p),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:l===`allow:${e.fp}`?"Allowing…":"Let it ask again"}),(e.kind==="nearby"||e.kind==="declined")&&n.pairingMode==="invite"&&m&&o.jsx("button",{type:"button",className:"btn primary lan-peer-verb",onClick:m,title:"This deck pairs only by invite. Make one and send it to whoever is at that machine.",children:"Invite to pair"})]})]})}),document.body)}function Lz(e){if(!e.running)return`Tailscale is ${e.state==="Stopped"?"turned off":e.state==="NeedsLogin"||e.state==="NeedsMachineAuth"?"signed out":e.state==="Starting"?"still starting":"not answering"} on this machine`;const t=e.login??"your Tailscale account";return e.on?`${e.devices} online · ${t}`:t}const kh="Paused while this deck pairs only by invite. Turn that off above to use it.";function Pz({status:e,accounts:t,onClose:n,onChanged:r}){const s=pn(n),[l,c]=w.useState(null),[u,f]=w.useState(null),[p,h]=w.useState(!1),[m,y]=w.useState(null),v=w.useRef(null),S=M=>{const Z=ao(m,M);return{disabled:Z.disabled,"aria-busy":Z.busy}},b=w.useRef(null),_=w.useRef(!0);w.useEffect(()=>()=>{_.current=!1},[]),w.useEffect(()=>{b.current=XS(b.current,e.shared??[],null)},[e.shared]);const k=w.useCallback(async(M,Z,K="write")=>{v.current=K,y(K);try{const P=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:M})})).json().catch(()=>null);return _.current?(P!=null&&P.ok?f(null):f(un(Z,P)),r(),(P==null?void 0:P.ok)===!0):!1}catch{return _.current&&f(un(Z,null)),!1}finally{v.current=null,_.current&&y(null)}},[r]),j=w.useCallback(async()=>{if(l!=null&&l!==(e.name??"")){if(!await k({name:l},"save the name","name"))return;_.current&&c(null)}n()},[l,e.name,k,n]),E=async()=>{if(!e.fp)return;const M=await hi(e.fp);if(_.current){if(!M){f("Could not copy it — select the fingerprint and copy it by hand.");return}h(!0),window.setTimeout(()=>{_.current&&h(!1)},1600)}},C=new Set(b.current??e.shared??[]),R=e.autoAsk!==!1,I=e.autoAccept!==!1,O=e.pairingMode==="invite",H=M=>{const Z=S(M);return{...Z,disabled:Z.disabled||O}},q=e.shareActive!==!1,$=e.tailscale??null,V=!!($!=null&&$.on),ne=($==null?void 0:$.ask)!==!1,ee=($==null?void 0:$.accept)!==!1;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:s,className:"modal lan-modal",onClick:M=>M.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[u&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:u}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>f(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Name"}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("span",{className:"ap-lan-label",children:"appear as"}),o.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:l??e.name??"",placeholder:"this machine",onChange:M=>c(M.target.value),onKeyDown:M=>{M.key!=="Enter"||l==null||(k({name:l},"save the name","name"),c(null))}}),l!=null&&l!==(e.name??"")&&o.jsx("button",{type:"button",className:"ap-manage-btn",...S("name"),onClick:()=>{k({name:l},"save the name","name"),c(null)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?o.jsxs("span",{className:"lan-fp",children:[o.jsx("code",{className:"ap-lan-code",children:e.fp}),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void E(),"aria-label":p?"Fingerprint copied":"Copy this deck's fingerprint",children:p?"copied":"copy"})]}):o.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Share these accounts"}),o.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&o.jsx("span",{className:"ap-lan-empty",children:"No Claude accounts on this deck yet — add one with + at the top of this panel."}),t.map(M=>o.jsxs("label",{className:"ap-lan-pick",title:M.alive?"Offer this account to the decks you have paired with, so one whose copy has died can heal from yours. Unticking stops it being offered from now on; it does not take back a copy somebody already has.":"This deck cannot use this login, so it has nothing to offer — a deck that can will heal it",children:[o.jsx("input",{type:"checkbox",checked:C.has(M.key),onChange:Z=>{const K=Hz(b.current,e.shared??[],M.key,Z.target.checked);b.current=K,k({shared:K},Z.target.checked?"share that account":"stop sharing that account").then(D=>{b.current===K&&(b.current=XS(K,e.shared??[],{ok:D}))})}}),o.jsx("span",{className:"ap-lan-pick-name",children:M.email}),!M.alive&&o.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},M.key))]}),t.length>0&&o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":q,"aria-label":"Show paired decks which of these this deck is using",...S("current"),onClick:()=>void k({shareActive:!q},q?"stop showing which account this deck is using":"show which account this deck is using","current"),title:q?"Stop telling paired decks which account this one is on. They read “current account hidden” instead.":"Tell paired decks which of the ticked accounts this one is on. An unticked account is never named.",children:o.jsx("span",{className:"switch-knob"})})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",id:"lan-pairing-h",children:"Pairing"}),o.jsx("div",{className:"lan-switches lan-switches-lead",role:"group","aria-labelledby":"lan-pairing-h",children:o.jsxs("div",{className:"lan-switch",children:[o.jsxs("span",{className:"lan-switch-what",children:["Pair new decks only by invite",O&&o.jsx("span",{id:"lan-invite-only-detail",className:"lan-switch-detail",children:"A new deck needs an invite from + in the panel. Paired decks stay paired."})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":O,"aria-label":"Pair new decks only by invite","aria-describedby":O?"lan-invite-only-detail":void 0,...S("mode"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({pairingMode:O?"automatic":"invite"},O?"let decks pair on their own again":"pair new decks only by invite","mode"),title:O?"Let decks on this network pair as the two switches below say again.":"Only a deck you send an invite to can pair with this one. Nearby decks can't ask, and requests waiting now are turned away.",children:o.jsx("span",{className:"switch-knob"})})]})}),o.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-auto-h",children:[o.jsxs("p",{className:"lan-sub",id:"lan-auto-h",children:["Automatic pairing",O&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches","data-paused":O||void 0,children:[o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":R,"aria-label":"Ask every deck this one finds",...H("ask"),onClick:()=>void k({autoAsk:!R},R?"stop asking automatically":"ask every deck this one finds","ask"),title:O?kh:R?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck heard on this network. Somebody over there still has to say yes.",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":I,"aria-label":"Say yes to every deck that asks","data-tone":"warn",...H("accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({autoAccept:!I},I?"stop accepting automatically":"accept every deck that asks","accept"),title:O?kh:I?"Stop saying yes for you. A deck that asks waits in the panel again.":"Say yes for you. Every deck on this network that asks is paired without anybody being asked here.",children:o.jsx("span",{className:"switch-knob"})})]})]})]})]}),($==null?void 0:$.found)&&o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Tailscale"}),o.jsxs("div",{className:"lan-switches",children:[o.jsxs("div",{className:"lan-switch",children:[o.jsxs("span",{className:"lan-switch-what",children:["Look for my devices",o.jsx("span",{id:"lan-ts-detail",className:"lan-switch-detail",children:Lz($)})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":V,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",...S("tailscale"),onClick:()=>void k({tailscale:!V},V?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:V?"Stop. Nothing is looked for or answered over the tailnet; decks already paired stay paired.":"Find the decks on your other machines on Tailscale, wherever they are. Only machines signed in to your Tailscale account are asked.",children:o.jsx("span",{className:"switch-knob"})})]}),V&&o.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-ts-auto-h",children:[o.jsxs("p",{className:"lan-sub",id:"lan-ts-auto-h",children:["Automatic pairing with my devices",O&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches",children:[o.jsxs("div",{className:"lan-switch","data-paused":O||void 0,children:[o.jsx("span",{className:"lan-switch-what",children:"Ask each device it finds"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ne,"aria-label":"Ask each of my devices it finds over Tailscale",...H("tailscale-ask"),onClick:()=>void k({tailscaleAsk:!ne},ne?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:O?kh:ne?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck found on your devices over Tailscale.",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"lan-switch","data-paused":O||void 0,children:[o.jsx("span",{className:"lan-switch-what",children:"Say yes to each device that asks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ee,"aria-label":"Say yes to my devices when they ask over Tailscale","data-tone":"warn",...H("tailscale-accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({tailscaleAccept:!ee},ee?"stop accepting your devices automatically":"accept your devices automatically","tailscale-accept"),title:O?kh:ee?"Stop saying yes for you. A device that asks waits in the panel again.":"Say yes for you when a deck on one of your own devices asks. Anybody else on the tailnet still waits for a press.",children:o.jsx("span",{className:"switch-knob"})})]})]})]})]})]})]}),o.jsxs("footer",{className:"lan-setup-foot",children:[o.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),o.jsx("button",{type:"button",className:"btn primary",...S("name"),onClick:()=>void j(),children:"Done"})]})]})}),document.body)}function qs(e,t){if(e==null)return"not seen";const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"now";const r=Math.round(n/60);if(r<60)return`${r}m ago`;const s=Math.round(r/60);return s<48?`${s}h ago`:`${Math.round(s/24)}d ago`}const KS={keychain_unavailable:{short:"Keychain locked on the other Mac",long:`the other Mac could not export it. On that Mac: ${Lb}. The next round brings it.`}};function F0(e){return e.why?Object.hasOwn(KS,e.why)?KS[e.why]:tf(e.why):null}const Fb={"waiting for the other deck to accept this one":{text:"waiting for them to say yes",tone:"idle"},"that deck said no":{text:"it said no",tone:"bad"},"that deck pairs only by invite":{text:"it pairs only by invite",tone:"idle"},"this deck pairs only by invite":{text:"needs an invite · your setting",tone:"idle"}},Dz={ECONNREFUSED:"not listening",EHOSTUNREACH:"no route to it",ENETUNREACH:"no network here",ETIMEDOUT:"no answer",ECONNRESET:"it hung up",EHOSTDOWN:"it is down",ENOTFOUND:"name not found",EACCES:"blocked here",EPIPE:"it hung up"};function YS(e){var r;const t=Fz[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&Dz[n]||e}const Fz={"handshake timed out":"no answer","peer closed the connection":"it hung up","peer went quiet":"it stopped mid-sentence","bad reply":"it answered with nonsense","no manifest":"it would not say what it has","bad challenge":"it answered as somebody else","a different deck is answering at that address":"a different deck is at that address","that deck could not prove its own key":"it could not prove who it is","the other deck refused this one's proof":"it would not take this deck's word","the other deck refused this handshake":"it turned this deck away","that deck has this one pinned under a different key":"it knows this deck by another key"};function qb(e,t){var h;if(!e)return null;if(e.error&&((h=e.done)!=null&&h.length)){const m=qb({...e,error:void 0},t),y=` · ${qs(e.at,t)}`;return{...m,text:`${m.text.slice(0,-y.length)}, then ${YS(e.error)}${y}`,tone:"bad"}}if(e.error)return Fb[e.error]??{text:YS(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${qs(e.at,t)}`,tone:"idle"};const r=n.filter(m=>m.ok),s=r.length===1?"login":"logins",l=n.map(m=>({d:m,why:F0(m)})).filter(m=>m.why),c=[...new Set(l.map(m=>m.why.short))],u=c.length?`, ${c.join(", ")}`:"",f=l.length?l.map(m=>`${m.d.email}: ${m.why.long}`).join(" "):void 0,p=qs(e.at,t);return r.length===n.length?{text:`${r.length} ${s} arrived${u} · ${p}`,tone:l.length?"warn":"ok",...f?{hint:f}:{}}:{text:`${r.length} of ${n.length} logins arrived${u} · ${p}`,tone:"bad",...f?{hint:f}:{}}}const qz=9e4;function Bz({error:e,host:t,port:n},r,s,l=45317){if(e!=="handshake timed out")return null;const c=(t??"").trim();if(!c)return null;const u=r.filter(p=>p.addr===c&&p.port&&p.at>0&&s-p.at<qz);if(!u.length)return null;const f=[...new Set(u.map(p=>p.port))];if(n!=null&&!f.includes(n)){const p=f.length===1?`port ${f[0]}`:`ports ${f.join(" and ")}`;return`A deck at ${c} is announcing itself on ${p}, not on ${n}. This deck already hears it and dials it there, so this typed row has nothing to reach.`}return`That machine is running the deck — its beacon arrives here every half minute — and what this deck sends back never gets there. That is a firewall on ${c}, not a network fault. Whoever uses it can allow two ports: UDP ${l} and TCP ${n??f[0]}.`}const q0=5e3,VM=6e4,Mu=400;function zz(e){const t=(e??"").trim(),n=t.lastIndexOf(":");if(n<=0||n===t.length-1)return null;const r=t.slice(0,n).trim(),s=Number(t.slice(n+1).trim());return!r||!Number.isInteger(s)||s<1||s>65535||r.includes(":")&&!(r.startsWith("[")&&r.endsWith("]"))?null:{addr:r,port:s}}function un(e,t){return t==null?`Could not ${e} — the deck did not answer.`:t.reason?`Could not ${e} — the deck refused it (${t.reason}).`:`Could not ${e}.`}function Uz(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function Hz(e,t,n,r){const s=new Set(e??t);return r?s.add(n):s.delete(n),[...s]}function XS(e,t,n){return e==null||n!=null&&!n.ok||Uz(e,t)?null:e}function Wz(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function GM(e,t){var n,r;return(n=e.last)!=null&&n.error&&!Fb[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<rf||e.lastSeen!=null&&t-e.lastSeen<rf)}const rf=95e3,KM=160,Vz=6,YM=140;function Gz(e,t){const n=[],r=[];for(const s of e??[])(GM(s,t)?n:r).push(s);return{online:n,offline:r}}function Kz(e){var t;return(t=e.tailscale)!=null&&t.exitNode?"Tailscale sends this machine's local network through an exit node, so decks on this network cannot find this one. Turn on Allow local network access in Tailscale's exit node menu to bring them back.":"This machine sends its local network through a VPN, so decks on this network cannot find this one. Allowing local network access in the VPN brings them back."}function Yz(e,t){if(!e)return{text:"checking…",tone:"idle"};if(!e.enabled)return{text:"",tone:"idle"};if(e.stalled)return{text:`could not start — ${e.stalled}`,tone:"bad"};if(!e.running)return{text:"starting…",tone:"wait"};const n=(e.pending??[]).length;if(n)return{text:n===1?"1 deck is waiting for your answer":`${n} decks are waiting for your answer`,tone:"wait"};const r=(e.peers??[]).filter(v=>v.paired!==!1||v.met);if(!r.length)return{text:"no deck paired yet",tone:"idle"};const s=r.filter(v=>v.waiting),l=r.filter(v=>!v.waiting),c=s.filter(v=>{var S;return!((S=v.last)!=null&&S.error)&&v.lastSeen!=null&&t-v.lastSeen<rf}),{online:u,offline:f}=Gz(l,t),p=[...f,...s.filter(v=>!c.includes(v))],h=u.length+c.length,m=u.filter(v=>{var S;return((S=v.last)==null?void 0:S.error)==="waiting for the other deck to accept this one"});if(h&&m.length===h)return{text:h===1?"1 deck found · waiting for them to accept":`${h} decks found · waiting for them to accept`,tone:"wait"};if(!h)return{text:p.length===1?"this deck cannot reach the one it is paired with":`this deck cannot reach any of its ${p.length} decks`,tone:"bad"};const y=h===1?"1 deck ready":`${h} decks ready`;return{text:p.length?`${y} · ${p.length} away`:y,tone:"ok"}}function Xz(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const r=qs(e,t);return r==="now"?"checked just now":`checked ${r}`}function Bb(e,t){const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"just now";const r=Math.round(n/60);return r<60?`${r}m ago`:`${Math.round(r/60)}h ago`}function Zz(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<rf;return{text:n?"online · one-way, it calls in":`one-way · last online ${qs(e,t)}`,here:n}}function ZS(e,t,n){return t?"online":e.lastSeen!=null?`last online ${qs(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function Qz(e,t){var y,v,S,b,_;if(!e)return[];const n=[],r=new Set,s=(k,j)=>k.name.localeCompare(j.name,void 0,{numeric:!0}),l=e.aliases??{},c=(k,j)=>{const E=k?l[k]:void 0;return E&&E!==j?{name:E,self:j}:{name:j}};for(const k of e.pending??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);n.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"asks",state:`wants to pair · ${Bb(k.at,t)}`,tone:"wait",here:!0,hint:`${j.name} at ${k.addr}${k.via==="tailscale"?", over Tailscale,":""} is waiting for an answer.`,...k.via==="tailscale"?{via:"tailscale"}:{}})}const u=[],f=[];for(const k of e.peers??[]){const j=k.peerFp??k.fp;if(!j||r.has(j))continue;r.add(j);const E=qb(k.last,t),C=GM(k,t),R=k.addr?`${k.addr}:${k.port}`:"";if(!k.paired&&k.manual&&!k.met){f.push({fp:R,name:R||k.name||j,addr:k.addr??"",kind:"dialling",state:E?E.text.replace(/ · .*$/,""):"trying…",tone:E?E.tone:"idle",here:!1,hint:(y=k.last)!=null&&y.error?`Nothing has answered at ${R} yet — ${k.last.error}.`:`Dialling ${R} until something answers.`,...k.via==="tailscale"?{via:"tailscale"}:{}});continue}const I=k.waiting?Zz(k.lastSeen,t):null,O=I?I.here:C,H=!I&&E?O?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${ZS(k,O,t)}`:I?I.text:ZS(k,O,t),q=(v=k.last)!=null&&v.error?Fb[k.last.error]:null,$=!I&&O&&!((S=k.last)!=null&&S.error)&&!(((b=k.last)==null?void 0:b.done)??[]).length,V=k.manual&&!k.met?{name:R}:c(j,k.name||j);u.push({fp:j,name:V.name,...V.self?{self:V.self}:{},addr:k.addr??"",kind:"paired",state:H,quiet:$,tone:q?q.tone==="bad"?"bad":"wait":E?E.tone:O?"ok":"idle",here:I?I.here:C,...k.via==="tailscale"?{via:"tailscale"}:{},hint:I?`${V.name} calls this deck, and this deck has no address to call back on — so it can repair its logins from here, and this deck cannot repair from it. ${k.lastSeen==null?"It has not called since this deck started.":`It last called ${qs(k.lastSeen,t)}.`} Add its address with the + at the top of this section to reach it either way.`:`${V.name}${R?` at ${R}`:""}${(_=k.last)!=null&&_.error?` — ${k.last.error}`:""}${E!=null&&E.hint?` — ${E.hint}`:""}`})}n.push(...Jz(u).sort(s),...f.sort(s));const p=[];for(const k of e.strangers??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);p.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"nearby",state:e.pairingMode==="invite"?"needs an invite":"not paired yet",tone:"idle",here:!0,hint:k.via==="tailscale"?`${j.name} at ${k.addr} is on your tailnet and nothing is shared with it.`:`${j.name} at ${k.addr} is on this network and nothing is shared with it.`,...k.via==="tailscale"?{via:"tailscale"}:{}})}n.push(...p.sort(s));const h=[];for(const k of e.declined??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);h.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${j.name} asked and was turned away. It is not asking any more.`})}n.push(...h.sort(s));const m=new Map;for(const k of n)m.set(k.name,(m.get(k.name)??0)+1);for(const k of n)(m.get(k.name)??0)<2||!k.addr||(k.state=k.quiet||!k.state?k.addr:`${k.addr} · ${k.state}`,k.quiet=!1);return n}function Jz(e){const t=new Map;for(const r of e){const s=t.get(r.name);s?s.push(r):t.set(r.name,[r])}const n=[];for(const r of t.values()){const s=[...new Set(r.filter(l=>l.addr).map(l=>l.addr))];if(s.length>1){for(const l of s)n.push(QS(r.filter(c=>c.addr===l)));n.push(...r.filter(l=>!l.addr))}else n.push(QS(r))}return n}function QS(e){const[t,...n]=[...e].sort((r,s)=>Number(s.here)-Number(r.here)||+!!s.addr-+!!r.addr);return n.length?{...t,twins:n}:t}function JS(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function ej(e,t){if(!e)return{};switch(t.kind){case"paired":return{peer:(e.peers??[]).find(n=>(n.peerFp??n.fp)===t.fp)??null};case"dialling":return{peer:(e.peers??[]).find(n=>n.manual&&!n.met&&`${n.addr}:${n.port}`===t.fp)??null};case"nearby":return{stranger:(e.strangers??[]).find(n=>n.fp===t.fp)??null};case"declined":return{stranger:(e.declined??[]).find(n=>n.fp===t.fp)??null};case"asks":return{stranger:(e.pending??[]).find(n=>n.fp===t.fp)??null}}}function eU(e,t){const n=/^(\d+)\.(\d+)\.(\d+)/.exec(e??""),r=/^(\d+)\.(\d+)\.(\d+)/.exec(t??"");if(!n||!r)return null;for(let s=1;s<=3;s++){const l=Number(n[s])-Number(r[s]);if(l)return Math.sign(l)}return 0}function tU(e,t,n){const r=t?t.alive?t.shareable===!1?"cannot share here":"works here":"expired here":"not on this deck";if(e.alive&&e.shareable===!1)return{there:"cannot share there",here:r,note:null,tone:"idle"};if(!e.alive){const s=t&&!t.alive?"neither copy works — sign in again here":null;return{there:"broken there",here:r,note:s,tone:s?"bad":"idle"}}return t?t.alive?{there:"works there",here:r,note:null,tone:t.shareable===!1?"idle":"ok"}:n?{there:"works there",here:r,note:"repairs next round",tone:"wait"}:{there:"works there",here:r,note:"share it to repair",tone:"bad"}:{there:"works there",here:r,note:"arrives next round",tone:"wait"}}function nU(e,t,n,r=null){var f;const s=new Map;for(const p of t)(f=s.get(p.key))!=null&&f.alive||s.set(p.key,p);const l=new Set(n),c=[],u=new Set;for(const p of e??[]){if(u.has(p.key))continue;u.add(p.key);const h=s.get(p.key)??null,m=l.has(p.key),y=tU(p,h,m),v=h?h.alive?h.shareable===!1?"unavailable":"works":"expired":"missing",S=!p.alive&&h&&!h.alive?y.note:[v==="works"?null:y.here,p.alive&&p.shareable!==!1?null:y.there,y.note].filter(Boolean).join(" · ")||null;c.push({key:p.key,email:p.email,here:v,there:p.alive?p.shareable===!1?"unavailable":"works":"broken",in:!p.alive||p.shareable===!1?"cut":y.tone==="wait"?"wait":y.tone==="bad"?"blocked":"live",out:m&&h?h.alive&&h.shareable!==!1?"live":"cut":null,caption:S,tone:y.tone,usedThere:r===p.key})}for(const p of n){const h=s.get(p);!h||u.has(p)||(u.add(p),c.push({key:p,email:h.email,here:h.alive?h.shareable===!1?"unavailable":"works":"expired",there:"unknown",in:null,out:h.alive&&h.shareable!==!1?"live":"cut",caption:h.alive?h.shareable===!1?"cannot share here":null:"expired here",tone:h.alive?h.shareable===!1?"idle":"ok":"bad",usedThere:!1}))}return c}async function Nl(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function rU({anchorId:e,id:t,rows:n,onHold:r,onLet:s}){const l=w.useRef(null),c=n.filter(y=>y.kind==="paired"),u=c.filter(y=>y.here),f=u.slice(0,Vz),p=c.length-u.length,h=u.length>f.length?`and ${u.length-f.length} more`:p>0?`${p} not on right now`:null,m=w.useCallback(()=>{const y=l.current,v=document.getElementById(e);if(!y||!v)return;const S=$b(v.getBoundingClientRect(),{width:y.offsetWidth,height:y.offsetHeight},{width:window.innerWidth,height:window.innerHeight});y.style.top=`${S.top}px`,y.style.left=`${S.left}px`,y.style.maxHeight=S.maxHeight==null?"":`${S.maxHeight}px`,y.dataset.side=S.side},[e]);return w.useLayoutEffect(()=>{m()}),w.useEffect(()=>(window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}),[m]),Mn.createPortal(o.jsxs("div",{ref:l,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[o.jsx("p",{className:"ap-peek-title",children:u.length?"On the network now":"Nobody on the network"}),f.length>0&&o.jsx("div",{className:"ap-peek-list",children:f.map(y=>o.jsxs("span",{className:"ap-peek-who",children:[o.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),o.jsxs("span",{children:[y.name,y.via==="tailscale"&&o.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]})]},`${y.kind}:${y.fp}`))}),h&&o.jsx("p",{className:"ap-peek-rest",children:h})]}),document.body)}function sU(e,t){var l;if(!e)return{text:"checking…",tone:"idle",live:!1};if(!e.enabled)return{text:"Off",tone:"idle",live:!1};if(e.stalled)return{text:"could not start",tone:"bad",live:!1};if(!e.running)return{text:"starting…",tone:"wait",live:!1};const n=t.filter(c=>c.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};if((l=e.reach)!=null&&l.blocked)return{text:"nothing can get in",tone:"bad",live:!1};const r=t.filter(c=>c.kind==="paired");if(!r.length)return{text:"On · none paired yet",tone:"idle",live:!1};const s=r.filter(c=>c.here).length;return s?s===r.length?{text:`${s} online`,tone:"ok",live:!0}:{text:`${s} of ${r.length} online`,tone:"ok",live:!0}:{text:`none of ${r.length} online`,tone:"idle",live:!1}}function aU({accounts:e,onChanged:t,view:n,onOpen:r,onBack:s,closeButton:l}){const[c,u]=w.useState(null),[f,p]=w.useState([]),[h,m]=w.useState(null),[y,v]=w.useState(!1),[S,b]=w.useState(null),_=w.useRef(0),[k,j]=w.useState(!1),[E,C]=w.useState(!1),[R,I]=w.useState(!1),O=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(O.current),[]);const[H,q]=w.useState(!1),[$,V]=w.useState(null),ne=w.useRef(null),ee=w.useCallback(ce=>Tf(ne.current)?(ne.current=ce,m(ce),!0):!1,[]),M=w.useCallback(()=>{ne.current=null,P.current&&m(null)},[]),Z=ce=>{const pe=ao(h,ce);return{disabled:pe.disabled,"aria-busy":pe.busy}},[K,D]=w.useState(()=>Date.now()),P=w.useRef(!0),B=w.useRef(q0),W=w.useCallback(async()=>{var ce,pe;try{const[Ae,fe]=await Promise.all([fetch("/api/lan").then(Se=>Se.json()),fetch("/api/prefs").then(Se=>Se.json())]);if(!P.current)return;Ae!=null&&Ae.ok&&u(Ae),fe!=null&&fe.ok&&p(Array.isArray((pe=(ce=fe.prefs)==null?void 0:ce.lan)==null?void 0:pe.manual)?fe.prefs.lan.manual:[]),B.current=(Ae==null?void 0:Ae.enabled)===!0?q0:VM}catch{}},[]);w.useEffect(()=>{P.current=!0;let ce=0;const pe=async()=>{D(Date.now()),await W(),P.current&&(ce=window.setTimeout(pe,B.current))};return pe(),()=>{P.current=!1,window.clearTimeout(ce)}},[W]);const F=w.useCallback(async()=>{const ce=(c==null?void 0:c.enabled)===!0;if(ee("switch"))try{const pe=await Nl("/api/prefs",{lan:{enabled:!ce}});if(!P.current)return;pe!=null&&pe.ok?(V(null),ce||v(!0)):V(un(ce?"turn this off":"turn this on",pe)),await W()}catch{P.current&&V(un(ce?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,W,ee,M]),G=w.useCallback(async(ce,pe,Ae)=>{if(!ee(`${ce}:${pe}`))return null;let fe=null;try{const Se=await Nl("/api/lan/peer",{action:ce,fp:pe});if(!P.current)return null;Se!=null&&Se.ok?(u(Se),V(null)):(fe=un(Ae,Se),V(fe)),await W()}catch{fe=un(Ae,null),P.current&&V(fe)}finally{M()}return fe},[W,ee,M]),re=w.useCallback(async ce=>{if(!ee(`drop:${ce}`))return null;let pe=null;try{const Ae=await Nl("/api/prefs",{lan:{manual:f.filter(fe=>fe!==ce)}});if(!P.current)return null;Ae!=null&&Ae.ok?(V(null),t()):(pe=un("stop dialling that address",Ae),V(pe)),await W()}catch{pe=un("stop dialling that address",null),P.current&&V(pe)}finally{M()}return pe},[f,W,t,ee,M]),[U,Y]=w.useState(null),z=w.useCallback(async(ce,pe)=>{if(!ee(`alias:${ce}`))return"Something else is still being saved. Try again in a moment.";try{const Ae=await Nl("/api/lan/peer",{action:"alias",fp:ce,name:pe});return P.current?Ae!=null&&Ae.ok?(u(Ae),null):un("rename that deck",Ae):null}catch{return un("rename that deck",null)}finally{M()}},[ee,M]),ie=w.useCallback(async ce=>{if(!ee(`check:${ce}`))return null;try{const pe=await Nl("/api/lan/sync",{fp:ce});return P.current?pe!=null&&pe.ok?(u(pe),t(),null):(pe==null?void 0:pe.reason)==="no_address"?"There is no address here to call it on. It calls this deck, and it is up to date each time it does.":un("check that deck",pe):null}catch{return un("check that deck",null)}finally{M()}},[ee,M,t]),le=w.useCallback(async()=>{if(ee("check"))try{const ce=await Nl("/api/lan/sync",{});if(!P.current)return;ce!=null&&ce.ok?(u(ce),V(null)):V(un("check the other decks",ce)),t()}catch{P.current&&V(un("check the other decks",null))}finally{M()}},[ee,M,t]),ge=(c==null?void 0:c.enabled)===!0,Ne=Qz((c==null?void 0:c.pairingMode)==="invite"&&c?{...c,pending:[]}:c,K),Ie=U?Ne.find(ce=>{var pe;return ce.fp===U||((pe=ce.twins)==null?void 0:pe.some(Ae=>Ae.fp===U))})??null:null;w.useEffect(()=>{U&&c&&!Ie&&Y(null)},[U,c,Ie]);const Ge=Ne.filter(ce=>ce.kind==="asks"),Pe=Ne.filter(ce=>ce.kind!=="asks"),Be=Pe.filter(ce=>ce.here),Te=Pe.filter(ce=>!ce.here),st=Te.filter(ce=>ce.tone==="bad").length,de=H||Be.length===0,ue=Yz(c,K),se=Pe.filter(ce=>ce.kind==="paired").length,be=sU(c,Ne),Le=o.jsxs(o.Fragment,{children:[k&&c&&o.jsx(Ez,{status:c,manual:f,startWith:k==="invite"?"invite":void 0,onClose:()=>j(!1),onChanged:()=>{W(),t()}}),E&&o.jsx(UM,{title:"How Local network works",steps:bz,finish:ge?void 0:{label:"Turn it on",act:()=>{C(!1),F()}},onClose:()=>C(!1)}),y&&c&&o.jsx(Pz,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>v(!1),onChanged:()=>{W(),t()}}),Ie&&c&&o.jsx(Oz,{row:Ie,source:ej(c,Ie),status:c,accounts:e,now:K,busy:h,onClose:()=>Y(null),onRename:ce=>z(Ie.fp,ce),onCheck:()=>ie(Ie.fp),onVerb:()=>{switch(Ie.kind){case"paired":return G("unpair",Ie.fp,"unpair that deck");case"nearby":return G("accept",Ie.fp,"reach that deck");case"declined":return G("allow",Ie.fp,"let that deck ask again");case"dialling":return re(Ie.fp);default:return Promise.resolve(null)}},onSettings:()=>{Y(null),v(!0)},onInvite:()=>{Y(null),j("invite")},twins:(Ie.twins??[]).map(ce=>({row:ce,peer:ej(c,ce).peer??null})),onUnpair:ce=>G("unpair",ce,"unpair that deck")})]});if(!n){const ce=Se=>{window.clearTimeout(O.current),O.current=window.setTimeout(()=>I(!0),Se)},pe=()=>{window.clearTimeout(O.current),O.current=window.setTimeout(()=>I(!1),YM)},Ae=()=>window.clearTimeout(O.current),fe=()=>{window.clearTimeout(O.current),I(!1)};return o.jsxs("div",{className:"ap-foot",children:[o.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{fe(),r()},"aria-describedby":R?"ap-lan-peek":void 0,onPointerEnter:Se=>{Se.pointerType==="mouse"&&ce(KM)},onPointerLeave:pe,onFocus:Se=>{Se.target.matches(":focus-visible")&&ce(0)},onBlur:pe,children:[o.jsxs("svg",{className:"ap-nav-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),o.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),o.jsxs("span",{className:"ap-nav-text",children:[o.jsx("span",{className:"ap-nav-name",children:"Local network"}),o.jsxs("span",{className:"ap-nav-state","data-tone":be.tone,children:[be.live&&o.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),be.text]})]}),o.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),R&&o.jsx(rU,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:Ne,onHold:Ae,onLet:pe}),o.jsx("p",{className:"vis-hidden",role:"status",children:ue.tone==="ok"?"":ue.text}),Le]})}return o.jsxs("div",{className:"ap-lan-view",children:[o.jsxs("div",{className:"ap-header",children:[o.jsx("button",{type:"button",id:"ap-lan-back",className:"glyph-btn ap-back",onClick:s,"aria-label":"Back to Claude accounts",title:"Back to Claude accounts",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),o.jsx("h2",{id:"ap-lan-title",children:"Local network"}),o.jsxs("div",{className:"ap-header-right",children:[ge&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>j("add"),"aria-label":"Add a deck",title:(c==null?void 0:c.pairingMode)==="invite"?"Send an invite, or use one you were sent. This deck pairs only by invite.":"Reach a deck that has not turned up on its own — by address, or with an invite",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M6.1 7.9a2.6 2.6 0 0 0 3.7 0l1.9-1.9a2.6 2.6 0 0 0-3.7-3.7l-.9.9"}),o.jsx("path",{d:"M7.9 6.1a2.6 2.6 0 0 0-3.7 0L2.3 8a2.6 2.6 0 0 0 3.7 3.7l.9-.9"})]})}),ge&&se>0&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...Z("check"),onClick:()=>void le(),"aria-label":h==="check"?"Checking every paired deck":"Check every paired deck now",title:"Ask every paired deck now for anything this deck's expired logins need, instead of waiting for the next round",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),o.jsx("path",{d:"M4.6 4.6a3.4 3.4 0 0 0 0 4.8M9.4 4.6a3.4 3.4 0 0 1 0 4.8"}),o.jsx("path",{d:"M2.6 2.6a6.2 6.2 0 0 0 0 8.8M11.4 2.6a6.2 6.2 0 0 1 0 8.8"})]})}),ge&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...Z("setup"),onClick:()=>v(!0),"aria-label":"This deck's name and shared logins",title:"This deck's name on the network, and which of its logins it offers",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),o.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),o.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),l]})]}),o.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:o.jsxs("div",{className:"ap-lan",children:[o.jsxs("div",{className:"ap-policy",children:[o.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ge,"aria-label":"Sync with paired decks",...Z("switch"),onClick:()=>void F(),title:ge?"Stop talking to other decks. Nothing is shared while this is off.":"Let the decks you pair with repair this one's expired logins",children:o.jsx("span",{className:"switch-knob"})})]}),ge&&o.jsx(WM,{reach:c==null?void 0:c.reach,where:"panel"}),ge&&(c==null?void 0:c.deaf)&&o.jsx("p",{className:"ap-lan-fine",children:c.deaf}),ge&&(c==null?void 0:c.lanTunneled)&&o.jsx("p",{className:"ap-lan-fine",children:Kz(c)}),!ge&&o.jsxs("button",{type:"button",className:"ap-lan-intro",onClick:()=>C(!0),title:"Four pictures: what this does, and what to do on each machine",children:[o.jsx(kz,{}),o.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),o.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),o.jsx("p",{className:`ap-lan-status ${ue.tone}`,role:"status",children:ue.tone==="ok"?"":ue.text}),$&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:$}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>V(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ge&&o.jsxs(o.Fragment,{children:[Ge.length>0&&o.jsx("div",{className:"ap-lan-asks",role:"alert",children:Ge.map(ce=>o.jsxs("div",{className:"ap-lan-ask",children:[o.jsxs("span",{className:"ap-lan-ask-what",children:[o.jsx("strong",{className:"ap-lan-peer-name",children:ce.name})," at ",o.jsx("code",{className:"ap-lan-code",children:ce.addr})," wants to pair"]}),o.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",o.jsx("code",{className:"ap-lan-code",children:ce.fp})]}),o.jsxs("span",{className:"ap-lan-ask-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`accept:${ce.fp}`),onClick:()=>void G("accept",ce.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${ce.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`dismiss:${ce.fp}`),onClick:()=>void G("dismiss",ce.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},ce.fp))}),(de?[...Be,...Te]:Be).length>0&&o.jsx("ul",{className:"ap-lan-here",children:(de?[...Be,...Te]:Be).map((ce,pe)=>o.jsxs("li",{className:"ap-lan-who","data-tone":ce.tone,children:[o.jsx("i",{className:ce.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[ce.name,ce.via==="tailscale"&&o.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]}),o.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${pe}`,onClick:()=>Y(ce.fp),children:o.jsxs("span",{className:"vis-hidden",children:[ce.name,ce.via==="tailscale"?", over Tailscale":"",", details"]})}),o.jsx("span",{id:`lan-who-state-${pe}`,className:ce.quiet?"vis-hidden":"ap-lan-who-when",children:ce.state}),ce.kind==="nearby"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`accept:${ce.fp}`),onClick:()=>void G("accept",ce.fp,"reach that deck"),"aria-label":`Ask ${ce.name} to pair`,title:`Send ${ce.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${ce.fp}.`,children:"ask"}),(ce.kind==="nearby"||ce.kind==="declined")&&(c==null?void 0:c.pairingMode)==="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do","aria-haspopup":"dialog",onClick:()=>j("invite"),"aria-label":`Invite ${ce.name} to pair`,title:`This deck pairs only by invite. Make one and send it to whoever is at ${ce.name}.`,children:"invite"}),ce.kind==="paired"&&o.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${S===ce.fp?" armed":""}`,...Z(`unpair:${ce.fp}`),onClick:()=>{const Ae=Date.now(),fe=Cu({armedFor:S,target:ce.fp,armedAt:_.current,now:Ae,gapMs:Mu});if(fe==="arm"){b(ce.fp),_.current=Ae,window.setTimeout(()=>b(Se=>Se===ce.fp?null:Se),4e3);return}fe!=="ignore"&&(b(null),G("unpair",ce.fp,"unpair that deck"))},"aria-label":S===ce.fp?`Confirm unpairing ${ce.name}`:`Unpair ${ce.name}`,title:S===ce.fp?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:S===ce.fp?"confirm":"unpair"}),ce.kind==="dialling"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`drop:${ce.fp}`),onClick:()=>void re(ce.fp),"aria-label":`Stop dialling ${ce.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),ce.kind==="declined"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`allow:${ce.fp}`),onClick:()=>void G("allow",ce.fp,"let that deck ask again"),"aria-label":`Let ${ce.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${ce.kind}:${ce.fp}`))}),(Be.length>0&&Te.length>0||ge&&se>0)&&o.jsxs("div",{className:"ap-lan-tail",children:[Be.length>0&&Te.length>0&&o.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":H,onClick:()=>q(ce=>!ce),title:H?"Show only the decks that are on":`Show the ${Te.length} deck${Te.length===1?"":"s"} that are not responding right now`,children:[o.jsx("span",{className:`ap-lan-chev${H?" open":""}`,"aria-hidden":!0,children:"›"}),H?"fewer":`${Te.length} more`,!H&&st>0&&o.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",st," not responding"]})]}),ge&&se>0&&o.jsx("span",{className:"ap-lan-checked",children:Xz(c==null?void 0:c.checkedAt,K,h==="check")})]}),Pe.length===0&&Ge.length===0&&!(c!=null&&c.stalled)&&!(c!=null&&c.deaf)&&!(c!=null&&c.lanTunneled)&&o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"ap-lan-fine",children:"No other deck yet. Decks on one network usually find each other on their own; when that has not happened, the link at the top of this view reaches one by address or by invite."}),o.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>C(!0),children:"How it works"})]})]})]})}),Le]})}function oU({anchorId:e,id:t,peers:n,onHold:r,onLet:s}){const l=w.useRef(null),{title:c,shown:u,rest:f}=iz(n),p=w.useCallback(()=>{const h=l.current,m=document.getElementById(e);if(!h||!m)return;const y=$b(m.getBoundingClientRect(),{width:h.offsetWidth,height:h.offsetHeight},{width:window.innerWidth,height:window.innerHeight});h.style.top=`${y.top}px`,h.style.left=`${y.left}px`,h.style.maxHeight=y.maxHeight==null?"":`${y.maxHeight}px`,h.dataset.side=y.side},[e]);return w.useLayoutEffect(()=>{p()}),w.useEffect(()=>(window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}),[p]),Mn.createPortal(o.jsxs("div",{ref:l,id:t,className:"ap-peek ap-fold-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[o.jsx("p",{className:"ap-peek-title",children:c}),o.jsx("div",{className:"ap-peek-list",children:u.map(h=>o.jsxs("span",{className:"ap-peek-who ap-fold-who",children:[o.jsx("span",{className:"ap-fold-name",children:h.name}),o.jsx("span",{className:"ap-fold-state","data-tone":h.ready?"ok":h.warn?"warn":"idle",children:h.ready?h.headroom==null?"not read yet":`${h.headroom}% free`:h.why})]},h.key))}),f&&o.jsx("p",{className:"ap-peek-rest",children:f})]}),document.body)}function iU({peers:e,strained:t,armed:n,threshold:r,open:s,onToggle:l}){const[c,u]=w.useState(!1),f=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(f.current),[]),w.useEffect(()=>{s&&(window.clearTimeout(f.current),u(!1))},[s]);const p=S=>{s||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!0),S))},h=()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!1),YM)},m=()=>window.clearTimeout(f.current),y=()=>{window.clearTimeout(f.current),u(!1)},v=az(e,{strained:t&&!s,armed:n,threshold:r});return o.jsxs("div",{className:"ap-rest",children:[o.jsxs("button",{type:"button",id:"ap-rest-entry",className:"ap-nav","aria-expanded":s,"aria-controls":s?"ap-rest-panel":void 0,"aria-describedby":c?"ap-rest-peek":void 0,onClick:()=>{y(),l()},onPointerEnter:S=>{S.pointerType==="mouse"&&p(KM)},onPointerLeave:h,onFocus:S=>{S.target.matches(":focus-visible")&&p(0)},onBlur:h,children:[o.jsxs("span",{className:"ap-nav-text",children:[o.jsx("span",{className:"ap-nav-name",children:"Other accounts"}),o.jsx("span",{className:"ap-nav-state","data-tone":v.tone,children:v.text})]}),o.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),c&&o.jsx(oU,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:m,onLet:h})]})}async function lU(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const cU=1800;function uU({accounts:e,onClose:t,copyText:n}){const[r,s]=w.useState([]),[l,c]=w.useState(null),[u,f]=w.useState(!1),[p,h]=w.useState(null),[m,y]=w.useState(!1),[v,S]=w.useState(()=>Math.floor(Date.now()/1e3)),b=w.useRef(null),_=w.useRef(!1),k=pn(t,{focusRef:b});w.useEffect(()=>{if(!l)return;S(Math.floor(Date.now()/1e3));const $=window.setInterval(()=>S(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval($)},[l]);const j=KB(e),E=YB(e,r),C=E.length===e.length,R=$=>s(V=>XB(V,$)),I=w.useCallback(async()=>{const $=ZB(E);if(!Ps(_.current)||!$)return;_.current=!0,f(!0),h(null),y(!1);const V=await lU($).catch(()=>null);if(_.current=!1,f(!1),!(V!=null&&V.ok)){h(Al(V,"the share could not be made"));return}c({blob:V.blob,expiresAt:V.expiresAt,shared:V.shared??[],failed:V.failed??[]})},[e,E]),O=l?zM(l.expiresAt,v):null,H=(O==null?void 0:O.tone)==="gone",q=(l==null?void 0:l.shared.length)??0;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:o.jsxs("div",{ref:k,className:"modal sa-modal",onClick:$=>$.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Share accounts with another deck",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("h3",{children:"Share accounts"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsx("section",{className:"modal-body sa-body",children:l?o.jsxs("div",{className:"sa-step",children:[o.jsx("h4",{children:H?"This share has expired":q===1?"1 account, ready to paste":`${q} accounts, ready to paste`}),o.jsx("code",{className:`ap-share-blob${H?" sa-dead":""}`,children:l.blob}),o.jsxs("div",{className:"ap-share-foot",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",ref:b,onClick:async()=>{if(H){c(null),I();return}await n(l.blob)&&(y(!0),window.setTimeout(()=>y(!1),cU))},children:H?"make a new share":m?"copied":`copy ${q===1?"the share":"all "+q}`}),o.jsxs("span",{className:"ap-manage-hint",title:"This text is the sign-in for every account in it. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the logins themselves are in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign those accounts out and back in.",children:[o.jsx("span",{className:"ap-share-warn",children:q===1?"this is the password":`this is ${q} passwords`})," · ",o.jsx("span",{className:`ap-share-expiry ${O==null?void 0:O.tone}`,children:O==null?void 0:O.text})]})]}),l.failed.length>0&&o.jsxs("div",{className:"sa-failed",role:"alert",children:[o.jsx("p",{className:"sa-failed-head",children:l.failed.length===1?"One account is not in this bundle:":`${l.failed.length} accounts are not in this bundle:`}),o.jsx("ul",{className:"sa-list",children:l.failed.map($=>{var ne;const V=!!($.email&&((ne=$.detail)!=null&&ne.includes($.email)));return o.jsxs("li",{children:[!V&&o.jsx("span",{className:"sa-who",children:$.email||`account ${$.num}`}),o.jsx("span",{className:"sa-why",children:$.detail||"could not be exported"})]},`${$.num}-${$.email}`)})})]}),o.jsx("p",{className:"sa-note",children:H?o.jsx(o.Fragment,{children:"Another deck will refuse this text now. Make a new one — the same accounts are still picked."}):o.jsxs(o.Fragment,{children:["Paste it into the other deck with ",o.jsx("strong",{children:"+"})," → ",o.jsx("strong",{children:"Paste a share"}),". Accounts it already holds are left exactly as they are."]})}),o.jsxs("div",{className:"sa-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>{c(null),y(!1)},children:"Pick again"}),o.jsx("button",{type:"button",className:"btn primary",onClick:t,children:"Done"})]})]}):e.length===0?o.jsxs("div",{className:"sa-step",children:[o.jsx("h4",{children:"Nothing to share"}),o.jsxs("p",{className:"sa-note",children:["This deck is not holding any accounts right now. Sign one in with ",o.jsx("strong",{children:"+"}),", or wait — the panel is still reading the store."]}),o.jsx("div",{className:"sa-actions",children:o.jsx("button",{type:"button",className:"btn primary",ref:b,onClick:t,children:"Close"})})]}):o.jsxs("div",{className:"sa-step",children:[o.jsxs("h4",{children:["Which accounts go to the other ",dn,"?"]}),o.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:QB(E.length)}),o.jsx("ul",{className:"sa-list sa-pick",children:j.map($=>o.jsx("li",{children:o.jsxs("label",{className:"sa-row",children:[o.jsx("input",{type:"checkbox",checked:E.includes($.num),onChange:()=>R($.num)}),o.jsx("span",{className:"sa-who",children:$.label}),$.sub&&o.jsx("span",{className:"sa-sub",children:$.sub})]})},$.num))}),p&&o.jsx("p",{className:"aa-err",children:p}),o.jsxs("div",{className:"sa-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>s(C?e.map($=>$.num):[]),children:C?"Clear all":"Select all"}),o.jsx("button",{type:"button",className:"btn primary",ref:b,...Qa(u,!E.length),onClick:I,children:u?"making the share…":E.length===0?"Share":E.length===1?"Share 1 account":`Share ${E.length} accounts`})]})]})})]})}),document.body)}function dU(e,t){const n=new Set(e),r=e.length?Math.max(...e):0;return[...new Set([...e,r+1])].sort((s,l)=>s-l).map(s=>{const l=s===t?"here":n.has(s)?"swap":"free";return{slot:s,kind:l,label:l==="here"?`slot ${s}`:`slot ${s} · ${l}`}})}function hU(e,t,n){if(!(n!=null&&n.ok))return null;const r=Number.isInteger(n.to)?n.to:null;if(r==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const s=n.swapped===!0&&r!==t;return{menuFor:e.menuFor===t?r:s&&e.menuFor===r?t:e.menuFor,confirmRemove:null,shareFor:null,swapNote:s?{at:r,displaced:t}:null}}function fU(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function pU(e,t,n){var s;const r=((s=e.find(l=>l.slot===t))==null?void 0:s.kind)??"here";return r==="swap"?{label:"swap",done:"swapped",sends:!0,swaps:!0,title:`Send this account to slot ${t}. That slot is taken, so the two accounts trade places and the one standing there moves to slot ${n}.`}:r==="free"?{label:"move",done:"moved",sends:!0,swaps:!1,title:`Send this account to slot ${t}. That slot is empty, so no other account moves.`}:{label:"move",done:"here",sends:!1,swaps:!1,title:`This account already holds slot ${n}.`}}function mU(e,t){return{label:"save",done:"saved",sends:e!==t,swaps:!1,title:`Switch the active account out once it passes ${e}% of its limit.`}}function tj(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function gU(e){const t=e.filter(u=>!tj(u)),n=e.filter(u=>tj(u)),r=t.length?t:n,s=t.length?n:[],l=r.reduce((u,f)=>u&&u.pct>=f.pct?u:f,null);let c=null;for(const u of s)l&&u.pct<=l.pct||(!c||u.pct>c.pct)&&(c=u);return{shown:r,rest:s,fuller:c,peak:c??l}}const yU="\0";function sf(e){const t=typeof e.email=="string"?e.email.trim():"";if(!t)return`slot:${e.num}`;const n=typeof e.org=="string"?e.org.trim():"";return`acct:${t}${yU}${n}`}function wU(e,t){const n=sf(t);return e.includes(n)?e.filter(r=>r!==n):[...e,n]}function vU(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(sf)),r=e.filter(s=>n.has(s));return r.length===e.length?e:r}const xU=64;function bU(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}function kU(e,t){return!e||!t||t.some(n=>n.num===e.num&&n.active)?e:null}const NU=Object.freeze({text:"couldn't reach the deck server",reload:!0}),SU=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function nj(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function jU(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=Au(t.body);return{text:O0(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function rj(e,t){return t?e!=null&&e.reload&&e.text===t.text&&e.raw===t.raw?e:t:e!=null&&e.reload?null:e}const sj=15e3,_U=8e3,EU=1800,CU=3e4,Tm=[70,80,85,90,95];function Rm(e,t){return kM(t-Math.floor(e/1e3))}function TU(e,t){if(!e)return"";const n=Math.floor(e/1e3)-t;return n<=0?" · due":n<60?` · next in ${n}s`:` · next in ${Math.round(n/60)}m`}function lu(e){return e.charAt(0).toUpperCase()+e.slice(1)}function RU(e,t){const n="The deck can still see this account — its live usage is being read — but claude-swap's own stored copy of the login was rejected, so these numbers stopped updating.";if((e==null?void 0:e.state)==="running")return{text:"resuming…",hint:`${n} The deck is re-capturing it from the login you already have. No sign-in, no switch.`};if((e==null?void 0:e.state)==="failed"){const r=Math.max(1,Math.ceil((e.retryAt/1e3-t)/60)),s=e.reason?`Re-capturing it from the login you already have did not work (${e.reason}).`:"The deck re-captured it from the login you already have, and claude-swap still cannot read it.";return{text:"numbers paused",hint:`${n} ${s} It tries again in ${r}m. No sign-in, no switch.`}}return{text:"numbers paused",hint:n}}function AU(e){switch(e){case"invalid_grant":case"no_refresh_token":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fixable:!0};case"http-401":return{text:"re-login needed",hint:"Anthropic refused this account's token.",fixable:!0};case"http-429":return{text:"rate limited",hint:"Anthropic is throttling requests for this account. It clears on its own.",fixable:!1};case"transient":return{text:"temporary error",hint:"A network or server hiccup while reading usage. The next collection retries.",fixable:!1};case"timeout":return{text:"timed out",hint:"Reading this account's usage took too long. The next collection retries.",fixable:!1};case"network":return{text:"unreachable",hint:"Could not reach Anthropic to read this account's usage.",fixable:!1};default:return{text:e,hint:`claude-swap reported "${e}" for this account.`,fixable:!1}}}function MU(e){switch(e){case"no_credentials":return{text:"no stored login",hint:"claude-swap holds no credentials for this account, so there is nothing to read its usage with and nothing to switch to. A paired deck that has them sends them on its own; signing in as this account puts them there by hand.",fix:"sign in"};case"relogin_required":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fix:"sign in again"};case"keychain_unavailable":return{text:"keychain unreadable",hint:"This is about the deck, not the account: claude-swap could not open your keychain, so it cannot read any account's stored login. A deck started from a background session cannot reach the keychain at all — start it from a terminal, or let it start at login, and this clears."};case"token_expired":return{text:"token expired",hint:"The access token ran out and the refresh was deferred. The next collection retries."};case"foreign_credential":return{text:"wrong credential",hint:"The live credential belongs to a different account. Switching to this one repairs it."};case null:case void 0:return null;default:return{text:e,hint:`claude-swap reported "${e}" for this account.`}}}function Nh(e,t){if(e.staleCopy){const n=RU(e.repair??null,t);return{text:lu(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=MU(e.collector??null);if(!n)return{text:"Not collecting",hint:"claude-swap has collected nothing for this account in over half a day and has not said why. A paired deck holding a working copy of this account will replace it on its own. To do it by hand, sign in as this account from + Add.",fix:null,tone:"quiet",blocksSwitch:!1};const r=e.collector==="no_credentials"||e.collector==="relogin_required";return{text:lu(n.text),hint:n.hint,fix:n.fix?lu(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=AU(e.error);return{text:lu(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function Am(){return o.jsxs("svg",{className:"ap-warn-glyph",width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),o.jsx("path",{d:"M7 5.6v2.9"}),o.jsx("path",{d:"M7 10.3v.05"})]})}function IU(e){return e>=90?"hi":e>=70?"mid":void 0}function $U(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!Tm.includes(t)?[...Tm,t]:Tm].sort((r,s)=>r-s)}function OU({lane:e,nowSec:t,frozen:n}){const r=Math.min(100,Math.max(0,e.pct)),s=n?"var(--muted)":r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",l=e.resetAt&&!n?NM(e.resetAt,t):null;return o.jsxs("div",{className:"ap-lane",children:[o.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),o.jsx("div",{className:"ap-lane-track",children:o.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:s,opacity:r===0||n?.4:1}})}),o.jsxs("span",{className:"ap-lane-pct",style:{color:s},children:[r,"%"]}),o.jsx("span",{className:"ap-lane-reset",title:l?`${e.label} resets in ${l}`:void 0,children:l&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"vis-hidden",children:"resets in "}),l]})})]})}function LU({onClose:e,leaving:t}){var xr,$n,Hs;const[n,r]=w.useState(null),[s,l]=w.useState(null),[c,u]=w.useState(null),[f,p]=w.useState(!1),[h,m]=w.useState(null),[y,v]=w.useState(null),[S,b]=w.useState("accounts"),[_,k]=w.useState(!1),[j,E]=w.useState(null),C=w.useRef(j);C.current=j;const[R,I]=w.useState(()=>Math.floor(Date.now()/1e3)),O=w.useRef(null),[H,q]=w.useState(null),$=(H==null?void 0:H.num)??null,V=w.useRef(H);V.current=H;const[ne,ee]=w.useState(null),[M,Z]=w.useState(!1),[K,D]=w.useState(""),[P,B]=w.useState(null),W=w.useRef(0),[F,G]=w.useState(null),[re,U]=w.useState(!1),[Y,z]=w.useState(!1),[ie,le]=w.useState(null),[ge,Ne]=w.useState(null),[Ie,Ge]=w.useState(null),[Pe,Be]=w.useState(null),[Te,st]=w.useState(!1),de=w.useRef(null),ue=w.useRef(null),[se,be]=w.useState([]),[Le,ce]=w.useState(!1),pe=w.useRef(null),Ae=w.useCallback(Q=>Tf(pe.current)?(pe.current=Q,u(Q),!0):!1,[]),fe=w.useCallback(()=>{pe.current=null,u(null)},[]),Se=(Q,De=!1)=>{const et=ao(c,Q);return{disabled:et.disabled,"aria-busy":et.busy||De}},Ye=w.useCallback(Q=>{window.requestAnimationFrame(()=>{var De;if(A0(((De=document.activeElement)==null?void 0:De.tagName)??null))for(const et of u8(Q)){const Ue=document.querySelector(et);if(Ue){Ue.focus();return}}})},[]),qe=w.useCallback(async(Q=!1)=>{Q&&p(!0);const De=new AbortController,et=window.setTimeout(()=>De.abort(),CU);try{const[Ue,tt]=await Promise.all([fetch(`/api/claude-accounts${Q?"?refresh=1":""}`,{signal:De.signal}),fetch("/api/cswap-auto",{signal:De.signal})]);if(Ue.ok){const gt=await Ue.json();r(gt),be(It=>vU(It,gt.accounts))}tt.ok&&l(await tt.json());const wt=jU([await nj(Ue),await nj(tt)]);m(gt=>rj(gt,wt))}catch{m(Ue=>rj(Ue,De.signal.aborted?SU:NU))}finally{window.clearTimeout(et),Q&&p(!1)}},[]),ke=w.useCallback(async(Q,De,et="panel")=>{if(!Ae(De))return null;const Ue=et==="menu"?ee:m;Ue(null);try{const tt=await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),wt=await tt.json().catch(()=>null);return wt!=null&&wt.ok||Ue({text:O0(wt,"command failed",tt.status),raw:Au(wt)}),wt}catch{return Ue({text:"server unreachable"}),null}finally{fe()}},[Ae,fe]),Re=w.useCallback(async(Q,De)=>{if(!Ae(De))return null;m(null),ee(null);try{const et=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),Ue=await et.json().catch(()=>null);return Ue!=null&&Ue.ok||ee({text:Al(Ue,"command failed",et.status)}),Ue}catch{return ee({text:"server unreachable"}),null}finally{fe()}},[Ae,fe]);w.useEffect(()=>(qe(!0),O.current=window.setInterval(()=>qe(!1),sj),()=>{O.current!=null&&window.clearInterval(O.current)}),[qe]),w.useEffect(()=>{!(n!=null&&n.ok)||!n.accounts||v(Q=>kU(Q,n.accounts))},[n]),w.useEffect(()=>{const Q=window.setInterval(()=>I(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(Q)},[]);const ze=((xr=s==null?void 0:s.settings["autoswitch.threshold"])==null?void 0:xr.value)??"90",Fe=Pe??ze,We=mU(Fe,ze),rt=($n=n==null?void 0:n.accounts)==null?void 0:$n.find(Q=>Q.active),dt=rt?Nh(rt,R):null,ct=(n==null?void 0:n.accounts)??[],yt=rt?ct.filter(Q=>!Q.active):[],Ot=yt.length?ct.filter(Q=>Q.active):ct,zt=yt.map(Q=>{const De=Nh(Q,R);return{key:sf(Q),name:Q.alias??Q.email??`account ${Q.num}`,ready:!Q.disabled&&!(De!=null&&De.blocksSwitch),why:Q.disabled?"held out":De!=null&&De.blocksSwitch?De.text:null,warn:(De==null?void 0:De.tone)==="warn",headroom:Q.headroom}}),Xt=Number(ze),Dt=(rt==null?void 0:rt.headroom)!=null&&Number.isFinite(Xt)&&100-rt.headroom>=Xt,rn=(s==null?void 0:s.ok)===!0&&(s.enabled||s.external),je=Q=>Le&&yt.some(De=>De.num===Q)?"ap-rest-list":"ap-scroll",xt=async(Q,De)=>{if(Ae(`switch-${Q}`)){m(null),v(null);try{const Ue=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:Q})})).json().catch(()=>null);Ue!=null&&Ue.ok?v({num:Q,name:De}):m({text:O0(Ue,"the switch failed"),raw:Au(Ue),row:Q}),await qe(!0)}catch{m({text:"server unreachable",row:Q})}finally{fe(),Ye(Q)}}},bt=w.useCallback(()=>{q(null),ee(null),B(null),G(null),z(!1)},[]),_n=(Q,De="first")=>{bt(),E(null),Ge(null),q({num:Q,view:"menu",start:De})},Ut=(Q,De)=>{bt(),E(et=>(et==null?void 0:et.anchor)===De?null:{num:Q,anchor:De})},Vn=w.useCallback((Q=!1)=>{var et;const De=C.current;Q&&De&&((et=document.getElementById(De.anchor))==null||et.focus()),E(null)},[]),Vt=()=>{bt(),E(null),b("lan")},Lt=w.useRef(S);w.useEffect(()=>{Lt.current!==S&&(Lt.current=S,window.requestAnimationFrame(()=>{var Q;(Q=document.getElementById(S==="lan"?"ap-lan-back":"ap-lan-entry"))==null||Q.focus()}))},[S]),w.useEffect(()=>{n!=null&&n.ok&&k(!0)},[n==null?void 0:n.ok]);const Zt=w.useCallback(Q=>{var Ue,tt;const De=V.current;if(!De||Q!=null&&De.num!==Q)return;const et=document.getElementById(`ap-menu-${De.num}`);(et!=null&&et.contains(document.activeElement)||A0(((Ue=document.activeElement)==null?void 0:Ue.tagName)??null))&&((tt=document.getElementById(`ap-more-${De.num}`))==null||tt.focus()),bt()},[bt]);w.useEffect(()=>{t&&(bt(),E(null))},[t,bt]),w.useEffect(()=>{H&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===H.num)&&bt(),j&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===j.num)&&E(null)},[n,H,j,bt]);const In=async Q=>{var et;z(!1);const De=await Re({action:"share",account:Q},`share-${Q}`);!(De!=null&&De.ok)||((et=V.current)==null?void 0:et.num)!==Q||(G({num:Q,blob:De.blob,expiresAt:De.expiresAt}),q({num:Q,view:"share"}))},Hr=async(Q,De)=>{const{commit:et,alias:Ue}=bU(K,De);if(et){const tt=await Re({action:"alias",account:Q,alias:Ue},`alias-${Q}`);if(await qe(!0),!(tt!=null&&tt.ok))return}Zt(Q)},xe=async(Q,De)=>{var tt,wt;const et=await Re({action:"move",account:Q,slot:De},`move-${Q}`),Ue=hU({menuFor:((tt=V.current)==null?void 0:tt.num)??null,shareFor:(F==null?void 0:F.num)??null},Q,et);if(await qe(!0),Ue){((wt=V.current)==null?void 0:wt.num)===Q&&bt(),B(Ue.confirmRemove),Ue.shareFor==null&&(G(null),z(!1)),Ne(Ue.swapNote);const gt=Ue.swapNote;gt&&window.setTimeout(()=>Ne(It=>It===gt?null:It),_U),Ge(null),Ye(Ue.menuFor)}return et},lr=async(Q,De,et)=>{if(!et.sends){Zt(Q);return}await xe(Q,De)},ks=async(Q,De)=>{if(De.sends){const et=await ke({action:"setting",key:"autoswitch.threshold",value:Q},"threshold");if(await qe(!0),!(et!=null&&et.ok))return;Be(null)}st(!0),window.setTimeout(()=>{var et;document.activeElement===ue.current&&((et=de.current)==null||et.focus()),st(!1)},EU)},Wr=o.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:o.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})}),fa=Q=>{const{shown:De,fuller:et}=gU(Q.lanes),Ue=Nh(Q,R),tt=Q.active||se.includes(sf(Q)),wt=Q.alias??Q.email??`account ${Q.num}`,gt=Q.alias&&Q.email?`${Q.alias} · ${Q.email}`:wt,It=Q.stale||(Ue==null?void 0:Ue.blocksSwitch)===!0,Rt=et?[...De,et]:De,Qt=Q.fetchedAt?Rm(Q.fetchedAt,R):null;return o.jsxs("li",{className:`ap-account${Q.active?" active":""}`,"aria-current":Q.active?"true":void 0,"data-open":tt?"":void 0,"data-frozen":It?"":void 0,children:[!Q.active&&o.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${Q.num}`,title:gt,"aria-expanded":tt,"aria-controls":tt?`ap-detail-${Q.num}`:void 0,"aria-describedby":[Q.alias&&Q.email?`ap-email-${Q.num}`:null,!tt&&!(Ue!=null&&Ue.blocksSwitch)?`ap-quota-${Q.num}`:null].filter(Boolean).join(" ")||void 0,onClick:()=>be(Nt=>wU(Nt,Q)),children:o.jsxs("span",{className:"vis-hidden",children:[wt,", ",tt?"hide details":"details"]})}),o.jsxs("div",{className:"ap-account-head",children:[Q.active?o.jsx("span",{className:"ap-live",title:`Active account · slot ${Q.num}`,children:o.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",Q.num,":"]})}):o.jsx("span",{className:"ap-num",children:Q.num}),Q.alias&&o.jsx("span",{className:"ap-alias",title:Q.alias,children:Q.alias}),o.jsx("span",{className:"ap-email",id:`ap-email-${Q.num}`,title:Q.email??void 0,children:Q.email}),Q.disabled&&o.jsx("span",{className:"ap-held",children:"held out"}),!Q.active&&!Q.disabled&&!(Ue!=null&&Ue.blocksSwitch)&&o.jsx("button",{type:"button",className:"ap-switch",...Se(`switch-${Q.num}`),onClick:()=>xt(Q.num,wt),"aria-label":`Switch to ${wt}`,title:`Switch to ${Q.alias??Q.email}`,children:c===`switch-${Q.num}`?"…":"Switch"}),o.jsx("button",{type:"button",id:`ap-more-${Q.num}`,className:"ap-more","aria-label":`More actions for ${Q.email??Q.alias??`account ${Q.num}`}`,"aria-haspopup":"menu","aria-expanded":$===Q.num,"aria-controls":$===Q.num?`ap-menu-${Q.num}`:void 0,title:"More actions",onClick:()=>$===Q.num?Zt():_n(Q.num),onKeyDown:Nt=>{Nt.key!=="ArrowDown"&&Nt.key!=="ArrowUp"||(Nt.preventDefault(),_n(Q.num,Nt.key==="ArrowUp"?"last":"first"))},children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[o.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),o.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),o.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),(h==null?void 0:h.row)===Q.num&&o.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),Q.active&&(y==null?void 0:y.num)===Q.num&&o.jsx("p",{className:"ap-switched",children:"Now active. New sessions start on it; ones already running pick it up on their next message, up to about 30 seconds later on macOS."}),(ge==null?void 0:ge.at)===Q.num&&(()=>{const Nt=ct.find(cr=>cr.num===ge.displaced),br=(Nt==null?void 0:Nt.alias)??(Nt==null?void 0:Nt.email)??"the account that was there";return o.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${ge.at} was taken, so the two accounts traded places: ${br} now holds slot ${ge.displaced}.`,children:["swapped with slot ",ge.displaced]})})(),Ue&&o.jsxs("div",{className:"ap-issue-line",children:[o.jsxs("button",{type:"button",id:`ap-issue-${Q.num}`,className:"ap-issue","data-tone":Ue.tone,"aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)===`ap-issue-${Q.num}`,"aria-controls":(j==null?void 0:j.anchor)===`ap-issue-${Q.num}`?"ap-issue-pop":void 0,onClick:()=>Ut(Q.num,`ap-issue-${Q.num}`),children:[Ue.tone==="warn"&&o.jsx(Am,{}),o.jsx("span",{className:"ap-issue-text",children:Ue.text})]}),!tt&&o.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),!tt&&!(Ue!=null&&Ue.blocksSwitch)&&o.jsxs("p",{className:"ap-quota",id:`ap-quota-${Q.num}`,children:[Rt.length?Rt.map(Nt=>o.jsxs("span",{className:"ap-q",children:[o.jsx("span",{className:"ap-q-label",children:Nt.label})," ",o.jsxs("span",{className:"ap-q-pct","data-level":It?void 0:IU(Nt.pct),children:[Math.round(Nt.pct),"%"]})]},Nt.id)):o.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),Q.stale&&!Ue&&o.jsx("span",{className:"ap-q-age","data-never":Qt?void 0:"",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),tt&&o.jsxs("div",{className:"ap-detail",id:`ap-detail-${Q.num}`,children:[o.jsx("div",{className:"ap-lanes",children:Q.lanes.length?Q.lanes.map(Nt=>o.jsx(OU,{lane:Nt,nowSec:R,frozen:It},Nt.id)):o.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),o.jsx("div",{className:"ap-meta",children:Q.fetchedAt?o.jsxs("span",{className:`ap-age${Q.stale&&!Ue?" ap-stale":""}`,title:"When claude-swap last read this account's usage, and when it plans to read it again. It sets that interval itself — 3 minutes at the fastest, wider while an account is recovering from a rate limit — and every surface, including `cswap watch`, follows the same plan.",children:["collected ",Rm(Q.fetchedAt,R),Ue!=null&&Ue.blocksSwitch?"":TU(Q.nextAt,R)]}):o.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]},Q.num)},Ns=n!=null&&n.ok&&(s!=null&&s.ok)?o.jsxs("div",{className:"ap-policy-block",children:[o.jsxs("div",{className:"ap-policy",children:[o.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),o.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:o.jsx("select",{ref:de,"aria-label":"Switch threshold",value:Fe,...Se("threshold"),onChange:Q=>Be(Q.target.value),children:$U(ze).map(Q=>o.jsxs("option",{value:Q,children:[Q,"%"]},Q))})}),(We.sends||Te)&&o.jsx("button",{ref:ue,type:"button",className:"ap-manage-btn",...Se("threshold"),title:We.title,onClick:()=>ks(Fe,We),children:Te&&!We.sends?We.done:We.label}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":s.enabled,"aria-label":"Auto-switch",...Se("enable"),onClick:()=>ke({action:"enable",enabled:!s.enabled},"enable").then(()=>qe(!0)),title:s.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:o.jsx("span",{className:"switch-knob"})})]}),s.external&&o.jsxs("p",{className:"ap-auto-note",children:[o.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",o.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",s.enabled?" — this toggle takes over when you stop it.":"."]})]}):null;return o.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",children:[S==="accounts"&&o.jsxs("div",{className:"ap-header",children:[o.jsx("h2",{children:"Claude accounts"}),o.jsxs("div",{className:"ap-header-right",children:[o.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>Z(!0),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:o.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),(((Hs=n==null?void 0:n.accounts)==null?void 0:Hs.length)??0)>0&&o.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>U(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${dn} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),o.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),o.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>qe(!0),...Se("reload",f),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),o.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),Wr]})]}),S==="accounts"&&o.jsx("div",{className:"ap-scroll",id:"ap-scroll",children:n==null?h?o.jsxs("div",{className:"ap-empty",role:"alert",children:[o.jsx("span",{title:h.raw||void 0,children:h.text}),o.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",sj/1e3," seconds."]}),o.jsx("button",{type:"button",className:"ap-fix",disabled:f,onClick:()=>qe(!0),children:f?"trying…":"try again"})]}):o.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?o.jsxs(o.Fragment,{children:[rt&&(dt==null?void 0:dt.tone)==="warn"&&o.jsxs("div",{className:"ap-notice",children:[o.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)==="ap-notice","aria-controls":(j==null?void 0:j.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>Ut(rt.num,"ap-notice"),children:[o.jsx(Am,{}),o.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),dt.fix&&o.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>Z(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),o.jsx("ul",{className:"ap-list",children:Ot.map(fa)}),yt.length>0&&o.jsx(iU,{peers:zt,strained:Dt,armed:rn,threshold:s!=null&&s.ok?ze:null,open:Le,onToggle:()=>ce(Q=>!Q)}),yt.length>0&&Le&&o.jsxs("div",{className:"ap-rest-panel",id:"ap-rest-panel",children:[o.jsx("ul",{className:"ap-list ap-others",id:"ap-rest-list",children:yt.map(fa)}),Ns]}),yt.length===0&&Ns,h&&h.row==null&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),H&&(()=>{var Ue;const Q=(Ue=n.accounts)==null?void 0:Ue.find(tt=>tt.num===H.num);if(!Q)return null;const De=`ap-pop-title-${Q.num}`,et=ne&&o.jsx("p",{className:"ap-pop-error",role:"alert",title:ne.raw||void 0,children:ne.text});return o.jsxs(M0,{anchorId:`ap-more-${Q.num}`,boundaryId:je(Q.num),id:`ap-menu-${Q.num}`,className:"ap-pop",role:H.view==="menu"?"menu":"dialog",labelledBy:H.view==="menu"?`ap-more-${Q.num}`:De,start:H.start,onClose:bt,children:[H.view==="menu"&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{D(Q.alias??""),ee(null),q({num:Q.num,view:"rename"})},children:"Rename"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{Ge(null),ee(null),q({num:Q.num,view:"move"})},children:"Move to slot…"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Se(`share-${Q.num}`),title:`Copy this account to another ${dn}. Anyone who has the text can use the account — treat it as the password. The other deck stops accepting it after 10 minutes; that does not make an escaped copy safe.`,onClick:()=>In(Q.num),children:c===`share-${Q.num}`?"Sharing…":"Share"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",title:"See how much this account worked in each project",onClick:()=>{le(Q.num),Zt(Q.num)},children:"Projects"}),(((s==null?void 0:s.enabled)||(s==null?void 0:s.external))&&!Q.active||Q.disabled)&&o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Se(`rot-${Q.num}`),title:Q.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>ke({action:"account",account:Q.num,enabled:Q.disabled},`rot-${Q.num}`,"menu").then(tt=>{qe(!0),tt!=null&&tt.ok&&Zt(Q.num)}),children:Q.disabled?"Put back in rotation":"Hold out of rotation"}),o.jsx("div",{role:"separator",className:"ap-menu-sep"}),o.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${P===Q.num?" armed":""}`,...Se(`rm-${Q.num}`),"aria-label":P===Q.num?"Confirm remove":void 0,title:P===Q.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{const tt=Date.now(),wt=Cu({armedFor:P,target:Q.num,armedAt:W.current,now:tt,gapMs:Mu});if(wt==="arm"){B(Q.num),W.current=tt,window.setTimeout(()=>B(gt=>gt===Q.num?null:gt),4e3);return}wt!=="ignore"&&(B(null),Re({action:"remove",account:Q.num},`rm-${Q.num}`).then(gt=>{var It;qe(!0),gt!=null&>.ok&&(((It=V.current)==null?void 0:It.num)===Q.num&&bt(),Ye(null))}))},children:c===`rm-${Q.num}`?"Removing…":P===Q.num?"Confirm":"Remove"}),et]}),H.view==="rename"&&o.jsxs("form",{className:"ap-pop-form",onSubmit:tt=>{tt.preventDefault(),Hr(Q.num,Q.alias)},children:[o.jsx("label",{className:"ap-pop-title",id:De,htmlFor:`ap-alias-${Q.num}`,children:"Rename account"}),o.jsx("input",{id:`ap-alias-${Q.num}`,className:"ap-manage-input",type:"text",value:K,onChange:tt=>D(tt.target.value),maxLength:xU,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:tt=>tt.currentTarget.select()}),et,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Cancel"}),o.jsx("button",{type:"submit",className:"btn primary",...Se(`alias-${Q.num}`),title:"A short name to show instead of the email",children:c===`alias-${Q.num}`?"…":"Save"})]})]}),H.view==="move"&&(()=>{const tt=dU((n.accounts??[]).map(It=>It.num),Q.num),wt=fU(tt,Ie,Q.num),gt=pU(tt,wt,Q.num);return o.jsxs("div",{className:"ap-pop-form",children:[o.jsx("label",{className:"ap-pop-title",id:De,htmlFor:`ap-slot-${Q.num}`,children:"Move to slot"}),o.jsx("span",{className:"ap-field",children:o.jsx("select",{id:`ap-slot-${Q.num}`,value:String(wt),...Se(`move-${Q.num}`),onChange:It=>Ge(Number(It.target.value)),autoFocus:!0,children:tt.map(It=>o.jsx("option",{value:It.slot,children:It.label},It.slot))})}),et,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Cancel"}),o.jsx("button",{type:"button",className:"btn primary",...Se(`move-${Q.num}`),title:gt.title,onClick:()=>lr(Q.num,wt,gt),children:c===`move-${Q.num}`?"…":lu(gt.label)})]})]})})(),H.view==="share"&&(F==null?void 0:F.num)===Q.num&&(()=>{const tt=zM(F.expiresAt,R),wt=tt.tone==="gone";return o.jsxs("div",{className:`ap-pop-form ap-share${wt?" expired":""}`,children:[o.jsx("p",{className:"ap-pop-title",id:De,children:"Share account"}),o.jsx("code",{className:"ap-share-blob",children:F.blob}),o.jsxs("p",{className:"ap-pop-note",title:"This text is the account's password. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the login itself is in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign the account out and back in.",children:[o.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",o.jsx("span",{className:`ap-share-expiry ${tt.tone}`,children:tt.text})]}),et,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Done"}),o.jsx("button",{type:"button",className:"btn primary",...Se(`share-${Q.num}`),autoFocus:!0,onClick:async()=>{if(wt){await In(Q.num);return}await hi(F.blob)&&(z(!0),window.setTimeout(()=>z(!1),1800))},children:wt?"Make a new share":Y?"Copied":"Copy"})]})]})})()]})})(),j&&(()=>{var et;const Q=(et=n.accounts)==null?void 0:et.find(Ue=>Ue.num===j.num),De=Q?Nh(Q,R):null;return!Q||!De?null:o.jsx(M0,{anchorId:j.anchor,boundaryId:j.anchor==="ap-notice"?"ap-scroll":je(Q.num),id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",onClose:()=>Vn(),children:o.jsxs("div",{className:"ap-pop-form",children:[o.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":De.tone,children:[De.tone==="warn"&&o.jsx(Am,{}),De.text]}),o.jsx("p",{className:"ap-pop-note ap-issue-hint",children:De.hint}),o.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[o.jsx("span",{className:"ap-issue-who",children:Q.alias??Q.email??`account ${Q.num}`})," · ",Q.fetchedAt?`last collected ${Rm(Q.fetchedAt,R)}`:"never collected"]}),o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Vn(!0),children:"Done"}),De.fix&&o.jsx("button",{type:"button",className:"btn primary",onClick:()=>{Vn(!0),Z(!0)},title:"Open the sign-in dialog. Signing in as this account puts its login back in this slot — it keeps its slot, its alias and its history.",children:De.fix})]})]})})})()]}):o.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"claude-swap isn't installed."}),o.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&o.jsx("code",{className:"ap-cmd",children:n.hint}),o.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",o.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"No accounts added yet."}),o.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",o.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"Couldn't read the account store."}),o.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})})}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:y?`Now active: ${y.name}`:""}),_&&o.jsx(aU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({key:`${String(Q.email??"").trim().toLowerCase()}@@${Q.orgUuid??""}`,email:Q.email??"",alive:Q.alive===!0,shareable:Q.collector==="ok"||Q.collector==null&&!Q.active})),onChanged:()=>qe(!0),view:S==="lan",onOpen:Vt,onBack:()=>b("accounts"),closeButton:Wr}),M&&o.jsx(rz,{onClose:()=>Z(!1),onChanged:()=>qe(!0)}),re&&o.jsx(uU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({num:Q.num,email:Q.email,alias:Q.alias,org:Q.org})),onClose:()=>U(!1),copyText:hi}),ie!=null&&(()=>{const Q=((n==null?void 0:n.accounts)??[]).find(De=>De.num===ie);return Q?o.jsx(NB,{num:Q.num,name:Q.alias??Q.email??`account ${Q.num}`,onClose:()=>le(null)}):(le(null),null)})()]})}const PU=3e4;function DU({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function FU({bundle:e,running:t,pending:n,lastTried:r}){return t?DU({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function qU(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function BU({asked:e,reported:t}){return t?t!==e:!1}function XM(e){const t=e.thresholdMs??PU;return!e.enabled||e.kind!=="restart"||!e.canRestart||!e.noticeOpen||!e.visible||e.busy?null:e.idleSince==null||e.now<e.idleSince?t:Math.max(0,t-(e.now-e.idleSince))}function zU(e){const t=Math.max(0,Math.ceil(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function UU(e,t){return e?t==null?"auto when idle":`auto in ${zU(t)}`:"auto-restart off"}function aj(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function HU(e){return e<=0?{label:"Restart now",clause:"nothing is running"}:{label:"Restart anyway",clause:`${e===1?"1 agent is running":`${e} agents are running`} — their events during the restart are lost`}}function WU(e){const t=XM(e);return t==null?{idleSince:null,restart:!1,remainingMs:null}:e.idleSince==null||e.now<e.idleSince?{idleSince:e.now,restart:!1,remainingMs:t}:{idleSince:e.idleSince,restart:t===0,remainingMs:t}}function zb(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Mm,oj;function VU(){if(oj)return Mm;oj=1;function e(){this.__data__=[],this.size=0}return Mm=e,Mm}var Im,ij;function tc(){if(ij)return Im;ij=1;function e(t,n){return t===n||t!==t&&n!==n}return Im=e,Im}var $m,lj;function Mf(){if(lj)return $m;lj=1;var e=tc();function t(n,r){for(var s=n.length;s--;)if(e(n[s][0],r))return s;return-1}return $m=t,$m}var Om,cj;function GU(){if(cj)return Om;cj=1;var e=Mf(),t=Array.prototype,n=t.splice;function r(s){var l=this.__data__,c=e(l,s);if(c<0)return!1;var u=l.length-1;return c==u?l.pop():n.call(l,c,1),--this.size,!0}return Om=r,Om}var Lm,uj;function KU(){if(uj)return Lm;uj=1;var e=Mf();function t(n){var r=this.__data__,s=e(r,n);return s<0?void 0:r[s][1]}return Lm=t,Lm}var Pm,dj;function YU(){if(dj)return Pm;dj=1;var e=Mf();function t(n){return e(this.__data__,n)>-1}return Pm=t,Pm}var Dm,hj;function XU(){if(hj)return Dm;hj=1;var e=Mf();function t(n,r){var s=this.__data__,l=e(s,n);return l<0?(++this.size,s.push([n,r])):s[l][1]=r,this}return Dm=t,Dm}var Fm,fj;function If(){if(fj)return Fm;fj=1;var e=VU(),t=GU(),n=KU(),r=YU(),s=XU();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,Fm=l,Fm}var qm,pj;function ZU(){if(pj)return qm;pj=1;var e=If();function t(){this.__data__=new e,this.size=0}return qm=t,qm}var Bm,mj;function QU(){if(mj)return Bm;mj=1;function e(t){var n=this.__data__,r=n.delete(t);return this.size=n.size,r}return Bm=e,Bm}var zm,gj;function JU(){if(gj)return zm;gj=1;function e(t){return this.__data__.get(t)}return zm=e,zm}var Um,yj;function eH(){if(yj)return Um;yj=1;function e(t){return this.__data__.has(t)}return Um=e,Um}var Hm,wj;function ZM(){if(wj)return Hm;wj=1;var e=typeof th=="object"&&th&&th.Object===Object&&th;return Hm=e,Hm}var Wm,vj;function bs(){if(vj)return Wm;vj=1;var e=ZM(),t=typeof self=="object"&&self&&self.Object===Object&&self,n=e||t||Function("return this")();return Wm=n,Wm}var Vm,xj;function nc(){if(xj)return Vm;xj=1;var e=bs(),t=e.Symbol;return Vm=t,Vm}var Gm,bj;function tH(){if(bj)return Gm;bj=1;var e=nc(),t=Object.prototype,n=t.hasOwnProperty,r=t.toString,s=e?e.toStringTag:void 0;function l(c){var u=n.call(c,s),f=c[s];try{c[s]=void 0;var p=!0}catch{}var h=r.call(c);return p&&(u?c[s]=f:delete c[s]),h}return Gm=l,Gm}var Km,kj;function nH(){if(kj)return Km;kj=1;var e=Object.prototype,t=e.toString;function n(r){return t.call(r)}return Km=n,Km}var Ym,Nj;function wi(){if(Nj)return Ym;Nj=1;var e=nc(),t=tH(),n=nH(),r="[object Null]",s="[object Undefined]",l=e?e.toStringTag:void 0;function c(u){return u==null?u===void 0?s:r:l&&l in Object(u)?t(u):n(u)}return Ym=c,Ym}var Xm,Sj;function zr(){if(Sj)return Xm;Sj=1;function e(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}return Xm=e,Xm}var Zm,jj;function Uu(){if(jj)return Zm;jj=1;var e=wi(),t=zr(),n="[object AsyncFunction]",r="[object Function]",s="[object GeneratorFunction]",l="[object Proxy]";function c(u){if(!t(u))return!1;var f=e(u);return f==r||f==s||f==n||f==l}return Zm=c,Zm}var Qm,_j;function rH(){if(_j)return Qm;_j=1;var e=bs(),t=e["__core-js_shared__"];return Qm=t,Qm}var Jm,Ej;function sH(){if(Ej)return Jm;Ej=1;var e=rH(),t=(function(){var r=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""})();function n(r){return!!t&&t in r}return Jm=n,Jm}var eg,Cj;function QM(){if(Cj)return eg;Cj=1;var e=Function.prototype,t=e.toString;function n(r){if(r!=null){try{return t.call(r)}catch{}try{return r+""}catch{}}return""}return eg=n,eg}var tg,Tj;function aH(){if(Tj)return tg;Tj=1;var e=Uu(),t=sH(),n=zr(),r=QM(),s=/[\\^$.*+?()[\]{}|]/g,l=/^\[object .+?Constructor\]$/,c=Function.prototype,u=Object.prototype,f=c.toString,p=u.hasOwnProperty,h=RegExp("^"+f.call(p).replace(s,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function m(y){if(!n(y)||t(y))return!1;var v=e(y)?h:l;return v.test(r(y))}return tg=m,tg}var ng,Rj;function oH(){if(Rj)return ng;Rj=1;function e(t,n){return t==null?void 0:t[n]}return ng=e,ng}var rg,Aj;function vi(){if(Aj)return rg;Aj=1;var e=aH(),t=oH();function n(r,s){var l=t(r,s);return e(l)?l:void 0}return rg=n,rg}var sg,Mj;function Ub(){if(Mj)return sg;Mj=1;var e=vi(),t=bs(),n=e(t,"Map");return sg=n,sg}var ag,Ij;function $f(){if(Ij)return ag;Ij=1;var e=vi(),t=e(Object,"create");return ag=t,ag}var og,$j;function iH(){if($j)return og;$j=1;var e=$f();function t(){this.__data__=e?e(null):{},this.size=0}return og=t,og}var ig,Oj;function lH(){if(Oj)return ig;Oj=1;function e(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}return ig=e,ig}var lg,Lj;function cH(){if(Lj)return lg;Lj=1;var e=$f(),t="__lodash_hash_undefined__",n=Object.prototype,r=n.hasOwnProperty;function s(l){var c=this.__data__;if(e){var u=c[l];return u===t?void 0:u}return r.call(c,l)?c[l]:void 0}return lg=s,lg}var cg,Pj;function uH(){if(Pj)return cg;Pj=1;var e=$f(),t=Object.prototype,n=t.hasOwnProperty;function r(s){var l=this.__data__;return e?l[s]!==void 0:n.call(l,s)}return cg=r,cg}var ug,Dj;function dH(){if(Dj)return ug;Dj=1;var e=$f(),t="__lodash_hash_undefined__";function n(r,s){var l=this.__data__;return this.size+=this.has(r)?0:1,l[r]=e&&s===void 0?t:s,this}return ug=n,ug}var dg,Fj;function hH(){if(Fj)return dg;Fj=1;var e=iH(),t=lH(),n=cH(),r=uH(),s=dH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,dg=l,dg}var hg,qj;function fH(){if(qj)return hg;qj=1;var e=hH(),t=If(),n=Ub();function r(){this.size=0,this.__data__={hash:new e,map:new(n||t),string:new e}}return hg=r,hg}var fg,Bj;function pH(){if(Bj)return fg;Bj=1;function e(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}return fg=e,fg}var pg,zj;function Of(){if(zj)return pg;zj=1;var e=pH();function t(n,r){var s=n.__data__;return e(r)?s[typeof r=="string"?"string":"hash"]:s.map}return pg=t,pg}var mg,Uj;function mH(){if(Uj)return mg;Uj=1;var e=Of();function t(n){var r=e(this,n).delete(n);return this.size-=r?1:0,r}return mg=t,mg}var gg,Hj;function gH(){if(Hj)return gg;Hj=1;var e=Of();function t(n){return e(this,n).get(n)}return gg=t,gg}var yg,Wj;function yH(){if(Wj)return yg;Wj=1;var e=Of();function t(n){return e(this,n).has(n)}return yg=t,yg}var wg,Vj;function wH(){if(Vj)return wg;Vj=1;var e=Of();function t(n,r){var s=e(this,n),l=s.size;return s.set(n,r),this.size+=s.size==l?0:1,this}return wg=t,wg}var vg,Gj;function Hb(){if(Gj)return vg;Gj=1;var e=fH(),t=mH(),n=gH(),r=yH(),s=wH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,vg=l,vg}var xg,Kj;function vH(){if(Kj)return xg;Kj=1;var e=If(),t=Ub(),n=Hb(),r=200;function s(l,c){var u=this.__data__;if(u instanceof e){var f=u.__data__;if(!t||f.length<r-1)return f.push([l,c]),this.size=++u.size,this;u=this.__data__=new n(f)}return u.set(l,c),this.size=u.size,this}return xg=s,xg}var bg,Yj;function Lf(){if(Yj)return bg;Yj=1;var e=If(),t=ZU(),n=QU(),r=JU(),s=eH(),l=vH();function c(u){var f=this.__data__=new e(u);this.size=f.size}return c.prototype.clear=t,c.prototype.delete=n,c.prototype.get=r,c.prototype.has=s,c.prototype.set=l,bg=c,bg}var kg,Xj;function Wb(){if(Xj)return kg;Xj=1;function e(t,n){for(var r=-1,s=t==null?0:t.length;++r<s&&n(t[r],r,t)!==!1;);return t}return kg=e,kg}var Ng,Zj;function JM(){if(Zj)return Ng;Zj=1;var e=vi(),t=(function(){try{var n=e(Object,"defineProperty");return n({},"",{}),n}catch{}})();return Ng=t,Ng}var Sg,Qj;function Pf(){if(Qj)return Sg;Qj=1;var e=JM();function t(n,r,s){r=="__proto__"&&e?e(n,r,{configurable:!0,enumerable:!0,value:s,writable:!0}):n[r]=s}return Sg=t,Sg}var jg,Jj;function Df(){if(Jj)return jg;Jj=1;var e=Pf(),t=tc(),n=Object.prototype,r=n.hasOwnProperty;function s(l,c,u){var f=l[c];(!(r.call(l,c)&&t(f,u))||u===void 0&&!(c in l))&&e(l,c,u)}return jg=s,jg}var _g,e_;function Hu(){if(e_)return _g;e_=1;var e=Df(),t=Pf();function n(r,s,l,c){var u=!l;l||(l={});for(var f=-1,p=s.length;++f<p;){var h=s[f],m=c?c(l[h],r[h],h,l,r):void 0;m===void 0&&(m=r[h]),u?t(l,h,m):e(l,h,m)}return l}return _g=n,_g}var Eg,t_;function xH(){if(t_)return Eg;t_=1;function e(t,n){for(var r=-1,s=Array(t);++r<t;)s[r]=n(r);return s}return Eg=e,Eg}var Cg,n_;function Us(){if(n_)return Cg;n_=1;function e(t){return t!=null&&typeof t=="object"}return Cg=e,Cg}var Tg,r_;function bH(){if(r_)return Tg;r_=1;var e=wi(),t=Us(),n="[object Arguments]";function r(s){return t(s)&&e(s)==n}return Tg=r,Tg}var Rg,s_;function Wu(){if(s_)return Rg;s_=1;var e=bH(),t=Us(),n=Object.prototype,r=n.hasOwnProperty,s=n.propertyIsEnumerable,l=e((function(){return arguments})())?e:function(c){return t(c)&&r.call(c,"callee")&&!s.call(c,"callee")};return Rg=l,Rg}var Ag,a_;function nn(){if(a_)return Ag;a_=1;var e=Array.isArray;return Ag=e,Ag}var cu={exports:{}},Mg,o_;function kH(){if(o_)return Mg;o_=1;function e(){return!1}return Mg=e,Mg}cu.exports;var i_;function rc(){return i_||(i_=1,(function(e,t){var n=bs(),r=kH(),s=t&&!t.nodeType&&t,l=s&&!0&&e&&!e.nodeType&&e,c=l&&l.exports===s,u=c?n.Buffer:void 0,f=u?u.isBuffer:void 0,p=f||r;e.exports=p})(cu,cu.exports)),cu.exports}var Ig,l_;function Ff(){if(l_)return Ig;l_=1;var e=9007199254740991,t=/^(?:0|[1-9]\d*)$/;function n(r,s){var l=typeof r;return s=s??e,!!s&&(l=="number"||l!="symbol"&&t.test(r))&&r>-1&&r%1==0&&r<s}return Ig=n,Ig}var $g,c_;function Vb(){if(c_)return $g;c_=1;var e=9007199254740991;function t(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=e}return $g=t,$g}var Og,u_;function NH(){if(u_)return Og;u_=1;var e=wi(),t=Vb(),n=Us(),r="[object Arguments]",s="[object Array]",l="[object Boolean]",c="[object Date]",u="[object Error]",f="[object Function]",p="[object Map]",h="[object Number]",m="[object Object]",y="[object RegExp]",v="[object Set]",S="[object String]",b="[object WeakMap]",_="[object ArrayBuffer]",k="[object DataView]",j="[object Float32Array]",E="[object Float64Array]",C="[object Int8Array]",R="[object Int16Array]",I="[object Int32Array]",O="[object Uint8Array]",H="[object Uint8ClampedArray]",q="[object Uint16Array]",$="[object Uint32Array]",V={};V[j]=V[E]=V[C]=V[R]=V[I]=V[O]=V[H]=V[q]=V[$]=!0,V[r]=V[s]=V[_]=V[l]=V[k]=V[c]=V[u]=V[f]=V[p]=V[h]=V[m]=V[y]=V[v]=V[S]=V[b]=!1;function ne(ee){return n(ee)&&t(ee.length)&&!!V[e(ee)]}return Og=ne,Og}var Lg,d_;function qf(){if(d_)return Lg;d_=1;function e(t){return function(n){return t(n)}}return Lg=e,Lg}var uu={exports:{}};uu.exports;var h_;function Gb(){return h_||(h_=1,(function(e,t){var n=ZM(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,l=s&&s.exports===r,c=l&&n.process,u=(function(){try{var f=s&&s.require&&s.require("util").types;return f||c&&c.binding&&c.binding("util")}catch{}})();e.exports=u})(uu,uu.exports)),uu.exports}var Pg,f_;function Vu(){if(f_)return Pg;f_=1;var e=NH(),t=qf(),n=Gb(),r=n&&n.isTypedArray,s=r?t(r):e;return Pg=s,Pg}var Dg,p_;function eI(){if(p_)return Dg;p_=1;var e=xH(),t=Wu(),n=nn(),r=rc(),s=Ff(),l=Vu(),c=Object.prototype,u=c.hasOwnProperty;function f(p,h){var m=n(p),y=!m&&t(p),v=!m&&!y&&r(p),S=!m&&!y&&!v&&l(p),b=m||y||v||S,_=b?e(p.length,String):[],k=_.length;for(var j in p)(h||u.call(p,j))&&!(b&&(j=="length"||v&&(j=="offset"||j=="parent")||S&&(j=="buffer"||j=="byteLength"||j=="byteOffset")||s(j,k)))&&_.push(j);return _}return Dg=f,Dg}var Fg,m_;function Bf(){if(m_)return Fg;m_=1;var e=Object.prototype;function t(n){var r=n&&n.constructor,s=typeof r=="function"&&r.prototype||e;return n===s}return Fg=t,Fg}var qg,g_;function tI(){if(g_)return qg;g_=1;function e(t,n){return function(r){return t(n(r))}}return qg=e,qg}var Bg,y_;function SH(){if(y_)return Bg;y_=1;var e=tI(),t=e(Object.keys,Object);return Bg=t,Bg}var zg,w_;function Kb(){if(w_)return zg;w_=1;var e=Bf(),t=SH(),n=Object.prototype,r=n.hasOwnProperty;function s(l){if(!e(l))return t(l);var c=[];for(var u in Object(l))r.call(l,u)&&u!="constructor"&&c.push(u);return c}return zg=s,zg}var Ug,v_;function da(){if(v_)return Ug;v_=1;var e=Uu(),t=Vb();function n(r){return r!=null&&t(r.length)&&!e(r)}return Ug=n,Ug}var Hg,x_;function oo(){if(x_)return Hg;x_=1;var e=eI(),t=Kb(),n=da();function r(s){return n(s)?e(s):t(s)}return Hg=r,Hg}var Wg,b_;function jH(){if(b_)return Wg;b_=1;var e=Hu(),t=oo();function n(r,s){return r&&e(s,t(s),r)}return Wg=n,Wg}var Vg,k_;function _H(){if(k_)return Vg;k_=1;function e(t){var n=[];if(t!=null)for(var r in Object(t))n.push(r);return n}return Vg=e,Vg}var Gg,N_;function EH(){if(N_)return Gg;N_=1;var e=zr(),t=Bf(),n=_H(),r=Object.prototype,s=r.hasOwnProperty;function l(c){if(!e(c))return n(c);var u=t(c),f=[];for(var p in c)p=="constructor"&&(u||!s.call(c,p))||f.push(p);return f}return Gg=l,Gg}var Kg,S_;function xi(){if(S_)return Kg;S_=1;var e=eI(),t=EH(),n=da();function r(s){return n(s)?e(s,!0):t(s)}return Kg=r,Kg}var Yg,j_;function CH(){if(j_)return Yg;j_=1;var e=Hu(),t=xi();function n(r,s){return r&&e(s,t(s),r)}return Yg=n,Yg}var du={exports:{}};du.exports;var __;function nI(){return __||(__=1,(function(e,t){var n=bs(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,l=s&&s.exports===r,c=l?n.Buffer:void 0,u=c?c.allocUnsafe:void 0;function f(p,h){if(h)return p.slice();var m=p.length,y=u?u(m):new p.constructor(m);return p.copy(y),y}e.exports=f})(du,du.exports)),du.exports}var Xg,E_;function rI(){if(E_)return Xg;E_=1;function e(t,n){var r=-1,s=t.length;for(n||(n=Array(s));++r<s;)n[r]=t[r];return n}return Xg=e,Xg}var Zg,C_;function sI(){if(C_)return Zg;C_=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,l=0,c=[];++r<s;){var u=t[r];n(u,r,t)&&(c[l++]=u)}return c}return Zg=e,Zg}var Qg,T_;function aI(){if(T_)return Qg;T_=1;function e(){return[]}return Qg=e,Qg}var Jg,R_;function Yb(){if(R_)return Jg;R_=1;var e=sI(),t=aI(),n=Object.prototype,r=n.propertyIsEnumerable,s=Object.getOwnPropertySymbols,l=s?function(c){return c==null?[]:(c=Object(c),e(s(c),function(u){return r.call(c,u)}))}:t;return Jg=l,Jg}var ey,A_;function TH(){if(A_)return ey;A_=1;var e=Hu(),t=Yb();function n(r,s){return e(r,t(r),s)}return ey=n,ey}var ty,M_;function Xb(){if(M_)return ty;M_=1;function e(t,n){for(var r=-1,s=n.length,l=t.length;++r<s;)t[l+r]=n[r];return t}return ty=e,ty}var ny,I_;function zf(){if(I_)return ny;I_=1;var e=tI(),t=e(Object.getPrototypeOf,Object);return ny=t,ny}var ry,$_;function oI(){if($_)return ry;$_=1;var e=Xb(),t=zf(),n=Yb(),r=aI(),s=Object.getOwnPropertySymbols,l=s?function(c){for(var u=[];c;)e(u,n(c)),c=t(c);return u}:r;return ry=l,ry}var sy,O_;function RH(){if(O_)return sy;O_=1;var e=Hu(),t=oI();function n(r,s){return e(r,t(r),s)}return sy=n,sy}var ay,L_;function iI(){if(L_)return ay;L_=1;var e=Xb(),t=nn();function n(r,s,l){var c=s(r);return t(r)?c:e(c,l(r))}return ay=n,ay}var oy,P_;function lI(){if(P_)return oy;P_=1;var e=iI(),t=Yb(),n=oo();function r(s){return e(s,n,t)}return oy=r,oy}var iy,D_;function AH(){if(D_)return iy;D_=1;var e=iI(),t=oI(),n=xi();function r(s){return e(s,n,t)}return iy=r,iy}var ly,F_;function MH(){if(F_)return ly;F_=1;var e=vi(),t=bs(),n=e(t,"DataView");return ly=n,ly}var cy,q_;function IH(){if(q_)return cy;q_=1;var e=vi(),t=bs(),n=e(t,"Promise");return cy=n,cy}var uy,B_;function cI(){if(B_)return uy;B_=1;var e=vi(),t=bs(),n=e(t,"Set");return uy=n,uy}var dy,z_;function $H(){if(z_)return dy;z_=1;var e=vi(),t=bs(),n=e(t,"WeakMap");return dy=n,dy}var hy,U_;function sc(){if(U_)return hy;U_=1;var e=MH(),t=Ub(),n=IH(),r=cI(),s=$H(),l=wi(),c=QM(),u="[object Map]",f="[object Object]",p="[object Promise]",h="[object Set]",m="[object WeakMap]",y="[object DataView]",v=c(e),S=c(t),b=c(n),_=c(r),k=c(s),j=l;return(e&&j(new e(new ArrayBuffer(1)))!=y||t&&j(new t)!=u||n&&j(n.resolve())!=p||r&&j(new r)!=h||s&&j(new s)!=m)&&(j=function(E){var C=l(E),R=C==f?E.constructor:void 0,I=R?c(R):"";if(I)switch(I){case v:return y;case S:return u;case b:return p;case _:return h;case k:return m}return C}),hy=j,hy}var fy,H_;function OH(){if(H_)return fy;H_=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r){var s=r.length,l=new r.constructor(s);return s&&typeof r[0]=="string"&&t.call(r,"index")&&(l.index=r.index,l.input=r.input),l}return fy=n,fy}var py,W_;function uI(){if(W_)return py;W_=1;var e=bs(),t=e.Uint8Array;return py=t,py}var my,V_;function Zb(){if(V_)return my;V_=1;var e=uI();function t(n){var r=new n.constructor(n.byteLength);return new e(r).set(new e(n)),r}return my=t,my}var gy,G_;function LH(){if(G_)return gy;G_=1;var e=Zb();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.byteLength)}return gy=t,gy}var yy,K_;function PH(){if(K_)return yy;K_=1;var e=/\w*$/;function t(n){var r=new n.constructor(n.source,e.exec(n));return r.lastIndex=n.lastIndex,r}return yy=t,yy}var wy,Y_;function DH(){if(Y_)return wy;Y_=1;var e=nc(),t=e?e.prototype:void 0,n=t?t.valueOf:void 0;function r(s){return n?Object(n.call(s)):{}}return wy=r,wy}var vy,X_;function dI(){if(X_)return vy;X_=1;var e=Zb();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.length)}return vy=t,vy}var xy,Z_;function FH(){if(Z_)return xy;Z_=1;var e=Zb(),t=LH(),n=PH(),r=DH(),s=dI(),l="[object Boolean]",c="[object Date]",u="[object Map]",f="[object Number]",p="[object RegExp]",h="[object Set]",m="[object String]",y="[object Symbol]",v="[object ArrayBuffer]",S="[object DataView]",b="[object Float32Array]",_="[object Float64Array]",k="[object Int8Array]",j="[object Int16Array]",E="[object Int32Array]",C="[object Uint8Array]",R="[object Uint8ClampedArray]",I="[object Uint16Array]",O="[object Uint32Array]";function H(q,$,V){var ne=q.constructor;switch($){case v:return e(q);case l:case c:return new ne(+q);case S:return t(q,V);case b:case _:case k:case j:case E:case C:case R:case I:case O:return s(q,V);case u:return new ne;case f:case m:return new ne(q);case p:return n(q);case h:return new ne;case y:return r(q)}}return xy=H,xy}var by,Q_;function hI(){if(Q_)return by;Q_=1;var e=zr(),t=Object.create,n=(function(){function r(){}return function(s){if(!e(s))return{};if(t)return t(s);r.prototype=s;var l=new r;return r.prototype=void 0,l}})();return by=n,by}var ky,J_;function fI(){if(J_)return ky;J_=1;var e=hI(),t=zf(),n=Bf();function r(s){return typeof s.constructor=="function"&&!n(s)?e(t(s)):{}}return ky=r,ky}var Ny,eE;function qH(){if(eE)return Ny;eE=1;var e=sc(),t=Us(),n="[object Map]";function r(s){return t(s)&&e(s)==n}return Ny=r,Ny}var Sy,tE;function BH(){if(tE)return Sy;tE=1;var e=qH(),t=qf(),n=Gb(),r=n&&n.isMap,s=r?t(r):e;return Sy=s,Sy}var jy,nE;function zH(){if(nE)return jy;nE=1;var e=sc(),t=Us(),n="[object Set]";function r(s){return t(s)&&e(s)==n}return jy=r,jy}var _y,rE;function UH(){if(rE)return _y;rE=1;var e=zH(),t=qf(),n=Gb(),r=n&&n.isSet,s=r?t(r):e;return _y=s,_y}var Ey,sE;function pI(){if(sE)return Ey;sE=1;var e=Lf(),t=Wb(),n=Df(),r=jH(),s=CH(),l=nI(),c=rI(),u=TH(),f=RH(),p=lI(),h=AH(),m=sc(),y=OH(),v=FH(),S=fI(),b=nn(),_=rc(),k=BH(),j=zr(),E=UH(),C=oo(),R=xi(),I=1,O=2,H=4,q="[object Arguments]",$="[object Array]",V="[object Boolean]",ne="[object Date]",ee="[object Error]",M="[object Function]",Z="[object GeneratorFunction]",K="[object Map]",D="[object Number]",P="[object Object]",B="[object RegExp]",W="[object Set]",F="[object String]",G="[object Symbol]",re="[object WeakMap]",U="[object ArrayBuffer]",Y="[object DataView]",z="[object Float32Array]",ie="[object Float64Array]",le="[object Int8Array]",ge="[object Int16Array]",Ne="[object Int32Array]",Ie="[object Uint8Array]",Ge="[object Uint8ClampedArray]",Pe="[object Uint16Array]",Be="[object Uint32Array]",Te={};Te[q]=Te[$]=Te[U]=Te[Y]=Te[V]=Te[ne]=Te[z]=Te[ie]=Te[le]=Te[ge]=Te[Ne]=Te[K]=Te[D]=Te[P]=Te[B]=Te[W]=Te[F]=Te[G]=Te[Ie]=Te[Ge]=Te[Pe]=Te[Be]=!0,Te[ee]=Te[M]=Te[re]=!1;function st(de,ue,se,be,Le,ce){var pe,Ae=ue&I,fe=ue&O,Se=ue&H;if(se&&(pe=Le?se(de,be,Le,ce):se(de)),pe!==void 0)return pe;if(!j(de))return de;var Ye=b(de);if(Ye){if(pe=y(de),!Ae)return c(de,pe)}else{var qe=m(de),ke=qe==M||qe==Z;if(_(de))return l(de,Ae);if(qe==P||qe==q||ke&&!Le){if(pe=fe||ke?{}:S(de),!Ae)return fe?f(de,s(pe,de)):u(de,r(pe,de))}else{if(!Te[qe])return Le?de:{};pe=v(de,qe,Ae)}}ce||(ce=new e);var Re=ce.get(de);if(Re)return Re;ce.set(de,pe),E(de)?de.forEach(function(We){pe.add(st(We,ue,se,We,de,ce))}):k(de)&&de.forEach(function(We,rt){pe.set(rt,st(We,ue,se,rt,de,ce))});var ze=Se?fe?h:p:fe?R:C,Fe=Ye?void 0:ze(de);return t(Fe||de,function(We,rt){Fe&&(rt=We,We=de[rt]),n(pe,rt,st(We,ue,se,rt,de,ce))}),pe}return Ey=st,Ey}var Cy,aE;function HH(){if(aE)return Cy;aE=1;var e=pI(),t=4;function n(r){return e(r,t)}return Cy=n,Cy}var Ty,oE;function Qb(){if(oE)return Ty;oE=1;function e(t){return function(){return t}}return Ty=e,Ty}var Ry,iE;function WH(){if(iE)return Ry;iE=1;function e(t){return function(n,r,s){for(var l=-1,c=Object(n),u=s(n),f=u.length;f--;){var p=u[t?f:++l];if(r(c[p],p,c)===!1)break}return n}}return Ry=e,Ry}var Ay,lE;function Jb(){if(lE)return Ay;lE=1;var e=WH(),t=e();return Ay=t,Ay}var My,cE;function ek(){if(cE)return My;cE=1;var e=Jb(),t=oo();function n(r,s){return r&&e(r,s,t)}return My=n,My}var Iy,uE;function VH(){if(uE)return Iy;uE=1;var e=da();function t(n,r){return function(s,l){if(s==null)return s;if(!e(s))return n(s,l);for(var c=s.length,u=r?c:-1,f=Object(s);(r?u--:++u<c)&&l(f[u],u,f)!==!1;);return s}}return Iy=t,Iy}var $y,dE;function Uf(){if(dE)return $y;dE=1;var e=ek(),t=VH(),n=t(e);return $y=n,$y}var Oy,hE;function bi(){if(hE)return Oy;hE=1;function e(t){return t}return Oy=e,Oy}var Ly,fE;function mI(){if(fE)return Ly;fE=1;var e=bi();function t(n){return typeof n=="function"?n:e}return Ly=t,Ly}var Py,pE;function gI(){if(pE)return Py;pE=1;var e=Wb(),t=Uf(),n=mI(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c))}return Py=s,Py}var Dy,mE;function yI(){return mE||(mE=1,Dy=gI()),Dy}var Fy,gE;function GH(){if(gE)return Fy;gE=1;var e=Uf();function t(n,r){var s=[];return e(n,function(l,c,u){r(l,c,u)&&s.push(l)}),s}return Fy=t,Fy}var qy,yE;function KH(){if(yE)return qy;yE=1;var e="__lodash_hash_undefined__";function t(n){return this.__data__.set(n,e),this}return qy=t,qy}var By,wE;function YH(){if(wE)return By;wE=1;function e(t){return this.__data__.has(t)}return By=e,By}var zy,vE;function wI(){if(vE)return zy;vE=1;var e=Hb(),t=KH(),n=YH();function r(s){var l=-1,c=s==null?0:s.length;for(this.__data__=new e;++l<c;)this.add(s[l])}return r.prototype.add=r.prototype.push=t,r.prototype.has=n,zy=r,zy}var Uy,xE;function XH(){if(xE)return Uy;xE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length;++r<s;)if(n(t[r],r,t))return!0;return!1}return Uy=e,Uy}var Hy,bE;function vI(){if(bE)return Hy;bE=1;function e(t,n){return t.has(n)}return Hy=e,Hy}var Wy,kE;function xI(){if(kE)return Wy;kE=1;var e=wI(),t=XH(),n=vI(),r=1,s=2;function l(c,u,f,p,h,m){var y=f&r,v=c.length,S=u.length;if(v!=S&&!(y&&S>v))return!1;var b=m.get(c),_=m.get(u);if(b&&_)return b==u&&_==c;var k=-1,j=!0,E=f&s?new e:void 0;for(m.set(c,u),m.set(u,c);++k<v;){var C=c[k],R=u[k];if(p)var I=y?p(R,C,k,u,c,m):p(C,R,k,c,u,m);if(I!==void 0){if(I)continue;j=!1;break}if(E){if(!t(u,function(O,H){if(!n(E,H)&&(C===O||h(C,O,f,p,m)))return E.push(H)})){j=!1;break}}else if(!(C===R||h(C,R,f,p,m))){j=!1;break}}return m.delete(c),m.delete(u),j}return Wy=l,Wy}var Vy,NE;function ZH(){if(NE)return Vy;NE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s,l){r[++n]=[l,s]}),r}return Vy=e,Vy}var Gy,SE;function tk(){if(SE)return Gy;SE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s){r[++n]=s}),r}return Gy=e,Gy}var Ky,jE;function QH(){if(jE)return Ky;jE=1;var e=nc(),t=uI(),n=tc(),r=xI(),s=ZH(),l=tk(),c=1,u=2,f="[object Boolean]",p="[object Date]",h="[object Error]",m="[object Map]",y="[object Number]",v="[object RegExp]",S="[object Set]",b="[object String]",_="[object Symbol]",k="[object ArrayBuffer]",j="[object DataView]",E=e?e.prototype:void 0,C=E?E.valueOf:void 0;function R(I,O,H,q,$,V,ne){switch(H){case j:if(I.byteLength!=O.byteLength||I.byteOffset!=O.byteOffset)return!1;I=I.buffer,O=O.buffer;case k:return!(I.byteLength!=O.byteLength||!V(new t(I),new t(O)));case f:case p:case y:return n(+I,+O);case h:return I.name==O.name&&I.message==O.message;case v:case b:return I==O+"";case m:var ee=s;case S:var M=q&c;if(ee||(ee=l),I.size!=O.size&&!M)return!1;var Z=ne.get(I);if(Z)return Z==O;q|=u,ne.set(I,O);var K=r(ee(I),ee(O),q,$,V,ne);return ne.delete(I),K;case _:if(C)return C.call(I)==C.call(O)}return!1}return Ky=R,Ky}var Yy,_E;function JH(){if(_E)return Yy;_E=1;var e=lI(),t=1,n=Object.prototype,r=n.hasOwnProperty;function s(l,c,u,f,p,h){var m=u&t,y=e(l),v=y.length,S=e(c),b=S.length;if(v!=b&&!m)return!1;for(var _=v;_--;){var k=y[_];if(!(m?k in c:r.call(c,k)))return!1}var j=h.get(l),E=h.get(c);if(j&&E)return j==c&&E==l;var C=!0;h.set(l,c),h.set(c,l);for(var R=m;++_<v;){k=y[_];var I=l[k],O=c[k];if(f)var H=m?f(O,I,k,c,l,h):f(I,O,k,l,c,h);if(!(H===void 0?I===O||p(I,O,u,f,h):H)){C=!1;break}R||(R=k=="constructor")}if(C&&!R){var q=l.constructor,$=c.constructor;q!=$&&"constructor"in l&&"constructor"in c&&!(typeof q=="function"&&q instanceof q&&typeof $=="function"&&$ instanceof $)&&(C=!1)}return h.delete(l),h.delete(c),C}return Yy=s,Yy}var Xy,EE;function eW(){if(EE)return Xy;EE=1;var e=Lf(),t=xI(),n=QH(),r=JH(),s=sc(),l=nn(),c=rc(),u=Vu(),f=1,p="[object Arguments]",h="[object Array]",m="[object Object]",y=Object.prototype,v=y.hasOwnProperty;function S(b,_,k,j,E,C){var R=l(b),I=l(_),O=R?h:s(b),H=I?h:s(_);O=O==p?m:O,H=H==p?m:H;var q=O==m,$=H==m,V=O==H;if(V&&c(b)){if(!c(_))return!1;R=!0,q=!1}if(V&&!q)return C||(C=new e),R||u(b)?t(b,_,k,j,E,C):n(b,_,O,k,j,E,C);if(!(k&f)){var ne=q&&v.call(b,"__wrapped__"),ee=$&&v.call(_,"__wrapped__");if(ne||ee){var M=ne?b.value():b,Z=ee?_.value():_;return C||(C=new e),E(M,Z,k,j,C)}}return V?(C||(C=new e),r(b,_,k,j,E,C)):!1}return Xy=S,Xy}var Zy,CE;function bI(){if(CE)return Zy;CE=1;var e=eW(),t=Us();function n(r,s,l,c,u){return r===s?!0:r==null||s==null||!t(r)&&!t(s)?r!==r&&s!==s:e(r,s,l,c,n,u)}return Zy=n,Zy}var Qy,TE;function tW(){if(TE)return Qy;TE=1;var e=Lf(),t=bI(),n=1,r=2;function s(l,c,u,f){var p=u.length,h=p,m=!f;if(l==null)return!h;for(l=Object(l);p--;){var y=u[p];if(m&&y[2]?y[1]!==l[y[0]]:!(y[0]in l))return!1}for(;++p<h;){y=u[p];var v=y[0],S=l[v],b=y[1];if(m&&y[2]){if(S===void 0&&!(v in l))return!1}else{var _=new e;if(f)var k=f(S,b,v,l,c,_);if(!(k===void 0?t(b,S,n|r,f,_):k))return!1}}return!0}return Qy=s,Qy}var Jy,RE;function kI(){if(RE)return Jy;RE=1;var e=zr();function t(n){return n===n&&!e(n)}return Jy=t,Jy}var ew,AE;function nW(){if(AE)return ew;AE=1;var e=kI(),t=oo();function n(r){for(var s=t(r),l=s.length;l--;){var c=s[l],u=r[c];s[l]=[c,u,e(u)]}return s}return ew=n,ew}var tw,ME;function NI(){if(ME)return tw;ME=1;function e(t,n){return function(r){return r==null?!1:r[t]===n&&(n!==void 0||t in Object(r))}}return tw=e,tw}var nw,IE;function rW(){if(IE)return nw;IE=1;var e=tW(),t=nW(),n=NI();function r(s){var l=t(s);return l.length==1&&l[0][2]?n(l[0][0],l[0][1]):function(c){return c===s||e(c,s,l)}}return nw=r,nw}var rw,$E;function ac(){if($E)return rw;$E=1;var e=wi(),t=Us(),n="[object Symbol]";function r(s){return typeof s=="symbol"||t(s)&&e(s)==n}return rw=r,rw}var sw,OE;function nk(){if(OE)return sw;OE=1;var e=nn(),t=ac(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function s(l,c){if(e(l))return!1;var u=typeof l;return u=="number"||u=="symbol"||u=="boolean"||l==null||t(l)?!0:r.test(l)||!n.test(l)||c!=null&&l in Object(c)}return sw=s,sw}var aw,LE;function sW(){if(LE)return aw;LE=1;var e=Hb(),t="Expected a function";function n(r,s){if(typeof r!="function"||s!=null&&typeof s!="function")throw new TypeError(t);var l=function(){var c=arguments,u=s?s.apply(this,c):c[0],f=l.cache;if(f.has(u))return f.get(u);var p=r.apply(this,c);return l.cache=f.set(u,p)||f,p};return l.cache=new(n.Cache||e),l}return n.Cache=e,aw=n,aw}var ow,PE;function aW(){if(PE)return ow;PE=1;var e=sW(),t=500;function n(r){var s=e(r,function(c){return l.size===t&&l.clear(),c}),l=s.cache;return s}return ow=n,ow}var iw,DE;function oW(){if(DE)return iw;DE=1;var e=aW(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,n=/\\(\\)?/g,r=e(function(s){var l=[];return s.charCodeAt(0)===46&&l.push(""),s.replace(t,function(c,u,f,p){l.push(f?p.replace(n,"$1"):u||c)}),l});return iw=r,iw}var lw,FE;function Hf(){if(FE)return lw;FE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,l=Array(s);++r<s;)l[r]=n(t[r],r,t);return l}return lw=e,lw}var cw,qE;function iW(){if(qE)return cw;qE=1;var e=nc(),t=Hf(),n=nn(),r=ac(),s=e?e.prototype:void 0,l=s?s.toString:void 0;function c(u){if(typeof u=="string")return u;if(n(u))return t(u,c)+"";if(r(u))return l?l.call(u):"";var f=u+"";return f=="0"&&1/u==-1/0?"-0":f}return cw=c,cw}var uw,BE;function SI(){if(BE)return uw;BE=1;var e=iW();function t(n){return n==null?"":e(n)}return uw=t,uw}var dw,zE;function Wf(){if(zE)return dw;zE=1;var e=nn(),t=nk(),n=oW(),r=SI();function s(l,c){return e(l)?l:t(l,c)?[l]:n(r(l))}return dw=s,dw}var hw,UE;function Gu(){if(UE)return hw;UE=1;var e=ac();function t(n){if(typeof n=="string"||e(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}return hw=t,hw}var fw,HE;function Vf(){if(HE)return fw;HE=1;var e=Wf(),t=Gu();function n(r,s){s=e(s,r);for(var l=0,c=s.length;r!=null&&l<c;)r=r[t(s[l++])];return l&&l==c?r:void 0}return fw=n,fw}var pw,WE;function lW(){if(WE)return pw;WE=1;var e=Vf();function t(n,r,s){var l=n==null?void 0:e(n,r);return l===void 0?s:l}return pw=t,pw}var mw,VE;function cW(){if(VE)return mw;VE=1;function e(t,n){return t!=null&&n in Object(t)}return mw=e,mw}var gw,GE;function jI(){if(GE)return gw;GE=1;var e=Wf(),t=Wu(),n=nn(),r=Ff(),s=Vb(),l=Gu();function c(u,f,p){f=e(f,u);for(var h=-1,m=f.length,y=!1;++h<m;){var v=l(f[h]);if(!(y=u!=null&&p(u,v)))break;u=u[v]}return y||++h!=m?y:(m=u==null?0:u.length,!!m&&s(m)&&r(v,m)&&(n(u)||t(u)))}return gw=c,gw}var yw,KE;function _I(){if(KE)return yw;KE=1;var e=cW(),t=jI();function n(r,s){return r!=null&&t(r,s,e)}return yw=n,yw}var ww,YE;function uW(){if(YE)return ww;YE=1;var e=bI(),t=lW(),n=_I(),r=nk(),s=kI(),l=NI(),c=Gu(),u=1,f=2;function p(h,m){return r(h)&&s(m)?l(c(h),m):function(y){var v=t(y,h);return v===void 0&&v===m?n(y,h):e(m,v,u|f)}}return ww=p,ww}var vw,XE;function EI(){if(XE)return vw;XE=1;function e(t){return function(n){return n==null?void 0:n[t]}}return vw=e,vw}var xw,ZE;function dW(){if(ZE)return xw;ZE=1;var e=Vf();function t(n){return function(r){return e(r,n)}}return xw=t,xw}var bw,QE;function hW(){if(QE)return bw;QE=1;var e=EI(),t=dW(),n=nk(),r=Gu();function s(l){return n(l)?e(r(l)):t(l)}return bw=s,bw}var kw,JE;function ha(){if(JE)return kw;JE=1;var e=rW(),t=uW(),n=bi(),r=nn(),s=hW();function l(c){return typeof c=="function"?c:c==null?n:typeof c=="object"?r(c)?t(c[0],c[1]):e(c):s(c)}return kw=l,kw}var Nw,eC;function CI(){if(eC)return Nw;eC=1;var e=sI(),t=GH(),n=ha(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c,3))}return Nw=s,Nw}var Sw,tC;function fW(){if(tC)return Sw;tC=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r,s){return r!=null&&t.call(r,s)}return Sw=n,Sw}var jw,nC;function TI(){if(nC)return jw;nC=1;var e=fW(),t=jI();function n(r,s){return r!=null&&t(r,s,e)}return jw=n,jw}var _w,rC;function pW(){if(rC)return _w;rC=1;var e=Kb(),t=sc(),n=Wu(),r=nn(),s=da(),l=rc(),c=Bf(),u=Vu(),f="[object Map]",p="[object Set]",h=Object.prototype,m=h.hasOwnProperty;function y(v){if(v==null)return!0;if(s(v)&&(r(v)||typeof v=="string"||typeof v.splice=="function"||l(v)||u(v)||n(v)))return!v.length;var S=t(v);if(S==f||S==p)return!v.size;if(c(v))return!e(v).length;for(var b in v)if(m.call(v,b))return!1;return!0}return _w=y,_w}var Ew,sC;function RI(){if(sC)return Ew;sC=1;function e(t){return t===void 0}return Ew=e,Ew}var Cw,aC;function AI(){if(aC)return Cw;aC=1;var e=Uf(),t=da();function n(r,s){var l=-1,c=t(r)?Array(r.length):[];return e(r,function(u,f,p){c[++l]=s(u,f,p)}),c}return Cw=n,Cw}var Tw,oC;function MI(){if(oC)return Tw;oC=1;var e=Hf(),t=ha(),n=AI(),r=nn();function s(l,c){var u=r(l)?e:n;return u(l,t(c,3))}return Tw=s,Tw}var Rw,iC;function mW(){if(iC)return Rw;iC=1;function e(t,n,r,s){var l=-1,c=t==null?0:t.length;for(s&&c&&(r=t[++l]);++l<c;)r=n(r,t[l],l,t);return r}return Rw=e,Rw}var Aw,lC;function gW(){if(lC)return Aw;lC=1;function e(t,n,r,s,l){return l(t,function(c,u,f){r=s?(s=!1,c):n(r,c,u,f)}),r}return Aw=e,Aw}var Mw,cC;function II(){if(cC)return Mw;cC=1;var e=mW(),t=Uf(),n=ha(),r=gW(),s=nn();function l(c,u,f){var p=s(c)?e:r,h=arguments.length<3;return p(c,n(u,4),f,h,t)}return Mw=l,Mw}var Iw,uC;function yW(){if(uC)return Iw;uC=1;var e=wi(),t=nn(),n=Us(),r="[object String]";function s(l){return typeof l=="string"||!t(l)&&n(l)&&e(l)==r}return Iw=s,Iw}var $w,dC;function wW(){if(dC)return $w;dC=1;var e=EI(),t=e("length");return $w=t,$w}var Ow,hC;function vW(){if(hC)return Ow;hC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,l="\\ufe0e\\ufe0f",c="\\u200d",u=RegExp("["+c+e+s+l+"]");function f(p){return u.test(p)}return Ow=f,Ow}var Lw,fC;function xW(){if(fC)return Lw;fC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,l="\\ufe0e\\ufe0f",c="["+e+"]",u="["+s+"]",f="\\ud83c[\\udffb-\\udfff]",p="(?:"+u+"|"+f+")",h="[^"+e+"]",m="(?:\\ud83c[\\udde6-\\uddff]){2}",y="[\\ud800-\\udbff][\\udc00-\\udfff]",v="\\u200d",S=p+"?",b="["+l+"]?",_="(?:"+v+"(?:"+[h,m,y].join("|")+")"+b+S+")*",k=b+S+_,j="(?:"+[h+u+"?",u,m,y,c].join("|")+")",E=RegExp(f+"(?="+f+")|"+j+k,"g");function C(R){for(var I=E.lastIndex=0;E.test(R);)++I;return I}return Lw=C,Lw}var Pw,pC;function bW(){if(pC)return Pw;pC=1;var e=wW(),t=vW(),n=xW();function r(s){return t(s)?n(s):e(s)}return Pw=r,Pw}var Dw,mC;function kW(){if(mC)return Dw;mC=1;var e=Kb(),t=sc(),n=da(),r=yW(),s=bW(),l="[object Map]",c="[object Set]";function u(f){if(f==null)return 0;if(n(f))return r(f)?s(f):f.length;var p=t(f);return p==l||p==c?f.size:e(f).length}return Dw=u,Dw}var Fw,gC;function NW(){if(gC)return Fw;gC=1;var e=Wb(),t=hI(),n=ek(),r=ha(),s=zf(),l=nn(),c=rc(),u=Uu(),f=zr(),p=Vu();function h(m,y,v){var S=l(m),b=S||c(m)||p(m);if(y=r(y,4),v==null){var _=m&&m.constructor;b?v=S?new _:[]:f(m)?v=u(_)?t(s(m)):{}:v={}}return(b?e:n)(m,function(k,j,E){return y(v,k,j,E)}),v}return Fw=h,Fw}var qw,yC;function SW(){if(yC)return qw;yC=1;var e=nc(),t=Wu(),n=nn(),r=e?e.isConcatSpreadable:void 0;function s(l){return n(l)||t(l)||!!(r&&l&&l[r])}return qw=s,qw}var Bw,wC;function rk(){if(wC)return Bw;wC=1;var e=Xb(),t=SW();function n(r,s,l,c,u){var f=-1,p=r.length;for(l||(l=t),u||(u=[]);++f<p;){var h=r[f];s>0&&l(h)?s>1?n(h,s-1,l,c,u):e(u,h):c||(u[u.length]=h)}return u}return Bw=n,Bw}var zw,vC;function jW(){if(vC)return zw;vC=1;function e(t,n,r){switch(r.length){case 0:return t.call(n);case 1:return t.call(n,r[0]);case 2:return t.call(n,r[0],r[1]);case 3:return t.call(n,r[0],r[1],r[2])}return t.apply(n,r)}return zw=e,zw}var Uw,xC;function $I(){if(xC)return Uw;xC=1;var e=jW(),t=Math.max;function n(r,s,l){return s=t(s===void 0?r.length-1:s,0),function(){for(var c=arguments,u=-1,f=t(c.length-s,0),p=Array(f);++u<f;)p[u]=c[s+u];u=-1;for(var h=Array(s+1);++u<s;)h[u]=c[u];return h[s]=l(p),e(r,this,h)}}return Uw=n,Uw}var Hw,bC;function _W(){if(bC)return Hw;bC=1;var e=Qb(),t=JM(),n=bi(),r=t?function(s,l){return t(s,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:n;return Hw=r,Hw}var Ww,kC;function EW(){if(kC)return Ww;kC=1;var e=800,t=16,n=Date.now;function r(s){var l=0,c=0;return function(){var u=n(),f=t-(u-c);if(c=u,f>0){if(++l>=e)return arguments[0]}else l=0;return s.apply(void 0,arguments)}}return Ww=r,Ww}var Vw,NC;function OI(){if(NC)return Vw;NC=1;var e=_W(),t=EW(),n=t(e);return Vw=n,Vw}var Gw,SC;function Gf(){if(SC)return Gw;SC=1;var e=bi(),t=$I(),n=OI();function r(s,l){return n(t(s,l,e),s+"")}return Gw=r,Gw}var Kw,jC;function LI(){if(jC)return Kw;jC=1;function e(t,n,r,s){for(var l=t.length,c=r+(s?1:-1);s?c--:++c<l;)if(n(t[c],c,t))return c;return-1}return Kw=e,Kw}var Yw,_C;function CW(){if(_C)return Yw;_C=1;function e(t){return t!==t}return Yw=e,Yw}var Xw,EC;function TW(){if(EC)return Xw;EC=1;function e(t,n,r){for(var s=r-1,l=t.length;++s<l;)if(t[s]===n)return s;return-1}return Xw=e,Xw}var Zw,CC;function RW(){if(CC)return Zw;CC=1;var e=LI(),t=CW(),n=TW();function r(s,l,c){return l===l?n(s,l,c):e(s,t,c)}return Zw=r,Zw}var Qw,TC;function AW(){if(TC)return Qw;TC=1;var e=RW();function t(n,r){var s=n==null?0:n.length;return!!s&&e(n,r,0)>-1}return Qw=t,Qw}var Jw,RC;function MW(){if(RC)return Jw;RC=1;function e(t,n,r){for(var s=-1,l=t==null?0:t.length;++s<l;)if(r(n,t[s]))return!0;return!1}return Jw=e,Jw}var ev,AC;function IW(){if(AC)return ev;AC=1;function e(){}return ev=e,ev}var tv,MC;function $W(){if(MC)return tv;MC=1;var e=cI(),t=IW(),n=tk(),r=1/0,s=e&&1/n(new e([,-0]))[1]==r?function(l){return new e(l)}:t;return tv=s,tv}var nv,IC;function OW(){if(IC)return nv;IC=1;var e=wI(),t=AW(),n=MW(),r=vI(),s=$W(),l=tk(),c=200;function u(f,p,h){var m=-1,y=t,v=f.length,S=!0,b=[],_=b;if(h)S=!1,y=n;else if(v>=c){var k=p?null:s(f);if(k)return l(k);S=!1,y=r,_=new e}else _=p?[]:b;e:for(;++m<v;){var j=f[m],E=p?p(j):j;if(j=h||j!==0?j:0,S&&E===E){for(var C=_.length;C--;)if(_[C]===E)continue e;p&&_.push(E),b.push(j)}else y(_,E,h)||(_!==b&&_.push(E),b.push(j))}return b}return nv=u,nv}var rv,$C;function PI(){if($C)return rv;$C=1;var e=da(),t=Us();function n(r){return t(r)&&e(r)}return rv=n,rv}var sv,OC;function LW(){if(OC)return sv;OC=1;var e=rk(),t=Gf(),n=OW(),r=PI(),s=t(function(l){return n(e(l,1,r,!0))});return sv=s,sv}var av,LC;function PW(){if(LC)return av;LC=1;var e=Hf();function t(n,r){return e(r,function(s){return n[s]})}return av=t,av}var ov,PC;function DI(){if(PC)return ov;PC=1;var e=PW(),t=oo();function n(r){return r==null?[]:e(r,t(r))}return ov=n,ov}var iv,DC;function Ur(){if(DC)return iv;DC=1;var e;if(typeof zb=="function")try{e={clone:HH(),constant:Qb(),each:yI(),filter:CI(),has:TI(),isArray:nn(),isEmpty:pW(),isFunction:Uu(),isUndefined:RI(),keys:oo(),map:MI(),reduce:II(),size:kW(),transform:NW(),union:LW(),values:DI()}}catch{}return e||(e=window._),iv=e,iv}var lv,FC;function sk(){if(FC)return lv;FC=1;var e=Ur();lv=s;var t="\0",n="\0",r="";function s(h){this._isDirected=e.has(h,"directed")?h.directed:!0,this._isMultigraph=e.has(h,"multigraph")?h.multigraph:!1,this._isCompound=e.has(h,"compound")?h.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[n]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}s.prototype._nodeCount=0,s.prototype._edgeCount=0,s.prototype.isDirected=function(){return this._isDirected},s.prototype.isMultigraph=function(){return this._isMultigraph},s.prototype.isCompound=function(){return this._isCompound},s.prototype.setGraph=function(h){return this._label=h,this},s.prototype.graph=function(){return this._label},s.prototype.setDefaultNodeLabel=function(h){return e.isFunction(h)||(h=e.constant(h)),this._defaultNodeLabelFn=h,this},s.prototype.nodeCount=function(){return this._nodeCount},s.prototype.nodes=function(){return e.keys(this._nodes)},s.prototype.sources=function(){var h=this;return e.filter(this.nodes(),function(m){return e.isEmpty(h._in[m])})},s.prototype.sinks=function(){var h=this;return e.filter(this.nodes(),function(m){return e.isEmpty(h._out[m])})},s.prototype.setNodes=function(h,m){var y=arguments,v=this;return e.each(h,function(S){y.length>1?v.setNode(S,m):v.setNode(S)}),this},s.prototype.setNode=function(h,m){return e.has(this._nodes,h)?(arguments.length>1&&(this._nodes[h]=m),this):(this._nodes[h]=arguments.length>1?m:this._defaultNodeLabelFn(h),this._isCompound&&(this._parent[h]=n,this._children[h]={},this._children[n][h]=!0),this._in[h]={},this._preds[h]={},this._out[h]={},this._sucs[h]={},++this._nodeCount,this)},s.prototype.node=function(h){return this._nodes[h]},s.prototype.hasNode=function(h){return e.has(this._nodes,h)},s.prototype.removeNode=function(h){var m=this;if(e.has(this._nodes,h)){var y=function(v){m.removeEdge(m._edgeObjs[v])};delete this._nodes[h],this._isCompound&&(this._removeFromParentsChildList(h),delete this._parent[h],e.each(this.children(h),function(v){m.setParent(v)}),delete this._children[h]),e.each(e.keys(this._in[h]),y),delete this._in[h],delete this._preds[h],e.each(e.keys(this._out[h]),y),delete this._out[h],delete this._sucs[h],--this._nodeCount}return this},s.prototype.setParent=function(h,m){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(m))m=n;else{m+="";for(var y=m;!e.isUndefined(y);y=this.parent(y))if(y===h)throw new Error("Setting "+m+" as parent of "+h+" would create a cycle");this.setNode(m)}return this.setNode(h),this._removeFromParentsChildList(h),this._parent[h]=m,this._children[m][h]=!0,this},s.prototype._removeFromParentsChildList=function(h){delete this._children[this._parent[h]][h]},s.prototype.parent=function(h){if(this._isCompound){var m=this._parent[h];if(m!==n)return m}},s.prototype.children=function(h){if(e.isUndefined(h)&&(h=n),this._isCompound){var m=this._children[h];if(m)return e.keys(m)}else{if(h===n)return this.nodes();if(this.hasNode(h))return[]}},s.prototype.predecessors=function(h){var m=this._preds[h];if(m)return e.keys(m)},s.prototype.successors=function(h){var m=this._sucs[h];if(m)return e.keys(m)},s.prototype.neighbors=function(h){var m=this.predecessors(h);if(m)return e.union(m,this.successors(h))},s.prototype.isLeaf=function(h){var m;return this.isDirected()?m=this.successors(h):m=this.neighbors(h),m.length===0},s.prototype.filterNodes=function(h){var m=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});m.setGraph(this.graph());var y=this;e.each(this._nodes,function(b,_){h(_)&&m.setNode(_,b)}),e.each(this._edgeObjs,function(b){m.hasNode(b.v)&&m.hasNode(b.w)&&m.setEdge(b,y.edge(b))});var v={};function S(b){var _=y.parent(b);return _===void 0||m.hasNode(_)?(v[b]=_,_):_ in v?v[_]:S(_)}return this._isCompound&&e.each(m.nodes(),function(b){m.setParent(b,S(b))}),m},s.prototype.setDefaultEdgeLabel=function(h){return e.isFunction(h)||(h=e.constant(h)),this._defaultEdgeLabelFn=h,this},s.prototype.edgeCount=function(){return this._edgeCount},s.prototype.edges=function(){return e.values(this._edgeObjs)},s.prototype.setPath=function(h,m){var y=this,v=arguments;return e.reduce(h,function(S,b){return v.length>1?y.setEdge(S,b,m):y.setEdge(S,b),b}),this},s.prototype.setEdge=function(){var h,m,y,v,S=!1,b=arguments[0];typeof b=="object"&&b!==null&&"v"in b?(h=b.v,m=b.w,y=b.name,arguments.length===2&&(v=arguments[1],S=!0)):(h=b,m=arguments[1],y=arguments[3],arguments.length>2&&(v=arguments[2],S=!0)),h=""+h,m=""+m,e.isUndefined(y)||(y=""+y);var _=u(this._isDirected,h,m,y);if(e.has(this._edgeLabels,_))return S&&(this._edgeLabels[_]=v),this;if(!e.isUndefined(y)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(h),this.setNode(m),this._edgeLabels[_]=S?v:this._defaultEdgeLabelFn(h,m,y);var k=f(this._isDirected,h,m,y);return h=k.v,m=k.w,Object.freeze(k),this._edgeObjs[_]=k,l(this._preds[m],h),l(this._sucs[h],m),this._in[m][_]=k,this._out[h][_]=k,this._edgeCount++,this},s.prototype.edge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y);return this._edgeLabels[v]},s.prototype.hasEdge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y);return e.has(this._edgeLabels,v)},s.prototype.removeEdge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y),S=this._edgeObjs[v];return S&&(h=S.v,m=S.w,delete this._edgeLabels[v],delete this._edgeObjs[v],c(this._preds[m],h),c(this._sucs[h],m),delete this._in[m][v],delete this._out[h][v],this._edgeCount--),this},s.prototype.inEdges=function(h,m){var y=this._in[h];if(y){var v=e.values(y);return m?e.filter(v,function(S){return S.v===m}):v}},s.prototype.outEdges=function(h,m){var y=this._out[h];if(y){var v=e.values(y);return m?e.filter(v,function(S){return S.w===m}):v}},s.prototype.nodeEdges=function(h,m){var y=this.inEdges(h,m);if(y)return y.concat(this.outEdges(h,m))};function l(h,m){h[m]?h[m]++:h[m]=1}function c(h,m){--h[m]||delete h[m]}function u(h,m,y,v){var S=""+m,b=""+y;if(!h&&S>b){var _=S;S=b,b=_}return S+r+b+r+(e.isUndefined(v)?t:v)}function f(h,m,y,v){var S=""+m,b=""+y;if(!h&&S>b){var _=S;S=b,b=_}var k={v:S,w:b};return v&&(k.name=v),k}function p(h,m){return u(h,m.v,m.w,m.name)}return lv}var cv,qC;function DW(){return qC||(qC=1,cv="2.1.8"),cv}var uv,BC;function FW(){return BC||(BC=1,uv={Graph:sk(),version:DW()}),uv}var dv,zC;function qW(){if(zC)return dv;zC=1;var e=Ur(),t=sk();dv={write:n,read:l};function n(c){var u={options:{directed:c.isDirected(),multigraph:c.isMultigraph(),compound:c.isCompound()},nodes:r(c),edges:s(c)};return e.isUndefined(c.graph())||(u.value=e.clone(c.graph())),u}function r(c){return e.map(c.nodes(),function(u){var f=c.node(u),p=c.parent(u),h={v:u};return e.isUndefined(f)||(h.value=f),e.isUndefined(p)||(h.parent=p),h})}function s(c){return e.map(c.edges(),function(u){var f=c.edge(u),p={v:u.v,w:u.w};return e.isUndefined(u.name)||(p.name=u.name),e.isUndefined(f)||(p.value=f),p})}function l(c){var u=new t(c.options).setGraph(c.value);return e.each(c.nodes,function(f){u.setNode(f.v,f.value),f.parent&&u.setParent(f.v,f.parent)}),e.each(c.edges,function(f){u.setEdge({v:f.v,w:f.w,name:f.name},f.value)}),u}return dv}var hv,UC;function BW(){if(UC)return hv;UC=1;var e=Ur();hv=t;function t(n){var r={},s=[],l;function c(u){e.has(r,u)||(r[u]=!0,l.push(u),e.each(n.successors(u),c),e.each(n.predecessors(u),c))}return e.each(n.nodes(),function(u){l=[],c(u),l.length&&s.push(l)}),s}return hv}var fv,HC;function FI(){if(HC)return fv;HC=1;var e=Ur();fv=t;function t(){this._arr=[],this._keyIndices={}}return t.prototype.size=function(){return this._arr.length},t.prototype.keys=function(){return this._arr.map(function(n){return n.key})},t.prototype.has=function(n){return e.has(this._keyIndices,n)},t.prototype.priority=function(n){var r=this._keyIndices[n];if(r!==void 0)return this._arr[r].priority},t.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},t.prototype.add=function(n,r){var s=this._keyIndices;if(n=String(n),!e.has(s,n)){var l=this._arr,c=l.length;return s[n]=c,l.push({key:n,priority:r}),this._decrease(c),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var n=this._arr.pop();return delete this._keyIndices[n.key],this._heapify(0),n.key},t.prototype.decrease=function(n,r){var s=this._keyIndices[n];if(r>this._arr[s].priority)throw new Error("New priority is greater than current priority. Key: "+n+" Old: "+this._arr[s].priority+" New: "+r);this._arr[s].priority=r,this._decrease(s)},t.prototype._heapify=function(n){var r=this._arr,s=2*n,l=s+1,c=n;s<r.length&&(c=r[s].priority<r[c].priority?s:c,l<r.length&&(c=r[l].priority<r[c].priority?l:c),c!==n&&(this._swap(n,c),this._heapify(c)))},t.prototype._decrease=function(n){for(var r=this._arr,s=r[n].priority,l;n!==0&&(l=n>>1,!(r[l].priority<s));)this._swap(n,l),n=l},t.prototype._swap=function(n,r){var s=this._arr,l=this._keyIndices,c=s[n],u=s[r];s[n]=u,s[r]=c,l[u.key]=n,l[c.key]=r},fv}var pv,WC;function qI(){if(WC)return pv;WC=1;var e=Ur(),t=FI();pv=r;var n=e.constant(1);function r(l,c,u,f){return s(l,String(c),u||n,f||function(p){return l.outEdges(p)})}function s(l,c,u,f){var p={},h=new t,m,y,v=function(S){var b=S.v!==m?S.v:S.w,_=p[b],k=u(S),j=y.distance+k;if(k<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+S+" Weight: "+k);j<_.distance&&(_.distance=j,_.predecessor=m,h.decrease(b,j))};for(l.nodes().forEach(function(S){var b=S===c?0:Number.POSITIVE_INFINITY;p[S]={distance:b},h.add(S,b)});h.size()>0&&(m=h.removeMin(),y=p[m],y.distance!==Number.POSITIVE_INFINITY);)f(m).forEach(v);return p}return pv}var mv,VC;function zW(){if(VC)return mv;VC=1;var e=qI(),t=Ur();mv=n;function n(r,s,l){return t.transform(r.nodes(),function(c,u){c[u]=e(r,u,s,l)},{})}return mv}var gv,GC;function BI(){if(GC)return gv;GC=1;var e=Ur();gv=t;function t(n){var r=0,s=[],l={},c=[];function u(f){var p=l[f]={onStack:!0,lowlink:r,index:r++};if(s.push(f),n.successors(f).forEach(function(y){e.has(l,y)?l[y].onStack&&(p.lowlink=Math.min(p.lowlink,l[y].index)):(u(y),p.lowlink=Math.min(p.lowlink,l[y].lowlink))}),p.lowlink===p.index){var h=[],m;do m=s.pop(),l[m].onStack=!1,h.push(m);while(f!==m);c.push(h)}}return n.nodes().forEach(function(f){e.has(l,f)||u(f)}),c}return gv}var yv,KC;function UW(){if(KC)return yv;KC=1;var e=Ur(),t=BI();yv=n;function n(r){return e.filter(t(r),function(s){return s.length>1||s.length===1&&r.hasEdge(s[0],s[0])})}return yv}var wv,YC;function HW(){if(YC)return wv;YC=1;var e=Ur();wv=n;var t=e.constant(1);function n(s,l,c){return r(s,l||t,c||function(u){return s.outEdges(u)})}function r(s,l,c){var u={},f=s.nodes();return f.forEach(function(p){u[p]={},u[p][p]={distance:0},f.forEach(function(h){p!==h&&(u[p][h]={distance:Number.POSITIVE_INFINITY})}),c(p).forEach(function(h){var m=h.v===p?h.w:h.v,y=l(h);u[p][m]={distance:y,predecessor:p}})}),f.forEach(function(p){var h=u[p];f.forEach(function(m){var y=u[m];f.forEach(function(v){var S=y[p],b=h[v],_=y[v],k=S.distance+b.distance;k<_.distance&&(_.distance=k,_.predecessor=b.predecessor)})})}),u}return wv}var vv,XC;function zI(){if(XC)return vv;XC=1;var e=Ur();vv=t,t.CycleException=n;function t(r){var s={},l={},c=[];function u(f){if(e.has(l,f))throw new n;e.has(s,f)||(l[f]=!0,s[f]=!0,e.each(r.predecessors(f),u),delete l[f],c.push(f))}if(e.each(r.sinks(),u),e.size(s)!==r.nodeCount())throw new n;return c}function n(){}return n.prototype=new Error,vv}var xv,ZC;function WW(){if(ZC)return xv;ZC=1;var e=zI();xv=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return xv}var bv,QC;function UI(){if(QC)return bv;QC=1;var e=Ur();bv=t;function t(r,s,l){e.isArray(s)||(s=[s]);var c=(r.isDirected()?r.successors:r.neighbors).bind(r),u=[],f={};return e.each(s,function(p){if(!r.hasNode(p))throw new Error("Graph does not have node: "+p);n(r,p,l==="post",f,c,u)}),u}function n(r,s,l,c,u,f){e.has(c,s)||(c[s]=!0,l||f.push(s),e.each(u(s),function(p){n(r,p,l,c,u,f)}),l&&f.push(s))}return bv}var kv,JC;function VW(){if(JC)return kv;JC=1;var e=UI();kv=t;function t(n,r){return e(n,r,"post")}return kv}var Nv,eT;function GW(){if(eT)return Nv;eT=1;var e=UI();Nv=t;function t(n,r){return e(n,r,"pre")}return Nv}var Sv,tT;function KW(){if(tT)return Sv;tT=1;var e=Ur(),t=sk(),n=FI();Sv=r;function r(s,l){var c=new t,u={},f=new n,p;function h(y){var v=y.v===p?y.w:y.v,S=f.priority(v);if(S!==void 0){var b=l(y);b<S&&(u[v]=p,f.decrease(v,b))}}if(s.nodeCount()===0)return c;e.each(s.nodes(),function(y){f.add(y,Number.POSITIVE_INFINITY),c.setNode(y)}),f.decrease(s.nodes()[0],0);for(var m=!1;f.size()>0;){if(p=f.removeMin(),e.has(u,p))c.setEdge(p,u[p]);else{if(m)throw new Error("Input graph is not connected: "+s);m=!0}s.nodeEdges(p).forEach(h)}return c}return Sv}var jv,nT;function YW(){return nT||(nT=1,jv={components:BW(),dijkstra:qI(),dijkstraAll:zW(),findCycles:UW(),floydWarshall:HW(),isAcyclic:WW(),postorder:VW(),preorder:GW(),prim:KW(),tarjan:BI(),topsort:zI()}),jv}var _v,rT;function XW(){if(rT)return _v;rT=1;var e=FW();return _v={Graph:e.Graph,json:qW(),alg:YW(),version:e.version},_v}var Ev,sT;function vs(){if(sT)return Ev;sT=1;var e;if(typeof zb=="function")try{e=XW()}catch{}return e||(e=window.graphlib),Ev=e,Ev}var Cv,aT;function ZW(){if(aT)return Cv;aT=1;var e=pI(),t=1,n=4;function r(s){return e(s,t|n)}return Cv=r,Cv}var Tv,oT;function Kf(){if(oT)return Tv;oT=1;var e=tc(),t=da(),n=Ff(),r=zr();function s(l,c,u){if(!r(u))return!1;var f=typeof c;return(f=="number"?t(u)&&n(c,u.length):f=="string"&&c in u)?e(u[c],l):!1}return Tv=s,Tv}var Rv,iT;function QW(){if(iT)return Rv;iT=1;var e=Gf(),t=tc(),n=Kf(),r=xi(),s=Object.prototype,l=s.hasOwnProperty,c=e(function(u,f){u=Object(u);var p=-1,h=f.length,m=h>2?f[2]:void 0;for(m&&n(f[0],f[1],m)&&(h=1);++p<h;)for(var y=f[p],v=r(y),S=-1,b=v.length;++S<b;){var _=v[S],k=u[_];(k===void 0||t(k,s[_])&&!l.call(u,_))&&(u[_]=y[_])}return u});return Rv=c,Rv}var Av,lT;function JW(){if(lT)return Av;lT=1;var e=ha(),t=da(),n=oo();function r(s){return function(l,c,u){var f=Object(l);if(!t(l)){var p=e(c,3);l=n(l),c=function(m){return p(f[m],m,f)}}var h=s(l,c,u);return h>-1?f[p?l[h]:h]:void 0}}return Av=r,Av}var Mv,cT;function e7(){if(cT)return Mv;cT=1;var e=/\s/;function t(n){for(var r=n.length;r--&&e.test(n.charAt(r)););return r}return Mv=t,Mv}var Iv,uT;function t7(){if(uT)return Iv;uT=1;var e=e7(),t=/^\s+/;function n(r){return r&&r.slice(0,e(r)+1).replace(t,"")}return Iv=n,Iv}var $v,dT;function n7(){if(dT)return $v;dT=1;var e=t7(),t=zr(),n=ac(),r=NaN,s=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,c=/^0o[0-7]+$/i,u=parseInt;function f(p){if(typeof p=="number")return p;if(n(p))return r;if(t(p)){var h=typeof p.valueOf=="function"?p.valueOf():p;p=t(h)?h+"":h}if(typeof p!="string")return p===0?p:+p;p=e(p);var m=l.test(p);return m||c.test(p)?u(p.slice(2),m?2:8):s.test(p)?r:+p}return $v=f,$v}var Ov,hT;function HI(){if(hT)return Ov;hT=1;var e=n7(),t=1/0,n=17976931348623157e292;function r(s){if(!s)return s===0?s:0;if(s=e(s),s===t||s===-t){var l=s<0?-1:1;return l*n}return s===s?s:0}return Ov=r,Ov}var Lv,fT;function r7(){if(fT)return Lv;fT=1;var e=HI();function t(n){var r=e(n),s=r%1;return r===r?s?r-s:r:0}return Lv=t,Lv}var Pv,pT;function s7(){if(pT)return Pv;pT=1;var e=LI(),t=ha(),n=r7(),r=Math.max;function s(l,c,u){var f=l==null?0:l.length;if(!f)return-1;var p=u==null?0:n(u);return p<0&&(p=r(f+p,0)),e(l,t(c,3),p)}return Pv=s,Pv}var Dv,mT;function a7(){if(mT)return Dv;mT=1;var e=JW(),t=s7(),n=e(t);return Dv=n,Dv}var Fv,gT;function WI(){if(gT)return Fv;gT=1;var e=rk();function t(n){var r=n==null?0:n.length;return r?e(n,1):[]}return Fv=t,Fv}var qv,yT;function o7(){if(yT)return qv;yT=1;var e=Jb(),t=mI(),n=xi();function r(s,l){return s==null?s:e(s,t(l),n)}return qv=r,qv}var Bv,wT;function i7(){if(wT)return Bv;wT=1;function e(t){var n=t==null?0:t.length;return n?t[n-1]:void 0}return Bv=e,Bv}var zv,vT;function l7(){if(vT)return zv;vT=1;var e=Pf(),t=ek(),n=ha();function r(s,l){var c={};return l=n(l,3),t(s,function(u,f,p){e(c,f,l(u,f,p))}),c}return zv=r,zv}var Uv,xT;function ak(){if(xT)return Uv;xT=1;var e=ac();function t(n,r,s){for(var l=-1,c=n.length;++l<c;){var u=n[l],f=r(u);if(f!=null&&(p===void 0?f===f&&!e(f):s(f,p)))var p=f,h=u}return h}return Uv=t,Uv}var Hv,bT;function c7(){if(bT)return Hv;bT=1;function e(t,n){return t>n}return Hv=e,Hv}var Wv,kT;function u7(){if(kT)return Wv;kT=1;var e=ak(),t=c7(),n=bi();function r(s){return s&&s.length?e(s,n,t):void 0}return Wv=r,Wv}var Vv,NT;function VI(){if(NT)return Vv;NT=1;var e=Pf(),t=tc();function n(r,s,l){(l!==void 0&&!t(r[s],l)||l===void 0&&!(s in r))&&e(r,s,l)}return Vv=n,Vv}var Gv,ST;function d7(){if(ST)return Gv;ST=1;var e=wi(),t=zf(),n=Us(),r="[object Object]",s=Function.prototype,l=Object.prototype,c=s.toString,u=l.hasOwnProperty,f=c.call(Object);function p(h){if(!n(h)||e(h)!=r)return!1;var m=t(h);if(m===null)return!0;var y=u.call(m,"constructor")&&m.constructor;return typeof y=="function"&&y instanceof y&&c.call(y)==f}return Gv=p,Gv}var Kv,jT;function GI(){if(jT)return Kv;jT=1;function e(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}return Kv=e,Kv}var Yv,_T;function h7(){if(_T)return Yv;_T=1;var e=Hu(),t=xi();function n(r){return e(r,t(r))}return Yv=n,Yv}var Xv,ET;function f7(){if(ET)return Xv;ET=1;var e=VI(),t=nI(),n=dI(),r=rI(),s=fI(),l=Wu(),c=nn(),u=PI(),f=rc(),p=Uu(),h=zr(),m=d7(),y=Vu(),v=GI(),S=h7();function b(_,k,j,E,C,R,I){var O=v(_,j),H=v(k,j),q=I.get(H);if(q){e(_,j,q);return}var $=R?R(O,H,j+"",_,k,I):void 0,V=$===void 0;if(V){var ne=c(H),ee=!ne&&f(H),M=!ne&&!ee&&y(H);$=H,ne||ee||M?c(O)?$=O:u(O)?$=r(O):ee?(V=!1,$=t(H,!0)):M?(V=!1,$=n(H,!0)):$=[]:m(H)||l(H)?($=O,l(O)?$=S(O):(!h(O)||p(O))&&($=s(H))):V=!1}V&&(I.set(H,$),C($,H,E,R,I),I.delete(H)),e(_,j,$)}return Xv=b,Xv}var Zv,CT;function p7(){if(CT)return Zv;CT=1;var e=Lf(),t=VI(),n=Jb(),r=f7(),s=zr(),l=xi(),c=GI();function u(f,p,h,m,y){f!==p&&n(p,function(v,S){if(y||(y=new e),s(v))r(f,p,S,h,u,m,y);else{var b=m?m(c(f,S),v,S+"",f,p,y):void 0;b===void 0&&(b=v),t(f,S,b)}},l)}return Zv=u,Zv}var Qv,TT;function m7(){if(TT)return Qv;TT=1;var e=Gf(),t=Kf();function n(r){return e(function(s,l){var c=-1,u=l.length,f=u>1?l[u-1]:void 0,p=u>2?l[2]:void 0;for(f=r.length>3&&typeof f=="function"?(u--,f):void 0,p&&t(l[0],l[1],p)&&(f=u<3?void 0:f,u=1),s=Object(s);++c<u;){var h=l[c];h&&r(s,h,c,f)}return s})}return Qv=n,Qv}var Jv,RT;function g7(){if(RT)return Jv;RT=1;var e=p7(),t=m7(),n=t(function(r,s,l){e(r,s,l)});return Jv=n,Jv}var ex,AT;function KI(){if(AT)return ex;AT=1;function e(t,n){return t<n}return ex=e,ex}var tx,MT;function y7(){if(MT)return tx;MT=1;var e=ak(),t=KI(),n=bi();function r(s){return s&&s.length?e(s,n,t):void 0}return tx=r,tx}var nx,IT;function w7(){if(IT)return nx;IT=1;var e=ak(),t=ha(),n=KI();function r(s,l){return s&&s.length?e(s,t(l,2),n):void 0}return nx=r,nx}var rx,$T;function v7(){if($T)return rx;$T=1;var e=bs(),t=function(){return e.Date.now()};return rx=t,rx}var sx,OT;function x7(){if(OT)return sx;OT=1;var e=Df(),t=Wf(),n=Ff(),r=zr(),s=Gu();function l(c,u,f,p){if(!r(c))return c;u=t(u,c);for(var h=-1,m=u.length,y=m-1,v=c;v!=null&&++h<m;){var S=s(u[h]),b=f;if(S==="__proto__"||S==="constructor"||S==="prototype")return c;if(h!=y){var _=v[S];b=p?p(_,S,v):void 0,b===void 0&&(b=r(_)?_:n(u[h+1])?[]:{})}e(v,S,b),v=v[S]}return c}return sx=l,sx}var ax,LT;function b7(){if(LT)return ax;LT=1;var e=Vf(),t=x7(),n=Wf();function r(s,l,c){for(var u=-1,f=l.length,p={};++u<f;){var h=l[u],m=e(s,h);c(m,h)&&t(p,n(h,s),m)}return p}return ax=r,ax}var ox,PT;function k7(){if(PT)return ox;PT=1;var e=b7(),t=_I();function n(r,s){return e(r,s,function(l,c){return t(r,c)})}return ox=n,ox}var ix,DT;function N7(){if(DT)return ix;DT=1;var e=WI(),t=$I(),n=OI();function r(s){return n(t(s,void 0,e),s+"")}return ix=r,ix}var lx,FT;function S7(){if(FT)return lx;FT=1;var e=k7(),t=N7(),n=t(function(r,s){return r==null?{}:e(r,s)});return lx=n,lx}var cx,qT;function j7(){if(qT)return cx;qT=1;var e=Math.ceil,t=Math.max;function n(r,s,l,c){for(var u=-1,f=t(e((s-r)/(l||1)),0),p=Array(f);f--;)p[c?f:++u]=r,r+=l;return p}return cx=n,cx}var ux,BT;function _7(){if(BT)return ux;BT=1;var e=j7(),t=Kf(),n=HI();function r(s){return function(l,c,u){return u&&typeof u!="number"&&t(l,c,u)&&(c=u=void 0),l=n(l),c===void 0?(c=l,l=0):c=n(c),u=u===void 0?l<c?1:-1:n(u),e(l,c,u,s)}}return ux=r,ux}var dx,zT;function E7(){if(zT)return dx;zT=1;var e=_7(),t=e();return dx=t,dx}var hx,UT;function C7(){if(UT)return hx;UT=1;function e(t,n){var r=t.length;for(t.sort(n);r--;)t[r]=t[r].value;return t}return hx=e,hx}var fx,HT;function T7(){if(HT)return fx;HT=1;var e=ac();function t(n,r){if(n!==r){var s=n!==void 0,l=n===null,c=n===n,u=e(n),f=r!==void 0,p=r===null,h=r===r,m=e(r);if(!p&&!m&&!u&&n>r||u&&f&&h&&!p&&!m||l&&f&&h||!s&&h||!c)return 1;if(!l&&!u&&!m&&n<r||m&&s&&c&&!l&&!u||p&&s&&c||!f&&c||!h)return-1}return 0}return fx=t,fx}var px,WT;function R7(){if(WT)return px;WT=1;var e=T7();function t(n,r,s){for(var l=-1,c=n.criteria,u=r.criteria,f=c.length,p=s.length;++l<f;){var h=e(c[l],u[l]);if(h){if(l>=p)return h;var m=s[l];return h*(m=="desc"?-1:1)}}return n.index-r.index}return px=t,px}var mx,VT;function A7(){if(VT)return mx;VT=1;var e=Hf(),t=Vf(),n=ha(),r=AI(),s=C7(),l=qf(),c=R7(),u=bi(),f=nn();function p(h,m,y){m.length?m=e(m,function(b){return f(b)?function(_){return t(_,b.length===1?b[0]:b)}:b}):m=[u];var v=-1;m=e(m,l(n));var S=r(h,function(b,_,k){var j=e(m,function(E){return E(b)});return{criteria:j,index:++v,value:b}});return s(S,function(b,_){return c(b,_,y)})}return mx=p,mx}var gx,GT;function M7(){if(GT)return gx;GT=1;var e=rk(),t=A7(),n=Gf(),r=Kf(),s=n(function(l,c){if(l==null)return[];var u=c.length;return u>1&&r(l,c[0],c[1])?c=[]:u>2&&r(c[0],c[1],c[2])&&(c=[c[0]]),t(l,e(c,1),[])});return gx=s,gx}var yx,KT;function I7(){if(KT)return yx;KT=1;var e=SI(),t=0;function n(r){var s=++t;return e(r)+s}return yx=n,yx}var wx,YT;function $7(){if(YT)return wx;YT=1;function e(t,n,r){for(var s=-1,l=t.length,c=n.length,u={};++s<l;){var f=s<c?n[s]:void 0;r(u,t[s],f)}return u}return wx=e,wx}var vx,XT;function O7(){if(XT)return vx;XT=1;var e=Df(),t=$7();function n(r,s){return t(r||[],s||[],e)}return vx=n,vx}var xx,ZT;function Pt(){if(ZT)return xx;ZT=1;var e;if(typeof zb=="function")try{e={cloneDeep:ZW(),constant:Qb(),defaults:QW(),each:yI(),filter:CI(),find:a7(),flatten:WI(),forEach:gI(),forIn:o7(),has:TI(),isUndefined:RI(),last:i7(),map:MI(),mapValues:l7(),max:u7(),merge:g7(),min:y7(),minBy:w7(),now:v7(),pick:S7(),range:E7(),reduce:II(),sortBy:M7(),uniqueId:I7(),values:DI(),zipObject:O7()}}catch{}return e||(e=window._),xx=e,xx}var bx,QT;function L7(){if(QT)return bx;QT=1,bx=e;function e(){var r={};r._next=r._prev=r,this._sentinel=r}e.prototype.dequeue=function(){var r=this._sentinel,s=r._prev;if(s!==r)return t(s),s},e.prototype.enqueue=function(r){var s=this._sentinel;r._prev&&r._next&&t(r),r._next=s._next,s._next._prev=r,s._next=r,r._prev=s},e.prototype.toString=function(){for(var r=[],s=this._sentinel,l=s._prev;l!==s;)r.push(JSON.stringify(l,n)),l=l._prev;return"["+r.join(", ")+"]"};function t(r){r._prev._next=r._next,r._next._prev=r._prev,delete r._next,delete r._prev}function n(r,s){if(r!=="_next"&&r!=="_prev")return s}return bx}var kx,JT;function P7(){if(JT)return kx;JT=1;var e=Pt(),t=vs().Graph,n=L7();kx=s;var r=e.constant(1);function s(p,h){if(p.nodeCount()<=1)return[];var m=u(p,h||r),y=l(m.graph,m.buckets,m.zeroIdx);return e.flatten(e.map(y,function(v){return p.outEdges(v.v,v.w)}),!0)}function l(p,h,m){for(var y=[],v=h[h.length-1],S=h[0],b;p.nodeCount();){for(;b=S.dequeue();)c(p,h,m,b);for(;b=v.dequeue();)c(p,h,m,b);if(p.nodeCount()){for(var _=h.length-2;_>0;--_)if(b=h[_].dequeue(),b){y=y.concat(c(p,h,m,b,!0));break}}}return y}function c(p,h,m,y,v){var S=v?[]:void 0;return e.forEach(p.inEdges(y.v),function(b){var _=p.edge(b),k=p.node(b.v);v&&S.push({v:b.v,w:b.w}),k.out-=_,f(h,m,k)}),e.forEach(p.outEdges(y.v),function(b){var _=p.edge(b),k=b.w,j=p.node(k);j.in-=_,f(h,m,j)}),p.removeNode(y.v),S}function u(p,h){var m=new t,y=0,v=0;e.forEach(p.nodes(),function(_){m.setNode(_,{v:_,in:0,out:0})}),e.forEach(p.edges(),function(_){var k=m.edge(_.v,_.w)||0,j=h(_),E=k+j;m.setEdge(_.v,_.w,E),v=Math.max(v,m.node(_.v).out+=j),y=Math.max(y,m.node(_.w).in+=j)});var S=e.range(v+y+3).map(function(){return new n}),b=y+1;return e.forEach(m.nodes(),function(_){f(S,b,m.node(_))}),{graph:m,buckets:S,zeroIdx:b}}function f(p,h,m){m.out?m.in?p[m.out-m.in+h].enqueue(m):p[p.length-1].enqueue(m):p[0].enqueue(m)}return kx}var Nx,e2;function D7(){if(e2)return Nx;e2=1;var e=Pt(),t=P7();Nx={run:n,undo:s};function n(l){var c=l.graph().acyclicer==="greedy"?t(l,u(l)):r(l);e.forEach(c,function(f){var p=l.edge(f);l.removeEdge(f),p.forwardName=f.name,p.reversed=!0,l.setEdge(f.w,f.v,p,e.uniqueId("rev"))});function u(f){return function(p){return f.edge(p).weight}}}function r(l){var c=[],u={},f={};function p(h){e.has(f,h)||(f[h]=!0,u[h]=!0,e.forEach(l.outEdges(h),function(m){e.has(u,m.w)?c.push(m):p(m.w)}),delete u[h])}return e.forEach(l.nodes(),p),c}function s(l){e.forEach(l.edges(),function(c){var u=l.edge(c);if(u.reversed){l.removeEdge(c);var f=u.forwardName;delete u.reversed,delete u.forwardName,l.setEdge(c.w,c.v,u,f)}})}return Nx}var Sx,t2;function or(){if(t2)return Sx;t2=1;var e=Pt(),t=vs().Graph;Sx={addDummyNode:n,simplify:r,asNonCompoundGraph:s,successorWeights:l,predecessorWeights:c,intersectRect:u,buildLayerMatrix:f,normalizeRanks:p,removeEmptyRanks:h,addBorderNode:m,maxRank:y,partition:v,time:S,notime:b};function n(_,k,j,E){var C;do C=e.uniqueId(E);while(_.hasNode(C));return j.dummy=k,_.setNode(C,j),C}function r(_){var k=new t().setGraph(_.graph());return e.forEach(_.nodes(),function(j){k.setNode(j,_.node(j))}),e.forEach(_.edges(),function(j){var E=k.edge(j.v,j.w)||{weight:0,minlen:1},C=_.edge(j);k.setEdge(j.v,j.w,{weight:E.weight+C.weight,minlen:Math.max(E.minlen,C.minlen)})}),k}function s(_){var k=new t({multigraph:_.isMultigraph()}).setGraph(_.graph());return e.forEach(_.nodes(),function(j){_.children(j).length||k.setNode(j,_.node(j))}),e.forEach(_.edges(),function(j){k.setEdge(j,_.edge(j))}),k}function l(_){var k=e.map(_.nodes(),function(j){var E={};return e.forEach(_.outEdges(j),function(C){E[C.w]=(E[C.w]||0)+_.edge(C).weight}),E});return e.zipObject(_.nodes(),k)}function c(_){var k=e.map(_.nodes(),function(j){var E={};return e.forEach(_.inEdges(j),function(C){E[C.v]=(E[C.v]||0)+_.edge(C).weight}),E});return e.zipObject(_.nodes(),k)}function u(_,k){var j=_.x,E=_.y,C=k.x-j,R=k.y-E,I=_.width/2,O=_.height/2;if(!C&&!R)throw new Error("Not possible to find intersection inside of the rectangle");var H,q;return Math.abs(R)*I>Math.abs(C)*O?(R<0&&(O=-O),H=O*C/R,q=O):(C<0&&(I=-I),H=I,q=I*R/C),{x:j+H,y:E+q}}function f(_){var k=e.map(e.range(y(_)+1),function(){return[]});return e.forEach(_.nodes(),function(j){var E=_.node(j),C=E.rank;e.isUndefined(C)||(k[C][E.order]=j)}),k}function p(_){var k=e.min(e.map(_.nodes(),function(j){return _.node(j).rank}));e.forEach(_.nodes(),function(j){var E=_.node(j);e.has(E,"rank")&&(E.rank-=k)})}function h(_){var k=e.min(e.map(_.nodes(),function(R){return _.node(R).rank})),j=[];e.forEach(_.nodes(),function(R){var I=_.node(R).rank-k;j[I]||(j[I]=[]),j[I].push(R)});var E=0,C=_.graph().nodeRankFactor;e.forEach(j,function(R,I){e.isUndefined(R)&&I%C!==0?--E:E&&e.forEach(R,function(O){_.node(O).rank+=E})})}function m(_,k,j,E){var C={width:0,height:0};return arguments.length>=4&&(C.rank=j,C.order=E),n(_,"border",C,k)}function y(_){return e.max(e.map(_.nodes(),function(k){var j=_.node(k).rank;if(!e.isUndefined(j))return j}))}function v(_,k){var j={lhs:[],rhs:[]};return e.forEach(_,function(E){k(E)?j.lhs.push(E):j.rhs.push(E)}),j}function S(_,k){var j=e.now();try{return k()}finally{console.log(_+" time: "+(e.now()-j)+"ms")}}function b(_,k){return k()}return Sx}var jx,n2;function F7(){if(n2)return jx;n2=1;var e=Pt(),t=or();jx={run:n,undo:s};function n(l){l.graph().dummyChains=[],e.forEach(l.edges(),function(c){r(l,c)})}function r(l,c){var u=c.v,f=l.node(u).rank,p=c.w,h=l.node(p).rank,m=c.name,y=l.edge(c),v=y.labelRank;if(h!==f+1){l.removeEdge(c);var S,b,_;for(_=0,++f;f<h;++_,++f)y.points=[],b={width:0,height:0,edgeLabel:y,edgeObj:c,rank:f},S=t.addDummyNode(l,"edge",b,"_d"),f===v&&(b.width=y.width,b.height=y.height,b.dummy="edge-label",b.labelpos=y.labelpos),l.setEdge(u,S,{weight:y.weight},m),_===0&&l.graph().dummyChains.push(S),u=S;l.setEdge(u,p,{weight:y.weight},m)}}function s(l){e.forEach(l.graph().dummyChains,function(c){var u=l.node(c),f=u.edgeLabel,p;for(l.setEdge(u.edgeObj,f);u.dummy;)p=l.successors(c)[0],l.removeNode(c),f.points.push({x:u.x,y:u.y}),u.dummy==="edge-label"&&(f.x=u.x,f.y=u.y,f.width=u.width,f.height=u.height),c=p,u=l.node(c)})}return jx}var _x,r2;function af(){if(r2)return _x;r2=1;var e=Pt();_x={longestPath:t,slack:n};function t(r){var s={};function l(c){var u=r.node(c);if(e.has(s,c))return u.rank;s[c]=!0;var f=e.min(e.map(r.outEdges(c),function(p){return l(p.w)-r.edge(p).minlen}));return(f===Number.POSITIVE_INFINITY||f===void 0||f===null)&&(f=0),u.rank=f}e.forEach(r.sources(),l)}function n(r,s){return r.node(s.w).rank-r.node(s.v).rank-r.edge(s).minlen}return _x}var Ex,s2;function YI(){if(s2)return Ex;s2=1;var e=Pt(),t=vs().Graph,n=af().slack;Ex=r;function r(u){var f=new t({directed:!1}),p=u.nodes()[0],h=u.nodeCount();f.setNode(p,{});for(var m,y;s(f,u)<h;)m=l(f,u),y=f.hasNode(m.v)?n(u,m):-n(u,m),c(f,u,y);return f}function s(u,f){function p(h){e.forEach(f.nodeEdges(h),function(m){var y=m.v,v=h===y?m.w:y;!u.hasNode(v)&&!n(f,m)&&(u.setNode(v,{}),u.setEdge(h,v,{}),p(v))})}return e.forEach(u.nodes(),p),u.nodeCount()}function l(u,f){return e.minBy(f.edges(),function(p){if(u.hasNode(p.v)!==u.hasNode(p.w))return n(f,p)})}function c(u,f,p){e.forEach(u.nodes(),function(h){f.node(h).rank+=p})}return Ex}var Cx,a2;function q7(){if(a2)return Cx;a2=1;var e=Pt(),t=YI(),n=af().slack,r=af().longestPath,s=vs().alg.preorder,l=vs().alg.postorder,c=or().simplify;Cx=u,u.initLowLimValues=m,u.initCutValues=f,u.calcCutValue=h,u.leaveEdge=v,u.enterEdge=S,u.exchangeEdges=b;function u(E){E=c(E),r(E);var C=t(E);m(C),f(C,E);for(var R,I;R=v(C);)I=S(C,E,R),b(C,E,R,I)}function f(E,C){var R=l(E,E.nodes());R=R.slice(0,R.length-1),e.forEach(R,function(I){p(E,C,I)})}function p(E,C,R){var I=E.node(R),O=I.parent;E.edge(R,O).cutvalue=h(E,C,R)}function h(E,C,R){var I=E.node(R),O=I.parent,H=!0,q=C.edge(R,O),$=0;return q||(H=!1,q=C.edge(O,R)),$=q.weight,e.forEach(C.nodeEdges(R),function(V){var ne=V.v===R,ee=ne?V.w:V.v;if(ee!==O){var M=ne===H,Z=C.edge(V).weight;if($+=M?Z:-Z,k(E,R,ee)){var K=E.edge(R,ee).cutvalue;$+=M?-K:K}}}),$}function m(E,C){arguments.length<2&&(C=E.nodes()[0]),y(E,{},1,C)}function y(E,C,R,I,O){var H=R,q=E.node(I);return C[I]=!0,e.forEach(E.neighbors(I),function($){e.has(C,$)||(R=y(E,C,R,$,I))}),q.low=H,q.lim=R++,O?q.parent=O:delete q.parent,R}function v(E){return e.find(E.edges(),function(C){return E.edge(C).cutvalue<0})}function S(E,C,R){var I=R.v,O=R.w;C.hasEdge(I,O)||(I=R.w,O=R.v);var H=E.node(I),q=E.node(O),$=H,V=!1;H.lim>q.lim&&($=q,V=!0);var ne=e.filter(C.edges(),function(ee){return V===j(E,E.node(ee.v),$)&&V!==j(E,E.node(ee.w),$)});return e.minBy(ne,function(ee){return n(C,ee)})}function b(E,C,R,I){var O=R.v,H=R.w;E.removeEdge(O,H),E.setEdge(I.v,I.w,{}),m(E),f(E,C),_(E,C)}function _(E,C){var R=e.find(E.nodes(),function(O){return!C.node(O).parent}),I=s(E,R);I=I.slice(1),e.forEach(I,function(O){var H=E.node(O).parent,q=C.edge(O,H),$=!1;q||(q=C.edge(H,O),$=!0),C.node(O).rank=C.node(H).rank+($?q.minlen:-q.minlen)})}function k(E,C,R){return E.hasEdge(C,R)}function j(E,C,R){return R.low<=C.lim&&C.lim<=R.lim}return Cx}var Tx,o2;function B7(){if(o2)return Tx;o2=1;var e=af(),t=e.longestPath,n=YI(),r=q7();Tx=s;function s(f){switch(f.graph().ranker){case"network-simplex":u(f);break;case"tight-tree":c(f);break;case"longest-path":l(f);break;default:u(f)}}var l=t;function c(f){t(f),n(f)}function u(f){r(f)}return Tx}var Rx,i2;function z7(){if(i2)return Rx;i2=1;var e=Pt();Rx=t;function t(s){var l=r(s);e.forEach(s.graph().dummyChains,function(c){for(var u=s.node(c),f=u.edgeObj,p=n(s,l,f.v,f.w),h=p.path,m=p.lca,y=0,v=h[y],S=!0;c!==f.w;){if(u=s.node(c),S){for(;(v=h[y])!==m&&s.node(v).maxRank<u.rank;)y++;v===m&&(S=!1)}if(!S){for(;y<h.length-1&&s.node(v=h[y+1]).minRank<=u.rank;)y++;v=h[y]}s.setParent(c,v),c=s.successors(c)[0]}})}function n(s,l,c,u){var f=[],p=[],h=Math.min(l[c].low,l[u].low),m=Math.max(l[c].lim,l[u].lim),y,v;y=c;do y=s.parent(y),f.push(y);while(y&&(l[y].low>h||m>l[y].lim));for(v=y,y=u;(y=s.parent(y))!==v;)p.push(y);return{path:f.concat(p.reverse()),lca:v}}function r(s){var l={},c=0;function u(f){var p=c;e.forEach(s.children(f),u),l[f]={low:p,lim:c++}}return e.forEach(s.children(),u),l}return Rx}var Ax,l2;function U7(){if(l2)return Ax;l2=1;var e=Pt(),t=or();Ax={run:n,cleanup:c};function n(u){var f=t.addDummyNode(u,"root",{},"_root"),p=s(u),h=e.max(e.values(p))-1,m=2*h+1;u.graph().nestingRoot=f,e.forEach(u.edges(),function(v){u.edge(v).minlen*=m});var y=l(u)+1;e.forEach(u.children(),function(v){r(u,f,m,y,h,p,v)}),u.graph().nodeRankFactor=m}function r(u,f,p,h,m,y,v){var S=u.children(v);if(!S.length){v!==f&&u.setEdge(f,v,{weight:0,minlen:p});return}var b=t.addBorderNode(u,"_bt"),_=t.addBorderNode(u,"_bb"),k=u.node(v);u.setParent(b,v),k.borderTop=b,u.setParent(_,v),k.borderBottom=_,e.forEach(S,function(j){r(u,f,p,h,m,y,j);var E=u.node(j),C=E.borderTop?E.borderTop:j,R=E.borderBottom?E.borderBottom:j,I=E.borderTop?h:2*h,O=C!==R?1:m-y[v]+1;u.setEdge(b,C,{weight:I,minlen:O,nestingEdge:!0}),u.setEdge(R,_,{weight:I,minlen:O,nestingEdge:!0})}),u.parent(v)||u.setEdge(f,b,{weight:0,minlen:m+y[v]})}function s(u){var f={};function p(h,m){var y=u.children(h);y&&y.length&&e.forEach(y,function(v){p(v,m+1)}),f[h]=m}return e.forEach(u.children(),function(h){p(h,1)}),f}function l(u){return e.reduce(u.edges(),function(f,p){return f+u.edge(p).weight},0)}function c(u){var f=u.graph();u.removeNode(f.nestingRoot),delete f.nestingRoot,e.forEach(u.edges(),function(p){var h=u.edge(p);h.nestingEdge&&u.removeEdge(p)})}return Ax}var Mx,c2;function H7(){if(c2)return Mx;c2=1;var e=Pt(),t=or();Mx=n;function n(s){function l(c){var u=s.children(c),f=s.node(c);if(u.length&&e.forEach(u,l),e.has(f,"minRank")){f.borderLeft=[],f.borderRight=[];for(var p=f.minRank,h=f.maxRank+1;p<h;++p)r(s,"borderLeft","_bl",c,f,p),r(s,"borderRight","_br",c,f,p)}}e.forEach(s.children(),l)}function r(s,l,c,u,f,p){var h={width:0,height:0,rank:p,borderType:l},m=f[l][p-1],y=t.addDummyNode(s,"border",h,c);f[l][p]=y,s.setParent(y,u),m&&s.setEdge(m,y,{weight:1})}return Mx}var Ix,u2;function W7(){if(u2)return Ix;u2=1;var e=Pt();Ix={adjust:t,undo:n};function t(p){var h=p.graph().rankdir.toLowerCase();(h==="lr"||h==="rl")&&r(p)}function n(p){var h=p.graph().rankdir.toLowerCase();(h==="bt"||h==="rl")&&l(p),(h==="lr"||h==="rl")&&(u(p),r(p))}function r(p){e.forEach(p.nodes(),function(h){s(p.node(h))}),e.forEach(p.edges(),function(h){s(p.edge(h))})}function s(p){var h=p.width;p.width=p.height,p.height=h}function l(p){e.forEach(p.nodes(),function(h){c(p.node(h))}),e.forEach(p.edges(),function(h){var m=p.edge(h);e.forEach(m.points,c),e.has(m,"y")&&c(m)})}function c(p){p.y=-p.y}function u(p){e.forEach(p.nodes(),function(h){f(p.node(h))}),e.forEach(p.edges(),function(h){var m=p.edge(h);e.forEach(m.points,f),e.has(m,"x")&&f(m)})}function f(p){var h=p.x;p.x=p.y,p.y=h}return Ix}var $x,d2;function V7(){if(d2)return $x;d2=1;var e=Pt();$x=t;function t(n){var r={},s=e.filter(n.nodes(),function(p){return!n.children(p).length}),l=e.max(e.map(s,function(p){return n.node(p).rank})),c=e.map(e.range(l+1),function(){return[]});function u(p){if(!e.has(r,p)){r[p]=!0;var h=n.node(p);c[h.rank].push(p),e.forEach(n.successors(p),u)}}var f=e.sortBy(s,function(p){return n.node(p).rank});return e.forEach(f,u),c}return $x}var Ox,h2;function G7(){if(h2)return Ox;h2=1;var e=Pt();Ox=t;function t(r,s){for(var l=0,c=1;c<s.length;++c)l+=n(r,s[c-1],s[c]);return l}function n(r,s,l){for(var c=e.zipObject(l,e.map(l,function(y,v){return v})),u=e.flatten(e.map(s,function(y){return e.sortBy(e.map(r.outEdges(y),function(v){return{pos:c[v.w],weight:r.edge(v).weight}}),"pos")}),!0),f=1;f<l.length;)f<<=1;var p=2*f-1;f-=1;var h=e.map(new Array(p),function(){return 0}),m=0;return e.forEach(u.forEach(function(y){var v=y.pos+f;h[v]+=y.weight;for(var S=0;v>0;)v%2&&(S+=h[v+1]),v=v-1>>1,h[v]+=y.weight;m+=y.weight*S})),m}return Ox}var Lx,f2;function K7(){if(f2)return Lx;f2=1;var e=Pt();Lx=t;function t(n,r){return e.map(r,function(s){var l=n.inEdges(s);if(l.length){var c=e.reduce(l,function(u,f){var p=n.edge(f),h=n.node(f.v);return{sum:u.sum+p.weight*h.order,weight:u.weight+p.weight}},{sum:0,weight:0});return{v:s,barycenter:c.sum/c.weight,weight:c.weight}}else return{v:s}})}return Lx}var Px,p2;function Y7(){if(p2)return Px;p2=1;var e=Pt();Px=t;function t(s,l){var c={};e.forEach(s,function(f,p){var h=c[f.v]={indegree:0,in:[],out:[],vs:[f.v],i:p};e.isUndefined(f.barycenter)||(h.barycenter=f.barycenter,h.weight=f.weight)}),e.forEach(l.edges(),function(f){var p=c[f.v],h=c[f.w];!e.isUndefined(p)&&!e.isUndefined(h)&&(h.indegree++,p.out.push(c[f.w]))});var u=e.filter(c,function(f){return!f.indegree});return n(u)}function n(s){var l=[];function c(p){return function(h){h.merged||(e.isUndefined(h.barycenter)||e.isUndefined(p.barycenter)||h.barycenter>=p.barycenter)&&r(p,h)}}function u(p){return function(h){h.in.push(p),--h.indegree===0&&s.push(h)}}for(;s.length;){var f=s.pop();l.push(f),e.forEach(f.in.reverse(),c(f)),e.forEach(f.out,u(f))}return e.map(e.filter(l,function(p){return!p.merged}),function(p){return e.pick(p,["vs","i","barycenter","weight"])})}function r(s,l){var c=0,u=0;s.weight&&(c+=s.barycenter*s.weight,u+=s.weight),l.weight&&(c+=l.barycenter*l.weight,u+=l.weight),s.vs=l.vs.concat(s.vs),s.barycenter=c/u,s.weight=u,s.i=Math.min(l.i,s.i),l.merged=!0}return Px}var Dx,m2;function X7(){if(m2)return Dx;m2=1;var e=Pt(),t=or();Dx=n;function n(l,c){var u=t.partition(l,function(b){return e.has(b,"barycenter")}),f=u.lhs,p=e.sortBy(u.rhs,function(b){return-b.i}),h=[],m=0,y=0,v=0;f.sort(s(!!c)),v=r(h,p,v),e.forEach(f,function(b){v+=b.vs.length,h.push(b.vs),m+=b.barycenter*b.weight,y+=b.weight,v=r(h,p,v)});var S={vs:e.flatten(h,!0)};return y&&(S.barycenter=m/y,S.weight=y),S}function r(l,c,u){for(var f;c.length&&(f=e.last(c)).i<=u;)c.pop(),l.push(f.vs),u++;return u}function s(l){return function(c,u){return c.barycenter<u.barycenter?-1:c.barycenter>u.barycenter?1:l?u.i-c.i:c.i-u.i}}return Dx}var Fx,g2;function Z7(){if(g2)return Fx;g2=1;var e=Pt(),t=K7(),n=Y7(),r=X7();Fx=s;function s(u,f,p,h){var m=u.children(f),y=u.node(f),v=y?y.borderLeft:void 0,S=y?y.borderRight:void 0,b={};v&&(m=e.filter(m,function(R){return R!==v&&R!==S}));var _=t(u,m);e.forEach(_,function(R){if(u.children(R.v).length){var I=s(u,R.v,p,h);b[R.v]=I,e.has(I,"barycenter")&&c(R,I)}});var k=n(_,p);l(k,b);var j=r(k,h);if(v&&(j.vs=e.flatten([v,j.vs,S],!0),u.predecessors(v).length)){var E=u.node(u.predecessors(v)[0]),C=u.node(u.predecessors(S)[0]);e.has(j,"barycenter")||(j.barycenter=0,j.weight=0),j.barycenter=(j.barycenter*j.weight+E.order+C.order)/(j.weight+2),j.weight+=2}return j}function l(u,f){e.forEach(u,function(p){p.vs=e.flatten(p.vs.map(function(h){return f[h]?f[h].vs:h}),!0)})}function c(u,f){e.isUndefined(u.barycenter)?(u.barycenter=f.barycenter,u.weight=f.weight):(u.barycenter=(u.barycenter*u.weight+f.barycenter*f.weight)/(u.weight+f.weight),u.weight+=f.weight)}return Fx}var qx,y2;function Q7(){if(y2)return qx;y2=1;var e=Pt(),t=vs().Graph;qx=n;function n(s,l,c){var u=r(s),f=new t({compound:!0}).setGraph({root:u}).setDefaultNodeLabel(function(p){return s.node(p)});return e.forEach(s.nodes(),function(p){var h=s.node(p),m=s.parent(p);(h.rank===l||h.minRank<=l&&l<=h.maxRank)&&(f.setNode(p),f.setParent(p,m||u),e.forEach(s[c](p),function(y){var v=y.v===p?y.w:y.v,S=f.edge(v,p),b=e.isUndefined(S)?0:S.weight;f.setEdge(v,p,{weight:s.edge(y).weight+b})}),e.has(h,"minRank")&&f.setNode(p,{borderLeft:h.borderLeft[l],borderRight:h.borderRight[l]}))}),f}function r(s){for(var l;s.hasNode(l=e.uniqueId("_root")););return l}return qx}var Bx,w2;function J7(){if(w2)return Bx;w2=1;var e=Pt();Bx=t;function t(n,r,s){var l={},c;e.forEach(s,function(u){for(var f=n.parent(u),p,h;f;){if(p=n.parent(f),p?(h=l[p],l[p]=f):(h=c,c=f),h&&h!==f){r.setEdge(h,f);return}f=p}})}return Bx}var zx,v2;function e9(){if(v2)return zx;v2=1;var e=Pt(),t=V7(),n=G7(),r=Z7(),s=Q7(),l=J7(),c=vs().Graph,u=or();zx=f;function f(y){var v=u.maxRank(y),S=p(y,e.range(1,v+1),"inEdges"),b=p(y,e.range(v-1,-1,-1),"outEdges"),_=t(y);m(y,_);for(var k=Number.POSITIVE_INFINITY,j,E=0,C=0;C<4;++E,++C){h(E%2?S:b,E%4>=2),_=u.buildLayerMatrix(y);var R=n(y,_);R<k&&(C=0,j=e.cloneDeep(_),k=R)}m(y,j)}function p(y,v,S){return e.map(v,function(b){return s(y,b,S)})}function h(y,v){var S=new c;e.forEach(y,function(b){var _=b.graph().root,k=r(b,_,S,v);e.forEach(k.vs,function(j,E){b.node(j).order=E}),l(b,S,k.vs)})}function m(y,v){e.forEach(v,function(S){e.forEach(S,function(b,_){y.node(b).order=_})})}return zx}var Ux,x2;function t9(){if(x2)return Ux;x2=1;var e=Pt(),t=vs().Graph,n=or();Ux={positionX:S,findType1Conflicts:r,findType2Conflicts:s,addConflict:c,hasConflict:u,verticalAlignment:f,horizontalCompaction:p,alignCoordinates:y,findSmallestWidthAlignment:m,balance:v};function r(k,j){var E={};function C(R,I){var O=0,H=0,q=R.length,$=e.last(I);return e.forEach(I,function(V,ne){var ee=l(k,V),M=ee?k.node(ee).order:q;(ee||V===$)&&(e.forEach(I.slice(H,ne+1),function(Z){e.forEach(k.predecessors(Z),function(K){var D=k.node(K),P=D.order;(P<O||M<P)&&!(D.dummy&&k.node(Z).dummy)&&c(E,K,Z)})}),H=ne+1,O=M)}),I}return e.reduce(j,C),E}function s(k,j){var E={};function C(I,O,H,q,$){var V;e.forEach(e.range(O,H),function(ne){V=I[ne],k.node(V).dummy&&e.forEach(k.predecessors(V),function(ee){var M=k.node(ee);M.dummy&&(M.order<q||M.order>$)&&c(E,ee,V)})})}function R(I,O){var H=-1,q,$=0;return e.forEach(O,function(V,ne){if(k.node(V).dummy==="border"){var ee=k.predecessors(V);ee.length&&(q=k.node(ee[0]).order,C(O,$,ne,H,q),$=ne,H=q)}C(O,$,O.length,q,I.length)}),O}return e.reduce(j,R),E}function l(k,j){if(k.node(j).dummy)return e.find(k.predecessors(j),function(E){return k.node(E).dummy})}function c(k,j,E){if(j>E){var C=j;j=E,E=C}var R=k[j];R||(k[j]=R={}),R[E]=!0}function u(k,j,E){if(j>E){var C=j;j=E,E=C}return e.has(k[j],E)}function f(k,j,E,C){var R={},I={},O={};return e.forEach(j,function(H){e.forEach(H,function(q,$){R[q]=q,I[q]=q,O[q]=$})}),e.forEach(j,function(H){var q=-1;e.forEach(H,function($){var V=C($);if(V.length){V=e.sortBy(V,function(K){return O[K]});for(var ne=(V.length-1)/2,ee=Math.floor(ne),M=Math.ceil(ne);ee<=M;++ee){var Z=V[ee];I[$]===$&&q<O[Z]&&!u(E,$,Z)&&(I[Z]=$,I[$]=R[$]=R[Z],q=O[Z])}}})}),{root:R,align:I}}function p(k,j,E,C,R){var I={},O=h(k,j,E,R),H=R?"borderLeft":"borderRight";function q(ne,ee){for(var M=O.nodes(),Z=M.pop(),K={};Z;)K[Z]?ne(Z):(K[Z]=!0,M.push(Z),M=M.concat(ee(Z))),Z=M.pop()}function $(ne){I[ne]=O.inEdges(ne).reduce(function(ee,M){return Math.max(ee,I[M.v]+O.edge(M))},0)}function V(ne){var ee=O.outEdges(ne).reduce(function(Z,K){return Math.min(Z,I[K.w]-O.edge(K))},Number.POSITIVE_INFINITY),M=k.node(ne);ee!==Number.POSITIVE_INFINITY&&M.borderType!==H&&(I[ne]=Math.max(I[ne],ee))}return q($,O.predecessors.bind(O)),q(V,O.successors.bind(O)),e.forEach(C,function(ne){I[ne]=I[E[ne]]}),I}function h(k,j,E,C){var R=new t,I=k.graph(),O=b(I.nodesep,I.edgesep,C);return e.forEach(j,function(H){var q;e.forEach(H,function($){var V=E[$];if(R.setNode(V),q){var ne=E[q],ee=R.edge(ne,V);R.setEdge(ne,V,Math.max(O(k,$,q),ee||0))}q=$})}),R}function m(k,j){return e.minBy(e.values(j),function(E){var C=Number.NEGATIVE_INFINITY,R=Number.POSITIVE_INFINITY;return e.forIn(E,function(I,O){var H=_(k,O)/2;C=Math.max(I+H,C),R=Math.min(I-H,R)}),C-R})}function y(k,j){var E=e.values(j),C=e.min(E),R=e.max(E);e.forEach(["u","d"],function(I){e.forEach(["l","r"],function(O){var H=I+O,q=k[H],$;if(q!==j){var V=e.values(q);$=O==="l"?C-e.min(V):R-e.max(V),$&&(k[H]=e.mapValues(q,function(ne){return ne+$}))}})})}function v(k,j){return e.mapValues(k.ul,function(E,C){if(j)return k[j.toLowerCase()][C];var R=e.sortBy(e.map(k,C));return(R[1]+R[2])/2})}function S(k){var j=n.buildLayerMatrix(k),E=e.merge(r(k,j),s(k,j)),C={},R;e.forEach(["u","d"],function(O){R=O==="u"?j:e.values(j).reverse(),e.forEach(["l","r"],function(H){H==="r"&&(R=e.map(R,function(ne){return e.values(ne).reverse()}));var q=(O==="u"?k.predecessors:k.successors).bind(k),$=f(k,R,E,q),V=p(k,R,$.root,$.align,H==="r");H==="r"&&(V=e.mapValues(V,function(ne){return-ne})),C[O+H]=V})});var I=m(k,C);return y(C,I),v(C,k.graph().align)}function b(k,j,E){return function(C,R,I){var O=C.node(R),H=C.node(I),q=0,$;if(q+=O.width/2,e.has(O,"labelpos"))switch(O.labelpos.toLowerCase()){case"l":$=-O.width/2;break;case"r":$=O.width/2;break}if($&&(q+=E?$:-$),$=0,q+=(O.dummy?j:k)/2,q+=(H.dummy?j:k)/2,q+=H.width/2,e.has(H,"labelpos"))switch(H.labelpos.toLowerCase()){case"l":$=H.width/2;break;case"r":$=-H.width/2;break}return $&&(q+=E?$:-$),$=0,q}}function _(k,j){return k.node(j).width}return Ux}var Hx,b2;function n9(){if(b2)return Hx;b2=1;var e=Pt(),t=or(),n=t9().positionX;Hx=r;function r(l){l=t.asNonCompoundGraph(l),s(l),e.forEach(n(l),function(c,u){l.node(u).x=c})}function s(l){var c=t.buildLayerMatrix(l),u=l.graph().ranksep,f=0;e.forEach(c,function(p){var h=e.max(e.map(p,function(m){return l.node(m).height}));e.forEach(p,function(m){l.node(m).y=f+h/2}),f+=h+u})}return Hx}var Wx,k2;function r9(){if(k2)return Wx;k2=1;var e=Pt(),t=D7(),n=F7(),r=B7(),s=or().normalizeRanks,l=z7(),c=or().removeEmptyRanks,u=U7(),f=H7(),p=W7(),h=e9(),m=n9(),y=or(),v=vs().Graph;Wx=S;function S(U,Y){var z=Y&&Y.debugTiming?y.time:y.notime;z("layout",function(){var ie=z(" buildLayoutGraph",function(){return q(U)});z(" runLayout",function(){b(ie,z)}),z(" updateInputGraph",function(){_(U,ie)})})}function b(U,Y){Y(" makeSpaceForEdgeLabels",function(){$(U)}),Y(" removeSelfEdges",function(){B(U)}),Y(" acyclic",function(){t.run(U)}),Y(" nestingGraph.run",function(){u.run(U)}),Y(" rank",function(){r(y.asNonCompoundGraph(U))}),Y(" injectEdgeLabelProxies",function(){V(U)}),Y(" removeEmptyRanks",function(){c(U)}),Y(" nestingGraph.cleanup",function(){u.cleanup(U)}),Y(" normalizeRanks",function(){s(U)}),Y(" assignRankMinMax",function(){ne(U)}),Y(" removeEdgeLabelProxies",function(){ee(U)}),Y(" normalize.run",function(){n.run(U)}),Y(" parentDummyChains",function(){l(U)}),Y(" addBorderSegments",function(){f(U)}),Y(" order",function(){h(U)}),Y(" insertSelfEdges",function(){W(U)}),Y(" adjustCoordinateSystem",function(){p.adjust(U)}),Y(" position",function(){m(U)}),Y(" positionSelfEdges",function(){F(U)}),Y(" removeBorderNodes",function(){P(U)}),Y(" normalize.undo",function(){n.undo(U)}),Y(" fixupEdgeLabelCoords",function(){K(U)}),Y(" undoCoordinateSystem",function(){p.undo(U)}),Y(" translateGraph",function(){M(U)}),Y(" assignNodeIntersects",function(){Z(U)}),Y(" reversePoints",function(){D(U)}),Y(" acyclic.undo",function(){t.undo(U)})}function _(U,Y){e.forEach(U.nodes(),function(z){var ie=U.node(z),le=Y.node(z);ie&&(ie.x=le.x,ie.y=le.y,Y.children(z).length&&(ie.width=le.width,ie.height=le.height))}),e.forEach(U.edges(),function(z){var ie=U.edge(z),le=Y.edge(z);ie.points=le.points,e.has(le,"x")&&(ie.x=le.x,ie.y=le.y)}),U.graph().width=Y.graph().width,U.graph().height=Y.graph().height}var k=["nodesep","edgesep","ranksep","marginx","marginy"],j={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},E=["acyclicer","ranker","rankdir","align"],C=["width","height"],R={width:0,height:0},I=["minlen","weight","width","height","labeloffset"],O={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},H=["labelpos"];function q(U){var Y=new v({multigraph:!0,compound:!0}),z=re(U.graph());return Y.setGraph(e.merge({},j,G(z,k),e.pick(z,E))),e.forEach(U.nodes(),function(ie){var le=re(U.node(ie));Y.setNode(ie,e.defaults(G(le,C),R)),Y.setParent(ie,U.parent(ie))}),e.forEach(U.edges(),function(ie){var le=re(U.edge(ie));Y.setEdge(ie,e.merge({},O,G(le,I),e.pick(le,H)))}),Y}function $(U){var Y=U.graph();Y.ranksep/=2,e.forEach(U.edges(),function(z){var ie=U.edge(z);ie.minlen*=2,ie.labelpos.toLowerCase()!=="c"&&(Y.rankdir==="TB"||Y.rankdir==="BT"?ie.width+=ie.labeloffset:ie.height+=ie.labeloffset)})}function V(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);if(z.width&&z.height){var ie=U.node(Y.v),le=U.node(Y.w),ge={rank:(le.rank-ie.rank)/2+ie.rank,e:Y};y.addDummyNode(U,"edge-proxy",ge,"_ep")}})}function ne(U){var Y=0;e.forEach(U.nodes(),function(z){var ie=U.node(z);ie.borderTop&&(ie.minRank=U.node(ie.borderTop).rank,ie.maxRank=U.node(ie.borderBottom).rank,Y=e.max(Y,ie.maxRank))}),U.graph().maxRank=Y}function ee(U){e.forEach(U.nodes(),function(Y){var z=U.node(Y);z.dummy==="edge-proxy"&&(U.edge(z.e).labelRank=z.rank,U.removeNode(Y))})}function M(U){var Y=Number.POSITIVE_INFINITY,z=0,ie=Number.POSITIVE_INFINITY,le=0,ge=U.graph(),Ne=ge.marginx||0,Ie=ge.marginy||0;function Ge(Pe){var Be=Pe.x,Te=Pe.y,st=Pe.width,de=Pe.height;Y=Math.min(Y,Be-st/2),z=Math.max(z,Be+st/2),ie=Math.min(ie,Te-de/2),le=Math.max(le,Te+de/2)}e.forEach(U.nodes(),function(Pe){Ge(U.node(Pe))}),e.forEach(U.edges(),function(Pe){var Be=U.edge(Pe);e.has(Be,"x")&&Ge(Be)}),Y-=Ne,ie-=Ie,e.forEach(U.nodes(),function(Pe){var Be=U.node(Pe);Be.x-=Y,Be.y-=ie}),e.forEach(U.edges(),function(Pe){var Be=U.edge(Pe);e.forEach(Be.points,function(Te){Te.x-=Y,Te.y-=ie}),e.has(Be,"x")&&(Be.x-=Y),e.has(Be,"y")&&(Be.y-=ie)}),ge.width=z-Y+Ne,ge.height=le-ie+Ie}function Z(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y),ie=U.node(Y.v),le=U.node(Y.w),ge,Ne;z.points?(ge=z.points[0],Ne=z.points[z.points.length-1]):(z.points=[],ge=le,Ne=ie),z.points.unshift(y.intersectRect(ie,ge)),z.points.push(y.intersectRect(le,Ne))})}function K(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);if(e.has(z,"x"))switch((z.labelpos==="l"||z.labelpos==="r")&&(z.width-=z.labeloffset),z.labelpos){case"l":z.x-=z.width/2+z.labeloffset;break;case"r":z.x+=z.width/2+z.labeloffset;break}})}function D(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);z.reversed&&z.points.reverse()})}function P(U){e.forEach(U.nodes(),function(Y){if(U.children(Y).length){var z=U.node(Y),ie=U.node(z.borderTop),le=U.node(z.borderBottom),ge=U.node(e.last(z.borderLeft)),Ne=U.node(e.last(z.borderRight));z.width=Math.abs(Ne.x-ge.x),z.height=Math.abs(le.y-ie.y),z.x=ge.x+z.width/2,z.y=ie.y+z.height/2}}),e.forEach(U.nodes(),function(Y){U.node(Y).dummy==="border"&&U.removeNode(Y)})}function B(U){e.forEach(U.edges(),function(Y){if(Y.v===Y.w){var z=U.node(Y.v);z.selfEdges||(z.selfEdges=[]),z.selfEdges.push({e:Y,label:U.edge(Y)}),U.removeEdge(Y)}})}function W(U){var Y=y.buildLayerMatrix(U);e.forEach(Y,function(z){var ie=0;e.forEach(z,function(le,ge){var Ne=U.node(le);Ne.order=ge+ie,e.forEach(Ne.selfEdges,function(Ie){y.addDummyNode(U,"selfedge",{width:Ie.label.width,height:Ie.label.height,rank:Ne.rank,order:ge+ ++ie,e:Ie.e,label:Ie.label},"_se")}),delete Ne.selfEdges})})}function F(U){e.forEach(U.nodes(),function(Y){var z=U.node(Y);if(z.dummy==="selfedge"){var ie=U.node(z.e.v),le=ie.x+ie.width/2,ge=ie.y,Ne=z.x-le,Ie=ie.height/2;U.setEdge(z.e,z.label),U.removeNode(Y),z.label.points=[{x:le+2*Ne/3,y:ge-Ie},{x:le+5*Ne/6,y:ge-Ie},{x:le+Ne,y:ge},{x:le+5*Ne/6,y:ge+Ie},{x:le+2*Ne/3,y:ge+Ie}],z.label.x=z.x,z.label.y=z.y}})}function G(U,Y){return e.mapValues(e.pick(U,Y),Number)}function re(U){var Y={};return e.forEach(U,function(z,ie){Y[ie.toLowerCase()]=z}),Y}return Wx}var Vx,N2;function s9(){if(N2)return Vx;N2=1;var e=Pt(),t=or(),n=vs().Graph;Vx={debugOrdering:r};function r(s){var l=t.buildLayerMatrix(s),c=new n({compound:!0,multigraph:!0}).setGraph({});return e.forEach(s.nodes(),function(u){c.setNode(u,{label:u}),c.setParent(u,"layer"+s.node(u).rank)}),e.forEach(s.edges(),function(u){c.setEdge(u.v,u.w,{},u.name)}),e.forEach(l,function(u,f){var p="layer"+f;c.setNode(p,{rank:"same"}),e.reduce(u,function(h,m){return c.setEdge(h,m,{style:"invis"}),m})}),c}return Vx}var Gx,S2;function a9(){return S2||(S2=1,Gx="0.8.5"),Gx}var Kx,j2;function o9(){return j2||(j2=1,Kx={graphlib:vs(),layout:r9(),debug:s9(),util:{time:or().time,notime:or().notime},version:a9()}),Kx}var i9=o9();const _2=tb(i9),pi=240,Iu=130,Dl=74,Yf=72,gu=Dl+Yf;function XI(e,t){var r;let n=pi;for(const s of e)n=Math.max(n,((r=t.get(s.id))==null?void 0:r.width)??pi);return n}const of=420,ZI=1;function l9(e,t,n,r){return Math.min(ZI,n/Math.max(1,e),r/Math.max(1,t))}function mi(e){var n;return((n=e.data)==null?void 0:n.sessionId)??"_default"}function c9(e,t){return((t==null?void 0:t.get(e))??0)>0?of:0}function u9(e,t){const n=(t==null?void 0:t.get(e))??0;return n>0?6+n*36:0}function $u(e,t,n){const r=t.get(e);return{w:((r==null?void 0:r.width)??pi)+c9(e,n),h:Math.max((r==null?void 0:r.height)??Iu,u9(e,n))}}function d9(e){return[...e.keys()].sort().map(t=>`${t}:${e.get(t)}`).join("|")}function h9(e,t,n,r,s,l){const c=new _2.graphlib.Graph;c.setDefaultEdgeLabel(()=>({})),c.setGraph({rankdir:n,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const u=e.filter(k=>!s.has(k)),f=new Set(u);for(const k of u){const{w:j,h:E}=$u(k,r,l);c.setNode(k,{width:j,height:E})}for(const k of t)f.has(k.source)&&f.has(k.target)&&c.setEdge(k.source,k.target);_2.layout(c);const p=new Map;let h=1/0,m=1/0,y=-1/0,v=-1/0;for(const k of u){const j=c.node(k);if(!j)continue;const E=r.get(k),C=(E==null?void 0:E.width)??pi,R=(E==null?void 0:E.height)??Iu,I=$u(k,r,l),O=j.x-I.w/2,H=j.y-I.h/2;p.set(k,{x:O,y:H}),O<h&&(h=O),H<m&&(m=H),O+C>y&&(y=O+C),H+R>v&&(v=H+R)}if(Number.isFinite(h)&&Number.isFinite(m))for(const[k,j]of p)p.set(k,{x:j.x-h,y:j.y-m});const S=Number.isFinite(y)?y-h:0,b=Number.isFinite(v)?v-m:0;let _=null;for(const k of e){const j=s.get(k);if(!j)continue;const E=r.get(k),C=(E==null?void 0:E.width)??pi,R=(E==null?void 0:E.height)??Iu;_=_===null?{minX:j.x,minY:j.y,maxX:j.x+C,maxY:j.y+R}:{minX:Math.min(_.minX,j.x),minY:Math.min(_.minY,j.y),maxX:Math.max(_.maxX,j.x+C),maxY:Math.max(_.maxY,j.y+R)}}return{positions:p,width:S,height:b,pinnedBox:_}}function QI(e,t,n){const r=n.direction??"LR",s=n.pinned??new Map,l=n.measured??new Map,c=n.lanes,u=new Map;for(const h of e){const m=mi(h),y=u.get(m);y?y.push(h.id):u.set(m,[h.id])}return{laid:Array.from(u.keys()).sort().map(h=>({sid:h,...h9(u.get(h),t,r,l,s,c)})),gap:XI(e,l)}}const JI=e=>e.reduce((t,n)=>Math.max(t,n.width),0)+of,f9=e=>e.reduce((t,n)=>t+n.height,0)+gu*Math.max(0,e.length-1);function B0(e,t,n,r){const s=f=>{const p=[[]];let h=0;for(const m of e)h>0&&h+m.height>f&&(p.push([]),h=0),p[p.length-1].push(m),h+=m.height+gu;return p},l=[];for(let f=0;f<e.length;f++){let p=-gu;for(let h=f;h<e.length;h++)l.push(p+=e[h].height+gu)}l.sort((f,p)=>f-p);const c=f=>{let p=0,h=l.length-1;for(;p<h;){const m=p+h>>1;s(l[m]).length<=f?h=m:p=m+1}return s(l[p])};let u=[e];if(n>0&&r>0){const f=h=>l9(h.reduce((m,y)=>m+JI(y),0)+t*(h.length-1),Math.max(...h.map(f9)),n,r);let p=f(u);for(let h=2;h<=e.length;h++){const m=c(h),y=f(m);y>p+1e-9&&(p=y,u=m)}}return u}function p9(e,t,n,r,s){if(!(r.width>0&&r.height>0&&s.width>0&&s.height>0))return!1;const{laid:l,gap:c}=QI(e,t,n);return l.length<2?!1:B0(l,c,r.width,r.height).length!==B0(l,c,s.width,s.height).length}function m9(e,t,n={}){const r=n.pinned??new Map,{laid:s,gap:l}=QI(e,t,n),c=B0(s,l,n.availableWidth??0,n.availableHeight??0),u=new Map;let f=0;for(const p of c){const h=JI(p);let m=0;for(const{positions:y,height:v,pinnedBox:S}of p){for(const[_,k]of y)u.set(_,{x:k.x+f,y:k.y+m});let b=m+v;S&&S.maxY>b&&S.minX<f+h&&f<S.maxX&&(b=S.maxY),m=b+gu}f+=h+l}return e.map(p=>{const h=r.get(p.id);if(h)return{...p,position:h};const m=u.get(p.id);return m?{...p,position:m}:p})}function g9(e,t,n,r,s){const c=Dl+Yf,u=60,f=v=>$u(v,r,s),p=new Map(e.map(v=>[v.id,mi(v)])),h=[],m=e.map(v=>({id:v.id,pos:n.get(v.id)??t.get(v.id)})).filter(v=>v.pos!=null).sort((v,S)=>v.pos.y-S.pos.y||v.pos.x-S.pos.x||v.id.localeCompare(S.id)),y=[];for(const{id:v,pos:S}of m){const{w:b,h:_}=f(v),k=p.get(v)??"_default";if(n.has(v)){h.push({x:S.x,y:S.y,w:b,h:_,sid:k});continue}let j=S.y;for(let E=0;E<h.length+1;E++){const C=h.find(R=>{const I=R.sid===k?24:u,O=R.sid===k?24:c;return S.x<R.x+R.w+I&&R.x<S.x+b+I&&j<R.y+R.h+O&&R.y<j+_+O});if(!C)break;j=C.y+C.h+(C.sid===k?24:c)}j!==S.y&&(t.set(v,{x:S.x,y:j}),y.push(v)),h.push({x:S.x,y:j,w:b,h:_,sid:k})}return y}function y9(e,t,n,r,s,l,c){const u=E=>$u(E,r,l),f=E=>n.get(E)??t.get(E),p=E=>{const C=r.get(E);return{cw:(C==null?void 0:C.width)??pi,ch:(C==null?void 0:C.height)??Iu}},h=c!=null&&c.width>0&&c.height>0,m=new Map;for(const E of e){if(!f(E.id))continue;const C=mi(E),R=m.get(C);R?R.push(E):m.set(C,[E])}const y=new Set;for(const[E,C]of m)C.every(R=>s.has(R.id)&&!n.has(R.id))&&y.add(E);const v=new Map,S=[];for(const E of e){const C=f(E.id);if(!C)continue;const{w:R,h:I}=u(E.id),O=mi(E);y.has(O)?(v.get(O)??v.set(O,[]).get(O)).push(E):S.push({x:C.x,y:C.y,w:R,h:I,...p(E.id)})}if(v.size===0||h&&S.length===0)return[];const b=Dl+Yf,_=(E,C,R,I)=>S.some(O=>E<O.x+O.w+Dl&&O.x<E+R+Dl&&C<O.y+O.h+b&&O.y<C+I+b),k=XI(e,r),j=[];for(const E of[...v.keys()].sort()){const C=v.get(E);let R=1/0,I=1/0,O=-1/0,H=-1/0,q=-1/0,$=-1/0;for(const D of C){const P=f(D.id),{w:B,h:W}=u(D.id),{cw:F,ch:G}=p(D.id);R=Math.min(R,P.x),I=Math.min(I,P.y),O=Math.max(O,P.x+B),H=Math.max(H,P.y+W),q=Math.max(q,P.x+F),$=Math.max($,P.y+G)}const V=O-R,ne=H-I,ee=[...new Set(S.map(D=>Math.round(D.x)))].sort((D,P)=>D-P),M=ee.length?ee:[R],Z=[0,...S.map(D=>D.y+D.h+b)].sort((D,P)=>D-P);let K=null;if(h){let D=1/0,P=1/0,B=-1/0,W=-1/0;for(const z of S)D=Math.min(D,z.x),P=Math.min(P,z.y),B=Math.max(B,z.x+z.cw),W=Math.max(W,z.y+z.ch);const F=(z,ie)=>{const le=c.width/(Math.max(B,z+q-R)-Math.min(D,z)+of),ge=c.height/(Math.max(W,ie+$-I)-Math.min(P,ie));return[Math.min(ZI,le,ge),Math.min(le,ge),Math.max(le,ge)]},G=(z,ie)=>{for(let le=0;le<z.length;le++){if(z[le]>ie[le]+1e-9)return!0;if(z[le]<ie[le]-1e-9)return!1}return!1},re=Math.round(B+of+k),U=[...new Set([...Z,P])].sort((z,ie)=>z-ie);let Y=null;for(const z of[...M,re])for(const ie of U){if(_(z,ie,V,ne))continue;const le=F(z,ie);(Y===null||G(le,Y))&&(Y=le,K={x:z,y:ie})}K&&K.x===R&&K.y===I&&(K=null)}else e:for(const D of M)for(const P of Z){if(P>=I)break;if(!_(D,P,V,ne)){K={x:D,y:P};break e}}if(K){const D=K.x-R,P=K.y-I;for(const B of C){const W=f(B.id);t.set(B.id,{x:W.x+D,y:W.y+P})}j.push(E)}for(const D of C){const P=f(D.id),{w:B,h:W}=u(D.id);S.push({x:P.x,y:P.y,w:B,h:W,...p(D.id)})}}return j}function w9(e,t,n){const r=new Map;for(const s of e){if(t.has(s.id)||!n(s.id))continue;const l=mi(s);(r.get(l)??r.set(l,[]).get(l)).push(s)}if(r.size===0)return e;for(const s of r.values())s.sort((l,c)=>l.id.localeCompare(c.id));return e.map(s=>{var p;if(t.has(s.id)||n(s.id))return s;const l=r.get(mi(s));if(!l)return s;const c=(p=s.data)==null?void 0:p.parentId,u=l.find(h=>h.id===c)??l[0],f=n(u.id);return{...s,position:{x:s.position.x+f.x-u.position.x,y:s.position.y+f.y-u.position.y}}})}function v9(e,t,n,r,s,l=!1,c){const p=Dl+Yf+1,h=8,m=1.75,y=200,v=.7,S=.01,b=$=>$u($,r,c),_=$=>n.get($)??t.get($),k=new Map;for(const $ of e){if(!_($.id))continue;const V=mi($),ne=k.get(V);ne?ne.push($):k.set(V,[$])}const j=[],E=new Set,C=new Set,R=s.size===0;for(const $ of[...k.keys()].sort()){const V=k.get($);let ne=1/0,ee=1/0,M=-1/0,Z=-1/0,K=!1;for(const W of V){const F=_(W.id),{w:G,h:re}=b(W.id);ne=Math.min(ne,F.x),ee=Math.min(ee,F.y),M=Math.max(M,F.x+G),Z=Math.max(Z,F.y+re),n.has(W.id)&&(K=!0)}const D=M-ne,P=Z-ee;C.add($);const B=s.get($);B&&(D>B.w+h||P>B.h+h)&&E.add($),s.set($,{w:D,h:P}),j.push({sid:$,members:V.map(W=>W.id),x:ne,y:ee,w:D,h:P,anchored:K,mass:1})}for(const $ of[...s.keys()])C.has($)||s.delete($);if(l||R)return[];let I=!1;for(let $=0;$<j.length&&!I;$++)for(let V=$+1;V<j.length;V++){const ne=j[$],ee=j[V];if(!(ne.anchored&&ee.anchored)&&Math.abs(ne.x+ne.w/2-(ee.x+ee.w/2))<(ne.w+ee.w)/2+61&&Math.abs(ne.y+ne.h/2-(ee.y+ee.h/2))<(ne.h+ee.h)/2+p){I=!0;break}}if(E.size===0&&!I)return[];if(E.size>0)for(const $ of j)E.has($.sid)&&($.mass=8);else for(const $ of j)$.mass=Math.max(1,$.w*$.h/(pi*Iu));const O=new Map(j.map($=>[$.sid,$.x])),H=new Map(j.map($=>[$.sid,$.y]));for(let $=0;$<y;$++){const V=new Map,ne=new Map;let ee=0;for(let M=0;M<j.length;M++)for(let Z=M+1;Z<j.length;Z++){const K=j[M],D=j[Z];if(K.anchored&&D.anchored)continue;const P=K.x+K.w/2,B=K.y+K.h/2,W=D.x+D.w/2,F=D.y+D.h/2,G=(K.w+D.w)/2+61-Math.abs(P-W),re=(K.h+D.h)/2+p-Math.abs(B-F);if(G<=0||re<=0)continue;const U=(pe,Ae)=>!pe.anchored&&!(Ae<0&&pe.x<=0),Y=(pe,Ae)=>!pe.anchored&&!(Ae<0&&pe.y<=0),z=(pe,Ae,fe)=>{const Se=pe===Ae,Ye=Se?K.sid<D.sid?-1:1:Math.sign(pe-Ae);return fe(K,Ye)||fe(D,-Ye)?Ye:Se&&(fe(K,-Ye)||fe(D,Ye))?-Ye:0},ie=z(P,W,U),le=z(B,F,Y),ge=ie!==0,Ne=le!==0;if(!ge&&!Ne)continue;const Ie=ge&&(!Ne||G*m<re),[Ge,Pe,Be,Te]=Ie?[ie,G,V,U]:[le,re,ne,Y],st=Te(K,Ge),de=Te(D,-Ge),ue=K.mass,se=D.mass,be=st?de?se/(ue+se):1:0,Le=de?st?ue/(ue+se):1:0,ce=Pe*v;Be.set(K.sid,(Be.get(K.sid)??0)+Ge*ce*be),Be.set(D.sid,(Be.get(D.sid)??0)-Ge*ce*Le),ee+=ce}for(const M of j)M.anchored||(M.x=Math.max(0,M.x+(V.get(M.sid)??0)),M.y=Math.max(0,M.y+(ne.get(M.sid)??0)));if(ee<S)break}const q=[];for(const $ of j){const V=$.x-O.get($.sid),ne=$.y-H.get($.sid);if(!(Math.abs(V)<1&&Math.abs(ne)<1)){for(const ee of $.members){if(n.has(ee))continue;const M=t.get(ee);M&&t.set(ee,{x:M.x+V,y:M.y+ne})}q.push($.sid)}}return q}function Fh(e,t,n){return!t.has(e)||n.has(e)}function x9(e,t,n,r){return!t.has(e)&&Fh(e,n,r)}function b9(e,t,n){const r={x:0,y:0};return t.set(e,r),n.add(e),r}function E2(e,t,n,r){n.set(e,t),r.delete(e)}const k9=200,N9=5*6e4,S9=6,j9=2*6e4;function Sh(e,t){if(t.size!==0)for(const n of Array.from(e.keys()))t.has(n)||e.delete(n)}function _9(e,t){let n=!1;for(const s of e)if(!t.has(s)){n=!0;break}if(!n)return e;const r=new Set;for(const s of e)t.has(s)&&r.add(s);return r}function E9(e){const t=new Set;for(const n of e)t.add(n.id),t.add(`group:${n.sessionId}`),n.kind==="root"&&t.add(_b(n.id));return t}function C9(e){const t=new Set;for(const n of e)t.add(n.id),n.kind==="root"&&t.add(_b(n.id));return t}function T9(e,t){let n=s6(e,t,BN);a6(e,t,BN)&&(n=!0);const r=[],s=l=>{r.push(l)};return e6(e,t,k9,N9,s)&&(n=!0),t6(e,t,S9,j9,s)&&(n=!0),{changed:n,forgotten:r}}const R9=300,C2=130,A9=160,T2=new WeakMap;function M9(e,t){let n=T2.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:pF(e.agents.values())},T2.set(e,n));const{byId:r,branches:s}=n;return l=>{let c=r.get(l.id);if(!c){const u=l.kind==="root"?s.get(l.sessionId):void 0;c=u?{...l,onOpenContext:t,branch:u}:{...l,onOpenContext:t},r.set(l.id,c)}return c}}function z0(e){const t=new Map;for(const n of e.agents.values())n.tools.length>0&&t.set(n.id,Math.min(4,n.tools.length));return t}function I9(e,t,n,r,s,l,c,u,f,p,h,m,y,v,S,b,_,k){var ee,M,Z,K;const j=[],E=[],C=M9(e,k);for(const D of e.agents.values()){if(!_.has(D.id))continue;const P=D.exitAt!=null,B=b!=null&&!b.has(D.id),W=[P?"rf-exiting":"",B?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,F=l.get(D.id);if(j.push({id:D.id,type:"agent",position:{x:0,y:0},data:C(D),className:W,ariaLabel:sq(D,t,S.has(D.id)),...F?{width:F.width,height:F.height}:null}),D.parentId&&_.has(D.parentId)){const U=Qh(D.sessionId),Y=P,z=S.size>0&&(S.has(D.id)||S.has(D.parentId)),ie=b!=null&&!b.has(D.id)&&!b.has(D.parentId),le=D.state==="active"?2:1.5,ge=z?le+1.5:le,Ne=Y?.2:ie?.12:1,Ie=["sess-edge",D.state==="active"?"sess-live":"sess-idle",Y?"rf-edge-exiting":"",z?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${D.parentId}->${D.id}`,source:D.parentId,target:D.id,animated:(D.state==="active"||z)&&!Y,type:"smoothstep",style:{"--session-hue":U,strokeWidth:`calc(${ge}px * var(--edge-k, 1))`,opacity:Ne,transition:"var(--edge-transition)"},className:Ie})}const G=D.kind==="root"?jf(D):null,re=G?hM(D.sessionId,G.at):null;if(G&&re&&!lF(re)){const U=_b(D.id),Y=Qh(D.sessionId),z=l.get(U);j.push({id:U,type:"recapNote",position:{x:0,y:0},data:{sessionId:D.sessionId,parentId:D.id,recap:G,noteKey:re,hue:Y},className:B?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${D.label}`,...z?{width:z.width,height:z.height}:null}),E.push({id:`e:recap:${D.id}`,source:U,target:D.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Y}})}}const R=z0(e),I=`${y}#lanes:${d9(R)}`,O=new Set(j.filter(D=>D.type==="recapNote").map(D=>D.id));for(const D of Array.from(h.keys()))hF(D)&&!O.has(D)&&!s.has(D)&&(h.delete(D),m.delete(D));const H=j.filter(D=>x9(D.id,s,h,m));if(H.length>0||I!==v.current){if(H.length>0){const D=w9(m9(j,E,{direction:"LR",pinned:s,measured:l,availableWidth:n,availableHeight:r,lanes:R}),s,P=>Fh(P,h,m)?void 0:h.get(P));for(const P of D)Fh(P.id,h,m)&&E2(P.id,P.position,h,m);y9(j,h,s,l,new Set(H.filter(P=>P.type!=="recapNote").map(P=>P.id)),R,{width:n,height:r});for(const P of H){if(P.type!=="recapNote")continue;const B=(ee=P.data)==null?void 0:ee.parentId;if(!B)continue;const W=s.get(B)??(Fh(B,h,m)?void 0:h.get(B));if(!W)continue;const F=((M=l.get(P.id))==null?void 0:M.width)??R9,G=((Z=l.get(P.id))==null?void 0:Z.height)??C2,re=((K=l.get(B))==null?void 0:K.height)??C2;E2(P.id,{x:W.x-A9-F,y:W.y+(re-G)/2},h,m)}}g9(j,h,s,l,R),v.current=I}const q=v9(j,h,s,l,c,!f||p,R);q.length>0&&u(q);const $=C9(e.agents.values());Sh(h,$),Sh(m,$),Sh(s,$),Sh(l,E9(e.agents.values()));const V=[];let ne=!1;for(const D of j){let P=s.get(D.id)??h.get(D.id);P||(P=b9(D.id,h,m),ne=!0),V.push({...D,position:P})}return ne&&(v.current=""),{nodes:V,edges:E}}const $9=1;function O9(e){return{id:e.id,name:e.name,inputPreview:e.inputPreview,startedAt:e.startedAt,endedAt:e.endedAt,ok:e.ok,errorPreview:e.errorPreview,usage:e.usage}}function L9(e,t,n){const r=e.agents.get(t);if(!r)return null;const s=[];for(const l of e.agents.values())l.sessionId===t&&s.push(l);return{schemaVersion:$9,exportedAt:n,sessionId:t,label:r.label,cwd:r.cwd,startedAt:r.startedAt,endedAt:r.endedAt,model:r.model,agents:s.map(l=>({id:l.id,kind:l.kind,label:l.label,parentId:l.parentId,state:l.state,startedAt:l.startedAt,endedAt:l.endedAt,model:l.model,cwd:l.cwd,usage:l.usage,prompts:l.prompts,tools:l.tools.map(O9)}))}}function P9(e,t){const n=(e||"session").replace(/[^a-z0-9._-]/gi,"_");return`${dn}-${n}-${t.slice(0,8)}.json`}function D9(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function F9(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.decks!="number"||typeof t.mine!="boolean")return null;const n=t.owner&&typeof t.owner=="object"?t.owner.port:null;return{path:typeof t.path=="string"&&t.path!==""?t.path:null,decks:t.decks,mine:t.mine,ownerPort:typeof n=="number"?n:null}}function q9(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function B9(e,t){const n=q9(e),r=(...c)=>[n?`${n} on the canvas`:null,...c,"layout, pins and selection"].filter(u=>u!==null),s="This cannot be undone.";if(!t)return{goes:r("the event log on disk — the file a restarted deck replays to rebuild what you see, and the file every deck on this machine shares unless one was told otherwise"),stays:[],final:s,confirm:"Clear everything"};if(!t.path)return{goes:r(),stays:[],final:`This deck keeps no event log, so nothing on disk changes — and nothing can bring the canvas back. ${s}`,confirm:"Clear everything"};if(!t.mine){const c=t.ownerPort===null?"another running deck owns that file":`the deck on port ${t.ownerPort} owns that file`,u=t.decks>2?`, one of ${t.decks} decks sharing it`:"";return{goes:r(),stays:[`the event log — ${c}${u}`,"restart this deck and the log replays back onto it"],final:null,confirm:"Clear this canvas"}}if(t.decks<=1)return{goes:r("this deck's event log — the file a restarted deck replays to rebuild what you see"),stays:[],final:s,confirm:"Clear everything"};const l=t.decks-1;return{goes:r(`the event log ${l===1?"1 other running deck shares":`${l} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[l===1?"what that deck shows, until it restarts — then it is gone there too":"what those decks show, until they restart — then it is gone there too"],final:s,confirm:"Clear everything"}}function z9({agentCount:e,onConfirm:t,onCancel:n}){const r=w.useRef(null),s=pn(n,{focusRef:r,layer:$6}),[l,c]=w.useState(null);w.useEffect(()=>{let m=!1;return fetch("/api/clear").then(y=>y.ok?y.json():null).then(y=>{m||c(F9(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=B9(e,l);return o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:s,className:"modal clear-confirm",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{className:"status-dot err","aria-hidden":!0}),o.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsxs("dl",{className:"cc-plan",children:[o.jsx("dt",{children:"Goes"}),o.jsx("dd",{children:u.map(m=>o.jsx("span",{children:m},m))}),o.jsx("dt",{children:"Stays"}),o.jsx("dd",{children:f.length>0?f.map(m=>o.jsx("span",{children:m},m)):o.jsx("span",{children:"nothing"})})]}),p&&o.jsx("p",{className:"cc-final",children:p}),o.jsxs("div",{className:"cc-actions",children:[o.jsx("button",{type:"button",ref:r,className:"btn",onClick:n,children:"Cancel"}),o.jsx("button",{type:"button",className:"btn danger",onClick:t,children:h})]})]})]})})}const U9="Press Esc first if a key does nothing.",H9=[{title:"Canvas",rows:[{cap:"Space",action:"pause or resume the stream",binds:[" "]},{cap:"J",action:"next agent",binds:["j","J"]},{cap:"K",action:"previous agent",binds:["k","K"]},{cap:"W",action:"the session waiting on you — oldest first, again for the next",binds:["w","W"]},{cap:"F",action:"fit every agent on screen",binds:["f","F"]},{cap:"Z",action:"zoom to the selected agent and its session",binds:["z","Z"]},{cap:"Delete",action:"take the selected card off the board — Undo brings it back",binds:["Delete"]},{cap:"R",action:"re-arrange the canvas and drop the pins",binds:["r","R"]},{cap:"C",action:"clear the canvas and the event log — asks first",binds:["c","C"]}]},{title:"Panels and dialogs",rows:[{cap:"U",action:"usage panel",binds:["u","U"]},{cap:"L",action:"session list",binds:["l","L"]},{cap:"D",action:"detail panel",binds:["d","D"]},{cap:"H",action:"usage history",binds:["h","H"]},{cap:"A",action:"Claude accounts, where Claude Code is installed",binds:["a","A"]},{cap:"S",action:"this machine — cores, memory, temperature",binds:["s","S"]},{cap:"B",action:"Browser Watch",binds:["b","B"]},{cap:"V",action:"the sound menu — volume, tones, notifications",binds:["v","V"]},{cap:"?",action:"this sheet",binds:["?"]}]},{title:"Settings",rows:[{cap:"M",action:"sound on or off",binds:["m","M"]},{cap:"T",action:"light or dark theme",binds:["t","T"]}]},{title:"Focus and selection",rows:[{cap:"Tab",action:"reach the agent cards",binds:[]},{cap:"Enter",action:"select the focused card",binds:["Enter"]},{cap:"Shift + Enter",action:"add the focused card to the selection",binds:["Enter"]},{cap:"Esc",action:"close what is open, deselect, release focus",binds:["Escape"]}]},{title:"Mouse",rows:[{cap:"drag",action:"move a node, and pin it where you dropped it",binds:[]},{cap:"shift-click",action:"add an agent to the selection",binds:[]},{cap:"click",action:"a card: go to it and its session",binds:[]},{cap:"double-click",action:"a card: its prompt, every tool call, tokens and timing",binds:[]},{cap:"hover",action:"zoomed out, a card's name, state and numbers",binds:[]},{cap:"click",action:"the topbar speaker opens volume and sound settings",binds:[]}]}];function W9({onClose:e,onTour:t}){const n=pn(e);return o.jsx("div",{className:"modal-backdrop",onClick:e,role:"presentation",children:o.jsxs("div",{ref:n,className:"modal key-help",onClick:r=>r.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[t&&o.jsxs("div",{className:"guide-door",children:[o.jsx("span",{children:"Eight pictures of what the deck shows."}),o.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),o.jsx("div",{className:"shortcuts",children:H9.map(r=>o.jsxs(w.Fragment,{children:[o.jsx("h3",{className:"kh-group",children:r.title}),r.rows.map(s=>o.jsxs("div",{className:"sc",children:[o.jsx("kbd",{children:s.cap}),o.jsx("span",{children:s.action})]},`${r.title}:${s.cap}:${s.action}`))]},r.title))}),o.jsx("p",{className:"kh-foot",children:U9})]})]})})}const V9=1024*1024,R2=5,e$=.8,U0=24,G9="agent-dag.soundCustom.done",K9="agent-dag.soundCustom.needs-input",yu={done:G9,"needs-input":K9};function Ou(e){if(e.kind!=="audio")return e;const{bytes:t,...n}=e;return n}function A2(e){return!e||!/^[a-zA-Z0-9._-]{1,96}$/.test(e)?null:e}function Y9(e){return{done:A2(e(yu.done)),"needs-input":A2(e(yu["needs-input"]))}}function X9(e,t){return{done:e.done===t?null:e.done,"needs-input":e["needs-input"]===t?null:e["needs-input"]}}function Z9(e){return e.done&&e.done===e["needs-input"]?e.done:null}const Q9={wav:"audio/wav",wave:"audio/wav",mp3:"audio/mpeg",ogg:"audio/ogg",oga:"audio/ogg",webm:"audio/webm",m4a:"audio/mp4",mp4:"audio/mp4"},t$=new Set(["audio/wav","audio/x-wav","audio/mpeg","audio/mp3","audio/ogg","audio/webm","audio/mp4"]);function n$(e,t){const n=t.toLowerCase().split(";")[0].trim();if(t$.has(n))return n;const r=e.toLowerCase().split(".").pop()??"";return Q9[r]??n}function M2(e,t){const n=n$(e.name,e.type);if(!t$.has(n))return"Use a WAV, MP3, OGG, or browser-recorded audio file.";if(!Number.isFinite(e.size)||e.size<=0)return"The audio file is empty.";if(e.size>V9)return"Audio must be 1 MB or smaller.";if(t!==void 0){if(!Number.isFinite(t)||t<=0)return"The audio file could not be decoded.";if(t>R2)return`Audio must be ${R2} seconds or shorter.`}return null}function H0(e){return e>=U0?`There are already ${U0} custom sounds. Delete one first.`:null}function J9(e,t){const n=e.indexOf(t);return n<0?null:e[n+1]??e[n-1]??null}function eV(e){let t=0;for(const n of e)for(let r=0;r<n.length;r++)t=Math.max(t,Math.abs(n[r]));return t<=1e-5?1:Math.min(16,e$/t)}function r$(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}async function tV(e,t,n=r$()){var p;const r=((p=e.name)==null?void 0:p.trim())||"Custom sound",s=M2({name:r,type:e.type,size:e.size});if(s)throw new Error(s);const l=await e.arrayBuffer();let c;try{c=await t(l.slice(0))}catch{throw new Error("The audio file could not be decoded.")}const u=M2({name:r,type:e.type,size:e.size},c.duration);if(u)throw new Error(u);const f=Array.from({length:c.numberOfChannels},(h,m)=>c.getChannelData(m));return{id:n,name:r.replace(/\.(wav|wave|mp3|ogg|oga|webm|m4a|mp4)$/i,"")||"Custom sound",kind:"audio",mime:n$(r,e.type),duration:c.duration,normalizationGain:eV(f),bytes:l}}function nV(e,t=r$()){const n=e.name.trim()||"Custom voice",r=e.text.trim();if(!r)throw new Error("Enter the words this voice should say.");const s=Number.isFinite(e.rate)?e.rate:1,l=Number.isFinite(e.pitch)?e.pitch:1;return{id:t,name:n,kind:"tts",text:r.slice(0,180),voiceURI:e.voiceURI??"",rate:Math.min(2,Math.max(.5,s)),pitch:Math.min(2,Math.max(.5,l))}}const rV="ccdeck-notification-audio",sV=2,ws="assets",Bs="summaries";function Ku(){return typeof window<"u"?window.ccdeckNotificationAudio??null:null}function aV(){return new Promise((e,t)=>{const n=indexedDB.open(rV,sV);n.onupgradeneeded=r=>{const s=n.result,l=s.objectStoreNames.contains(ws)?n.transaction.objectStore(ws):s.createObjectStore(ws,{keyPath:"id"});if(s.objectStoreNames.contains(Bs))return;const c=s.createObjectStore(Bs,{keyPath:"id"});if(r.oldVersion<1)return;const u=l.openCursor();u.onsuccess=()=>{const f=u.result;f&&(c.put(Ou(f.value)),f.continue())}},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error??new Error("Could not open local audio storage."))})}async function Yu(e,t,n){const r=await aV();try{return await new Promise((s,l)=>{const c=r.transaction(e,t),u=n(c),f=()=>l(c.error??new Error("Local audio storage failed."));c.oncomplete=()=>s(u?u.result:void 0),c.onerror=f,c.onabort=f})}finally{r.close()}}async function oV(){const e=Ku();return e?e.list():typeof indexedDB>"u"?[]:await Yu([Bs],"readonly",t=>t.objectStore(Bs).getAll())??[]}async function iV(e){const t=Ku();return t?t.get(e):typeof indexedDB>"u"?null:await Yu([ws],"readonly",n=>n.objectStore(ws).get(e))??null}async function I2(e){const t=Ku();if(t){await t.put(e);return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Yu([ws,Bs],"readwrite",n=>{n.objectStore(ws).put(e),n.objectStore(Bs).put(Ou(e))})}async function lV(e,t){const n=Ku();if(n){const r=await n.get(e);r&&await n.put({...r,name:t});return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Yu([ws,Bs],"readwrite",r=>{const s=r.objectStore(ws),l=s.get(e);l.onsuccess=()=>{const c=l.result;if(!c)return;const u={...c,name:t};s.put(u),r.objectStore(Bs).put(Ou(u))}})}async function cV(e){const t=Ku();if(t){await t.remove(e);return}typeof indexedDB>"u"||await Yu([ws,Bs],"readwrite",n=>{n.objectStore(ws).delete(e),n.objectStore(Bs).delete(e)})}const qh=["done","needs-input"],uV=[{id:"two",label:"Two notes",notes:[{at:0,hz:740,ms:90},{at:.085,hz:440,ms:150}]},{id:"arc",label:"Descent",notes:[{at:0,hz:988,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:440,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:740,ms:55},{at:.055,hz:740,ms:55},{at:.165,hz:440,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:988,ms:110},{at:0,hz:740,ms:110},{at:.1,hz:440,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:740,ms:120},{at:.11,hz:440,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:740,ms:55},{at:.06,hz:440,ms:90}]}],dV=[{id:"two",label:"Two notes",notes:[{at:0,hz:440,ms:90},{at:.085,hz:740,ms:150}]},{id:"arc",label:"Ascent",notes:[{at:0,hz:440,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:988,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:440,ms:55},{at:.055,hz:440,ms:55},{at:.165,hz:740,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:440,ms:110},{at:.1,hz:740,ms:170},{at:.1,hz:988,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:440,ms:120},{at:.11,hz:740,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:440,ms:55},{at:.06,hz:740,ms:90}]}],ok={done:uV,"needs-input":dV},wr="two";function W0(e,t){const n=ok[e];return n.find(r=>r.id===t)??n.find(r=>r.id===wr)??n[0]}function s$(e,t){return ok[e].some(r=>r.id===t)?t:wr}W0("done",wr).notes,W0("needs-input",wr).notes;const $2=.04,a$=.24,oi=0,Gl=100,lf=5,gi=50;function Kl(e){if(!Number.isFinite(e))return gi;const t=Math.round(e/lf)*lf;return Math.min(Gl,Math.max(oi,t))}function o$(e){if(e==null)return gi;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Kl(Number(t)):gi}function V0(e){const t=Kl(e),n=$2+(a$-$2)*(t/Gl);return Math.round(n*1e4)/1e4}function hV(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(V0(e)*r*1e4)/1e4}const fV=160,pV="agent-dag.soundLevel.done",mV="agent-dag.soundLevel.needs-input",gV="agent-dag.soundFigure.done",yV="agent-dag.soundFigure.needs-input",i$={done:pV,"needs-input":mV},Bh={done:gV,"needs-input":yV},G0={done:{level:gi,figure:wr},"needs-input":{level:gi,figure:wr}};function wV(e){const t=n=>({level:o$(e(i$[n])),figure:s$(n,e(Bh[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const O2={Stop:"done",Notification:"needs-input"};function vV(e,t){var r;if(t)return null;const n=(r=e==null?void 0:e.payload)==null?void 0:r.hook_event_name;return typeof n!="string"?null:Object.hasOwn(O2,n)?O2[n]:null}function xV(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null,r=!1;const s=()=>e.enabled()?r&&(n==null?void 0:n.state)==="running"?"ready":"locked":"off",l=()=>{var m;return(m=e.onState)==null?void 0:m.call(e,s())};function c(){var m;if(!(!t||r))try{n=n??new t,(m=n.resume)==null||m.call(n).then(l,()=>{}),r=!0,l()}catch{}}function u(m,y,v=y.figure){if(!n||n.state!=="running")return!1;const S=W0(m,v),b=hV(y.level,S),_=n.currentTime;for(const k of S.notes){const j=n.createOscillator(),E=n.createGain();j.type=S.type??"sine",j.frequency.value=k.hz;const C=_+k.at,R=C+k.ms/1e3;E.gain.setValueAtTime(1e-4,C),E.gain.exponentialRampToValueAtTime(b,C+.012),E.gain.exponentialRampToValueAtTime(1e-4,R),j.connect(E).connect(n.destination),j.start(C),j.stop(R+.02)}return!0}async function f(m,y){if(!e.loadCustom)return"unavailable";let v;try{v=await e.loadCustom(m)}catch{return"unavailable"}if(!v)return"missing";if(v.kind==="tts"){if(typeof window>"u"||!("speechSynthesis"in window)||typeof SpeechSynthesisUtterance>"u")return"unavailable";const b=new SpeechSynthesisUtterance(v.text),_=window.speechSynthesis.getVoices();b.voice=_.find(k=>k.voiceURI===v.voiceURI)??null,b.rate=v.rate,b.pitch=v.pitch,b.volume=Math.min(1,V0(y.level)/a$);try{return window.speechSynthesis.cancel(),window.speechSynthesis.speak(b),"played"}catch{return"unavailable"}}if(!n||n.state!=="running")return"locked";let S;try{S=await n.decodeAudioData(v.bytes.slice(0))}catch{return"broken"}try{const b=n.createBufferSource(),_=n.createGain();b.buffer=S;const k=v.normalizationGain*(V0(y.level)/e$);return _.gain.setValueAtTime(Math.max(1e-4,k),n.currentTime),b.connect(_).connect(n.destination),b.start(n.currentTime),"played"}catch{return"unavailable"}}function p(m,y=!1){var b,_;if(!y&&!e.enabled())return!1;const v=(((b=e.prefs)==null?void 0:b.call(e))??G0)[m]??G0[m],S=((_=e.customSelection)==null?void 0:_.call(e)[m])??null;return S&&e.loadCustom?(f(S,v).then(k=>{var j;k==="played"||k==="locked"||((k==="missing"||k==="broken")&&((j=e.onCustomFailure)==null||j.call(e,m,S)),u(m,{...v,figure:wr},wr))}),!0):!n||n.state!=="running"?!1:u(m,v)}function h(m,y=gi){return f(m,{level:Kl(y),figure:wr}),!0}return{unlock:c,play:p,previewCustom:h,state:s,get context(){return n}}}const bV="With no deck tab open, get a notification wherever a sound would have played.",kV="With the ccdeck window closed, get a notification wherever a sound would have played.";function NV(e){return e?kV:bV}const SV="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",L2="Get notified when you're away from this tab.";function jV(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:L2};case"default":return{status:null,ask:!0,ok:!1,note:L2};case"denied":return{status:"Blocked",ask:!1,ok:!1,note:"Your browser is blocking them; only its own site settings can undo that. You'll still be told once this tab is closed."};default:return{status:"Unavailable",ask:!1,ok:!1,note:"This browser cannot show them. You'll still be told once this tab is closed."}}}function hu(e=typeof navigator>"u"?"":navigator.userAgent){return/\bccdeck-desktop\/\d/.test(e)}const P2={done:"Turn finished","needs-input":"Claude is asking"},_V={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function EV({onClose:e,soundOn:t,onToggleSound:n,prefs:r,onLevel:s,onFigure:l,onPreview:c,openerRef:u,customAssets:f,customSelections:p,onBuiltInSelected:h,onCustomSelected:m,onImportCustom:y,onCreateVoice:v,onRenameCustom:S,onPreviewCustom:b,onDeleteCustom:_,notifyOn:k,onToggleNotify:j,notifyVetoed:E,notifyPermission:C,onAskNotify:R}){var Ae;const I=jV(C),O=hu(),H=k&&!E&&!O,[q,$]=w.useState(""),[V,ne]=w.useState("Custom voice"),[ee,M]=w.useState("Your turn"),[Z,K]=w.useState(""),[D,P]=w.useState("1"),[B,W]=w.useState("1"),[F,G]=w.useState([]),[re,U]=w.useState(!1),Y=w.useRef(null),z=w.useRef(null),ie=Z9(p),le=((Ae=f.find(fe=>fe.id===ie))==null?void 0:Ae.name)??"the same custom sound",ge=f.length,Ne=H0(ge),Ie=Ne!==null,Ge=Ie?{"aria-disabled":!0,"aria-describedby":"sm-custom-full"}:{},[Pe,Be]=w.useState(null),Te=w.useRef(0),st=w.useRef(new Map),de=w.useRef(null);w.useEffect(()=>{if(!Pe)return;const fe=window.setTimeout(()=>Be(null),4e3);return()=>window.clearTimeout(fe)},[Pe]),w.useEffect(()=>{if(typeof window>"u"||!("speechSynthesis"in window))return;const fe=()=>{const Se=window.speechSynthesis.getVoices();G(Se),K(Ye=>{var qe;return Ye||((qe=Se[0])==null?void 0:qe.voiceURI)||""})};return fe(),window.speechSynthesis.addEventListener("voiceschanged",fe),()=>window.speechSynthesis.removeEventListener("voiceschanged",fe)},[]);const ue=async fe=>{$("");try{await fe()}catch(Se){$(Se instanceof Error?Se.message:"Custom audio could not be saved.")}},se=(fe,Se)=>{const Ye=Date.now(),qe=Cu({armedFor:Pe,target:fe,armedAt:Te.current,now:Ye,gapMs:Mu});if(qe==="arm"){Be(fe),Te.current=Ye;return}if(qe==="ignore")return;Be(null);const ke=J9(f.map(Re=>Re.id),fe);ue(async()=>{var ze;await _(fe);const Re=document.activeElement;Re!==Se&&!A0((Re==null?void 0:Re.tagName)??null)||(ze=ke?st.current.get(ke):de.current)==null||ze.focus()})},be=()=>{var fe;z.current!==null&&clearTimeout(z.current),z.current=null,((fe=Y.current)==null?void 0:fe.state)==="recording"&&Y.current.stop()},Le=async()=>{var Se;if(Ie)return;if($(""),!((Se=navigator.mediaDevices)!=null&&Se.getUserMedia)||typeof MediaRecorder>"u"){$("Microphone recording is unavailable in this browser.");return}let fe;try{fe=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{$("Microphone access was denied or unavailable.");return}if(Y.current){fe.getTracks().forEach(Ye=>Ye.stop());return}try{const Ye=["audio/webm;codecs=opus","audio/ogg;codecs=opus","audio/mp4"].find(Re=>MediaRecorder.isTypeSupported(Re)),qe=new MediaRecorder(fe,Ye?{mimeType:Ye}:void 0),ke=[];Y.current=qe,qe.ondataavailable=Re=>{Re.data.size&&ke.push(Re.data)},qe.onerror=()=>$("Recording failed. Please try again."),qe.onstop=()=>{fe.getTracks().forEach(rt=>rt.stop()),z.current!==null&&clearTimeout(z.current),z.current=null;const Re=Y.current===qe;if(Re&&(Y.current=null),U(!1),!Re||!ke.length)return;const ze=qe.mimeType.split(";")[0],Fe=ze==="audio/mp4"?"m4a":ze==="audio/ogg"?"ogg":"webm",We=new File(ke,`Recorded voice.${Fe}`,{type:ze});ue(()=>y(We))},qe.start(200),U(!0),z.current=setTimeout(be,4400)}catch{Y.current=null,fe.getTracks().forEach(Ye=>Ye.stop()),$("This browser cannot record a supported audio format.")}};w.useEffect(()=>()=>{z.current!==null&&clearTimeout(z.current);const fe=Y.current;Y.current=null,(fe==null?void 0:fe.state)==="recording"&&fe.stop()},[]);const ce=pn(e,{popover:!0}),pe=w.useRef(e);return pe.current=e,w.useEffect(()=>{const fe=Se=>{var qe,ke;const Ye=Se.target;Ye&&((qe=ce.current)!=null&&qe.contains(Ye)||(ke=u.current)!=null&&ke.contains(Ye)||pe.current())};return window.addEventListener("pointerdown",fe,!0),()=>window.removeEventListener("pointerdown",fe,!0)},[ce,u]),o.jsxs("div",{ref:ce,id:"sound-menu",className:"sound-menu",role:"dialog","aria-label":"Sound settings",children:[o.jsxs("div",{className:"sm-switches",children:[o.jsxs("label",{className:"sm-switch",children:[o.jsx("span",{className:"sm-switch-label",id:"sm-sound-label",children:"Sounds"}),o.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-labelledby":"sm-sound-label",className:"switch",onClick:n,title:"A tone when a turn finishes, and when Claude asks for something",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"sm-setting",children:[o.jsxs("label",{className:"sm-switch",children:[o.jsx("span",{className:"sm-switch-label",id:"sm-notify-label",children:"Notifications while closed"}),o.jsx("button",{type:"button",role:"switch","aria-checked":k,"aria-labelledby":"sm-notify-label",className:"switch",onClick:j,title:"With no deck tab open, a notification wherever a sound would play",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsx("p",{className:"sm-note",children:E?SV:NV(O)})]})]}),H&&o.jsxs("section",{className:"sm-channel","aria-labelledby":"sm-channel-name",children:[o.jsxs("div",{className:"sm-channel-head",children:[o.jsx("h3",{className:"sm-channel-name",id:"sm-channel-name",children:"Browser notifications"}),I.ask?o.jsx("button",{type:"button",className:"btn sm-channel-action",onClick:R,children:"Enable"}):o.jsxs("span",{className:"sm-channel-state","data-ok":I.ok||void 0,children:[I.ok&&o.jsx("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M1.5 5.2 3.9 7.6 8.5 2.4"})}),I.status]})]}),o.jsx("p",{className:"sm-note",children:I.note})]}),!t&&o.jsx("span",{id:"sm-preview-note",className:"vis-hidden",children:"Plays even when Sounds is off, so you can set a tone before turning sounds back on."}),o.jsx("div",{className:"sm-tones",children:qh.map(fe=>{const Se=r[fe],Ye=`sm-level-${fe}`,qe=`sm-figure-${fe}`;return o.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${fe}`,children:[o.jsxs("div",{className:"sm-tone-head",children:[o.jsx("h3",{className:"sm-tone-name",id:`sm-name-${fe}`,children:P2[fe]}),o.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(fe),"aria-label":`Hear the ${P2[fe].toLowerCase()} tone`,title:t?"Play this tone now, at what it is set to":"Plays even when Sounds is off","aria-describedby":t?void 0:"sm-preview-note",children:[o.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":!0,children:o.jsx("path",{d:"M3 1.6v8.8l7-4.4z"})}),"Hear it"]})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:Ye,children:"Volume"}),o.jsx("input",{id:Ye,type:"range",min:oi,max:Gl,step:lf,value:Se.level,onChange:ke=>s(fe,Number(ke.target.value)),style:{"--sm-level":`${(Se.level-oi)/(Gl-oi)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[Se.level,"%"]})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:qe,children:"Tone"}),o.jsxs("select",{id:qe,className:"sm-select",value:p[fe]?`custom:${p[fe]}`:Se.figure,onChange:ke=>{const Re=ke.target.value;Re.startsWith("custom:")?m(fe,Re.slice(7)):(h(fe),l(fe,Re))},children:[ok[fe].map(ke=>o.jsx("option",{value:ke.id,children:ke.label},ke.id)),f.length>0&&o.jsx("optgroup",{label:"Custom",children:f.map(ke=>o.jsx("option",{value:`custom:${ke.id}`,children:ke.name},ke.id))})]})]}),o.jsx("p",{className:"sm-note",children:_V[fe]})]},fe)})}),ie&&o.jsxs("p",{className:"sm-note",role:"status",children:["Both tones use “",le,"”. They may be harder to tell apart."]}),o.jsxs("section",{className:"sm-custom","aria-labelledby":"sm-custom-title",children:[o.jsxs("div",{className:"sm-custom-head",children:[o.jsx("h3",{className:"sm-tone-name",id:"sm-custom-title",children:"Custom sounds"}),o.jsxs("span",{children:[ge," of ",U0,", kept on this machine"]})]}),Ie&&o.jsx("p",{className:"sm-note",id:"sm-custom-full",children:Ne}),o.jsxs("div",{className:"sm-custom-actions",children:[o.jsxs("label",{className:"sm-custom-card sm-file",children:[o.jsxs("span",{className:"sm-custom-card-copy",children:[o.jsx("strong",{children:"Import audio"}),o.jsx("span",{children:"WAV, MP3 or OGG"})]}),o.jsx("span",{className:"btn sm-custom-action","aria-hidden":"true",children:"Choose file"}),o.jsx("input",{ref:de,type:"file",accept:"audio/wav,audio/x-wav,audio/mpeg,audio/mp3,audio/ogg,.wav,.mp3,.ogg",...Ge,onClick:fe=>{Ie&&fe.preventDefault()},onChange:fe=>{var Ye;const Se=(Ye=fe.target.files)==null?void 0:Ye[0];fe.currentTarget.value="",Se&&!Ie&&ue(()=>y(Se))}})]}),o.jsxs("div",{className:"sm-custom-card",children:[o.jsxs("span",{className:"sm-custom-card-copy",children:[o.jsx("strong",{children:"Record a clip"}),o.jsx("span",{children:re?"Recording…":"Up to 5 seconds"})]}),re?o.jsx("button",{type:"button",className:"btn sm-custom-action",onClick:be,children:"Stop & save"}):o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>void Le(),children:"Record"})]})]}),o.jsxs("details",{className:"sm-voice",children:[o.jsxs("summary",{...Ge,onClick:fe=>{const Se=fe.currentTarget.parentElement;Ie&&Se&&!Se.open&&fe.preventDefault()},children:[o.jsx("span",{children:"Spoken voice"}),o.jsx("span",{children:"Create from text"})]}),o.jsxs("div",{className:"sm-voice-fields",children:[o.jsxs("label",{children:[o.jsx("span",{children:"Name"}),o.jsx("input",{className:"ap-manage-input",value:V,maxLength:80,onChange:fe=>ne(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Text"}),o.jsx("input",{className:"ap-manage-input",value:ee,maxLength:180,onChange:fe=>M(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Voice"}),o.jsxs("select",{className:"sm-select",value:Z,onChange:fe=>K(fe.target.value),children:[o.jsx("option",{value:"",children:"System default"}),F.map(fe=>o.jsx("option",{value:fe.voiceURI,children:fe.name},fe.voiceURI))]})]}),o.jsxs("div",{className:"sm-voice-pair",children:[o.jsxs("label",{children:[o.jsx("span",{children:"Rate"}),o.jsx("input",{className:"ap-manage-input",type:"number",min:"0.5",max:"2",step:"0.1",value:D,onChange:fe=>P(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Pitch"}),o.jsx("input",{className:"ap-manage-input",type:"number",min:"0.5",max:"2",step:"0.1",value:B,onChange:fe=>W(fe.target.value)})]})]}),o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>{Ie||ue(async()=>{await v({name:V,text:ee,voiceURI:Z,rate:parseFloat(D),pitch:parseFloat(B)}),M("Your turn")})},children:"Add spoken voice"})]})]}),f.length>0&&o.jsx("div",{className:"sm-custom-list",children:f.map(fe=>o.jsxs("div",{className:"sm-custom-item",children:[o.jsx("input",{className:"ap-manage-input","aria-label":`Rename ${fe.name}`,defaultValue:fe.name,maxLength:80,onBlur:Se=>{if(!Se.target.value.trim()){Se.target.value=fe.name;return}ue(()=>S(fe.id,Se.target.value))},onKeyDown:Se=>{Se.key==="Enter"&&Se.currentTarget.blur()}}),o.jsx("span",{children:fe.kind==="audio"?`${fe.duration.toFixed(1)}s`:"Voice"}),o.jsx("button",{type:"button",className:"btn sm-custom-icon","aria-label":`Play ${fe.name}`,onClick:()=>b(fe.id),children:"Play"}),o.jsx("button",{type:"button",ref:Se=>{Se?st.current.set(fe.id,Se):st.current.delete(fe.id)},className:`btn sm-custom-icon${Pe===fe.id?" armed":""}`,onKeyDown:Se=>{Se.repeat&&Se.preventDefault()},onClick:Se=>se(fe.id,Se.currentTarget),"aria-label":Pe===fe.id?`Confirm deleting ${fe.name}`:`Delete ${fe.name}`,title:Pe===fe.id?"Press again to delete this sound. It cannot be brought back.":"Delete this sound",children:Pe===fe.id?"Confirm":"Delete"})]},fe.id))}),q&&o.jsx("p",{className:"sm-custom-error",role:"alert",children:q})]}),o.jsxs("p",{className:"sm-foot",children:[o.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const l$="agent-dag.character-enabled",c$="agent-dag.fm-volume",D2="agent-dag.fm-source",CV=[{value:"claude-fm",label:"🎧 Claude FM"},{group:"📻 Lofi Girl",value:"lofi-relax",label:"📚 Relax / study"},{group:"📻 Lofi Girl",value:"lofi-game",label:"🎮 Chill / game"},{group:"📻 Lofi Girl",value:"lofi-vibe",label:"🌅 Vibe / chill"},{group:"📻 Lofi Girl",value:"lofi-sleep",label:"💤 Sleep / chill"},{group:"📻 Radio Mix",value:"radio-mix",label:"📡 Live radio mix"},{group:"📻 Best of Nostalgia",value:"best-of-nostalgia",label:"📼 Best of nostalgia live"},{group:"📻 The Good Life Radio",value:"good-life-radio",label:"🌴 The Good Life Radio"},{group:"☕ Cafe Music BGM",value:"cafe-music-bgm",label:"☕ Cafe music BGM"}];function TV(e){return e==="lofi-relax"||e==="lofi-game"||e==="lofi-vibe"||e==="lofi-sleep"||e==="radio-mix"||e==="best-of-nostalgia"||e==="good-life-radio"||e==="cafe-music-bgm"?e:"claude-fm"}function RV(e){return e!=="0"}function AV(){return RV(yr(l$))}function MV(e){return o$(e)}function IV(){return MV(yr(c$))}const F2="agent-dag.fm-custom-stations",q2="agent-dag.fm-muted",K0="custom:",$V=/^UC[A-Za-z0-9_-]{22}$/,OV=/^[A-Za-z0-9_-]{11}$/,ik=/^[A-Za-z0-9_-]{1,80}$/,LV=/\.(mp3|aac|ogg)$/i,PV=/\.m3u8$/i,u$=2048,Lu=80;function yi(e){return`${K0}${e}`}function Yl(e){if(!e.startsWith(K0))return null;const t=e.slice(K0.length);return ik.test(t)?t:null}function B2(e){return Yl(e)??e}function DV(e){return e?"This station could not be played. Check its link, pick another, or pick it again to retry.":"This station is not live right now. Pick another, or pick it again later to retry."}function lk(e){var c,u;const t=e.trim();if(t.length>u$)return null;let n;try{n=new URL(t)}catch{return null}if(n.protocol!=="https:"||n.username||n.password)return null;const r=n.toString(),s=n.hostname.toLowerCase();if(s==="youtube.com"||s==="www.youtube.com"||s==="m.youtube.com"){if(n.port)return null;const f=(c=/^\/channel\/([^/]+)(?:\/live)?\/?$/.exec(n.pathname))==null?void 0:c[1];if(f&&$V.test(f))return{kind:"youtube-channel",url:r,channel:f};const p=(u=/^\/@([^/]+)\/live\/?$/.exec(n.pathname))==null?void 0:u[1];if(p&&/^[A-Za-z0-9._-]{1,64}$/.test(p))return{kind:"youtube-handle",url:r,handle:p};if(n.pathname==="/watch"){const h=n.searchParams.get("v")??"";if(OV.test(h))return{kind:"youtube-video",url:r,video:h}}return null}return PV.test(n.pathname)?{kind:"direct-audio",url:r,format:"hls"}:LV.test(n.pathname)?{kind:"direct-audio",url:r,format:"audio"}:null}function FV(e){return e==="1"}function qV(e){if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];const n=new Set,r=[];for(const s of t){if(!s||typeof s!="object")continue;const l=typeof s.id=="string"?s.id:"",c=typeof s.name=="string"?s.name.trim():"",u=typeof s.url=="string"?s.url.trim():"",f=lk(u);!ik.test(l)||n.has(l)||!c||c.length>Lu||!f||(n.add(l),r.push({id:l,name:c,url:f.url}))}return r}function BV(e,t,n){const r=Yl(e??"");return r&&t.some(s=>s.id===r)?yi(r):n(e)}function zV(e,t){return e===yi(t)?"claude-fm":e}function UV(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function HV(e,t,n=UV()){const r=e.trim(),s=lk(t);return!r||r.length>Lu||!ik.test(n)||!s?null:{id:n,name:r,url:s.url}}const Sl=["light","dark"],WV={light:"Light",dark:"Dark"},z2=CV,jl="Give the station a name.",VV="Use an https YouTube live or channel link, or a .mp3, .aac, .ogg or .m3u8 stream.";function GV({theme:e}){return o.jsx("span",{className:"appearance-preview","data-swatch":e,children:o.jsxs("svg",{viewBox:"0 0 112 56","aria-hidden":!0,focusable:"false",children:[o.jsx("rect",{className:"tp-canvas",width:"112",height:"56"}),o.jsx("rect",{className:"tp-surface",width:"112",height:"7"}),o.jsx("rect",{className:"tp-rule",y:"7",width:"112",height:"1"}),o.jsx("rect",{className:"tp-surface",y:"8",width:"25",height:"48"}),o.jsx("rect",{className:"tp-rule",x:"25",y:"8",width:"1",height:"48"}),o.jsx("rect",{className:"tp-card",x:"36.5",y:"27.5",width:"28",height:"14",rx:"2.5"}),o.jsx("rect",{className:"tp-tag",x:"39.5",y:"25.5",width:"13",height:"4",rx:"2"}),o.jsx("rect",{className:"tp-card",x:"76.5",y:"14.5",width:"29",height:"20",rx:"2.5"}),o.jsx("rect",{className:"tp-rule",x:"81",y:"23",width:"20",height:"2",rx:"1"}),o.jsx("rect",{className:"tp-accent",x:"81",y:"23",width:"12",height:"2",rx:"1"})]})})}function KV({theme:e,onTheme:t,characterEnabled:n,onToggleCharacter:r,fmVolume:s,onFmVolume:l,fmMuted:c,onFmMuted:u,fmSource:f,onFmSource:p,customFmStations:h,unavailableFmStations:m,onAddFmStation:y,onRenameFmStation:v,onRemoveFmStation:S,onClose:b}){var ue;const _=pn(b),k=[...z2.map(se=>({...se,label:m.has(se.value)?`${se.label} · not live`:se.label,unavailable:m.has(se.value)})),...h.map(se=>({group:"🎵 Your stations",value:yi(se.id),label:m.has(se.id)?`${se.name} · unavailable`:se.name,unavailable:m.has(se.id)}))],j=k.some(se=>se.value===f&&se.unavailable),E=[];k.forEach((se,be)=>{const Le=E[E.length-1];Le&&Le.group===se.group?Le.indexes.push(be):E.push({group:se.group,indexes:[be]})});const[C,R]=w.useState(!1),[I,O]=w.useState(()=>Math.max(0,k.findIndex(se=>se.value===f))),[H,q]=w.useState(!1),[$,V]=w.useState(""),[ne,ee]=w.useState(""),[M,Z]=w.useState(""),[K,D]=w.useState(!1),[P,B]=w.useState(""),[W,F]=w.useState(""),G=w.useRef(null),re=w.useRef(null),U=w.useRef(null),Y=w.useRef(null),z=w.useRef(null),ie=Yl(f),le=ie?h.find(se=>se.id===ie):void 0;w.useEffect(()=>{const se=k.findIndex(be=>be.value===f);O(se<0?0:se)},[f,h,m]),w.useEffect(()=>{D(!1),B((le==null?void 0:le.name)??"")},[le==null?void 0:le.id,le==null?void 0:le.name]),w.useEffect(()=>{var se;C&&((se=document.getElementById(`appearance-fm-option-${I}`))==null||se.scrollIntoView({block:"nearest"}))},[I,C]),w.useEffect(()=>{if(!C)return;const se=be=>{var ce,pe;const Le=be.target;!((ce=G.current)!=null&&ce.contains(Le))&&!((pe=z.current)!=null&&pe.contains(Le))&&R(!1)};return document.addEventListener("pointerdown",se),()=>document.removeEventListener("pointerdown",se)},[C]);const ge=se=>{const be=se.relatedTarget;be&&!se.currentTarget.contains(be)&&R(!1)},Ne=se=>{var Le;const be=k[se];be&&(O(se),p(be.value),R(!1),(Le=G.current)==null||Le.focus())},Ie=se=>{if(L6(se.key)){if(!C)return;se.preventDefault(),se.stopPropagation(),R(!1);return}if(se.key==="Tab"){R(!1);return}if(se.key==="Enter"||se.key===" "){se.preventDefault(),C?Ne(I):R(!0);return}se.key!=="ArrowDown"&&se.key!=="ArrowUp"&&se.key!=="Home"&&se.key!=="End"||(se.preventDefault(),R(!0),O(be=>se.key==="Home"?0:se.key==="End"?k.length-1:Math.min(k.length-1,Math.max(0,be+(se.key==="ArrowDown"?1:-1)))))},Ge=()=>{var se;return(se=G.current)==null?void 0:se.focus()},Pe=se=>{var Le,ce;if(se.preventDefault(),!$.trim()){Z(jl),(Le=re.current)==null||Le.focus();return}const be=HV($,ne);if(!be){Z(VV),(ce=U.current)==null||ce.focus();return}y(be),p(yi(be.id)),V(""),ee(""),Z(""),q(!1),Ge()},Be=se=>{var be;if(se.preventDefault(),!!ie){if(!P.trim()){F(jl),(be=Y.current)==null||be.focus();return}v(ie,P),D(!1),Ge()}},Te=se=>{var ce;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(se.key))return;se.preventDefault();const Le=(Sl.indexOf(e)+(se.key==="ArrowLeft"||se.key==="ArrowUp"?-1:1)+Sl.length)%Sl.length;t(Sl[Le]),(ce=se.currentTarget.querySelectorAll('[role="radio"]')[Le])==null||ce.focus()},st=se=>{var Le;if(se.key===" "){se.stopPropagation();return}if(Sf(se.target)||se.key!=="t"&&se.key!=="T"||se.ctrlKey||se.metaKey||se.altKey)return;se.preventDefault(),se.stopPropagation();const be=e==="dark"?"light":"dark";t(be),se.target.getAttribute("role")==="radio"&&((Le=se.currentTarget.querySelectorAll('[role="radio"]')[Sl.indexOf(be)])==null||Le.focus())},de=se=>{const be=k[se],Le="unavailable"in be&&be.unavailable;return o.jsxs("div",{className:"appearance-source-option",role:"option",id:`appearance-fm-option-${se}`,"aria-selected":f===be.value,"data-highlighted":I===se||void 0,"data-unavailable":Le||void 0,onMouseEnter:()=>O(se),onClick:()=>Ne(se),children:[o.jsx("span",{children:be.label}),f===be.value&&o.jsx("span",{"aria-hidden":!0,children:"✓"})]},be.value)};return Mn.createPortal(o.jsx("div",{className:"modal-backdrop appearance-backdrop",onClick:b,role:"presentation",children:o.jsxs("div",{ref:_,id:"appearance-menu",className:"modal appearance-menu appearance-modal",role:"dialog","aria-modal":"true","aria-labelledby":"appearance-title",onClick:se=>se.stopPropagation(),onKeyDown:st,children:[o.jsxs("div",{className:"appearance-head",children:[o.jsxs("div",{className:"appearance-heading",children:[o.jsx("h2",{id:"appearance-title",className:"appearance-title",children:"Appearance"}),o.jsx("p",{className:"appearance-subtitle",children:"Tune the deck to your workspace."})]}),o.jsx("button",{type:"button",className:"glyph-btn appearance-close",onClick:b,"aria-label":"Close appearance settings",title:"Close (Esc)",children:"×"})]}),o.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-theme-caption",children:[o.jsxs("div",{className:"appearance-caption",children:[o.jsxs("div",{children:[o.jsx("h3",{id:"appearance-theme-caption",children:"Color theme"}),o.jsx("p",{className:"appearance-section-note",children:"Choose how the dashboard looks."})]}),o.jsx("kbd",{className:"appearance-key","aria-hidden":!0,title:"Press T anywhere to switch themes",children:"T"})]}),o.jsx("div",{className:"appearance-themes",role:"radiogroup","aria-labelledby":"appearance-theme-caption","aria-keyshortcuts":"T",onKeyDown:Te,children:Sl.map(se=>o.jsxs("button",{type:"button",className:"appearance-theme",role:"radio","aria-checked":e===se,tabIndex:e===se?0:-1,onClick:()=>t(se),children:[o.jsx(GV,{theme:se}),o.jsxs("span",{className:"appearance-theme-name",children:[WV[se],o.jsx("svg",{className:"appearance-check",viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:o.jsx("path",{d:"M2.5 6.4 4.9 8.7 9.5 3.6"})})]})]},se))})]}),o.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-fm-caption",children:[o.jsx("div",{className:"appearance-caption",children:o.jsx("h3",{id:"appearance-fm-caption",children:"Music source"})}),o.jsxs("div",{className:"appearance-controls",children:[o.jsxs("div",{className:"appearance-source-row",children:[o.jsx("label",{htmlFor:"appearance-fm-source",children:"Station"}),o.jsxs("div",{className:`appearance-source-picker${C?" is-open":""}`,onBlur:ge,children:[o.jsxs("button",{ref:G,type:"button",id:"appearance-fm-source",className:"appearance-source-trigger",role:"combobox","aria-haspopup":"listbox","aria-expanded":C,"aria-controls":C?"appearance-fm-source-list":void 0,"aria-activedescendant":C?`appearance-fm-option-${I}`:void 0,"aria-describedby":"appearance-fm-source-note",onClick:()=>R(se=>!se),onKeyDown:Ie,children:[o.jsx("span",{children:((ue=k.find(se=>se.value===f))==null?void 0:ue.label)??z2[0].label}),o.jsx("svg",{viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:o.jsx("path",{d:"m2.5 4.5 3.5 3 3.5-3"})})]}),C&&o.jsx("div",{ref:z,id:"appearance-fm-source-list",className:"appearance-source-list",role:"listbox","aria-label":"Music stations",children:E.map((se,be)=>se.group?o.jsxs("div",{role:"group","aria-labelledby":`appearance-fm-group-${be}`,children:[o.jsx("div",{id:`appearance-fm-group-${be}`,className:"appearance-source-group",role:"presentation",children:se.group}),se.indexes.map(de)]},`group-${be}`):se.indexes.map(de))})]})]}),o.jsx("span",{id:"appearance-fm-source-note",className:"vis-hidden",children:"Changing station starts live playback automatically."}),o.jsx("p",{className:"appearance-fm-status",role:"status",children:j?DV(Yl(f)!==null):""}),o.jsxs("div",{className:"appearance-station-manage",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action","aria-expanded":H,onClick:()=>{q(se=>!se),Z("")},children:H?"Cancel":"+ Add station"}),le&&!K&&o.jsxs("span",{className:"appearance-station-edit",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action",onClick:()=>{B(le.name),F(""),D(!0)},children:"Rename"}),o.jsx("button",{type:"button",className:"btn danger appearance-station-action",onClick:()=>{S(le.id),Ge()},children:"Remove"})]})]}),H&&o.jsxs("form",{className:"appearance-station-form",onSubmit:Pe,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:re,className:"ap-manage-input",value:$,onChange:se=>V(se.target.value),"aria-invalid":M===jl||void 0,"aria-describedby":M===jl?"appearance-station-error":void 0,maxLength:Lu,autoFocus:!0})]}),o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Link"}),o.jsx("input",{ref:U,className:"ap-manage-input",value:ne,onChange:se=>ee(se.target.value),placeholder:"https://…","aria-invalid":M!==""&&M!==jl||void 0,"aria-describedby":M&&M!==jl?"appearance-station-error":void 0,inputMode:"url",autoComplete:"off",spellCheck:!1,maxLength:u$})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Add"}),M&&o.jsx("p",{id:"appearance-station-error",className:"appearance-station-error",role:"alert",children:M})]}),le&&K&&o.jsxs("form",{className:"appearance-station-form is-rename",onSubmit:Be,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:Y,className:"ap-manage-input",value:P,onChange:se=>B(se.target.value),"aria-invalid":W!==""||void 0,"aria-describedby":W?"appearance-rename-error":void 0,maxLength:Lu,autoFocus:!0})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Save"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{D(!1),Ge()},children:"Cancel"}),W&&o.jsx("p",{id:"appearance-rename-error",className:"appearance-station-error",role:"alert",children:W})]}),o.jsxs("label",{className:"appearance-row",children:[o.jsx("span",{className:"appearance-row-label",id:"appearance-character-label",children:"Show character on minimap"}),o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":n,"aria-labelledby":"appearance-character-label","aria-describedby":"appearance-character-note",onClick:r,children:o.jsx("span",{className:"switch-knob"})}),o.jsx("span",{id:"appearance-character-note",className:"vis-hidden",children:"Shows the animated minimap character and enables music playback."})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:"appearance-fm-volume",children:"Volume"}),o.jsx("input",{id:"appearance-fm-volume",type:"range",min:oi,max:Gl,step:lf,value:s,"aria-describedby":"appearance-fm-volume-note",onChange:se=>l(Number(se.target.value)),style:{"--sm-level":`${(s-oi)/(Gl-oi)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[s,"%"]})]}),o.jsxs("label",{className:"appearance-row",children:[o.jsx("span",{className:"appearance-row-label",id:"appearance-fm-mute-label",children:"Mute music"}),o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":c,"aria-labelledby":"appearance-fm-mute-label",onClick:u,children:o.jsx("span",{className:"switch-knob"})})]})]}),o.jsx("span",{id:"appearance-fm-volume-note",className:"vis-hidden",children:"Controls live music volume."})]})]})}),document.body)}const Y0="https://www.youtube-nocookie.com";function YV(e,t,n){const r=new URLSearchParams({...n?{}:{channel:e},enablejsapi:"1",autoplay:"1",playsinline:"1",rel:"0",modestbranding:"1",origin:t});return`${Y0}/embed/${n?encodeURIComponent(n):"live_stream"}?${r.toString()}`}function _l(e,t=[]){return JSON.stringify({event:"command",func:e,args:t})}function XV(e="claude-fm"){return JSON.stringify({event:"listening",id:e,channel:"widget"})}const ZV=[1,3],QV=[0,2],JV=[2,5,100,101,150];function eG(e){let t=e;if(typeof e=="string")try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;const{event:n,info:r}=t;if(n==="onReady")return{kind:"ready"};if(n==="onError"){const s=typeof r=="number"?r:Number(r==null?void 0:r.errorCode);return Number.isFinite(s)?{kind:"error",code:s}:null}if(n==="onStateChange"||n==="infoDelivery"){const s=typeof r=="number"?r:r==null?void 0:r.playerState;return typeof s!="number"||!Number.isFinite(s)?null:ZV.includes(s)?{kind:"playing",playing:!0}:QV.includes(s)?{kind:"playing",playing:!1}:null}return null}const d$=["......aaaaaa......","....aa......aa....","...a..bbbbbs..a...","...cpcbbbbbscpc...","...cpcbebbescpc...","...cpcbbbbbscpc...","...cpcbbbbbscpc...","....ccbbbbbscc....","....bbbbbbbbbs....","....bbbbbbbbbs....","......bbbbbs......","......bb..bs......","......bb..bs......","......bb..bs......"],U2=18,tG=d$.length,h$=new Set(["a","c","p"]);function Xf(e=d$){const t=[];return e.forEach((n,r)=>{let s=0;for(;s<n.length;){const l=n[s];if(l==="."){s+=1;continue}let c=1;for(;s+c<n.length&&n[s+c]===l;)c+=1;t.push({x:s,y:r,w:c,cell:l}),s+=c}}),t}const ii=148,H2=6e3,nG=16e3,f$=46,eo=34;function rG(e,t,n=ii){let r=-Math.round(t()*n);if(Math.abs(r-e)<eo){const s=e-eo>=-n?-eo:eo;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return{to:r,ms:Math.round(Math.abs(r-e)*f$)}}function sG(e){return Math.round(H2+e()*(nG-H2))}const W2=[{kind:"stroll",weight:44},{kind:"tidy",weight:17},{kind:"kick",weight:17},{kind:"sit",weight:12},{kind:"watch",weight:16},{kind:"leave",weight:7},{kind:"fish",weight:12},{kind:"skip",weight:10}];function aG(e){const t=W2.reduce((r,s)=>r+s.weight,0);let n=e()*t;for(const r of W2)if(n-=r.weight,n<0)return r.kind;return"stroll"}const oG=720,iG=260,lG=620,cG=220,V2=520,p$=1600,G2=7e3,uG=15e3,K2=6e3,dG=14e3;function El(e,t,n=ii){let r=-Math.round(t()*n);if(Math.abs(r-e)<eo){const s=e-eo>=-n?-eo:eo;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return r}const hn=(e,t)=>Math.round(Math.abs(t-e)*f$),hG=120,jh=0;function fG(e,t){const n=r=>({kind:"litter",at:t,...r});return[{x:t,prop:n({}),act:"walk",ms:hn(e,t)},{x:t,prop:n({}),act:"stoop",ms:oG},{x:jh,prop:n({held:!0}),act:"carry",ms:hn(t,jh)},{x:jh,prop:n({held:!0}),act:"windup",ms:iG},{x:jh,prop:n({held:!0,leaving:!0}),act:"toss",ms:lG}]}function pG(e,t){const n=t>e?1:-1,r=t-n*Math.min(15,Math.abs(t-e)),s=(l={})=>({kind:"ball",at:t,...l});return[{x:r,prop:s(),act:"walk",ms:hn(e,r)},{x:r,prop:s(),act:"windup",ms:cG,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"kick",ms:V2,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"stand",ms:p$-V2}]}const m$=640;function mG(e,t,n){const r=Math.max(-70,Math.min(-20,t)),s={x:r,prop:null,facing:"left"};return[{x:r,prop:null,act:"walk",ms:hn(e,r)},{...s,act:"sit",ms:600},{...s,act:"cast",ms:900},{...s,act:"fish",ms:6e3+Math.round(n()*4e3)},{...s,act:"reel",ms:1200},{...s,act:"stow",ms:500},{...s,act:"stand",ms:400},{x:0,prop:null,act:"walk",ms:hn(r,0)}]}function gG(e,t,n){const r=Math.max(-110,Math.min(-30,t)),s={x:r,prop:null};return[{...s,act:"walk",ms:hn(e,r)},{...s,act:"skip-ready",ms:500},{...s,act:"skip",ms:m$*(6+Math.floor(n()*5))},{...s,act:"skip-rest",ms:600},{...s,act:"stand",ms:350},{x:0,prop:null,act:"walk",ms:hn(r,0)}]}function yG(e,t,n){return[{x:t,prop:null,act:"walk",ms:hn(e,t)},{x:t,prop:null,act:"sit",ms:Math.round(K2+n()*(dG-K2))},{x:t,prop:null,act:"stand",ms:400}]}function wG(e,t,n){t=Math.max(-110,Math.min(0,t));const r=()=>({kind:"scope",at:t,held:!0});return[{x:t,prop:null,act:"walk",ms:hn(e,t)},{x:t,prop:r(),act:"watch",ms:Math.round(G2+n()*(uG-G2))},{x:t,prop:r(),act:"scope-pack",ms:480},{x:t,prop:null,act:"stand",ms:240}]}function Yx(e,t,n){return e.facing?e.facing:e.act==="watch"||e.act==="scope-pack"?"left":e.x===t?n:e.x>t?"right":"left"}const vG=1500,xG=e=>Math.round(1e3*Math.sqrt(2*e/vG)),bG=115,kG=e=>Math.round(e/bG*1e3),NG=620,SG=200,jG=760,_G=600,EG=240;function CG(e,t,n){const s=-(t.ledgeSpan??ii),l=xG(t.ledgeH),c=kG(t.ledgeH),u=n(),f=n(),p=-Math.round(u*t.floorSpan),h=-Math.round(f*t.floorSpan);return[{x:s,act:"walk",prop:null,ms:hn(e,s)},{x:s,act:"peer",prop:null,ms:NG},{x:s,act:"fall",prop:null,ms:l,place:"floor"},{x:s,act:"land",prop:null,ms:SG,place:"floor"},{x:p,act:"walk",prop:null,ms:hn(s,p),place:"floor",floorFrac:u},{x:h,act:"walk",prop:null,ms:hn(p,h),place:"floor",floorFrac:f},{x:s,act:"walk",prop:null,ms:hn(h,s),place:"floor"},{x:s,act:"lasso",prop:null,ms:jG,place:"floor"},{x:s,act:"rope-throw",prop:null,ms:_G,place:"floor"},{x:s,act:"rope-catch",prop:null,ms:EG,place:"floor"},{x:s,act:"climb",prop:null,ms:c},{x:s,act:"pull-up",prop:null,ms:480}]}function TG(e,t,n){const r=(n==null?void 0:n.ledgeSpan)??ii;switch(aG(t)){case"tidy":return fG(e,El(e,t,r));case"kick":return pG(e,El(e,t,r));case"sit":return yG(e,El(e,t,r),t);case"watch":return wG(e,El(e,t,r),t);case"fish":return mG(e,El(e,t,r),t);case"skip":return gG(e,El(e,t,r),t);case"leave":{if(!n||!(n.ledgeH>0)||!(n.floorSpan>0))break;return CG(e,n,t)}}const l=rG(e,t,r);return[{x:l.to,prop:null,act:"walk",ms:l.ms}]}const RG=[".xx.","xxxx",".xx."],AG=["..xx..",".xsxx.","xssxxx","xxxxsx",".xxxx.","..xx.."],MG=["...xx...............","..xaax..............",".xaallx.............","xaallllx............",".xllllllx...........","..xllllllx..........","...xllllllx.........","....xllllllxx.......",".....xllllxsxx..xx..","......xllxsssx.xllxx",".......xxssssxxxllxx","........xssssssxx...",".........xssssx.....","..........xxxx......","..........xax.......",".........xxxxx......","........xx.x.xx.....","........xl.x.lx.....",".......xl..x..lx....",".......xl..x..lx....","......xl...x...lx...","......xl...x...lx...",".....xl....x....lx..","....xxx...xxx...xxx."],Xx={litter:RG,ball:AG,scope:MG},g$=["bob","sway","groove"],Y2=9e3,IG=16e3,y$=1e3,$G=.08;function OG(e,t){const n=g$.filter(l=>l!==e),r=n[Math.min(n.length-1,Math.floor(t()*n.length))],s=(t()*2-1)*$G;return{dance:r,beatMs:Math.round(y$*(1+s))}}function LG(e){return Math.round(Y2+e()*(IG-Y2))}const PG=["...hhhhhh...","...hhhhhh...","...kkkkkk...","hhhhhhhhhhhh"],DG=3,FG=-1,X0=11,X2=9,qG=420;function BG(e,t,n){const r=t==="right"?n-e-18:e-18;return(t==="right"?1:-1)*Math.min(qG,Math.max(0,r))}const zG=260,UG=200;function HG(e,t,n){const r=(h,m=hn(e,h))=>({x:h,prop:null,act:"walk",ms:m,place:"floor"});if(!n||n.height<=0)return[r(t)];const s=Math.min(e,t);if(Math.max(e,t)<=n.left||s>=n.right)return[r(t)];const c=t>e,u=c?n.left:n.right,f=c?n.right:n.left,p={place:"floor",riser:n.height,prop:null};return[r(u,hn(e,u)),{...p,x:u,act:"mount",ms:zG},{...p,x:f,act:"walk",ms:hn(u,f)},{x:f,prop:null,act:"dismount",ms:UG,place:"floor"},{x:t,prop:null,act:"walk",ms:hn(f,t),place:"floor"}]}function Z2(e){let t=null,n=null,r=0,s=0,l=!1;const c=()=>{t!==null&&clearTimeout(t),t=null},u=()=>{l||e.hidden||!n||t!==null||(s=performance.now(),t=setTimeout(()=>{t=null;const p=n;n=null,p==null||p()},r))},f=()=>{e.hidden&&t!==null?(r=Math.max(0,r-(performance.now()-s)),c()):e.hidden||u()};return e.addEventListener("visibilitychange",f),{schedule(p,h){l||(c(),n=p,r=Math.max(0,h),u())},dispose(){l=!0,c(),n=null,e.removeEventListener("visibilitychange",f)}}}const WG={"claude-fm":"Claude FM","lofi-relax":"Lofi Girl relax/study","lofi-game":"Lofi Girl chill/game","lofi-vibe":"Lofi Girl vibe/chill","lofi-sleep":"Lofi Girl sleep/chill","radio-mix":"Radio Mix Live","best-of-nostalgia":"Best of Nostalgia Live","good-life-radio":"The Good Life Radio Live","cafe-music-bgm":"Cafe Music BGM Live"};function VG(e,t){return t&&yi(t.id)===e?t.name:Yl(e)?"Custom FM":WG[e]}const GG={"claude-fm":null,"lofi-relax":null,"lofi-game":null,"lofi-vibe":null,"lofi-sleep":null,"radio-mix":"/api/live-radio-mix","best-of-nostalgia":"/api/best-of-nostalgia","good-life-radio":"/api/good-life-radio","cafe-music-bgm":"/api/cafe-music-bgm"};function Zx(e,t){var r;const n=((r=e[0])==null?void 0:r.length)??0;return o.jsx("svg",{viewBox:`0 0 ${n} ${e.length}`,shapeRendering:"crispEdges","aria-hidden":!0,children:Xf(e).map(s=>o.jsx("rect",{x:s.x,y:s.y,width:s.w,height:1,fill:s.cell==="s"?"var(--fm-prop-shadow, var(--bg))":s.cell==="l"?"var(--fm-prop-light, var(--text))":s.cell==="a"?"var(--accent)":void 0},`${t}${s.y}-${s.x}`))})}const Qx={e:"fm-eye",s:"fm-shade",p:"fm-pad"},cf=Xf().filter(e=>!h$.has(e.cell)),KG=Xf().filter(e=>h$.has(e.cell)),Q2=cf.filter(e=>e.cell==="e"),YG=Xf(PG),XG=cf.filter(e=>e.y<X0&&e.cell!=="e").map(e=>{if(e.y!==8&&e.y!==9)return e;const t=Math.max(6,e.x);return{...e,x:t,w:Math.max(0,Math.min(12,e.x+e.w)-t)}}).filter(e=>e.w>0),ZG={left:cf.filter(e=>e.y>=X0&&e.x<X2),right:cf.filter(e=>e.y>=X0&&e.x>=X2)},J2={litter:Zx(Xx.litter,"litter"),ball:Zx(Xx.ball,"ball"),scope:Zx(Xx.scope,"scope")};function QG(e){try{return new URL(e).host}catch{return"the station's server"}}const JG=w.memo(function({fetchImpl:t,volume:n,muted:r=!1,source:s="claude-fm",playRequest:l=0,customStation:c,onAvailabilityChange:u}){const[f,p]=w.useState(null),[h,m]=w.useState(!1),[y,v]=w.useState(!1),[S,b]=w.useState(!1),_=w.useRef(l),k=w.useRef(null),j=w.useRef(null),[E,C]=w.useState(0),[R,I]=w.useState(0),[O,H]=w.useState(null),[q,$]=w.useState(null),[V,ne]=w.useState({x:0,drop:0}),[ee,M]=w.useState("ledge"),[Z,K]=w.useState("left"),[D,P]=w.useState(0),B=w.useRef(null),[W,F]=w.useState(()=>document.hidden);w.useEffect(()=>{const de=new Set,ue=()=>{var se;if(document.hidden){for(const be of((se=B.current)==null?void 0:se.getAnimations({subtree:!0}))??[])if(be.playState==="running"||be.pending){const Le=be.currentTime;be.pause(),Le!==null&&(be.currentTime=Le),de.add(be)}}else{for(const be of de)be.playState==="paused"&&be.play();de.clear()}F(document.hidden)};return ue(),document.addEventListener("visibilitychange",ue),()=>document.removeEventListener("visibilitychange",ue)},[f,h]);const[G,re]=w.useState(null),[U,Y]=w.useState(y$),[z,ie]=w.useState(()=>{var de;return((de=window.matchMedia)==null?void 0:de.call(window,"(prefers-reduced-motion: reduce)").matches)??!1});w.useEffect(()=>{var se;const de=(se=window.matchMedia)==null?void 0:se.call(window,"(prefers-reduced-motion: reduce)");if(!de)return;const ue=()=>ie(de.matches);return ue(),de.addEventListener("change",ue),()=>de.removeEventListener("change",ue)},[]);const le=w.useRef(null),ge=w.useCallback(()=>{var ue;(ue=j.current)==null||ue.destroy(),j.current=null;const de=k.current;de&&(de.pause(),de.removeAttribute("src"),de.load(),k.current=null)},[]),Ne=w.useCallback(de=>{var ue,se;(se=(ue=le.current)==null?void 0:ue.contentWindow)==null||se.postMessage(de,Y0)},[]),Ie=w.useRef(n);Ie.current=n;const Ge=w.useRef(r);Ge.current=r;const Pe=w.useCallback((de,ue,se)=>{ge();const be=new Audio;be.preload="none",be.volume=Ie.current/100,be.muted=Ge.current,k.current=be,v(!0),b(!0);const Le=()=>k.current===be,ce=()=>{ge(),v(!1),b(!1)},pe=()=>{Le()&&(ce(),m(!0),u==null||u(se,!0))},Ae=fe=>{if(Le()){if(fe instanceof DOMException&&fe.name==="NotAllowedError"){ce();return}pe()}};be.addEventListener("playing",()=>{Le()&&(b(!0),u==null||u(se,!1))}),be.addEventListener("ended",()=>{Le()&&ce()}),be.addEventListener("error",pe,{once:!0}),ue&&!be.canPlayType("application/vnd.apple.mpegurl")?nb(async()=>{const{default:fe}=await import("./hls-BFpXDghs.js");return{default:fe}},[]).then(({default:fe})=>{if(!Le())return;if(!fe.isSupported()){pe();return}const Se=new fe;j.current=Se,Se.on(fe.Events.ERROR,(Ye,qe)=>{qe.fatal&&pe()}),Se.on(fe.Events.MEDIA_ATTACHED,()=>Se.loadSource(de)),Se.on(fe.Events.MANIFEST_PARSED,()=>{be.play().catch(Ae)}),Se.attachMedia(be)},pe):(be.src=de,be.play().catch(Ae))},[u,ge]);if(w.useEffect(()=>{y&&(Ne(_l("setVolume",[n])),Ne(_l(r?"mute":"unMute")),k.current&&(k.current.volume=n/100,k.current.muted=r))},[n,r,y,Ne]),w.useEffect(()=>{let de=!0;const ue=t??fetch,se=_.current!==l;_.current=l,p(null),m(!1),v(se),b(se),ge();const be=c&&yi(c.id)===s?lk(c.url):null;if(be)return be.kind==="direct-audio"?(p({live:!0,channel:"",audio:be.url,hls:be.format==="hls"}),u==null||u(s,!1),se&&Pe(be.url,be.format==="hls",s),()=>{de=!1}):(ue(`/api/fm-station?url=${encodeURIComponent(be.url)}`).then(pe=>pe.ok?pe.json():null).then(pe=>{de&&(pe!=null&&pe.channel||pe!=null&&pe.video?(p({live:!0,channel:pe.channel??"",video:pe.video??void 0}),u==null||u(s,!1)):(m(!0),u==null||u(s,!0)))}).catch(()=>{de&&(m(!0),u==null||u(s,!0))}),()=>{de=!1});if(Yl(s))return m(!0),u==null||u(s,!0),()=>{de=!1};const Le=s,ce=GG[Le];if(ce)ue(ce).then(pe=>pe.ok?pe.json():null).then(pe=>{de&&(pe!=null&&pe.video&&p({live:!0,channel:"",video:pe.video}),u==null||u(s,!(pe!=null&&pe.video)))}).catch(()=>{de&&(u==null||u(s,!0))});else if(Le!=="claude-fm"){const pe=Le.replace("lofi-","");ue(`/api/lofi-girl?station=${encodeURIComponent(pe)}`).then(Ae=>Ae.ok?Ae.json():null).then(Ae=>{de&&(Ae!=null&&Ae.video&&p({live:!0,channel:"",video:Ae.video}),u==null||u(s,!(Ae!=null&&Ae.video)))}).catch(()=>{de&&(u==null||u(s,!0))})}else ue("/api/claude-fm").then(pe=>pe.ok?pe.json():null).then(pe=>{if(!de)return;const Ae=!!(pe!=null&&pe.live&&(pe!=null&&pe.channel));Ae&&p({live:!0,channel:pe.channel}),u==null||u(s,!Ae)}).catch(()=>{de&&(u==null||u(s,!0))});return()=>{de=!1}},[c==null?void 0:c.id,c==null?void 0:c.url,t,u,l,s,Pe,ge]),w.useEffect(()=>()=>ge(),[ge]),w.useEffect(()=>{if(!y)return;const de=ue=>{var be;if(ue.origin!==Y0||ue.source!==((be=le.current)==null?void 0:be.contentWindow))return;const se=eG(ue.data);if(se){if(se.kind==="ready"){Ne(_l("setVolume",[Ie.current])),Ne(_l(r?"mute":"unMute")),Ne(_l("playVideo"));return}if(se.kind==="playing"){b(se.playing);return}JV.includes(se.code)&&(v(!1),b(!1),m(!0),u==null||u(s,!0))}};return window.addEventListener("message",de),()=>window.removeEventListener("message",de)},[y,r,u,Ne,s]),w.useEffect(()=>{var ze;if(!f||h||z)return;const de=Z2(document);let ue=0;C(Fe=>ue=Fe);let se=null,be=0,Le=0;const ce=Fe=>{var yt,Ot;const[We,...rt]=Fe;if(!We){se=null,H(null),$(null),qe();return}H(We.act),$(We.prop),M(We.place??"ledge"),P(We.riser??0);const dt=ue,ct=Se(We);if(We.act==="kick"){const zt=(Ot=(yt=B.current)==null?void 0:yt.querySelector('.fm-prop[data-prop="ball"]'))==null?void 0:Ot.getBoundingClientRect();zt&&ne({x:BG(zt.x,Yx(We,dt,"left"),window.innerWidth),drop:Math.max(48,window.innerHeight-zt.y+24)})}Le=We.act==="walk"?Math.max(hn(dt,ct),hG):We.ms,We.act==="carry"&&(Le=hn(dt,ct)),I(Le),K(zt=>Yx({...We,x:ct},dt,zt)),C(ct),ue=ct,se=We,be=Date.now(),de.schedule(()=>ce(rt),Le)},pe=()=>{const Fe=B.current,We=Fe==null?void 0:Fe.querySelector(".fm-sprite"),rt=Fe==null?void 0:Fe.parentElement;if(!Fe||!We||!rt)return null;const dt=Fe.getBoundingClientRect(),ct=rt.getBoundingClientRect(),yt=ct.right-dt.right,Ot=ct.width-yt*2-We.offsetWidth;return Ot>0?Ot:null},Ae=()=>{const Fe=B.current,We=Fe==null?void 0:Fe.querySelector(".fm-walker"),rt=pe();if(!Fe||!We||rt==null)return;const dt=Fe.getBoundingClientRect().bottom-We.getBoundingClientRect().bottom;if(dt>0)return{ledgeH:dt,floorSpan:rt}},fe=()=>{const Fe=B.current,We=document.querySelector(".autofit-chip");if(!Fe||!We)return null;const rt=Fe.getBoundingClientRect(),dt=We.getBoundingClientRect();return dt.width<=0||dt.height<=0?null:{left:dt.left-rt.right,right:dt.right-rt.right,height:dt.height}},Se=Fe=>{const We=(Fe.place??"ledge")==="floor",rt=We?pe()??ii:ii,dt=We&&Fe.floorFrac!=null?-Math.round(Fe.floorFrac*rt):Fe.x;return Math.max(-rt,Math.min(0,dt))},Ye=()=>{if(!se)return;const Fe=Se(se);Fe!==ue&&(I(Math.max(0,be+Le-Date.now())),K(We=>Yx({...se,x:Fe},ue,We)),C(Fe),ue=Fe)},qe=()=>{de.schedule(()=>{const Fe=TG(ue,Math.random,Ae()),We=Fe.some(ct=>ct.place==="floor")?fe():null;let rt=ue;const dt=Fe.flatMap(ct=>{const yt=rt;if(rt=ct.x,!(ct.place==="floor"&&ct.act==="walk"))return[ct];const Ot=HG(yt,ct.x,We),zt=Ot.length-1;return ct.floorFrac==null?Ot:Ot.map((Xt,Dt)=>Dt===zt?{...Xt,floorFrac:ct.floorFrac}:Xt)});ce(dt)},sG(Math.random))},ke=(ze=B.current)==null?void 0:ze.parentElement,Re=typeof ResizeObserver>"u"?null:new ResizeObserver(Ye);return ke&&Re&&Re.observe(ke),qe(),()=>{de.dispose(),Re==null||Re.disconnect(),M("ledge"),C(Fe=>Math.max(-ii,Math.min(0,Fe))),I(0),H(null),$(null),P(0)}},[f,h,z]),w.useEffect(()=>{if(!S||z){re(null);return}const de=Z2(document),ue=se=>{const be=OG(se,Math.random);re(be.dance),Y(be.beatMs),de.schedule(()=>ue(be.dance),LG(Math.random))};return ue(null),()=>de.dispose()},[S,z]),!f||h)return null;const Be=()=>{if(f.audio){if(y){ge(),v(!1),b(!1);return}Pe(f.audio,f.hls===!0,s);return}if(!y){v(!0),b(!0);return}const de=!S;b(de),Ne(_l(de?"playVideo":"pauseVideo")),de||v(!1)},Te=VG(s,c),st=f.audio?QG(f.audio):"YouTube";return o.jsxs("div",{ref:B,className:"fm","data-suspended":W?"":void 0,"data-place":ee,style:{"--fm-beat":`${U}ms`},children:[q&&!q.held&&o.jsx("div",{className:"fm-prop","data-prop":q.kind,"data-leaving":q.leaving?"":void 0,style:{"--fm-prop-x":`${q.at}px`,"--fm-roll-to":`${V.x}px`,"--fm-ball-drop":`${V.drop}px`,"--fm-ball-flight-ms":`${p$}ms`,"--fm-ball-turn":Z==="right"?"1080deg":"-1080deg"},children:J2[q.kind]}),(O==="lasso"||O==="rope-throw"||O==="rope-catch"||O==="climb"||O==="pull-up")&&o.jsxs("div",{className:"fm-rope","data-act":O,style:{"--fm-rope-x":`${E}px`,"--fm-rope-ms":`${R}ms`},children:[o.jsx("div",{className:"fm-rope-line"}),o.jsxs("svg",{className:"fm-rope-hook",viewBox:"0 0 9 9",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("path",{d:"M4 8V3H3V1H1V3H0V5H2V4H3V6H5V4H6V5H8V3H7V1H5V3H4"}),o.jsx("rect",{className:"fm-rope-knot",x:"3",y:"6",width:"3",height:"2"})]})]}),o.jsxs("div",{className:"fm-walker","data-act":O??void 0,"data-place":ee,"data-facing":Z,style:{"--fm-x":`${E}px`,"--fm-walk-ms":`${R}ms`,"--fm-riser":`${D}px`,"--fm-skip-beat":`${m$}ms`},children:[(q==null?void 0:q.held)&&o.jsx("div",{className:"fm-held","data-prop":q.kind,"data-toss":q.leaving?"":void 0,children:J2[q.kind]}),["cast","fish","reel","stow"].includes(O)&&o.jsxs("svg",{className:"fm-fishing",viewBox:"0 0 24 32",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsxs("g",{children:[o.jsx("path",{d:"M24 11H22V9H20V7H18V5H16V3H13V2H8"}),o.jsx("rect",{className:"fm-fishing-grip",x:"21",y:"9",width:"3",height:"3"})]}),o.jsxs("g",{className:"fm-fishing-line",children:[o.jsx("path",{d:"M8 2V26"}),o.jsxs("g",{className:"fm-float",children:[o.jsx("rect",{x:"7",y:"25",width:"3",height:"2"}),o.jsx("rect",{x:"8",y:"24",width:"1",height:"1"})]})]}),o.jsx("path",{className:"fm-ripple",d:"M3 28H6M10 28H14M5 30H12"})]}),["skip-ready","skip","skip-rest"].includes(O)&&o.jsxs("svg",{className:"fm-skipping-rope",viewBox:"0 0 26 26",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("path",{className:"fm-skip-back",d:"M5 18H3V8H5V5H8V2H18V5H21V8H23V18H21"}),o.jsx("path",{className:"fm-skip-forward",d:"M5 18H3V14H5V11H8V9H18V11H21V14H23V18H21"}),o.jsx("path",{className:"fm-skip-front",d:"M5 18H3V21H5V23H8V25H18V23H21V21H23V18H21"}),o.jsx("path",{className:"fm-skip-return",d:"M5 18H3V19H8V20H18V19H23V18H21"}),o.jsx("path",{className:"fm-skip-handles",d:"M5 17V19M21 17V19"})]}),o.jsx("button",{type:"button",className:"fm-sprite","data-playing":S?"":void 0,"data-dance":S?G??g$[0]:void 0,onClick:Be,title:S?`Stop ${Te}`:`Play ${Te} — streams from ${st}`,"aria-label":S?`Stop ${Te}`:`Play ${Te}`,children:o.jsxs("svg",{viewBox:`0 0 ${U2} ${tG}`,shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("g",{className:"fm-gear",children:o.jsx("g",{className:"fm-gear-motion",children:KG.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,className:Qx[de.cell]},`g${de.y}-${de.x}`))})}),o.jsxs("g",{className:"fm-body",children:[Q2.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,fill:"var(--accent)"},`eye-bed-${de.x}`)),XG.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,className:Qx[de.cell]},`b${de.y}-${de.x}`)),o.jsxs("g",{className:"fm-arms",children:[o.jsx("rect",{x:4,y:8,width:2,height:2}),o.jsx("rect",{x:12,y:8,width:1,height:2}),o.jsx("rect",{x:13,y:8,width:1,height:2,className:"fm-shade"})]}),Q2.map(de=>o.jsx("rect",{x:de.x-(de.x>=U2/2?1:0)+(Z==="right"?1:0),y:de.y,width:de.w,height:1,className:"fm-eye"},`eye-${de.x}`))]}),o.jsx("g",{className:"fm-hat",children:YG.map(de=>o.jsx("rect",{x:DG+de.x,y:FG+de.y,width:de.w,height:1,className:de.cell==="k"?"fm-hatband":void 0},`h${de.y}-${de.x}`))}),(O==="climb"||O==="rope-throw"||O==="rope-catch"||O==="pull-up")&&o.jsxs("g",{className:"fm-grip",children:[o.jsx("path",{className:"fm-grip-left",d:"M5 9H4V4H7V3H9V5H6V9Z"}),o.jsx("path",{className:"fm-grip-right",d:"M12 9H14V6H11V5H9V7H12Z"})]}),(O==="land"||O==="dismount")&&o.jsxs("g",{className:"fm-crouch-legs",children:[o.jsx("path",{d:"M6 11H8V13H6Z"}),o.jsx("path",{d:"M10 11H12V13H10Z"})]}),["sit","cast","fish","reel","stow"].includes(O)&&o.jsxs("g",{className:"fm-seated-legs",children:[o.jsx("path",{className:"fm-seated-far",d:"M10 10H12V11H11V14H8V13H9V11H10Z"}),o.jsx("path",{d:"M6 10H9V11H7V15H4V14H5V11H6Z"})]}),["left","right"].map(de=>o.jsx("g",{className:"fm-leg","data-side":de,children:ZG[de].map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,className:Qx[ue.cell]},`${de}${ue.y}-${ue.x}`))},de))]})})]}),y&&!f.audio&&(f.channel||f.video)&&o.jsx("iframe",{ref:le,className:"fm-frame",title:Te,src:YV(f.channel,window.location.origin,f.video),onLoad:()=>Ne(XV()),allow:"autoplay; encrypted-media",sandbox:"allow-scripts allow-same-origin allow-presentation"})]})}),eK=15e3;function tK(e){return e.visibilityState==="visible"&&e.hasFocus()}function nK(e,t){return t||e===!0}function rK(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}const sK={"//":["What a user would NOTICE. One key per version that has something to say,","and no key at all for a version that has nothing — which is most of them.","","The rule this file exists to serve: before every release, ask 'what would a","user notice?' and write the answer here. 'Nothing user-visible' is a valid","and expected answer, and it is spelled by adding no key. A release with no","key shows no modal, and that silence is what keeps the modal worth reading","on the day it is not silent.","","What belongs here: something that changed on the user's machine or under","their hands — a hook written to or removed from settings.json, a default","that flipped, a control that moved or went away, a stored preference that","changed meaning. What does not: bounds, races, assertions that could not","fire, anything that is invisible when it is correct.","","Write it for the person running the deck, not for the person reading the","diff. `title` is the sentence they scan; `body` is what they need in order","to act on it, or to stop worrying about it.","","Keys are versions exactly as package.json spells them. A key that is not a","version, or an entry missing either field, fails the suite rather than","being quietly dropped — see src/web/__tests__/release-notes-file.test.ts.","Ordering here is for humans; the deck sorts by version itself.","","A title may open with an emoji, and if it does, put exactly ONE space after","it. Not two: the dialog gives a leading emoji its own optical gap, because","a colour glyph is drawn edge to edge inside its advance and one word space","after one reads as none. A second space here would be a lie in the data","about a defect in the type, and the suite refuses both it and no space at","all.","","A release that genuinely has nothing to say is spelled TWICE: no key here,",'and its version written into "//nothing-to-say" below. One spelling on its',"own is ambiguous — a missing key reads the same whether it was a decision","or a forgotten step, and five releases in a row were once forgotten. The list","is what tells the two apart, and release-notes-current-version.test.ts fails","the release whose version is in neither place. Any key opening with // is a","note to the author and never a release."],"//nothing-to-say":["3.23.1","3.23.2","3.23.3","3.23.4","3.26.0","3.26.1","3.26.3","3.26.4","3.26.5","3.27.6","3.27.7","3.28.0","3.28.1"],"3.29.1":[{title:"🗂️ One row per project in Projects",body:"The Projects report now counts a session's work under the folder you started it in, the same name its card has on the canvas, instead of adding a row for every folder the agent moved into. The first start after updating re-reads your transcripts once to regroup the report."},{title:"🔔 Tidier custom sounds",body:"Importing a sound, recording one and choosing a spoken voice now sit in compact cards that respond to clicks and focus like the rest of the deck."}],"3.29.0":[{title:"🎵 Your own stations in Claude FM",body:"Add any YouTube live link or radio stream as a station in Appearance, next to the built-in ones, and mute the music without losing your volume. When a station is not live, the picker now says so instead of staying silent."},{title:"🔔 Notification sounds and voices of your own",body:"Pick a local audio file or a spoken voice for each alert, so the sound that means an agent is waiting is one you will recognise."},{title:"🗑️ Drag a card off the board to remove it",body:"Drag a card to the target at the bottom of the canvas to take it off the board, or use Remove from board in the detail panel (Delete). The session keeps running, and the session list (L) brings it back."},{title:"🔐 Optional invite-only pairing",body:"Pairing works as before, with or without an invite. If you want, Local network can now be set to accept only decks that join with an invite you created, so a nearby machine cannot ask to pair on its own."},{title:"🌐 Account sharing between your machines is more reliable",body:"A locked macOS Keychain is explained instead of failing silently, a login that is broken or belongs to another account is never shared, and a sync that stops partway keeps what already arrived."},{title:"📅 Projects opens on Today",body:"The Projects report per account starts with today's work, and an empty window offers the next wider one. The topbar also shows this month's usage, and the desktop app can restart into an update from its own window."}],"3.27.0":[{title:"📊 Projects: where each account spent its work",body:"Each account card's ⋯ menu now breaks its cost down by project, over 7d / 30d / all."}],"3.27.1":[{title:"🎨 Make Appearance easier to tune",body:"The Appearance dialog now has clearer sections, stronger selection states, and a calmer layout for choosing a theme and configuring music. Your existing settings and keyboard shortcuts continue to work."}],"3.27.2":[{title:"💰 Project costs now match Usage",body:"Project cost totals no longer count the same Claude request once for every content block. Existing project history is rebuilt automatically so the totals align with the Usage panel."}],"3.27.3":[{title:"🎵 Station selection works in the desktop app",body:"The music station picker now opens inside ccdeck instead of relying on the operating system popup, so choosing a station works reliably in the Electron app."}],"3.27.4":[{title:"✅ Desktop picker release checks are green",body:"The station picker now keeps the same keyboard, motion, focus, and layout behavior as the rest of ccdeck across desktop and browser builds."}],"3.27.5":[{title:"🧭 The welcome tour stays dismissed",body:"Electron now remembers that you completed the onboarding tour at the deck level, so an update or loopback port change no longer shows the same tour again."},{title:"🎵 The station picker has a clearer finish",body:"The music selector has a tighter trigger, a purposeful chevron, and more deliberate option spacing so it reads like a native part of Appearance."}],"3.25.0":[{title:"🖱️ A click goes to the session, a double-click opens the details",body:"Clicking a card frames it with the rest of its session and leaves the detail panel shut. Double-click a card to open its details; `j`/`k`, the session list, Enter and `D` still open them too."},{title:"🔭 Cards stay readable when you zoom out",body:"At every zoom a card shows its name, its state and anything waiting on you, instead of shrinking to a coloured pill. Hover or focus a card to see it whole. Recap notes read at a distance too, and show the full recap on hover."},{title:"🌐 The Machine panel shows your network",body:"A new Network section shows download, upload and the round trip to Claude's API, and names the route when traffic goes through a VPN or a Tailscale exit node. Those checks run only while the panel is open. The panel is regrouped into CPU, Memory, Network and Thermal, with a flag at the top when something needs attention."},{title:"🎨 See each theme before you pick it",body:"The Appearance menu shows a small preview of the deck in Light and in Dark. Claude FM also keeps its volume when a notification chime plays, instead of dipping under it."}],"3.24.1":[{title:"🎛️ Appearance is one small menu now",body:"The topbar's appearance control opens a compact menu where you can choose Light or Dark and show or hide the character. The character stays on by default, and your choice is remembered."}],"3.24.0":[{title:"🎧 Claude FM plays from the minimap",body:"A small character stands on the minimap's top edge. Press it and the Claude channel's live stream plays; press it again and it stops. It only turns up when the channel is actually broadcasting, so a deck with no network never shows it at all."},{title:"🤠 And it gets on with its day",body:"It walks that edge, tidies up what it finds, kicks a ball along it, sits with its legs over the side, and watches the board through a scope. Now and then it drops onto the canvas and ropes its way back up. Headphones on while the music plays, a hat when it does not."}],"3.23.5":[{title:"🧭 The accounts panel opens on the account you are on",body:"Its windows, its resets and how old the numbers are — whole, at the top of the column. Every other account stands behind one row that says how many of them a switch could actually reach; press it to see them, or rest on it to be shown their names and how much room each has left."},{title:"⚙️ Auto-switch moved in there with them",body:"It is behind that same row now, after the accounts it switches between, rather than at the foot of the panel. The row says `auto 90%` or `auto off` so you can tell what the policy is doing without opening it — and says so in amber when it is armed with nowhere left to go."}],"3.23.0":[{title:"🧭 The accounts column leads with accounts",body:`The live account is the open row: its windows as bars, when each one resets, and how old the numbers are. Every other account rests on the two figures a switch is decided by, and opens with a click when you want the rest.
|
|
92
|
+
`)})}),o.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>void c(),title:u?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:n?"copied":"copy command"})]})]})}async function Cm(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const jz={not_an_invite:"That is not an invite — paste the whole line they sent you.",expired:"That invite has run out. Ask them for a fresh one.",not_running:"This deck is not on the network yet. Turn Local network on, then try again."},_z={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function WS(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||un(n,t)}function Ez({status:e,manual:t,startWith:n,onClose:r,onChanged:s}){const l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),f=e.pairingMode==="invite",p=pn(r,{focusRef:f?c:l}),[h,m]=w.useState(""),[y,v]=w.useState(""),[S,b]=w.useState(null),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(null),[I,O]=w.useState(()=>Date.now());w.useEffect(()=>{const re=window.setInterval(()=>O(Date.now()),1e3);return()=>window.clearInterval(re)},[]);const H=w.useRef(!0);w.useEffect(()=>()=>{H.current=!1},[]);const q=w.useRef(null),$=w.useCallback(re=>Tf(q.current)?(q.current=re,E(re),!0):!1,[]),V=w.useCallback(()=>{q.current=null,H.current&&E(null)},[]),ne=re=>{const U=ao(j,re);return{disabled:U.disabled,"aria-busy":U.busy}},ee=re=>(S==null?void 0:S.field)===re?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},M=re=>b(U=>U&&U.field===re?null:U),Z=w.useCallback(async()=>{if(f)return;const re=zz(h);if(!re){b({text:Cz(h),field:"addr"});return}const U=`${re.addr}:${re.port}`,Y=e.peers.find(z=>z.addr===re.addr&&z.port===re.port&&z.paired);if(Y){b({text:`Already paired with ${Y.name} at that address.`,field:"addr"});return}if(t.includes(U)){b({text:"This deck already calls that address.",field:"addr"});return}if($("add"))try{const z=await Cm("/api/prefs",{lan:{manual:[...t,U]}});if(!H.current)return;z!=null&&z.ok?(b(null),m(""),s(),r()):b({text:un("add that address",z),field:"addr"})}catch{H.current&&b({text:un("add that address",null),field:"addr"})}finally{V()}},[h,f,t,e.peers,s,r,$,V]),K=w.useCallback(async re=>{if(!$(`invite:${re}`))return;const U=re==="make"?"make an invite":"cancel that invite";try{const Y=await Cm("/api/lan/invite",{action:re});if(!H.current)return;Y!=null&&Y.ok?(b(null),k(null),s()):b({text:WS(_z,Y,U)})}catch{H.current&&b({text:un(U,null)})}finally{V()}},[s,$,V]),D=w.useCallback(async()=>{const re=y.trim();if(!(!re||!$("join"))){R(null);try{const U=await Cm("/api/lan/invite",{action:"join",token:re});if(!H.current)return;U!=null&&U.ok?(v(""),b(null),s(),r()):(U==null?void 0:U.reason)==="unreachable"&&Array.isArray(U.tried)&&U.tried.length?(R(U.tried),b(null)):(R(null),b({text:WS(jz,U,"use that invite"),field:"join"}))}catch{H.current&&b({text:un("use that invite",null),field:"join"})}finally{V()}}},[y,s,r,$,V]),P=w.useCallback(async(re,U)=>{try{await navigator.clipboard.writeText(re),k(U),window.setTimeout(()=>{H.current&&k(Y=>Y===U?null:Y)},1600)}catch{b({text:"Could not copy it — select the text and copy it by hand."})}},[]),B=e.invite&&e.invite.expiresAt>I?e.invite:null,W=w.useRef(!1);w.useEffect(()=>{n!=="invite"||W.current||B||(W.current=!0,K("make"))},[n,B,K]);const F=w.useRef(!1);w.useEffect(()=>{var re;n!=="invite"||F.current||!B||(F.current=!0,(re=u.current)==null||re.focus())},[n,B]);const G=e.port!=null?(e.addrs??[]).map(re=>`${re}:${e.port}`):[];return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:o.jsxs("div",{ref:p,className:"modal lan-add",onClick:re=>re.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{className:"glyph-btn",onClick:r,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[S&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:S.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>b(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsx(WM,{reach:e.reach,where:"dialog"}),f&&o.jsx("div",{className:"modal-section",children:o.jsx("p",{className:"lan-note",children:"Adding by address is off while this deck pairs only by invite."})}),!f&&o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"By address"}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("input",{ref:l,className:"ap-manage-input ap-lan-input","aria-label":"Another deck's address",value:h,placeholder:"192.168.1.5:54340",spellCheck:!1,...ee("addr"),onChange:re=>{m(re.target.value),M("addr")},onKeyDown:re=>{re.key==="Enter"&&Z()}}),h.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("add"),onClick:()=>void Z(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),o.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&G.length>0&&o.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",G.map((re,U)=>o.jsxs("span",{children:[U>0&&" or ",o.jsx("code",{className:"ap-lan-code",children:re})]},re)),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...ne("copy:mine"),onClick:()=>void P(G.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:_==="mine"?"copied":"copy"})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsxs("h3",{className:"lan-h",children:["With an invite",!B&&o.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...ne("invite:make"),onClick:()=>void K("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:j==="invite:make"?"making…":"make one to send"})]}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("input",{ref:c,className:"ap-manage-input ap-lan-input","aria-label":"An invite you were sent",value:y,placeholder:"paste one you were sent",spellCheck:!1,...ee("join"),onChange:re=>{v(re.target.value),R(null),M("join")},onKeyDown:re=>{re.key==="Enter"&&D()}}),y.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("join"),onClick:()=>void D(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:j==="join"?"joining…":"join"})]}),o.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),C&&o.jsxs("div",{className:"ap-lan-tried",children:[o.jsx("span",{className:"lan-note",children:"Nothing answered at any address in that invite. Check that deck is running with its Local network switch on."}),C.map(re=>o.jsxs("span",{className:"ap-lan-tried-row",children:[o.jsx("code",{className:"ap-lan-code",children:re.addr}),o.jsx("span",{className:"ap-lan-bad",children:re.why})]},re.addr))]}),B&&o.jsxs("div",{className:"ap-lan-invite",children:[o.jsxs("div",{className:"ap-lan-invite-head",children:[o.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),o.jsxs("span",{className:"ap-lan-invite-left",id:"lan-invite-left",children:[Vz(B.expiresAt,I)," left"]})]}),o.jsx("code",{className:"ap-lan-token",children:B.token}),o.jsxs("div",{className:"ap-lan-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",ref:u,...ne("copy:invite"),"aria-label":_==="invite"?"Invite copied":"Copy invite","aria-describedby":"lan-invite-left",onClick:()=>void P(B.token,"invite"),title:"Copy it, and send it however you already talk to them",children:_==="invite"?"copied":"copy"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("invite:withdraw"),onClick:()=>void K("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),o.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function Cz(e){const t=(e??"").trim();if(t==="")return"Type an address and a port, like 192.168.1.5:54340.";if(!t.startsWith("[")&&(t.match(/:/g)??[]).length>1)return"Too many colons to split. Use that deck's IPv4 address or its name, like 192.168.1.5:54340.";if(!t.includes(":"))return`Add the port too, like ${t}:54340.`;const n=t.slice(t.lastIndexOf(":")+1).trim();return n===""?"That is missing its port — try 192.168.1.5:54340.":/^\d+$/.test(n)?`A port runs from 1 to 65535, and this one is ${n}.`:`A port is a number, and this one is "${n}".`}const Tz=1e3;function Rz(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),r=qs(e,t);return`${n} · ${r==="now"?"just now":r}`}function VS(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function Az(){return o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),o.jsx("path",{d:"M8.4 3.6l2 2"})]})}function GS(){return o.jsxs("svg",{className:"lan-machine",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),o.jsx("path",{d:"M1 13h14"})]})}function bh({dir:e,gate:t=!1}){const n=t?12:8;return o.jsx("svg",{className:"lan-chev","data-dir":e,"data-gate":t||void 0,width:n,height:"8",viewBox:`0 0 ${n} 8`,fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:e==="out"?"M2.8 1L6 4 2.8 7":t?"M1 1v6M9.6 1L6.4 4l3.2 3":"M5.2 1L2 4l3.2 3"})})}const Mz={works:"works here",expired:"expired here",missing:"not on this deck",unavailable:"cannot share here"},Iz={works:"works there",broken:"broken there",unavailable:"cannot share there",unknown:"not offered by that deck"};function $z(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${Mz[e.here]}, ${Iz[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function Oz({row:e,source:t,status:n,accounts:r,now:s,busy:l,onClose:c,onRename:u,onCheck:f,onVerb:p,onSettings:h,onInvite:m,twins:y=[],onUnpair:v}){var Ot,zt,Xt,Dt,rn;const S=w.useRef(null),b=pn(c,{focusRef:S}),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(!1),I=w.useRef(0),[O,H]=w.useState(null),[q,$]=w.useState(!1),[V,ne]=w.useState(0),ee=w.useRef(null),M=w.useRef(!0);w.useEffect(()=>()=>{M.current=!1},[]);const Z=_!=null;w.useEffect(()=>{var je;Z&&((je=ee.current)==null||je.select())},[Z]),w.useEffect(()=>{if(!C)return;const je=window.setTimeout(()=>R(!1),4e3);return()=>window.clearTimeout(je)},[C]),w.useEffect(()=>{if(!O)return;const je=window.setTimeout(()=>H(null),4e3);return()=>window.clearTimeout(je)},[O]);const K=je=>{const xt=ao(l,je);return{disabled:xt.disabled,"aria-busy":xt.busy}},D=async je=>{const xt=await je();return M.current&&E(xt),xt==null},{peer:P,stranger:B}=t,W=e.kind==="paired",F=e.self??e.name,G=e.kind!=="dialling",re=e.kind==="dialling"?null:e.fp,U=P?P.addr?`${P.addr}:${P.port}`:"":B?B.port?`${B.addr}:${B.port}`:B.addr:e.addr,Y=(P==null?void 0:P.about)??null,z=((Ot=n.about)==null?void 0:Ot.version)??null,ie=async je=>{const xt=je.trim()===F?"":je;await D(()=>u(xt))&&k(null)},le=async()=>{if(re)try{if(await navigator.clipboard.writeText(re),!M.current)return;$(!0),window.setTimeout(()=>{M.current&&$(!1)},1600)}catch{M.current&&E("Could not copy it — select the fingerprint and copy it by hand.")}},ge=W?P!=null&&P.waiting?P.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":P!=null&&P.offers?"not said — it runs an older version":"not reached yet":"shown once paired",Ne=VS(n.about),Ie=VS(Y),Ge=Y!=null&&Y.version&&z?tU(Y.version,z):null,Pe=P?qb(P.last,s):null,Be=P&&((zt=P.last)!=null&&zt.error)?Bz({error:P.last.error,host:P.addr,port:P.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(je=>!je.manual&&je.addr).map(je=>({fp:je.fp,name:je.name,addr:je.addr,port:je.port,at:je.lastSeen??0}))],s):null,Te=(Xt=P==null?void 0:P.last)!=null&&Xt.error&&Pe&&Pe.text!==P.last.error?P.last.error:null,st=((Dt=P==null?void 0:P.last)==null?void 0:Dt.done)??[],de=!!Pe&&!!Te&&!e.quiet&&e.state.startsWith(Pe.text),ue=W||e.kind==="dialling",se=((P==null?void 0:P.via)??e.via)==="tailscale",be=P?P.waiting?null:P.manual?se?"added by its Tailscale address":"added by address":se?"over Tailscale":"on this network":e.kind==="nearby"?se?"heard over Tailscale":"heard on this network":se?"asked this deck to pair, over Tailscale":"asked this deck to pair",Le=e.tone==="bad"?"bad":W?e.here?"up":"down":"loose",ce=l===`check:${e.fp}`,pe=(P==null?void 0:P.offers)??null,Ae=Le==="up"?(pe==null?void 0:pe.current)??null:null,fe=Ae&&"key"in Ae?Ae.key:null,Se=!!Ae&&"hidden"in Ae,Ye=!!Ae&&"other"in Ae,qe=W?rU((pe==null?void 0:pe.accounts)??null,r,n.shared??[],fe):[],ke=qe.filter(je=>je.in==null&&je.out==="cut"),Re=qe.some(je=>je.in!=null),ze=qe.some(je=>je.out!=null),Fe=new Map(st.map(je=>[je.email,je])),We=st.filter(je=>!qe.some(xt=>xt.email===je.email)),rt=W?pe?pe.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:P!=null&&P.waiting?"What that deck offers is not known yet. A deck that calls in says so each time it calls — one on an older version never does.":(rn=P==null?void 0:P.last)!=null&&rn.error?"What that deck offers is not known — the last attempt to ask it did not get through.":"Nobody has asked that deck what it offers yet. The next round asks it.":null,dt=pe&&(P!=null&&P.last)&&P.last.at-pe.at>Tz?qs(pe.at,s):null,ct=[];W&&(P!=null&&P.pairedAt)?ct.push({label:"Paired",value:Rz(P.pairedAt,s),tone:"meta"}):e.kind==="declined"&&B&&ct.push({label:"Paired",value:`no · you said no ${Bb(B.at,s)}`,tone:"meta"}),ct.push({label:"Fingerprint",value:re?o.jsxs("span",{className:"lan-fp",children:[o.jsx("code",{className:"ap-lan-code",children:re}),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void le(),"aria-label":q?"Fingerprint copied":"Copy the fingerprint",children:q?"copied":"copy"})]}):"not known — nothing has answered there",tone:re?void 0:"quiet"});const yt=y.length?[{row:e,peer:P??null},...y]:[];return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:o.jsxs("div",{ref:b,className:"modal lan-peer","data-tone":e.tone,onClick:je=>je.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[o.jsxs("header",{className:"modal-head lan-peer-head",children:[o.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("div",{className:"lan-peer-id",children:[Z?o.jsxs("form",{className:"lan-peer-edit",onSubmit:je=>{je.preventDefault(),ie(_??"")},children:[o.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),o.jsx("input",{ref:ee,className:"ap-manage-input lan-peer-input",value:_??"",maxLength:48,placeholder:F,"aria-label":"Name for this deck, shown on this deck only",onChange:je=>k(je.target.value)}),o.jsx("button",{type:"submit",className:"ap-manage-btn",...K(`alias:${e.fp}`),children:"save"}),o.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>k(null),children:"cancel"})]}):o.jsxs("span",{className:"lan-peer-title",children:[o.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),G&&o.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",onClick:()=>{E(null),k(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:o.jsx(Az,{})})]}),o.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&o.jsxs(o.Fragment,{children:["calls itself ",o.jsx("span",{className:"lan-peer-self",children:e.self}),Z&&o.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...K(`alias:${e.fp}`),onClick:()=>void ie(""),children:"use this name"}),o.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&o.jsx("span",{"aria-hidden":!0,children:" · "})]}),o.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{ref:S,type:"button",className:"glyph-btn",onClick:c,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body lan-peer-body",children:[j&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:j}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>E(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsxs("div",{className:"lan-map","data-link":Le,"data-asking":ce||void 0,"data-bus":qe.length>0||void 0,children:[o.jsxs("div",{className:"lan-ends",children:[o.jsxs("p",{className:"lan-end",children:[o.jsx("span",{className:"lan-end-name",children:"This deck"}),Ne&&o.jsx("span",{className:"lan-end-runs",children:Ne}),W&&n.shareActive===!1&&o.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),o.jsxs("p",{className:"lan-end","data-side":"there",children:[o.jsx("span",{className:"lan-end-name",children:e.name}),e.kind!=="dialling"&&o.jsxs("span",{className:"lan-end-runs",children:[Ie??(Y?"not said":ge),Ge?` · ${Ge<0?"older":"newer"}`:null]}),Se&&o.jsx("span",{className:"lan-end-note",children:"current account hidden"}),Ye&&o.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),o.jsxs("div",{className:"lan-link",children:[o.jsx(GS,{}),o.jsxs("span",{className:"lan-span",children:[o.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[o.jsx("i",{className:"lan-glint","data-dir":"out"}),o.jsx("i",{className:"lan-glint","data-dir":"in"})]}),o.jsx("span",{className:"lan-link-label",children:U?o.jsx("code",{className:"ap-lan-code",children:U}):"none here — it calls this deck"})]}),o.jsx(GS,{}),(U&&be||ue)&&o.jsxs("p",{className:"lan-link-sub",children:[U&&be,U&&be&&ue&&" · ",ue&&(Pe?de?o.jsx("code",{className:"ap-lan-code",children:Te}):o.jsx("span",{className:"lan-round","data-tone":Pe.tone,children:Pe.text.replace(/ · now$/," · just now")}):"not asked yet"),ue&&Te&&!de&&o.jsx("code",{className:"lan-fact-raw",children:Te})]}),We.length>0&&o.jsx("ul",{className:"lan-done",children:We.map(je=>{const xt=F0(je);return o.jsxs("li",{"data-ok":je.ok&&!xt,children:[je.email," ",o.jsxs("span",{className:"lan-done-what",children:[je.ok?"arrived":"did not arrive",xt&&` — ${xt.long}`]})]},`${je.email}:${je.action}`)})}),Be&&o.jsx("p",{className:"lan-note lan-link-note",children:Be}),(P==null?void 0:P.waiting)&&o.jsx("p",{className:"lan-note lan-link-note",children:e.hint}),(Pe==null?void 0:Pe.hint)&&o.jsx("p",{className:"lan-note lan-link-note",children:Pe.hint})]}),qe.length>0&&o.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${e.name}`,children:qe.map((je,xt)=>{const bt=Fe.get(je.email),_n=bt?F0(bt):null,Ut=je.out==="live"||je.in!=null&&je.in!=="cut";return o.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":je.tone,"data-draw":je.in&&je.out?"both":je.in?"in":"out","data-used-there":je.usedThere||void 0,style:{"--i":xt},children:[o.jsx("i",{className:"lan-pip","data-end":"here","data-state":je.here,"aria-hidden":!0}),o.jsxs("span",{className:"lan-track",children:[o.jsxs("span",{className:"lan-wire","data-flow":Ut?"live":"cut","aria-hidden":!0,children:[(je.in==="live"||je.in==="wait")&&o.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":je.in}),je.out==="live"&&o.jsx("i",{className:"lan-glint","data-dir":"out"})]}),je.in&&je.in!=="cut"&&o.jsx(bh,{dir:"in",gate:je.in==="blocked"}),je.out==="live"&&o.jsx(bh,{dir:"out"}),o.jsx("span",{className:"lan-lane-email",children:je.email})]}),o.jsx("i",{className:"lan-pip","data-end":"there","data-state":je.there,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:$z(je)}),(je.caption||bt)&&o.jsxs("span",{className:"lan-lane-note",children:[je.caption,je.caption&&bt&&" · ",bt&&o.jsxs("span",{className:"lan-lane-done","data-ok":bt.ok&&!_n,children:[bt.ok?"arrived last round":"did not arrive last round",_n&&` — ${_n.long}`]})]})]},je.key)})},V),W&&o.jsxs(o.Fragment,{children:[ke.length>0&&o.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",ke.length===1?ke[0].email:"the expired ones"," until you sign in again here."]}),rt&&o.jsx("p",{className:"lan-empty",children:rt}),dt&&o.jsxs("p",{className:"lan-stale",children:["As of ",dt==="now"?"just now":dt,", when it last answered."]}),o.jsxs("div",{className:"lan-legend",children:[Re&&o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:o.jsx(bh,{dir:"in"})}),"from ",e.name]}),ze?o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:o.jsx(bh,{dir:"out"})}),"from this deck, to every paired deck"]}):o.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),o.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:h,"aria-label":"Change what this deck offers",children:"change"})]})]})]}),o.jsx("dl",{className:"lan-facts",children:ct.map(je=>o.jsxs("div",{className:"lan-fact","data-tone":je.tone,children:[o.jsx("dt",{children:je.label}),o.jsx("dd",{children:je.value})]},je.label))}),yt.length>1&&o.jsxs("div",{className:"modal-section",children:[o.jsxs("h3",{className:"lan-h",children:[yt.length," decks on this machine"]}),o.jsx("ul",{className:"lan-twins",role:"list",children:yt.map((je,xt)=>{var Lt,Zt,In,Hr;const bt=(Lt=je.peer)!=null&&Lt.addr?`${je.peer.addr}:${je.peer.port}`:je.row.addr,_n=bt||je.row.fp,Ut=(Zt=je.peer)!=null&&Zt.pairedAt?qs(je.peer.pairedAt,s):null,Vn=[(Hr=(In=je.peer)==null?void 0:In.about)!=null&&Hr.version?`runs ${je.peer.about.version}`:null,Ut?`paired ${Ut==="now"?"just now":Ut}`:null,je.row.state].filter(Boolean).join(" · "),Vt=je.row.fp;return o.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":je.row.tone,children:[o.jsx("i",{className:je.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),bt?o.jsx("code",{className:"ap-lan-code lan-twin-at",children:bt}):o.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),o.jsx("code",{className:"ap-lan-code lan-twin-fp",children:Vt}),xt>0&&v&&o.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${O===Vt?" armed":""}`,...K(`unpair:${Vt}`),onKeyDown:xe=>{xe.repeat&&xe.preventDefault()},onClick:()=>{const xe=Date.now(),lr=Cu({armedFor:O,target:Vt,armedAt:I.current,now:xe,gapMs:Mu});if(lr==="arm"){H(Vt),I.current=xe;return}lr!=="ignore"&&(H(null),D(()=>v(Vt)))},"aria-label":O===Vt?`Confirm unpairing ${_n}`:`Unpair ${_n}`,title:O===Vt?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this one of the machine's decks",children:l===`unpair:${Vt}`?"unpairing…":O===Vt?"confirm":"unpair"}),o.jsx("span",{className:"lan-twin-meta",children:xt===0?`${Vn} · shown above`:Vn})]},Vt)})})]})]}),o.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&o.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),W&&!(P!=null&&P.waiting)&&o.jsx("button",{type:"button",className:"btn",...K(`check:${e.fp}`),onClick:()=>void D(f).then(je=>{je&&M.current&&ne(xt=>xt+1)}),title:"Ask this deck now instead of waiting for the next round",children:l===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&o.jsx("button",{type:"button",className:`btn danger lan-peer-verb${C?" armed":""}`,...K(`unpair:${e.fp}`),onKeyDown:je=>{je.repeat&&je.preventDefault()},onClick:()=>{const je=Date.now(),xt=Cu({armedFor:C?e.fp:null,target:e.fp,armedAt:I.current,now:je,gapMs:Mu});if(xt==="arm"){R(!0),I.current=je;return}xt!=="ignore"&&(R(!1),D(p))},"aria-label":C?`Confirm unpairing ${e.name}`:`Unpair ${e.name}`,title:C?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:l===`unpair:${e.fp}`?"Unpairing…":C?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&n.pairingMode!=="invite"&&o.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...K(`accept:${e.fp}`),onClick:()=>void D(p),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:l===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&o.jsx("button",{type:"button",className:"btn lan-peer-verb",...K(`drop:${e.fp}`),onClick:()=>void D(p),title:"Stop trying this address. Nothing was ever paired here.",children:l===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&n.pairingMode!=="invite"&&o.jsx("button",{type:"button",className:"btn lan-peer-verb",...K(`allow:${e.fp}`),onClick:()=>void D(p),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:l===`allow:${e.fp}`?"Allowing…":"Let it ask again"}),(e.kind==="nearby"||e.kind==="declined")&&n.pairingMode==="invite"&&m&&o.jsx("button",{type:"button",className:"btn primary lan-peer-verb",onClick:m,title:"This deck pairs only by invite. Make one and send it to whoever is at that machine.",children:"Invite to pair"})]})]})}),document.body)}function Lz(e){if(!e.running)return`Tailscale is ${e.state==="Stopped"?"turned off":e.state==="NeedsLogin"||e.state==="NeedsMachineAuth"?"signed out":e.state==="Starting"?"still starting":"not answering"} on this machine`;const t=e.login??"your Tailscale account";return e.on?`${e.devices} online · ${t}`:t}const kh="Paused while this deck pairs only by invite. Turn that off above to use it.";function Pz({status:e,accounts:t,onClose:n,onChanged:r}){const s=pn(n),[l,c]=w.useState(null),[u,f]=w.useState(null),[p,h]=w.useState(!1),[m,y]=w.useState(null),v=w.useRef(null),S=M=>{const Z=ao(m,M);return{disabled:Z.disabled,"aria-busy":Z.busy}},b=w.useRef(null),_=w.useRef(!0);w.useEffect(()=>()=>{_.current=!1},[]),w.useEffect(()=>{b.current=XS(b.current,e.shared??[],null)},[e.shared]);const k=w.useCallback(async(M,Z,K="write")=>{v.current=K,y(K);try{const P=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:M})})).json().catch(()=>null);return _.current?(P!=null&&P.ok?f(null):f(un(Z,P)),r(),(P==null?void 0:P.ok)===!0):!1}catch{return _.current&&f(un(Z,null)),!1}finally{v.current=null,_.current&&y(null)}},[r]),j=w.useCallback(async()=>{if(l!=null&&l!==(e.name??"")){if(!await k({name:l},"save the name","name"))return;_.current&&c(null)}n()},[l,e.name,k,n]),E=async()=>{if(!e.fp)return;const M=await hi(e.fp);if(_.current){if(!M){f("Could not copy it — select the fingerprint and copy it by hand.");return}h(!0),window.setTimeout(()=>{_.current&&h(!1)},1600)}},C=new Set(b.current??e.shared??[]),R=e.autoAsk!==!1,I=e.autoAccept!==!1,O=e.pairingMode==="invite",H=M=>{const Z=S(M);return{...Z,disabled:Z.disabled||O}},q=e.shareActive!==!1,$=e.tailscale??null,V=!!($!=null&&$.on),ne=($==null?void 0:$.ask)!==!1,ee=($==null?void 0:$.accept)!==!1;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:s,className:"modal lan-modal",onClick:M=>M.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[u&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:u}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>f(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Name"}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("span",{className:"ap-lan-label",children:"appear as"}),o.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:l??e.name??"",placeholder:"this machine",onChange:M=>c(M.target.value),onKeyDown:M=>{M.key!=="Enter"||l==null||(k({name:l},"save the name","name"),c(null))}}),l!=null&&l!==(e.name??"")&&o.jsx("button",{type:"button",className:"ap-manage-btn",...S("name"),onClick:()=>{k({name:l},"save the name","name"),c(null)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?o.jsxs("span",{className:"lan-fp",children:[o.jsx("code",{className:"ap-lan-code",children:e.fp}),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void E(),"aria-label":p?"Fingerprint copied":"Copy this deck's fingerprint",children:p?"copied":"copy"})]}):o.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Share these accounts"}),o.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&o.jsx("span",{className:"ap-lan-empty",children:"No Claude accounts on this deck yet — add one with + at the top of this panel."}),t.map(M=>o.jsxs("label",{className:"ap-lan-pick",title:M.alive?"Offer this account to the decks you have paired with, so one whose copy has died can heal from yours. Unticking stops it being offered from now on; it does not take back a copy somebody already has.":"This deck cannot use this login, so it has nothing to offer — a deck that can will heal it",children:[o.jsx("input",{type:"checkbox",checked:C.has(M.key),onChange:Z=>{const K=Wz(b.current,e.shared??[],M.key,Z.target.checked);b.current=K,k({shared:K},Z.target.checked?"share that account":"stop sharing that account").then(D=>{b.current===K&&(b.current=XS(K,e.shared??[],{ok:D}))})}}),o.jsx("span",{className:"ap-lan-pick-name",children:M.email}),!M.alive&&o.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},M.key))]}),t.length>0&&o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":q,"aria-label":"Show paired decks which of these this deck is using",...S("current"),onClick:()=>void k({shareActive:!q},q?"stop showing which account this deck is using":"show which account this deck is using","current"),title:q?"Stop telling paired decks which account this one is on. They read “current account hidden” instead.":"Tell paired decks which of the ticked accounts this one is on. An unticked account is never named.",children:o.jsx("span",{className:"switch-knob"})})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",id:"lan-pairing-h",children:"Pairing"}),o.jsx("div",{className:"lan-switches lan-switches-lead",role:"group","aria-labelledby":"lan-pairing-h",children:o.jsxs("div",{className:"lan-switch",children:[o.jsxs("span",{className:"lan-switch-what",children:["Pair new decks only by invite",O&&o.jsx("span",{id:"lan-invite-only-detail",className:"lan-switch-detail",children:"A new deck needs an invite from + in the panel. Paired decks stay paired."})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":O,"aria-label":"Pair new decks only by invite","aria-describedby":O?"lan-invite-only-detail":void 0,...S("mode"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({pairingMode:O?"automatic":"invite"},O?"let decks pair on their own again":"pair new decks only by invite","mode"),title:O?"Let decks on this network pair as the two switches below say again.":"Only a deck you send an invite to can pair with this one. Nearby decks can't ask, and requests waiting now are turned away.",children:o.jsx("span",{className:"switch-knob"})})]})}),o.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-auto-h",children:[o.jsxs("p",{className:"lan-sub",id:"lan-auto-h",children:["Automatic pairing",O&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches","data-paused":O||void 0,children:[o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":R,"aria-label":"Ask every deck this one finds",...H("ask"),onClick:()=>void k({autoAsk:!R},R?"stop asking automatically":"ask every deck this one finds","ask"),title:O?kh:R?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck heard on this network. Somebody over there still has to say yes.",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":I,"aria-label":"Say yes to every deck that asks","data-tone":"warn",...H("accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({autoAccept:!I},I?"stop accepting automatically":"accept every deck that asks","accept"),title:O?kh:I?"Stop saying yes for you. A deck that asks waits in the panel again.":"Say yes for you. Every deck on this network that asks is paired without anybody being asked here.",children:o.jsx("span",{className:"switch-knob"})})]})]})]})]}),($==null?void 0:$.found)&&o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Tailscale"}),o.jsxs("div",{className:"lan-switches",children:[o.jsxs("div",{className:"lan-switch",children:[o.jsxs("span",{className:"lan-switch-what",children:["Look for my devices",o.jsx("span",{id:"lan-ts-detail",className:"lan-switch-detail",children:Lz($)})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":V,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",...S("tailscale"),onClick:()=>void k({tailscale:!V},V?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:V?"Stop. Nothing is looked for or answered over the tailnet; decks already paired stay paired.":"Find the decks on your other machines on Tailscale, wherever they are. Only machines signed in to your Tailscale account are asked.",children:o.jsx("span",{className:"switch-knob"})})]}),V&&o.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-ts-auto-h",children:[o.jsxs("p",{className:"lan-sub",id:"lan-ts-auto-h",children:["Automatic pairing with my devices",O&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches",children:[o.jsxs("div",{className:"lan-switch","data-paused":O||void 0,children:[o.jsx("span",{className:"lan-switch-what",children:"Ask each device it finds"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ne,"aria-label":"Ask each of my devices it finds over Tailscale",...H("tailscale-ask"),onClick:()=>void k({tailscaleAsk:!ne},ne?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:O?kh:ne?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck found on your devices over Tailscale.",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"lan-switch","data-paused":O||void 0,children:[o.jsx("span",{className:"lan-switch-what",children:"Say yes to each device that asks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ee,"aria-label":"Say yes to my devices when they ask over Tailscale","data-tone":"warn",...H("tailscale-accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({tailscaleAccept:!ee},ee?"stop accepting your devices automatically":"accept your devices automatically","tailscale-accept"),title:O?kh:ee?"Stop saying yes for you. A device that asks waits in the panel again.":"Say yes for you when a deck on one of your own devices asks. Anybody else on the tailnet still waits for a press.",children:o.jsx("span",{className:"switch-knob"})})]})]})]})]})]})]}),o.jsxs("footer",{className:"lan-setup-foot",children:[o.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),o.jsx("button",{type:"button",className:"btn primary",...S("name"),onClick:()=>void j(),children:"Done"})]})]})}),document.body)}function qs(e,t){if(e==null)return"not seen";const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"now";const r=Math.round(n/60);if(r<60)return`${r}m ago`;const s=Math.round(r/60);return s<48?`${s}h ago`:`${Math.round(s/24)}d ago`}const KS={keychain_unavailable:{short:"Keychain locked on the other Mac",long:`the other Mac could not export it. On that Mac: ${Lb}. The next round brings it.`}};function F0(e){return e.why?Object.hasOwn(KS,e.why)?KS[e.why]:tf(e.why):null}const Fb={"waiting for the other deck to accept this one":{text:"waiting for them to say yes",tone:"idle"},"that deck said no":{text:"it said no",tone:"bad"},"that deck pairs only by invite":{text:"it pairs only by invite",tone:"idle"},"this deck pairs only by invite":{text:"needs an invite · your setting",tone:"idle"}},Dz={ECONNREFUSED:"not listening",EHOSTUNREACH:"no route to it",ENETUNREACH:"no network here",ETIMEDOUT:"no answer",ECONNRESET:"it hung up",EHOSTDOWN:"it is down",ENOTFOUND:"name not found",EACCES:"blocked here",EPIPE:"it hung up"};function YS(e){var r;const t=Fz[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&Dz[n]||e}const Fz={"handshake timed out":"no answer","peer closed the connection":"it hung up","peer went quiet":"it stopped mid-sentence","bad reply":"it answered with nonsense","no manifest":"it would not say what it has","bad challenge":"it answered as somebody else","a different deck is answering at that address":"a different deck is at that address","that deck could not prove its own key":"it could not prove who it is","the other deck refused this one's proof":"it would not take this deck's word","the other deck refused this handshake":"it turned this deck away","that deck has this one pinned under a different key":"it knows this deck by another key"};function qb(e,t){var h;if(!e)return null;if(e.error&&((h=e.done)!=null&&h.length)){const m=qb({...e,error:void 0},t),y=` · ${qs(e.at,t)}`;return{...m,text:`${m.text.slice(0,-y.length)}, then ${YS(e.error)}${y}`,tone:"bad"}}if(e.error)return Fb[e.error]??{text:YS(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${qs(e.at,t)}`,tone:"idle"};const r=n.filter(m=>m.ok),s=r.length===1?"login":"logins",l=n.map(m=>({d:m,why:F0(m)})).filter(m=>m.why),c=[...new Set(l.map(m=>m.why.short))],u=c.length?`, ${c.join(", ")}`:"",f=l.length?l.map(m=>`${m.d.email}: ${m.why.long}`).join(" "):void 0,p=qs(e.at,t);return r.length===n.length?{text:`${r.length} ${s} arrived${u} · ${p}`,tone:l.length?"warn":"ok",...f?{hint:f}:{}}:{text:`${r.length} of ${n.length} logins arrived${u} · ${p}`,tone:"bad",...f?{hint:f}:{}}}const qz=9e4;function Bz({error:e,host:t,port:n},r,s,l=45317){if(e!=="handshake timed out")return null;const c=(t??"").trim();if(!c)return null;const u=r.filter(p=>p.addr===c&&p.port&&p.at>0&&s-p.at<qz);if(!u.length)return null;const f=[...new Set(u.map(p=>p.port))];if(n!=null&&!f.includes(n)){const p=f.length===1?`port ${f[0]}`:`ports ${f.join(" and ")}`;return`A deck at ${c} is announcing itself on ${p}, not on ${n}. This deck already hears it and dials it there, so this typed row has nothing to reach.`}return`That machine is running the deck — its beacon arrives here every half minute — and what this deck sends back never gets there. That is a firewall on ${c}, not a network fault. Whoever uses it can allow two ports: UDP ${l} and TCP ${n??f[0]}.`}const q0=5e3,VM=6e4,Mu=400;function zz(e){const t=(e??"").trim(),n=t.lastIndexOf(":");if(n<=0||n===t.length-1)return null;const r=t.slice(0,n).trim(),s=Number(t.slice(n+1).trim());return!r||!Number.isInteger(s)||s<1||s>65535||r.includes(":")&&!(r.startsWith("[")&&r.endsWith("]"))?null:{addr:r,port:s}}function un(e,t){if(t==null)return`Could not ${e} — the deck did not answer.`;const n=t.reason?Uz[t.reason]:void 0;return n?`Could not ${e} — ${n}`:t.reason?`Could not ${e} — the deck refused it (${t.reason}).`:`Could not ${e}.`}const Uz={prefs_unreadable:"this deck cannot read its settings file, so it will not write over it. The file may belong to another user, for example after ccdeck was run with sudo. The deck's log names the file.",prefs_not_writable:"this deck is not allowed to save its settings. The settings folder may belong to another user, for example after ccdeck was run with sudo, or another program may be holding the file. The deck's log names the folder."};function Hz(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function Wz(e,t,n,r){const s=new Set(e??t);return r?s.add(n):s.delete(n),[...s]}function XS(e,t,n){return e==null||n!=null&&!n.ok||Hz(e,t)?null:e}function Vz(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function GM(e,t){var n,r;return(n=e.last)!=null&&n.error&&!Fb[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<rf||e.lastSeen!=null&&t-e.lastSeen<rf)}const rf=95e3,KM=160,Gz=6,YM=140;function Kz(e,t){const n=[],r=[];for(const s of e??[])(GM(s,t)?n:r).push(s);return{online:n,offline:r}}function Yz(e){var t;return(t=e.tailscale)!=null&&t.exitNode?"Tailscale sends this machine's local network through an exit node, so decks on this network cannot find this one. Turn on Allow local network access in Tailscale's exit node menu to bring them back.":"This machine sends its local network through a VPN, so decks on this network cannot find this one. Allowing local network access in the VPN brings them back."}function Xz(e,t){if(!e)return{text:"checking…",tone:"idle"};if(!e.enabled)return{text:"",tone:"idle"};if(e.stalled)return{text:`could not start — ${e.stalled}`,tone:"bad"};if(!e.running)return{text:"starting…",tone:"wait"};const n=(e.pending??[]).length;if(n)return{text:n===1?"1 deck is waiting for your answer":`${n} decks are waiting for your answer`,tone:"wait"};const r=(e.peers??[]).filter(v=>v.paired!==!1||v.met);if(!r.length)return{text:"no deck paired yet",tone:"idle"};const s=r.filter(v=>v.waiting),l=r.filter(v=>!v.waiting),c=s.filter(v=>{var S;return!((S=v.last)!=null&&S.error)&&v.lastSeen!=null&&t-v.lastSeen<rf}),{online:u,offline:f}=Kz(l,t),p=[...f,...s.filter(v=>!c.includes(v))],h=u.length+c.length,m=u.filter(v=>{var S;return((S=v.last)==null?void 0:S.error)==="waiting for the other deck to accept this one"});if(h&&m.length===h)return{text:h===1?"1 deck found · waiting for them to accept":`${h} decks found · waiting for them to accept`,tone:"wait"};if(!h)return{text:p.length===1?"this deck cannot reach the one it is paired with":`this deck cannot reach any of its ${p.length} decks`,tone:"bad"};const y=h===1?"1 deck ready":`${h} decks ready`;return{text:p.length?`${y} · ${p.length} away`:y,tone:"ok"}}function Zz(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const r=qs(e,t);return r==="now"?"checked just now":`checked ${r}`}function Bb(e,t){const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"just now";const r=Math.round(n/60);return r<60?`${r}m ago`:`${Math.round(r/60)}h ago`}function Qz(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<rf;return{text:n?"online · one-way, it calls in":`one-way · last online ${qs(e,t)}`,here:n}}function ZS(e,t,n){return t?"online":e.lastSeen!=null?`last online ${qs(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function Jz(e,t){var y,v,S,b,_;if(!e)return[];const n=[],r=new Set,s=(k,j)=>k.name.localeCompare(j.name,void 0,{numeric:!0}),l=e.aliases??{},c=(k,j)=>{const E=k?l[k]:void 0;return E&&E!==j?{name:E,self:j}:{name:j}};for(const k of e.pending??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);n.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"asks",state:`wants to pair · ${Bb(k.at,t)}`,tone:"wait",here:!0,hint:`${j.name} at ${k.addr}${k.via==="tailscale"?", over Tailscale,":""} is waiting for an answer.`,...k.via==="tailscale"?{via:"tailscale"}:{}})}const u=[],f=[];for(const k of e.peers??[]){const j=k.peerFp??k.fp;if(!j||r.has(j))continue;r.add(j);const E=qb(k.last,t),C=GM(k,t),R=k.addr?`${k.addr}:${k.port}`:"";if(!k.paired&&k.manual&&!k.met){f.push({fp:R,name:R||k.name||j,addr:k.addr??"",kind:"dialling",state:E?E.text.replace(/ · .*$/,""):"trying…",tone:E?E.tone:"idle",here:!1,hint:(y=k.last)!=null&&y.error?`Nothing has answered at ${R} yet — ${k.last.error}.`:`Dialling ${R} until something answers.`,...k.via==="tailscale"?{via:"tailscale"}:{}});continue}const I=k.waiting?Qz(k.lastSeen,t):null,O=I?I.here:C,H=!I&&E?O?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${ZS(k,O,t)}`:I?I.text:ZS(k,O,t),q=(v=k.last)!=null&&v.error?Fb[k.last.error]:null,$=!I&&O&&!((S=k.last)!=null&&S.error)&&!(((b=k.last)==null?void 0:b.done)??[]).length,V=k.manual&&!k.met?{name:R}:c(j,k.name||j);u.push({fp:j,name:V.name,...V.self?{self:V.self}:{},addr:k.addr??"",kind:"paired",state:H,quiet:$,tone:q?q.tone==="bad"?"bad":"wait":E?E.tone:O?"ok":"idle",here:I?I.here:C,...k.via==="tailscale"?{via:"tailscale"}:{},hint:I?`${V.name} calls this deck, and this deck has no address to call back on — so it can repair its logins from here, and this deck cannot repair from it. ${k.lastSeen==null?"It has not called since this deck started.":`It last called ${qs(k.lastSeen,t)}.`} Add its address with the + at the top of this section to reach it either way.`:`${V.name}${R?` at ${R}`:""}${(_=k.last)!=null&&_.error?` — ${k.last.error}`:""}${E!=null&&E.hint?` — ${E.hint}`:""}`})}n.push(...eU(u).sort(s),...f.sort(s));const p=[];for(const k of e.strangers??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);p.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"nearby",state:e.pairingMode==="invite"?"needs an invite":"not paired yet",tone:"idle",here:!0,hint:k.via==="tailscale"?`${j.name} at ${k.addr} is on your tailnet and nothing is shared with it.`:`${j.name} at ${k.addr} is on this network and nothing is shared with it.`,...k.via==="tailscale"?{via:"tailscale"}:{}})}n.push(...p.sort(s));const h=[];for(const k of e.declined??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);h.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${j.name} asked and was turned away. It is not asking any more.`})}n.push(...h.sort(s));const m=new Map;for(const k of n)m.set(k.name,(m.get(k.name)??0)+1);for(const k of n)(m.get(k.name)??0)<2||!k.addr||(k.state=k.quiet||!k.state?k.addr:`${k.addr} · ${k.state}`,k.quiet=!1);return n}function eU(e){const t=new Map;for(const r of e){const s=t.get(r.name);s?s.push(r):t.set(r.name,[r])}const n=[];for(const r of t.values()){const s=[...new Set(r.filter(l=>l.addr).map(l=>l.addr))];if(s.length>1){for(const l of s)n.push(QS(r.filter(c=>c.addr===l)));n.push(...r.filter(l=>!l.addr))}else n.push(QS(r))}return n}function QS(e){const[t,...n]=[...e].sort((r,s)=>Number(s.here)-Number(r.here)||+!!s.addr-+!!r.addr);return n.length?{...t,twins:n}:t}function JS(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function ej(e,t){if(!e)return{};switch(t.kind){case"paired":return{peer:(e.peers??[]).find(n=>(n.peerFp??n.fp)===t.fp)??null};case"dialling":return{peer:(e.peers??[]).find(n=>n.manual&&!n.met&&`${n.addr}:${n.port}`===t.fp)??null};case"nearby":return{stranger:(e.strangers??[]).find(n=>n.fp===t.fp)??null};case"declined":return{stranger:(e.declined??[]).find(n=>n.fp===t.fp)??null};case"asks":return{stranger:(e.pending??[]).find(n=>n.fp===t.fp)??null}}}function tU(e,t){const n=/^(\d+)\.(\d+)\.(\d+)/.exec(e??""),r=/^(\d+)\.(\d+)\.(\d+)/.exec(t??"");if(!n||!r)return null;for(let s=1;s<=3;s++){const l=Number(n[s])-Number(r[s]);if(l)return Math.sign(l)}return 0}function nU(e,t,n){const r=t?t.alive?t.shareable===!1?"cannot share here":"works here":"expired here":"not on this deck";if(e.alive&&e.shareable===!1)return{there:"cannot share there",here:r,note:null,tone:"idle"};if(!e.alive){const s=t&&!t.alive?"neither copy works — sign in again here":null;return{there:"broken there",here:r,note:s,tone:s?"bad":"idle"}}return t?t.alive?{there:"works there",here:r,note:null,tone:t.shareable===!1?"idle":"ok"}:n?{there:"works there",here:r,note:"repairs next round",tone:"wait"}:{there:"works there",here:r,note:"share it to repair",tone:"bad"}:{there:"works there",here:r,note:"arrives next round",tone:"wait"}}function rU(e,t,n,r=null){var f;const s=new Map;for(const p of t)(f=s.get(p.key))!=null&&f.alive||s.set(p.key,p);const l=new Set(n),c=[],u=new Set;for(const p of e??[]){if(u.has(p.key))continue;u.add(p.key);const h=s.get(p.key)??null,m=l.has(p.key),y=nU(p,h,m),v=h?h.alive?h.shareable===!1?"unavailable":"works":"expired":"missing",S=!p.alive&&h&&!h.alive?y.note:[v==="works"?null:y.here,p.alive&&p.shareable!==!1?null:y.there,y.note].filter(Boolean).join(" · ")||null;c.push({key:p.key,email:p.email,here:v,there:p.alive?p.shareable===!1?"unavailable":"works":"broken",in:!p.alive||p.shareable===!1?"cut":y.tone==="wait"?"wait":y.tone==="bad"?"blocked":"live",out:m&&h?h.alive&&h.shareable!==!1?"live":"cut":null,caption:S,tone:y.tone,usedThere:r===p.key})}for(const p of n){const h=s.get(p);!h||u.has(p)||(u.add(p),c.push({key:p,email:h.email,here:h.alive?h.shareable===!1?"unavailable":"works":"expired",there:"unknown",in:null,out:h.alive&&h.shareable!==!1?"live":"cut",caption:h.alive?h.shareable===!1?"cannot share here":null:"expired here",tone:h.alive?h.shareable===!1?"idle":"ok":"bad",usedThere:!1}))}return c}async function Nl(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function sU({anchorId:e,id:t,rows:n,onHold:r,onLet:s}){const l=w.useRef(null),c=n.filter(y=>y.kind==="paired"),u=c.filter(y=>y.here),f=u.slice(0,Gz),p=c.length-u.length,h=u.length>f.length?`and ${u.length-f.length} more`:p>0?`${p} not on right now`:null,m=w.useCallback(()=>{const y=l.current,v=document.getElementById(e);if(!y||!v)return;const S=$b(v.getBoundingClientRect(),{width:y.offsetWidth,height:y.offsetHeight},{width:window.innerWidth,height:window.innerHeight});y.style.top=`${S.top}px`,y.style.left=`${S.left}px`,y.style.maxHeight=S.maxHeight==null?"":`${S.maxHeight}px`,y.dataset.side=S.side},[e]);return w.useLayoutEffect(()=>{m()}),w.useEffect(()=>(window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}),[m]),Mn.createPortal(o.jsxs("div",{ref:l,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[o.jsx("p",{className:"ap-peek-title",children:u.length?"On the network now":"Nobody on the network"}),f.length>0&&o.jsx("div",{className:"ap-peek-list",children:f.map(y=>o.jsxs("span",{className:"ap-peek-who",children:[o.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),o.jsxs("span",{children:[y.name,y.via==="tailscale"&&o.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]})]},`${y.kind}:${y.fp}`))}),h&&o.jsx("p",{className:"ap-peek-rest",children:h})]}),document.body)}function aU(e,t){var l;if(!e)return{text:"checking…",tone:"idle",live:!1};if(!e.enabled)return{text:"Off",tone:"idle",live:!1};if(e.stalled)return{text:"could not start",tone:"bad",live:!1};if(!e.running)return{text:"starting…",tone:"wait",live:!1};const n=t.filter(c=>c.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};if((l=e.reach)!=null&&l.blocked)return{text:"nothing can get in",tone:"bad",live:!1};const r=t.filter(c=>c.kind==="paired");if(!r.length)return{text:"On · none paired yet",tone:"idle",live:!1};const s=r.filter(c=>c.here).length;return s?s===r.length?{text:`${s} online`,tone:"ok",live:!0}:{text:`${s} of ${r.length} online`,tone:"ok",live:!0}:{text:`none of ${r.length} online`,tone:"idle",live:!1}}function oU({accounts:e,onChanged:t,view:n,onOpen:r,onBack:s,closeButton:l}){const[c,u]=w.useState(null),[f,p]=w.useState([]),[h,m]=w.useState(null),[y,v]=w.useState(!1),[S,b]=w.useState(null),_=w.useRef(0),[k,j]=w.useState(!1),[E,C]=w.useState(!1),[R,I]=w.useState(!1),O=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(O.current),[]);const[H,q]=w.useState(!1),[$,V]=w.useState(null),ne=w.useRef(null),ee=w.useCallback(ce=>Tf(ne.current)?(ne.current=ce,m(ce),!0):!1,[]),M=w.useCallback(()=>{ne.current=null,P.current&&m(null)},[]),Z=ce=>{const pe=ao(h,ce);return{disabled:pe.disabled,"aria-busy":pe.busy}},[K,D]=w.useState(()=>Date.now()),P=w.useRef(!0),B=w.useRef(q0),W=w.useCallback(async()=>{var ce,pe;try{const[Ae,fe]=await Promise.all([fetch("/api/lan").then(Se=>Se.json()),fetch("/api/prefs").then(Se=>Se.json())]);if(!P.current)return;Ae!=null&&Ae.ok&&u(Ae),fe!=null&&fe.ok&&p(Array.isArray((pe=(ce=fe.prefs)==null?void 0:ce.lan)==null?void 0:pe.manual)?fe.prefs.lan.manual:[]),B.current=(Ae==null?void 0:Ae.enabled)===!0?q0:VM}catch{}},[]);w.useEffect(()=>{P.current=!0;let ce=0;const pe=async()=>{D(Date.now()),await W(),P.current&&(ce=window.setTimeout(pe,B.current))};return pe(),()=>{P.current=!1,window.clearTimeout(ce)}},[W]);const F=w.useCallback(async()=>{const ce=(c==null?void 0:c.enabled)===!0;if(ee("switch"))try{const pe=await Nl("/api/prefs",{lan:{enabled:!ce}});if(!P.current)return;pe!=null&&pe.ok?(V(null),ce||v(!0)):V(un(ce?"turn this off":"turn this on",pe)),await W()}catch{P.current&&V(un(ce?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,W,ee,M]),G=w.useCallback(async(ce,pe,Ae)=>{if(!ee(`${ce}:${pe}`))return null;let fe=null;try{const Se=await Nl("/api/lan/peer",{action:ce,fp:pe});if(!P.current)return null;Se!=null&&Se.ok?(u(Se),V(null)):(fe=un(Ae,Se),V(fe)),await W()}catch{fe=un(Ae,null),P.current&&V(fe)}finally{M()}return fe},[W,ee,M]),re=w.useCallback(async ce=>{if(!ee(`drop:${ce}`))return null;let pe=null;try{const Ae=await Nl("/api/prefs",{lan:{manual:f.filter(fe=>fe!==ce)}});if(!P.current)return null;Ae!=null&&Ae.ok?(V(null),t()):(pe=un("stop dialling that address",Ae),V(pe)),await W()}catch{pe=un("stop dialling that address",null),P.current&&V(pe)}finally{M()}return pe},[f,W,t,ee,M]),[U,Y]=w.useState(null),z=w.useCallback(async(ce,pe)=>{if(!ee(`alias:${ce}`))return"Something else is still being saved. Try again in a moment.";try{const Ae=await Nl("/api/lan/peer",{action:"alias",fp:ce,name:pe});return P.current?Ae!=null&&Ae.ok?(u(Ae),null):un("rename that deck",Ae):null}catch{return un("rename that deck",null)}finally{M()}},[ee,M]),ie=w.useCallback(async ce=>{if(!ee(`check:${ce}`))return null;try{const pe=await Nl("/api/lan/sync",{fp:ce});return P.current?pe!=null&&pe.ok?(u(pe),t(),null):(pe==null?void 0:pe.reason)==="no_address"?"There is no address here to call it on. It calls this deck, and it is up to date each time it does.":un("check that deck",pe):null}catch{return un("check that deck",null)}finally{M()}},[ee,M,t]),le=w.useCallback(async()=>{if(ee("check"))try{const ce=await Nl("/api/lan/sync",{});if(!P.current)return;ce!=null&&ce.ok?(u(ce),V(null)):V(un("check the other decks",ce)),t()}catch{P.current&&V(un("check the other decks",null))}finally{M()}},[ee,M,t]),ge=(c==null?void 0:c.enabled)===!0,Ne=Jz((c==null?void 0:c.pairingMode)==="invite"&&c?{...c,pending:[]}:c,K),Ie=U?Ne.find(ce=>{var pe;return ce.fp===U||((pe=ce.twins)==null?void 0:pe.some(Ae=>Ae.fp===U))})??null:null;w.useEffect(()=>{U&&c&&!Ie&&Y(null)},[U,c,Ie]);const Ge=Ne.filter(ce=>ce.kind==="asks"),Pe=Ne.filter(ce=>ce.kind!=="asks"),Be=Pe.filter(ce=>ce.here),Te=Pe.filter(ce=>!ce.here),st=Te.filter(ce=>ce.tone==="bad").length,de=H||Be.length===0,ue=Xz(c,K),se=Pe.filter(ce=>ce.kind==="paired").length,be=aU(c,Ne),Le=o.jsxs(o.Fragment,{children:[k&&c&&o.jsx(Ez,{status:c,manual:f,startWith:k==="invite"?"invite":void 0,onClose:()=>j(!1),onChanged:()=>{W(),t()}}),E&&o.jsx(UM,{title:"How Local network works",steps:bz,finish:ge?void 0:{label:"Turn it on",act:()=>{C(!1),F()}},onClose:()=>C(!1)}),y&&c&&o.jsx(Pz,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>v(!1),onChanged:()=>{W(),t()}}),Ie&&c&&o.jsx(Oz,{row:Ie,source:ej(c,Ie),status:c,accounts:e,now:K,busy:h,onClose:()=>Y(null),onRename:ce=>z(Ie.fp,ce),onCheck:()=>ie(Ie.fp),onVerb:()=>{switch(Ie.kind){case"paired":return G("unpair",Ie.fp,"unpair that deck");case"nearby":return G("accept",Ie.fp,"reach that deck");case"declined":return G("allow",Ie.fp,"let that deck ask again");case"dialling":return re(Ie.fp);default:return Promise.resolve(null)}},onSettings:()=>{Y(null),v(!0)},onInvite:()=>{Y(null),j("invite")},twins:(Ie.twins??[]).map(ce=>({row:ce,peer:ej(c,ce).peer??null})),onUnpair:ce=>G("unpair",ce,"unpair that deck")})]});if(!n){const ce=Se=>{window.clearTimeout(O.current),O.current=window.setTimeout(()=>I(!0),Se)},pe=()=>{window.clearTimeout(O.current),O.current=window.setTimeout(()=>I(!1),YM)},Ae=()=>window.clearTimeout(O.current),fe=()=>{window.clearTimeout(O.current),I(!1)};return o.jsxs("div",{className:"ap-foot",children:[o.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{fe(),r()},"aria-describedby":R?"ap-lan-peek":void 0,onPointerEnter:Se=>{Se.pointerType==="mouse"&&ce(KM)},onPointerLeave:pe,onFocus:Se=>{Se.target.matches(":focus-visible")&&ce(0)},onBlur:pe,children:[o.jsxs("svg",{className:"ap-nav-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),o.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),o.jsxs("span",{className:"ap-nav-text",children:[o.jsx("span",{className:"ap-nav-name",children:"Local network"}),o.jsxs("span",{className:"ap-nav-state","data-tone":be.tone,children:[be.live&&o.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),be.text]})]}),o.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),R&&o.jsx(sU,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:Ne,onHold:Ae,onLet:pe}),o.jsx("p",{className:"vis-hidden",role:"status",children:ue.tone==="ok"?"":ue.text}),Le]})}return o.jsxs("div",{className:"ap-lan-view",children:[o.jsxs("div",{className:"ap-header",children:[o.jsx("button",{type:"button",id:"ap-lan-back",className:"glyph-btn ap-back",onClick:s,"aria-label":"Back to Claude accounts",title:"Back to Claude accounts",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),o.jsx("h2",{id:"ap-lan-title",children:"Local network"}),o.jsxs("div",{className:"ap-header-right",children:[ge&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>j("add"),"aria-label":"Add a deck",title:(c==null?void 0:c.pairingMode)==="invite"?"Send an invite, or use one you were sent. This deck pairs only by invite.":"Reach a deck that has not turned up on its own — by address, or with an invite",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M6.1 7.9a2.6 2.6 0 0 0 3.7 0l1.9-1.9a2.6 2.6 0 0 0-3.7-3.7l-.9.9"}),o.jsx("path",{d:"M7.9 6.1a2.6 2.6 0 0 0-3.7 0L2.3 8a2.6 2.6 0 0 0 3.7 3.7l.9-.9"})]})}),ge&&se>0&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...Z("check"),onClick:()=>void le(),"aria-label":h==="check"?"Checking every paired deck":"Check every paired deck now",title:"Ask every paired deck now for anything this deck's expired logins need, instead of waiting for the next round",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),o.jsx("path",{d:"M4.6 4.6a3.4 3.4 0 0 0 0 4.8M9.4 4.6a3.4 3.4 0 0 1 0 4.8"}),o.jsx("path",{d:"M2.6 2.6a6.2 6.2 0 0 0 0 8.8M11.4 2.6a6.2 6.2 0 0 1 0 8.8"})]})}),ge&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...Z("setup"),onClick:()=>v(!0),"aria-label":"This deck's name and shared logins",title:"This deck's name on the network, and which of its logins it offers",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),o.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),o.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),l]})]}),o.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:o.jsxs("div",{className:"ap-lan",children:[o.jsxs("div",{className:"ap-policy",children:[o.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ge,"aria-label":"Sync with paired decks",...Z("switch"),onClick:()=>void F(),title:ge?"Stop talking to other decks. Nothing is shared while this is off.":"Let the decks you pair with repair this one's expired logins",children:o.jsx("span",{className:"switch-knob"})})]}),ge&&o.jsx(WM,{reach:c==null?void 0:c.reach,where:"panel"}),ge&&(c==null?void 0:c.deaf)&&o.jsx("p",{className:"ap-lan-fine",children:c.deaf}),ge&&(c==null?void 0:c.lanTunneled)&&o.jsx("p",{className:"ap-lan-fine",children:Yz(c)}),!ge&&o.jsxs("button",{type:"button",className:"ap-lan-intro",onClick:()=>C(!0),title:"Four pictures: what this does, and what to do on each machine",children:[o.jsx(kz,{}),o.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),o.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),o.jsx("p",{className:`ap-lan-status ${ue.tone}`,role:"status",children:ue.tone==="ok"?"":ue.text}),$&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:$}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>V(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ge&&o.jsxs(o.Fragment,{children:[Ge.length>0&&o.jsx("div",{className:"ap-lan-asks",role:"alert",children:Ge.map(ce=>o.jsxs("div",{className:"ap-lan-ask",children:[o.jsxs("span",{className:"ap-lan-ask-what",children:[o.jsx("strong",{className:"ap-lan-peer-name",children:ce.name})," at ",o.jsx("code",{className:"ap-lan-code",children:ce.addr})," wants to pair"]}),o.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",o.jsx("code",{className:"ap-lan-code",children:ce.fp})]}),o.jsxs("span",{className:"ap-lan-ask-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`accept:${ce.fp}`),onClick:()=>void G("accept",ce.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${ce.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`dismiss:${ce.fp}`),onClick:()=>void G("dismiss",ce.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},ce.fp))}),(de?[...Be,...Te]:Be).length>0&&o.jsx("ul",{className:"ap-lan-here",children:(de?[...Be,...Te]:Be).map((ce,pe)=>o.jsxs("li",{className:"ap-lan-who","data-tone":ce.tone,children:[o.jsx("i",{className:ce.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[ce.name,ce.via==="tailscale"&&o.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]}),o.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${pe}`,onClick:()=>Y(ce.fp),children:o.jsxs("span",{className:"vis-hidden",children:[ce.name,ce.via==="tailscale"?", over Tailscale":"",", details"]})}),o.jsx("span",{id:`lan-who-state-${pe}`,className:ce.quiet?"vis-hidden":"ap-lan-who-when",children:ce.state}),ce.kind==="nearby"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`accept:${ce.fp}`),onClick:()=>void G("accept",ce.fp,"reach that deck"),"aria-label":`Ask ${ce.name} to pair`,title:`Send ${ce.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${ce.fp}.`,children:"ask"}),(ce.kind==="nearby"||ce.kind==="declined")&&(c==null?void 0:c.pairingMode)==="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do","aria-haspopup":"dialog",onClick:()=>j("invite"),"aria-label":`Invite ${ce.name} to pair`,title:`This deck pairs only by invite. Make one and send it to whoever is at ${ce.name}.`,children:"invite"}),ce.kind==="paired"&&o.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${S===ce.fp?" armed":""}`,...Z(`unpair:${ce.fp}`),onClick:()=>{const Ae=Date.now(),fe=Cu({armedFor:S,target:ce.fp,armedAt:_.current,now:Ae,gapMs:Mu});if(fe==="arm"){b(ce.fp),_.current=Ae,window.setTimeout(()=>b(Se=>Se===ce.fp?null:Se),4e3);return}fe!=="ignore"&&(b(null),G("unpair",ce.fp,"unpair that deck"))},"aria-label":S===ce.fp?`Confirm unpairing ${ce.name}`:`Unpair ${ce.name}`,title:S===ce.fp?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:S===ce.fp?"confirm":"unpair"}),ce.kind==="dialling"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`drop:${ce.fp}`),onClick:()=>void re(ce.fp),"aria-label":`Stop dialling ${ce.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),ce.kind==="declined"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`allow:${ce.fp}`),onClick:()=>void G("allow",ce.fp,"let that deck ask again"),"aria-label":`Let ${ce.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${ce.kind}:${ce.fp}`))}),(Be.length>0&&Te.length>0||ge&&se>0)&&o.jsxs("div",{className:"ap-lan-tail",children:[Be.length>0&&Te.length>0&&o.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":H,onClick:()=>q(ce=>!ce),title:H?"Show only the decks that are on":`Show the ${Te.length} deck${Te.length===1?"":"s"} that are not responding right now`,children:[o.jsx("span",{className:`ap-lan-chev${H?" open":""}`,"aria-hidden":!0,children:"›"}),H?"fewer":`${Te.length} more`,!H&&st>0&&o.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",st," not responding"]})]}),ge&&se>0&&o.jsx("span",{className:"ap-lan-checked",children:Zz(c==null?void 0:c.checkedAt,K,h==="check")})]}),Pe.length===0&&Ge.length===0&&!(c!=null&&c.stalled)&&!(c!=null&&c.deaf)&&!(c!=null&&c.lanTunneled)&&o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"ap-lan-fine",children:"No other deck yet. Decks on one network usually find each other on their own; when that has not happened, the link at the top of this view reaches one by address or by invite."}),o.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>C(!0),children:"How it works"})]})]})]})}),Le]})}function iU({anchorId:e,id:t,peers:n,onHold:r,onLet:s}){const l=w.useRef(null),{title:c,shown:u,rest:f}=iz(n),p=w.useCallback(()=>{const h=l.current,m=document.getElementById(e);if(!h||!m)return;const y=$b(m.getBoundingClientRect(),{width:h.offsetWidth,height:h.offsetHeight},{width:window.innerWidth,height:window.innerHeight});h.style.top=`${y.top}px`,h.style.left=`${y.left}px`,h.style.maxHeight=y.maxHeight==null?"":`${y.maxHeight}px`,h.dataset.side=y.side},[e]);return w.useLayoutEffect(()=>{p()}),w.useEffect(()=>(window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}),[p]),Mn.createPortal(o.jsxs("div",{ref:l,id:t,className:"ap-peek ap-fold-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[o.jsx("p",{className:"ap-peek-title",children:c}),o.jsx("div",{className:"ap-peek-list",children:u.map(h=>o.jsxs("span",{className:"ap-peek-who ap-fold-who",children:[o.jsx("span",{className:"ap-fold-name",children:h.name}),o.jsx("span",{className:"ap-fold-state","data-tone":h.ready?"ok":h.warn?"warn":"idle",children:h.ready?h.headroom==null?"not read yet":`${h.headroom}% free`:h.why})]},h.key))}),f&&o.jsx("p",{className:"ap-peek-rest",children:f})]}),document.body)}function lU({peers:e,strained:t,armed:n,threshold:r,open:s,onToggle:l}){const[c,u]=w.useState(!1),f=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(f.current),[]),w.useEffect(()=>{s&&(window.clearTimeout(f.current),u(!1))},[s]);const p=S=>{s||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!0),S))},h=()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!1),YM)},m=()=>window.clearTimeout(f.current),y=()=>{window.clearTimeout(f.current),u(!1)},v=az(e,{strained:t&&!s,armed:n,threshold:r});return o.jsxs("div",{className:"ap-rest",children:[o.jsxs("button",{type:"button",id:"ap-rest-entry",className:"ap-nav","aria-expanded":s,"aria-controls":s?"ap-rest-panel":void 0,"aria-describedby":c?"ap-rest-peek":void 0,onClick:()=>{y(),l()},onPointerEnter:S=>{S.pointerType==="mouse"&&p(KM)},onPointerLeave:h,onFocus:S=>{S.target.matches(":focus-visible")&&p(0)},onBlur:h,children:[o.jsxs("span",{className:"ap-nav-text",children:[o.jsx("span",{className:"ap-nav-name",children:"Other accounts"}),o.jsx("span",{className:"ap-nav-state","data-tone":v.tone,children:v.text})]}),o.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),c&&o.jsx(iU,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:m,onLet:h})]})}async function cU(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const uU=1800;function dU({accounts:e,onClose:t,copyText:n}){const[r,s]=w.useState([]),[l,c]=w.useState(null),[u,f]=w.useState(!1),[p,h]=w.useState(null),[m,y]=w.useState(!1),[v,S]=w.useState(()=>Math.floor(Date.now()/1e3)),b=w.useRef(null),_=w.useRef(!1),k=pn(t,{focusRef:b});w.useEffect(()=>{if(!l)return;S(Math.floor(Date.now()/1e3));const $=window.setInterval(()=>S(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval($)},[l]);const j=KB(e),E=YB(e,r),C=E.length===e.length,R=$=>s(V=>XB(V,$)),I=w.useCallback(async()=>{const $=ZB(E);if(!Ps(_.current)||!$)return;_.current=!0,f(!0),h(null),y(!1);const V=await cU($).catch(()=>null);if(_.current=!1,f(!1),!(V!=null&&V.ok)){h(Al(V,"the share could not be made"));return}c({blob:V.blob,expiresAt:V.expiresAt,shared:V.shared??[],failed:V.failed??[]})},[e,E]),O=l?zM(l.expiresAt,v):null,H=(O==null?void 0:O.tone)==="gone",q=(l==null?void 0:l.shared.length)??0;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:o.jsxs("div",{ref:k,className:"modal sa-modal",onClick:$=>$.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Share accounts with another deck",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("h3",{children:"Share accounts"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsx("section",{className:"modal-body sa-body",children:l?o.jsxs("div",{className:"sa-step",children:[o.jsx("h4",{children:H?"This share has expired":q===1?"1 account, ready to paste":`${q} accounts, ready to paste`}),o.jsx("code",{className:`ap-share-blob${H?" sa-dead":""}`,children:l.blob}),o.jsxs("div",{className:"ap-share-foot",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",ref:b,onClick:async()=>{if(H){c(null),I();return}await n(l.blob)&&(y(!0),window.setTimeout(()=>y(!1),uU))},children:H?"make a new share":m?"copied":`copy ${q===1?"the share":"all "+q}`}),o.jsxs("span",{className:"ap-manage-hint",title:"This text is the sign-in for every account in it. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the logins themselves are in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign those accounts out and back in.",children:[o.jsx("span",{className:"ap-share-warn",children:q===1?"this is the password":`this is ${q} passwords`})," · ",o.jsx("span",{className:`ap-share-expiry ${O==null?void 0:O.tone}`,children:O==null?void 0:O.text})]})]}),l.failed.length>0&&o.jsxs("div",{className:"sa-failed",role:"alert",children:[o.jsx("p",{className:"sa-failed-head",children:l.failed.length===1?"One account is not in this bundle:":`${l.failed.length} accounts are not in this bundle:`}),o.jsx("ul",{className:"sa-list",children:l.failed.map($=>{var ne;const V=!!($.email&&((ne=$.detail)!=null&&ne.includes($.email)));return o.jsxs("li",{children:[!V&&o.jsx("span",{className:"sa-who",children:$.email||`account ${$.num}`}),o.jsx("span",{className:"sa-why",children:$.detail||"could not be exported"})]},`${$.num}-${$.email}`)})})]}),o.jsx("p",{className:"sa-note",children:H?o.jsx(o.Fragment,{children:"Another deck will refuse this text now. Make a new one — the same accounts are still picked."}):o.jsxs(o.Fragment,{children:["Paste it into the other deck with ",o.jsx("strong",{children:"+"})," → ",o.jsx("strong",{children:"Paste a share"}),". Accounts it already holds are left exactly as they are."]})}),o.jsxs("div",{className:"sa-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>{c(null),y(!1)},children:"Pick again"}),o.jsx("button",{type:"button",className:"btn primary",onClick:t,children:"Done"})]})]}):e.length===0?o.jsxs("div",{className:"sa-step",children:[o.jsx("h4",{children:"Nothing to share"}),o.jsxs("p",{className:"sa-note",children:["This deck is not holding any accounts right now. Sign one in with ",o.jsx("strong",{children:"+"}),", or wait — the panel is still reading the store."]}),o.jsx("div",{className:"sa-actions",children:o.jsx("button",{type:"button",className:"btn primary",ref:b,onClick:t,children:"Close"})})]}):o.jsxs("div",{className:"sa-step",children:[o.jsxs("h4",{children:["Which accounts go to the other ",dn,"?"]}),o.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:QB(E.length)}),o.jsx("ul",{className:"sa-list sa-pick",children:j.map($=>o.jsx("li",{children:o.jsxs("label",{className:"sa-row",children:[o.jsx("input",{type:"checkbox",checked:E.includes($.num),onChange:()=>R($.num)}),o.jsx("span",{className:"sa-who",children:$.label}),$.sub&&o.jsx("span",{className:"sa-sub",children:$.sub})]})},$.num))}),p&&o.jsx("p",{className:"aa-err",children:p}),o.jsxs("div",{className:"sa-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>s(C?e.map($=>$.num):[]),children:C?"Clear all":"Select all"}),o.jsx("button",{type:"button",className:"btn primary",ref:b,...Qa(u,!E.length),onClick:I,children:u?"making the share…":E.length===0?"Share":E.length===1?"Share 1 account":`Share ${E.length} accounts`})]})]})})]})}),document.body)}function hU(e,t){const n=new Set(e),r=e.length?Math.max(...e):0;return[...new Set([...e,r+1])].sort((s,l)=>s-l).map(s=>{const l=s===t?"here":n.has(s)?"swap":"free";return{slot:s,kind:l,label:l==="here"?`slot ${s}`:`slot ${s} · ${l}`}})}function fU(e,t,n){if(!(n!=null&&n.ok))return null;const r=Number.isInteger(n.to)?n.to:null;if(r==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const s=n.swapped===!0&&r!==t;return{menuFor:e.menuFor===t?r:s&&e.menuFor===r?t:e.menuFor,confirmRemove:null,shareFor:null,swapNote:s?{at:r,displaced:t}:null}}function pU(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function mU(e,t,n){var s;const r=((s=e.find(l=>l.slot===t))==null?void 0:s.kind)??"here";return r==="swap"?{label:"swap",done:"swapped",sends:!0,swaps:!0,title:`Send this account to slot ${t}. That slot is taken, so the two accounts trade places and the one standing there moves to slot ${n}.`}:r==="free"?{label:"move",done:"moved",sends:!0,swaps:!1,title:`Send this account to slot ${t}. That slot is empty, so no other account moves.`}:{label:"move",done:"here",sends:!1,swaps:!1,title:`This account already holds slot ${n}.`}}function gU(e,t){return{label:"save",done:"saved",sends:e!==t,swaps:!1,title:`Switch the active account out once it passes ${e}% of its limit.`}}function tj(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function yU(e){const t=e.filter(u=>!tj(u)),n=e.filter(u=>tj(u)),r=t.length?t:n,s=t.length?n:[],l=r.reduce((u,f)=>u&&u.pct>=f.pct?u:f,null);let c=null;for(const u of s)l&&u.pct<=l.pct||(!c||u.pct>c.pct)&&(c=u);return{shown:r,rest:s,fuller:c,peak:c??l}}const wU="\0";function sf(e){const t=typeof e.email=="string"?e.email.trim():"";if(!t)return`slot:${e.num}`;const n=typeof e.org=="string"?e.org.trim():"";return`acct:${t}${wU}${n}`}function vU(e,t){const n=sf(t);return e.includes(n)?e.filter(r=>r!==n):[...e,n]}function xU(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(sf)),r=e.filter(s=>n.has(s));return r.length===e.length?e:r}const bU=64;function kU(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}function NU(e,t){return!e||!t||t.some(n=>n.num===e.num&&n.active)?e:null}const SU=Object.freeze({text:"couldn't reach the deck server",reload:!0}),jU=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function nj(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function _U(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=Au(t.body);return{text:O0(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function rj(e,t){return t?e!=null&&e.reload&&e.text===t.text&&e.raw===t.raw?e:t:e!=null&&e.reload?null:e}const sj=15e3,EU=8e3,CU=1800,TU=3e4,Tm=[70,80,85,90,95];function Rm(e,t){return kM(t-Math.floor(e/1e3))}function RU(e,t){if(!e)return"";const n=Math.floor(e/1e3)-t;return n<=0?" · due":n<60?` · next in ${n}s`:` · next in ${Math.round(n/60)}m`}function lu(e){return e.charAt(0).toUpperCase()+e.slice(1)}function AU(e,t){const n="The deck can still see this account — its live usage is being read — but claude-swap's own stored copy of the login was rejected, so these numbers stopped updating.";if((e==null?void 0:e.state)==="running")return{text:"resuming…",hint:`${n} The deck is re-capturing it from the login you already have. No sign-in, no switch.`};if((e==null?void 0:e.state)==="failed"){const r=Math.max(1,Math.ceil((e.retryAt/1e3-t)/60)),s=e.reason?`Re-capturing it from the login you already have did not work (${e.reason}).`:"The deck re-captured it from the login you already have, and claude-swap still cannot read it.";return{text:"numbers paused",hint:`${n} ${s} It tries again in ${r}m. No sign-in, no switch.`}}return{text:"numbers paused",hint:n}}function MU(e){switch(e){case"invalid_grant":case"no_refresh_token":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fixable:!0};case"http-401":return{text:"re-login needed",hint:"Anthropic refused this account's token.",fixable:!0};case"http-429":return{text:"rate limited",hint:"Anthropic is throttling requests for this account. It clears on its own.",fixable:!1};case"transient":return{text:"temporary error",hint:"A network or server hiccup while reading usage. The next collection retries.",fixable:!1};case"timeout":return{text:"timed out",hint:"Reading this account's usage took too long. The next collection retries.",fixable:!1};case"network":return{text:"unreachable",hint:"Could not reach Anthropic to read this account's usage.",fixable:!1};default:return{text:e,hint:`claude-swap reported "${e}" for this account.`,fixable:!1}}}function IU(e){switch(e){case"no_credentials":return{text:"no stored login",hint:"claude-swap holds no credentials for this account, so there is nothing to read its usage with and nothing to switch to. A paired deck that has them sends them on its own; signing in as this account puts them there by hand.",fix:"sign in"};case"relogin_required":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fix:"sign in again"};case"keychain_unavailable":return{text:"keychain unreadable",hint:"This is about the deck, not the account: claude-swap could not open your keychain, so it cannot read any account's stored login. A deck started from a background session cannot reach the keychain at all — start it from a terminal, or let it start at login, and this clears."};case"token_expired":return{text:"token expired",hint:"The access token ran out and the refresh was deferred. The next collection retries."};case"foreign_credential":return{text:"wrong credential",hint:"The live credential belongs to a different account. Switching to this one repairs it."};case null:case void 0:return null;default:return{text:e,hint:`claude-swap reported "${e}" for this account.`}}}function Nh(e,t){if(e.staleCopy){const n=AU(e.repair??null,t);return{text:lu(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=IU(e.collector??null);if(!n)return{text:"Not collecting",hint:"claude-swap has collected nothing for this account in over half a day and has not said why. A paired deck holding a working copy of this account will replace it on its own. To do it by hand, sign in as this account from + Add.",fix:null,tone:"quiet",blocksSwitch:!1};const r=e.collector==="no_credentials"||e.collector==="relogin_required";return{text:lu(n.text),hint:n.hint,fix:n.fix?lu(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=MU(e.error);return{text:lu(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function Am(){return o.jsxs("svg",{className:"ap-warn-glyph",width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),o.jsx("path",{d:"M7 5.6v2.9"}),o.jsx("path",{d:"M7 10.3v.05"})]})}function $U(e){return e>=90?"hi":e>=70?"mid":void 0}function OU(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!Tm.includes(t)?[...Tm,t]:Tm].sort((r,s)=>r-s)}function LU({lane:e,nowSec:t,frozen:n}){const r=Math.min(100,Math.max(0,e.pct)),s=n?"var(--muted)":r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",l=e.resetAt&&!n?NM(e.resetAt,t):null;return o.jsxs("div",{className:"ap-lane",children:[o.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),o.jsx("div",{className:"ap-lane-track",children:o.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:s,opacity:r===0||n?.4:1}})}),o.jsxs("span",{className:"ap-lane-pct",style:{color:s},children:[r,"%"]}),o.jsx("span",{className:"ap-lane-reset",title:l?`${e.label} resets in ${l}`:void 0,children:l&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"vis-hidden",children:"resets in "}),l]})})]})}function PU({onClose:e,leaving:t}){var xr,$n,Hs;const[n,r]=w.useState(null),[s,l]=w.useState(null),[c,u]=w.useState(null),[f,p]=w.useState(!1),[h,m]=w.useState(null),[y,v]=w.useState(null),[S,b]=w.useState("accounts"),[_,k]=w.useState(!1),[j,E]=w.useState(null),C=w.useRef(j);C.current=j;const[R,I]=w.useState(()=>Math.floor(Date.now()/1e3)),O=w.useRef(null),[H,q]=w.useState(null),$=(H==null?void 0:H.num)??null,V=w.useRef(H);V.current=H;const[ne,ee]=w.useState(null),[M,Z]=w.useState(!1),[K,D]=w.useState(""),[P,B]=w.useState(null),W=w.useRef(0),[F,G]=w.useState(null),[re,U]=w.useState(!1),[Y,z]=w.useState(!1),[ie,le]=w.useState(null),[ge,Ne]=w.useState(null),[Ie,Ge]=w.useState(null),[Pe,Be]=w.useState(null),[Te,st]=w.useState(!1),de=w.useRef(null),ue=w.useRef(null),[se,be]=w.useState([]),[Le,ce]=w.useState(!1),pe=w.useRef(null),Ae=w.useCallback(Q=>Tf(pe.current)?(pe.current=Q,u(Q),!0):!1,[]),fe=w.useCallback(()=>{pe.current=null,u(null)},[]),Se=(Q,De=!1)=>{const et=ao(c,Q);return{disabled:et.disabled,"aria-busy":et.busy||De}},Ye=w.useCallback(Q=>{window.requestAnimationFrame(()=>{var De;if(A0(((De=document.activeElement)==null?void 0:De.tagName)??null))for(const et of u8(Q)){const Ue=document.querySelector(et);if(Ue){Ue.focus();return}}})},[]),qe=w.useCallback(async(Q=!1)=>{Q&&p(!0);const De=new AbortController,et=window.setTimeout(()=>De.abort(),TU);try{const[Ue,tt]=await Promise.all([fetch(`/api/claude-accounts${Q?"?refresh=1":""}`,{signal:De.signal}),fetch("/api/cswap-auto",{signal:De.signal})]);if(Ue.ok){const gt=await Ue.json();r(gt),be(It=>xU(It,gt.accounts))}tt.ok&&l(await tt.json());const wt=_U([await nj(Ue),await nj(tt)]);m(gt=>rj(gt,wt))}catch{m(Ue=>rj(Ue,De.signal.aborted?jU:SU))}finally{window.clearTimeout(et),Q&&p(!1)}},[]),ke=w.useCallback(async(Q,De,et="panel")=>{if(!Ae(De))return null;const Ue=et==="menu"?ee:m;Ue(null);try{const tt=await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),wt=await tt.json().catch(()=>null);return wt!=null&&wt.ok||Ue({text:O0(wt,"command failed",tt.status),raw:Au(wt)}),wt}catch{return Ue({text:"server unreachable"}),null}finally{fe()}},[Ae,fe]),Re=w.useCallback(async(Q,De)=>{if(!Ae(De))return null;m(null),ee(null);try{const et=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),Ue=await et.json().catch(()=>null);return Ue!=null&&Ue.ok||ee({text:Al(Ue,"command failed",et.status)}),Ue}catch{return ee({text:"server unreachable"}),null}finally{fe()}},[Ae,fe]);w.useEffect(()=>(qe(!0),O.current=window.setInterval(()=>qe(!1),sj),()=>{O.current!=null&&window.clearInterval(O.current)}),[qe]),w.useEffect(()=>{!(n!=null&&n.ok)||!n.accounts||v(Q=>NU(Q,n.accounts))},[n]),w.useEffect(()=>{const Q=window.setInterval(()=>I(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(Q)},[]);const ze=((xr=s==null?void 0:s.settings["autoswitch.threshold"])==null?void 0:xr.value)??"90",Fe=Pe??ze,We=gU(Fe,ze),rt=($n=n==null?void 0:n.accounts)==null?void 0:$n.find(Q=>Q.active),dt=rt?Nh(rt,R):null,ct=(n==null?void 0:n.accounts)??[],yt=rt?ct.filter(Q=>!Q.active):[],Ot=yt.length?ct.filter(Q=>Q.active):ct,zt=yt.map(Q=>{const De=Nh(Q,R);return{key:sf(Q),name:Q.alias??Q.email??`account ${Q.num}`,ready:!Q.disabled&&!(De!=null&&De.blocksSwitch),why:Q.disabled?"held out":De!=null&&De.blocksSwitch?De.text:null,warn:(De==null?void 0:De.tone)==="warn",headroom:Q.headroom}}),Xt=Number(ze),Dt=(rt==null?void 0:rt.headroom)!=null&&Number.isFinite(Xt)&&100-rt.headroom>=Xt,rn=(s==null?void 0:s.ok)===!0&&(s.enabled||s.external),je=Q=>Le&&yt.some(De=>De.num===Q)?"ap-rest-list":"ap-scroll",xt=async(Q,De)=>{if(Ae(`switch-${Q}`)){m(null),v(null);try{const Ue=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:Q})})).json().catch(()=>null);Ue!=null&&Ue.ok?v({num:Q,name:De}):m({text:O0(Ue,"the switch failed"),raw:Au(Ue),row:Q}),await qe(!0)}catch{m({text:"server unreachable",row:Q})}finally{fe(),Ye(Q)}}},bt=w.useCallback(()=>{q(null),ee(null),B(null),G(null),z(!1)},[]),_n=(Q,De="first")=>{bt(),E(null),Ge(null),q({num:Q,view:"menu",start:De})},Ut=(Q,De)=>{bt(),E(et=>(et==null?void 0:et.anchor)===De?null:{num:Q,anchor:De})},Vn=w.useCallback((Q=!1)=>{var et;const De=C.current;Q&&De&&((et=document.getElementById(De.anchor))==null||et.focus()),E(null)},[]),Vt=()=>{bt(),E(null),b("lan")},Lt=w.useRef(S);w.useEffect(()=>{Lt.current!==S&&(Lt.current=S,window.requestAnimationFrame(()=>{var Q;(Q=document.getElementById(S==="lan"?"ap-lan-back":"ap-lan-entry"))==null||Q.focus()}))},[S]),w.useEffect(()=>{n!=null&&n.ok&&k(!0)},[n==null?void 0:n.ok]);const Zt=w.useCallback(Q=>{var Ue,tt;const De=V.current;if(!De||Q!=null&&De.num!==Q)return;const et=document.getElementById(`ap-menu-${De.num}`);(et!=null&&et.contains(document.activeElement)||A0(((Ue=document.activeElement)==null?void 0:Ue.tagName)??null))&&((tt=document.getElementById(`ap-more-${De.num}`))==null||tt.focus()),bt()},[bt]);w.useEffect(()=>{t&&(bt(),E(null))},[t,bt]),w.useEffect(()=>{H&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===H.num)&&bt(),j&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===j.num)&&E(null)},[n,H,j,bt]);const In=async Q=>{var et;z(!1);const De=await Re({action:"share",account:Q},`share-${Q}`);!(De!=null&&De.ok)||((et=V.current)==null?void 0:et.num)!==Q||(G({num:Q,blob:De.blob,expiresAt:De.expiresAt}),q({num:Q,view:"share"}))},Hr=async(Q,De)=>{const{commit:et,alias:Ue}=kU(K,De);if(et){const tt=await Re({action:"alias",account:Q,alias:Ue},`alias-${Q}`);if(await qe(!0),!(tt!=null&&tt.ok))return}Zt(Q)},xe=async(Q,De)=>{var tt,wt;const et=await Re({action:"move",account:Q,slot:De},`move-${Q}`),Ue=fU({menuFor:((tt=V.current)==null?void 0:tt.num)??null,shareFor:(F==null?void 0:F.num)??null},Q,et);if(await qe(!0),Ue){((wt=V.current)==null?void 0:wt.num)===Q&&bt(),B(Ue.confirmRemove),Ue.shareFor==null&&(G(null),z(!1)),Ne(Ue.swapNote);const gt=Ue.swapNote;gt&&window.setTimeout(()=>Ne(It=>It===gt?null:It),EU),Ge(null),Ye(Ue.menuFor)}return et},lr=async(Q,De,et)=>{if(!et.sends){Zt(Q);return}await xe(Q,De)},ks=async(Q,De)=>{if(De.sends){const et=await ke({action:"setting",key:"autoswitch.threshold",value:Q},"threshold");if(await qe(!0),!(et!=null&&et.ok))return;Be(null)}st(!0),window.setTimeout(()=>{var et;document.activeElement===ue.current&&((et=de.current)==null||et.focus()),st(!1)},CU)},Wr=o.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:o.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})}),fa=Q=>{const{shown:De,fuller:et}=yU(Q.lanes),Ue=Nh(Q,R),tt=Q.active||se.includes(sf(Q)),wt=Q.alias??Q.email??`account ${Q.num}`,gt=Q.alias&&Q.email?`${Q.alias} · ${Q.email}`:wt,It=Q.stale||(Ue==null?void 0:Ue.blocksSwitch)===!0,Rt=et?[...De,et]:De,Qt=Q.fetchedAt?Rm(Q.fetchedAt,R):null;return o.jsxs("li",{className:`ap-account${Q.active?" active":""}`,"aria-current":Q.active?"true":void 0,"data-open":tt?"":void 0,"data-frozen":It?"":void 0,children:[!Q.active&&o.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${Q.num}`,title:gt,"aria-expanded":tt,"aria-controls":tt?`ap-detail-${Q.num}`:void 0,"aria-describedby":[Q.alias&&Q.email?`ap-email-${Q.num}`:null,!tt&&!(Ue!=null&&Ue.blocksSwitch)?`ap-quota-${Q.num}`:null].filter(Boolean).join(" ")||void 0,onClick:()=>be(Nt=>vU(Nt,Q)),children:o.jsxs("span",{className:"vis-hidden",children:[wt,", ",tt?"hide details":"details"]})}),o.jsxs("div",{className:"ap-account-head",children:[Q.active?o.jsx("span",{className:"ap-live",title:`Active account · slot ${Q.num}`,children:o.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",Q.num,":"]})}):o.jsx("span",{className:"ap-num",children:Q.num}),Q.alias&&o.jsx("span",{className:"ap-alias",title:Q.alias,children:Q.alias}),o.jsx("span",{className:"ap-email",id:`ap-email-${Q.num}`,title:Q.email??void 0,children:Q.email}),Q.disabled&&o.jsx("span",{className:"ap-held",children:"held out"}),!Q.active&&!Q.disabled&&!(Ue!=null&&Ue.blocksSwitch)&&o.jsx("button",{type:"button",className:"ap-switch",...Se(`switch-${Q.num}`),onClick:()=>xt(Q.num,wt),"aria-label":`Switch to ${wt}`,title:`Switch to ${Q.alias??Q.email}`,children:c===`switch-${Q.num}`?"…":"Switch"}),o.jsx("button",{type:"button",id:`ap-more-${Q.num}`,className:"ap-more","aria-label":`More actions for ${Q.email??Q.alias??`account ${Q.num}`}`,"aria-haspopup":"menu","aria-expanded":$===Q.num,"aria-controls":$===Q.num?`ap-menu-${Q.num}`:void 0,title:"More actions",onClick:()=>$===Q.num?Zt():_n(Q.num),onKeyDown:Nt=>{Nt.key!=="ArrowDown"&&Nt.key!=="ArrowUp"||(Nt.preventDefault(),_n(Q.num,Nt.key==="ArrowUp"?"last":"first"))},children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[o.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),o.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),o.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),(h==null?void 0:h.row)===Q.num&&o.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),Q.active&&(y==null?void 0:y.num)===Q.num&&o.jsx("p",{className:"ap-switched",children:"Now active. New sessions start on it; ones already running pick it up on their next message, up to about 30 seconds later on macOS."}),(ge==null?void 0:ge.at)===Q.num&&(()=>{const Nt=ct.find(cr=>cr.num===ge.displaced),br=(Nt==null?void 0:Nt.alias)??(Nt==null?void 0:Nt.email)??"the account that was there";return o.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${ge.at} was taken, so the two accounts traded places: ${br} now holds slot ${ge.displaced}.`,children:["swapped with slot ",ge.displaced]})})(),Ue&&o.jsxs("div",{className:"ap-issue-line",children:[o.jsxs("button",{type:"button",id:`ap-issue-${Q.num}`,className:"ap-issue","data-tone":Ue.tone,"aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)===`ap-issue-${Q.num}`,"aria-controls":(j==null?void 0:j.anchor)===`ap-issue-${Q.num}`?"ap-issue-pop":void 0,onClick:()=>Ut(Q.num,`ap-issue-${Q.num}`),children:[Ue.tone==="warn"&&o.jsx(Am,{}),o.jsx("span",{className:"ap-issue-text",children:Ue.text})]}),!tt&&o.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),!tt&&!(Ue!=null&&Ue.blocksSwitch)&&o.jsxs("p",{className:"ap-quota",id:`ap-quota-${Q.num}`,children:[Rt.length?Rt.map(Nt=>o.jsxs("span",{className:"ap-q",children:[o.jsx("span",{className:"ap-q-label",children:Nt.label})," ",o.jsxs("span",{className:"ap-q-pct","data-level":It?void 0:$U(Nt.pct),children:[Math.round(Nt.pct),"%"]})]},Nt.id)):o.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),Q.stale&&!Ue&&o.jsx("span",{className:"ap-q-age","data-never":Qt?void 0:"",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),tt&&o.jsxs("div",{className:"ap-detail",id:`ap-detail-${Q.num}`,children:[o.jsx("div",{className:"ap-lanes",children:Q.lanes.length?Q.lanes.map(Nt=>o.jsx(LU,{lane:Nt,nowSec:R,frozen:It},Nt.id)):o.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),o.jsx("div",{className:"ap-meta",children:Q.fetchedAt?o.jsxs("span",{className:`ap-age${Q.stale&&!Ue?" ap-stale":""}`,title:"When claude-swap last read this account's usage, and when it plans to read it again. It sets that interval itself — 3 minutes at the fastest, wider while an account is recovering from a rate limit — and every surface, including `cswap watch`, follows the same plan.",children:["collected ",Rm(Q.fetchedAt,R),Ue!=null&&Ue.blocksSwitch?"":RU(Q.nextAt,R)]}):o.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]},Q.num)},Ns=n!=null&&n.ok&&(s!=null&&s.ok)?o.jsxs("div",{className:"ap-policy-block",children:[o.jsxs("div",{className:"ap-policy",children:[o.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),o.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:o.jsx("select",{ref:de,"aria-label":"Switch threshold",value:Fe,...Se("threshold"),onChange:Q=>Be(Q.target.value),children:OU(ze).map(Q=>o.jsxs("option",{value:Q,children:[Q,"%"]},Q))})}),(We.sends||Te)&&o.jsx("button",{ref:ue,type:"button",className:"ap-manage-btn",...Se("threshold"),title:We.title,onClick:()=>ks(Fe,We),children:Te&&!We.sends?We.done:We.label}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":s.enabled,"aria-label":"Auto-switch",...Se("enable"),onClick:()=>ke({action:"enable",enabled:!s.enabled},"enable").then(()=>qe(!0)),title:s.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:o.jsx("span",{className:"switch-knob"})})]}),s.external&&o.jsxs("p",{className:"ap-auto-note",children:[o.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",o.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",s.enabled?" — this toggle takes over when you stop it.":"."]})]}):null;return o.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",children:[S==="accounts"&&o.jsxs("div",{className:"ap-header",children:[o.jsx("h2",{children:"Claude accounts"}),o.jsxs("div",{className:"ap-header-right",children:[o.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>Z(!0),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:o.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),(((Hs=n==null?void 0:n.accounts)==null?void 0:Hs.length)??0)>0&&o.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>U(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${dn} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),o.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),o.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>qe(!0),...Se("reload",f),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),o.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),Wr]})]}),S==="accounts"&&o.jsx("div",{className:"ap-scroll",id:"ap-scroll",children:n==null?h?o.jsxs("div",{className:"ap-empty",role:"alert",children:[o.jsx("span",{title:h.raw||void 0,children:h.text}),o.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",sj/1e3," seconds."]}),o.jsx("button",{type:"button",className:"ap-fix",disabled:f,onClick:()=>qe(!0),children:f?"trying…":"try again"})]}):o.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?o.jsxs(o.Fragment,{children:[rt&&(dt==null?void 0:dt.tone)==="warn"&&o.jsxs("div",{className:"ap-notice",children:[o.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)==="ap-notice","aria-controls":(j==null?void 0:j.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>Ut(rt.num,"ap-notice"),children:[o.jsx(Am,{}),o.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),dt.fix&&o.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>Z(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),o.jsx("ul",{className:"ap-list",children:Ot.map(fa)}),yt.length>0&&o.jsx(lU,{peers:zt,strained:Dt,armed:rn,threshold:s!=null&&s.ok?ze:null,open:Le,onToggle:()=>ce(Q=>!Q)}),yt.length>0&&Le&&o.jsxs("div",{className:"ap-rest-panel",id:"ap-rest-panel",children:[o.jsx("ul",{className:"ap-list ap-others",id:"ap-rest-list",children:yt.map(fa)}),Ns]}),yt.length===0&&Ns,h&&h.row==null&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),H&&(()=>{var Ue;const Q=(Ue=n.accounts)==null?void 0:Ue.find(tt=>tt.num===H.num);if(!Q)return null;const De=`ap-pop-title-${Q.num}`,et=ne&&o.jsx("p",{className:"ap-pop-error",role:"alert",title:ne.raw||void 0,children:ne.text});return o.jsxs(M0,{anchorId:`ap-more-${Q.num}`,boundaryId:je(Q.num),id:`ap-menu-${Q.num}`,className:"ap-pop",role:H.view==="menu"?"menu":"dialog",labelledBy:H.view==="menu"?`ap-more-${Q.num}`:De,start:H.start,onClose:bt,children:[H.view==="menu"&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{D(Q.alias??""),ee(null),q({num:Q.num,view:"rename"})},children:"Rename"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{Ge(null),ee(null),q({num:Q.num,view:"move"})},children:"Move to slot…"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Se(`share-${Q.num}`),title:`Copy this account to another ${dn}. Anyone who has the text can use the account — treat it as the password. The other deck stops accepting it after 10 minutes; that does not make an escaped copy safe.`,onClick:()=>In(Q.num),children:c===`share-${Q.num}`?"Sharing…":"Share"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",title:"See how much this account worked in each project",onClick:()=>{le(Q.num),Zt(Q.num)},children:"Projects"}),(((s==null?void 0:s.enabled)||(s==null?void 0:s.external))&&!Q.active||Q.disabled)&&o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Se(`rot-${Q.num}`),title:Q.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>ke({action:"account",account:Q.num,enabled:Q.disabled},`rot-${Q.num}`,"menu").then(tt=>{qe(!0),tt!=null&&tt.ok&&Zt(Q.num)}),children:Q.disabled?"Put back in rotation":"Hold out of rotation"}),o.jsx("div",{role:"separator",className:"ap-menu-sep"}),o.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${P===Q.num?" armed":""}`,...Se(`rm-${Q.num}`),"aria-label":P===Q.num?"Confirm remove":void 0,title:P===Q.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{const tt=Date.now(),wt=Cu({armedFor:P,target:Q.num,armedAt:W.current,now:tt,gapMs:Mu});if(wt==="arm"){B(Q.num),W.current=tt,window.setTimeout(()=>B(gt=>gt===Q.num?null:gt),4e3);return}wt!=="ignore"&&(B(null),Re({action:"remove",account:Q.num},`rm-${Q.num}`).then(gt=>{var It;qe(!0),gt!=null&>.ok&&(((It=V.current)==null?void 0:It.num)===Q.num&&bt(),Ye(null))}))},children:c===`rm-${Q.num}`?"Removing…":P===Q.num?"Confirm":"Remove"}),et]}),H.view==="rename"&&o.jsxs("form",{className:"ap-pop-form",onSubmit:tt=>{tt.preventDefault(),Hr(Q.num,Q.alias)},children:[o.jsx("label",{className:"ap-pop-title",id:De,htmlFor:`ap-alias-${Q.num}`,children:"Rename account"}),o.jsx("input",{id:`ap-alias-${Q.num}`,className:"ap-manage-input",type:"text",value:K,onChange:tt=>D(tt.target.value),maxLength:bU,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:tt=>tt.currentTarget.select()}),et,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Cancel"}),o.jsx("button",{type:"submit",className:"btn primary",...Se(`alias-${Q.num}`),title:"A short name to show instead of the email",children:c===`alias-${Q.num}`?"…":"Save"})]})]}),H.view==="move"&&(()=>{const tt=hU((n.accounts??[]).map(It=>It.num),Q.num),wt=pU(tt,Ie,Q.num),gt=mU(tt,wt,Q.num);return o.jsxs("div",{className:"ap-pop-form",children:[o.jsx("label",{className:"ap-pop-title",id:De,htmlFor:`ap-slot-${Q.num}`,children:"Move to slot"}),o.jsx("span",{className:"ap-field",children:o.jsx("select",{id:`ap-slot-${Q.num}`,value:String(wt),...Se(`move-${Q.num}`),onChange:It=>Ge(Number(It.target.value)),autoFocus:!0,children:tt.map(It=>o.jsx("option",{value:It.slot,children:It.label},It.slot))})}),et,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Cancel"}),o.jsx("button",{type:"button",className:"btn primary",...Se(`move-${Q.num}`),title:gt.title,onClick:()=>lr(Q.num,wt,gt),children:c===`move-${Q.num}`?"…":lu(gt.label)})]})]})})(),H.view==="share"&&(F==null?void 0:F.num)===Q.num&&(()=>{const tt=zM(F.expiresAt,R),wt=tt.tone==="gone";return o.jsxs("div",{className:`ap-pop-form ap-share${wt?" expired":""}`,children:[o.jsx("p",{className:"ap-pop-title",id:De,children:"Share account"}),o.jsx("code",{className:"ap-share-blob",children:F.blob}),o.jsxs("p",{className:"ap-pop-note",title:"This text is the account's password. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the login itself is in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign the account out and back in.",children:[o.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",o.jsx("span",{className:`ap-share-expiry ${tt.tone}`,children:tt.text})]}),et,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Done"}),o.jsx("button",{type:"button",className:"btn primary",...Se(`share-${Q.num}`),autoFocus:!0,onClick:async()=>{if(wt){await In(Q.num);return}await hi(F.blob)&&(z(!0),window.setTimeout(()=>z(!1),1800))},children:wt?"Make a new share":Y?"Copied":"Copy"})]})]})})()]})})(),j&&(()=>{var et;const Q=(et=n.accounts)==null?void 0:et.find(Ue=>Ue.num===j.num),De=Q?Nh(Q,R):null;return!Q||!De?null:o.jsx(M0,{anchorId:j.anchor,boundaryId:j.anchor==="ap-notice"?"ap-scroll":je(Q.num),id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",onClose:()=>Vn(),children:o.jsxs("div",{className:"ap-pop-form",children:[o.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":De.tone,children:[De.tone==="warn"&&o.jsx(Am,{}),De.text]}),o.jsx("p",{className:"ap-pop-note ap-issue-hint",children:De.hint}),o.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[o.jsx("span",{className:"ap-issue-who",children:Q.alias??Q.email??`account ${Q.num}`})," · ",Q.fetchedAt?`last collected ${Rm(Q.fetchedAt,R)}`:"never collected"]}),o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Vn(!0),children:"Done"}),De.fix&&o.jsx("button",{type:"button",className:"btn primary",onClick:()=>{Vn(!0),Z(!0)},title:"Open the sign-in dialog. Signing in as this account puts its login back in this slot — it keeps its slot, its alias and its history.",children:De.fix})]})]})})})()]}):o.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"claude-swap isn't installed."}),o.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&o.jsx("code",{className:"ap-cmd",children:n.hint}),o.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",o.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"No accounts added yet."}),o.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",o.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"Couldn't read the account store."}),o.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})})}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:y?`Now active: ${y.name}`:""}),_&&o.jsx(oU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({key:`${String(Q.email??"").trim().toLowerCase()}@@${Q.orgUuid??""}`,email:Q.email??"",alive:Q.alive===!0,shareable:Q.collector==="ok"||Q.collector==null&&!Q.active})),onChanged:()=>qe(!0),view:S==="lan",onOpen:Vt,onBack:()=>b("accounts"),closeButton:Wr}),M&&o.jsx(rz,{onClose:()=>Z(!1),onChanged:()=>qe(!0)}),re&&o.jsx(dU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({num:Q.num,email:Q.email,alias:Q.alias,org:Q.org})),onClose:()=>U(!1),copyText:hi}),ie!=null&&(()=>{const Q=((n==null?void 0:n.accounts)??[]).find(De=>De.num===ie);return Q?o.jsx(NB,{num:Q.num,name:Q.alias??Q.email??`account ${Q.num}`,onClose:()=>le(null)}):(le(null),null)})()]})}const DU=3e4;function FU({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function qU({bundle:e,running:t,pending:n,lastTried:r}){return t?FU({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function BU(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function zU({asked:e,reported:t}){return t?t!==e:!1}function XM(e){const t=e.thresholdMs??DU;return!e.enabled||e.kind!=="restart"||!e.canRestart||!e.noticeOpen||!e.visible||e.busy?null:e.idleSince==null||e.now<e.idleSince?t:Math.max(0,t-(e.now-e.idleSince))}function UU(e){const t=Math.max(0,Math.ceil(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function HU(e,t){return e?t==null?"auto when idle":`auto in ${UU(t)}`:"auto-restart off"}function aj(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function WU(e){return e<=0?{label:"Restart now",clause:"nothing is running"}:{label:"Restart anyway",clause:`${e===1?"1 agent is running":`${e} agents are running`} — their events during the restart are lost`}}function VU(e){const t=XM(e);return t==null?{idleSince:null,restart:!1,remainingMs:null}:e.idleSince==null||e.now<e.idleSince?{idleSince:e.now,restart:!1,remainingMs:t}:{idleSince:e.idleSince,restart:t===0,remainingMs:t}}function zb(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Mm,oj;function GU(){if(oj)return Mm;oj=1;function e(){this.__data__=[],this.size=0}return Mm=e,Mm}var Im,ij;function tc(){if(ij)return Im;ij=1;function e(t,n){return t===n||t!==t&&n!==n}return Im=e,Im}var $m,lj;function Mf(){if(lj)return $m;lj=1;var e=tc();function t(n,r){for(var s=n.length;s--;)if(e(n[s][0],r))return s;return-1}return $m=t,$m}var Om,cj;function KU(){if(cj)return Om;cj=1;var e=Mf(),t=Array.prototype,n=t.splice;function r(s){var l=this.__data__,c=e(l,s);if(c<0)return!1;var u=l.length-1;return c==u?l.pop():n.call(l,c,1),--this.size,!0}return Om=r,Om}var Lm,uj;function YU(){if(uj)return Lm;uj=1;var e=Mf();function t(n){var r=this.__data__,s=e(r,n);return s<0?void 0:r[s][1]}return Lm=t,Lm}var Pm,dj;function XU(){if(dj)return Pm;dj=1;var e=Mf();function t(n){return e(this.__data__,n)>-1}return Pm=t,Pm}var Dm,hj;function ZU(){if(hj)return Dm;hj=1;var e=Mf();function t(n,r){var s=this.__data__,l=e(s,n);return l<0?(++this.size,s.push([n,r])):s[l][1]=r,this}return Dm=t,Dm}var Fm,fj;function If(){if(fj)return Fm;fj=1;var e=GU(),t=KU(),n=YU(),r=XU(),s=ZU();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,Fm=l,Fm}var qm,pj;function QU(){if(pj)return qm;pj=1;var e=If();function t(){this.__data__=new e,this.size=0}return qm=t,qm}var Bm,mj;function JU(){if(mj)return Bm;mj=1;function e(t){var n=this.__data__,r=n.delete(t);return this.size=n.size,r}return Bm=e,Bm}var zm,gj;function eH(){if(gj)return zm;gj=1;function e(t){return this.__data__.get(t)}return zm=e,zm}var Um,yj;function tH(){if(yj)return Um;yj=1;function e(t){return this.__data__.has(t)}return Um=e,Um}var Hm,wj;function ZM(){if(wj)return Hm;wj=1;var e=typeof th=="object"&&th&&th.Object===Object&&th;return Hm=e,Hm}var Wm,vj;function bs(){if(vj)return Wm;vj=1;var e=ZM(),t=typeof self=="object"&&self&&self.Object===Object&&self,n=e||t||Function("return this")();return Wm=n,Wm}var Vm,xj;function nc(){if(xj)return Vm;xj=1;var e=bs(),t=e.Symbol;return Vm=t,Vm}var Gm,bj;function nH(){if(bj)return Gm;bj=1;var e=nc(),t=Object.prototype,n=t.hasOwnProperty,r=t.toString,s=e?e.toStringTag:void 0;function l(c){var u=n.call(c,s),f=c[s];try{c[s]=void 0;var p=!0}catch{}var h=r.call(c);return p&&(u?c[s]=f:delete c[s]),h}return Gm=l,Gm}var Km,kj;function rH(){if(kj)return Km;kj=1;var e=Object.prototype,t=e.toString;function n(r){return t.call(r)}return Km=n,Km}var Ym,Nj;function wi(){if(Nj)return Ym;Nj=1;var e=nc(),t=nH(),n=rH(),r="[object Null]",s="[object Undefined]",l=e?e.toStringTag:void 0;function c(u){return u==null?u===void 0?s:r:l&&l in Object(u)?t(u):n(u)}return Ym=c,Ym}var Xm,Sj;function zr(){if(Sj)return Xm;Sj=1;function e(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}return Xm=e,Xm}var Zm,jj;function Uu(){if(jj)return Zm;jj=1;var e=wi(),t=zr(),n="[object AsyncFunction]",r="[object Function]",s="[object GeneratorFunction]",l="[object Proxy]";function c(u){if(!t(u))return!1;var f=e(u);return f==r||f==s||f==n||f==l}return Zm=c,Zm}var Qm,_j;function sH(){if(_j)return Qm;_j=1;var e=bs(),t=e["__core-js_shared__"];return Qm=t,Qm}var Jm,Ej;function aH(){if(Ej)return Jm;Ej=1;var e=sH(),t=(function(){var r=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""})();function n(r){return!!t&&t in r}return Jm=n,Jm}var eg,Cj;function QM(){if(Cj)return eg;Cj=1;var e=Function.prototype,t=e.toString;function n(r){if(r!=null){try{return t.call(r)}catch{}try{return r+""}catch{}}return""}return eg=n,eg}var tg,Tj;function oH(){if(Tj)return tg;Tj=1;var e=Uu(),t=aH(),n=zr(),r=QM(),s=/[\\^$.*+?()[\]{}|]/g,l=/^\[object .+?Constructor\]$/,c=Function.prototype,u=Object.prototype,f=c.toString,p=u.hasOwnProperty,h=RegExp("^"+f.call(p).replace(s,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function m(y){if(!n(y)||t(y))return!1;var v=e(y)?h:l;return v.test(r(y))}return tg=m,tg}var ng,Rj;function iH(){if(Rj)return ng;Rj=1;function e(t,n){return t==null?void 0:t[n]}return ng=e,ng}var rg,Aj;function vi(){if(Aj)return rg;Aj=1;var e=oH(),t=iH();function n(r,s){var l=t(r,s);return e(l)?l:void 0}return rg=n,rg}var sg,Mj;function Ub(){if(Mj)return sg;Mj=1;var e=vi(),t=bs(),n=e(t,"Map");return sg=n,sg}var ag,Ij;function $f(){if(Ij)return ag;Ij=1;var e=vi(),t=e(Object,"create");return ag=t,ag}var og,$j;function lH(){if($j)return og;$j=1;var e=$f();function t(){this.__data__=e?e(null):{},this.size=0}return og=t,og}var ig,Oj;function cH(){if(Oj)return ig;Oj=1;function e(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}return ig=e,ig}var lg,Lj;function uH(){if(Lj)return lg;Lj=1;var e=$f(),t="__lodash_hash_undefined__",n=Object.prototype,r=n.hasOwnProperty;function s(l){var c=this.__data__;if(e){var u=c[l];return u===t?void 0:u}return r.call(c,l)?c[l]:void 0}return lg=s,lg}var cg,Pj;function dH(){if(Pj)return cg;Pj=1;var e=$f(),t=Object.prototype,n=t.hasOwnProperty;function r(s){var l=this.__data__;return e?l[s]!==void 0:n.call(l,s)}return cg=r,cg}var ug,Dj;function hH(){if(Dj)return ug;Dj=1;var e=$f(),t="__lodash_hash_undefined__";function n(r,s){var l=this.__data__;return this.size+=this.has(r)?0:1,l[r]=e&&s===void 0?t:s,this}return ug=n,ug}var dg,Fj;function fH(){if(Fj)return dg;Fj=1;var e=lH(),t=cH(),n=uH(),r=dH(),s=hH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,dg=l,dg}var hg,qj;function pH(){if(qj)return hg;qj=1;var e=fH(),t=If(),n=Ub();function r(){this.size=0,this.__data__={hash:new e,map:new(n||t),string:new e}}return hg=r,hg}var fg,Bj;function mH(){if(Bj)return fg;Bj=1;function e(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}return fg=e,fg}var pg,zj;function Of(){if(zj)return pg;zj=1;var e=mH();function t(n,r){var s=n.__data__;return e(r)?s[typeof r=="string"?"string":"hash"]:s.map}return pg=t,pg}var mg,Uj;function gH(){if(Uj)return mg;Uj=1;var e=Of();function t(n){var r=e(this,n).delete(n);return this.size-=r?1:0,r}return mg=t,mg}var gg,Hj;function yH(){if(Hj)return gg;Hj=1;var e=Of();function t(n){return e(this,n).get(n)}return gg=t,gg}var yg,Wj;function wH(){if(Wj)return yg;Wj=1;var e=Of();function t(n){return e(this,n).has(n)}return yg=t,yg}var wg,Vj;function vH(){if(Vj)return wg;Vj=1;var e=Of();function t(n,r){var s=e(this,n),l=s.size;return s.set(n,r),this.size+=s.size==l?0:1,this}return wg=t,wg}var vg,Gj;function Hb(){if(Gj)return vg;Gj=1;var e=pH(),t=gH(),n=yH(),r=wH(),s=vH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,vg=l,vg}var xg,Kj;function xH(){if(Kj)return xg;Kj=1;var e=If(),t=Ub(),n=Hb(),r=200;function s(l,c){var u=this.__data__;if(u instanceof e){var f=u.__data__;if(!t||f.length<r-1)return f.push([l,c]),this.size=++u.size,this;u=this.__data__=new n(f)}return u.set(l,c),this.size=u.size,this}return xg=s,xg}var bg,Yj;function Lf(){if(Yj)return bg;Yj=1;var e=If(),t=QU(),n=JU(),r=eH(),s=tH(),l=xH();function c(u){var f=this.__data__=new e(u);this.size=f.size}return c.prototype.clear=t,c.prototype.delete=n,c.prototype.get=r,c.prototype.has=s,c.prototype.set=l,bg=c,bg}var kg,Xj;function Wb(){if(Xj)return kg;Xj=1;function e(t,n){for(var r=-1,s=t==null?0:t.length;++r<s&&n(t[r],r,t)!==!1;);return t}return kg=e,kg}var Ng,Zj;function JM(){if(Zj)return Ng;Zj=1;var e=vi(),t=(function(){try{var n=e(Object,"defineProperty");return n({},"",{}),n}catch{}})();return Ng=t,Ng}var Sg,Qj;function Pf(){if(Qj)return Sg;Qj=1;var e=JM();function t(n,r,s){r=="__proto__"&&e?e(n,r,{configurable:!0,enumerable:!0,value:s,writable:!0}):n[r]=s}return Sg=t,Sg}var jg,Jj;function Df(){if(Jj)return jg;Jj=1;var e=Pf(),t=tc(),n=Object.prototype,r=n.hasOwnProperty;function s(l,c,u){var f=l[c];(!(r.call(l,c)&&t(f,u))||u===void 0&&!(c in l))&&e(l,c,u)}return jg=s,jg}var _g,e_;function Hu(){if(e_)return _g;e_=1;var e=Df(),t=Pf();function n(r,s,l,c){var u=!l;l||(l={});for(var f=-1,p=s.length;++f<p;){var h=s[f],m=c?c(l[h],r[h],h,l,r):void 0;m===void 0&&(m=r[h]),u?t(l,h,m):e(l,h,m)}return l}return _g=n,_g}var Eg,t_;function bH(){if(t_)return Eg;t_=1;function e(t,n){for(var r=-1,s=Array(t);++r<t;)s[r]=n(r);return s}return Eg=e,Eg}var Cg,n_;function Us(){if(n_)return Cg;n_=1;function e(t){return t!=null&&typeof t=="object"}return Cg=e,Cg}var Tg,r_;function kH(){if(r_)return Tg;r_=1;var e=wi(),t=Us(),n="[object Arguments]";function r(s){return t(s)&&e(s)==n}return Tg=r,Tg}var Rg,s_;function Wu(){if(s_)return Rg;s_=1;var e=kH(),t=Us(),n=Object.prototype,r=n.hasOwnProperty,s=n.propertyIsEnumerable,l=e((function(){return arguments})())?e:function(c){return t(c)&&r.call(c,"callee")&&!s.call(c,"callee")};return Rg=l,Rg}var Ag,a_;function nn(){if(a_)return Ag;a_=1;var e=Array.isArray;return Ag=e,Ag}var cu={exports:{}},Mg,o_;function NH(){if(o_)return Mg;o_=1;function e(){return!1}return Mg=e,Mg}cu.exports;var i_;function rc(){return i_||(i_=1,(function(e,t){var n=bs(),r=NH(),s=t&&!t.nodeType&&t,l=s&&!0&&e&&!e.nodeType&&e,c=l&&l.exports===s,u=c?n.Buffer:void 0,f=u?u.isBuffer:void 0,p=f||r;e.exports=p})(cu,cu.exports)),cu.exports}var Ig,l_;function Ff(){if(l_)return Ig;l_=1;var e=9007199254740991,t=/^(?:0|[1-9]\d*)$/;function n(r,s){var l=typeof r;return s=s??e,!!s&&(l=="number"||l!="symbol"&&t.test(r))&&r>-1&&r%1==0&&r<s}return Ig=n,Ig}var $g,c_;function Vb(){if(c_)return $g;c_=1;var e=9007199254740991;function t(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=e}return $g=t,$g}var Og,u_;function SH(){if(u_)return Og;u_=1;var e=wi(),t=Vb(),n=Us(),r="[object Arguments]",s="[object Array]",l="[object Boolean]",c="[object Date]",u="[object Error]",f="[object Function]",p="[object Map]",h="[object Number]",m="[object Object]",y="[object RegExp]",v="[object Set]",S="[object String]",b="[object WeakMap]",_="[object ArrayBuffer]",k="[object DataView]",j="[object Float32Array]",E="[object Float64Array]",C="[object Int8Array]",R="[object Int16Array]",I="[object Int32Array]",O="[object Uint8Array]",H="[object Uint8ClampedArray]",q="[object Uint16Array]",$="[object Uint32Array]",V={};V[j]=V[E]=V[C]=V[R]=V[I]=V[O]=V[H]=V[q]=V[$]=!0,V[r]=V[s]=V[_]=V[l]=V[k]=V[c]=V[u]=V[f]=V[p]=V[h]=V[m]=V[y]=V[v]=V[S]=V[b]=!1;function ne(ee){return n(ee)&&t(ee.length)&&!!V[e(ee)]}return Og=ne,Og}var Lg,d_;function qf(){if(d_)return Lg;d_=1;function e(t){return function(n){return t(n)}}return Lg=e,Lg}var uu={exports:{}};uu.exports;var h_;function Gb(){return h_||(h_=1,(function(e,t){var n=ZM(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,l=s&&s.exports===r,c=l&&n.process,u=(function(){try{var f=s&&s.require&&s.require("util").types;return f||c&&c.binding&&c.binding("util")}catch{}})();e.exports=u})(uu,uu.exports)),uu.exports}var Pg,f_;function Vu(){if(f_)return Pg;f_=1;var e=SH(),t=qf(),n=Gb(),r=n&&n.isTypedArray,s=r?t(r):e;return Pg=s,Pg}var Dg,p_;function eI(){if(p_)return Dg;p_=1;var e=bH(),t=Wu(),n=nn(),r=rc(),s=Ff(),l=Vu(),c=Object.prototype,u=c.hasOwnProperty;function f(p,h){var m=n(p),y=!m&&t(p),v=!m&&!y&&r(p),S=!m&&!y&&!v&&l(p),b=m||y||v||S,_=b?e(p.length,String):[],k=_.length;for(var j in p)(h||u.call(p,j))&&!(b&&(j=="length"||v&&(j=="offset"||j=="parent")||S&&(j=="buffer"||j=="byteLength"||j=="byteOffset")||s(j,k)))&&_.push(j);return _}return Dg=f,Dg}var Fg,m_;function Bf(){if(m_)return Fg;m_=1;var e=Object.prototype;function t(n){var r=n&&n.constructor,s=typeof r=="function"&&r.prototype||e;return n===s}return Fg=t,Fg}var qg,g_;function tI(){if(g_)return qg;g_=1;function e(t,n){return function(r){return t(n(r))}}return qg=e,qg}var Bg,y_;function jH(){if(y_)return Bg;y_=1;var e=tI(),t=e(Object.keys,Object);return Bg=t,Bg}var zg,w_;function Kb(){if(w_)return zg;w_=1;var e=Bf(),t=jH(),n=Object.prototype,r=n.hasOwnProperty;function s(l){if(!e(l))return t(l);var c=[];for(var u in Object(l))r.call(l,u)&&u!="constructor"&&c.push(u);return c}return zg=s,zg}var Ug,v_;function da(){if(v_)return Ug;v_=1;var e=Uu(),t=Vb();function n(r){return r!=null&&t(r.length)&&!e(r)}return Ug=n,Ug}var Hg,x_;function oo(){if(x_)return Hg;x_=1;var e=eI(),t=Kb(),n=da();function r(s){return n(s)?e(s):t(s)}return Hg=r,Hg}var Wg,b_;function _H(){if(b_)return Wg;b_=1;var e=Hu(),t=oo();function n(r,s){return r&&e(s,t(s),r)}return Wg=n,Wg}var Vg,k_;function EH(){if(k_)return Vg;k_=1;function e(t){var n=[];if(t!=null)for(var r in Object(t))n.push(r);return n}return Vg=e,Vg}var Gg,N_;function CH(){if(N_)return Gg;N_=1;var e=zr(),t=Bf(),n=EH(),r=Object.prototype,s=r.hasOwnProperty;function l(c){if(!e(c))return n(c);var u=t(c),f=[];for(var p in c)p=="constructor"&&(u||!s.call(c,p))||f.push(p);return f}return Gg=l,Gg}var Kg,S_;function xi(){if(S_)return Kg;S_=1;var e=eI(),t=CH(),n=da();function r(s){return n(s)?e(s,!0):t(s)}return Kg=r,Kg}var Yg,j_;function TH(){if(j_)return Yg;j_=1;var e=Hu(),t=xi();function n(r,s){return r&&e(s,t(s),r)}return Yg=n,Yg}var du={exports:{}};du.exports;var __;function nI(){return __||(__=1,(function(e,t){var n=bs(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,l=s&&s.exports===r,c=l?n.Buffer:void 0,u=c?c.allocUnsafe:void 0;function f(p,h){if(h)return p.slice();var m=p.length,y=u?u(m):new p.constructor(m);return p.copy(y),y}e.exports=f})(du,du.exports)),du.exports}var Xg,E_;function rI(){if(E_)return Xg;E_=1;function e(t,n){var r=-1,s=t.length;for(n||(n=Array(s));++r<s;)n[r]=t[r];return n}return Xg=e,Xg}var Zg,C_;function sI(){if(C_)return Zg;C_=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,l=0,c=[];++r<s;){var u=t[r];n(u,r,t)&&(c[l++]=u)}return c}return Zg=e,Zg}var Qg,T_;function aI(){if(T_)return Qg;T_=1;function e(){return[]}return Qg=e,Qg}var Jg,R_;function Yb(){if(R_)return Jg;R_=1;var e=sI(),t=aI(),n=Object.prototype,r=n.propertyIsEnumerable,s=Object.getOwnPropertySymbols,l=s?function(c){return c==null?[]:(c=Object(c),e(s(c),function(u){return r.call(c,u)}))}:t;return Jg=l,Jg}var ey,A_;function RH(){if(A_)return ey;A_=1;var e=Hu(),t=Yb();function n(r,s){return e(r,t(r),s)}return ey=n,ey}var ty,M_;function Xb(){if(M_)return ty;M_=1;function e(t,n){for(var r=-1,s=n.length,l=t.length;++r<s;)t[l+r]=n[r];return t}return ty=e,ty}var ny,I_;function zf(){if(I_)return ny;I_=1;var e=tI(),t=e(Object.getPrototypeOf,Object);return ny=t,ny}var ry,$_;function oI(){if($_)return ry;$_=1;var e=Xb(),t=zf(),n=Yb(),r=aI(),s=Object.getOwnPropertySymbols,l=s?function(c){for(var u=[];c;)e(u,n(c)),c=t(c);return u}:r;return ry=l,ry}var sy,O_;function AH(){if(O_)return sy;O_=1;var e=Hu(),t=oI();function n(r,s){return e(r,t(r),s)}return sy=n,sy}var ay,L_;function iI(){if(L_)return ay;L_=1;var e=Xb(),t=nn();function n(r,s,l){var c=s(r);return t(r)?c:e(c,l(r))}return ay=n,ay}var oy,P_;function lI(){if(P_)return oy;P_=1;var e=iI(),t=Yb(),n=oo();function r(s){return e(s,n,t)}return oy=r,oy}var iy,D_;function MH(){if(D_)return iy;D_=1;var e=iI(),t=oI(),n=xi();function r(s){return e(s,n,t)}return iy=r,iy}var ly,F_;function IH(){if(F_)return ly;F_=1;var e=vi(),t=bs(),n=e(t,"DataView");return ly=n,ly}var cy,q_;function $H(){if(q_)return cy;q_=1;var e=vi(),t=bs(),n=e(t,"Promise");return cy=n,cy}var uy,B_;function cI(){if(B_)return uy;B_=1;var e=vi(),t=bs(),n=e(t,"Set");return uy=n,uy}var dy,z_;function OH(){if(z_)return dy;z_=1;var e=vi(),t=bs(),n=e(t,"WeakMap");return dy=n,dy}var hy,U_;function sc(){if(U_)return hy;U_=1;var e=IH(),t=Ub(),n=$H(),r=cI(),s=OH(),l=wi(),c=QM(),u="[object Map]",f="[object Object]",p="[object Promise]",h="[object Set]",m="[object WeakMap]",y="[object DataView]",v=c(e),S=c(t),b=c(n),_=c(r),k=c(s),j=l;return(e&&j(new e(new ArrayBuffer(1)))!=y||t&&j(new t)!=u||n&&j(n.resolve())!=p||r&&j(new r)!=h||s&&j(new s)!=m)&&(j=function(E){var C=l(E),R=C==f?E.constructor:void 0,I=R?c(R):"";if(I)switch(I){case v:return y;case S:return u;case b:return p;case _:return h;case k:return m}return C}),hy=j,hy}var fy,H_;function LH(){if(H_)return fy;H_=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r){var s=r.length,l=new r.constructor(s);return s&&typeof r[0]=="string"&&t.call(r,"index")&&(l.index=r.index,l.input=r.input),l}return fy=n,fy}var py,W_;function uI(){if(W_)return py;W_=1;var e=bs(),t=e.Uint8Array;return py=t,py}var my,V_;function Zb(){if(V_)return my;V_=1;var e=uI();function t(n){var r=new n.constructor(n.byteLength);return new e(r).set(new e(n)),r}return my=t,my}var gy,G_;function PH(){if(G_)return gy;G_=1;var e=Zb();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.byteLength)}return gy=t,gy}var yy,K_;function DH(){if(K_)return yy;K_=1;var e=/\w*$/;function t(n){var r=new n.constructor(n.source,e.exec(n));return r.lastIndex=n.lastIndex,r}return yy=t,yy}var wy,Y_;function FH(){if(Y_)return wy;Y_=1;var e=nc(),t=e?e.prototype:void 0,n=t?t.valueOf:void 0;function r(s){return n?Object(n.call(s)):{}}return wy=r,wy}var vy,X_;function dI(){if(X_)return vy;X_=1;var e=Zb();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.length)}return vy=t,vy}var xy,Z_;function qH(){if(Z_)return xy;Z_=1;var e=Zb(),t=PH(),n=DH(),r=FH(),s=dI(),l="[object Boolean]",c="[object Date]",u="[object Map]",f="[object Number]",p="[object RegExp]",h="[object Set]",m="[object String]",y="[object Symbol]",v="[object ArrayBuffer]",S="[object DataView]",b="[object Float32Array]",_="[object Float64Array]",k="[object Int8Array]",j="[object Int16Array]",E="[object Int32Array]",C="[object Uint8Array]",R="[object Uint8ClampedArray]",I="[object Uint16Array]",O="[object Uint32Array]";function H(q,$,V){var ne=q.constructor;switch($){case v:return e(q);case l:case c:return new ne(+q);case S:return t(q,V);case b:case _:case k:case j:case E:case C:case R:case I:case O:return s(q,V);case u:return new ne;case f:case m:return new ne(q);case p:return n(q);case h:return new ne;case y:return r(q)}}return xy=H,xy}var by,Q_;function hI(){if(Q_)return by;Q_=1;var e=zr(),t=Object.create,n=(function(){function r(){}return function(s){if(!e(s))return{};if(t)return t(s);r.prototype=s;var l=new r;return r.prototype=void 0,l}})();return by=n,by}var ky,J_;function fI(){if(J_)return ky;J_=1;var e=hI(),t=zf(),n=Bf();function r(s){return typeof s.constructor=="function"&&!n(s)?e(t(s)):{}}return ky=r,ky}var Ny,eE;function BH(){if(eE)return Ny;eE=1;var e=sc(),t=Us(),n="[object Map]";function r(s){return t(s)&&e(s)==n}return Ny=r,Ny}var Sy,tE;function zH(){if(tE)return Sy;tE=1;var e=BH(),t=qf(),n=Gb(),r=n&&n.isMap,s=r?t(r):e;return Sy=s,Sy}var jy,nE;function UH(){if(nE)return jy;nE=1;var e=sc(),t=Us(),n="[object Set]";function r(s){return t(s)&&e(s)==n}return jy=r,jy}var _y,rE;function HH(){if(rE)return _y;rE=1;var e=UH(),t=qf(),n=Gb(),r=n&&n.isSet,s=r?t(r):e;return _y=s,_y}var Ey,sE;function pI(){if(sE)return Ey;sE=1;var e=Lf(),t=Wb(),n=Df(),r=_H(),s=TH(),l=nI(),c=rI(),u=RH(),f=AH(),p=lI(),h=MH(),m=sc(),y=LH(),v=qH(),S=fI(),b=nn(),_=rc(),k=zH(),j=zr(),E=HH(),C=oo(),R=xi(),I=1,O=2,H=4,q="[object Arguments]",$="[object Array]",V="[object Boolean]",ne="[object Date]",ee="[object Error]",M="[object Function]",Z="[object GeneratorFunction]",K="[object Map]",D="[object Number]",P="[object Object]",B="[object RegExp]",W="[object Set]",F="[object String]",G="[object Symbol]",re="[object WeakMap]",U="[object ArrayBuffer]",Y="[object DataView]",z="[object Float32Array]",ie="[object Float64Array]",le="[object Int8Array]",ge="[object Int16Array]",Ne="[object Int32Array]",Ie="[object Uint8Array]",Ge="[object Uint8ClampedArray]",Pe="[object Uint16Array]",Be="[object Uint32Array]",Te={};Te[q]=Te[$]=Te[U]=Te[Y]=Te[V]=Te[ne]=Te[z]=Te[ie]=Te[le]=Te[ge]=Te[Ne]=Te[K]=Te[D]=Te[P]=Te[B]=Te[W]=Te[F]=Te[G]=Te[Ie]=Te[Ge]=Te[Pe]=Te[Be]=!0,Te[ee]=Te[M]=Te[re]=!1;function st(de,ue,se,be,Le,ce){var pe,Ae=ue&I,fe=ue&O,Se=ue&H;if(se&&(pe=Le?se(de,be,Le,ce):se(de)),pe!==void 0)return pe;if(!j(de))return de;var Ye=b(de);if(Ye){if(pe=y(de),!Ae)return c(de,pe)}else{var qe=m(de),ke=qe==M||qe==Z;if(_(de))return l(de,Ae);if(qe==P||qe==q||ke&&!Le){if(pe=fe||ke?{}:S(de),!Ae)return fe?f(de,s(pe,de)):u(de,r(pe,de))}else{if(!Te[qe])return Le?de:{};pe=v(de,qe,Ae)}}ce||(ce=new e);var Re=ce.get(de);if(Re)return Re;ce.set(de,pe),E(de)?de.forEach(function(We){pe.add(st(We,ue,se,We,de,ce))}):k(de)&&de.forEach(function(We,rt){pe.set(rt,st(We,ue,se,rt,de,ce))});var ze=Se?fe?h:p:fe?R:C,Fe=Ye?void 0:ze(de);return t(Fe||de,function(We,rt){Fe&&(rt=We,We=de[rt]),n(pe,rt,st(We,ue,se,rt,de,ce))}),pe}return Ey=st,Ey}var Cy,aE;function WH(){if(aE)return Cy;aE=1;var e=pI(),t=4;function n(r){return e(r,t)}return Cy=n,Cy}var Ty,oE;function Qb(){if(oE)return Ty;oE=1;function e(t){return function(){return t}}return Ty=e,Ty}var Ry,iE;function VH(){if(iE)return Ry;iE=1;function e(t){return function(n,r,s){for(var l=-1,c=Object(n),u=s(n),f=u.length;f--;){var p=u[t?f:++l];if(r(c[p],p,c)===!1)break}return n}}return Ry=e,Ry}var Ay,lE;function Jb(){if(lE)return Ay;lE=1;var e=VH(),t=e();return Ay=t,Ay}var My,cE;function ek(){if(cE)return My;cE=1;var e=Jb(),t=oo();function n(r,s){return r&&e(r,s,t)}return My=n,My}var Iy,uE;function GH(){if(uE)return Iy;uE=1;var e=da();function t(n,r){return function(s,l){if(s==null)return s;if(!e(s))return n(s,l);for(var c=s.length,u=r?c:-1,f=Object(s);(r?u--:++u<c)&&l(f[u],u,f)!==!1;);return s}}return Iy=t,Iy}var $y,dE;function Uf(){if(dE)return $y;dE=1;var e=ek(),t=GH(),n=t(e);return $y=n,$y}var Oy,hE;function bi(){if(hE)return Oy;hE=1;function e(t){return t}return Oy=e,Oy}var Ly,fE;function mI(){if(fE)return Ly;fE=1;var e=bi();function t(n){return typeof n=="function"?n:e}return Ly=t,Ly}var Py,pE;function gI(){if(pE)return Py;pE=1;var e=Wb(),t=Uf(),n=mI(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c))}return Py=s,Py}var Dy,mE;function yI(){return mE||(mE=1,Dy=gI()),Dy}var Fy,gE;function KH(){if(gE)return Fy;gE=1;var e=Uf();function t(n,r){var s=[];return e(n,function(l,c,u){r(l,c,u)&&s.push(l)}),s}return Fy=t,Fy}var qy,yE;function YH(){if(yE)return qy;yE=1;var e="__lodash_hash_undefined__";function t(n){return this.__data__.set(n,e),this}return qy=t,qy}var By,wE;function XH(){if(wE)return By;wE=1;function e(t){return this.__data__.has(t)}return By=e,By}var zy,vE;function wI(){if(vE)return zy;vE=1;var e=Hb(),t=YH(),n=XH();function r(s){var l=-1,c=s==null?0:s.length;for(this.__data__=new e;++l<c;)this.add(s[l])}return r.prototype.add=r.prototype.push=t,r.prototype.has=n,zy=r,zy}var Uy,xE;function ZH(){if(xE)return Uy;xE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length;++r<s;)if(n(t[r],r,t))return!0;return!1}return Uy=e,Uy}var Hy,bE;function vI(){if(bE)return Hy;bE=1;function e(t,n){return t.has(n)}return Hy=e,Hy}var Wy,kE;function xI(){if(kE)return Wy;kE=1;var e=wI(),t=ZH(),n=vI(),r=1,s=2;function l(c,u,f,p,h,m){var y=f&r,v=c.length,S=u.length;if(v!=S&&!(y&&S>v))return!1;var b=m.get(c),_=m.get(u);if(b&&_)return b==u&&_==c;var k=-1,j=!0,E=f&s?new e:void 0;for(m.set(c,u),m.set(u,c);++k<v;){var C=c[k],R=u[k];if(p)var I=y?p(R,C,k,u,c,m):p(C,R,k,c,u,m);if(I!==void 0){if(I)continue;j=!1;break}if(E){if(!t(u,function(O,H){if(!n(E,H)&&(C===O||h(C,O,f,p,m)))return E.push(H)})){j=!1;break}}else if(!(C===R||h(C,R,f,p,m))){j=!1;break}}return m.delete(c),m.delete(u),j}return Wy=l,Wy}var Vy,NE;function QH(){if(NE)return Vy;NE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s,l){r[++n]=[l,s]}),r}return Vy=e,Vy}var Gy,SE;function tk(){if(SE)return Gy;SE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s){r[++n]=s}),r}return Gy=e,Gy}var Ky,jE;function JH(){if(jE)return Ky;jE=1;var e=nc(),t=uI(),n=tc(),r=xI(),s=QH(),l=tk(),c=1,u=2,f="[object Boolean]",p="[object Date]",h="[object Error]",m="[object Map]",y="[object Number]",v="[object RegExp]",S="[object Set]",b="[object String]",_="[object Symbol]",k="[object ArrayBuffer]",j="[object DataView]",E=e?e.prototype:void 0,C=E?E.valueOf:void 0;function R(I,O,H,q,$,V,ne){switch(H){case j:if(I.byteLength!=O.byteLength||I.byteOffset!=O.byteOffset)return!1;I=I.buffer,O=O.buffer;case k:return!(I.byteLength!=O.byteLength||!V(new t(I),new t(O)));case f:case p:case y:return n(+I,+O);case h:return I.name==O.name&&I.message==O.message;case v:case b:return I==O+"";case m:var ee=s;case S:var M=q&c;if(ee||(ee=l),I.size!=O.size&&!M)return!1;var Z=ne.get(I);if(Z)return Z==O;q|=u,ne.set(I,O);var K=r(ee(I),ee(O),q,$,V,ne);return ne.delete(I),K;case _:if(C)return C.call(I)==C.call(O)}return!1}return Ky=R,Ky}var Yy,_E;function eW(){if(_E)return Yy;_E=1;var e=lI(),t=1,n=Object.prototype,r=n.hasOwnProperty;function s(l,c,u,f,p,h){var m=u&t,y=e(l),v=y.length,S=e(c),b=S.length;if(v!=b&&!m)return!1;for(var _=v;_--;){var k=y[_];if(!(m?k in c:r.call(c,k)))return!1}var j=h.get(l),E=h.get(c);if(j&&E)return j==c&&E==l;var C=!0;h.set(l,c),h.set(c,l);for(var R=m;++_<v;){k=y[_];var I=l[k],O=c[k];if(f)var H=m?f(O,I,k,c,l,h):f(I,O,k,l,c,h);if(!(H===void 0?I===O||p(I,O,u,f,h):H)){C=!1;break}R||(R=k=="constructor")}if(C&&!R){var q=l.constructor,$=c.constructor;q!=$&&"constructor"in l&&"constructor"in c&&!(typeof q=="function"&&q instanceof q&&typeof $=="function"&&$ instanceof $)&&(C=!1)}return h.delete(l),h.delete(c),C}return Yy=s,Yy}var Xy,EE;function tW(){if(EE)return Xy;EE=1;var e=Lf(),t=xI(),n=JH(),r=eW(),s=sc(),l=nn(),c=rc(),u=Vu(),f=1,p="[object Arguments]",h="[object Array]",m="[object Object]",y=Object.prototype,v=y.hasOwnProperty;function S(b,_,k,j,E,C){var R=l(b),I=l(_),O=R?h:s(b),H=I?h:s(_);O=O==p?m:O,H=H==p?m:H;var q=O==m,$=H==m,V=O==H;if(V&&c(b)){if(!c(_))return!1;R=!0,q=!1}if(V&&!q)return C||(C=new e),R||u(b)?t(b,_,k,j,E,C):n(b,_,O,k,j,E,C);if(!(k&f)){var ne=q&&v.call(b,"__wrapped__"),ee=$&&v.call(_,"__wrapped__");if(ne||ee){var M=ne?b.value():b,Z=ee?_.value():_;return C||(C=new e),E(M,Z,k,j,C)}}return V?(C||(C=new e),r(b,_,k,j,E,C)):!1}return Xy=S,Xy}var Zy,CE;function bI(){if(CE)return Zy;CE=1;var e=tW(),t=Us();function n(r,s,l,c,u){return r===s?!0:r==null||s==null||!t(r)&&!t(s)?r!==r&&s!==s:e(r,s,l,c,n,u)}return Zy=n,Zy}var Qy,TE;function nW(){if(TE)return Qy;TE=1;var e=Lf(),t=bI(),n=1,r=2;function s(l,c,u,f){var p=u.length,h=p,m=!f;if(l==null)return!h;for(l=Object(l);p--;){var y=u[p];if(m&&y[2]?y[1]!==l[y[0]]:!(y[0]in l))return!1}for(;++p<h;){y=u[p];var v=y[0],S=l[v],b=y[1];if(m&&y[2]){if(S===void 0&&!(v in l))return!1}else{var _=new e;if(f)var k=f(S,b,v,l,c,_);if(!(k===void 0?t(b,S,n|r,f,_):k))return!1}}return!0}return Qy=s,Qy}var Jy,RE;function kI(){if(RE)return Jy;RE=1;var e=zr();function t(n){return n===n&&!e(n)}return Jy=t,Jy}var ew,AE;function rW(){if(AE)return ew;AE=1;var e=kI(),t=oo();function n(r){for(var s=t(r),l=s.length;l--;){var c=s[l],u=r[c];s[l]=[c,u,e(u)]}return s}return ew=n,ew}var tw,ME;function NI(){if(ME)return tw;ME=1;function e(t,n){return function(r){return r==null?!1:r[t]===n&&(n!==void 0||t in Object(r))}}return tw=e,tw}var nw,IE;function sW(){if(IE)return nw;IE=1;var e=nW(),t=rW(),n=NI();function r(s){var l=t(s);return l.length==1&&l[0][2]?n(l[0][0],l[0][1]):function(c){return c===s||e(c,s,l)}}return nw=r,nw}var rw,$E;function ac(){if($E)return rw;$E=1;var e=wi(),t=Us(),n="[object Symbol]";function r(s){return typeof s=="symbol"||t(s)&&e(s)==n}return rw=r,rw}var sw,OE;function nk(){if(OE)return sw;OE=1;var e=nn(),t=ac(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function s(l,c){if(e(l))return!1;var u=typeof l;return u=="number"||u=="symbol"||u=="boolean"||l==null||t(l)?!0:r.test(l)||!n.test(l)||c!=null&&l in Object(c)}return sw=s,sw}var aw,LE;function aW(){if(LE)return aw;LE=1;var e=Hb(),t="Expected a function";function n(r,s){if(typeof r!="function"||s!=null&&typeof s!="function")throw new TypeError(t);var l=function(){var c=arguments,u=s?s.apply(this,c):c[0],f=l.cache;if(f.has(u))return f.get(u);var p=r.apply(this,c);return l.cache=f.set(u,p)||f,p};return l.cache=new(n.Cache||e),l}return n.Cache=e,aw=n,aw}var ow,PE;function oW(){if(PE)return ow;PE=1;var e=aW(),t=500;function n(r){var s=e(r,function(c){return l.size===t&&l.clear(),c}),l=s.cache;return s}return ow=n,ow}var iw,DE;function iW(){if(DE)return iw;DE=1;var e=oW(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,n=/\\(\\)?/g,r=e(function(s){var l=[];return s.charCodeAt(0)===46&&l.push(""),s.replace(t,function(c,u,f,p){l.push(f?p.replace(n,"$1"):u||c)}),l});return iw=r,iw}var lw,FE;function Hf(){if(FE)return lw;FE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,l=Array(s);++r<s;)l[r]=n(t[r],r,t);return l}return lw=e,lw}var cw,qE;function lW(){if(qE)return cw;qE=1;var e=nc(),t=Hf(),n=nn(),r=ac(),s=e?e.prototype:void 0,l=s?s.toString:void 0;function c(u){if(typeof u=="string")return u;if(n(u))return t(u,c)+"";if(r(u))return l?l.call(u):"";var f=u+"";return f=="0"&&1/u==-1/0?"-0":f}return cw=c,cw}var uw,BE;function SI(){if(BE)return uw;BE=1;var e=lW();function t(n){return n==null?"":e(n)}return uw=t,uw}var dw,zE;function Wf(){if(zE)return dw;zE=1;var e=nn(),t=nk(),n=iW(),r=SI();function s(l,c){return e(l)?l:t(l,c)?[l]:n(r(l))}return dw=s,dw}var hw,UE;function Gu(){if(UE)return hw;UE=1;var e=ac();function t(n){if(typeof n=="string"||e(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}return hw=t,hw}var fw,HE;function Vf(){if(HE)return fw;HE=1;var e=Wf(),t=Gu();function n(r,s){s=e(s,r);for(var l=0,c=s.length;r!=null&&l<c;)r=r[t(s[l++])];return l&&l==c?r:void 0}return fw=n,fw}var pw,WE;function cW(){if(WE)return pw;WE=1;var e=Vf();function t(n,r,s){var l=n==null?void 0:e(n,r);return l===void 0?s:l}return pw=t,pw}var mw,VE;function uW(){if(VE)return mw;VE=1;function e(t,n){return t!=null&&n in Object(t)}return mw=e,mw}var gw,GE;function jI(){if(GE)return gw;GE=1;var e=Wf(),t=Wu(),n=nn(),r=Ff(),s=Vb(),l=Gu();function c(u,f,p){f=e(f,u);for(var h=-1,m=f.length,y=!1;++h<m;){var v=l(f[h]);if(!(y=u!=null&&p(u,v)))break;u=u[v]}return y||++h!=m?y:(m=u==null?0:u.length,!!m&&s(m)&&r(v,m)&&(n(u)||t(u)))}return gw=c,gw}var yw,KE;function _I(){if(KE)return yw;KE=1;var e=uW(),t=jI();function n(r,s){return r!=null&&t(r,s,e)}return yw=n,yw}var ww,YE;function dW(){if(YE)return ww;YE=1;var e=bI(),t=cW(),n=_I(),r=nk(),s=kI(),l=NI(),c=Gu(),u=1,f=2;function p(h,m){return r(h)&&s(m)?l(c(h),m):function(y){var v=t(y,h);return v===void 0&&v===m?n(y,h):e(m,v,u|f)}}return ww=p,ww}var vw,XE;function EI(){if(XE)return vw;XE=1;function e(t){return function(n){return n==null?void 0:n[t]}}return vw=e,vw}var xw,ZE;function hW(){if(ZE)return xw;ZE=1;var e=Vf();function t(n){return function(r){return e(r,n)}}return xw=t,xw}var bw,QE;function fW(){if(QE)return bw;QE=1;var e=EI(),t=hW(),n=nk(),r=Gu();function s(l){return n(l)?e(r(l)):t(l)}return bw=s,bw}var kw,JE;function ha(){if(JE)return kw;JE=1;var e=sW(),t=dW(),n=bi(),r=nn(),s=fW();function l(c){return typeof c=="function"?c:c==null?n:typeof c=="object"?r(c)?t(c[0],c[1]):e(c):s(c)}return kw=l,kw}var Nw,eC;function CI(){if(eC)return Nw;eC=1;var e=sI(),t=KH(),n=ha(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c,3))}return Nw=s,Nw}var Sw,tC;function pW(){if(tC)return Sw;tC=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r,s){return r!=null&&t.call(r,s)}return Sw=n,Sw}var jw,nC;function TI(){if(nC)return jw;nC=1;var e=pW(),t=jI();function n(r,s){return r!=null&&t(r,s,e)}return jw=n,jw}var _w,rC;function mW(){if(rC)return _w;rC=1;var e=Kb(),t=sc(),n=Wu(),r=nn(),s=da(),l=rc(),c=Bf(),u=Vu(),f="[object Map]",p="[object Set]",h=Object.prototype,m=h.hasOwnProperty;function y(v){if(v==null)return!0;if(s(v)&&(r(v)||typeof v=="string"||typeof v.splice=="function"||l(v)||u(v)||n(v)))return!v.length;var S=t(v);if(S==f||S==p)return!v.size;if(c(v))return!e(v).length;for(var b in v)if(m.call(v,b))return!1;return!0}return _w=y,_w}var Ew,sC;function RI(){if(sC)return Ew;sC=1;function e(t){return t===void 0}return Ew=e,Ew}var Cw,aC;function AI(){if(aC)return Cw;aC=1;var e=Uf(),t=da();function n(r,s){var l=-1,c=t(r)?Array(r.length):[];return e(r,function(u,f,p){c[++l]=s(u,f,p)}),c}return Cw=n,Cw}var Tw,oC;function MI(){if(oC)return Tw;oC=1;var e=Hf(),t=ha(),n=AI(),r=nn();function s(l,c){var u=r(l)?e:n;return u(l,t(c,3))}return Tw=s,Tw}var Rw,iC;function gW(){if(iC)return Rw;iC=1;function e(t,n,r,s){var l=-1,c=t==null?0:t.length;for(s&&c&&(r=t[++l]);++l<c;)r=n(r,t[l],l,t);return r}return Rw=e,Rw}var Aw,lC;function yW(){if(lC)return Aw;lC=1;function e(t,n,r,s,l){return l(t,function(c,u,f){r=s?(s=!1,c):n(r,c,u,f)}),r}return Aw=e,Aw}var Mw,cC;function II(){if(cC)return Mw;cC=1;var e=gW(),t=Uf(),n=ha(),r=yW(),s=nn();function l(c,u,f){var p=s(c)?e:r,h=arguments.length<3;return p(c,n(u,4),f,h,t)}return Mw=l,Mw}var Iw,uC;function wW(){if(uC)return Iw;uC=1;var e=wi(),t=nn(),n=Us(),r="[object String]";function s(l){return typeof l=="string"||!t(l)&&n(l)&&e(l)==r}return Iw=s,Iw}var $w,dC;function vW(){if(dC)return $w;dC=1;var e=EI(),t=e("length");return $w=t,$w}var Ow,hC;function xW(){if(hC)return Ow;hC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,l="\\ufe0e\\ufe0f",c="\\u200d",u=RegExp("["+c+e+s+l+"]");function f(p){return u.test(p)}return Ow=f,Ow}var Lw,fC;function bW(){if(fC)return Lw;fC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,l="\\ufe0e\\ufe0f",c="["+e+"]",u="["+s+"]",f="\\ud83c[\\udffb-\\udfff]",p="(?:"+u+"|"+f+")",h="[^"+e+"]",m="(?:\\ud83c[\\udde6-\\uddff]){2}",y="[\\ud800-\\udbff][\\udc00-\\udfff]",v="\\u200d",S=p+"?",b="["+l+"]?",_="(?:"+v+"(?:"+[h,m,y].join("|")+")"+b+S+")*",k=b+S+_,j="(?:"+[h+u+"?",u,m,y,c].join("|")+")",E=RegExp(f+"(?="+f+")|"+j+k,"g");function C(R){for(var I=E.lastIndex=0;E.test(R);)++I;return I}return Lw=C,Lw}var Pw,pC;function kW(){if(pC)return Pw;pC=1;var e=vW(),t=xW(),n=bW();function r(s){return t(s)?n(s):e(s)}return Pw=r,Pw}var Dw,mC;function NW(){if(mC)return Dw;mC=1;var e=Kb(),t=sc(),n=da(),r=wW(),s=kW(),l="[object Map]",c="[object Set]";function u(f){if(f==null)return 0;if(n(f))return r(f)?s(f):f.length;var p=t(f);return p==l||p==c?f.size:e(f).length}return Dw=u,Dw}var Fw,gC;function SW(){if(gC)return Fw;gC=1;var e=Wb(),t=hI(),n=ek(),r=ha(),s=zf(),l=nn(),c=rc(),u=Uu(),f=zr(),p=Vu();function h(m,y,v){var S=l(m),b=S||c(m)||p(m);if(y=r(y,4),v==null){var _=m&&m.constructor;b?v=S?new _:[]:f(m)?v=u(_)?t(s(m)):{}:v={}}return(b?e:n)(m,function(k,j,E){return y(v,k,j,E)}),v}return Fw=h,Fw}var qw,yC;function jW(){if(yC)return qw;yC=1;var e=nc(),t=Wu(),n=nn(),r=e?e.isConcatSpreadable:void 0;function s(l){return n(l)||t(l)||!!(r&&l&&l[r])}return qw=s,qw}var Bw,wC;function rk(){if(wC)return Bw;wC=1;var e=Xb(),t=jW();function n(r,s,l,c,u){var f=-1,p=r.length;for(l||(l=t),u||(u=[]);++f<p;){var h=r[f];s>0&&l(h)?s>1?n(h,s-1,l,c,u):e(u,h):c||(u[u.length]=h)}return u}return Bw=n,Bw}var zw,vC;function _W(){if(vC)return zw;vC=1;function e(t,n,r){switch(r.length){case 0:return t.call(n);case 1:return t.call(n,r[0]);case 2:return t.call(n,r[0],r[1]);case 3:return t.call(n,r[0],r[1],r[2])}return t.apply(n,r)}return zw=e,zw}var Uw,xC;function $I(){if(xC)return Uw;xC=1;var e=_W(),t=Math.max;function n(r,s,l){return s=t(s===void 0?r.length-1:s,0),function(){for(var c=arguments,u=-1,f=t(c.length-s,0),p=Array(f);++u<f;)p[u]=c[s+u];u=-1;for(var h=Array(s+1);++u<s;)h[u]=c[u];return h[s]=l(p),e(r,this,h)}}return Uw=n,Uw}var Hw,bC;function EW(){if(bC)return Hw;bC=1;var e=Qb(),t=JM(),n=bi(),r=t?function(s,l){return t(s,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:n;return Hw=r,Hw}var Ww,kC;function CW(){if(kC)return Ww;kC=1;var e=800,t=16,n=Date.now;function r(s){var l=0,c=0;return function(){var u=n(),f=t-(u-c);if(c=u,f>0){if(++l>=e)return arguments[0]}else l=0;return s.apply(void 0,arguments)}}return Ww=r,Ww}var Vw,NC;function OI(){if(NC)return Vw;NC=1;var e=EW(),t=CW(),n=t(e);return Vw=n,Vw}var Gw,SC;function Gf(){if(SC)return Gw;SC=1;var e=bi(),t=$I(),n=OI();function r(s,l){return n(t(s,l,e),s+"")}return Gw=r,Gw}var Kw,jC;function LI(){if(jC)return Kw;jC=1;function e(t,n,r,s){for(var l=t.length,c=r+(s?1:-1);s?c--:++c<l;)if(n(t[c],c,t))return c;return-1}return Kw=e,Kw}var Yw,_C;function TW(){if(_C)return Yw;_C=1;function e(t){return t!==t}return Yw=e,Yw}var Xw,EC;function RW(){if(EC)return Xw;EC=1;function e(t,n,r){for(var s=r-1,l=t.length;++s<l;)if(t[s]===n)return s;return-1}return Xw=e,Xw}var Zw,CC;function AW(){if(CC)return Zw;CC=1;var e=LI(),t=TW(),n=RW();function r(s,l,c){return l===l?n(s,l,c):e(s,t,c)}return Zw=r,Zw}var Qw,TC;function MW(){if(TC)return Qw;TC=1;var e=AW();function t(n,r){var s=n==null?0:n.length;return!!s&&e(n,r,0)>-1}return Qw=t,Qw}var Jw,RC;function IW(){if(RC)return Jw;RC=1;function e(t,n,r){for(var s=-1,l=t==null?0:t.length;++s<l;)if(r(n,t[s]))return!0;return!1}return Jw=e,Jw}var ev,AC;function $W(){if(AC)return ev;AC=1;function e(){}return ev=e,ev}var tv,MC;function OW(){if(MC)return tv;MC=1;var e=cI(),t=$W(),n=tk(),r=1/0,s=e&&1/n(new e([,-0]))[1]==r?function(l){return new e(l)}:t;return tv=s,tv}var nv,IC;function LW(){if(IC)return nv;IC=1;var e=wI(),t=MW(),n=IW(),r=vI(),s=OW(),l=tk(),c=200;function u(f,p,h){var m=-1,y=t,v=f.length,S=!0,b=[],_=b;if(h)S=!1,y=n;else if(v>=c){var k=p?null:s(f);if(k)return l(k);S=!1,y=r,_=new e}else _=p?[]:b;e:for(;++m<v;){var j=f[m],E=p?p(j):j;if(j=h||j!==0?j:0,S&&E===E){for(var C=_.length;C--;)if(_[C]===E)continue e;p&&_.push(E),b.push(j)}else y(_,E,h)||(_!==b&&_.push(E),b.push(j))}return b}return nv=u,nv}var rv,$C;function PI(){if($C)return rv;$C=1;var e=da(),t=Us();function n(r){return t(r)&&e(r)}return rv=n,rv}var sv,OC;function PW(){if(OC)return sv;OC=1;var e=rk(),t=Gf(),n=LW(),r=PI(),s=t(function(l){return n(e(l,1,r,!0))});return sv=s,sv}var av,LC;function DW(){if(LC)return av;LC=1;var e=Hf();function t(n,r){return e(r,function(s){return n[s]})}return av=t,av}var ov,PC;function DI(){if(PC)return ov;PC=1;var e=DW(),t=oo();function n(r){return r==null?[]:e(r,t(r))}return ov=n,ov}var iv,DC;function Ur(){if(DC)return iv;DC=1;var e;if(typeof zb=="function")try{e={clone:WH(),constant:Qb(),each:yI(),filter:CI(),has:TI(),isArray:nn(),isEmpty:mW(),isFunction:Uu(),isUndefined:RI(),keys:oo(),map:MI(),reduce:II(),size:NW(),transform:SW(),union:PW(),values:DI()}}catch{}return e||(e=window._),iv=e,iv}var lv,FC;function sk(){if(FC)return lv;FC=1;var e=Ur();lv=s;var t="\0",n="\0",r="";function s(h){this._isDirected=e.has(h,"directed")?h.directed:!0,this._isMultigraph=e.has(h,"multigraph")?h.multigraph:!1,this._isCompound=e.has(h,"compound")?h.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[n]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}s.prototype._nodeCount=0,s.prototype._edgeCount=0,s.prototype.isDirected=function(){return this._isDirected},s.prototype.isMultigraph=function(){return this._isMultigraph},s.prototype.isCompound=function(){return this._isCompound},s.prototype.setGraph=function(h){return this._label=h,this},s.prototype.graph=function(){return this._label},s.prototype.setDefaultNodeLabel=function(h){return e.isFunction(h)||(h=e.constant(h)),this._defaultNodeLabelFn=h,this},s.prototype.nodeCount=function(){return this._nodeCount},s.prototype.nodes=function(){return e.keys(this._nodes)},s.prototype.sources=function(){var h=this;return e.filter(this.nodes(),function(m){return e.isEmpty(h._in[m])})},s.prototype.sinks=function(){var h=this;return e.filter(this.nodes(),function(m){return e.isEmpty(h._out[m])})},s.prototype.setNodes=function(h,m){var y=arguments,v=this;return e.each(h,function(S){y.length>1?v.setNode(S,m):v.setNode(S)}),this},s.prototype.setNode=function(h,m){return e.has(this._nodes,h)?(arguments.length>1&&(this._nodes[h]=m),this):(this._nodes[h]=arguments.length>1?m:this._defaultNodeLabelFn(h),this._isCompound&&(this._parent[h]=n,this._children[h]={},this._children[n][h]=!0),this._in[h]={},this._preds[h]={},this._out[h]={},this._sucs[h]={},++this._nodeCount,this)},s.prototype.node=function(h){return this._nodes[h]},s.prototype.hasNode=function(h){return e.has(this._nodes,h)},s.prototype.removeNode=function(h){var m=this;if(e.has(this._nodes,h)){var y=function(v){m.removeEdge(m._edgeObjs[v])};delete this._nodes[h],this._isCompound&&(this._removeFromParentsChildList(h),delete this._parent[h],e.each(this.children(h),function(v){m.setParent(v)}),delete this._children[h]),e.each(e.keys(this._in[h]),y),delete this._in[h],delete this._preds[h],e.each(e.keys(this._out[h]),y),delete this._out[h],delete this._sucs[h],--this._nodeCount}return this},s.prototype.setParent=function(h,m){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(m))m=n;else{m+="";for(var y=m;!e.isUndefined(y);y=this.parent(y))if(y===h)throw new Error("Setting "+m+" as parent of "+h+" would create a cycle");this.setNode(m)}return this.setNode(h),this._removeFromParentsChildList(h),this._parent[h]=m,this._children[m][h]=!0,this},s.prototype._removeFromParentsChildList=function(h){delete this._children[this._parent[h]][h]},s.prototype.parent=function(h){if(this._isCompound){var m=this._parent[h];if(m!==n)return m}},s.prototype.children=function(h){if(e.isUndefined(h)&&(h=n),this._isCompound){var m=this._children[h];if(m)return e.keys(m)}else{if(h===n)return this.nodes();if(this.hasNode(h))return[]}},s.prototype.predecessors=function(h){var m=this._preds[h];if(m)return e.keys(m)},s.prototype.successors=function(h){var m=this._sucs[h];if(m)return e.keys(m)},s.prototype.neighbors=function(h){var m=this.predecessors(h);if(m)return e.union(m,this.successors(h))},s.prototype.isLeaf=function(h){var m;return this.isDirected()?m=this.successors(h):m=this.neighbors(h),m.length===0},s.prototype.filterNodes=function(h){var m=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});m.setGraph(this.graph());var y=this;e.each(this._nodes,function(b,_){h(_)&&m.setNode(_,b)}),e.each(this._edgeObjs,function(b){m.hasNode(b.v)&&m.hasNode(b.w)&&m.setEdge(b,y.edge(b))});var v={};function S(b){var _=y.parent(b);return _===void 0||m.hasNode(_)?(v[b]=_,_):_ in v?v[_]:S(_)}return this._isCompound&&e.each(m.nodes(),function(b){m.setParent(b,S(b))}),m},s.prototype.setDefaultEdgeLabel=function(h){return e.isFunction(h)||(h=e.constant(h)),this._defaultEdgeLabelFn=h,this},s.prototype.edgeCount=function(){return this._edgeCount},s.prototype.edges=function(){return e.values(this._edgeObjs)},s.prototype.setPath=function(h,m){var y=this,v=arguments;return e.reduce(h,function(S,b){return v.length>1?y.setEdge(S,b,m):y.setEdge(S,b),b}),this},s.prototype.setEdge=function(){var h,m,y,v,S=!1,b=arguments[0];typeof b=="object"&&b!==null&&"v"in b?(h=b.v,m=b.w,y=b.name,arguments.length===2&&(v=arguments[1],S=!0)):(h=b,m=arguments[1],y=arguments[3],arguments.length>2&&(v=arguments[2],S=!0)),h=""+h,m=""+m,e.isUndefined(y)||(y=""+y);var _=u(this._isDirected,h,m,y);if(e.has(this._edgeLabels,_))return S&&(this._edgeLabels[_]=v),this;if(!e.isUndefined(y)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(h),this.setNode(m),this._edgeLabels[_]=S?v:this._defaultEdgeLabelFn(h,m,y);var k=f(this._isDirected,h,m,y);return h=k.v,m=k.w,Object.freeze(k),this._edgeObjs[_]=k,l(this._preds[m],h),l(this._sucs[h],m),this._in[m][_]=k,this._out[h][_]=k,this._edgeCount++,this},s.prototype.edge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y);return this._edgeLabels[v]},s.prototype.hasEdge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y);return e.has(this._edgeLabels,v)},s.prototype.removeEdge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y),S=this._edgeObjs[v];return S&&(h=S.v,m=S.w,delete this._edgeLabels[v],delete this._edgeObjs[v],c(this._preds[m],h),c(this._sucs[h],m),delete this._in[m][v],delete this._out[h][v],this._edgeCount--),this},s.prototype.inEdges=function(h,m){var y=this._in[h];if(y){var v=e.values(y);return m?e.filter(v,function(S){return S.v===m}):v}},s.prototype.outEdges=function(h,m){var y=this._out[h];if(y){var v=e.values(y);return m?e.filter(v,function(S){return S.w===m}):v}},s.prototype.nodeEdges=function(h,m){var y=this.inEdges(h,m);if(y)return y.concat(this.outEdges(h,m))};function l(h,m){h[m]?h[m]++:h[m]=1}function c(h,m){--h[m]||delete h[m]}function u(h,m,y,v){var S=""+m,b=""+y;if(!h&&S>b){var _=S;S=b,b=_}return S+r+b+r+(e.isUndefined(v)?t:v)}function f(h,m,y,v){var S=""+m,b=""+y;if(!h&&S>b){var _=S;S=b,b=_}var k={v:S,w:b};return v&&(k.name=v),k}function p(h,m){return u(h,m.v,m.w,m.name)}return lv}var cv,qC;function FW(){return qC||(qC=1,cv="2.1.8"),cv}var uv,BC;function qW(){return BC||(BC=1,uv={Graph:sk(),version:FW()}),uv}var dv,zC;function BW(){if(zC)return dv;zC=1;var e=Ur(),t=sk();dv={write:n,read:l};function n(c){var u={options:{directed:c.isDirected(),multigraph:c.isMultigraph(),compound:c.isCompound()},nodes:r(c),edges:s(c)};return e.isUndefined(c.graph())||(u.value=e.clone(c.graph())),u}function r(c){return e.map(c.nodes(),function(u){var f=c.node(u),p=c.parent(u),h={v:u};return e.isUndefined(f)||(h.value=f),e.isUndefined(p)||(h.parent=p),h})}function s(c){return e.map(c.edges(),function(u){var f=c.edge(u),p={v:u.v,w:u.w};return e.isUndefined(u.name)||(p.name=u.name),e.isUndefined(f)||(p.value=f),p})}function l(c){var u=new t(c.options).setGraph(c.value);return e.each(c.nodes,function(f){u.setNode(f.v,f.value),f.parent&&u.setParent(f.v,f.parent)}),e.each(c.edges,function(f){u.setEdge({v:f.v,w:f.w,name:f.name},f.value)}),u}return dv}var hv,UC;function zW(){if(UC)return hv;UC=1;var e=Ur();hv=t;function t(n){var r={},s=[],l;function c(u){e.has(r,u)||(r[u]=!0,l.push(u),e.each(n.successors(u),c),e.each(n.predecessors(u),c))}return e.each(n.nodes(),function(u){l=[],c(u),l.length&&s.push(l)}),s}return hv}var fv,HC;function FI(){if(HC)return fv;HC=1;var e=Ur();fv=t;function t(){this._arr=[],this._keyIndices={}}return t.prototype.size=function(){return this._arr.length},t.prototype.keys=function(){return this._arr.map(function(n){return n.key})},t.prototype.has=function(n){return e.has(this._keyIndices,n)},t.prototype.priority=function(n){var r=this._keyIndices[n];if(r!==void 0)return this._arr[r].priority},t.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},t.prototype.add=function(n,r){var s=this._keyIndices;if(n=String(n),!e.has(s,n)){var l=this._arr,c=l.length;return s[n]=c,l.push({key:n,priority:r}),this._decrease(c),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var n=this._arr.pop();return delete this._keyIndices[n.key],this._heapify(0),n.key},t.prototype.decrease=function(n,r){var s=this._keyIndices[n];if(r>this._arr[s].priority)throw new Error("New priority is greater than current priority. Key: "+n+" Old: "+this._arr[s].priority+" New: "+r);this._arr[s].priority=r,this._decrease(s)},t.prototype._heapify=function(n){var r=this._arr,s=2*n,l=s+1,c=n;s<r.length&&(c=r[s].priority<r[c].priority?s:c,l<r.length&&(c=r[l].priority<r[c].priority?l:c),c!==n&&(this._swap(n,c),this._heapify(c)))},t.prototype._decrease=function(n){for(var r=this._arr,s=r[n].priority,l;n!==0&&(l=n>>1,!(r[l].priority<s));)this._swap(n,l),n=l},t.prototype._swap=function(n,r){var s=this._arr,l=this._keyIndices,c=s[n],u=s[r];s[n]=u,s[r]=c,l[u.key]=n,l[c.key]=r},fv}var pv,WC;function qI(){if(WC)return pv;WC=1;var e=Ur(),t=FI();pv=r;var n=e.constant(1);function r(l,c,u,f){return s(l,String(c),u||n,f||function(p){return l.outEdges(p)})}function s(l,c,u,f){var p={},h=new t,m,y,v=function(S){var b=S.v!==m?S.v:S.w,_=p[b],k=u(S),j=y.distance+k;if(k<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+S+" Weight: "+k);j<_.distance&&(_.distance=j,_.predecessor=m,h.decrease(b,j))};for(l.nodes().forEach(function(S){var b=S===c?0:Number.POSITIVE_INFINITY;p[S]={distance:b},h.add(S,b)});h.size()>0&&(m=h.removeMin(),y=p[m],y.distance!==Number.POSITIVE_INFINITY);)f(m).forEach(v);return p}return pv}var mv,VC;function UW(){if(VC)return mv;VC=1;var e=qI(),t=Ur();mv=n;function n(r,s,l){return t.transform(r.nodes(),function(c,u){c[u]=e(r,u,s,l)},{})}return mv}var gv,GC;function BI(){if(GC)return gv;GC=1;var e=Ur();gv=t;function t(n){var r=0,s=[],l={},c=[];function u(f){var p=l[f]={onStack:!0,lowlink:r,index:r++};if(s.push(f),n.successors(f).forEach(function(y){e.has(l,y)?l[y].onStack&&(p.lowlink=Math.min(p.lowlink,l[y].index)):(u(y),p.lowlink=Math.min(p.lowlink,l[y].lowlink))}),p.lowlink===p.index){var h=[],m;do m=s.pop(),l[m].onStack=!1,h.push(m);while(f!==m);c.push(h)}}return n.nodes().forEach(function(f){e.has(l,f)||u(f)}),c}return gv}var yv,KC;function HW(){if(KC)return yv;KC=1;var e=Ur(),t=BI();yv=n;function n(r){return e.filter(t(r),function(s){return s.length>1||s.length===1&&r.hasEdge(s[0],s[0])})}return yv}var wv,YC;function WW(){if(YC)return wv;YC=1;var e=Ur();wv=n;var t=e.constant(1);function n(s,l,c){return r(s,l||t,c||function(u){return s.outEdges(u)})}function r(s,l,c){var u={},f=s.nodes();return f.forEach(function(p){u[p]={},u[p][p]={distance:0},f.forEach(function(h){p!==h&&(u[p][h]={distance:Number.POSITIVE_INFINITY})}),c(p).forEach(function(h){var m=h.v===p?h.w:h.v,y=l(h);u[p][m]={distance:y,predecessor:p}})}),f.forEach(function(p){var h=u[p];f.forEach(function(m){var y=u[m];f.forEach(function(v){var S=y[p],b=h[v],_=y[v],k=S.distance+b.distance;k<_.distance&&(_.distance=k,_.predecessor=b.predecessor)})})}),u}return wv}var vv,XC;function zI(){if(XC)return vv;XC=1;var e=Ur();vv=t,t.CycleException=n;function t(r){var s={},l={},c=[];function u(f){if(e.has(l,f))throw new n;e.has(s,f)||(l[f]=!0,s[f]=!0,e.each(r.predecessors(f),u),delete l[f],c.push(f))}if(e.each(r.sinks(),u),e.size(s)!==r.nodeCount())throw new n;return c}function n(){}return n.prototype=new Error,vv}var xv,ZC;function VW(){if(ZC)return xv;ZC=1;var e=zI();xv=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return xv}var bv,QC;function UI(){if(QC)return bv;QC=1;var e=Ur();bv=t;function t(r,s,l){e.isArray(s)||(s=[s]);var c=(r.isDirected()?r.successors:r.neighbors).bind(r),u=[],f={};return e.each(s,function(p){if(!r.hasNode(p))throw new Error("Graph does not have node: "+p);n(r,p,l==="post",f,c,u)}),u}function n(r,s,l,c,u,f){e.has(c,s)||(c[s]=!0,l||f.push(s),e.each(u(s),function(p){n(r,p,l,c,u,f)}),l&&f.push(s))}return bv}var kv,JC;function GW(){if(JC)return kv;JC=1;var e=UI();kv=t;function t(n,r){return e(n,r,"post")}return kv}var Nv,eT;function KW(){if(eT)return Nv;eT=1;var e=UI();Nv=t;function t(n,r){return e(n,r,"pre")}return Nv}var Sv,tT;function YW(){if(tT)return Sv;tT=1;var e=Ur(),t=sk(),n=FI();Sv=r;function r(s,l){var c=new t,u={},f=new n,p;function h(y){var v=y.v===p?y.w:y.v,S=f.priority(v);if(S!==void 0){var b=l(y);b<S&&(u[v]=p,f.decrease(v,b))}}if(s.nodeCount()===0)return c;e.each(s.nodes(),function(y){f.add(y,Number.POSITIVE_INFINITY),c.setNode(y)}),f.decrease(s.nodes()[0],0);for(var m=!1;f.size()>0;){if(p=f.removeMin(),e.has(u,p))c.setEdge(p,u[p]);else{if(m)throw new Error("Input graph is not connected: "+s);m=!0}s.nodeEdges(p).forEach(h)}return c}return Sv}var jv,nT;function XW(){return nT||(nT=1,jv={components:zW(),dijkstra:qI(),dijkstraAll:UW(),findCycles:HW(),floydWarshall:WW(),isAcyclic:VW(),postorder:GW(),preorder:KW(),prim:YW(),tarjan:BI(),topsort:zI()}),jv}var _v,rT;function ZW(){if(rT)return _v;rT=1;var e=qW();return _v={Graph:e.Graph,json:BW(),alg:XW(),version:e.version},_v}var Ev,sT;function vs(){if(sT)return Ev;sT=1;var e;if(typeof zb=="function")try{e=ZW()}catch{}return e||(e=window.graphlib),Ev=e,Ev}var Cv,aT;function QW(){if(aT)return Cv;aT=1;var e=pI(),t=1,n=4;function r(s){return e(s,t|n)}return Cv=r,Cv}var Tv,oT;function Kf(){if(oT)return Tv;oT=1;var e=tc(),t=da(),n=Ff(),r=zr();function s(l,c,u){if(!r(u))return!1;var f=typeof c;return(f=="number"?t(u)&&n(c,u.length):f=="string"&&c in u)?e(u[c],l):!1}return Tv=s,Tv}var Rv,iT;function JW(){if(iT)return Rv;iT=1;var e=Gf(),t=tc(),n=Kf(),r=xi(),s=Object.prototype,l=s.hasOwnProperty,c=e(function(u,f){u=Object(u);var p=-1,h=f.length,m=h>2?f[2]:void 0;for(m&&n(f[0],f[1],m)&&(h=1);++p<h;)for(var y=f[p],v=r(y),S=-1,b=v.length;++S<b;){var _=v[S],k=u[_];(k===void 0||t(k,s[_])&&!l.call(u,_))&&(u[_]=y[_])}return u});return Rv=c,Rv}var Av,lT;function e7(){if(lT)return Av;lT=1;var e=ha(),t=da(),n=oo();function r(s){return function(l,c,u){var f=Object(l);if(!t(l)){var p=e(c,3);l=n(l),c=function(m){return p(f[m],m,f)}}var h=s(l,c,u);return h>-1?f[p?l[h]:h]:void 0}}return Av=r,Av}var Mv,cT;function t7(){if(cT)return Mv;cT=1;var e=/\s/;function t(n){for(var r=n.length;r--&&e.test(n.charAt(r)););return r}return Mv=t,Mv}var Iv,uT;function n7(){if(uT)return Iv;uT=1;var e=t7(),t=/^\s+/;function n(r){return r&&r.slice(0,e(r)+1).replace(t,"")}return Iv=n,Iv}var $v,dT;function r7(){if(dT)return $v;dT=1;var e=n7(),t=zr(),n=ac(),r=NaN,s=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,c=/^0o[0-7]+$/i,u=parseInt;function f(p){if(typeof p=="number")return p;if(n(p))return r;if(t(p)){var h=typeof p.valueOf=="function"?p.valueOf():p;p=t(h)?h+"":h}if(typeof p!="string")return p===0?p:+p;p=e(p);var m=l.test(p);return m||c.test(p)?u(p.slice(2),m?2:8):s.test(p)?r:+p}return $v=f,$v}var Ov,hT;function HI(){if(hT)return Ov;hT=1;var e=r7(),t=1/0,n=17976931348623157e292;function r(s){if(!s)return s===0?s:0;if(s=e(s),s===t||s===-t){var l=s<0?-1:1;return l*n}return s===s?s:0}return Ov=r,Ov}var Lv,fT;function s7(){if(fT)return Lv;fT=1;var e=HI();function t(n){var r=e(n),s=r%1;return r===r?s?r-s:r:0}return Lv=t,Lv}var Pv,pT;function a7(){if(pT)return Pv;pT=1;var e=LI(),t=ha(),n=s7(),r=Math.max;function s(l,c,u){var f=l==null?0:l.length;if(!f)return-1;var p=u==null?0:n(u);return p<0&&(p=r(f+p,0)),e(l,t(c,3),p)}return Pv=s,Pv}var Dv,mT;function o7(){if(mT)return Dv;mT=1;var e=e7(),t=a7(),n=e(t);return Dv=n,Dv}var Fv,gT;function WI(){if(gT)return Fv;gT=1;var e=rk();function t(n){var r=n==null?0:n.length;return r?e(n,1):[]}return Fv=t,Fv}var qv,yT;function i7(){if(yT)return qv;yT=1;var e=Jb(),t=mI(),n=xi();function r(s,l){return s==null?s:e(s,t(l),n)}return qv=r,qv}var Bv,wT;function l7(){if(wT)return Bv;wT=1;function e(t){var n=t==null?0:t.length;return n?t[n-1]:void 0}return Bv=e,Bv}var zv,vT;function c7(){if(vT)return zv;vT=1;var e=Pf(),t=ek(),n=ha();function r(s,l){var c={};return l=n(l,3),t(s,function(u,f,p){e(c,f,l(u,f,p))}),c}return zv=r,zv}var Uv,xT;function ak(){if(xT)return Uv;xT=1;var e=ac();function t(n,r,s){for(var l=-1,c=n.length;++l<c;){var u=n[l],f=r(u);if(f!=null&&(p===void 0?f===f&&!e(f):s(f,p)))var p=f,h=u}return h}return Uv=t,Uv}var Hv,bT;function u7(){if(bT)return Hv;bT=1;function e(t,n){return t>n}return Hv=e,Hv}var Wv,kT;function d7(){if(kT)return Wv;kT=1;var e=ak(),t=u7(),n=bi();function r(s){return s&&s.length?e(s,n,t):void 0}return Wv=r,Wv}var Vv,NT;function VI(){if(NT)return Vv;NT=1;var e=Pf(),t=tc();function n(r,s,l){(l!==void 0&&!t(r[s],l)||l===void 0&&!(s in r))&&e(r,s,l)}return Vv=n,Vv}var Gv,ST;function h7(){if(ST)return Gv;ST=1;var e=wi(),t=zf(),n=Us(),r="[object Object]",s=Function.prototype,l=Object.prototype,c=s.toString,u=l.hasOwnProperty,f=c.call(Object);function p(h){if(!n(h)||e(h)!=r)return!1;var m=t(h);if(m===null)return!0;var y=u.call(m,"constructor")&&m.constructor;return typeof y=="function"&&y instanceof y&&c.call(y)==f}return Gv=p,Gv}var Kv,jT;function GI(){if(jT)return Kv;jT=1;function e(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}return Kv=e,Kv}var Yv,_T;function f7(){if(_T)return Yv;_T=1;var e=Hu(),t=xi();function n(r){return e(r,t(r))}return Yv=n,Yv}var Xv,ET;function p7(){if(ET)return Xv;ET=1;var e=VI(),t=nI(),n=dI(),r=rI(),s=fI(),l=Wu(),c=nn(),u=PI(),f=rc(),p=Uu(),h=zr(),m=h7(),y=Vu(),v=GI(),S=f7();function b(_,k,j,E,C,R,I){var O=v(_,j),H=v(k,j),q=I.get(H);if(q){e(_,j,q);return}var $=R?R(O,H,j+"",_,k,I):void 0,V=$===void 0;if(V){var ne=c(H),ee=!ne&&f(H),M=!ne&&!ee&&y(H);$=H,ne||ee||M?c(O)?$=O:u(O)?$=r(O):ee?(V=!1,$=t(H,!0)):M?(V=!1,$=n(H,!0)):$=[]:m(H)||l(H)?($=O,l(O)?$=S(O):(!h(O)||p(O))&&($=s(H))):V=!1}V&&(I.set(H,$),C($,H,E,R,I),I.delete(H)),e(_,j,$)}return Xv=b,Xv}var Zv,CT;function m7(){if(CT)return Zv;CT=1;var e=Lf(),t=VI(),n=Jb(),r=p7(),s=zr(),l=xi(),c=GI();function u(f,p,h,m,y){f!==p&&n(p,function(v,S){if(y||(y=new e),s(v))r(f,p,S,h,u,m,y);else{var b=m?m(c(f,S),v,S+"",f,p,y):void 0;b===void 0&&(b=v),t(f,S,b)}},l)}return Zv=u,Zv}var Qv,TT;function g7(){if(TT)return Qv;TT=1;var e=Gf(),t=Kf();function n(r){return e(function(s,l){var c=-1,u=l.length,f=u>1?l[u-1]:void 0,p=u>2?l[2]:void 0;for(f=r.length>3&&typeof f=="function"?(u--,f):void 0,p&&t(l[0],l[1],p)&&(f=u<3?void 0:f,u=1),s=Object(s);++c<u;){var h=l[c];h&&r(s,h,c,f)}return s})}return Qv=n,Qv}var Jv,RT;function y7(){if(RT)return Jv;RT=1;var e=m7(),t=g7(),n=t(function(r,s,l){e(r,s,l)});return Jv=n,Jv}var ex,AT;function KI(){if(AT)return ex;AT=1;function e(t,n){return t<n}return ex=e,ex}var tx,MT;function w7(){if(MT)return tx;MT=1;var e=ak(),t=KI(),n=bi();function r(s){return s&&s.length?e(s,n,t):void 0}return tx=r,tx}var nx,IT;function v7(){if(IT)return nx;IT=1;var e=ak(),t=ha(),n=KI();function r(s,l){return s&&s.length?e(s,t(l,2),n):void 0}return nx=r,nx}var rx,$T;function x7(){if($T)return rx;$T=1;var e=bs(),t=function(){return e.Date.now()};return rx=t,rx}var sx,OT;function b7(){if(OT)return sx;OT=1;var e=Df(),t=Wf(),n=Ff(),r=zr(),s=Gu();function l(c,u,f,p){if(!r(c))return c;u=t(u,c);for(var h=-1,m=u.length,y=m-1,v=c;v!=null&&++h<m;){var S=s(u[h]),b=f;if(S==="__proto__"||S==="constructor"||S==="prototype")return c;if(h!=y){var _=v[S];b=p?p(_,S,v):void 0,b===void 0&&(b=r(_)?_:n(u[h+1])?[]:{})}e(v,S,b),v=v[S]}return c}return sx=l,sx}var ax,LT;function k7(){if(LT)return ax;LT=1;var e=Vf(),t=b7(),n=Wf();function r(s,l,c){for(var u=-1,f=l.length,p={};++u<f;){var h=l[u],m=e(s,h);c(m,h)&&t(p,n(h,s),m)}return p}return ax=r,ax}var ox,PT;function N7(){if(PT)return ox;PT=1;var e=k7(),t=_I();function n(r,s){return e(r,s,function(l,c){return t(r,c)})}return ox=n,ox}var ix,DT;function S7(){if(DT)return ix;DT=1;var e=WI(),t=$I(),n=OI();function r(s){return n(t(s,void 0,e),s+"")}return ix=r,ix}var lx,FT;function j7(){if(FT)return lx;FT=1;var e=N7(),t=S7(),n=t(function(r,s){return r==null?{}:e(r,s)});return lx=n,lx}var cx,qT;function _7(){if(qT)return cx;qT=1;var e=Math.ceil,t=Math.max;function n(r,s,l,c){for(var u=-1,f=t(e((s-r)/(l||1)),0),p=Array(f);f--;)p[c?f:++u]=r,r+=l;return p}return cx=n,cx}var ux,BT;function E7(){if(BT)return ux;BT=1;var e=_7(),t=Kf(),n=HI();function r(s){return function(l,c,u){return u&&typeof u!="number"&&t(l,c,u)&&(c=u=void 0),l=n(l),c===void 0?(c=l,l=0):c=n(c),u=u===void 0?l<c?1:-1:n(u),e(l,c,u,s)}}return ux=r,ux}var dx,zT;function C7(){if(zT)return dx;zT=1;var e=E7(),t=e();return dx=t,dx}var hx,UT;function T7(){if(UT)return hx;UT=1;function e(t,n){var r=t.length;for(t.sort(n);r--;)t[r]=t[r].value;return t}return hx=e,hx}var fx,HT;function R7(){if(HT)return fx;HT=1;var e=ac();function t(n,r){if(n!==r){var s=n!==void 0,l=n===null,c=n===n,u=e(n),f=r!==void 0,p=r===null,h=r===r,m=e(r);if(!p&&!m&&!u&&n>r||u&&f&&h&&!p&&!m||l&&f&&h||!s&&h||!c)return 1;if(!l&&!u&&!m&&n<r||m&&s&&c&&!l&&!u||p&&s&&c||!f&&c||!h)return-1}return 0}return fx=t,fx}var px,WT;function A7(){if(WT)return px;WT=1;var e=R7();function t(n,r,s){for(var l=-1,c=n.criteria,u=r.criteria,f=c.length,p=s.length;++l<f;){var h=e(c[l],u[l]);if(h){if(l>=p)return h;var m=s[l];return h*(m=="desc"?-1:1)}}return n.index-r.index}return px=t,px}var mx,VT;function M7(){if(VT)return mx;VT=1;var e=Hf(),t=Vf(),n=ha(),r=AI(),s=T7(),l=qf(),c=A7(),u=bi(),f=nn();function p(h,m,y){m.length?m=e(m,function(b){return f(b)?function(_){return t(_,b.length===1?b[0]:b)}:b}):m=[u];var v=-1;m=e(m,l(n));var S=r(h,function(b,_,k){var j=e(m,function(E){return E(b)});return{criteria:j,index:++v,value:b}});return s(S,function(b,_){return c(b,_,y)})}return mx=p,mx}var gx,GT;function I7(){if(GT)return gx;GT=1;var e=rk(),t=M7(),n=Gf(),r=Kf(),s=n(function(l,c){if(l==null)return[];var u=c.length;return u>1&&r(l,c[0],c[1])?c=[]:u>2&&r(c[0],c[1],c[2])&&(c=[c[0]]),t(l,e(c,1),[])});return gx=s,gx}var yx,KT;function $7(){if(KT)return yx;KT=1;var e=SI(),t=0;function n(r){var s=++t;return e(r)+s}return yx=n,yx}var wx,YT;function O7(){if(YT)return wx;YT=1;function e(t,n,r){for(var s=-1,l=t.length,c=n.length,u={};++s<l;){var f=s<c?n[s]:void 0;r(u,t[s],f)}return u}return wx=e,wx}var vx,XT;function L7(){if(XT)return vx;XT=1;var e=Df(),t=O7();function n(r,s){return t(r||[],s||[],e)}return vx=n,vx}var xx,ZT;function Pt(){if(ZT)return xx;ZT=1;var e;if(typeof zb=="function")try{e={cloneDeep:QW(),constant:Qb(),defaults:JW(),each:yI(),filter:CI(),find:o7(),flatten:WI(),forEach:gI(),forIn:i7(),has:TI(),isUndefined:RI(),last:l7(),map:MI(),mapValues:c7(),max:d7(),merge:y7(),min:w7(),minBy:v7(),now:x7(),pick:j7(),range:C7(),reduce:II(),sortBy:I7(),uniqueId:$7(),values:DI(),zipObject:L7()}}catch{}return e||(e=window._),xx=e,xx}var bx,QT;function P7(){if(QT)return bx;QT=1,bx=e;function e(){var r={};r._next=r._prev=r,this._sentinel=r}e.prototype.dequeue=function(){var r=this._sentinel,s=r._prev;if(s!==r)return t(s),s},e.prototype.enqueue=function(r){var s=this._sentinel;r._prev&&r._next&&t(r),r._next=s._next,s._next._prev=r,s._next=r,r._prev=s},e.prototype.toString=function(){for(var r=[],s=this._sentinel,l=s._prev;l!==s;)r.push(JSON.stringify(l,n)),l=l._prev;return"["+r.join(", ")+"]"};function t(r){r._prev._next=r._next,r._next._prev=r._prev,delete r._next,delete r._prev}function n(r,s){if(r!=="_next"&&r!=="_prev")return s}return bx}var kx,JT;function D7(){if(JT)return kx;JT=1;var e=Pt(),t=vs().Graph,n=P7();kx=s;var r=e.constant(1);function s(p,h){if(p.nodeCount()<=1)return[];var m=u(p,h||r),y=l(m.graph,m.buckets,m.zeroIdx);return e.flatten(e.map(y,function(v){return p.outEdges(v.v,v.w)}),!0)}function l(p,h,m){for(var y=[],v=h[h.length-1],S=h[0],b;p.nodeCount();){for(;b=S.dequeue();)c(p,h,m,b);for(;b=v.dequeue();)c(p,h,m,b);if(p.nodeCount()){for(var _=h.length-2;_>0;--_)if(b=h[_].dequeue(),b){y=y.concat(c(p,h,m,b,!0));break}}}return y}function c(p,h,m,y,v){var S=v?[]:void 0;return e.forEach(p.inEdges(y.v),function(b){var _=p.edge(b),k=p.node(b.v);v&&S.push({v:b.v,w:b.w}),k.out-=_,f(h,m,k)}),e.forEach(p.outEdges(y.v),function(b){var _=p.edge(b),k=b.w,j=p.node(k);j.in-=_,f(h,m,j)}),p.removeNode(y.v),S}function u(p,h){var m=new t,y=0,v=0;e.forEach(p.nodes(),function(_){m.setNode(_,{v:_,in:0,out:0})}),e.forEach(p.edges(),function(_){var k=m.edge(_.v,_.w)||0,j=h(_),E=k+j;m.setEdge(_.v,_.w,E),v=Math.max(v,m.node(_.v).out+=j),y=Math.max(y,m.node(_.w).in+=j)});var S=e.range(v+y+3).map(function(){return new n}),b=y+1;return e.forEach(m.nodes(),function(_){f(S,b,m.node(_))}),{graph:m,buckets:S,zeroIdx:b}}function f(p,h,m){m.out?m.in?p[m.out-m.in+h].enqueue(m):p[p.length-1].enqueue(m):p[0].enqueue(m)}return kx}var Nx,e2;function F7(){if(e2)return Nx;e2=1;var e=Pt(),t=D7();Nx={run:n,undo:s};function n(l){var c=l.graph().acyclicer==="greedy"?t(l,u(l)):r(l);e.forEach(c,function(f){var p=l.edge(f);l.removeEdge(f),p.forwardName=f.name,p.reversed=!0,l.setEdge(f.w,f.v,p,e.uniqueId("rev"))});function u(f){return function(p){return f.edge(p).weight}}}function r(l){var c=[],u={},f={};function p(h){e.has(f,h)||(f[h]=!0,u[h]=!0,e.forEach(l.outEdges(h),function(m){e.has(u,m.w)?c.push(m):p(m.w)}),delete u[h])}return e.forEach(l.nodes(),p),c}function s(l){e.forEach(l.edges(),function(c){var u=l.edge(c);if(u.reversed){l.removeEdge(c);var f=u.forwardName;delete u.reversed,delete u.forwardName,l.setEdge(c.w,c.v,u,f)}})}return Nx}var Sx,t2;function or(){if(t2)return Sx;t2=1;var e=Pt(),t=vs().Graph;Sx={addDummyNode:n,simplify:r,asNonCompoundGraph:s,successorWeights:l,predecessorWeights:c,intersectRect:u,buildLayerMatrix:f,normalizeRanks:p,removeEmptyRanks:h,addBorderNode:m,maxRank:y,partition:v,time:S,notime:b};function n(_,k,j,E){var C;do C=e.uniqueId(E);while(_.hasNode(C));return j.dummy=k,_.setNode(C,j),C}function r(_){var k=new t().setGraph(_.graph());return e.forEach(_.nodes(),function(j){k.setNode(j,_.node(j))}),e.forEach(_.edges(),function(j){var E=k.edge(j.v,j.w)||{weight:0,minlen:1},C=_.edge(j);k.setEdge(j.v,j.w,{weight:E.weight+C.weight,minlen:Math.max(E.minlen,C.minlen)})}),k}function s(_){var k=new t({multigraph:_.isMultigraph()}).setGraph(_.graph());return e.forEach(_.nodes(),function(j){_.children(j).length||k.setNode(j,_.node(j))}),e.forEach(_.edges(),function(j){k.setEdge(j,_.edge(j))}),k}function l(_){var k=e.map(_.nodes(),function(j){var E={};return e.forEach(_.outEdges(j),function(C){E[C.w]=(E[C.w]||0)+_.edge(C).weight}),E});return e.zipObject(_.nodes(),k)}function c(_){var k=e.map(_.nodes(),function(j){var E={};return e.forEach(_.inEdges(j),function(C){E[C.v]=(E[C.v]||0)+_.edge(C).weight}),E});return e.zipObject(_.nodes(),k)}function u(_,k){var j=_.x,E=_.y,C=k.x-j,R=k.y-E,I=_.width/2,O=_.height/2;if(!C&&!R)throw new Error("Not possible to find intersection inside of the rectangle");var H,q;return Math.abs(R)*I>Math.abs(C)*O?(R<0&&(O=-O),H=O*C/R,q=O):(C<0&&(I=-I),H=I,q=I*R/C),{x:j+H,y:E+q}}function f(_){var k=e.map(e.range(y(_)+1),function(){return[]});return e.forEach(_.nodes(),function(j){var E=_.node(j),C=E.rank;e.isUndefined(C)||(k[C][E.order]=j)}),k}function p(_){var k=e.min(e.map(_.nodes(),function(j){return _.node(j).rank}));e.forEach(_.nodes(),function(j){var E=_.node(j);e.has(E,"rank")&&(E.rank-=k)})}function h(_){var k=e.min(e.map(_.nodes(),function(R){return _.node(R).rank})),j=[];e.forEach(_.nodes(),function(R){var I=_.node(R).rank-k;j[I]||(j[I]=[]),j[I].push(R)});var E=0,C=_.graph().nodeRankFactor;e.forEach(j,function(R,I){e.isUndefined(R)&&I%C!==0?--E:E&&e.forEach(R,function(O){_.node(O).rank+=E})})}function m(_,k,j,E){var C={width:0,height:0};return arguments.length>=4&&(C.rank=j,C.order=E),n(_,"border",C,k)}function y(_){return e.max(e.map(_.nodes(),function(k){var j=_.node(k).rank;if(!e.isUndefined(j))return j}))}function v(_,k){var j={lhs:[],rhs:[]};return e.forEach(_,function(E){k(E)?j.lhs.push(E):j.rhs.push(E)}),j}function S(_,k){var j=e.now();try{return k()}finally{console.log(_+" time: "+(e.now()-j)+"ms")}}function b(_,k){return k()}return Sx}var jx,n2;function q7(){if(n2)return jx;n2=1;var e=Pt(),t=or();jx={run:n,undo:s};function n(l){l.graph().dummyChains=[],e.forEach(l.edges(),function(c){r(l,c)})}function r(l,c){var u=c.v,f=l.node(u).rank,p=c.w,h=l.node(p).rank,m=c.name,y=l.edge(c),v=y.labelRank;if(h!==f+1){l.removeEdge(c);var S,b,_;for(_=0,++f;f<h;++_,++f)y.points=[],b={width:0,height:0,edgeLabel:y,edgeObj:c,rank:f},S=t.addDummyNode(l,"edge",b,"_d"),f===v&&(b.width=y.width,b.height=y.height,b.dummy="edge-label",b.labelpos=y.labelpos),l.setEdge(u,S,{weight:y.weight},m),_===0&&l.graph().dummyChains.push(S),u=S;l.setEdge(u,p,{weight:y.weight},m)}}function s(l){e.forEach(l.graph().dummyChains,function(c){var u=l.node(c),f=u.edgeLabel,p;for(l.setEdge(u.edgeObj,f);u.dummy;)p=l.successors(c)[0],l.removeNode(c),f.points.push({x:u.x,y:u.y}),u.dummy==="edge-label"&&(f.x=u.x,f.y=u.y,f.width=u.width,f.height=u.height),c=p,u=l.node(c)})}return jx}var _x,r2;function af(){if(r2)return _x;r2=1;var e=Pt();_x={longestPath:t,slack:n};function t(r){var s={};function l(c){var u=r.node(c);if(e.has(s,c))return u.rank;s[c]=!0;var f=e.min(e.map(r.outEdges(c),function(p){return l(p.w)-r.edge(p).minlen}));return(f===Number.POSITIVE_INFINITY||f===void 0||f===null)&&(f=0),u.rank=f}e.forEach(r.sources(),l)}function n(r,s){return r.node(s.w).rank-r.node(s.v).rank-r.edge(s).minlen}return _x}var Ex,s2;function YI(){if(s2)return Ex;s2=1;var e=Pt(),t=vs().Graph,n=af().slack;Ex=r;function r(u){var f=new t({directed:!1}),p=u.nodes()[0],h=u.nodeCount();f.setNode(p,{});for(var m,y;s(f,u)<h;)m=l(f,u),y=f.hasNode(m.v)?n(u,m):-n(u,m),c(f,u,y);return f}function s(u,f){function p(h){e.forEach(f.nodeEdges(h),function(m){var y=m.v,v=h===y?m.w:y;!u.hasNode(v)&&!n(f,m)&&(u.setNode(v,{}),u.setEdge(h,v,{}),p(v))})}return e.forEach(u.nodes(),p),u.nodeCount()}function l(u,f){return e.minBy(f.edges(),function(p){if(u.hasNode(p.v)!==u.hasNode(p.w))return n(f,p)})}function c(u,f,p){e.forEach(u.nodes(),function(h){f.node(h).rank+=p})}return Ex}var Cx,a2;function B7(){if(a2)return Cx;a2=1;var e=Pt(),t=YI(),n=af().slack,r=af().longestPath,s=vs().alg.preorder,l=vs().alg.postorder,c=or().simplify;Cx=u,u.initLowLimValues=m,u.initCutValues=f,u.calcCutValue=h,u.leaveEdge=v,u.enterEdge=S,u.exchangeEdges=b;function u(E){E=c(E),r(E);var C=t(E);m(C),f(C,E);for(var R,I;R=v(C);)I=S(C,E,R),b(C,E,R,I)}function f(E,C){var R=l(E,E.nodes());R=R.slice(0,R.length-1),e.forEach(R,function(I){p(E,C,I)})}function p(E,C,R){var I=E.node(R),O=I.parent;E.edge(R,O).cutvalue=h(E,C,R)}function h(E,C,R){var I=E.node(R),O=I.parent,H=!0,q=C.edge(R,O),$=0;return q||(H=!1,q=C.edge(O,R)),$=q.weight,e.forEach(C.nodeEdges(R),function(V){var ne=V.v===R,ee=ne?V.w:V.v;if(ee!==O){var M=ne===H,Z=C.edge(V).weight;if($+=M?Z:-Z,k(E,R,ee)){var K=E.edge(R,ee).cutvalue;$+=M?-K:K}}}),$}function m(E,C){arguments.length<2&&(C=E.nodes()[0]),y(E,{},1,C)}function y(E,C,R,I,O){var H=R,q=E.node(I);return C[I]=!0,e.forEach(E.neighbors(I),function($){e.has(C,$)||(R=y(E,C,R,$,I))}),q.low=H,q.lim=R++,O?q.parent=O:delete q.parent,R}function v(E){return e.find(E.edges(),function(C){return E.edge(C).cutvalue<0})}function S(E,C,R){var I=R.v,O=R.w;C.hasEdge(I,O)||(I=R.w,O=R.v);var H=E.node(I),q=E.node(O),$=H,V=!1;H.lim>q.lim&&($=q,V=!0);var ne=e.filter(C.edges(),function(ee){return V===j(E,E.node(ee.v),$)&&V!==j(E,E.node(ee.w),$)});return e.minBy(ne,function(ee){return n(C,ee)})}function b(E,C,R,I){var O=R.v,H=R.w;E.removeEdge(O,H),E.setEdge(I.v,I.w,{}),m(E),f(E,C),_(E,C)}function _(E,C){var R=e.find(E.nodes(),function(O){return!C.node(O).parent}),I=s(E,R);I=I.slice(1),e.forEach(I,function(O){var H=E.node(O).parent,q=C.edge(O,H),$=!1;q||(q=C.edge(H,O),$=!0),C.node(O).rank=C.node(H).rank+($?q.minlen:-q.minlen)})}function k(E,C,R){return E.hasEdge(C,R)}function j(E,C,R){return R.low<=C.lim&&C.lim<=R.lim}return Cx}var Tx,o2;function z7(){if(o2)return Tx;o2=1;var e=af(),t=e.longestPath,n=YI(),r=B7();Tx=s;function s(f){switch(f.graph().ranker){case"network-simplex":u(f);break;case"tight-tree":c(f);break;case"longest-path":l(f);break;default:u(f)}}var l=t;function c(f){t(f),n(f)}function u(f){r(f)}return Tx}var Rx,i2;function U7(){if(i2)return Rx;i2=1;var e=Pt();Rx=t;function t(s){var l=r(s);e.forEach(s.graph().dummyChains,function(c){for(var u=s.node(c),f=u.edgeObj,p=n(s,l,f.v,f.w),h=p.path,m=p.lca,y=0,v=h[y],S=!0;c!==f.w;){if(u=s.node(c),S){for(;(v=h[y])!==m&&s.node(v).maxRank<u.rank;)y++;v===m&&(S=!1)}if(!S){for(;y<h.length-1&&s.node(v=h[y+1]).minRank<=u.rank;)y++;v=h[y]}s.setParent(c,v),c=s.successors(c)[0]}})}function n(s,l,c,u){var f=[],p=[],h=Math.min(l[c].low,l[u].low),m=Math.max(l[c].lim,l[u].lim),y,v;y=c;do y=s.parent(y),f.push(y);while(y&&(l[y].low>h||m>l[y].lim));for(v=y,y=u;(y=s.parent(y))!==v;)p.push(y);return{path:f.concat(p.reverse()),lca:v}}function r(s){var l={},c=0;function u(f){var p=c;e.forEach(s.children(f),u),l[f]={low:p,lim:c++}}return e.forEach(s.children(),u),l}return Rx}var Ax,l2;function H7(){if(l2)return Ax;l2=1;var e=Pt(),t=or();Ax={run:n,cleanup:c};function n(u){var f=t.addDummyNode(u,"root",{},"_root"),p=s(u),h=e.max(e.values(p))-1,m=2*h+1;u.graph().nestingRoot=f,e.forEach(u.edges(),function(v){u.edge(v).minlen*=m});var y=l(u)+1;e.forEach(u.children(),function(v){r(u,f,m,y,h,p,v)}),u.graph().nodeRankFactor=m}function r(u,f,p,h,m,y,v){var S=u.children(v);if(!S.length){v!==f&&u.setEdge(f,v,{weight:0,minlen:p});return}var b=t.addBorderNode(u,"_bt"),_=t.addBorderNode(u,"_bb"),k=u.node(v);u.setParent(b,v),k.borderTop=b,u.setParent(_,v),k.borderBottom=_,e.forEach(S,function(j){r(u,f,p,h,m,y,j);var E=u.node(j),C=E.borderTop?E.borderTop:j,R=E.borderBottom?E.borderBottom:j,I=E.borderTop?h:2*h,O=C!==R?1:m-y[v]+1;u.setEdge(b,C,{weight:I,minlen:O,nestingEdge:!0}),u.setEdge(R,_,{weight:I,minlen:O,nestingEdge:!0})}),u.parent(v)||u.setEdge(f,b,{weight:0,minlen:m+y[v]})}function s(u){var f={};function p(h,m){var y=u.children(h);y&&y.length&&e.forEach(y,function(v){p(v,m+1)}),f[h]=m}return e.forEach(u.children(),function(h){p(h,1)}),f}function l(u){return e.reduce(u.edges(),function(f,p){return f+u.edge(p).weight},0)}function c(u){var f=u.graph();u.removeNode(f.nestingRoot),delete f.nestingRoot,e.forEach(u.edges(),function(p){var h=u.edge(p);h.nestingEdge&&u.removeEdge(p)})}return Ax}var Mx,c2;function W7(){if(c2)return Mx;c2=1;var e=Pt(),t=or();Mx=n;function n(s){function l(c){var u=s.children(c),f=s.node(c);if(u.length&&e.forEach(u,l),e.has(f,"minRank")){f.borderLeft=[],f.borderRight=[];for(var p=f.minRank,h=f.maxRank+1;p<h;++p)r(s,"borderLeft","_bl",c,f,p),r(s,"borderRight","_br",c,f,p)}}e.forEach(s.children(),l)}function r(s,l,c,u,f,p){var h={width:0,height:0,rank:p,borderType:l},m=f[l][p-1],y=t.addDummyNode(s,"border",h,c);f[l][p]=y,s.setParent(y,u),m&&s.setEdge(m,y,{weight:1})}return Mx}var Ix,u2;function V7(){if(u2)return Ix;u2=1;var e=Pt();Ix={adjust:t,undo:n};function t(p){var h=p.graph().rankdir.toLowerCase();(h==="lr"||h==="rl")&&r(p)}function n(p){var h=p.graph().rankdir.toLowerCase();(h==="bt"||h==="rl")&&l(p),(h==="lr"||h==="rl")&&(u(p),r(p))}function r(p){e.forEach(p.nodes(),function(h){s(p.node(h))}),e.forEach(p.edges(),function(h){s(p.edge(h))})}function s(p){var h=p.width;p.width=p.height,p.height=h}function l(p){e.forEach(p.nodes(),function(h){c(p.node(h))}),e.forEach(p.edges(),function(h){var m=p.edge(h);e.forEach(m.points,c),e.has(m,"y")&&c(m)})}function c(p){p.y=-p.y}function u(p){e.forEach(p.nodes(),function(h){f(p.node(h))}),e.forEach(p.edges(),function(h){var m=p.edge(h);e.forEach(m.points,f),e.has(m,"x")&&f(m)})}function f(p){var h=p.x;p.x=p.y,p.y=h}return Ix}var $x,d2;function G7(){if(d2)return $x;d2=1;var e=Pt();$x=t;function t(n){var r={},s=e.filter(n.nodes(),function(p){return!n.children(p).length}),l=e.max(e.map(s,function(p){return n.node(p).rank})),c=e.map(e.range(l+1),function(){return[]});function u(p){if(!e.has(r,p)){r[p]=!0;var h=n.node(p);c[h.rank].push(p),e.forEach(n.successors(p),u)}}var f=e.sortBy(s,function(p){return n.node(p).rank});return e.forEach(f,u),c}return $x}var Ox,h2;function K7(){if(h2)return Ox;h2=1;var e=Pt();Ox=t;function t(r,s){for(var l=0,c=1;c<s.length;++c)l+=n(r,s[c-1],s[c]);return l}function n(r,s,l){for(var c=e.zipObject(l,e.map(l,function(y,v){return v})),u=e.flatten(e.map(s,function(y){return e.sortBy(e.map(r.outEdges(y),function(v){return{pos:c[v.w],weight:r.edge(v).weight}}),"pos")}),!0),f=1;f<l.length;)f<<=1;var p=2*f-1;f-=1;var h=e.map(new Array(p),function(){return 0}),m=0;return e.forEach(u.forEach(function(y){var v=y.pos+f;h[v]+=y.weight;for(var S=0;v>0;)v%2&&(S+=h[v+1]),v=v-1>>1,h[v]+=y.weight;m+=y.weight*S})),m}return Ox}var Lx,f2;function Y7(){if(f2)return Lx;f2=1;var e=Pt();Lx=t;function t(n,r){return e.map(r,function(s){var l=n.inEdges(s);if(l.length){var c=e.reduce(l,function(u,f){var p=n.edge(f),h=n.node(f.v);return{sum:u.sum+p.weight*h.order,weight:u.weight+p.weight}},{sum:0,weight:0});return{v:s,barycenter:c.sum/c.weight,weight:c.weight}}else return{v:s}})}return Lx}var Px,p2;function X7(){if(p2)return Px;p2=1;var e=Pt();Px=t;function t(s,l){var c={};e.forEach(s,function(f,p){var h=c[f.v]={indegree:0,in:[],out:[],vs:[f.v],i:p};e.isUndefined(f.barycenter)||(h.barycenter=f.barycenter,h.weight=f.weight)}),e.forEach(l.edges(),function(f){var p=c[f.v],h=c[f.w];!e.isUndefined(p)&&!e.isUndefined(h)&&(h.indegree++,p.out.push(c[f.w]))});var u=e.filter(c,function(f){return!f.indegree});return n(u)}function n(s){var l=[];function c(p){return function(h){h.merged||(e.isUndefined(h.barycenter)||e.isUndefined(p.barycenter)||h.barycenter>=p.barycenter)&&r(p,h)}}function u(p){return function(h){h.in.push(p),--h.indegree===0&&s.push(h)}}for(;s.length;){var f=s.pop();l.push(f),e.forEach(f.in.reverse(),c(f)),e.forEach(f.out,u(f))}return e.map(e.filter(l,function(p){return!p.merged}),function(p){return e.pick(p,["vs","i","barycenter","weight"])})}function r(s,l){var c=0,u=0;s.weight&&(c+=s.barycenter*s.weight,u+=s.weight),l.weight&&(c+=l.barycenter*l.weight,u+=l.weight),s.vs=l.vs.concat(s.vs),s.barycenter=c/u,s.weight=u,s.i=Math.min(l.i,s.i),l.merged=!0}return Px}var Dx,m2;function Z7(){if(m2)return Dx;m2=1;var e=Pt(),t=or();Dx=n;function n(l,c){var u=t.partition(l,function(b){return e.has(b,"barycenter")}),f=u.lhs,p=e.sortBy(u.rhs,function(b){return-b.i}),h=[],m=0,y=0,v=0;f.sort(s(!!c)),v=r(h,p,v),e.forEach(f,function(b){v+=b.vs.length,h.push(b.vs),m+=b.barycenter*b.weight,y+=b.weight,v=r(h,p,v)});var S={vs:e.flatten(h,!0)};return y&&(S.barycenter=m/y,S.weight=y),S}function r(l,c,u){for(var f;c.length&&(f=e.last(c)).i<=u;)c.pop(),l.push(f.vs),u++;return u}function s(l){return function(c,u){return c.barycenter<u.barycenter?-1:c.barycenter>u.barycenter?1:l?u.i-c.i:c.i-u.i}}return Dx}var Fx,g2;function Q7(){if(g2)return Fx;g2=1;var e=Pt(),t=Y7(),n=X7(),r=Z7();Fx=s;function s(u,f,p,h){var m=u.children(f),y=u.node(f),v=y?y.borderLeft:void 0,S=y?y.borderRight:void 0,b={};v&&(m=e.filter(m,function(R){return R!==v&&R!==S}));var _=t(u,m);e.forEach(_,function(R){if(u.children(R.v).length){var I=s(u,R.v,p,h);b[R.v]=I,e.has(I,"barycenter")&&c(R,I)}});var k=n(_,p);l(k,b);var j=r(k,h);if(v&&(j.vs=e.flatten([v,j.vs,S],!0),u.predecessors(v).length)){var E=u.node(u.predecessors(v)[0]),C=u.node(u.predecessors(S)[0]);e.has(j,"barycenter")||(j.barycenter=0,j.weight=0),j.barycenter=(j.barycenter*j.weight+E.order+C.order)/(j.weight+2),j.weight+=2}return j}function l(u,f){e.forEach(u,function(p){p.vs=e.flatten(p.vs.map(function(h){return f[h]?f[h].vs:h}),!0)})}function c(u,f){e.isUndefined(u.barycenter)?(u.barycenter=f.barycenter,u.weight=f.weight):(u.barycenter=(u.barycenter*u.weight+f.barycenter*f.weight)/(u.weight+f.weight),u.weight+=f.weight)}return Fx}var qx,y2;function J7(){if(y2)return qx;y2=1;var e=Pt(),t=vs().Graph;qx=n;function n(s,l,c){var u=r(s),f=new t({compound:!0}).setGraph({root:u}).setDefaultNodeLabel(function(p){return s.node(p)});return e.forEach(s.nodes(),function(p){var h=s.node(p),m=s.parent(p);(h.rank===l||h.minRank<=l&&l<=h.maxRank)&&(f.setNode(p),f.setParent(p,m||u),e.forEach(s[c](p),function(y){var v=y.v===p?y.w:y.v,S=f.edge(v,p),b=e.isUndefined(S)?0:S.weight;f.setEdge(v,p,{weight:s.edge(y).weight+b})}),e.has(h,"minRank")&&f.setNode(p,{borderLeft:h.borderLeft[l],borderRight:h.borderRight[l]}))}),f}function r(s){for(var l;s.hasNode(l=e.uniqueId("_root")););return l}return qx}var Bx,w2;function e9(){if(w2)return Bx;w2=1;var e=Pt();Bx=t;function t(n,r,s){var l={},c;e.forEach(s,function(u){for(var f=n.parent(u),p,h;f;){if(p=n.parent(f),p?(h=l[p],l[p]=f):(h=c,c=f),h&&h!==f){r.setEdge(h,f);return}f=p}})}return Bx}var zx,v2;function t9(){if(v2)return zx;v2=1;var e=Pt(),t=G7(),n=K7(),r=Q7(),s=J7(),l=e9(),c=vs().Graph,u=or();zx=f;function f(y){var v=u.maxRank(y),S=p(y,e.range(1,v+1),"inEdges"),b=p(y,e.range(v-1,-1,-1),"outEdges"),_=t(y);m(y,_);for(var k=Number.POSITIVE_INFINITY,j,E=0,C=0;C<4;++E,++C){h(E%2?S:b,E%4>=2),_=u.buildLayerMatrix(y);var R=n(y,_);R<k&&(C=0,j=e.cloneDeep(_),k=R)}m(y,j)}function p(y,v,S){return e.map(v,function(b){return s(y,b,S)})}function h(y,v){var S=new c;e.forEach(y,function(b){var _=b.graph().root,k=r(b,_,S,v);e.forEach(k.vs,function(j,E){b.node(j).order=E}),l(b,S,k.vs)})}function m(y,v){e.forEach(v,function(S){e.forEach(S,function(b,_){y.node(b).order=_})})}return zx}var Ux,x2;function n9(){if(x2)return Ux;x2=1;var e=Pt(),t=vs().Graph,n=or();Ux={positionX:S,findType1Conflicts:r,findType2Conflicts:s,addConflict:c,hasConflict:u,verticalAlignment:f,horizontalCompaction:p,alignCoordinates:y,findSmallestWidthAlignment:m,balance:v};function r(k,j){var E={};function C(R,I){var O=0,H=0,q=R.length,$=e.last(I);return e.forEach(I,function(V,ne){var ee=l(k,V),M=ee?k.node(ee).order:q;(ee||V===$)&&(e.forEach(I.slice(H,ne+1),function(Z){e.forEach(k.predecessors(Z),function(K){var D=k.node(K),P=D.order;(P<O||M<P)&&!(D.dummy&&k.node(Z).dummy)&&c(E,K,Z)})}),H=ne+1,O=M)}),I}return e.reduce(j,C),E}function s(k,j){var E={};function C(I,O,H,q,$){var V;e.forEach(e.range(O,H),function(ne){V=I[ne],k.node(V).dummy&&e.forEach(k.predecessors(V),function(ee){var M=k.node(ee);M.dummy&&(M.order<q||M.order>$)&&c(E,ee,V)})})}function R(I,O){var H=-1,q,$=0;return e.forEach(O,function(V,ne){if(k.node(V).dummy==="border"){var ee=k.predecessors(V);ee.length&&(q=k.node(ee[0]).order,C(O,$,ne,H,q),$=ne,H=q)}C(O,$,O.length,q,I.length)}),O}return e.reduce(j,R),E}function l(k,j){if(k.node(j).dummy)return e.find(k.predecessors(j),function(E){return k.node(E).dummy})}function c(k,j,E){if(j>E){var C=j;j=E,E=C}var R=k[j];R||(k[j]=R={}),R[E]=!0}function u(k,j,E){if(j>E){var C=j;j=E,E=C}return e.has(k[j],E)}function f(k,j,E,C){var R={},I={},O={};return e.forEach(j,function(H){e.forEach(H,function(q,$){R[q]=q,I[q]=q,O[q]=$})}),e.forEach(j,function(H){var q=-1;e.forEach(H,function($){var V=C($);if(V.length){V=e.sortBy(V,function(K){return O[K]});for(var ne=(V.length-1)/2,ee=Math.floor(ne),M=Math.ceil(ne);ee<=M;++ee){var Z=V[ee];I[$]===$&&q<O[Z]&&!u(E,$,Z)&&(I[Z]=$,I[$]=R[$]=R[Z],q=O[Z])}}})}),{root:R,align:I}}function p(k,j,E,C,R){var I={},O=h(k,j,E,R),H=R?"borderLeft":"borderRight";function q(ne,ee){for(var M=O.nodes(),Z=M.pop(),K={};Z;)K[Z]?ne(Z):(K[Z]=!0,M.push(Z),M=M.concat(ee(Z))),Z=M.pop()}function $(ne){I[ne]=O.inEdges(ne).reduce(function(ee,M){return Math.max(ee,I[M.v]+O.edge(M))},0)}function V(ne){var ee=O.outEdges(ne).reduce(function(Z,K){return Math.min(Z,I[K.w]-O.edge(K))},Number.POSITIVE_INFINITY),M=k.node(ne);ee!==Number.POSITIVE_INFINITY&&M.borderType!==H&&(I[ne]=Math.max(I[ne],ee))}return q($,O.predecessors.bind(O)),q(V,O.successors.bind(O)),e.forEach(C,function(ne){I[ne]=I[E[ne]]}),I}function h(k,j,E,C){var R=new t,I=k.graph(),O=b(I.nodesep,I.edgesep,C);return e.forEach(j,function(H){var q;e.forEach(H,function($){var V=E[$];if(R.setNode(V),q){var ne=E[q],ee=R.edge(ne,V);R.setEdge(ne,V,Math.max(O(k,$,q),ee||0))}q=$})}),R}function m(k,j){return e.minBy(e.values(j),function(E){var C=Number.NEGATIVE_INFINITY,R=Number.POSITIVE_INFINITY;return e.forIn(E,function(I,O){var H=_(k,O)/2;C=Math.max(I+H,C),R=Math.min(I-H,R)}),C-R})}function y(k,j){var E=e.values(j),C=e.min(E),R=e.max(E);e.forEach(["u","d"],function(I){e.forEach(["l","r"],function(O){var H=I+O,q=k[H],$;if(q!==j){var V=e.values(q);$=O==="l"?C-e.min(V):R-e.max(V),$&&(k[H]=e.mapValues(q,function(ne){return ne+$}))}})})}function v(k,j){return e.mapValues(k.ul,function(E,C){if(j)return k[j.toLowerCase()][C];var R=e.sortBy(e.map(k,C));return(R[1]+R[2])/2})}function S(k){var j=n.buildLayerMatrix(k),E=e.merge(r(k,j),s(k,j)),C={},R;e.forEach(["u","d"],function(O){R=O==="u"?j:e.values(j).reverse(),e.forEach(["l","r"],function(H){H==="r"&&(R=e.map(R,function(ne){return e.values(ne).reverse()}));var q=(O==="u"?k.predecessors:k.successors).bind(k),$=f(k,R,E,q),V=p(k,R,$.root,$.align,H==="r");H==="r"&&(V=e.mapValues(V,function(ne){return-ne})),C[O+H]=V})});var I=m(k,C);return y(C,I),v(C,k.graph().align)}function b(k,j,E){return function(C,R,I){var O=C.node(R),H=C.node(I),q=0,$;if(q+=O.width/2,e.has(O,"labelpos"))switch(O.labelpos.toLowerCase()){case"l":$=-O.width/2;break;case"r":$=O.width/2;break}if($&&(q+=E?$:-$),$=0,q+=(O.dummy?j:k)/2,q+=(H.dummy?j:k)/2,q+=H.width/2,e.has(H,"labelpos"))switch(H.labelpos.toLowerCase()){case"l":$=H.width/2;break;case"r":$=-H.width/2;break}return $&&(q+=E?$:-$),$=0,q}}function _(k,j){return k.node(j).width}return Ux}var Hx,b2;function r9(){if(b2)return Hx;b2=1;var e=Pt(),t=or(),n=n9().positionX;Hx=r;function r(l){l=t.asNonCompoundGraph(l),s(l),e.forEach(n(l),function(c,u){l.node(u).x=c})}function s(l){var c=t.buildLayerMatrix(l),u=l.graph().ranksep,f=0;e.forEach(c,function(p){var h=e.max(e.map(p,function(m){return l.node(m).height}));e.forEach(p,function(m){l.node(m).y=f+h/2}),f+=h+u})}return Hx}var Wx,k2;function s9(){if(k2)return Wx;k2=1;var e=Pt(),t=F7(),n=q7(),r=z7(),s=or().normalizeRanks,l=U7(),c=or().removeEmptyRanks,u=H7(),f=W7(),p=V7(),h=t9(),m=r9(),y=or(),v=vs().Graph;Wx=S;function S(U,Y){var z=Y&&Y.debugTiming?y.time:y.notime;z("layout",function(){var ie=z(" buildLayoutGraph",function(){return q(U)});z(" runLayout",function(){b(ie,z)}),z(" updateInputGraph",function(){_(U,ie)})})}function b(U,Y){Y(" makeSpaceForEdgeLabels",function(){$(U)}),Y(" removeSelfEdges",function(){B(U)}),Y(" acyclic",function(){t.run(U)}),Y(" nestingGraph.run",function(){u.run(U)}),Y(" rank",function(){r(y.asNonCompoundGraph(U))}),Y(" injectEdgeLabelProxies",function(){V(U)}),Y(" removeEmptyRanks",function(){c(U)}),Y(" nestingGraph.cleanup",function(){u.cleanup(U)}),Y(" normalizeRanks",function(){s(U)}),Y(" assignRankMinMax",function(){ne(U)}),Y(" removeEdgeLabelProxies",function(){ee(U)}),Y(" normalize.run",function(){n.run(U)}),Y(" parentDummyChains",function(){l(U)}),Y(" addBorderSegments",function(){f(U)}),Y(" order",function(){h(U)}),Y(" insertSelfEdges",function(){W(U)}),Y(" adjustCoordinateSystem",function(){p.adjust(U)}),Y(" position",function(){m(U)}),Y(" positionSelfEdges",function(){F(U)}),Y(" removeBorderNodes",function(){P(U)}),Y(" normalize.undo",function(){n.undo(U)}),Y(" fixupEdgeLabelCoords",function(){K(U)}),Y(" undoCoordinateSystem",function(){p.undo(U)}),Y(" translateGraph",function(){M(U)}),Y(" assignNodeIntersects",function(){Z(U)}),Y(" reversePoints",function(){D(U)}),Y(" acyclic.undo",function(){t.undo(U)})}function _(U,Y){e.forEach(U.nodes(),function(z){var ie=U.node(z),le=Y.node(z);ie&&(ie.x=le.x,ie.y=le.y,Y.children(z).length&&(ie.width=le.width,ie.height=le.height))}),e.forEach(U.edges(),function(z){var ie=U.edge(z),le=Y.edge(z);ie.points=le.points,e.has(le,"x")&&(ie.x=le.x,ie.y=le.y)}),U.graph().width=Y.graph().width,U.graph().height=Y.graph().height}var k=["nodesep","edgesep","ranksep","marginx","marginy"],j={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},E=["acyclicer","ranker","rankdir","align"],C=["width","height"],R={width:0,height:0},I=["minlen","weight","width","height","labeloffset"],O={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},H=["labelpos"];function q(U){var Y=new v({multigraph:!0,compound:!0}),z=re(U.graph());return Y.setGraph(e.merge({},j,G(z,k),e.pick(z,E))),e.forEach(U.nodes(),function(ie){var le=re(U.node(ie));Y.setNode(ie,e.defaults(G(le,C),R)),Y.setParent(ie,U.parent(ie))}),e.forEach(U.edges(),function(ie){var le=re(U.edge(ie));Y.setEdge(ie,e.merge({},O,G(le,I),e.pick(le,H)))}),Y}function $(U){var Y=U.graph();Y.ranksep/=2,e.forEach(U.edges(),function(z){var ie=U.edge(z);ie.minlen*=2,ie.labelpos.toLowerCase()!=="c"&&(Y.rankdir==="TB"||Y.rankdir==="BT"?ie.width+=ie.labeloffset:ie.height+=ie.labeloffset)})}function V(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);if(z.width&&z.height){var ie=U.node(Y.v),le=U.node(Y.w),ge={rank:(le.rank-ie.rank)/2+ie.rank,e:Y};y.addDummyNode(U,"edge-proxy",ge,"_ep")}})}function ne(U){var Y=0;e.forEach(U.nodes(),function(z){var ie=U.node(z);ie.borderTop&&(ie.minRank=U.node(ie.borderTop).rank,ie.maxRank=U.node(ie.borderBottom).rank,Y=e.max(Y,ie.maxRank))}),U.graph().maxRank=Y}function ee(U){e.forEach(U.nodes(),function(Y){var z=U.node(Y);z.dummy==="edge-proxy"&&(U.edge(z.e).labelRank=z.rank,U.removeNode(Y))})}function M(U){var Y=Number.POSITIVE_INFINITY,z=0,ie=Number.POSITIVE_INFINITY,le=0,ge=U.graph(),Ne=ge.marginx||0,Ie=ge.marginy||0;function Ge(Pe){var Be=Pe.x,Te=Pe.y,st=Pe.width,de=Pe.height;Y=Math.min(Y,Be-st/2),z=Math.max(z,Be+st/2),ie=Math.min(ie,Te-de/2),le=Math.max(le,Te+de/2)}e.forEach(U.nodes(),function(Pe){Ge(U.node(Pe))}),e.forEach(U.edges(),function(Pe){var Be=U.edge(Pe);e.has(Be,"x")&&Ge(Be)}),Y-=Ne,ie-=Ie,e.forEach(U.nodes(),function(Pe){var Be=U.node(Pe);Be.x-=Y,Be.y-=ie}),e.forEach(U.edges(),function(Pe){var Be=U.edge(Pe);e.forEach(Be.points,function(Te){Te.x-=Y,Te.y-=ie}),e.has(Be,"x")&&(Be.x-=Y),e.has(Be,"y")&&(Be.y-=ie)}),ge.width=z-Y+Ne,ge.height=le-ie+Ie}function Z(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y),ie=U.node(Y.v),le=U.node(Y.w),ge,Ne;z.points?(ge=z.points[0],Ne=z.points[z.points.length-1]):(z.points=[],ge=le,Ne=ie),z.points.unshift(y.intersectRect(ie,ge)),z.points.push(y.intersectRect(le,Ne))})}function K(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);if(e.has(z,"x"))switch((z.labelpos==="l"||z.labelpos==="r")&&(z.width-=z.labeloffset),z.labelpos){case"l":z.x-=z.width/2+z.labeloffset;break;case"r":z.x+=z.width/2+z.labeloffset;break}})}function D(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);z.reversed&&z.points.reverse()})}function P(U){e.forEach(U.nodes(),function(Y){if(U.children(Y).length){var z=U.node(Y),ie=U.node(z.borderTop),le=U.node(z.borderBottom),ge=U.node(e.last(z.borderLeft)),Ne=U.node(e.last(z.borderRight));z.width=Math.abs(Ne.x-ge.x),z.height=Math.abs(le.y-ie.y),z.x=ge.x+z.width/2,z.y=ie.y+z.height/2}}),e.forEach(U.nodes(),function(Y){U.node(Y).dummy==="border"&&U.removeNode(Y)})}function B(U){e.forEach(U.edges(),function(Y){if(Y.v===Y.w){var z=U.node(Y.v);z.selfEdges||(z.selfEdges=[]),z.selfEdges.push({e:Y,label:U.edge(Y)}),U.removeEdge(Y)}})}function W(U){var Y=y.buildLayerMatrix(U);e.forEach(Y,function(z){var ie=0;e.forEach(z,function(le,ge){var Ne=U.node(le);Ne.order=ge+ie,e.forEach(Ne.selfEdges,function(Ie){y.addDummyNode(U,"selfedge",{width:Ie.label.width,height:Ie.label.height,rank:Ne.rank,order:ge+ ++ie,e:Ie.e,label:Ie.label},"_se")}),delete Ne.selfEdges})})}function F(U){e.forEach(U.nodes(),function(Y){var z=U.node(Y);if(z.dummy==="selfedge"){var ie=U.node(z.e.v),le=ie.x+ie.width/2,ge=ie.y,Ne=z.x-le,Ie=ie.height/2;U.setEdge(z.e,z.label),U.removeNode(Y),z.label.points=[{x:le+2*Ne/3,y:ge-Ie},{x:le+5*Ne/6,y:ge-Ie},{x:le+Ne,y:ge},{x:le+5*Ne/6,y:ge+Ie},{x:le+2*Ne/3,y:ge+Ie}],z.label.x=z.x,z.label.y=z.y}})}function G(U,Y){return e.mapValues(e.pick(U,Y),Number)}function re(U){var Y={};return e.forEach(U,function(z,ie){Y[ie.toLowerCase()]=z}),Y}return Wx}var Vx,N2;function a9(){if(N2)return Vx;N2=1;var e=Pt(),t=or(),n=vs().Graph;Vx={debugOrdering:r};function r(s){var l=t.buildLayerMatrix(s),c=new n({compound:!0,multigraph:!0}).setGraph({});return e.forEach(s.nodes(),function(u){c.setNode(u,{label:u}),c.setParent(u,"layer"+s.node(u).rank)}),e.forEach(s.edges(),function(u){c.setEdge(u.v,u.w,{},u.name)}),e.forEach(l,function(u,f){var p="layer"+f;c.setNode(p,{rank:"same"}),e.reduce(u,function(h,m){return c.setEdge(h,m,{style:"invis"}),m})}),c}return Vx}var Gx,S2;function o9(){return S2||(S2=1,Gx="0.8.5"),Gx}var Kx,j2;function i9(){return j2||(j2=1,Kx={graphlib:vs(),layout:s9(),debug:a9(),util:{time:or().time,notime:or().notime},version:o9()}),Kx}var l9=i9();const _2=tb(l9),pi=240,Iu=130,Dl=74,Yf=72,gu=Dl+Yf;function XI(e,t){var r;let n=pi;for(const s of e)n=Math.max(n,((r=t.get(s.id))==null?void 0:r.width)??pi);return n}const of=420,ZI=1;function c9(e,t,n,r){return Math.min(ZI,n/Math.max(1,e),r/Math.max(1,t))}function mi(e){var n;return((n=e.data)==null?void 0:n.sessionId)??"_default"}function u9(e,t){return((t==null?void 0:t.get(e))??0)>0?of:0}function d9(e,t){const n=(t==null?void 0:t.get(e))??0;return n>0?6+n*36:0}function $u(e,t,n){const r=t.get(e);return{w:((r==null?void 0:r.width)??pi)+u9(e,n),h:Math.max((r==null?void 0:r.height)??Iu,d9(e,n))}}function h9(e){return[...e.keys()].sort().map(t=>`${t}:${e.get(t)}`).join("|")}function f9(e,t,n,r,s,l){const c=new _2.graphlib.Graph;c.setDefaultEdgeLabel(()=>({})),c.setGraph({rankdir:n,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const u=e.filter(k=>!s.has(k)),f=new Set(u);for(const k of u){const{w:j,h:E}=$u(k,r,l);c.setNode(k,{width:j,height:E})}for(const k of t)f.has(k.source)&&f.has(k.target)&&c.setEdge(k.source,k.target);_2.layout(c);const p=new Map;let h=1/0,m=1/0,y=-1/0,v=-1/0;for(const k of u){const j=c.node(k);if(!j)continue;const E=r.get(k),C=(E==null?void 0:E.width)??pi,R=(E==null?void 0:E.height)??Iu,I=$u(k,r,l),O=j.x-I.w/2,H=j.y-I.h/2;p.set(k,{x:O,y:H}),O<h&&(h=O),H<m&&(m=H),O+C>y&&(y=O+C),H+R>v&&(v=H+R)}if(Number.isFinite(h)&&Number.isFinite(m))for(const[k,j]of p)p.set(k,{x:j.x-h,y:j.y-m});const S=Number.isFinite(y)?y-h:0,b=Number.isFinite(v)?v-m:0;let _=null;for(const k of e){const j=s.get(k);if(!j)continue;const E=r.get(k),C=(E==null?void 0:E.width)??pi,R=(E==null?void 0:E.height)??Iu;_=_===null?{minX:j.x,minY:j.y,maxX:j.x+C,maxY:j.y+R}:{minX:Math.min(_.minX,j.x),minY:Math.min(_.minY,j.y),maxX:Math.max(_.maxX,j.x+C),maxY:Math.max(_.maxY,j.y+R)}}return{positions:p,width:S,height:b,pinnedBox:_}}function QI(e,t,n){const r=n.direction??"LR",s=n.pinned??new Map,l=n.measured??new Map,c=n.lanes,u=new Map;for(const h of e){const m=mi(h),y=u.get(m);y?y.push(h.id):u.set(m,[h.id])}return{laid:Array.from(u.keys()).sort().map(h=>({sid:h,...f9(u.get(h),t,r,l,s,c)})),gap:XI(e,l)}}const JI=e=>e.reduce((t,n)=>Math.max(t,n.width),0)+of,p9=e=>e.reduce((t,n)=>t+n.height,0)+gu*Math.max(0,e.length-1);function B0(e,t,n,r){const s=f=>{const p=[[]];let h=0;for(const m of e)h>0&&h+m.height>f&&(p.push([]),h=0),p[p.length-1].push(m),h+=m.height+gu;return p},l=[];for(let f=0;f<e.length;f++){let p=-gu;for(let h=f;h<e.length;h++)l.push(p+=e[h].height+gu)}l.sort((f,p)=>f-p);const c=f=>{let p=0,h=l.length-1;for(;p<h;){const m=p+h>>1;s(l[m]).length<=f?h=m:p=m+1}return s(l[p])};let u=[e];if(n>0&&r>0){const f=h=>c9(h.reduce((m,y)=>m+JI(y),0)+t*(h.length-1),Math.max(...h.map(p9)),n,r);let p=f(u);for(let h=2;h<=e.length;h++){const m=c(h),y=f(m);y>p+1e-9&&(p=y,u=m)}}return u}function m9(e,t,n,r,s){if(!(r.width>0&&r.height>0&&s.width>0&&s.height>0))return!1;const{laid:l,gap:c}=QI(e,t,n);return l.length<2?!1:B0(l,c,r.width,r.height).length!==B0(l,c,s.width,s.height).length}function g9(e,t,n={}){const r=n.pinned??new Map,{laid:s,gap:l}=QI(e,t,n),c=B0(s,l,n.availableWidth??0,n.availableHeight??0),u=new Map;let f=0;for(const p of c){const h=JI(p);let m=0;for(const{positions:y,height:v,pinnedBox:S}of p){for(const[_,k]of y)u.set(_,{x:k.x+f,y:k.y+m});let b=m+v;S&&S.maxY>b&&S.minX<f+h&&f<S.maxX&&(b=S.maxY),m=b+gu}f+=h+l}return e.map(p=>{const h=r.get(p.id);if(h)return{...p,position:h};const m=u.get(p.id);return m?{...p,position:m}:p})}function y9(e,t,n,r,s){const c=Dl+Yf,u=60,f=v=>$u(v,r,s),p=new Map(e.map(v=>[v.id,mi(v)])),h=[],m=e.map(v=>({id:v.id,pos:n.get(v.id)??t.get(v.id)})).filter(v=>v.pos!=null).sort((v,S)=>v.pos.y-S.pos.y||v.pos.x-S.pos.x||v.id.localeCompare(S.id)),y=[];for(const{id:v,pos:S}of m){const{w:b,h:_}=f(v),k=p.get(v)??"_default";if(n.has(v)){h.push({x:S.x,y:S.y,w:b,h:_,sid:k});continue}let j=S.y;for(let E=0;E<h.length+1;E++){const C=h.find(R=>{const I=R.sid===k?24:u,O=R.sid===k?24:c;return S.x<R.x+R.w+I&&R.x<S.x+b+I&&j<R.y+R.h+O&&R.y<j+_+O});if(!C)break;j=C.y+C.h+(C.sid===k?24:c)}j!==S.y&&(t.set(v,{x:S.x,y:j}),y.push(v)),h.push({x:S.x,y:j,w:b,h:_,sid:k})}return y}function w9(e,t,n,r,s,l,c){const u=E=>$u(E,r,l),f=E=>n.get(E)??t.get(E),p=E=>{const C=r.get(E);return{cw:(C==null?void 0:C.width)??pi,ch:(C==null?void 0:C.height)??Iu}},h=c!=null&&c.width>0&&c.height>0,m=new Map;for(const E of e){if(!f(E.id))continue;const C=mi(E),R=m.get(C);R?R.push(E):m.set(C,[E])}const y=new Set;for(const[E,C]of m)C.every(R=>s.has(R.id)&&!n.has(R.id))&&y.add(E);const v=new Map,S=[];for(const E of e){const C=f(E.id);if(!C)continue;const{w:R,h:I}=u(E.id),O=mi(E);y.has(O)?(v.get(O)??v.set(O,[]).get(O)).push(E):S.push({x:C.x,y:C.y,w:R,h:I,...p(E.id)})}if(v.size===0||h&&S.length===0)return[];const b=Dl+Yf,_=(E,C,R,I)=>S.some(O=>E<O.x+O.w+Dl&&O.x<E+R+Dl&&C<O.y+O.h+b&&O.y<C+I+b),k=XI(e,r),j=[];for(const E of[...v.keys()].sort()){const C=v.get(E);let R=1/0,I=1/0,O=-1/0,H=-1/0,q=-1/0,$=-1/0;for(const D of C){const P=f(D.id),{w:B,h:W}=u(D.id),{cw:F,ch:G}=p(D.id);R=Math.min(R,P.x),I=Math.min(I,P.y),O=Math.max(O,P.x+B),H=Math.max(H,P.y+W),q=Math.max(q,P.x+F),$=Math.max($,P.y+G)}const V=O-R,ne=H-I,ee=[...new Set(S.map(D=>Math.round(D.x)))].sort((D,P)=>D-P),M=ee.length?ee:[R],Z=[0,...S.map(D=>D.y+D.h+b)].sort((D,P)=>D-P);let K=null;if(h){let D=1/0,P=1/0,B=-1/0,W=-1/0;for(const z of S)D=Math.min(D,z.x),P=Math.min(P,z.y),B=Math.max(B,z.x+z.cw),W=Math.max(W,z.y+z.ch);const F=(z,ie)=>{const le=c.width/(Math.max(B,z+q-R)-Math.min(D,z)+of),ge=c.height/(Math.max(W,ie+$-I)-Math.min(P,ie));return[Math.min(ZI,le,ge),Math.min(le,ge),Math.max(le,ge)]},G=(z,ie)=>{for(let le=0;le<z.length;le++){if(z[le]>ie[le]+1e-9)return!0;if(z[le]<ie[le]-1e-9)return!1}return!1},re=Math.round(B+of+k),U=[...new Set([...Z,P])].sort((z,ie)=>z-ie);let Y=null;for(const z of[...M,re])for(const ie of U){if(_(z,ie,V,ne))continue;const le=F(z,ie);(Y===null||G(le,Y))&&(Y=le,K={x:z,y:ie})}K&&K.x===R&&K.y===I&&(K=null)}else e:for(const D of M)for(const P of Z){if(P>=I)break;if(!_(D,P,V,ne)){K={x:D,y:P};break e}}if(K){const D=K.x-R,P=K.y-I;for(const B of C){const W=f(B.id);t.set(B.id,{x:W.x+D,y:W.y+P})}j.push(E)}for(const D of C){const P=f(D.id),{w:B,h:W}=u(D.id);S.push({x:P.x,y:P.y,w:B,h:W,...p(D.id)})}}return j}function v9(e,t,n){const r=new Map;for(const s of e){if(t.has(s.id)||!n(s.id))continue;const l=mi(s);(r.get(l)??r.set(l,[]).get(l)).push(s)}if(r.size===0)return e;for(const s of r.values())s.sort((l,c)=>l.id.localeCompare(c.id));return e.map(s=>{var p;if(t.has(s.id)||n(s.id))return s;const l=r.get(mi(s));if(!l)return s;const c=(p=s.data)==null?void 0:p.parentId,u=l.find(h=>h.id===c)??l[0],f=n(u.id);return{...s,position:{x:s.position.x+f.x-u.position.x,y:s.position.y+f.y-u.position.y}}})}function x9(e,t,n,r,s,l=!1,c){const p=Dl+Yf+1,h=8,m=1.75,y=200,v=.7,S=.01,b=$=>$u($,r,c),_=$=>n.get($)??t.get($),k=new Map;for(const $ of e){if(!_($.id))continue;const V=mi($),ne=k.get(V);ne?ne.push($):k.set(V,[$])}const j=[],E=new Set,C=new Set,R=s.size===0;for(const $ of[...k.keys()].sort()){const V=k.get($);let ne=1/0,ee=1/0,M=-1/0,Z=-1/0,K=!1;for(const W of V){const F=_(W.id),{w:G,h:re}=b(W.id);ne=Math.min(ne,F.x),ee=Math.min(ee,F.y),M=Math.max(M,F.x+G),Z=Math.max(Z,F.y+re),n.has(W.id)&&(K=!0)}const D=M-ne,P=Z-ee;C.add($);const B=s.get($);B&&(D>B.w+h||P>B.h+h)&&E.add($),s.set($,{w:D,h:P}),j.push({sid:$,members:V.map(W=>W.id),x:ne,y:ee,w:D,h:P,anchored:K,mass:1})}for(const $ of[...s.keys()])C.has($)||s.delete($);if(l||R)return[];let I=!1;for(let $=0;$<j.length&&!I;$++)for(let V=$+1;V<j.length;V++){const ne=j[$],ee=j[V];if(!(ne.anchored&&ee.anchored)&&Math.abs(ne.x+ne.w/2-(ee.x+ee.w/2))<(ne.w+ee.w)/2+61&&Math.abs(ne.y+ne.h/2-(ee.y+ee.h/2))<(ne.h+ee.h)/2+p){I=!0;break}}if(E.size===0&&!I)return[];if(E.size>0)for(const $ of j)E.has($.sid)&&($.mass=8);else for(const $ of j)$.mass=Math.max(1,$.w*$.h/(pi*Iu));const O=new Map(j.map($=>[$.sid,$.x])),H=new Map(j.map($=>[$.sid,$.y]));for(let $=0;$<y;$++){const V=new Map,ne=new Map;let ee=0;for(let M=0;M<j.length;M++)for(let Z=M+1;Z<j.length;Z++){const K=j[M],D=j[Z];if(K.anchored&&D.anchored)continue;const P=K.x+K.w/2,B=K.y+K.h/2,W=D.x+D.w/2,F=D.y+D.h/2,G=(K.w+D.w)/2+61-Math.abs(P-W),re=(K.h+D.h)/2+p-Math.abs(B-F);if(G<=0||re<=0)continue;const U=(pe,Ae)=>!pe.anchored&&!(Ae<0&&pe.x<=0),Y=(pe,Ae)=>!pe.anchored&&!(Ae<0&&pe.y<=0),z=(pe,Ae,fe)=>{const Se=pe===Ae,Ye=Se?K.sid<D.sid?-1:1:Math.sign(pe-Ae);return fe(K,Ye)||fe(D,-Ye)?Ye:Se&&(fe(K,-Ye)||fe(D,Ye))?-Ye:0},ie=z(P,W,U),le=z(B,F,Y),ge=ie!==0,Ne=le!==0;if(!ge&&!Ne)continue;const Ie=ge&&(!Ne||G*m<re),[Ge,Pe,Be,Te]=Ie?[ie,G,V,U]:[le,re,ne,Y],st=Te(K,Ge),de=Te(D,-Ge),ue=K.mass,se=D.mass,be=st?de?se/(ue+se):1:0,Le=de?st?ue/(ue+se):1:0,ce=Pe*v;Be.set(K.sid,(Be.get(K.sid)??0)+Ge*ce*be),Be.set(D.sid,(Be.get(D.sid)??0)-Ge*ce*Le),ee+=ce}for(const M of j)M.anchored||(M.x=Math.max(0,M.x+(V.get(M.sid)??0)),M.y=Math.max(0,M.y+(ne.get(M.sid)??0)));if(ee<S)break}const q=[];for(const $ of j){const V=$.x-O.get($.sid),ne=$.y-H.get($.sid);if(!(Math.abs(V)<1&&Math.abs(ne)<1)){for(const ee of $.members){if(n.has(ee))continue;const M=t.get(ee);M&&t.set(ee,{x:M.x+V,y:M.y+ne})}q.push($.sid)}}return q}function Fh(e,t,n){return!t.has(e)||n.has(e)}function b9(e,t,n,r){return!t.has(e)&&Fh(e,n,r)}function k9(e,t,n){const r={x:0,y:0};return t.set(e,r),n.add(e),r}function E2(e,t,n,r){n.set(e,t),r.delete(e)}const N9=200,S9=5*6e4,j9=6,_9=2*6e4;function Sh(e,t){if(t.size!==0)for(const n of Array.from(e.keys()))t.has(n)||e.delete(n)}function E9(e,t){let n=!1;for(const s of e)if(!t.has(s)){n=!0;break}if(!n)return e;const r=new Set;for(const s of e)t.has(s)&&r.add(s);return r}function C9(e){const t=new Set;for(const n of e)t.add(n.id),t.add(`group:${n.sessionId}`),n.kind==="root"&&t.add(_b(n.id));return t}function T9(e){const t=new Set;for(const n of e)t.add(n.id),n.kind==="root"&&t.add(_b(n.id));return t}function R9(e,t){let n=s6(e,t,BN);a6(e,t,BN)&&(n=!0);const r=[],s=l=>{r.push(l)};return e6(e,t,N9,S9,s)&&(n=!0),t6(e,t,j9,_9,s)&&(n=!0),{changed:n,forgotten:r}}const A9=300,C2=130,M9=160,T2=new WeakMap;function I9(e,t){let n=T2.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:pF(e.agents.values())},T2.set(e,n));const{byId:r,branches:s}=n;return l=>{let c=r.get(l.id);if(!c){const u=l.kind==="root"?s.get(l.sessionId):void 0;c=u?{...l,onOpenContext:t,branch:u}:{...l,onOpenContext:t},r.set(l.id,c)}return c}}function z0(e){const t=new Map;for(const n of e.agents.values())n.tools.length>0&&t.set(n.id,Math.min(4,n.tools.length));return t}function $9(e,t,n,r,s,l,c,u,f,p,h,m,y,v,S,b,_,k){var ee,M,Z,K;const j=[],E=[],C=I9(e,k);for(const D of e.agents.values()){if(!_.has(D.id))continue;const P=D.exitAt!=null,B=b!=null&&!b.has(D.id),W=[P?"rf-exiting":"",B?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,F=l.get(D.id);if(j.push({id:D.id,type:"agent",position:{x:0,y:0},data:C(D),className:W,ariaLabel:sq(D,t,S.has(D.id)),...F?{width:F.width,height:F.height}:null}),D.parentId&&_.has(D.parentId)){const U=Qh(D.sessionId),Y=P,z=S.size>0&&(S.has(D.id)||S.has(D.parentId)),ie=b!=null&&!b.has(D.id)&&!b.has(D.parentId),le=D.state==="active"?2:1.5,ge=z?le+1.5:le,Ne=Y?.2:ie?.12:1,Ie=["sess-edge",D.state==="active"?"sess-live":"sess-idle",Y?"rf-edge-exiting":"",z?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${D.parentId}->${D.id}`,source:D.parentId,target:D.id,animated:(D.state==="active"||z)&&!Y,type:"smoothstep",style:{"--session-hue":U,strokeWidth:`calc(${ge}px * var(--edge-k, 1))`,opacity:Ne,transition:"var(--edge-transition)"},className:Ie})}const G=D.kind==="root"?jf(D):null,re=G?hM(D.sessionId,G.at):null;if(G&&re&&!lF(re)){const U=_b(D.id),Y=Qh(D.sessionId),z=l.get(U);j.push({id:U,type:"recapNote",position:{x:0,y:0},data:{sessionId:D.sessionId,parentId:D.id,recap:G,noteKey:re,hue:Y},className:B?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${D.label}`,...z?{width:z.width,height:z.height}:null}),E.push({id:`e:recap:${D.id}`,source:U,target:D.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Y}})}}const R=z0(e),I=`${y}#lanes:${h9(R)}`,O=new Set(j.filter(D=>D.type==="recapNote").map(D=>D.id));for(const D of Array.from(h.keys()))hF(D)&&!O.has(D)&&!s.has(D)&&(h.delete(D),m.delete(D));const H=j.filter(D=>b9(D.id,s,h,m));if(H.length>0||I!==v.current){if(H.length>0){const D=v9(g9(j,E,{direction:"LR",pinned:s,measured:l,availableWidth:n,availableHeight:r,lanes:R}),s,P=>Fh(P,h,m)?void 0:h.get(P));for(const P of D)Fh(P.id,h,m)&&E2(P.id,P.position,h,m);w9(j,h,s,l,new Set(H.filter(P=>P.type!=="recapNote").map(P=>P.id)),R,{width:n,height:r});for(const P of H){if(P.type!=="recapNote")continue;const B=(ee=P.data)==null?void 0:ee.parentId;if(!B)continue;const W=s.get(B)??(Fh(B,h,m)?void 0:h.get(B));if(!W)continue;const F=((M=l.get(P.id))==null?void 0:M.width)??A9,G=((Z=l.get(P.id))==null?void 0:Z.height)??C2,re=((K=l.get(B))==null?void 0:K.height)??C2;E2(P.id,{x:W.x-M9-F,y:W.y+(re-G)/2},h,m)}}y9(j,h,s,l,R),v.current=I}const q=x9(j,h,s,l,c,!f||p,R);q.length>0&&u(q);const $=T9(e.agents.values());Sh(h,$),Sh(m,$),Sh(s,$),Sh(l,C9(e.agents.values()));const V=[];let ne=!1;for(const D of j){let P=s.get(D.id)??h.get(D.id);P||(P=k9(D.id,h,m),ne=!0),V.push({...D,position:P})}return ne&&(v.current=""),{nodes:V,edges:E}}const O9=1;function L9(e){return{id:e.id,name:e.name,inputPreview:e.inputPreview,startedAt:e.startedAt,endedAt:e.endedAt,ok:e.ok,errorPreview:e.errorPreview,usage:e.usage}}function P9(e,t,n){const r=e.agents.get(t);if(!r)return null;const s=[];for(const l of e.agents.values())l.sessionId===t&&s.push(l);return{schemaVersion:O9,exportedAt:n,sessionId:t,label:r.label,cwd:r.cwd,startedAt:r.startedAt,endedAt:r.endedAt,model:r.model,agents:s.map(l=>({id:l.id,kind:l.kind,label:l.label,parentId:l.parentId,state:l.state,startedAt:l.startedAt,endedAt:l.endedAt,model:l.model,cwd:l.cwd,usage:l.usage,prompts:l.prompts,tools:l.tools.map(L9)}))}}function D9(e,t){const n=(e||"session").replace(/[^a-z0-9._-]/gi,"_");return`${dn}-${n}-${t.slice(0,8)}.json`}function F9(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function q9(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.decks!="number"||typeof t.mine!="boolean")return null;const n=t.owner&&typeof t.owner=="object"?t.owner.port:null;return{path:typeof t.path=="string"&&t.path!==""?t.path:null,decks:t.decks,mine:t.mine,ownerPort:typeof n=="number"?n:null}}function B9(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function z9(e,t){const n=B9(e),r=(...c)=>[n?`${n} on the canvas`:null,...c,"layout, pins and selection"].filter(u=>u!==null),s="This cannot be undone.";if(!t)return{goes:r("the event log on disk — the file a restarted deck replays to rebuild what you see, and the file every deck on this machine shares unless one was told otherwise"),stays:[],final:s,confirm:"Clear everything"};if(!t.path)return{goes:r(),stays:[],final:`This deck keeps no event log, so nothing on disk changes — and nothing can bring the canvas back. ${s}`,confirm:"Clear everything"};if(!t.mine){const c=t.ownerPort===null?"another running deck owns that file":`the deck on port ${t.ownerPort} owns that file`,u=t.decks>2?`, one of ${t.decks} decks sharing it`:"";return{goes:r(),stays:[`the event log — ${c}${u}`,"restart this deck and the log replays back onto it"],final:null,confirm:"Clear this canvas"}}if(t.decks<=1)return{goes:r("this deck's event log — the file a restarted deck replays to rebuild what you see"),stays:[],final:s,confirm:"Clear everything"};const l=t.decks-1;return{goes:r(`the event log ${l===1?"1 other running deck shares":`${l} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[l===1?"what that deck shows, until it restarts — then it is gone there too":"what those decks show, until they restart — then it is gone there too"],final:s,confirm:"Clear everything"}}function U9({agentCount:e,onConfirm:t,onCancel:n}){const r=w.useRef(null),s=pn(n,{focusRef:r,layer:$6}),[l,c]=w.useState(null);w.useEffect(()=>{let m=!1;return fetch("/api/clear").then(y=>y.ok?y.json():null).then(y=>{m||c(q9(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=z9(e,l);return o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:s,className:"modal clear-confirm",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{className:"status-dot err","aria-hidden":!0}),o.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsxs("dl",{className:"cc-plan",children:[o.jsx("dt",{children:"Goes"}),o.jsx("dd",{children:u.map(m=>o.jsx("span",{children:m},m))}),o.jsx("dt",{children:"Stays"}),o.jsx("dd",{children:f.length>0?f.map(m=>o.jsx("span",{children:m},m)):o.jsx("span",{children:"nothing"})})]}),p&&o.jsx("p",{className:"cc-final",children:p}),o.jsxs("div",{className:"cc-actions",children:[o.jsx("button",{type:"button",ref:r,className:"btn",onClick:n,children:"Cancel"}),o.jsx("button",{type:"button",className:"btn danger",onClick:t,children:h})]})]})]})})}const H9="Press Esc first if a key does nothing.",W9=[{title:"Canvas",rows:[{cap:"Space",action:"pause or resume the stream",binds:[" "]},{cap:"J",action:"next agent",binds:["j","J"]},{cap:"K",action:"previous agent",binds:["k","K"]},{cap:"W",action:"the session waiting on you — oldest first, again for the next",binds:["w","W"]},{cap:"F",action:"fit every agent on screen",binds:["f","F"]},{cap:"Z",action:"zoom to the selected agent and its session",binds:["z","Z"]},{cap:"Delete",action:"take the selected card off the board — Undo brings it back",binds:["Delete"]},{cap:"R",action:"re-arrange the canvas and drop the pins",binds:["r","R"]},{cap:"C",action:"clear the canvas and the event log — asks first",binds:["c","C"]}]},{title:"Panels and dialogs",rows:[{cap:"U",action:"usage panel",binds:["u","U"]},{cap:"L",action:"session list",binds:["l","L"]},{cap:"D",action:"detail panel",binds:["d","D"]},{cap:"H",action:"usage history",binds:["h","H"]},{cap:"A",action:"Claude accounts, where Claude Code is installed",binds:["a","A"]},{cap:"S",action:"this machine — cores, memory, temperature",binds:["s","S"]},{cap:"B",action:"Browser Watch",binds:["b","B"]},{cap:"V",action:"the sound menu — volume, tones, notifications",binds:["v","V"]},{cap:"?",action:"this sheet",binds:["?"]}]},{title:"Settings",rows:[{cap:"M",action:"sound on or off",binds:["m","M"]},{cap:"T",action:"light or dark theme",binds:["t","T"]}]},{title:"Focus and selection",rows:[{cap:"Tab",action:"reach the agent cards",binds:[]},{cap:"Enter",action:"select the focused card",binds:["Enter"]},{cap:"Shift + Enter",action:"add the focused card to the selection",binds:["Enter"]},{cap:"Esc",action:"close what is open, deselect, release focus",binds:["Escape"]}]},{title:"Mouse",rows:[{cap:"drag",action:"move a node, and pin it where you dropped it",binds:[]},{cap:"shift-click",action:"add an agent to the selection",binds:[]},{cap:"click",action:"a card: go to it and its session",binds:[]},{cap:"double-click",action:"a card: its prompt, every tool call, tokens and timing",binds:[]},{cap:"hover",action:"zoomed out, a card's name, state and numbers",binds:[]},{cap:"click",action:"the topbar speaker opens volume and sound settings",binds:[]}]}];function V9({onClose:e,onTour:t}){const n=pn(e);return o.jsx("div",{className:"modal-backdrop",onClick:e,role:"presentation",children:o.jsxs("div",{ref:n,className:"modal key-help",onClick:r=>r.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[t&&o.jsxs("div",{className:"guide-door",children:[o.jsx("span",{children:"Eight pictures of what the deck shows."}),o.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),o.jsx("div",{className:"shortcuts",children:W9.map(r=>o.jsxs(w.Fragment,{children:[o.jsx("h3",{className:"kh-group",children:r.title}),r.rows.map(s=>o.jsxs("div",{className:"sc",children:[o.jsx("kbd",{children:s.cap}),o.jsx("span",{children:s.action})]},`${r.title}:${s.cap}:${s.action}`))]},r.title))}),o.jsx("p",{className:"kh-foot",children:H9})]})]})})}const G9=1024*1024,R2=5,e$=.8,U0=24,K9="agent-dag.soundCustom.done",Y9="agent-dag.soundCustom.needs-input",yu={done:K9,"needs-input":Y9};function Ou(e){if(e.kind!=="audio")return e;const{bytes:t,...n}=e;return n}function A2(e){return!e||!/^[a-zA-Z0-9._-]{1,96}$/.test(e)?null:e}function X9(e){return{done:A2(e(yu.done)),"needs-input":A2(e(yu["needs-input"]))}}function Z9(e,t){return{done:e.done===t?null:e.done,"needs-input":e["needs-input"]===t?null:e["needs-input"]}}function Q9(e){return e.done&&e.done===e["needs-input"]?e.done:null}const J9={wav:"audio/wav",wave:"audio/wav",mp3:"audio/mpeg",ogg:"audio/ogg",oga:"audio/ogg",webm:"audio/webm",m4a:"audio/mp4",mp4:"audio/mp4"},t$=new Set(["audio/wav","audio/x-wav","audio/mpeg","audio/mp3","audio/ogg","audio/webm","audio/mp4"]);function n$(e,t){const n=t.toLowerCase().split(";")[0].trim();if(t$.has(n))return n;const r=e.toLowerCase().split(".").pop()??"";return J9[r]??n}function M2(e,t){const n=n$(e.name,e.type);if(!t$.has(n))return"Use a WAV, MP3, OGG, or browser-recorded audio file.";if(!Number.isFinite(e.size)||e.size<=0)return"The audio file is empty.";if(e.size>G9)return"Audio must be 1 MB or smaller.";if(t!==void 0){if(!Number.isFinite(t)||t<=0)return"The audio file could not be decoded.";if(t>R2)return`Audio must be ${R2} seconds or shorter.`}return null}function H0(e){return e>=U0?`There are already ${U0} custom sounds. Delete one first.`:null}function eV(e,t){const n=e.indexOf(t);return n<0?null:e[n+1]??e[n-1]??null}function tV(e){let t=0;for(const n of e)for(let r=0;r<n.length;r++)t=Math.max(t,Math.abs(n[r]));return t<=1e-5?1:Math.min(16,e$/t)}function r$(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}async function nV(e,t,n=r$()){var p;const r=((p=e.name)==null?void 0:p.trim())||"Custom sound",s=M2({name:r,type:e.type,size:e.size});if(s)throw new Error(s);const l=await e.arrayBuffer();let c;try{c=await t(l.slice(0))}catch{throw new Error("The audio file could not be decoded.")}const u=M2({name:r,type:e.type,size:e.size},c.duration);if(u)throw new Error(u);const f=Array.from({length:c.numberOfChannels},(h,m)=>c.getChannelData(m));return{id:n,name:r.replace(/\.(wav|wave|mp3|ogg|oga|webm|m4a|mp4)$/i,"")||"Custom sound",kind:"audio",mime:n$(r,e.type),duration:c.duration,normalizationGain:tV(f),bytes:l}}function rV(e,t=r$()){const n=e.name.trim()||"Custom voice",r=e.text.trim();if(!r)throw new Error("Enter the words this voice should say.");const s=Number.isFinite(e.rate)?e.rate:1,l=Number.isFinite(e.pitch)?e.pitch:1;return{id:t,name:n,kind:"tts",text:r.slice(0,180),voiceURI:e.voiceURI??"",rate:Math.min(2,Math.max(.5,s)),pitch:Math.min(2,Math.max(.5,l))}}const sV="ccdeck-notification-audio",aV=2,ws="assets",Bs="summaries";function Ku(){return typeof window<"u"?window.ccdeckNotificationAudio??null:null}function oV(){return new Promise((e,t)=>{const n=indexedDB.open(sV,aV);n.onupgradeneeded=r=>{const s=n.result,l=s.objectStoreNames.contains(ws)?n.transaction.objectStore(ws):s.createObjectStore(ws,{keyPath:"id"});if(s.objectStoreNames.contains(Bs))return;const c=s.createObjectStore(Bs,{keyPath:"id"});if(r.oldVersion<1)return;const u=l.openCursor();u.onsuccess=()=>{const f=u.result;f&&(c.put(Ou(f.value)),f.continue())}},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error??new Error("Could not open local audio storage."))})}async function Yu(e,t,n){const r=await oV();try{return await new Promise((s,l)=>{const c=r.transaction(e,t),u=n(c),f=()=>l(c.error??new Error("Local audio storage failed."));c.oncomplete=()=>s(u?u.result:void 0),c.onerror=f,c.onabort=f})}finally{r.close()}}async function iV(){const e=Ku();return e?e.list():typeof indexedDB>"u"?[]:await Yu([Bs],"readonly",t=>t.objectStore(Bs).getAll())??[]}async function lV(e){const t=Ku();return t?t.get(e):typeof indexedDB>"u"?null:await Yu([ws],"readonly",n=>n.objectStore(ws).get(e))??null}async function I2(e){const t=Ku();if(t){await t.put(e);return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Yu([ws,Bs],"readwrite",n=>{n.objectStore(ws).put(e),n.objectStore(Bs).put(Ou(e))})}async function cV(e,t){const n=Ku();if(n){const r=await n.get(e);r&&await n.put({...r,name:t});return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Yu([ws,Bs],"readwrite",r=>{const s=r.objectStore(ws),l=s.get(e);l.onsuccess=()=>{const c=l.result;if(!c)return;const u={...c,name:t};s.put(u),r.objectStore(Bs).put(Ou(u))}})}async function uV(e){const t=Ku();if(t){await t.remove(e);return}typeof indexedDB>"u"||await Yu([ws,Bs],"readwrite",n=>{n.objectStore(ws).delete(e),n.objectStore(Bs).delete(e)})}const qh=["done","needs-input"],dV=[{id:"two",label:"Two notes",notes:[{at:0,hz:740,ms:90},{at:.085,hz:440,ms:150}]},{id:"arc",label:"Descent",notes:[{at:0,hz:988,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:440,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:740,ms:55},{at:.055,hz:740,ms:55},{at:.165,hz:440,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:988,ms:110},{at:0,hz:740,ms:110},{at:.1,hz:440,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:740,ms:120},{at:.11,hz:440,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:740,ms:55},{at:.06,hz:440,ms:90}]}],hV=[{id:"two",label:"Two notes",notes:[{at:0,hz:440,ms:90},{at:.085,hz:740,ms:150}]},{id:"arc",label:"Ascent",notes:[{at:0,hz:440,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:988,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:440,ms:55},{at:.055,hz:440,ms:55},{at:.165,hz:740,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:440,ms:110},{at:.1,hz:740,ms:170},{at:.1,hz:988,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:440,ms:120},{at:.11,hz:740,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:440,ms:55},{at:.06,hz:740,ms:90}]}],ok={done:dV,"needs-input":hV},wr="two";function W0(e,t){const n=ok[e];return n.find(r=>r.id===t)??n.find(r=>r.id===wr)??n[0]}function s$(e,t){return ok[e].some(r=>r.id===t)?t:wr}W0("done",wr).notes,W0("needs-input",wr).notes;const $2=.04,a$=.24,oi=0,Gl=100,lf=5,gi=50;function Kl(e){if(!Number.isFinite(e))return gi;const t=Math.round(e/lf)*lf;return Math.min(Gl,Math.max(oi,t))}function o$(e){if(e==null)return gi;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Kl(Number(t)):gi}function V0(e){const t=Kl(e),n=$2+(a$-$2)*(t/Gl);return Math.round(n*1e4)/1e4}function fV(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(V0(e)*r*1e4)/1e4}const pV=160,mV="agent-dag.soundLevel.done",gV="agent-dag.soundLevel.needs-input",yV="agent-dag.soundFigure.done",wV="agent-dag.soundFigure.needs-input",i$={done:mV,"needs-input":gV},Bh={done:yV,"needs-input":wV},G0={done:{level:gi,figure:wr},"needs-input":{level:gi,figure:wr}};function vV(e){const t=n=>({level:o$(e(i$[n])),figure:s$(n,e(Bh[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const O2={Stop:"done",Notification:"needs-input"};function xV(e,t){var r;if(t)return null;const n=(r=e==null?void 0:e.payload)==null?void 0:r.hook_event_name;return typeof n!="string"?null:Object.hasOwn(O2,n)?O2[n]:null}function bV(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null,r=!1;const s=()=>e.enabled()?r&&(n==null?void 0:n.state)==="running"?"ready":"locked":"off",l=()=>{var m;return(m=e.onState)==null?void 0:m.call(e,s())};function c(){var m;if(!(!t||r))try{n=n??new t,(m=n.resume)==null||m.call(n).then(l,()=>{}),r=!0,l()}catch{}}function u(m,y,v=y.figure){if(!n||n.state!=="running")return!1;const S=W0(m,v),b=fV(y.level,S),_=n.currentTime;for(const k of S.notes){const j=n.createOscillator(),E=n.createGain();j.type=S.type??"sine",j.frequency.value=k.hz;const C=_+k.at,R=C+k.ms/1e3;E.gain.setValueAtTime(1e-4,C),E.gain.exponentialRampToValueAtTime(b,C+.012),E.gain.exponentialRampToValueAtTime(1e-4,R),j.connect(E).connect(n.destination),j.start(C),j.stop(R+.02)}return!0}async function f(m,y){if(!e.loadCustom)return"unavailable";let v;try{v=await e.loadCustom(m)}catch{return"unavailable"}if(!v)return"missing";if(v.kind==="tts"){if(typeof window>"u"||!("speechSynthesis"in window)||typeof SpeechSynthesisUtterance>"u")return"unavailable";const b=new SpeechSynthesisUtterance(v.text),_=window.speechSynthesis.getVoices();b.voice=_.find(k=>k.voiceURI===v.voiceURI)??null,b.rate=v.rate,b.pitch=v.pitch,b.volume=Math.min(1,V0(y.level)/a$);try{return window.speechSynthesis.cancel(),window.speechSynthesis.speak(b),"played"}catch{return"unavailable"}}if(!n||n.state!=="running")return"locked";let S;try{S=await n.decodeAudioData(v.bytes.slice(0))}catch{return"broken"}try{const b=n.createBufferSource(),_=n.createGain();b.buffer=S;const k=v.normalizationGain*(V0(y.level)/e$);return _.gain.setValueAtTime(Math.max(1e-4,k),n.currentTime),b.connect(_).connect(n.destination),b.start(n.currentTime),"played"}catch{return"unavailable"}}function p(m,y=!1){var b,_;if(!y&&!e.enabled())return!1;const v=(((b=e.prefs)==null?void 0:b.call(e))??G0)[m]??G0[m],S=((_=e.customSelection)==null?void 0:_.call(e)[m])??null;return S&&e.loadCustom?(f(S,v).then(k=>{var j;k==="played"||k==="locked"||((k==="missing"||k==="broken")&&((j=e.onCustomFailure)==null||j.call(e,m,S)),u(m,{...v,figure:wr},wr))}),!0):!n||n.state!=="running"?!1:u(m,v)}function h(m,y=gi){return f(m,{level:Kl(y),figure:wr}),!0}return{unlock:c,play:p,previewCustom:h,state:s,get context(){return n}}}const kV="With no deck tab open, get a notification wherever a sound would have played.",NV="With the ccdeck window closed, get a notification wherever a sound would have played.";function SV(e){return e?NV:kV}const jV="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",L2="Get notified when you're away from this tab.";function _V(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:L2};case"default":return{status:null,ask:!0,ok:!1,note:L2};case"denied":return{status:"Blocked",ask:!1,ok:!1,note:"Your browser is blocking them; only its own site settings can undo that. You'll still be told once this tab is closed."};default:return{status:"Unavailable",ask:!1,ok:!1,note:"This browser cannot show them. You'll still be told once this tab is closed."}}}function hu(e=typeof navigator>"u"?"":navigator.userAgent){return/\bccdeck-desktop\/\d/.test(e)}const P2={done:"Turn finished","needs-input":"Claude is asking"},EV={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function CV({onClose:e,soundOn:t,onToggleSound:n,prefs:r,onLevel:s,onFigure:l,onPreview:c,openerRef:u,customAssets:f,customSelections:p,onBuiltInSelected:h,onCustomSelected:m,onImportCustom:y,onCreateVoice:v,onRenameCustom:S,onPreviewCustom:b,onDeleteCustom:_,notifyOn:k,onToggleNotify:j,notifyVetoed:E,notifyPermission:C,onAskNotify:R}){var Ae;const I=_V(C),O=hu(),H=k&&!E&&!O,[q,$]=w.useState(""),[V,ne]=w.useState("Custom voice"),[ee,M]=w.useState("Your turn"),[Z,K]=w.useState(""),[D,P]=w.useState("1"),[B,W]=w.useState("1"),[F,G]=w.useState([]),[re,U]=w.useState(!1),Y=w.useRef(null),z=w.useRef(null),ie=Q9(p),le=((Ae=f.find(fe=>fe.id===ie))==null?void 0:Ae.name)??"the same custom sound",ge=f.length,Ne=H0(ge),Ie=Ne!==null,Ge=Ie?{"aria-disabled":!0,"aria-describedby":"sm-custom-full"}:{},[Pe,Be]=w.useState(null),Te=w.useRef(0),st=w.useRef(new Map),de=w.useRef(null);w.useEffect(()=>{if(!Pe)return;const fe=window.setTimeout(()=>Be(null),4e3);return()=>window.clearTimeout(fe)},[Pe]),w.useEffect(()=>{if(typeof window>"u"||!("speechSynthesis"in window))return;const fe=()=>{const Se=window.speechSynthesis.getVoices();G(Se),K(Ye=>{var qe;return Ye||((qe=Se[0])==null?void 0:qe.voiceURI)||""})};return fe(),window.speechSynthesis.addEventListener("voiceschanged",fe),()=>window.speechSynthesis.removeEventListener("voiceschanged",fe)},[]);const ue=async fe=>{$("");try{await fe()}catch(Se){$(Se instanceof Error?Se.message:"Custom audio could not be saved.")}},se=(fe,Se)=>{const Ye=Date.now(),qe=Cu({armedFor:Pe,target:fe,armedAt:Te.current,now:Ye,gapMs:Mu});if(qe==="arm"){Be(fe),Te.current=Ye;return}if(qe==="ignore")return;Be(null);const ke=eV(f.map(Re=>Re.id),fe);ue(async()=>{var ze;await _(fe);const Re=document.activeElement;Re!==Se&&!A0((Re==null?void 0:Re.tagName)??null)||(ze=ke?st.current.get(ke):de.current)==null||ze.focus()})},be=()=>{var fe;z.current!==null&&clearTimeout(z.current),z.current=null,((fe=Y.current)==null?void 0:fe.state)==="recording"&&Y.current.stop()},Le=async()=>{var Se;if(Ie)return;if($(""),!((Se=navigator.mediaDevices)!=null&&Se.getUserMedia)||typeof MediaRecorder>"u"){$("Microphone recording is unavailable in this browser.");return}let fe;try{fe=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{$("Microphone access was denied or unavailable.");return}if(Y.current){fe.getTracks().forEach(Ye=>Ye.stop());return}try{const Ye=["audio/webm;codecs=opus","audio/ogg;codecs=opus","audio/mp4"].find(Re=>MediaRecorder.isTypeSupported(Re)),qe=new MediaRecorder(fe,Ye?{mimeType:Ye}:void 0),ke=[];Y.current=qe,qe.ondataavailable=Re=>{Re.data.size&&ke.push(Re.data)},qe.onerror=()=>$("Recording failed. Please try again."),qe.onstop=()=>{fe.getTracks().forEach(rt=>rt.stop()),z.current!==null&&clearTimeout(z.current),z.current=null;const Re=Y.current===qe;if(Re&&(Y.current=null),U(!1),!Re||!ke.length)return;const ze=qe.mimeType.split(";")[0],Fe=ze==="audio/mp4"?"m4a":ze==="audio/ogg"?"ogg":"webm",We=new File(ke,`Recorded voice.${Fe}`,{type:ze});ue(()=>y(We))},qe.start(200),U(!0),z.current=setTimeout(be,4400)}catch{Y.current=null,fe.getTracks().forEach(Ye=>Ye.stop()),$("This browser cannot record a supported audio format.")}};w.useEffect(()=>()=>{z.current!==null&&clearTimeout(z.current);const fe=Y.current;Y.current=null,(fe==null?void 0:fe.state)==="recording"&&fe.stop()},[]);const ce=pn(e,{popover:!0}),pe=w.useRef(e);return pe.current=e,w.useEffect(()=>{const fe=Se=>{var qe,ke;const Ye=Se.target;Ye&&((qe=ce.current)!=null&&qe.contains(Ye)||(ke=u.current)!=null&&ke.contains(Ye)||pe.current())};return window.addEventListener("pointerdown",fe,!0),()=>window.removeEventListener("pointerdown",fe,!0)},[ce,u]),o.jsxs("div",{ref:ce,id:"sound-menu",className:"sound-menu",role:"dialog","aria-label":"Sound settings",children:[o.jsxs("div",{className:"sm-switches",children:[o.jsxs("label",{className:"sm-switch",children:[o.jsx("span",{className:"sm-switch-label",id:"sm-sound-label",children:"Sounds"}),o.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-labelledby":"sm-sound-label",className:"switch",onClick:n,title:"A tone when a turn finishes, and when Claude asks for something",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"sm-setting",children:[o.jsxs("label",{className:"sm-switch",children:[o.jsx("span",{className:"sm-switch-label",id:"sm-notify-label",children:"Notifications while closed"}),o.jsx("button",{type:"button",role:"switch","aria-checked":k,"aria-labelledby":"sm-notify-label",className:"switch",onClick:j,title:"With no deck tab open, a notification wherever a sound would play",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsx("p",{className:"sm-note",children:E?jV:SV(O)})]})]}),H&&o.jsxs("section",{className:"sm-channel","aria-labelledby":"sm-channel-name",children:[o.jsxs("div",{className:"sm-channel-head",children:[o.jsx("h3",{className:"sm-channel-name",id:"sm-channel-name",children:"Browser notifications"}),I.ask?o.jsx("button",{type:"button",className:"btn sm-channel-action",onClick:R,children:"Enable"}):o.jsxs("span",{className:"sm-channel-state","data-ok":I.ok||void 0,children:[I.ok&&o.jsx("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M1.5 5.2 3.9 7.6 8.5 2.4"})}),I.status]})]}),o.jsx("p",{className:"sm-note",children:I.note})]}),!t&&o.jsx("span",{id:"sm-preview-note",className:"vis-hidden",children:"Plays even when Sounds is off, so you can set a tone before turning sounds back on."}),o.jsx("div",{className:"sm-tones",children:qh.map(fe=>{const Se=r[fe],Ye=`sm-level-${fe}`,qe=`sm-figure-${fe}`;return o.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${fe}`,children:[o.jsxs("div",{className:"sm-tone-head",children:[o.jsx("h3",{className:"sm-tone-name",id:`sm-name-${fe}`,children:P2[fe]}),o.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(fe),"aria-label":`Hear the ${P2[fe].toLowerCase()} tone`,title:t?"Play this tone now, at what it is set to":"Plays even when Sounds is off","aria-describedby":t?void 0:"sm-preview-note",children:[o.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":!0,children:o.jsx("path",{d:"M3 1.6v8.8l7-4.4z"})}),"Hear it"]})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:Ye,children:"Volume"}),o.jsx("input",{id:Ye,type:"range",min:oi,max:Gl,step:lf,value:Se.level,onChange:ke=>s(fe,Number(ke.target.value)),style:{"--sm-level":`${(Se.level-oi)/(Gl-oi)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[Se.level,"%"]})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:qe,children:"Tone"}),o.jsxs("select",{id:qe,className:"sm-select",value:p[fe]?`custom:${p[fe]}`:Se.figure,onChange:ke=>{const Re=ke.target.value;Re.startsWith("custom:")?m(fe,Re.slice(7)):(h(fe),l(fe,Re))},children:[ok[fe].map(ke=>o.jsx("option",{value:ke.id,children:ke.label},ke.id)),f.length>0&&o.jsx("optgroup",{label:"Custom",children:f.map(ke=>o.jsx("option",{value:`custom:${ke.id}`,children:ke.name},ke.id))})]})]}),o.jsx("p",{className:"sm-note",children:EV[fe]})]},fe)})}),ie&&o.jsxs("p",{className:"sm-note",role:"status",children:["Both tones use “",le,"”. They may be harder to tell apart."]}),o.jsxs("section",{className:"sm-custom","aria-labelledby":"sm-custom-title",children:[o.jsxs("div",{className:"sm-custom-head",children:[o.jsx("h3",{className:"sm-tone-name",id:"sm-custom-title",children:"Custom sounds"}),o.jsxs("span",{children:[ge," of ",U0,", kept on this machine"]})]}),Ie&&o.jsx("p",{className:"sm-note",id:"sm-custom-full",children:Ne}),o.jsxs("div",{className:"sm-custom-actions",children:[o.jsxs("label",{className:"sm-custom-card sm-file",children:[o.jsxs("span",{className:"sm-custom-card-copy",children:[o.jsx("strong",{children:"Import audio"}),o.jsx("span",{children:"WAV, MP3 or OGG"})]}),o.jsx("span",{className:"btn sm-custom-action","aria-hidden":"true",children:"Choose file"}),o.jsx("input",{ref:de,type:"file",accept:"audio/wav,audio/x-wav,audio/mpeg,audio/mp3,audio/ogg,.wav,.mp3,.ogg",...Ge,onClick:fe=>{Ie&&fe.preventDefault()},onChange:fe=>{var Ye;const Se=(Ye=fe.target.files)==null?void 0:Ye[0];fe.currentTarget.value="",Se&&!Ie&&ue(()=>y(Se))}})]}),o.jsxs("div",{className:"sm-custom-card",children:[o.jsxs("span",{className:"sm-custom-card-copy",children:[o.jsx("strong",{children:"Record a clip"}),o.jsx("span",{children:re?"Recording…":"Up to 5 seconds"})]}),re?o.jsx("button",{type:"button",className:"btn sm-custom-action",onClick:be,children:"Stop & save"}):o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>void Le(),children:"Record"})]})]}),o.jsxs("details",{className:"sm-voice",children:[o.jsxs("summary",{...Ge,onClick:fe=>{const Se=fe.currentTarget.parentElement;Ie&&Se&&!Se.open&&fe.preventDefault()},children:[o.jsx("span",{children:"Spoken voice"}),o.jsx("span",{children:"Create from text"})]}),o.jsxs("div",{className:"sm-voice-fields",children:[o.jsxs("label",{children:[o.jsx("span",{children:"Name"}),o.jsx("input",{className:"ap-manage-input",value:V,maxLength:80,onChange:fe=>ne(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Text"}),o.jsx("input",{className:"ap-manage-input",value:ee,maxLength:180,onChange:fe=>M(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Voice"}),o.jsxs("select",{className:"sm-select",value:Z,onChange:fe=>K(fe.target.value),children:[o.jsx("option",{value:"",children:"System default"}),F.map(fe=>o.jsx("option",{value:fe.voiceURI,children:fe.name},fe.voiceURI))]})]}),o.jsxs("div",{className:"sm-voice-pair",children:[o.jsxs("label",{children:[o.jsx("span",{children:"Rate"}),o.jsx("input",{className:"ap-manage-input",type:"number",min:"0.5",max:"2",step:"0.1",value:D,onChange:fe=>P(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Pitch"}),o.jsx("input",{className:"ap-manage-input",type:"number",min:"0.5",max:"2",step:"0.1",value:B,onChange:fe=>W(fe.target.value)})]})]}),o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>{Ie||ue(async()=>{await v({name:V,text:ee,voiceURI:Z,rate:parseFloat(D),pitch:parseFloat(B)}),M("Your turn")})},children:"Add spoken voice"})]})]}),f.length>0&&o.jsx("div",{className:"sm-custom-list",children:f.map(fe=>o.jsxs("div",{className:"sm-custom-item",children:[o.jsx("input",{className:"ap-manage-input","aria-label":`Rename ${fe.name}`,defaultValue:fe.name,maxLength:80,onBlur:Se=>{if(!Se.target.value.trim()){Se.target.value=fe.name;return}ue(()=>S(fe.id,Se.target.value))},onKeyDown:Se=>{Se.key==="Enter"&&Se.currentTarget.blur()}}),o.jsx("span",{children:fe.kind==="audio"?`${fe.duration.toFixed(1)}s`:"Voice"}),o.jsx("button",{type:"button",className:"btn sm-custom-icon","aria-label":`Play ${fe.name}`,onClick:()=>b(fe.id),children:"Play"}),o.jsx("button",{type:"button",ref:Se=>{Se?st.current.set(fe.id,Se):st.current.delete(fe.id)},className:`btn sm-custom-icon${Pe===fe.id?" armed":""}`,onKeyDown:Se=>{Se.repeat&&Se.preventDefault()},onClick:Se=>se(fe.id,Se.currentTarget),"aria-label":Pe===fe.id?`Confirm deleting ${fe.name}`:`Delete ${fe.name}`,title:Pe===fe.id?"Press again to delete this sound. It cannot be brought back.":"Delete this sound",children:Pe===fe.id?"Confirm":"Delete"})]},fe.id))}),q&&o.jsx("p",{className:"sm-custom-error",role:"alert",children:q})]}),o.jsxs("p",{className:"sm-foot",children:[o.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const l$="agent-dag.character-enabled",c$="agent-dag.fm-volume",D2="agent-dag.fm-source",TV=[{value:"claude-fm",label:"🎧 Claude FM"},{group:"📻 Lofi Girl",value:"lofi-relax",label:"📚 Relax / study"},{group:"📻 Lofi Girl",value:"lofi-game",label:"🎮 Chill / game"},{group:"📻 Lofi Girl",value:"lofi-vibe",label:"🌅 Vibe / chill"},{group:"📻 Lofi Girl",value:"lofi-sleep",label:"💤 Sleep / chill"},{group:"📻 Radio Mix",value:"radio-mix",label:"📡 Live radio mix"},{group:"📻 Best of Nostalgia",value:"best-of-nostalgia",label:"📼 Best of nostalgia live"},{group:"📻 The Good Life Radio",value:"good-life-radio",label:"🌴 The Good Life Radio"},{group:"☕ Cafe Music BGM",value:"cafe-music-bgm",label:"☕ Cafe music BGM"}];function RV(e){return e==="lofi-relax"||e==="lofi-game"||e==="lofi-vibe"||e==="lofi-sleep"||e==="radio-mix"||e==="best-of-nostalgia"||e==="good-life-radio"||e==="cafe-music-bgm"?e:"claude-fm"}function AV(e){return e!=="0"}function MV(){return AV(yr(l$))}function IV(e){return o$(e)}function $V(){return IV(yr(c$))}const F2="agent-dag.fm-custom-stations",q2="agent-dag.fm-muted",K0="custom:",OV=/^UC[A-Za-z0-9_-]{22}$/,LV=/^[A-Za-z0-9_-]{11}$/,ik=/^[A-Za-z0-9_-]{1,80}$/,PV=/\.(mp3|aac|ogg)$/i,DV=/\.m3u8$/i,u$=2048,Lu=80;function yi(e){return`${K0}${e}`}function Yl(e){if(!e.startsWith(K0))return null;const t=e.slice(K0.length);return ik.test(t)?t:null}function B2(e){return Yl(e)??e}function FV(e){return e?"This station could not be played. Check its link, pick another, or pick it again to retry.":"This station is not live right now. Pick another, or pick it again later to retry."}function lk(e){var c,u;const t=e.trim();if(t.length>u$)return null;let n;try{n=new URL(t)}catch{return null}if(n.protocol!=="https:"||n.username||n.password)return null;const r=n.toString(),s=n.hostname.toLowerCase();if(s==="youtube.com"||s==="www.youtube.com"||s==="m.youtube.com"){if(n.port)return null;const f=(c=/^\/channel\/([^/]+)(?:\/live)?\/?$/.exec(n.pathname))==null?void 0:c[1];if(f&&OV.test(f))return{kind:"youtube-channel",url:r,channel:f};const p=(u=/^\/@([^/]+)\/live\/?$/.exec(n.pathname))==null?void 0:u[1];if(p&&/^[A-Za-z0-9._-]{1,64}$/.test(p))return{kind:"youtube-handle",url:r,handle:p};if(n.pathname==="/watch"){const h=n.searchParams.get("v")??"";if(LV.test(h))return{kind:"youtube-video",url:r,video:h}}return null}return DV.test(n.pathname)?{kind:"direct-audio",url:r,format:"hls"}:PV.test(n.pathname)?{kind:"direct-audio",url:r,format:"audio"}:null}function qV(e){return e==="1"}function BV(e){if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];const n=new Set,r=[];for(const s of t){if(!s||typeof s!="object")continue;const l=typeof s.id=="string"?s.id:"",c=typeof s.name=="string"?s.name.trim():"",u=typeof s.url=="string"?s.url.trim():"",f=lk(u);!ik.test(l)||n.has(l)||!c||c.length>Lu||!f||(n.add(l),r.push({id:l,name:c,url:f.url}))}return r}function zV(e,t,n){const r=Yl(e??"");return r&&t.some(s=>s.id===r)?yi(r):n(e)}function UV(e,t){return e===yi(t)?"claude-fm":e}function HV(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function WV(e,t,n=HV()){const r=e.trim(),s=lk(t);return!r||r.length>Lu||!ik.test(n)||!s?null:{id:n,name:r,url:s.url}}const Sl=["light","dark"],VV={light:"Light",dark:"Dark"},z2=TV,jl="Give the station a name.",GV="Use an https YouTube live or channel link, or a .mp3, .aac, .ogg or .m3u8 stream.";function KV({theme:e}){return o.jsx("span",{className:"appearance-preview","data-swatch":e,children:o.jsxs("svg",{viewBox:"0 0 112 56","aria-hidden":!0,focusable:"false",children:[o.jsx("rect",{className:"tp-canvas",width:"112",height:"56"}),o.jsx("rect",{className:"tp-surface",width:"112",height:"7"}),o.jsx("rect",{className:"tp-rule",y:"7",width:"112",height:"1"}),o.jsx("rect",{className:"tp-surface",y:"8",width:"25",height:"48"}),o.jsx("rect",{className:"tp-rule",x:"25",y:"8",width:"1",height:"48"}),o.jsx("rect",{className:"tp-card",x:"36.5",y:"27.5",width:"28",height:"14",rx:"2.5"}),o.jsx("rect",{className:"tp-tag",x:"39.5",y:"25.5",width:"13",height:"4",rx:"2"}),o.jsx("rect",{className:"tp-card",x:"76.5",y:"14.5",width:"29",height:"20",rx:"2.5"}),o.jsx("rect",{className:"tp-rule",x:"81",y:"23",width:"20",height:"2",rx:"1"}),o.jsx("rect",{className:"tp-accent",x:"81",y:"23",width:"12",height:"2",rx:"1"})]})})}function YV({theme:e,onTheme:t,characterEnabled:n,onToggleCharacter:r,fmVolume:s,onFmVolume:l,fmMuted:c,onFmMuted:u,fmSource:f,onFmSource:p,customFmStations:h,unavailableFmStations:m,onAddFmStation:y,onRenameFmStation:v,onRemoveFmStation:S,onClose:b}){var ue;const _=pn(b),k=[...z2.map(se=>({...se,label:m.has(se.value)?`${se.label} · not live`:se.label,unavailable:m.has(se.value)})),...h.map(se=>({group:"🎵 Your stations",value:yi(se.id),label:m.has(se.id)?`${se.name} · unavailable`:se.name,unavailable:m.has(se.id)}))],j=k.some(se=>se.value===f&&se.unavailable),E=[];k.forEach((se,be)=>{const Le=E[E.length-1];Le&&Le.group===se.group?Le.indexes.push(be):E.push({group:se.group,indexes:[be]})});const[C,R]=w.useState(!1),[I,O]=w.useState(()=>Math.max(0,k.findIndex(se=>se.value===f))),[H,q]=w.useState(!1),[$,V]=w.useState(""),[ne,ee]=w.useState(""),[M,Z]=w.useState(""),[K,D]=w.useState(!1),[P,B]=w.useState(""),[W,F]=w.useState(""),G=w.useRef(null),re=w.useRef(null),U=w.useRef(null),Y=w.useRef(null),z=w.useRef(null),ie=Yl(f),le=ie?h.find(se=>se.id===ie):void 0;w.useEffect(()=>{const se=k.findIndex(be=>be.value===f);O(se<0?0:se)},[f,h,m]),w.useEffect(()=>{D(!1),B((le==null?void 0:le.name)??"")},[le==null?void 0:le.id,le==null?void 0:le.name]),w.useEffect(()=>{var se;C&&((se=document.getElementById(`appearance-fm-option-${I}`))==null||se.scrollIntoView({block:"nearest"}))},[I,C]),w.useEffect(()=>{if(!C)return;const se=be=>{var ce,pe;const Le=be.target;!((ce=G.current)!=null&&ce.contains(Le))&&!((pe=z.current)!=null&&pe.contains(Le))&&R(!1)};return document.addEventListener("pointerdown",se),()=>document.removeEventListener("pointerdown",se)},[C]);const ge=se=>{const be=se.relatedTarget;be&&!se.currentTarget.contains(be)&&R(!1)},Ne=se=>{var Le;const be=k[se];be&&(O(se),p(be.value),R(!1),(Le=G.current)==null||Le.focus())},Ie=se=>{if(L6(se.key)){if(!C)return;se.preventDefault(),se.stopPropagation(),R(!1);return}if(se.key==="Tab"){R(!1);return}if(se.key==="Enter"||se.key===" "){se.preventDefault(),C?Ne(I):R(!0);return}se.key!=="ArrowDown"&&se.key!=="ArrowUp"&&se.key!=="Home"&&se.key!=="End"||(se.preventDefault(),R(!0),O(be=>se.key==="Home"?0:se.key==="End"?k.length-1:Math.min(k.length-1,Math.max(0,be+(se.key==="ArrowDown"?1:-1)))))},Ge=()=>{var se;return(se=G.current)==null?void 0:se.focus()},Pe=se=>{var Le,ce;if(se.preventDefault(),!$.trim()){Z(jl),(Le=re.current)==null||Le.focus();return}const be=WV($,ne);if(!be){Z(GV),(ce=U.current)==null||ce.focus();return}y(be),p(yi(be.id)),V(""),ee(""),Z(""),q(!1),Ge()},Be=se=>{var be;if(se.preventDefault(),!!ie){if(!P.trim()){F(jl),(be=Y.current)==null||be.focus();return}v(ie,P),D(!1),Ge()}},Te=se=>{var ce;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(se.key))return;se.preventDefault();const Le=(Sl.indexOf(e)+(se.key==="ArrowLeft"||se.key==="ArrowUp"?-1:1)+Sl.length)%Sl.length;t(Sl[Le]),(ce=se.currentTarget.querySelectorAll('[role="radio"]')[Le])==null||ce.focus()},st=se=>{var Le;if(se.key===" "){se.stopPropagation();return}if(Sf(se.target)||se.key!=="t"&&se.key!=="T"||se.ctrlKey||se.metaKey||se.altKey)return;se.preventDefault(),se.stopPropagation();const be=e==="dark"?"light":"dark";t(be),se.target.getAttribute("role")==="radio"&&((Le=se.currentTarget.querySelectorAll('[role="radio"]')[Sl.indexOf(be)])==null||Le.focus())},de=se=>{const be=k[se],Le="unavailable"in be&&be.unavailable;return o.jsxs("div",{className:"appearance-source-option",role:"option",id:`appearance-fm-option-${se}`,"aria-selected":f===be.value,"data-highlighted":I===se||void 0,"data-unavailable":Le||void 0,onMouseEnter:()=>O(se),onClick:()=>Ne(se),children:[o.jsx("span",{children:be.label}),f===be.value&&o.jsx("span",{"aria-hidden":!0,children:"✓"})]},be.value)};return Mn.createPortal(o.jsx("div",{className:"modal-backdrop appearance-backdrop",onClick:b,role:"presentation",children:o.jsxs("div",{ref:_,id:"appearance-menu",className:"modal appearance-menu appearance-modal",role:"dialog","aria-modal":"true","aria-labelledby":"appearance-title",onClick:se=>se.stopPropagation(),onKeyDown:st,children:[o.jsxs("div",{className:"appearance-head",children:[o.jsxs("div",{className:"appearance-heading",children:[o.jsx("h2",{id:"appearance-title",className:"appearance-title",children:"Appearance"}),o.jsx("p",{className:"appearance-subtitle",children:"Tune the deck to your workspace."})]}),o.jsx("button",{type:"button",className:"glyph-btn appearance-close",onClick:b,"aria-label":"Close appearance settings",title:"Close (Esc)",children:"×"})]}),o.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-theme-caption",children:[o.jsxs("div",{className:"appearance-caption",children:[o.jsxs("div",{children:[o.jsx("h3",{id:"appearance-theme-caption",children:"Color theme"}),o.jsx("p",{className:"appearance-section-note",children:"Choose how the dashboard looks."})]}),o.jsx("kbd",{className:"appearance-key","aria-hidden":!0,title:"Press T anywhere to switch themes",children:"T"})]}),o.jsx("div",{className:"appearance-themes",role:"radiogroup","aria-labelledby":"appearance-theme-caption","aria-keyshortcuts":"T",onKeyDown:Te,children:Sl.map(se=>o.jsxs("button",{type:"button",className:"appearance-theme",role:"radio","aria-checked":e===se,tabIndex:e===se?0:-1,onClick:()=>t(se),children:[o.jsx(KV,{theme:se}),o.jsxs("span",{className:"appearance-theme-name",children:[VV[se],o.jsx("svg",{className:"appearance-check",viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:o.jsx("path",{d:"M2.5 6.4 4.9 8.7 9.5 3.6"})})]})]},se))})]}),o.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-fm-caption",children:[o.jsx("div",{className:"appearance-caption",children:o.jsx("h3",{id:"appearance-fm-caption",children:"Music source"})}),o.jsxs("div",{className:"appearance-controls",children:[o.jsxs("div",{className:"appearance-source-row",children:[o.jsx("label",{htmlFor:"appearance-fm-source",children:"Station"}),o.jsxs("div",{className:`appearance-source-picker${C?" is-open":""}`,onBlur:ge,children:[o.jsxs("button",{ref:G,type:"button",id:"appearance-fm-source",className:"appearance-source-trigger",role:"combobox","aria-haspopup":"listbox","aria-expanded":C,"aria-controls":C?"appearance-fm-source-list":void 0,"aria-activedescendant":C?`appearance-fm-option-${I}`:void 0,"aria-describedby":"appearance-fm-source-note",onClick:()=>R(se=>!se),onKeyDown:Ie,children:[o.jsx("span",{children:((ue=k.find(se=>se.value===f))==null?void 0:ue.label)??z2[0].label}),o.jsx("svg",{viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:o.jsx("path",{d:"m2.5 4.5 3.5 3 3.5-3"})})]}),C&&o.jsx("div",{ref:z,id:"appearance-fm-source-list",className:"appearance-source-list",role:"listbox","aria-label":"Music stations",children:E.map((se,be)=>se.group?o.jsxs("div",{role:"group","aria-labelledby":`appearance-fm-group-${be}`,children:[o.jsx("div",{id:`appearance-fm-group-${be}`,className:"appearance-source-group",role:"presentation",children:se.group}),se.indexes.map(de)]},`group-${be}`):se.indexes.map(de))})]})]}),o.jsx("span",{id:"appearance-fm-source-note",className:"vis-hidden",children:"Changing station starts live playback automatically."}),o.jsx("p",{className:"appearance-fm-status",role:"status",children:j?FV(Yl(f)!==null):""}),o.jsxs("div",{className:"appearance-station-manage",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action","aria-expanded":H,onClick:()=>{q(se=>!se),Z("")},children:H?"Cancel":"+ Add station"}),le&&!K&&o.jsxs("span",{className:"appearance-station-edit",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action",onClick:()=>{B(le.name),F(""),D(!0)},children:"Rename"}),o.jsx("button",{type:"button",className:"btn danger appearance-station-action",onClick:()=>{S(le.id),Ge()},children:"Remove"})]})]}),H&&o.jsxs("form",{className:"appearance-station-form",onSubmit:Pe,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:re,className:"ap-manage-input",value:$,onChange:se=>V(se.target.value),"aria-invalid":M===jl||void 0,"aria-describedby":M===jl?"appearance-station-error":void 0,maxLength:Lu,autoFocus:!0})]}),o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Link"}),o.jsx("input",{ref:U,className:"ap-manage-input",value:ne,onChange:se=>ee(se.target.value),placeholder:"https://…","aria-invalid":M!==""&&M!==jl||void 0,"aria-describedby":M&&M!==jl?"appearance-station-error":void 0,inputMode:"url",autoComplete:"off",spellCheck:!1,maxLength:u$})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Add"}),M&&o.jsx("p",{id:"appearance-station-error",className:"appearance-station-error",role:"alert",children:M})]}),le&&K&&o.jsxs("form",{className:"appearance-station-form is-rename",onSubmit:Be,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:Y,className:"ap-manage-input",value:P,onChange:se=>B(se.target.value),"aria-invalid":W!==""||void 0,"aria-describedby":W?"appearance-rename-error":void 0,maxLength:Lu,autoFocus:!0})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Save"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{D(!1),Ge()},children:"Cancel"}),W&&o.jsx("p",{id:"appearance-rename-error",className:"appearance-station-error",role:"alert",children:W})]}),o.jsxs("label",{className:"appearance-row",children:[o.jsx("span",{className:"appearance-row-label",id:"appearance-character-label",children:"Show character on minimap"}),o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":n,"aria-labelledby":"appearance-character-label","aria-describedby":"appearance-character-note",onClick:r,children:o.jsx("span",{className:"switch-knob"})}),o.jsx("span",{id:"appearance-character-note",className:"vis-hidden",children:"Shows the animated minimap character and enables music playback."})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:"appearance-fm-volume",children:"Volume"}),o.jsx("input",{id:"appearance-fm-volume",type:"range",min:oi,max:Gl,step:lf,value:s,"aria-describedby":"appearance-fm-volume-note",onChange:se=>l(Number(se.target.value)),style:{"--sm-level":`${(s-oi)/(Gl-oi)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[s,"%"]})]}),o.jsxs("label",{className:"appearance-row",children:[o.jsx("span",{className:"appearance-row-label",id:"appearance-fm-mute-label",children:"Mute music"}),o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":c,"aria-labelledby":"appearance-fm-mute-label",onClick:u,children:o.jsx("span",{className:"switch-knob"})})]})]}),o.jsx("span",{id:"appearance-fm-volume-note",className:"vis-hidden",children:"Controls live music volume."})]})]})}),document.body)}const Y0="https://www.youtube-nocookie.com";function XV(e,t,n){const r=new URLSearchParams({...n?{}:{channel:e},enablejsapi:"1",autoplay:"1",playsinline:"1",rel:"0",modestbranding:"1",origin:t});return`${Y0}/embed/${n?encodeURIComponent(n):"live_stream"}?${r.toString()}`}function _l(e,t=[]){return JSON.stringify({event:"command",func:e,args:t})}function ZV(e="claude-fm"){return JSON.stringify({event:"listening",id:e,channel:"widget"})}const QV=[1,3],JV=[0,2],eG=[2,5,100,101,150];function tG(e){let t=e;if(typeof e=="string")try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;const{event:n,info:r}=t;if(n==="onReady")return{kind:"ready"};if(n==="onError"){const s=typeof r=="number"?r:Number(r==null?void 0:r.errorCode);return Number.isFinite(s)?{kind:"error",code:s}:null}if(n==="onStateChange"||n==="infoDelivery"){const s=typeof r=="number"?r:r==null?void 0:r.playerState;return typeof s!="number"||!Number.isFinite(s)?null:QV.includes(s)?{kind:"playing",playing:!0}:JV.includes(s)?{kind:"playing",playing:!1}:null}return null}const d$=["......aaaaaa......","....aa......aa....","...a..bbbbbs..a...","...cpcbbbbbscpc...","...cpcbebbescpc...","...cpcbbbbbscpc...","...cpcbbbbbscpc...","....ccbbbbbscc....","....bbbbbbbbbs....","....bbbbbbbbbs....","......bbbbbs......","......bb..bs......","......bb..bs......","......bb..bs......"],U2=18,nG=d$.length,h$=new Set(["a","c","p"]);function Xf(e=d$){const t=[];return e.forEach((n,r)=>{let s=0;for(;s<n.length;){const l=n[s];if(l==="."){s+=1;continue}let c=1;for(;s+c<n.length&&n[s+c]===l;)c+=1;t.push({x:s,y:r,w:c,cell:l}),s+=c}}),t}const ii=148,H2=6e3,rG=16e3,f$=46,eo=34;function sG(e,t,n=ii){let r=-Math.round(t()*n);if(Math.abs(r-e)<eo){const s=e-eo>=-n?-eo:eo;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return{to:r,ms:Math.round(Math.abs(r-e)*f$)}}function aG(e){return Math.round(H2+e()*(rG-H2))}const W2=[{kind:"stroll",weight:44},{kind:"tidy",weight:17},{kind:"kick",weight:17},{kind:"sit",weight:12},{kind:"watch",weight:16},{kind:"leave",weight:7},{kind:"fish",weight:12},{kind:"skip",weight:10}];function oG(e){const t=W2.reduce((r,s)=>r+s.weight,0);let n=e()*t;for(const r of W2)if(n-=r.weight,n<0)return r.kind;return"stroll"}const iG=720,lG=260,cG=620,uG=220,V2=520,p$=1600,G2=7e3,dG=15e3,K2=6e3,hG=14e3;function El(e,t,n=ii){let r=-Math.round(t()*n);if(Math.abs(r-e)<eo){const s=e-eo>=-n?-eo:eo;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return r}const hn=(e,t)=>Math.round(Math.abs(t-e)*f$),fG=120,jh=0;function pG(e,t){const n=r=>({kind:"litter",at:t,...r});return[{x:t,prop:n({}),act:"walk",ms:hn(e,t)},{x:t,prop:n({}),act:"stoop",ms:iG},{x:jh,prop:n({held:!0}),act:"carry",ms:hn(t,jh)},{x:jh,prop:n({held:!0}),act:"windup",ms:lG},{x:jh,prop:n({held:!0,leaving:!0}),act:"toss",ms:cG}]}function mG(e,t){const n=t>e?1:-1,r=t-n*Math.min(15,Math.abs(t-e)),s=(l={})=>({kind:"ball",at:t,...l});return[{x:r,prop:s(),act:"walk",ms:hn(e,r)},{x:r,prop:s(),act:"windup",ms:uG,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"kick",ms:V2,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"stand",ms:p$-V2}]}const m$=640;function gG(e,t,n){const r=Math.max(-70,Math.min(-20,t)),s={x:r,prop:null,facing:"left"};return[{x:r,prop:null,act:"walk",ms:hn(e,r)},{...s,act:"sit",ms:600},{...s,act:"cast",ms:900},{...s,act:"fish",ms:6e3+Math.round(n()*4e3)},{...s,act:"reel",ms:1200},{...s,act:"stow",ms:500},{...s,act:"stand",ms:400},{x:0,prop:null,act:"walk",ms:hn(r,0)}]}function yG(e,t,n){const r=Math.max(-110,Math.min(-30,t)),s={x:r,prop:null};return[{...s,act:"walk",ms:hn(e,r)},{...s,act:"skip-ready",ms:500},{...s,act:"skip",ms:m$*(6+Math.floor(n()*5))},{...s,act:"skip-rest",ms:600},{...s,act:"stand",ms:350},{x:0,prop:null,act:"walk",ms:hn(r,0)}]}function wG(e,t,n){return[{x:t,prop:null,act:"walk",ms:hn(e,t)},{x:t,prop:null,act:"sit",ms:Math.round(K2+n()*(hG-K2))},{x:t,prop:null,act:"stand",ms:400}]}function vG(e,t,n){t=Math.max(-110,Math.min(0,t));const r=()=>({kind:"scope",at:t,held:!0});return[{x:t,prop:null,act:"walk",ms:hn(e,t)},{x:t,prop:r(),act:"watch",ms:Math.round(G2+n()*(dG-G2))},{x:t,prop:r(),act:"scope-pack",ms:480},{x:t,prop:null,act:"stand",ms:240}]}function Yx(e,t,n){return e.facing?e.facing:e.act==="watch"||e.act==="scope-pack"?"left":e.x===t?n:e.x>t?"right":"left"}const xG=1500,bG=e=>Math.round(1e3*Math.sqrt(2*e/xG)),kG=115,NG=e=>Math.round(e/kG*1e3),SG=620,jG=200,_G=760,EG=600,CG=240;function TG(e,t,n){const s=-(t.ledgeSpan??ii),l=bG(t.ledgeH),c=NG(t.ledgeH),u=n(),f=n(),p=-Math.round(u*t.floorSpan),h=-Math.round(f*t.floorSpan);return[{x:s,act:"walk",prop:null,ms:hn(e,s)},{x:s,act:"peer",prop:null,ms:SG},{x:s,act:"fall",prop:null,ms:l,place:"floor"},{x:s,act:"land",prop:null,ms:jG,place:"floor"},{x:p,act:"walk",prop:null,ms:hn(s,p),place:"floor",floorFrac:u},{x:h,act:"walk",prop:null,ms:hn(p,h),place:"floor",floorFrac:f},{x:s,act:"walk",prop:null,ms:hn(h,s),place:"floor"},{x:s,act:"lasso",prop:null,ms:_G,place:"floor"},{x:s,act:"rope-throw",prop:null,ms:EG,place:"floor"},{x:s,act:"rope-catch",prop:null,ms:CG,place:"floor"},{x:s,act:"climb",prop:null,ms:c},{x:s,act:"pull-up",prop:null,ms:480}]}function RG(e,t,n){const r=(n==null?void 0:n.ledgeSpan)??ii;switch(oG(t)){case"tidy":return pG(e,El(e,t,r));case"kick":return mG(e,El(e,t,r));case"sit":return wG(e,El(e,t,r),t);case"watch":return vG(e,El(e,t,r),t);case"fish":return gG(e,El(e,t,r),t);case"skip":return yG(e,El(e,t,r),t);case"leave":{if(!n||!(n.ledgeH>0)||!(n.floorSpan>0))break;return TG(e,n,t)}}const l=sG(e,t,r);return[{x:l.to,prop:null,act:"walk",ms:l.ms}]}const AG=[".xx.","xxxx",".xx."],MG=["..xx..",".xsxx.","xssxxx","xxxxsx",".xxxx.","..xx.."],IG=["...xx...............","..xaax..............",".xaallx.............","xaallllx............",".xllllllx...........","..xllllllx..........","...xllllllx.........","....xllllllxx.......",".....xllllxsxx..xx..","......xllxsssx.xllxx",".......xxssssxxxllxx","........xssssssxx...",".........xssssx.....","..........xxxx......","..........xax.......",".........xxxxx......","........xx.x.xx.....","........xl.x.lx.....",".......xl..x..lx....",".......xl..x..lx....","......xl...x...lx...","......xl...x...lx...",".....xl....x....lx..","....xxx...xxx...xxx."],Xx={litter:AG,ball:MG,scope:IG},g$=["bob","sway","groove"],Y2=9e3,$G=16e3,y$=1e3,OG=.08;function LG(e,t){const n=g$.filter(l=>l!==e),r=n[Math.min(n.length-1,Math.floor(t()*n.length))],s=(t()*2-1)*OG;return{dance:r,beatMs:Math.round(y$*(1+s))}}function PG(e){return Math.round(Y2+e()*($G-Y2))}const DG=["...hhhhhh...","...hhhhhh...","...kkkkkk...","hhhhhhhhhhhh"],FG=3,qG=-1,X0=11,X2=9,BG=420;function zG(e,t,n){const r=t==="right"?n-e-18:e-18;return(t==="right"?1:-1)*Math.min(BG,Math.max(0,r))}const UG=260,HG=200;function WG(e,t,n){const r=(h,m=hn(e,h))=>({x:h,prop:null,act:"walk",ms:m,place:"floor"});if(!n||n.height<=0)return[r(t)];const s=Math.min(e,t);if(Math.max(e,t)<=n.left||s>=n.right)return[r(t)];const c=t>e,u=c?n.left:n.right,f=c?n.right:n.left,p={place:"floor",riser:n.height,prop:null};return[r(u,hn(e,u)),{...p,x:u,act:"mount",ms:UG},{...p,x:f,act:"walk",ms:hn(u,f)},{x:f,prop:null,act:"dismount",ms:HG,place:"floor"},{x:t,prop:null,act:"walk",ms:hn(f,t),place:"floor"}]}function Z2(e){let t=null,n=null,r=0,s=0,l=!1;const c=()=>{t!==null&&clearTimeout(t),t=null},u=()=>{l||e.hidden||!n||t!==null||(s=performance.now(),t=setTimeout(()=>{t=null;const p=n;n=null,p==null||p()},r))},f=()=>{e.hidden&&t!==null?(r=Math.max(0,r-(performance.now()-s)),c()):e.hidden||u()};return e.addEventListener("visibilitychange",f),{schedule(p,h){l||(c(),n=p,r=Math.max(0,h),u())},dispose(){l=!0,c(),n=null,e.removeEventListener("visibilitychange",f)}}}const VG={"claude-fm":"Claude FM","lofi-relax":"Lofi Girl relax/study","lofi-game":"Lofi Girl chill/game","lofi-vibe":"Lofi Girl vibe/chill","lofi-sleep":"Lofi Girl sleep/chill","radio-mix":"Radio Mix Live","best-of-nostalgia":"Best of Nostalgia Live","good-life-radio":"The Good Life Radio Live","cafe-music-bgm":"Cafe Music BGM Live"};function GG(e,t){return t&&yi(t.id)===e?t.name:Yl(e)?"Custom FM":VG[e]}const KG={"claude-fm":null,"lofi-relax":null,"lofi-game":null,"lofi-vibe":null,"lofi-sleep":null,"radio-mix":"/api/live-radio-mix","best-of-nostalgia":"/api/best-of-nostalgia","good-life-radio":"/api/good-life-radio","cafe-music-bgm":"/api/cafe-music-bgm"};function Zx(e,t){var r;const n=((r=e[0])==null?void 0:r.length)??0;return o.jsx("svg",{viewBox:`0 0 ${n} ${e.length}`,shapeRendering:"crispEdges","aria-hidden":!0,children:Xf(e).map(s=>o.jsx("rect",{x:s.x,y:s.y,width:s.w,height:1,fill:s.cell==="s"?"var(--fm-prop-shadow, var(--bg))":s.cell==="l"?"var(--fm-prop-light, var(--text))":s.cell==="a"?"var(--accent)":void 0},`${t}${s.y}-${s.x}`))})}const Qx={e:"fm-eye",s:"fm-shade",p:"fm-pad"},cf=Xf().filter(e=>!h$.has(e.cell)),YG=Xf().filter(e=>h$.has(e.cell)),Q2=cf.filter(e=>e.cell==="e"),XG=Xf(DG),ZG=cf.filter(e=>e.y<X0&&e.cell!=="e").map(e=>{if(e.y!==8&&e.y!==9)return e;const t=Math.max(6,e.x);return{...e,x:t,w:Math.max(0,Math.min(12,e.x+e.w)-t)}}).filter(e=>e.w>0),QG={left:cf.filter(e=>e.y>=X0&&e.x<X2),right:cf.filter(e=>e.y>=X0&&e.x>=X2)},J2={litter:Zx(Xx.litter,"litter"),ball:Zx(Xx.ball,"ball"),scope:Zx(Xx.scope,"scope")};function JG(e){try{return new URL(e).host}catch{return"the station's server"}}const eK=w.memo(function({fetchImpl:t,volume:n,muted:r=!1,source:s="claude-fm",playRequest:l=0,customStation:c,onAvailabilityChange:u}){const[f,p]=w.useState(null),[h,m]=w.useState(!1),[y,v]=w.useState(!1),[S,b]=w.useState(!1),_=w.useRef(l),k=w.useRef(null),j=w.useRef(null),[E,C]=w.useState(0),[R,I]=w.useState(0),[O,H]=w.useState(null),[q,$]=w.useState(null),[V,ne]=w.useState({x:0,drop:0}),[ee,M]=w.useState("ledge"),[Z,K]=w.useState("left"),[D,P]=w.useState(0),B=w.useRef(null),[W,F]=w.useState(()=>document.hidden);w.useEffect(()=>{const de=new Set,ue=()=>{var se;if(document.hidden){for(const be of((se=B.current)==null?void 0:se.getAnimations({subtree:!0}))??[])if(be.playState==="running"||be.pending){const Le=be.currentTime;be.pause(),Le!==null&&(be.currentTime=Le),de.add(be)}}else{for(const be of de)be.playState==="paused"&&be.play();de.clear()}F(document.hidden)};return ue(),document.addEventListener("visibilitychange",ue),()=>document.removeEventListener("visibilitychange",ue)},[f,h]);const[G,re]=w.useState(null),[U,Y]=w.useState(y$),[z,ie]=w.useState(()=>{var de;return((de=window.matchMedia)==null?void 0:de.call(window,"(prefers-reduced-motion: reduce)").matches)??!1});w.useEffect(()=>{var se;const de=(se=window.matchMedia)==null?void 0:se.call(window,"(prefers-reduced-motion: reduce)");if(!de)return;const ue=()=>ie(de.matches);return ue(),de.addEventListener("change",ue),()=>de.removeEventListener("change",ue)},[]);const le=w.useRef(null),ge=w.useCallback(()=>{var ue;(ue=j.current)==null||ue.destroy(),j.current=null;const de=k.current;de&&(de.pause(),de.removeAttribute("src"),de.load(),k.current=null)},[]),Ne=w.useCallback(de=>{var ue,se;(se=(ue=le.current)==null?void 0:ue.contentWindow)==null||se.postMessage(de,Y0)},[]),Ie=w.useRef(n);Ie.current=n;const Ge=w.useRef(r);Ge.current=r;const Pe=w.useCallback((de,ue,se)=>{ge();const be=new Audio;be.preload="none",be.volume=Ie.current/100,be.muted=Ge.current,k.current=be,v(!0),b(!0);const Le=()=>k.current===be,ce=()=>{ge(),v(!1),b(!1)},pe=()=>{Le()&&(ce(),m(!0),u==null||u(se,!0))},Ae=fe=>{if(Le()){if(fe instanceof DOMException&&fe.name==="NotAllowedError"){ce();return}pe()}};be.addEventListener("playing",()=>{Le()&&(b(!0),u==null||u(se,!1))}),be.addEventListener("ended",()=>{Le()&&ce()}),be.addEventListener("error",pe,{once:!0}),ue&&!be.canPlayType("application/vnd.apple.mpegurl")?nb(async()=>{const{default:fe}=await import("./hls-BFpXDghs.js");return{default:fe}},[]).then(({default:fe})=>{if(!Le())return;if(!fe.isSupported()){pe();return}const Se=new fe;j.current=Se,Se.on(fe.Events.ERROR,(Ye,qe)=>{qe.fatal&&pe()}),Se.on(fe.Events.MEDIA_ATTACHED,()=>Se.loadSource(de)),Se.on(fe.Events.MANIFEST_PARSED,()=>{be.play().catch(Ae)}),Se.attachMedia(be)},pe):(be.src=de,be.play().catch(Ae))},[u,ge]);if(w.useEffect(()=>{y&&(Ne(_l("setVolume",[n])),Ne(_l(r?"mute":"unMute")),k.current&&(k.current.volume=n/100,k.current.muted=r))},[n,r,y,Ne]),w.useEffect(()=>{let de=!0;const ue=t??fetch,se=_.current!==l;_.current=l,p(null),m(!1),v(se),b(se),ge();const be=c&&yi(c.id)===s?lk(c.url):null;if(be)return be.kind==="direct-audio"?(p({live:!0,channel:"",audio:be.url,hls:be.format==="hls"}),u==null||u(s,!1),se&&Pe(be.url,be.format==="hls",s),()=>{de=!1}):(ue(`/api/fm-station?url=${encodeURIComponent(be.url)}`).then(pe=>pe.ok?pe.json():null).then(pe=>{de&&(pe!=null&&pe.channel||pe!=null&&pe.video?(p({live:!0,channel:pe.channel??"",video:pe.video??void 0}),u==null||u(s,!1)):(m(!0),u==null||u(s,!0)))}).catch(()=>{de&&(m(!0),u==null||u(s,!0))}),()=>{de=!1});if(Yl(s))return m(!0),u==null||u(s,!0),()=>{de=!1};const Le=s,ce=KG[Le];if(ce)ue(ce).then(pe=>pe.ok?pe.json():null).then(pe=>{de&&(pe!=null&&pe.video&&p({live:!0,channel:"",video:pe.video}),u==null||u(s,!(pe!=null&&pe.video)))}).catch(()=>{de&&(u==null||u(s,!0))});else if(Le!=="claude-fm"){const pe=Le.replace("lofi-","");ue(`/api/lofi-girl?station=${encodeURIComponent(pe)}`).then(Ae=>Ae.ok?Ae.json():null).then(Ae=>{de&&(Ae!=null&&Ae.video&&p({live:!0,channel:"",video:Ae.video}),u==null||u(s,!(Ae!=null&&Ae.video)))}).catch(()=>{de&&(u==null||u(s,!0))})}else ue("/api/claude-fm").then(pe=>pe.ok?pe.json():null).then(pe=>{if(!de)return;const Ae=!!(pe!=null&&pe.live&&(pe!=null&&pe.channel));Ae&&p({live:!0,channel:pe.channel}),u==null||u(s,!Ae)}).catch(()=>{de&&(u==null||u(s,!0))});return()=>{de=!1}},[c==null?void 0:c.id,c==null?void 0:c.url,t,u,l,s,Pe,ge]),w.useEffect(()=>()=>ge(),[ge]),w.useEffect(()=>{if(!y)return;const de=ue=>{var be;if(ue.origin!==Y0||ue.source!==((be=le.current)==null?void 0:be.contentWindow))return;const se=tG(ue.data);if(se){if(se.kind==="ready"){Ne(_l("setVolume",[Ie.current])),Ne(_l(r?"mute":"unMute")),Ne(_l("playVideo"));return}if(se.kind==="playing"){b(se.playing);return}eG.includes(se.code)&&(v(!1),b(!1),m(!0),u==null||u(s,!0))}};return window.addEventListener("message",de),()=>window.removeEventListener("message",de)},[y,r,u,Ne,s]),w.useEffect(()=>{var ze;if(!f||h||z)return;const de=Z2(document);let ue=0;C(Fe=>ue=Fe);let se=null,be=0,Le=0;const ce=Fe=>{var yt,Ot;const[We,...rt]=Fe;if(!We){se=null,H(null),$(null),qe();return}H(We.act),$(We.prop),M(We.place??"ledge"),P(We.riser??0);const dt=ue,ct=Se(We);if(We.act==="kick"){const zt=(Ot=(yt=B.current)==null?void 0:yt.querySelector('.fm-prop[data-prop="ball"]'))==null?void 0:Ot.getBoundingClientRect();zt&&ne({x:zG(zt.x,Yx(We,dt,"left"),window.innerWidth),drop:Math.max(48,window.innerHeight-zt.y+24)})}Le=We.act==="walk"?Math.max(hn(dt,ct),fG):We.ms,We.act==="carry"&&(Le=hn(dt,ct)),I(Le),K(zt=>Yx({...We,x:ct},dt,zt)),C(ct),ue=ct,se=We,be=Date.now(),de.schedule(()=>ce(rt),Le)},pe=()=>{const Fe=B.current,We=Fe==null?void 0:Fe.querySelector(".fm-sprite"),rt=Fe==null?void 0:Fe.parentElement;if(!Fe||!We||!rt)return null;const dt=Fe.getBoundingClientRect(),ct=rt.getBoundingClientRect(),yt=ct.right-dt.right,Ot=ct.width-yt*2-We.offsetWidth;return Ot>0?Ot:null},Ae=()=>{const Fe=B.current,We=Fe==null?void 0:Fe.querySelector(".fm-walker"),rt=pe();if(!Fe||!We||rt==null)return;const dt=Fe.getBoundingClientRect().bottom-We.getBoundingClientRect().bottom;if(dt>0)return{ledgeH:dt,floorSpan:rt}},fe=()=>{const Fe=B.current,We=document.querySelector(".autofit-chip");if(!Fe||!We)return null;const rt=Fe.getBoundingClientRect(),dt=We.getBoundingClientRect();return dt.width<=0||dt.height<=0?null:{left:dt.left-rt.right,right:dt.right-rt.right,height:dt.height}},Se=Fe=>{const We=(Fe.place??"ledge")==="floor",rt=We?pe()??ii:ii,dt=We&&Fe.floorFrac!=null?-Math.round(Fe.floorFrac*rt):Fe.x;return Math.max(-rt,Math.min(0,dt))},Ye=()=>{if(!se)return;const Fe=Se(se);Fe!==ue&&(I(Math.max(0,be+Le-Date.now())),K(We=>Yx({...se,x:Fe},ue,We)),C(Fe),ue=Fe)},qe=()=>{de.schedule(()=>{const Fe=RG(ue,Math.random,Ae()),We=Fe.some(ct=>ct.place==="floor")?fe():null;let rt=ue;const dt=Fe.flatMap(ct=>{const yt=rt;if(rt=ct.x,!(ct.place==="floor"&&ct.act==="walk"))return[ct];const Ot=WG(yt,ct.x,We),zt=Ot.length-1;return ct.floorFrac==null?Ot:Ot.map((Xt,Dt)=>Dt===zt?{...Xt,floorFrac:ct.floorFrac}:Xt)});ce(dt)},aG(Math.random))},ke=(ze=B.current)==null?void 0:ze.parentElement,Re=typeof ResizeObserver>"u"?null:new ResizeObserver(Ye);return ke&&Re&&Re.observe(ke),qe(),()=>{de.dispose(),Re==null||Re.disconnect(),M("ledge"),C(Fe=>Math.max(-ii,Math.min(0,Fe))),I(0),H(null),$(null),P(0)}},[f,h,z]),w.useEffect(()=>{if(!S||z){re(null);return}const de=Z2(document),ue=se=>{const be=LG(se,Math.random);re(be.dance),Y(be.beatMs),de.schedule(()=>ue(be.dance),PG(Math.random))};return ue(null),()=>de.dispose()},[S,z]),!f||h)return null;const Be=()=>{if(f.audio){if(y){ge(),v(!1),b(!1);return}Pe(f.audio,f.hls===!0,s);return}if(!y){v(!0),b(!0);return}const de=!S;b(de),Ne(_l(de?"playVideo":"pauseVideo")),de||v(!1)},Te=GG(s,c),st=f.audio?JG(f.audio):"YouTube";return o.jsxs("div",{ref:B,className:"fm","data-suspended":W?"":void 0,"data-place":ee,style:{"--fm-beat":`${U}ms`},children:[q&&!q.held&&o.jsx("div",{className:"fm-prop","data-prop":q.kind,"data-leaving":q.leaving?"":void 0,style:{"--fm-prop-x":`${q.at}px`,"--fm-roll-to":`${V.x}px`,"--fm-ball-drop":`${V.drop}px`,"--fm-ball-flight-ms":`${p$}ms`,"--fm-ball-turn":Z==="right"?"1080deg":"-1080deg"},children:J2[q.kind]}),(O==="lasso"||O==="rope-throw"||O==="rope-catch"||O==="climb"||O==="pull-up")&&o.jsxs("div",{className:"fm-rope","data-act":O,style:{"--fm-rope-x":`${E}px`,"--fm-rope-ms":`${R}ms`},children:[o.jsx("div",{className:"fm-rope-line"}),o.jsxs("svg",{className:"fm-rope-hook",viewBox:"0 0 9 9",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("path",{d:"M4 8V3H3V1H1V3H0V5H2V4H3V6H5V4H6V5H8V3H7V1H5V3H4"}),o.jsx("rect",{className:"fm-rope-knot",x:"3",y:"6",width:"3",height:"2"})]})]}),o.jsxs("div",{className:"fm-walker","data-act":O??void 0,"data-place":ee,"data-facing":Z,style:{"--fm-x":`${E}px`,"--fm-walk-ms":`${R}ms`,"--fm-riser":`${D}px`,"--fm-skip-beat":`${m$}ms`},children:[(q==null?void 0:q.held)&&o.jsx("div",{className:"fm-held","data-prop":q.kind,"data-toss":q.leaving?"":void 0,children:J2[q.kind]}),["cast","fish","reel","stow"].includes(O)&&o.jsxs("svg",{className:"fm-fishing",viewBox:"0 0 24 32",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsxs("g",{children:[o.jsx("path",{d:"M24 11H22V9H20V7H18V5H16V3H13V2H8"}),o.jsx("rect",{className:"fm-fishing-grip",x:"21",y:"9",width:"3",height:"3"})]}),o.jsxs("g",{className:"fm-fishing-line",children:[o.jsx("path",{d:"M8 2V26"}),o.jsxs("g",{className:"fm-float",children:[o.jsx("rect",{x:"7",y:"25",width:"3",height:"2"}),o.jsx("rect",{x:"8",y:"24",width:"1",height:"1"})]})]}),o.jsx("path",{className:"fm-ripple",d:"M3 28H6M10 28H14M5 30H12"})]}),["skip-ready","skip","skip-rest"].includes(O)&&o.jsxs("svg",{className:"fm-skipping-rope",viewBox:"0 0 26 26",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("path",{className:"fm-skip-back",d:"M5 18H3V8H5V5H8V2H18V5H21V8H23V18H21"}),o.jsx("path",{className:"fm-skip-forward",d:"M5 18H3V14H5V11H8V9H18V11H21V14H23V18H21"}),o.jsx("path",{className:"fm-skip-front",d:"M5 18H3V21H5V23H8V25H18V23H21V21H23V18H21"}),o.jsx("path",{className:"fm-skip-return",d:"M5 18H3V19H8V20H18V19H23V18H21"}),o.jsx("path",{className:"fm-skip-handles",d:"M5 17V19M21 17V19"})]}),o.jsx("button",{type:"button",className:"fm-sprite","data-playing":S?"":void 0,"data-dance":S?G??g$[0]:void 0,onClick:Be,title:S?`Stop ${Te}`:`Play ${Te} — streams from ${st}`,"aria-label":S?`Stop ${Te}`:`Play ${Te}`,children:o.jsxs("svg",{viewBox:`0 0 ${U2} ${nG}`,shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("g",{className:"fm-gear",children:o.jsx("g",{className:"fm-gear-motion",children:YG.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,className:Qx[de.cell]},`g${de.y}-${de.x}`))})}),o.jsxs("g",{className:"fm-body",children:[Q2.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,fill:"var(--accent)"},`eye-bed-${de.x}`)),ZG.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,className:Qx[de.cell]},`b${de.y}-${de.x}`)),o.jsxs("g",{className:"fm-arms",children:[o.jsx("rect",{x:4,y:8,width:2,height:2}),o.jsx("rect",{x:12,y:8,width:1,height:2}),o.jsx("rect",{x:13,y:8,width:1,height:2,className:"fm-shade"})]}),Q2.map(de=>o.jsx("rect",{x:de.x-(de.x>=U2/2?1:0)+(Z==="right"?1:0),y:de.y,width:de.w,height:1,className:"fm-eye"},`eye-${de.x}`))]}),o.jsx("g",{className:"fm-hat",children:XG.map(de=>o.jsx("rect",{x:FG+de.x,y:qG+de.y,width:de.w,height:1,className:de.cell==="k"?"fm-hatband":void 0},`h${de.y}-${de.x}`))}),(O==="climb"||O==="rope-throw"||O==="rope-catch"||O==="pull-up")&&o.jsxs("g",{className:"fm-grip",children:[o.jsx("path",{className:"fm-grip-left",d:"M5 9H4V4H7V3H9V5H6V9Z"}),o.jsx("path",{className:"fm-grip-right",d:"M12 9H14V6H11V5H9V7H12Z"})]}),(O==="land"||O==="dismount")&&o.jsxs("g",{className:"fm-crouch-legs",children:[o.jsx("path",{d:"M6 11H8V13H6Z"}),o.jsx("path",{d:"M10 11H12V13H10Z"})]}),["sit","cast","fish","reel","stow"].includes(O)&&o.jsxs("g",{className:"fm-seated-legs",children:[o.jsx("path",{className:"fm-seated-far",d:"M10 10H12V11H11V14H8V13H9V11H10Z"}),o.jsx("path",{d:"M6 10H9V11H7V15H4V14H5V11H6Z"})]}),["left","right"].map(de=>o.jsx("g",{className:"fm-leg","data-side":de,children:QG[de].map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,className:Qx[ue.cell]},`${de}${ue.y}-${ue.x}`))},de))]})})]}),y&&!f.audio&&(f.channel||f.video)&&o.jsx("iframe",{ref:le,className:"fm-frame",title:Te,src:XV(f.channel,window.location.origin,f.video),onLoad:()=>Ne(ZV()),allow:"autoplay; encrypted-media",sandbox:"allow-scripts allow-same-origin allow-presentation"})]})}),tK=15e3;function nK(e){return e.visibilityState==="visible"&&e.hasFocus()}function rK(e,t){return t||e===!0}function sK(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}const aK={"//":["What a user would NOTICE. One key per version that has something to say,","and no key at all for a version that has nothing — which is most of them.","","The rule this file exists to serve: before every release, ask 'what would a","user notice?' and write the answer here. 'Nothing user-visible' is a valid","and expected answer, and it is spelled by adding no key. A release with no","key shows no modal, and that silence is what keeps the modal worth reading","on the day it is not silent.","","What belongs here: something that changed on the user's machine or under","their hands — a hook written to or removed from settings.json, a default","that flipped, a control that moved or went away, a stored preference that","changed meaning. What does not: bounds, races, assertions that could not","fire, anything that is invisible when it is correct.","","Write it for the person running the deck, not for the person reading the","diff. `title` is the sentence they scan; `body` is what they need in order","to act on it, or to stop worrying about it.","","Keys are versions exactly as package.json spells them. A key that is not a","version, or an entry missing either field, fails the suite rather than","being quietly dropped — see src/web/__tests__/release-notes-file.test.ts.","Ordering here is for humans; the deck sorts by version itself.","","A title may open with an emoji, and if it does, put exactly ONE space after","it. Not two: the dialog gives a leading emoji its own optical gap, because","a colour glyph is drawn edge to edge inside its advance and one word space","after one reads as none. A second space here would be a lie in the data","about a defect in the type, and the suite refuses both it and no space at","all.","","A release that genuinely has nothing to say is spelled TWICE: no key here,",'and its version written into "//nothing-to-say" below. One spelling on its',"own is ambiguous — a missing key reads the same whether it was a decision","or a forgotten step, and five releases in a row were once forgotten. The list","is what tells the two apart, and release-notes-current-version.test.ts fails","the release whose version is in neither place. Any key opening with // is a","note to the author and never a release."],"//nothing-to-say":["3.23.1","3.23.2","3.23.3","3.23.4","3.26.0","3.26.1","3.26.3","3.26.4","3.26.5","3.27.6","3.27.7","3.28.0","3.28.1","3.29.3"],"3.29.1":[{title:"🗂️ One row per project in Projects",body:"The Projects report now counts a session's work under the folder you started it in, the same name its card has on the canvas, instead of adding a row for every folder the agent moved into. The first start after updating re-reads your transcripts once to regroup the report."},{title:"🔔 Tidier custom sounds",body:"Importing a sound, recording one and choosing a spoken voice now sit in compact cards that respond to clicks and focus like the rest of the deck."}],"3.29.0":[{title:"🎵 Your own stations in Claude FM",body:"Add any YouTube live link or radio stream as a station in Appearance, next to the built-in ones, and mute the music without losing your volume. When a station is not live, the picker now says so instead of staying silent."},{title:"🔔 Notification sounds and voices of your own",body:"Pick a local audio file or a spoken voice for each alert, so the sound that means an agent is waiting is one you will recognise."},{title:"🗑️ Drag a card off the board to remove it",body:"Drag a card to the target at the bottom of the canvas to take it off the board, or use Remove from board in the detail panel (Delete). The session keeps running, and the session list (L) brings it back."},{title:"🔐 Optional invite-only pairing",body:"Pairing works as before, with or without an invite. If you want, Local network can now be set to accept only decks that join with an invite you created, so a nearby machine cannot ask to pair on its own."},{title:"🌐 Account sharing between your machines is more reliable",body:"A locked macOS Keychain is explained instead of failing silently, a login that is broken or belongs to another account is never shared, and a sync that stops partway keeps what already arrived."},{title:"📅 Projects opens on Today",body:"The Projects report per account starts with today's work, and an empty window offers the next wider one. The topbar also shows this month's usage, and the desktop app can restart into an update from its own window."}],"3.27.0":[{title:"📊 Projects: where each account spent its work",body:"Each account card's ⋯ menu now breaks its cost down by project, over 7d / 30d / all."}],"3.27.1":[{title:"🎨 Make Appearance easier to tune",body:"The Appearance dialog now has clearer sections, stronger selection states, and a calmer layout for choosing a theme and configuring music. Your existing settings and keyboard shortcuts continue to work."}],"3.27.2":[{title:"💰 Project costs now match Usage",body:"Project cost totals no longer count the same Claude request once for every content block. Existing project history is rebuilt automatically so the totals align with the Usage panel."}],"3.27.3":[{title:"🎵 Station selection works in the desktop app",body:"The music station picker now opens inside ccdeck instead of relying on the operating system popup, so choosing a station works reliably in the Electron app."}],"3.27.4":[{title:"✅ Desktop picker release checks are green",body:"The station picker now keeps the same keyboard, motion, focus, and layout behavior as the rest of ccdeck across desktop and browser builds."}],"3.27.5":[{title:"🧭 The welcome tour stays dismissed",body:"Electron now remembers that you completed the onboarding tour at the deck level, so an update or loopback port change no longer shows the same tour again."},{title:"🎵 The station picker has a clearer finish",body:"The music selector has a tighter trigger, a purposeful chevron, and more deliberate option spacing so it reads like a native part of Appearance."}],"3.25.0":[{title:"🖱️ A click goes to the session, a double-click opens the details",body:"Clicking a card frames it with the rest of its session and leaves the detail panel shut. Double-click a card to open its details; `j`/`k`, the session list, Enter and `D` still open them too."},{title:"🔭 Cards stay readable when you zoom out",body:"At every zoom a card shows its name, its state and anything waiting on you, instead of shrinking to a coloured pill. Hover or focus a card to see it whole. Recap notes read at a distance too, and show the full recap on hover."},{title:"🌐 The Machine panel shows your network",body:"A new Network section shows download, upload and the round trip to Claude's API, and names the route when traffic goes through a VPN or a Tailscale exit node. Those checks run only while the panel is open. The panel is regrouped into CPU, Memory, Network and Thermal, with a flag at the top when something needs attention."},{title:"🎨 See each theme before you pick it",body:"The Appearance menu shows a small preview of the deck in Light and in Dark. Claude FM also keeps its volume when a notification chime plays, instead of dipping under it."}],"3.24.1":[{title:"🎛️ Appearance is one small menu now",body:"The topbar's appearance control opens a compact menu where you can choose Light or Dark and show or hide the character. The character stays on by default, and your choice is remembered."}],"3.24.0":[{title:"🎧 Claude FM plays from the minimap",body:"A small character stands on the minimap's top edge. Press it and the Claude channel's live stream plays; press it again and it stops. It only turns up when the channel is actually broadcasting, so a deck with no network never shows it at all."},{title:"🤠 And it gets on with its day",body:"It walks that edge, tidies up what it finds, kicks a ball along it, sits with its legs over the side, and watches the board through a scope. Now and then it drops onto the canvas and ropes its way back up. Headphones on while the music plays, a hat when it does not."}],"3.23.5":[{title:"🧭 The accounts panel opens on the account you are on",body:"Its windows, its resets and how old the numbers are — whole, at the top of the column. Every other account stands behind one row that says how many of them a switch could actually reach; press it to see them, or rest on it to be shown their names and how much room each has left."},{title:"⚙️ Auto-switch moved in there with them",body:"It is behind that same row now, after the accounts it switches between, rather than at the foot of the panel. The row says `auto 90%` or `auto off` so you can tell what the policy is doing without opening it — and says so in amber when it is armed with nowhere left to go."}],"3.23.0":[{title:"🧭 The accounts column leads with accounts",body:`The live account is the open row: its windows as bars, when each one resets, and how old the numbers are. Every other account rests on the two figures a switch is decided by, and opens with a click when you want the rest.
|
|
93
93
|
|
|
94
94
|
A problem stays on the row — an expired login, one that was never stored, a keychain the deck cannot open — with the reason and the sign-in one press away. Auto-switch is one row now: its threshold and its switch. Local network moved out of the column into a view of its own, reached from a row at the foot that says how many of the paired machines are on right now, and shows which ones when you hover it.`},{title:"💬 A resting session shows Claude Code's recap beside its card",body:"When a session stops, Claude Code's own recap of what it did is drawn beside the card — so a board you come back to says what happened without opening anything."},{title:"🪟 The chrome went quiet",body:`The topbar is borderless, one set of corners runs through the app, the canvas ground is flat, and the minimap, the zoom controls, the type filter and the Machine and Usage panels read as tooling rather than as cards.
|
|
95
95
|
|
|
@@ -281,18 +281,18 @@ While it is open it polls this machine once every few seconds, and it stops the
|
|
|
281
281
|
|
|
282
282
|
It marks that work now. A chart with bars in it means the agent is doing something, whether or not it has called a tool in the last minute; a flat chart means it genuinely is not. Hover it for the split — how many tool calls and how many blocks of thinking and writing landed in the last 60 seconds.
|
|
283
283
|
|
|
284
|
-
Nothing was added to the card and nothing new is polled. The deck already reads each session's transcript for its token counts; this reads the same file for what the model has finished writing, and a session that is quiet costs one file check per second and a half.`}]},ck="agent-dag.releaseNotesSeen";function eR(e){return e.split(/[.\-+]/).map(t=>parseInt(t,10)).map(t=>Number.isNaN(t)?0:t)}function Xl(e,t){const n=eR(e),r=eR(t);for(let s=0;s<Math.max(n.length,r.length);s++){const l=(n[s]??0)-(r[s]??0);if(l!==0)return l<0?-1:1}return 0}function Zl(e){return typeof e=="string"&&/^\d+\.\d+\.\d+/.test(e)}function aK(e){if(!e||typeof e!="object")return!1;const{title:t,body:n}=e;return typeof t=="string"&&t.trim()!==""&&typeof n=="string"&&n.trim()!==""}function oK(e){if(!e||typeof e!="object")return[];const t=[];for(const[n,r]of Object.entries(e)){if(!Zl(n)||!Array.isArray(r))continue;const s=r.filter(aK);s.length&&t.push({version:n,notes:s})}return t.sort((n,r)=>Xl(r.version,n.version))}const tR=oK(sK);function w$(e,t,n){return e.filter(r=>Xl(r.version,n)<=0&&(t===null||Xl(r.version,t)>0))}function iK(e,t){return e.filter(n=>Xl(n.version,t)===0)}function lK(e){if(!e.length)return"";const t=e[0].version,n=e[e.length-1].version;return t===n?`v${t}`:`v${n} – v${t}`}function cK({since:e,running:t,entries:n,firstRun:r}){if(!n.length)return"Nothing in this build has anything to report yet. Most releases do not, which is the point.";if(e!==null){const c=n.length===1?"one release":`${n.length} releases`;return`You were last caught up at v${e}. Since then ${c} changed something you would notice. Clicking the version in the topbar brings this back.`}if(r&&Zl(t))return`The deck has not run in this browser before, so this is what v${t} — the release you have — changed. Earlier releases are not repeated here; clicking the version in the topbar brings all of them back.`;const s=n[0].version;if(!Zl(t))return"Everything this build has to say, newest first. Most releases have nothing here, which is why the deck stays quiet about them.";const l=Xl(s,t);return l<0?`v${t} — the release you are running — changed nothing you would notice, which most releases do not. Below is the last release that did, and everything before it, newest first.`:l>0?"Everything this build has to say, newest first. Most releases have nothing here, which is why the deck stays quiet about them.":`You are running v${t}, and this is what it changed — and everything before it, newest first. Most releases have nothing here, which is why the deck stays quiet about them.`}const uK=new RegExp("^(?:\\p{Extended_Pictographic}|\\p{Emoji_Modifier}|\\p{Regional_Indicator}|[\\u200D\\uFE0F])+(?= \\S)","u");function dK(e){const t=uK.exec(e);return t?{icon:t[0],rest:e.slice(t[0].length)}:{icon:null,rest:e}}function nR(){if(typeof window>"u")return null;try{return window.localStorage}catch{return null}}function hK(e){if(!e)return null;let t=null;try{t=e.getItem(ck)}catch{return null}return Zl(t)?t:null}function fK(e){if(!e)return!1;try{return e.getItem(ck),!0}catch{return!1}}function pK(e,t){if(!e)return!1;try{return e.setItem(ck,t),!0}catch{return!1}}const v$="agent-dag.tourSeen";function mK(e){if(!e)return!1;try{return e.getItem(v$)==="1"}catch{return!1}}function gK(e){if(!e)return!1;try{return e.setItem(v$,"1"),!0}catch{return!1}}function yK({tourSeen:e,decision:t}){if(t.reason==="no-version"||t.reason==="cannot-remember")return{tour:!1,notes:"none"};if(t.reason==="welcome"||t.reason==="first-run")return{tour:!e,notes:"none"};const n=t.show.length>0;return e?{tour:!1,notes:n?"now":"none"}:{tour:!0,notes:n?"after":"none"}}function wK({stored:e,running:t,notes:n,remembers:r=!0}){if(!Zl(t))return{show:[],record:null,reason:"no-version"};if(!Zl(e)){if(!r)return{show:[],record:t,reason:"cannot-remember"};const c=iK(n,t);return c.length?{show:c,record:t,reason:"welcome"}:{show:[],record:t,reason:"first-run"}}const s=Xl(e,t);if(s===0)return{show:[],record:null,reason:"seen"};if(s>0)return{show:[],record:null,reason:"ahead"};const l=w$(n,e,t);return l.length?{show:l,record:t,reason:"new-notes"}:{show:[],record:t,reason:"nothing-new"}}function vK(e,t){if(/\s|^$/.test(e[t+2]??""))return-1;let n=t+2;for(;n<e.length;){if(e[n]==="`"){const r=e.indexOf("`",n+1);if(r<0)break;n=r+1;continue}if(e.startsWith("**",n)&&!/\s/.test(e[n-1]??" "))return n;n++}return-1}function x$(e,t=!0){const n=[];let r="";const s=()=>{r&&(n.push({kind:"text",text:r}),r="")};let l=0;for(;l<e.length;){if(e[l]==="`"){const c=e.indexOf("`",l+1);if(c>l+1){s(),n.push({kind:"code",text:e.slice(l+1,c)}),l=c+1;continue}}else if(t&&e.startsWith("**",l)){const c=vK(e,l);if(c>0){s(),n.push({kind:"bold",kids:x$(e.slice(l+2,c),!1)}),l=c+2;continue}}r+=e[l],l+=1}return s(),n}const xK=new Set(["idle","checking","current","downloading","ready","error"]);function rR(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.status!="string"||!xK.has(t.status))return null;const n=typeof t.version=="string"&&t.version.trim()?t.version.trim():null;return t.status==="ready"&&!n?null:{status:t.status,version:n}}function bK(e){return(e==null?void 0:e.status)==="ready"&&e.version?{version:e.version}:null}function kK(e=typeof navigator>"u"?"":navigator.userAgent){var t;return((t=/\bccdeck-desktop\/(\d[^\s]*)/.exec(e))==null?void 0:t[1])??null}const uf="Restart to update",b$=3e4;function NK(e=typeof navigator>"u"?"":navigator.userAgent){return/\bMac OS X\b|\bMacintosh\b/.test(e)?"the ccdeck menu in the menu bar":"the ccdeck tray menu"}function SK(e,t){const n=`v${e} → v${t}`;return{text:n,label:`${n}, update downloaded and verified`,title:`ccdeck v${t} is downloaded and verified · click to open What's new, where ${uf} comes first`}}function jK(e){const t=e==null?void 0:e.reason;return t==="app_disconnected"||t==="update_not_ready"?t:"refused"}function _K(e,t,n=typeof navigator>"u"?"":navigator.userAgent){const r=NK(n),s=`Use ${uf} in ${r}.`;switch(e){case"app_disconnected":return`Nothing restarted: the app is not connected to this deck, so the request had nowhere to go. ${s}`;case"update_not_ready":return`Nothing restarted: the app no longer has v${t} ready. When it has one, ${uf} is in ${r}.`;case"timeout":return`ccdeck has not restarted after ${b$/1e3} seconds. ${s}`;case"refused":return`Nothing restarted: the deck turned the request down. ${s}`;case"unreachable":return`Nothing restarted: the request did not reach the deck. ${s}`}}function EK({entries:e,since:t,running:n,firstRun:r,onClose:s,onTour:l,updateVersion:c,updateBusy:u,onUpdateRestart:f,updateFailure:p,onRestart:h}){const m=pn(s),y=lK(e);return o.jsx("div",{className:"modal-backdrop",onClick:s,role:"presentation",children:o.jsxs("div",{ref:m,className:"modal release-notes",onClick:v=>v.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"release-notes-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{id:"release-notes-title",className:"modal-tool-name",children:"What's new"}),y&&o.jsx("span",{className:"modal-tool-id",children:y})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:s,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[(c||p)&&o.jsxs("div",{className:"rn-update",children:[c&&f&&o.jsxs("div",{className:"guide-door",children:[o.jsxs("span",{children:["ccdeck v",c," is downloaded and verified."]}),o.jsx("button",{type:"button",className:"btn",onClick:f,"aria-busy":u||void 0,children:u?"Restarting…":uf})]}),o.jsx("p",{className:"rn-update-said",role:"status",children:p})]}),o.jsx("p",{className:"modal-note",children:cK({since:t,running:n,firstRun:r,entries:e})}),l&&!c&&o.jsxs("div",{className:"guide-door",children:[o.jsx("span",{children:"Eight pictures of what the deck shows."}),o.jsx("button",{type:"button",className:"btn",onClick:l,children:"Take the tour"})]}),h&&o.jsxs("div",{className:"guide-door",children:[o.jsx("span",{children:"Restart the deck. Sessions, settings and pairings come back as they were."}),o.jsx("button",{type:"button",className:"btn",onClick:h,children:"Restart"})]}),e.map(v=>o.jsxs("section",{className:"modal-section",children:[o.jsxs("h3",{className:"rn-version",children:["v",v.version]}),o.jsx("ul",{className:"rn-notes",children:v.notes.map((S,b)=>{const{icon:_,rest:k}=dK(S.title);return o.jsxs("li",{className:"rn-note",children:[o.jsxs("p",{className:"rn-note-title",children:[_&&o.jsx("span",{className:"rn-note-icon",children:_}),k]}),o.jsx("p",{className:"rn-note-body",children:k$(x$(S.body))})]},b)})})]},v.version))]})]})})}function k$(e){return e.map((t,n)=>t.kind==="text"?t.text:t.kind==="code"?o.jsx("code",{className:"rn-code",children:t.text},n):o.jsx("strong",{className:"rn-strong",children:k$(t.kids)},n))}function CK(e){return e.slice().sort((t,n)=>t.y-n.y||t.x-n.x)}function TK(e,t,n){var c;if(e.length===0)return null;const r=CK(e),s=t?r.findIndex(u=>u.id===t):-1,l=s===-1?n===1?0:r.length-1:(s+n+r.length)%r.length;return((c=r[l])==null?void 0:c.id)??null}const RK=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Escape","Delete","Backspace"]);function AK(e,t){return t==null?{kind:"deck",nodeId:null}:e.key==="Enter"||e.key===" "?{kind:"activate",nodeId:t,additive:e.shiftKey}:RK.has(e.key)?{kind:"node",nodeId:t}:{kind:"deck",nodeId:t}}const MK=new Set(["","BODY","HTML","#DOCUMENT"]);function IK(e){return!e||Sf(e)?!1:!MK.has(String(e.tagName??"").toUpperCase())}const uk="agent-dag.removedNodes";function $K(e){try{const t=JSON.parse((e==null?void 0:e.getItem(uk))??"[]");return new Set(Array.isArray(t)?t.filter(n=>typeof n=="string"):[])}catch{return new Set}}function sR(e,t){try{e==null||e.setItem(uk,JSON.stringify([...t]))}catch{}}function N$(e,t){const n=new Map(e.map(l=>[l.id,l.parentId])),r=new Set(t),s=l=>{if(r.has(l))return!0;const c=new Set([l]);let u=n.get(l);for(;u&&!c.has(u);){if(r.has(u))return r.add(l),!0;c.add(u),u=n.get(u)}return!1};return l=>s(l.id)||s(l.sessionId??l.id)}function OK(e,t){if(t.size===0)return new Set;const n=[...e],r=N$(n,t);return new Set(n.filter(r).map(s=>s.id))}function LK(e,t,n){const r=u=>({id:u.id,parentId:u.data.parentId,sessionId:u.data.sessionId}),s=N$(e.map(r),n),l=e.filter(u=>!s(r(u))),c=new Set(l.map(u=>u.id));return{nodes:l,edges:t.filter(u=>c.has(u.source)&&c.has(u.target))}}function PK(e,t){let n=null;for(const r of t)e.has(r)&&(n??(n=new Set(e)),n.delete(r));return n??e}function DK(e,t){return t.size===0?[]:[...e].filter(n=>t.has(n.id)).map(n=>n.id)}const FK=16,qK=120;function BK(e,t,n=0){return e.clientX>=t.left-n&&e.clientX<=t.right+n&&e.clientY>=t.top-n&&e.clientY<=t.bottom+n}function zK(e,t){const n=Math.max(t.left-e.clientX,0,e.clientX-t.right),r=Math.max(t.top-e.clientY,0,e.clientY-t.bottom);return Math.hypot(n,r)}function UK(e,t){return BK(e,t,FK)?"over":zK(e,t)<=qK?"near":"far"}function HK(e){var n,r;if(typeof e.clientX=="number"&&typeof e.clientY=="number")return{clientX:e.clientX,clientY:e.clientY};const t=((n=e.changedTouches)==null?void 0:n[0])??((r=e.touches)==null?void 0:r[0]);return t?{clientX:t.clientX,clientY:t.clientY}:null}function WK(e,t){if(!t||!e.agents.get(t))return null;const r=new Set([t]);let s=t;for(;s;){const c=e.agents.get(s);if(!(c!=null&&c.parentId)||r.has(c.parentId))break;r.add(c.parentId),s=c.parentId}let l=!0;for(;l;){l=!1;for(const c of e.agents.values())c.parentId&&r.has(c.parentId)&&!r.has(c.id)&&(r.add(c.id),l=!0)}return r}function VK(e,t){const n=new Set;for(const r of t){const s=WK(e,r);if(s)for(const l of s)n.add(l)}return n.size>0?n:null}const GK=40,KK=120;function YK(e,t){let n=null,r=0,s=Number.NEGATIVE_INFINITY;const l=()=>{n=null,s=t.now(),e()},c=()=>{n!=null&&(t.clearTimeout(n),n=null)},u=(f,p,h)=>{if(n!=null){if(r<=f)return;c()}const m=Math.min(h,Math.max(0,f-p));r=f,n=t.setTimeout(l,m)};return{live(f=GK){const p=t.now(),h=Math.max(s+f,p);if(h<=p){c(),l();return}u(h,p,f)},replay(f=KK){c(),r=t.now()+f,n=t.setTimeout(l,f)},flush(){c(),l()},cancel(){c()}}}const XK=1e3;function ZK(e={}){const t=Math.max(1,Math.floor(e.limit??XK)),n=e.protect;let r=!1,s=[],l=new Set,c=0,u=0,f=null;return{get paused(){return r},get size(){return s.length},get dropped(){return c},get overflowed(){return c>0},get through(){return u},accept(p){const h=typeof(p==null?void 0:p.seq)=="number"?p.seq:null,m=(p==null?void 0:p.epoch)??null,y=m!==null&&m!==f;y&&(f=m,u=0);const v=h!==null&&!y&&h<=u;if(h!==null&&h>u&&(u=h),!r)return!0;if(v)return!1;if(s.push(p),n!=null&&n(p)&&l.add(p),s.length>t){let S=0;if(l.size<s.length)for(;l.has(s[S]);)S++;const[b]=s.splice(S,1);l.delete(b),c++}return!1},setPaused(p){if(r=p,p)return[];const h=s;return s=[],l=new Set,c=0,h}}}const S$="agent-dag.theme";function QK(e,t=!1){return e==="light"||e==="dark"?e:t?"light":"dark"}function JK(){try{return window.matchMedia("(prefers-color-scheme: light)").matches}catch{return!1}}function eY(){return QK(yr(S$),JK())}const tY=6,nY="ccdeck-tabs";function rY(e){return e>=tY}function sY(e,t,n){const r=s=>{const l=s.data;(l==null?void 0:l.kind)==="who"&&l.from!==t&&e.postMessage({kind:"here",from:t,to:l.from,streaming:n()})};return e.addEventListener("message",r),{ask(s,l=(c,u)=>setTimeout(c,u)){return new Promise(c=>{const u=new Set,f=p=>{const h=p.data;(h==null?void 0:h.kind)==="here"&&h.to===t&&h.streaming&&u.add(h.from)};e.addEventListener("message",f),e.postMessage({kind:"who",from:t}),l(()=>{e.removeEventListener("message",f),c(u.size)},s)})},leave(){var s;e.removeEventListener("message",r),(s=e.close)==null||s.call(e)}}}function aY({waiting:e,running:t,connected:n=!0}){return{title:e>0?`(${e}) ${dn}`:dn,icon:n?e>0?"waiting":t>0?"running":"idle":"offline"}}const _h={offline:"#e05252",waiting:"#c97d12",running:"#2a90d4",idle:"#7e828c"};function Eh(e,t){const s=c=>`<circle cx="16" cy="16" r="12" fill="none" stroke="${e}" stroke-width="5"${c}/>`;return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">${t==="waiting"?`<circle cx="16" cy="16" r="14.5" fill="${e}"/>`:t==="offline"?s(` stroke-dasharray="${56.5485.toFixed(2)} ${18.8495.toFixed(2)}" transform="rotate(-58 16 16)"`):s("")+(t==="running"?`<circle cx="16" cy="16" r="5" fill="${e}"/>`:"")}</svg>`}const oY=Object.freeze({offline:`data:image/svg+xml,${encodeURIComponent(Eh(_h.offline,"offline"))}`,waiting:`data:image/svg+xml,${encodeURIComponent(Eh(_h.waiting,"waiting"))}`,running:`data:image/svg+xml,${encodeURIComponent(Eh(_h.running,"running"))}`,idle:`data:image/svg+xml,${encodeURIComponent(Eh(_h.idle,"idle"))}`}),iY="No sessions are waiting for you.";function lY(e){if(e.length===0)return"";const[t,...n]=e;if(n.length===0)return`${t.label} is waiting for your permission.`;const r=`${n.length} more session${n.length===1?"":"s"}`;return`${t.label} and ${r} are waiting for your permission.`}function aR(e,t,n=iY){return t!==""?t:e===""?"":n}const oR="agent-dag.browserWatch.seenMs";function cY(e,t){return e.filter(n=>n.startMs>t)}function uY(e,t){const n=(e??[]).filter(s=>s&&typeof s.fp=="string"&&!t.has(s.fp));if(!n.length)return{request:null,waiting:0};const r=[...n].sort((s,l)=>(s.at??0)-(l.at??0));return{request:r[0],waiting:r.length-1}}function dY({request:e,waiting:t,busy:n,now:r,onAccept:s,onDecline:l,onLater:c}){const u=w.useRef(null),f=pn(c,{focusRef:u}),p=ao(n,"accept"),h=ao(n,"dismiss");return o.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:o.jsxs("div",{ref:f,className:"modal lan-ask",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-ask-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("i",{className:"ap-pulse","aria-hidden":!0}),o.jsx("span",{id:"lan-ask-title",className:"modal-tool-name",children:"A deck wants to pair"})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:c,"aria-label":"Answer later (Esc)",title:"Answer later (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsxs("p",{className:"lan-ask-who",children:[o.jsx("strong",{className:"lan-ask-name",children:e.name})," at ",o.jsx("code",{className:"ap-lan-code",children:e.addr})," · asked ",Bb(e.at,r)]}),o.jsx("p",{className:"modal-note",children:"Paired decks repair each other's expired logins. Accept only if you know this machine — what it shares is an account, not a screen."}),o.jsxs("p",{className:"lan-ask-fp",children:["Its fingerprint is ",o.jsx("code",{className:"ap-lan-code",children:e.fp})," — that machine shows its own under This deck on the network; the two should match."]}),t>0&&o.jsx("p",{className:"lan-ask-more",children:t===1?"One more deck is waiting behind this one.":`${t} more decks are waiting behind this one.`}),o.jsxs("div",{className:"lan-ask-acts",children:[o.jsx("button",{type:"button",ref:u,className:"btn",disabled:h.disabled,"aria-busy":h.busy,onClick:l,title:"Nothing is shared. If that deck asks again, this comes back.",children:n==="dismiss"?"declining…":"Decline"}),o.jsx("button",{type:"button",className:"btn primary",disabled:p.disabled,"aria-busy":p.busy,onClick:s,title:"Talk to this deck from now on, and repair its expired logins with this deck's own.",children:n==="accept"?"accepting…":"Accept"})]})]})]})})}const hY=600;function Z0(e,t){return!(e.exitAt!=null&&t-e.exitAt>hY||e.kind==="root"&&e.state==="done"&&e.tools.length===0&&e.endedAt!=null&&e.endedAt-e.startedAt<3e3)}function fY(e,t){const n=new Set;for(const r of e.agents.values())Z0(r,t)&&n.add(r.id);return n}function pY(e,t,n=0){return e.right+n>t.left&&e.left-n<t.right&&e.bottom+n>t.top&&e.top-n<t.bottom}function mY(e,t,n=0){if(!e)return!1;for(const r of t)if(pY(e,r,n))return!0;return!1}const j$="sessionGroup";function gY(e,t){var r,s;if(e.type===j$)return"transparent";if(Fr((r=e.data)==null?void 0:r.waiting))return t("--warn");if(e.type==="recapNote")return t("--muted");const n=(s=e.data)==null?void 0:s.state;return t(n==="err"?"--err":n==="active"?"--inflight":"--ok")}const _$=["--err","--inflight","--ok","--grid-line","--minimap-mask","--panel","--line","--accent","--text-dim","--bg"];function iR(e){const t={};for(const n of _$)t[n]=e(n);return t}function yY(e){return t=>e[t]??""}function wY(e,t){return _$.every(n=>e[n]===t[n])}function vY(e){const t=new Set(e.pins),n=new Map,r=new Map;for(const[s,l]of e.positions)n.set(s,l),t.has(s)&&r.set(s,l);return{positions:n,pinned:r}}function lR(e){return Object.entries(e??{}).filter(([,t])=>t&&typeof t.x=="number"&&typeof t.y=="number")}function xY(e){const t={positions:[],pins:[]};if(!e)return t;let n;try{n=JSON.parse(e)}catch{return t}if(!n||typeof n!="object")return t;if(!("v"in n)){const s=lR(n);return{positions:s,pins:s.map(([l])=>l)}}const r=n;return{positions:lR(r.positions),pins:Array.isArray(r.pins)?r.pins:[]}}function bY(e,t){const n={};for(const[r,s]of e)n[r]=s;for(const[r,s]of t)n[r]=s;return JSON.stringify({v:2,positions:n,pins:Array.from(t.keys())})}function kY(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}return!(typeof(t==null?void 0:t.width)=="number"&&typeof(t==null?void 0:t.height)=="number")||!(t.width>0&&t.height>0)?null:{width:t.width,height:t.height}}const E$=.2,C$=1.6;function NY(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;const{x:n,y:r,zoom:s}=t;return typeof n!="number"||typeof r!="number"||typeof s!="number"||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(s)||s<E$||s>C$?null:{x:n,y:r,zoom:s}}const SY=1200,jY=1e3;function Jx(e){return e.lastDeckFitAt>0&&e.at-e.lastDeckFitAt<SY?!1:e.hasSourceEvent?!0:e.lastCanvasInputAt>0&&e.at-e.lastCanvasInputAt<jY}function Ch({durationMs:e,documentHidden:t,reducedMotion:n=_Y()}){return t||n?!1:Number.isFinite(e)&&e>0}function _Y(){return typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function EY(e,t,n){const r=e.x*t.zoom+t.x,s=e.y*t.zoom+t.y,l=(e.x+e.width)*t.zoom+t.x,c=(e.y+e.height)*t.zoom+t.y;return l>0&&r<n.width&&c>0&&s<n.height}function CY({pane:e,viewport:t,boxes:n}){if(!e||!(e.width>0)||!(e.height>0)||!Number.isFinite(t.zoom)||t.zoom<=0||!Number.isFinite(t.x)||!Number.isFinite(t.y))return!1;let r=!1;for(const s of n)if(r=!0,EY(s,t,e))return!1;return r}const dk=11,T$=7.2,R$=6.6,TY={width:104,height:48},cR={width:96,height:44},A$={width:220,height:103};function RY(e){let t=1/0,n=1/0;for(const r of e)!(r.width>0)||!(r.height>0)||(t=Math.min(t,r.width),n=Math.min(n,r.height));return!Number.isFinite(t)||!Number.isFinite(n)?A$:{width:Math.max(160,t),height:Math.max(72,n)}}function e0(e,t,n){return e.width*t>=n.width&&e.height*t>=n.height}function AY(e,t,n=A$){if(!Number.isFinite(t)||t<=0)return e??"detail";const r=dk*t;return e==="detail"?r>=R$?"detail":e0(n,t,cR)?"compact":"overview":r>=T$?"detail":e==="compact"?e0(n,t,cR)?"compact":"overview":e0(n,t,TY)?"compact":"overview"}const MY=T$/dk,IY=R$/dk;function $Y(e,t){return e>=MY?e:Math.max(e,Math.min(t,IY-.001))}const OY=.8,LY=1;function PY(e){const t=e.minZoom??OY,n=e.maxZoom??LY,r=e.fill??.9,s=e.insets.left,l=e.insets.top,c=Math.max(1,e.pane.width-e.insets.left-e.insets.right),u=Math.max(1,e.pane.height-e.insets.top-e.insets.bottom),f=e.context,p=e.anchor,h=Math.min(c/Math.max(1,f.width),u/Math.max(1,f.height))*r,m=Math.max(t,Math.min(n,h)),y=(v,S,b,_,k,j)=>{let E=v+(S-_*m)/2-b*m;const C=k*m+E,R=(k+j)*m+E;return j*m<=S?C<v?E+=v-C:R>v+S&&(E-=R-(v+S)):E+=v-C,E};return{x:y(s,c,f.x,f.width,p.x,p.width),y:y(l,u,f.y,f.height,p.y,p.height),zoom:m}}function DY(e){let t=1/0,n=1/0,r=-1/0,s=-1/0;for(const l of e)t=Math.min(t,l.x),n=Math.min(n,l.y),r=Math.max(r,l.x+l.width),s=Math.max(s,l.y+l.height);return Number.isFinite(t)?{x:t,y:n,width:r-t,height:s-n}:null}let li=null,Il=null;const Q0=new Set,J0=()=>{for(const e of Q0)e()},FY=e=>(Q0.add(e),()=>{Q0.delete(e)}),uR=()=>li,qY=90;function M$(e){!Il||e!=null&&Il.at.id!==e||(clearTimeout(Il.timer),Il=null)}function dR(e,t,n="pointer"){M$();const r={id:e,anchor:t,by:n};if(li||n==="focus"){li=r,J0();return}Il={at:r,timer:setTimeout(()=>{Il=null,li=r,J0()},qY)}}function Ka(e){M$(e),!(!li||e!=null&&li.id!==e)&&(li=null,J0())}function BY({agentFor:e,recapFor:t,labelFor:n,bounds:r}){const s=w.useSyncExternalStore(FY,uR,uR),l=s?e(s.id):void 0,c=s&&!l?t(s.id):void 0,u=s!=null&&(!l&&!c||!s.anchor.isConnected);return w.useEffect(()=>{u&&s&&Ka(s.id)},[u,s]),!s||u?null:l?o.jsx(UY,{a:l,anchor:s.anchor,parentLabel:l.parentId?n(l.parentId):void 0,bounds:r},s.id):c?o.jsx(zY,{r:c,anchor:s.anchor,bounds:r},s.id):null}function I$(e,t){const n=w.useRef(null),r=w.useCallback(()=>{const s=n.current;if(!s||!e.isConnected)return;const l=$b(e.getBoundingClientRect(),{width:s.offsetWidth,height:s.offsetHeight},t());s.style.top=`${l.top}px`,s.style.left=`${l.left}px`,s.style.maxHeight=l.maxHeight==null?"":`${l.maxHeight}px`,s.dataset.side=l.side},[e,t]);return w.useLayoutEffect(()=>{r()}),n}function zY({r:e,anchor:t,bounds:n}){const r=I$(t,n),s=ec(3e4),l=Jh(e.recap.at,s);return Mn.createPortal(o.jsxs("div",{ref:r,className:"ap-peek node-peek recap-peek",role:"tooltip",id:"node-peek",style:{"--session-hue":e.hue},children:[o.jsxs("div",{className:"node-peek-head",children:[o.jsxs("span",{className:"recap-peek-mark",children:[o.jsx(Eu,{}),"recap"]}),o.jsx("span",{className:"node-peek-time",title:l.title,children:l.label})]}),e.sessionLabel&&o.jsx("div",{className:"node-peek-kind",children:o.jsxs("span",{children:["Claude Code's recap of ",e.sessionLabel]})}),o.jsx("p",{className:"recap-peek-text",children:e.recap.text}),o.jsx("p",{className:"node-peek-hint",children:"Click to go to the session · double-click for its details"})]}),document.body)}function UY({a:e,anchor:t,parentLabel:n,bounds:r}){const s=I$(t,r),l=ec(1e3),c=Sb(e.sessionName,e.sessionTitle),u=e.tools.filter(S=>S.ok===!1).length,f=e.tools.filter(S=>!S.endedAt).length,p=ir(e,l).total,h=e.usage.inputTokens+e.usage.outputTokens,m=e.kind==="root"&&Fr(e.waiting),y=e.kind==="root"?"session":n?`subagent of ${n}`:"subagent",v=[`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`,f>0?`${f} in-flight`:null,h>0?`${Bt(h)} tok`:null,p>0?`${ut(p)}${_u(e,l)>0?"+":""}`:null].filter(Boolean).join(" · ");return Mn.createPortal(o.jsxs("div",{ref:s,className:"ap-peek node-peek",role:"tooltip",id:"node-peek",children:[o.jsxs("div",{className:"node-peek-head",children:[o.jsx("span",{className:"node-peek-name",children:e.label}),o.jsxs("span",{className:"node-peek-time",children:[e.synthetic?"≥ ":"",Ul(e.startedAt,e.endedAt,l)]})]}),o.jsxs("div",{className:"node-peek-kind",children:[o.jsxs("span",{className:"node-peek-state","data-kind":_0(e.state),children:[o.jsx(xM,{kind:_0(e.state)}),Wl(e.state)]}),o.jsx("span",{children:y}),e.model?o.jsx("span",{children:so(e.model)}):null]}),e.kind==="root"&&c.face&&o.jsx("p",{className:"node-peek-title",children:c.face}),e.kind==="root"&&e.waiting&&o.jsxs("p",{className:`node-peek-wait${m?" warn":""}`,children:[m&&o.jsx(Tb,{}),o.jsx("span",{children:Rb(e.waiting)}),o.jsx("b",{children:Ul(e.waiting.since,void 0,l)})]}),o.jsxs("p",{className:"node-peek-facts",children:[v,u>0&&o.jsxs("span",{className:"node-peek-failed",children:[" · ",u," failed"]})]}),e.branch&&e.branch.total>0&&o.jsx("p",{className:"node-peek-branch",children:fM(e.branch)}),o.jsx("p",{className:"node-peek-hint",children:"Click to go to the session · double-click for details"})]}),document.body)}const HY=5*6e4,WY=6e4;function VY({shown:e,tabVisible:t,lastReadAt:n,now:r,lastSince:s,since:l}){return!e||!t?!1:s&&l&&s!==l?!0:n===null||r-n>=HY}function hR(e=new Date){return TM("month",e)}function GY(e){const t=Cf(e);return{cost:t.cost,tokens:t.tokens}}function fR(e){return e>0?ut(e):"$0.00"}const KY="Update checks are off (AGENTS_DECK_NO_UPDATE_CHECK=1)",t0="click for what's new";function YY(e){if(e.checkDisabled)return`${KY} · ${t0}`;if(e.checking)return`Asking npm for the newest release… · ${t0}`;const t=e.latest?`npm has v${e.latest}`:e.latestPending?`npm's latest tag names v${e.latestPending}, which it cannot serve yet`:"npm not reached yet",n=e.checkFailedAgo?` · could not reach npm ${e.checkFailedAgo}`:e.checkedAgo?` · checked ${e.checkedAgo}`:"";return`${t}${n} · re-checked periodically · ${t0}, and to check npm now`}function XY(e){const t=`Version v${e.running}, show what's new`;return e.checkDisabled?`${t} — update checks are off`:e.checking?`${t} — checking npm for a newer release`:e.checkFailedAgo?`${t} — npm could not be reached ${e.checkFailedAgo}, check again`:`${t} and check npm for a newer release`}function ZY(e){const t=e.kind==="restart"?`v${e.to} is installed and waiting for a restart`:`v${e.to} is available on npm`,n=e.open?"show what's new":"show what's new and the notice";return`Version v${e.from}, ${t} — ${n}`}function $$(e){return e?`${e.kind}:${e.to}`:""}function QY(e,t){return e!=null&&t!==$$(e)}function JY(e){if(e==null)return{kind:"unknown",lead:"No data yet. Start a Claude Code or Codex session — it appears here as soon as the deck sees its first event.",workspace:null,tail:""};const t=e.trim();return t===""?{kind:"machine",lead:"No data yet. Start a Claude Code or Codex session anywhere on this machine — this deck is unscoped and captures every workspace.",workspace:null,tail:""}:{kind:"scoped",lead:"No data yet. This deck only captures sessions running under",workspace:t,tail:" — start one there, or restart it without --workspace/--scope to watch the whole machine."}}const eb={kind:"assumed",claude:!0,codex:!0};function eX(e){if(!e||typeof e!="object")return eb;const t=e.providers;if(!t||typeof t!="object")return eb;const n=t;return{kind:"reported",claude:n.claude!==!1,codex:n.codex!==!1}}function tX(e){return e.claude&&e.codex?"Claude Code and Codex":e.claude?"Claude Code":e.codex?"Codex":null}const pR={claude:"Claude Code",codex:"Codex",opencode:"OpenCode",openclaw:"OpenClaw",copilot:"GitHub Copilot",pi:"pi-agent",zcode:"ZCode"};function nX(e){const t=e.toLowerCase();return Object.hasOwn(pR,t)?pR[t]:t?t[0].toUpperCase()+t.slice(1):""}function rX(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function KX(e,t=[]){const n=t.length?rX(t.map(nX)):tX(e);return n?`via ccusage · local ${n} logs`:"via ccusage · local agent logs"}function sX(e){const t=e.claude?{provider:"claude",watching:!0,spans:[{text:"Claude Code sends its events through a hook in "},{text:"~/.claude/settings.json",code:!0},{text:" — or in "},{text:"$CLAUDE_CONFIG_DIR/settings.json",code:!0},{text:" when you have that set — which the deck installs on first run."}]}:{provider:"claude",watching:!1,spans:[{text:"Claude Code capture is off: no Claude Code was found on this machine, or the deck was started with "},{text:"--no-claude",code:!0},{text:"."}]},n=e.codex?{provider:"codex",watching:!0,spans:[{text:"Codex installs nothing and needs no trust prompt — the deck reads "},{text:"~/.codex/sessions/",code:!0},{text:" itself, so an empty canvas means no rollout has been written there yet, or that "},{text:"$CODEX_HOME",code:!0},{text:" points at a different tree."}]}:{provider:"codex",watching:!1,spans:[{text:"Codex capture is off: no "},{text:"~/.codex/",code:!0},{text:" was found — set "},{text:"$CODEX_HOME",code:!0},{text:" if yours lives elsewhere — or the deck was started with "},{text:"--no-codex",code:!0},{text:"."}]};return[t,n]}function aX(e,t){const n=t.prefs??G0,r=Kl(n.done.level),s=Kl(n["needs-input"].level),l=r===s?`${r}%`:`${r}% and ${s}%`,c=t.on?`Sound: on at ${l} — a tone when a turn finishes, another when Claude asks for you (M)`:"Sound: off — press M, or use the switch in here, for a tone when a turn finishes (M)",u=e.codex?`
|
|
284
|
+
Nothing was added to the card and nothing new is polled. The deck already reads each session's transcript for its token counts; this reads the same file for what the model has finished writing, and a session that is quiet costs one file check per second and a half.`}]},ck="agent-dag.releaseNotesSeen";function eR(e){return e.split(/[.\-+]/).map(t=>parseInt(t,10)).map(t=>Number.isNaN(t)?0:t)}function Xl(e,t){const n=eR(e),r=eR(t);for(let s=0;s<Math.max(n.length,r.length);s++){const l=(n[s]??0)-(r[s]??0);if(l!==0)return l<0?-1:1}return 0}function Zl(e){return typeof e=="string"&&/^\d+\.\d+\.\d+/.test(e)}function oK(e){if(!e||typeof e!="object")return!1;const{title:t,body:n}=e;return typeof t=="string"&&t.trim()!==""&&typeof n=="string"&&n.trim()!==""}function iK(e){if(!e||typeof e!="object")return[];const t=[];for(const[n,r]of Object.entries(e)){if(!Zl(n)||!Array.isArray(r))continue;const s=r.filter(oK);s.length&&t.push({version:n,notes:s})}return t.sort((n,r)=>Xl(r.version,n.version))}const tR=iK(aK);function w$(e,t,n){return e.filter(r=>Xl(r.version,n)<=0&&(t===null||Xl(r.version,t)>0))}function lK(e,t){return e.filter(n=>Xl(n.version,t)===0)}function cK(e){if(!e.length)return"";const t=e[0].version,n=e[e.length-1].version;return t===n?`v${t}`:`v${n} – v${t}`}function uK({since:e,running:t,entries:n,firstRun:r}){if(!n.length)return"Nothing in this build has anything to report yet. Most releases do not, which is the point.";if(e!==null){const c=n.length===1?"one release":`${n.length} releases`;return`You were last caught up at v${e}. Since then ${c} changed something you would notice. Clicking the version in the topbar brings this back.`}if(r&&Zl(t))return`The deck has not run in this browser before, so this is what v${t} — the release you have — changed. Earlier releases are not repeated here; clicking the version in the topbar brings all of them back.`;const s=n[0].version;if(!Zl(t))return"Everything this build has to say, newest first. Most releases have nothing here, which is why the deck stays quiet about them.";const l=Xl(s,t);return l<0?`v${t} — the release you are running — changed nothing you would notice, which most releases do not. Below is the last release that did, and everything before it, newest first.`:l>0?"Everything this build has to say, newest first. Most releases have nothing here, which is why the deck stays quiet about them.":`You are running v${t}, and this is what it changed — and everything before it, newest first. Most releases have nothing here, which is why the deck stays quiet about them.`}const dK=new RegExp("^(?:\\p{Extended_Pictographic}|\\p{Emoji_Modifier}|\\p{Regional_Indicator}|[\\u200D\\uFE0F])+(?= \\S)","u");function hK(e){const t=dK.exec(e);return t?{icon:t[0],rest:e.slice(t[0].length)}:{icon:null,rest:e}}function nR(){if(typeof window>"u")return null;try{return window.localStorage}catch{return null}}function fK(e){if(!e)return null;let t=null;try{t=e.getItem(ck)}catch{return null}return Zl(t)?t:null}function pK(e){if(!e)return!1;try{return e.getItem(ck),!0}catch{return!1}}function mK(e,t){if(!e)return!1;try{return e.setItem(ck,t),!0}catch{return!1}}const v$="agent-dag.tourSeen";function gK(e){if(!e)return!1;try{return e.getItem(v$)==="1"}catch{return!1}}function yK(e){if(!e)return!1;try{return e.setItem(v$,"1"),!0}catch{return!1}}function wK({tourSeen:e,decision:t}){if(t.reason==="no-version"||t.reason==="cannot-remember")return{tour:!1,notes:"none"};if(t.reason==="welcome"||t.reason==="first-run")return{tour:!e,notes:"none"};const n=t.show.length>0;return e?{tour:!1,notes:n?"now":"none"}:{tour:!0,notes:n?"after":"none"}}function vK({stored:e,running:t,notes:n,remembers:r=!0}){if(!Zl(t))return{show:[],record:null,reason:"no-version"};if(!Zl(e)){if(!r)return{show:[],record:t,reason:"cannot-remember"};const c=lK(n,t);return c.length?{show:c,record:t,reason:"welcome"}:{show:[],record:t,reason:"first-run"}}const s=Xl(e,t);if(s===0)return{show:[],record:null,reason:"seen"};if(s>0)return{show:[],record:null,reason:"ahead"};const l=w$(n,e,t);return l.length?{show:l,record:t,reason:"new-notes"}:{show:[],record:t,reason:"nothing-new"}}function xK(e,t){if(/\s|^$/.test(e[t+2]??""))return-1;let n=t+2;for(;n<e.length;){if(e[n]==="`"){const r=e.indexOf("`",n+1);if(r<0)break;n=r+1;continue}if(e.startsWith("**",n)&&!/\s/.test(e[n-1]??" "))return n;n++}return-1}function x$(e,t=!0){const n=[];let r="";const s=()=>{r&&(n.push({kind:"text",text:r}),r="")};let l=0;for(;l<e.length;){if(e[l]==="`"){const c=e.indexOf("`",l+1);if(c>l+1){s(),n.push({kind:"code",text:e.slice(l+1,c)}),l=c+1;continue}}else if(t&&e.startsWith("**",l)){const c=xK(e,l);if(c>0){s(),n.push({kind:"bold",kids:x$(e.slice(l+2,c),!1)}),l=c+2;continue}}r+=e[l],l+=1}return s(),n}const bK=new Set(["idle","checking","current","downloading","ready","error"]);function rR(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.status!="string"||!bK.has(t.status))return null;const n=typeof t.version=="string"&&t.version.trim()?t.version.trim():null;return t.status==="ready"&&!n?null:{status:t.status,version:n}}function kK(e){return(e==null?void 0:e.status)==="ready"&&e.version?{version:e.version}:null}function NK(e=typeof navigator>"u"?"":navigator.userAgent){var t;return((t=/\bccdeck-desktop\/(\d[^\s]*)/.exec(e))==null?void 0:t[1])??null}const uf="Restart to update",b$=3e4;function SK(e=typeof navigator>"u"?"":navigator.userAgent){return/\bMac OS X\b|\bMacintosh\b/.test(e)?"the ccdeck menu in the menu bar":"the ccdeck tray menu"}function jK(e,t){const n=`v${e} → v${t}`;return{text:n,label:`${n}, update downloaded and verified`,title:`ccdeck v${t} is downloaded and verified · click to open What's new, where ${uf} comes first`}}function _K(e){const t=e==null?void 0:e.reason;return t==="app_disconnected"||t==="update_not_ready"?t:"refused"}function EK(e,t,n=typeof navigator>"u"?"":navigator.userAgent){const r=SK(n),s=`Use ${uf} in ${r}.`;switch(e){case"app_disconnected":return`Nothing restarted: the app is not connected to this deck, so the request had nowhere to go. ${s}`;case"update_not_ready":return`Nothing restarted: the app no longer has v${t} ready. When it has one, ${uf} is in ${r}.`;case"timeout":return`ccdeck has not restarted after ${b$/1e3} seconds. ${s}`;case"refused":return`Nothing restarted: the deck turned the request down. ${s}`;case"unreachable":return`Nothing restarted: the request did not reach the deck. ${s}`}}function CK({entries:e,since:t,running:n,firstRun:r,onClose:s,onTour:l,updateVersion:c,updateBusy:u,onUpdateRestart:f,updateFailure:p,onRestart:h}){const m=pn(s),y=cK(e);return o.jsx("div",{className:"modal-backdrop",onClick:s,role:"presentation",children:o.jsxs("div",{ref:m,className:"modal release-notes",onClick:v=>v.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"release-notes-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{id:"release-notes-title",className:"modal-tool-name",children:"What's new"}),y&&o.jsx("span",{className:"modal-tool-id",children:y})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:s,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[(c||p)&&o.jsxs("div",{className:"rn-update",children:[c&&f&&o.jsxs("div",{className:"guide-door",children:[o.jsxs("span",{children:["ccdeck v",c," is downloaded and verified."]}),o.jsx("button",{type:"button",className:"btn",onClick:f,"aria-busy":u||void 0,children:u?"Restarting…":uf})]}),o.jsx("p",{className:"rn-update-said",role:"status",children:p})]}),o.jsx("p",{className:"modal-note",children:uK({since:t,running:n,firstRun:r,entries:e})}),l&&!c&&o.jsxs("div",{className:"guide-door",children:[o.jsx("span",{children:"Eight pictures of what the deck shows."}),o.jsx("button",{type:"button",className:"btn",onClick:l,children:"Take the tour"})]}),h&&o.jsxs("div",{className:"guide-door",children:[o.jsx("span",{children:"Restart the deck. Sessions, settings and pairings come back as they were."}),o.jsx("button",{type:"button",className:"btn",onClick:h,children:"Restart"})]}),e.map(v=>o.jsxs("section",{className:"modal-section",children:[o.jsxs("h3",{className:"rn-version",children:["v",v.version]}),o.jsx("ul",{className:"rn-notes",children:v.notes.map((S,b)=>{const{icon:_,rest:k}=hK(S.title);return o.jsxs("li",{className:"rn-note",children:[o.jsxs("p",{className:"rn-note-title",children:[_&&o.jsx("span",{className:"rn-note-icon",children:_}),k]}),o.jsx("p",{className:"rn-note-body",children:k$(x$(S.body))})]},b)})})]},v.version))]})]})})}function k$(e){return e.map((t,n)=>t.kind==="text"?t.text:t.kind==="code"?o.jsx("code",{className:"rn-code",children:t.text},n):o.jsx("strong",{className:"rn-strong",children:k$(t.kids)},n))}function TK(e){return e.slice().sort((t,n)=>t.y-n.y||t.x-n.x)}function RK(e,t,n){var c;if(e.length===0)return null;const r=TK(e),s=t?r.findIndex(u=>u.id===t):-1,l=s===-1?n===1?0:r.length-1:(s+n+r.length)%r.length;return((c=r[l])==null?void 0:c.id)??null}const AK=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Escape","Delete","Backspace"]);function MK(e,t){return t==null?{kind:"deck",nodeId:null}:e.key==="Enter"||e.key===" "?{kind:"activate",nodeId:t,additive:e.shiftKey}:AK.has(e.key)?{kind:"node",nodeId:t}:{kind:"deck",nodeId:t}}const IK=new Set(["","BODY","HTML","#DOCUMENT"]);function $K(e){return!e||Sf(e)?!1:!IK.has(String(e.tagName??"").toUpperCase())}const uk="agent-dag.removedNodes";function OK(e){try{const t=JSON.parse((e==null?void 0:e.getItem(uk))??"[]");return new Set(Array.isArray(t)?t.filter(n=>typeof n=="string"):[])}catch{return new Set}}function sR(e,t){try{e==null||e.setItem(uk,JSON.stringify([...t]))}catch{}}function N$(e,t){const n=new Map(e.map(l=>[l.id,l.parentId])),r=new Set(t),s=l=>{if(r.has(l))return!0;const c=new Set([l]);let u=n.get(l);for(;u&&!c.has(u);){if(r.has(u))return r.add(l),!0;c.add(u),u=n.get(u)}return!1};return l=>s(l.id)||s(l.sessionId??l.id)}function LK(e,t){if(t.size===0)return new Set;const n=[...e],r=N$(n,t);return new Set(n.filter(r).map(s=>s.id))}function PK(e,t,n){const r=u=>({id:u.id,parentId:u.data.parentId,sessionId:u.data.sessionId}),s=N$(e.map(r),n),l=e.filter(u=>!s(r(u))),c=new Set(l.map(u=>u.id));return{nodes:l,edges:t.filter(u=>c.has(u.source)&&c.has(u.target))}}function DK(e,t){let n=null;for(const r of t)e.has(r)&&(n??(n=new Set(e)),n.delete(r));return n??e}function FK(e,t){return t.size===0?[]:[...e].filter(n=>t.has(n.id)).map(n=>n.id)}const qK=16,BK=120;function zK(e,t,n=0){return e.clientX>=t.left-n&&e.clientX<=t.right+n&&e.clientY>=t.top-n&&e.clientY<=t.bottom+n}function UK(e,t){const n=Math.max(t.left-e.clientX,0,e.clientX-t.right),r=Math.max(t.top-e.clientY,0,e.clientY-t.bottom);return Math.hypot(n,r)}function HK(e,t){return zK(e,t,qK)?"over":UK(e,t)<=BK?"near":"far"}function WK(e){var n,r;if(typeof e.clientX=="number"&&typeof e.clientY=="number")return{clientX:e.clientX,clientY:e.clientY};const t=((n=e.changedTouches)==null?void 0:n[0])??((r=e.touches)==null?void 0:r[0]);return t?{clientX:t.clientX,clientY:t.clientY}:null}function VK(e,t){if(!t||!e.agents.get(t))return null;const r=new Set([t]);let s=t;for(;s;){const c=e.agents.get(s);if(!(c!=null&&c.parentId)||r.has(c.parentId))break;r.add(c.parentId),s=c.parentId}let l=!0;for(;l;){l=!1;for(const c of e.agents.values())c.parentId&&r.has(c.parentId)&&!r.has(c.id)&&(r.add(c.id),l=!0)}return r}function GK(e,t){const n=new Set;for(const r of t){const s=VK(e,r);if(s)for(const l of s)n.add(l)}return n.size>0?n:null}const KK=40,YK=120;function XK(e,t){let n=null,r=0,s=Number.NEGATIVE_INFINITY;const l=()=>{n=null,s=t.now(),e()},c=()=>{n!=null&&(t.clearTimeout(n),n=null)},u=(f,p,h)=>{if(n!=null){if(r<=f)return;c()}const m=Math.min(h,Math.max(0,f-p));r=f,n=t.setTimeout(l,m)};return{live(f=KK){const p=t.now(),h=Math.max(s+f,p);if(h<=p){c(),l();return}u(h,p,f)},replay(f=YK){c(),r=t.now()+f,n=t.setTimeout(l,f)},flush(){c(),l()},cancel(){c()}}}const ZK=1e3;function QK(e={}){const t=Math.max(1,Math.floor(e.limit??ZK)),n=e.protect;let r=!1,s=[],l=new Set,c=0,u=0,f=null;return{get paused(){return r},get size(){return s.length},get dropped(){return c},get overflowed(){return c>0},get through(){return u},accept(p){const h=typeof(p==null?void 0:p.seq)=="number"?p.seq:null,m=(p==null?void 0:p.epoch)??null,y=m!==null&&m!==f;y&&(f=m,u=0);const v=h!==null&&!y&&h<=u;if(h!==null&&h>u&&(u=h),!r)return!0;if(v)return!1;if(s.push(p),n!=null&&n(p)&&l.add(p),s.length>t){let S=0;if(l.size<s.length)for(;l.has(s[S]);)S++;const[b]=s.splice(S,1);l.delete(b),c++}return!1},setPaused(p){if(r=p,p)return[];const h=s;return s=[],l=new Set,c=0,h}}}const S$="agent-dag.theme";function JK(e,t=!1){return e==="light"||e==="dark"?e:t?"light":"dark"}function eY(){try{return window.matchMedia("(prefers-color-scheme: light)").matches}catch{return!1}}function tY(){return JK(yr(S$),eY())}const nY=6,rY="ccdeck-tabs";function sY(e){return e>=nY}function aY(e,t,n){const r=s=>{const l=s.data;(l==null?void 0:l.kind)==="who"&&l.from!==t&&e.postMessage({kind:"here",from:t,to:l.from,streaming:n()})};return e.addEventListener("message",r),{ask(s,l=(c,u)=>setTimeout(c,u)){return new Promise(c=>{const u=new Set,f=p=>{const h=p.data;(h==null?void 0:h.kind)==="here"&&h.to===t&&h.streaming&&u.add(h.from)};e.addEventListener("message",f),e.postMessage({kind:"who",from:t}),l(()=>{e.removeEventListener("message",f),c(u.size)},s)})},leave(){var s;e.removeEventListener("message",r),(s=e.close)==null||s.call(e)}}}function oY({waiting:e,running:t,connected:n=!0}){return{title:e>0?`(${e}) ${dn}`:dn,icon:n?e>0?"waiting":t>0?"running":"idle":"offline"}}const _h={offline:"#e05252",waiting:"#c97d12",running:"#2a90d4",idle:"#7e828c"};function Eh(e,t){const s=c=>`<circle cx="16" cy="16" r="12" fill="none" stroke="${e}" stroke-width="5"${c}/>`;return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">${t==="waiting"?`<circle cx="16" cy="16" r="14.5" fill="${e}"/>`:t==="offline"?s(` stroke-dasharray="${56.5485.toFixed(2)} ${18.8495.toFixed(2)}" transform="rotate(-58 16 16)"`):s("")+(t==="running"?`<circle cx="16" cy="16" r="5" fill="${e}"/>`:"")}</svg>`}const iY=Object.freeze({offline:`data:image/svg+xml,${encodeURIComponent(Eh(_h.offline,"offline"))}`,waiting:`data:image/svg+xml,${encodeURIComponent(Eh(_h.waiting,"waiting"))}`,running:`data:image/svg+xml,${encodeURIComponent(Eh(_h.running,"running"))}`,idle:`data:image/svg+xml,${encodeURIComponent(Eh(_h.idle,"idle"))}`}),lY="No sessions are waiting for you.";function cY(e){if(e.length===0)return"";const[t,...n]=e;if(n.length===0)return`${t.label} is waiting for your permission.`;const r=`${n.length} more session${n.length===1?"":"s"}`;return`${t.label} and ${r} are waiting for your permission.`}function aR(e,t,n=lY){return t!==""?t:e===""?"":n}const oR="agent-dag.browserWatch.seenMs";function uY(e,t){return e.filter(n=>n.startMs>t)}function dY(e,t){const n=(e??[]).filter(s=>s&&typeof s.fp=="string"&&!t.has(s.fp));if(!n.length)return{request:null,waiting:0};const r=[...n].sort((s,l)=>(s.at??0)-(l.at??0));return{request:r[0],waiting:r.length-1}}function hY({request:e,waiting:t,busy:n,now:r,onAccept:s,onDecline:l,onLater:c}){const u=w.useRef(null),f=pn(c,{focusRef:u}),p=ao(n,"accept"),h=ao(n,"dismiss");return o.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:o.jsxs("div",{ref:f,className:"modal lan-ask",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-ask-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("i",{className:"ap-pulse","aria-hidden":!0}),o.jsx("span",{id:"lan-ask-title",className:"modal-tool-name",children:"A deck wants to pair"})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:c,"aria-label":"Answer later (Esc)",title:"Answer later (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsxs("p",{className:"lan-ask-who",children:[o.jsx("strong",{className:"lan-ask-name",children:e.name})," at ",o.jsx("code",{className:"ap-lan-code",children:e.addr})," · asked ",Bb(e.at,r)]}),o.jsx("p",{className:"modal-note",children:"Paired decks repair each other's expired logins. Accept only if you know this machine — what it shares is an account, not a screen."}),o.jsxs("p",{className:"lan-ask-fp",children:["Its fingerprint is ",o.jsx("code",{className:"ap-lan-code",children:e.fp})," — that machine shows its own under This deck on the network; the two should match."]}),t>0&&o.jsx("p",{className:"lan-ask-more",children:t===1?"One more deck is waiting behind this one.":`${t} more decks are waiting behind this one.`}),o.jsxs("div",{className:"lan-ask-acts",children:[o.jsx("button",{type:"button",ref:u,className:"btn",disabled:h.disabled,"aria-busy":h.busy,onClick:l,title:"Nothing is shared. If that deck asks again, this comes back.",children:n==="dismiss"?"declining…":"Decline"}),o.jsx("button",{type:"button",className:"btn primary",disabled:p.disabled,"aria-busy":p.busy,onClick:s,title:"Talk to this deck from now on, and repair its expired logins with this deck's own.",children:n==="accept"?"accepting…":"Accept"})]})]})]})})}const fY=600;function Z0(e,t){return!(e.exitAt!=null&&t-e.exitAt>fY||e.kind==="root"&&e.state==="done"&&e.tools.length===0&&e.endedAt!=null&&e.endedAt-e.startedAt<3e3)}function pY(e,t){const n=new Set;for(const r of e.agents.values())Z0(r,t)&&n.add(r.id);return n}function mY(e,t,n=0){return e.right+n>t.left&&e.left-n<t.right&&e.bottom+n>t.top&&e.top-n<t.bottom}function gY(e,t,n=0){if(!e)return!1;for(const r of t)if(mY(e,r,n))return!0;return!1}const j$="sessionGroup";function yY(e,t){var r,s;if(e.type===j$)return"transparent";if(Fr((r=e.data)==null?void 0:r.waiting))return t("--warn");if(e.type==="recapNote")return t("--muted");const n=(s=e.data)==null?void 0:s.state;return t(n==="err"?"--err":n==="active"?"--inflight":"--ok")}const _$=["--err","--inflight","--ok","--grid-line","--minimap-mask","--panel","--line","--accent","--text-dim","--bg"];function iR(e){const t={};for(const n of _$)t[n]=e(n);return t}function wY(e){return t=>e[t]??""}function vY(e,t){return _$.every(n=>e[n]===t[n])}function xY(e){const t=new Set(e.pins),n=new Map,r=new Map;for(const[s,l]of e.positions)n.set(s,l),t.has(s)&&r.set(s,l);return{positions:n,pinned:r}}function lR(e){return Object.entries(e??{}).filter(([,t])=>t&&typeof t.x=="number"&&typeof t.y=="number")}function bY(e){const t={positions:[],pins:[]};if(!e)return t;let n;try{n=JSON.parse(e)}catch{return t}if(!n||typeof n!="object")return t;if(!("v"in n)){const s=lR(n);return{positions:s,pins:s.map(([l])=>l)}}const r=n;return{positions:lR(r.positions),pins:Array.isArray(r.pins)?r.pins:[]}}function kY(e,t){const n={};for(const[r,s]of e)n[r]=s;for(const[r,s]of t)n[r]=s;return JSON.stringify({v:2,positions:n,pins:Array.from(t.keys())})}function NY(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}return!(typeof(t==null?void 0:t.width)=="number"&&typeof(t==null?void 0:t.height)=="number")||!(t.width>0&&t.height>0)?null:{width:t.width,height:t.height}}const E$=.2,C$=1.6;function SY(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;const{x:n,y:r,zoom:s}=t;return typeof n!="number"||typeof r!="number"||typeof s!="number"||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(s)||s<E$||s>C$?null:{x:n,y:r,zoom:s}}const jY=1200,_Y=1e3;function Jx(e){return e.lastDeckFitAt>0&&e.at-e.lastDeckFitAt<jY?!1:e.hasSourceEvent?!0:e.lastCanvasInputAt>0&&e.at-e.lastCanvasInputAt<_Y}function Ch({durationMs:e,documentHidden:t,reducedMotion:n=EY()}){return t||n?!1:Number.isFinite(e)&&e>0}function EY(){return typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function CY(e,t,n){const r=e.x*t.zoom+t.x,s=e.y*t.zoom+t.y,l=(e.x+e.width)*t.zoom+t.x,c=(e.y+e.height)*t.zoom+t.y;return l>0&&r<n.width&&c>0&&s<n.height}function TY({pane:e,viewport:t,boxes:n}){if(!e||!(e.width>0)||!(e.height>0)||!Number.isFinite(t.zoom)||t.zoom<=0||!Number.isFinite(t.x)||!Number.isFinite(t.y))return!1;let r=!1;for(const s of n)if(r=!0,CY(s,t,e))return!1;return r}const dk=11,T$=7.2,R$=6.6,RY={width:104,height:48},cR={width:96,height:44},A$={width:220,height:103};function AY(e){let t=1/0,n=1/0;for(const r of e)!(r.width>0)||!(r.height>0)||(t=Math.min(t,r.width),n=Math.min(n,r.height));return!Number.isFinite(t)||!Number.isFinite(n)?A$:{width:Math.max(160,t),height:Math.max(72,n)}}function e0(e,t,n){return e.width*t>=n.width&&e.height*t>=n.height}function MY(e,t,n=A$){if(!Number.isFinite(t)||t<=0)return e??"detail";const r=dk*t;return e==="detail"?r>=R$?"detail":e0(n,t,cR)?"compact":"overview":r>=T$?"detail":e==="compact"?e0(n,t,cR)?"compact":"overview":e0(n,t,RY)?"compact":"overview"}const IY=T$/dk,$Y=R$/dk;function OY(e,t){return e>=IY?e:Math.max(e,Math.min(t,$Y-.001))}const LY=.8,PY=1;function DY(e){const t=e.minZoom??LY,n=e.maxZoom??PY,r=e.fill??.9,s=e.insets.left,l=e.insets.top,c=Math.max(1,e.pane.width-e.insets.left-e.insets.right),u=Math.max(1,e.pane.height-e.insets.top-e.insets.bottom),f=e.context,p=e.anchor,h=Math.min(c/Math.max(1,f.width),u/Math.max(1,f.height))*r,m=Math.max(t,Math.min(n,h)),y=(v,S,b,_,k,j)=>{let E=v+(S-_*m)/2-b*m;const C=k*m+E,R=(k+j)*m+E;return j*m<=S?C<v?E+=v-C:R>v+S&&(E-=R-(v+S)):E+=v-C,E};return{x:y(s,c,f.x,f.width,p.x,p.width),y:y(l,u,f.y,f.height,p.y,p.height),zoom:m}}function FY(e){let t=1/0,n=1/0,r=-1/0,s=-1/0;for(const l of e)t=Math.min(t,l.x),n=Math.min(n,l.y),r=Math.max(r,l.x+l.width),s=Math.max(s,l.y+l.height);return Number.isFinite(t)?{x:t,y:n,width:r-t,height:s-n}:null}let li=null,Il=null;const Q0=new Set,J0=()=>{for(const e of Q0)e()},qY=e=>(Q0.add(e),()=>{Q0.delete(e)}),uR=()=>li,BY=90;function M$(e){!Il||e!=null&&Il.at.id!==e||(clearTimeout(Il.timer),Il=null)}function dR(e,t,n="pointer"){M$();const r={id:e,anchor:t,by:n};if(li||n==="focus"){li=r,J0();return}Il={at:r,timer:setTimeout(()=>{Il=null,li=r,J0()},BY)}}function Ka(e){M$(e),!(!li||e!=null&&li.id!==e)&&(li=null,J0())}function zY({agentFor:e,recapFor:t,labelFor:n,bounds:r}){const s=w.useSyncExternalStore(qY,uR,uR),l=s?e(s.id):void 0,c=s&&!l?t(s.id):void 0,u=s!=null&&(!l&&!c||!s.anchor.isConnected);return w.useEffect(()=>{u&&s&&Ka(s.id)},[u,s]),!s||u?null:l?o.jsx(HY,{a:l,anchor:s.anchor,parentLabel:l.parentId?n(l.parentId):void 0,bounds:r},s.id):c?o.jsx(UY,{r:c,anchor:s.anchor,bounds:r},s.id):null}function I$(e,t){const n=w.useRef(null),r=w.useCallback(()=>{const s=n.current;if(!s||!e.isConnected)return;const l=$b(e.getBoundingClientRect(),{width:s.offsetWidth,height:s.offsetHeight},t());s.style.top=`${l.top}px`,s.style.left=`${l.left}px`,s.style.maxHeight=l.maxHeight==null?"":`${l.maxHeight}px`,s.dataset.side=l.side},[e,t]);return w.useLayoutEffect(()=>{r()}),n}function UY({r:e,anchor:t,bounds:n}){const r=I$(t,n),s=ec(3e4),l=Jh(e.recap.at,s);return Mn.createPortal(o.jsxs("div",{ref:r,className:"ap-peek node-peek recap-peek",role:"tooltip",id:"node-peek",style:{"--session-hue":e.hue},children:[o.jsxs("div",{className:"node-peek-head",children:[o.jsxs("span",{className:"recap-peek-mark",children:[o.jsx(Eu,{}),"recap"]}),o.jsx("span",{className:"node-peek-time",title:l.title,children:l.label})]}),e.sessionLabel&&o.jsx("div",{className:"node-peek-kind",children:o.jsxs("span",{children:["Claude Code's recap of ",e.sessionLabel]})}),o.jsx("p",{className:"recap-peek-text",children:e.recap.text}),o.jsx("p",{className:"node-peek-hint",children:"Click to go to the session · double-click for its details"})]}),document.body)}function HY({a:e,anchor:t,parentLabel:n,bounds:r}){const s=I$(t,r),l=ec(1e3),c=Sb(e.sessionName,e.sessionTitle),u=e.tools.filter(S=>S.ok===!1).length,f=e.tools.filter(S=>!S.endedAt).length,p=ir(e,l).total,h=e.usage.inputTokens+e.usage.outputTokens,m=e.kind==="root"&&Fr(e.waiting),y=e.kind==="root"?"session":n?`subagent of ${n}`:"subagent",v=[`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`,f>0?`${f} in-flight`:null,h>0?`${Bt(h)} tok`:null,p>0?`${ut(p)}${_u(e,l)>0?"+":""}`:null].filter(Boolean).join(" · ");return Mn.createPortal(o.jsxs("div",{ref:s,className:"ap-peek node-peek",role:"tooltip",id:"node-peek",children:[o.jsxs("div",{className:"node-peek-head",children:[o.jsx("span",{className:"node-peek-name",children:e.label}),o.jsxs("span",{className:"node-peek-time",children:[e.synthetic?"≥ ":"",Ul(e.startedAt,e.endedAt,l)]})]}),o.jsxs("div",{className:"node-peek-kind",children:[o.jsxs("span",{className:"node-peek-state","data-kind":_0(e.state),children:[o.jsx(xM,{kind:_0(e.state)}),Wl(e.state)]}),o.jsx("span",{children:y}),e.model?o.jsx("span",{children:so(e.model)}):null]}),e.kind==="root"&&c.face&&o.jsx("p",{className:"node-peek-title",children:c.face}),e.kind==="root"&&e.waiting&&o.jsxs("p",{className:`node-peek-wait${m?" warn":""}`,children:[m&&o.jsx(Tb,{}),o.jsx("span",{children:Rb(e.waiting)}),o.jsx("b",{children:Ul(e.waiting.since,void 0,l)})]}),o.jsxs("p",{className:"node-peek-facts",children:[v,u>0&&o.jsxs("span",{className:"node-peek-failed",children:[" · ",u," failed"]})]}),e.branch&&e.branch.total>0&&o.jsx("p",{className:"node-peek-branch",children:fM(e.branch)}),o.jsx("p",{className:"node-peek-hint",children:"Click to go to the session · double-click for details"})]}),document.body)}const WY=5*6e4,VY=6e4;function GY({shown:e,tabVisible:t,lastReadAt:n,now:r,lastSince:s,since:l}){return!e||!t?!1:s&&l&&s!==l?!0:n===null||r-n>=WY}function hR(e=new Date){return TM("month",e)}function KY(e){const t=Cf(e);return{cost:t.cost,tokens:t.tokens}}function fR(e){return e>0?ut(e):"$0.00"}const YY="Update checks are off (AGENTS_DECK_NO_UPDATE_CHECK=1)",t0="click for what's new";function XY(e){if(e.checkDisabled)return`${YY} · ${t0}`;if(e.checking)return`Asking npm for the newest release… · ${t0}`;const t=e.latest?`npm has v${e.latest}`:e.latestPending?`npm's latest tag names v${e.latestPending}, which it cannot serve yet`:"npm not reached yet",n=e.checkFailedAgo?` · could not reach npm ${e.checkFailedAgo}`:e.checkedAgo?` · checked ${e.checkedAgo}`:"";return`${t}${n} · re-checked periodically · ${t0}, and to check npm now`}function ZY(e){const t=`Version v${e.running}, show what's new`;return e.checkDisabled?`${t} — update checks are off`:e.checking?`${t} — checking npm for a newer release`:e.checkFailedAgo?`${t} — npm could not be reached ${e.checkFailedAgo}, check again`:`${t} and check npm for a newer release`}function QY(e){const t=e.kind==="restart"?`v${e.to} is installed and waiting for a restart`:`v${e.to} is available on npm`,n=e.open?"show what's new":"show what's new and the notice";return`Version v${e.from}, ${t} — ${n}`}function $$(e){return e?`${e.kind}:${e.to}`:""}function JY(e,t){return e!=null&&t!==$$(e)}function eX(e){if(e==null)return{kind:"unknown",lead:"No data yet. Start a Claude Code or Codex session — it appears here as soon as the deck sees its first event.",workspace:null,tail:""};const t=e.trim();return t===""?{kind:"machine",lead:"No data yet. Start a Claude Code or Codex session anywhere on this machine — this deck is unscoped and captures every workspace.",workspace:null,tail:""}:{kind:"scoped",lead:"No data yet. This deck only captures sessions running under",workspace:t,tail:" — start one there, or restart it without --workspace/--scope to watch the whole machine."}}const eb={kind:"assumed",claude:!0,codex:!0};function tX(e){if(!e||typeof e!="object")return eb;const t=e.providers;if(!t||typeof t!="object")return eb;const n=t;return{kind:"reported",claude:n.claude!==!1,codex:n.codex!==!1}}function nX(e){return e.claude&&e.codex?"Claude Code and Codex":e.claude?"Claude Code":e.codex?"Codex":null}const pR={claude:"Claude Code",codex:"Codex",opencode:"OpenCode",openclaw:"OpenClaw",copilot:"GitHub Copilot",pi:"pi-agent",zcode:"ZCode"};function rX(e){const t=e.toLowerCase();return Object.hasOwn(pR,t)?pR[t]:t?t[0].toUpperCase()+t.slice(1):""}function sX(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function YX(e,t=[]){const n=t.length?sX(t.map(rX)):nX(e);return n?`via ccusage · local ${n} logs`:"via ccusage · local agent logs"}function aX(e){const t=e.claude?{provider:"claude",watching:!0,spans:[{text:"Claude Code sends its events through a hook in "},{text:"~/.claude/settings.json",code:!0},{text:" — or in "},{text:"$CLAUDE_CONFIG_DIR/settings.json",code:!0},{text:" when you have that set — which the deck installs on first run."}]}:{provider:"claude",watching:!1,spans:[{text:"Claude Code capture is off: no Claude Code was found on this machine, or the deck was started with "},{text:"--no-claude",code:!0},{text:"."}]},n=e.codex?{provider:"codex",watching:!0,spans:[{text:"Codex installs nothing and needs no trust prompt — the deck reads "},{text:"~/.codex/sessions/",code:!0},{text:" itself, so an empty canvas means no rollout has been written there yet, or that "},{text:"$CODEX_HOME",code:!0},{text:" points at a different tree."}]}:{provider:"codex",watching:!1,spans:[{text:"Codex capture is off: no "},{text:"~/.codex/",code:!0},{text:" was found — set "},{text:"$CODEX_HOME",code:!0},{text:" if yours lives elsewhere — or the deck was started with "},{text:"--no-codex",code:!0},{text:"."}]};return[t,n]}function oX(e,t){const n=t.prefs??G0,r=Kl(n.done.level),s=Kl(n["needs-input"].level),l=r===s?`${r}%`:`${r}% and ${s}%`,c=t.on?`Sound: on at ${l} — a tone when a turn finishes, another when Claude asks for you (M)`:"Sound: off — press M, or use the switch in here, for a tone when a turn finishes (M)",u=e.codex?`
|
|
285
285
|
|
|
286
286
|
Both CLIs get the finish tone. The second tone — Claude is waiting for you — has no Codex equivalent to fire on, so it only ever plays for Claude Code.`:"",f=t.on&&t.locked?`
|
|
287
287
|
|
|
288
288
|
Waiting for a click: this browser plays no sound until the page has been used at least once. Anything you press unlocks it.`:"";return c+u+f+`
|
|
289
289
|
|
|
290
|
-
Click to set the volume and the sound of each tone, and to hear either one.`}function df(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const mR=99;function oX(e){const t=Math.max(0,Math.floor(e));return t>mR?`${mR}+`:String(t)}const iX="Pause the canvas";function lX(e){if(!e.paused)return"Pause live updates — events keep arriving and are applied when you resume (Space)";const t=Math.max(0,Math.floor(e.dropped??0));return t>0?`The pause is full — ${df(e.held)} held and ${t} older ${t===1?"one":"ones"} already dropped. Resume to follow the canvas again (Space)`:e.held<=0?"Nothing has arrived since you paused. Resume to follow the canvas again (Space)":`${df(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function cX(e){return e.connected||!e.paused?null:"The canvas is paused as well — Space resumes it, but nothing new arrives until the stream is back."}const O$="paused · full",uX=(e,t)=>t>0?O$:e>0?`paused · ${oX(e)}`:"paused";function dX(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:uX(e.held,t),widest:O$,title:t>0?`Connected — the pause is full at ${df(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${df(e.held)} held until you resume (Space)`:"Connected — updates held until you resume (Space)"}:{tone:"live",resting:!0,label:"live",widest:"live",title:"Receiving events"}:{tone:"dead",resting:!1,label:"offline",widest:"offline",title:e.paused?"SSE disconnected — and the canvas is paused, so resuming will not bring events back until it reconnects":"SSE disconnected"}}const hX=w.lazy(()=>nb(()=>import("./UsageHistoryModal-FKBbTozZ.js"),[])),fX=w.lazy(()=>nb(()=>import("./BrowserWatchModal-C-TkzDPi.js"),[]));function gR(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const pX={agent:eq,sessionGroup:Mq,recapNote:$q},mX={recapTie:Oq},L$="react-flow__node";function n0(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,L$))===!0}const r0=80,s0=.86;function yR(e){if(!e)return 0;const t=e.getBoundingClientRect();let n=t.right;for(const r of document.querySelectorAll(".sysdetail:not(.leaving), .usage-panel:not(.leaving)")){const s=r.getBoundingClientRect();s.width>0&&s.left>t.left&&(n=Math.min(n,s.left))}return Math.max(0,t.right-n)}function gX(e){try{const t=document.querySelector(`.${L$}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const yX=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),wX=420,Th=18,wR=400,a0=450,hk="agent-dag.layout",fk="agent-dag.layoutFrame",pk="agent-dag.viewport",P$="agent-dag.sessionListOpen",D$="agent-dag.detailOpen",F$="agent-dag.usagePanelOpen",q$="agent-dag.systemPanelOpen",vR="agent-dag.accountsPanelOpen",o0="agent-dag.versionNoticeDismissed",xR="agent-dag.oldNameNoticeDismissed",vX=15*6e4,i0={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:",retired_name:"this install came from a name that is no longer published — run:"},Rh="agent-dag.autoRestart",bR="agent-dag.bundleReloadedFor";function xX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(P$)==="1"}catch{return!1}}function bX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(P$,e?"1":"0")}catch{}}function kX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(D$)==="1"}catch{return!1}}function NX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(D$,e?"1":"0")}catch{}}function SX(){const e=yr(F$);return e===null?!0:e==="1"}function jX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(F$,e?"1":"0")}catch{}}function _X(){const e=yr(q$);return e===null?!0:e==="1"}function EX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(q$,e?"1":"0")}catch{}}function CX(){if(typeof window>"u")return{positions:[],pins:[]};try{return xY(window.localStorage.getItem(hk))}catch{return{positions:[],pins:[]}}}function Ah(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(hk,bY(e,t))}catch{}}function TX(){if(typeof window>"u")return null;try{return kY(window.localStorage.getItem(fk))}catch{return null}}function RX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(fk,JSON.stringify(e))}catch{}}function AX(){if(typeof window>"u")return null;try{return NY(window.localStorage.getItem(pk))}catch{return null}}function MX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(pk,JSON.stringify(e))}catch{}}function kR(){if(!(typeof window>"u")){try{window.localStorage.removeItem(hk)}catch{}try{window.localStorage.removeItem(pk)}catch{}try{window.localStorage.removeItem(fk)}catch{}}}function IX(e,t){const n=L9(e,t,new Date().toISOString());if(!n)return;const r=JSON.stringify(n,null,2),s=new Blob([r],{type:"application/json"}),l=URL.createObjectURL(s),c=document.createElement("a");c.href=l,c.download=P9(n.label,t),document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(l),1e3)}const B$={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},$X={file:"M3.4 1.8h4.5l2.7 2.7v7.7H3.4z M7.9 1.8v2.7h2.7",shell:"M2.4 3.8 5.6 7l-3.2 3.2 M7.4 10.6h4.2",web:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M1.8 7h10.4 M7 1.8c-1.5 1.4-2.3 3.1-2.3 5.2s.8 3.8 2.3 5.2c1.5-1.4 2.3-3.1 2.3-5.2S8.5 3.2 7 1.8z",agent:"M3.3 4.8h7.4a1.2 1.2 0 0 1 1.2 1.2v4.8a1.2 1.2 0 0 1-1.2 1.2H3.3a1.2 1.2 0 0 1-1.2-1.2V6a1.2 1.2 0 0 1 1.2-1.2z M7 4.8V2.4 M5.3 8.2h.01 M8.7 8.2h.01",task:"M2.2 4l1.2 1.2 2-2.2 M7.4 4.2h4.4 M2.2 9.4l1.2 1.2 2-2.2 M7.4 9.6h4.4",plan:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M9 5 8 8 5 9l1-3z",mcp:"M5 1.8v2.6 M9 1.8v2.6 M3.6 4.4h6.8v2.2a3.4 3.4 0 0 1-6.8 0z M7 10v2.2",other:"M3.5 7h.01 M7 7h.01 M10.5 7h.01"};function OX({cat:e}){return o.jsx("svg",{className:"cat-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:$X[e]})})}const hf={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},z$=mM;function LX(){return o.jsx(xb,{children:o.jsx(FX,{})})}const PX=e=>e.transform[2]>=e.maxZoom,DX=e=>e.transform[2]<=e.minZoom;function FX(){var Oc,Lc,ra,Pc;const e=xf(),t=Tt(PX),n=Tt(DX),r=tn(),s=w.useState(S0)[0],l=w.useRef(s),[c,u]=w.useState(()=>$K(typeof window>"u"?null:window.localStorage)),[f,p]=w.useState(null),[,h]=w.useState(0),m=w.useCallback(()=>h(T=>T+1),[]),[y,v]=w.useState(kX);w.useEffect(()=>{NX(y)},[y]);const[S,b]=w.useState(()=>new Set),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useCallback((T,A,X=!A)=>{b(te=>{if(!A)return new Set([T]);const ye=new Set(te);return ye.has(T)?ye.delete(T):ye.add(T),ye}),k(te=>A&&te===T?te:T),!A&&X&&v(!0)},[]),R=w.useCallback(()=>{b(new Set),k(null)},[]),[I,O]=w.useState(null),[H,q]=w.useState(null),$=w.useCallback(T=>q(T),[]),[V,ne]=w.useState(!1),[ee,M]=w.useState(!1),[Z,K]=w.useState(!1),D=w.useRef(null),[P,B]=w.useState(xX);w.useEffect(()=>{bX(P)},[P]);const[W,F]=w.useState(SX);w.useEffect(()=>{jX(W)},[W]);const[G,re]=w.useState(null),[U,Y]=w.useState(!1),z=w.useRef(null);w.useEffect(()=>{let T=!0,A=!1,X=null,te=null,ye="";const _e=vt=>{T&&(Y(!0),vt!==ye&&re(null))},Oe=()=>{if(A)return;A=!0,X=Date.now();const vt=hR();te=vt,fetch(`/api/ccusage?since=${vt}`).then(Et=>Et.ok?Et.json():null).then(Et=>{if(T){if(!(Et!=null&&Et.ok)){_e(vt);return}ye=vt,re(GY(Et)),Y(!1)}}).catch(()=>_e(vt)).finally(()=>{A=!1})},Ve=()=>{const vt=z.current;VY({shown:!!vt&&vt.getClientRects().length>0,tabVisible:document.visibilityState==="visible",lastSince:te,since:hR(),lastReadAt:X,now:Date.now()})&&Oe()};Ve();const it=window.setInterval(Ve,WY);document.addEventListener("visibilitychange",Ve);let Ze=null;return z.current&&typeof ResizeObserver<"u"&&(Ze=new ResizeObserver(Ve),Ze.observe(z.current)),()=>{T=!1,window.clearInterval(it),document.removeEventListener("visibilitychange",Ve),Ze==null||Ze.disconnect()}},[]);const[ie,le]=w.useState(_X);w.useEffect(()=>{EX(ie)},[ie]);const ge=w.useRef(!1),[Ne,Ie]=w.useState(()=>{const T=(()=>{try{const A=window.localStorage.getItem(vR);return A===null?!0:A==="1"}catch{return!0}})();return T&&P?(ge.current=!0,!1):T});w.useEffect(()=>{if(!(!Ne&&ge.current))try{window.localStorage.setItem(vR,Ne?"1":"0")}catch{}},[Ne]),w.useEffect(()=>{!P&&ge.current&&(ge.current=!1,Ie(!0))},[P]);const Ge=gh(Ne,200),Pe=gh(W,130),Be=gh(ie,130),[Te,st]=w.useState(null);w.useEffect(()=>{let T=null;try{T=localStorage.getItem("agent-dag.sound")}catch{}st(T===null?!0:T==="on")},[]);const de=w.useCallback(()=>{st(T=>{var X;const A=T!==!0;try{localStorage.setItem("agent-dag.sound",A?"on":"off")}catch{}return A&&((X=Ut.current)==null||X.unlock()),A})},[]),ue=w.useCallback(T=>{de()},[de]),se=w.useRef(ue);se.current=ue;const be=w.useRef(Te);be.current=Te;const[Le,ce]=w.useState(()=>wV(yr)),pe=w.useRef(Le);pe.current=Le;const[Ae,fe]=w.useState(()=>Y9(yr)),Se=w.useRef(Ae);Se.current=Ae;const[Ye,qe]=w.useState([]),ke=w.useCallback(T=>{fe(A=>{const X={...A,[T]:null};return Se.current=X,X});try{localStorage.removeItem(yu[T])}catch{}},[]),Re=w.useCallback((T,A)=>{const X=Se.current[T];if(!(A&&X!==A)){ke(T),ce(te=>{const ye={...te,[T]:{...te[T],figure:wr}};return pe.current=ye,ye});try{localStorage.setItem(Bh[T],wr)}catch{}}},[ke]),ze=w.useRef(Re);ze.current=Re,w.useEffect(()=>{let T=!0;return oV().then(A=>{if(!T)return;qe(A);const X=new Set(A.map(te=>te.id));for(const te of qh){const ye=Se.current[te];ye&&!X.has(ye)&&ze.current(te,ye)}},()=>{}),()=>{T=!1}},[]);const Fe=w.useRef(null),We=w.useCallback((T,A=!1)=>{var X,te;if((X=Ut.current)==null||X.unlock(),Fe.current!==null&&clearTimeout(Fe.current),Fe.current=null,!A){(te=Ut.current)==null||te.play(T,!0);return}Fe.current=setTimeout(()=>{var ye;Fe.current=null,(ye=Ut.current)==null||ye.play(T,!0)},fV)},[]),rt=w.useCallback((T,A)=>{ce(X=>{const te={level:Kl(A.level??X[T].level),figure:s$(T,A.figure??X[T].figure)};try{localStorage.setItem(i$[T],String(te.level)),localStorage.setItem(Bh[T],te.figure)}catch{}return{...X,[T]:te}}),We(T,!0)},[We]),dt=w.useCallback((T,A)=>{if(!Ye.some(te=>te.id===A))return;const X={...Se.current,[T]:A};Se.current=X,fe(X);try{localStorage.setItem(yu[T],A)}catch{}We(T,!0)},[Ye,We]),ct=w.useCallback(async T=>{var ye;const A=H0(Ye.length);if(A)throw new Error(A);const X=window.AudioContext??window.webkitAudioContext;if(!X)throw new Error("This browser cannot decode audio files.");const te=new X;try{const _e=await tV(T,Ve=>te.decodeAudioData(Ve));await I2(_e);const Oe=Ou(_e);qe(Ve=>[...Ve.filter(it=>it.id!==Oe.id),Oe])}finally{(ye=te.close)==null||ye.call(te)}},[Ye.length]),yt=w.useCallback(async T=>{const A=H0(Ye.length);if(A)throw new Error(A);const X=nV(T);await I2(X);const te=Ou(X);qe(ye=>[...ye.filter(_e=>_e.id!==te.id),te])},[Ye.length]),Ot=w.useCallback(async(T,A)=>{const X=Ye.find(ye=>ye.id===T),te=A.trim().slice(0,80);!X||!te||te===X.name||(await lV(T,te),qe(ye=>ye.map(_e=>_e.id===T?{..._e,name:te}:_e)))},[Ye]),zt=w.useCallback(async T=>{await cV(T),qe(ye=>ye.filter(_e=>_e.id!==T));const A=Se.current,X=X9(A,T);Se.current=X,fe(X);const te=qh.filter(ye=>A[ye]===T);for(const ye of te)try{localStorage.removeItem(yu[ye]),localStorage.setItem(Bh[ye],wr)}catch{}te.length>0&&ce(ye=>{const _e={...ye};for(const Oe of te)_e[Oe]={..._e[Oe],figure:wr};return pe.current=_e,_e})},[]),Xt=w.useCallback(T=>{var te,ye;const A=qh.find(_e=>Se.current[_e]===T),X=A?pe.current[A].level:gi;(te=Ut.current)==null||te.unlock(),(ye=Ut.current)==null||ye.previewCustom(T,X)},[]);w.useEffect(()=>()=>{Fe.current!==null&&clearTimeout(Fe.current)},[]);const[Dt,rn]=w.useState(!1),je=w.useRef(null),[xt,bt]=w.useState(!1),_n=w.useRef(null);w.useEffect(()=>{Dt&&bt(!1)},[Dt]);const Ut=w.useRef(null),[Vn,Vt]=w.useState("locked");w.useEffect(()=>{const T=xV({enabled:()=>be.current===!0,prefs:()=>pe.current,customSelection:()=>Se.current,loadCustom:iV,onCustomFailure:(X,te)=>ze.current(X,te),onState:Vt});Ut.current=T,Vt(T.state());const A=()=>T.unlock();return window.addEventListener("pointerdown",A,{once:!0,capture:!0}),window.addEventListener("keydown",A,{once:!0,capture:!0}),()=>{window.removeEventListener("pointerdown",A,{capture:!0}),window.removeEventListener("keydown",A,{capture:!0})}},[]);const[Lt,Zt]=w.useState(!1),[In,Hr]=w.useState(!1),[xe,lr]=w.useState(null),[ks,Wr]=w.useState(null),[fa,Ns]=w.useState(!1),[xr,$n]=w.useState(null),[Hs,Q]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(o0)??""}catch{return""}}),[De,et]=w.useState(!1),Ue=w.useRef(0),[tt,wt]=w.useState(!1),gt=w.useCallback((T=!1)=>(T&&(Ue.current=Date.now(),wt(!0)),fetch(T?"/api/version?refresh=1":"/api/version").then(A=>A.ok?A.json():null).then(A=>{A&&lr(A)}).catch(()=>{}).finally(()=>{T&&wt(!1)})),[]),It=w.useCallback(()=>{gt(Date.now()-Ue.current>=vX)},[gt]);w.useEffect(()=>{gt();const T=window.setInterval(It,5*6e4),A=()=>{document.visibilityState==="visible"&&It()};return document.addEventListener("visibilitychange",A),()=>{window.clearInterval(T),document.removeEventListener("visibilitychange",A)}},[gt,It]),w.useEffect(()=>{Lt&>()},[Lt,gt]);const Rt=w.useRef(0);w.useEffect(()=>{if(!Lt||!hu())return;let T=!1;const A=Rt.current;return fetch("/api/desktop-update").then(X=>X.ok?X.json():null).then(X=>{if(T||Rt.current!==A)return;const te=rR(X);te&&Wr(te)}).catch(()=>{}),()=>{T=!0}},[Lt]);const Qt=bK(ks),Nt=w.useRef(!1),br=w.useRef(0),cr=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(br.current),[]);const ki=w.useCallback(async T=>{if(!Ps(Nt.current))return;const A=++cr.current;window.clearTimeout(br.current),Nt.current=!0,Ns(!0),$n(null);const X=te=>{A===cr.current&&(window.clearTimeout(br.current),Nt.current=!1,Ns(!1),$n({failure:te,version:T}))};try{const te=await fetch("/api/desktop-update/restart",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:T})});if(!te.ok)return X(jK(await te.json().catch(()=>null)))}catch{return X("unreachable")}A===cr.current&&(br.current=window.setTimeout(()=>X("timeout"),b$))},[]);w.useEffect(()=>{const T=rK();let A=null;const X=Oe=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:T,looking:Oe}),keepalive:!0}).catch(()=>{})},te=()=>{const Oe=tK(document);nK(A,Oe)&&X(Oe),A=Oe},ye=()=>{A&&X(!1),A=!1};te();const _e=window.setInterval(te,eK);return window.addEventListener("focus",te),window.addEventListener("blur",te),document.addEventListener("visibilitychange",te),window.addEventListener("pagehide",ye),()=>{window.clearInterval(_e),window.removeEventListener("focus",te),window.removeEventListener("blur",te),document.removeEventListener("visibilitychange",te),window.removeEventListener("pagehide",ye),ye()}},[]);const ht=(xe==null?void 0:xe.notice)??null,[ur,sn]=w.useState(null),Vr=ur&&Qt?Qt.version:null,Gn=w.useRef(null);w.useEffect(()=>{!Vr||Gn.current===Vr||(Gn.current=Vr,fetch("/api/desktop-update/seen",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:Vr})}).catch(()=>{}))},[Vr]);const Xu=w.useRef(!1);w.useEffect(()=>{if(Xu.current)return;const T=nR(),A=hK(T),X=wK({stored:A,running:(xe==null?void 0:xe.running)??null,notes:tR,remembers:fK(T)});if(X.reason==="no-version")return;Xu.current=!0,X.record&&pK(T,X.record);let te=!0;return(async()=>{var it;let _e=mK(T);if(hu())try{const Ze=await fetch("/api/prefs");if(!Ze.ok)throw new Error("desktop tour preferences unavailable");const vt=await Ze.json();if(!(vt!=null&&vt.ok))throw new Error("desktop tour preferences unavailable");const Et=((it=vt.prefs)==null?void 0:it.tourSeen)===!0;_e&&!Et&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{}),_e=_e||Et}catch{_e=!0}if(!te)return;const Oe=yK({tourSeen:_e,decision:X}),Ve=X.show.length?{entries:X.show,since:A,firstRun:!1}:null;Oe.tour&&K(!0),Oe.notes==="now"?sn(Ve):Oe.notes==="after"&&(D.current=Ve)})(),()=>{te=!1}},[xe==null?void 0:xe.running]);const io=(xe==null?void 0:xe.running)??"3.29.1",Zu=w.useMemo(()=>w$(tR,null,io),[io]),pa=w.useCallback(()=>{sn({entries:Zu,since:null,firstRun:!1})},[Zu]),[Ni,lo]=w.useState(null),[Kn,Zf]=w.useState(eb);w.useEffect(()=>{let T=!1;return fetch("/api/health").then(A=>A.ok?A.json():null).then(A=>{T||(Zf(eX(A)),!(!A||typeof A.workspace!="string")&&lo(A.workspace))}).catch(()=>{}),()=>{T=!0}},[Lt]);const Si=w.useRef(Kn);Si.current=Kn;const co=$$(ht),ma=QY(ht,Hs),oc=w.useCallback(()=>{Q("");try{window.localStorage.setItem(o0,"")}catch{}},[]),uo=w.useCallback(()=>{if(ht){Q(co);try{window.localStorage.setItem(o0,co)}catch{}}},[ht,co]),[Qf,ic]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(xR)??""}catch{return""}}),ft=xe!=null&&xe.invokedAs&&xe.invokedAs!==dn?xe.invokedAs:null,Qu=ft!=null&&Qf!==ft,Ju=w.useCallback(()=>{if(ft){ic(ft);try{window.localStorage.setItem(xR,ft)}catch{}}},[ft]),On=((Oc=xe==null?void 0:xe.upgrade)==null?void 0:Oc.state)??"idle",ho=qU(xe==null?void 0:xe.upgrade),ji=w.useRef(!1),ed=w.useCallback(async()=>{if(Ps(ji.current||On==="running")){ji.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await gt(),ji.current=!1}},[On,gt]);w.useEffect(()=>{if(On!=="running")return;const T=window.setInterval(gt,3e3);return()=>window.clearInterval(T)},[On,gt]);const lc=w.useCallback(async()=>{const T=xe==null?void 0:xe.command;!T||!await hi(T)||(et(!0),window.setTimeout(()=>et(!1),1600))},[xe==null?void 0:xe.command]),fo=w.useCallback(()=>{B(T=>(T||Ie(A=>(A&&(ge.current=!0),!1)),!T))},[]),Gr=w.useCallback(()=>{ge.current=!1,Ie(T=>(T||B(!1),!T))},[]),[Kr,kr]=w.useState(!1),[ga,Ws]=w.useState(!1),[Yr,Jf]=w.useState(()=>{try{return Number(localStorage.getItem(oR))||0}catch{return 0}}),[cc,po]=w.useState([]),[uc,dc]=w.useState(!1);w.useEffect(()=>{let T=!0;const A=()=>{fetch("/api/browser-watch?live=0").then(te=>te.ok?te.json():null).then(te=>{var ye;!T||!(te!=null&&te.ok)||(po(te.episodes??[]),dc(((ye=te.settings)==null?void 0:ye.enabled)===!0))}).catch(()=>{})};A();const X=setInterval(A,5*6e4);return()=>{T=!1,clearInterval(X)}},[]);const[_i,mo]=w.useState([]),td=w.useRef(new Set),[Ss,ya]=w.useState(null);w.useEffect(()=>{let T=!0,A=0;const X=()=>{fetch("/api/lan").then(te=>te.ok?te.json():null).then(te=>T?(te!=null&&te.ok&&mo(JS(Array.isArray(te.pending)?te.pending:[],te.aliases)),te):null).catch(()=>null).then(te=>{T&&(A=window.setTimeout(X,(te==null?void 0:te.enabled)===!0?q0:VM))})};return X(),()=>{T=!1,window.clearTimeout(A)}},[]);const Vs=w.useCallback(async(T,A)=>{if(!Ss){ya(T);try{const te=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:T,fp:A})})).json().catch(()=>null);te&&Array.isArray(te.pending)?mo(JS(te.pending,te.aliases)):mo(ye=>ye.filter(_e=>_e.fp!==A))}catch{}finally{ya(null)}}},[Ss]),dr=w.useMemo(()=>cY(cc,Yr).length,[cc,Yr]),[ep,nd]=w.useState(0),Ei=w.useRef(null),[Ci,Ti]=w.useState(!1),wa=w.useRef(null),[js,Ri]=w.useState(0),En=w.useState(()=>ZK({protect:T=>n6(l.current,T)}))[0],[go,Ai]=w.useState(!1),va=w.useCallback(()=>{const T=En.paused&&En.dropped>0,A=En.setPaused(!En.paused);T&&r6(l.current);for(const X of A)l.current=zN(l.current,X);Ai(En.paused)},[En]),[Jt,Ln]=w.useState(Date.now()),[Pn,xa]=w.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Rh)!=="0"}catch{return!0}}),ba=w.useRef(!1),tp=w.useCallback(()=>{const T=!Pn;ba.current=!0;try{window.localStorage.removeItem(Rh)}catch{}xa(T),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:T})}).then(A=>A.ok?A.json():null).then(A=>{var X;A!=null&&A.ok&&xa(((X=A.prefs)==null?void 0:X.autoUpdate)!==!1)}).catch(()=>{})},[Pn]),[Nr,ka]=w.useState(!1),[yo,Mi]=w.useState("restart"),[hc,rd]=w.useState(null),Na=w.useRef(!1),sd=w.useRef(null),Ii=w.useRef(0),wo=w.useCallback(async T=>{if(!Ps(Na.current))return;const A=(T==null?void 0:T.upgrade)===!0;Na.current=!0,sd.current=ho;const X=++Ii.current;Mi(A?"npx":"restart"),ka(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(ht==null?void 0:ht.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:A})})}catch{}window.setTimeout(()=>{if(Ii.current===X&&Na.current){Na.current=!1,ka(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},A?18e4:3e4)},[ht==null?void 0:ht.to,ho]),fc=w.useRef(null);w.useEffect(()=>{const T=aj(l.current.agents.values())>0,A=WU({enabled:Pn,kind:ht==null?void 0:ht.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ma,visible:document.visibilityState==="visible",busy:T,idleSince:fc.current,now:Jt});fc.current=A.idleSince,A.restart&&wo()},[Pn,ht==null?void 0:ht.kind,xe==null?void 0:xe.canRestart,ma,Jt,wo]);const ad=aj(l.current.agents.values()),od=HU(ad),id=XM({enabled:Pn,kind:ht==null?void 0:ht.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ma,visible:document.visibilityState==="visible",busy:ad>0,idleSince:fc.current,now:Jt});w.useEffect(()=>{const T=xe==null?void 0:xe.running;let A=null,X=null;try{A=window.sessionStorage.getItem("agent-dag.restartPending"),X=window.sessionStorage.getItem(bR)}catch{return}const te=FU({bundle:"3.29.1",running:T,pending:A,lastTried:X});if(te==="reload"){try{window.sessionStorage.setItem(bR,T??"")}catch{return}window.location.reload();return}if(te!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Na.current=!1,ka(!1),rd(T??null);const ye=window.setTimeout(()=>rd(null),6e3);return()=>window.clearTimeout(ye)},[xe==null?void 0:xe.running]),w.useEffect(()=>{if(Nr&&BU({asked:sd.current,reported:ho})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Na.current=!1,ka(!1)}},[Nr,ho]);const pc=w.useState(()=>vY(CX()))[0],Gt=w.useRef(pc.pinned),$i=w.useRef(null),Oi=w.useState(()=>AX())[0],[mc,gc]=w.useState(()=>new Set),[Sa,ld]=w.useState(eY),[vo,cd]=w.useState(AV),[Li,np]=w.useState(IV),[xo,yc]=w.useState(()=>qV(yr(F2))),[Pi,rp]=w.useState(()=>FV(yr(q2))),[Gs,Di]=w.useState(()=>BV(yr(D2),xo,TV)),[Ks,Fi]=w.useState(()=>new Set),[ud,dd]=w.useState(0),[Xr,hd]=w.useState(()=>iR(gR)),wc=w.useMemo(()=>yY(Xr),[Xr]),ja=w.useCallback(T=>gY(T,wc),[wc]),[fd,sp]=w.useState(!1);w.useEffect(()=>{document.documentElement.dataset.theme=Sa;try{window.localStorage.setItem(S$,Sa)}catch{}hd(T=>{const A=iR(gR);return wY(T,A)?T:A})},[Sa]),w.useEffect(()=>{try{window.localStorage.setItem(l$,vo?"1":"0")}catch{}},[vo]),w.useEffect(()=>{try{window.localStorage.setItem(c$,String(Li))}catch{}},[Li]),w.useEffect(()=>{try{window.localStorage.setItem(q2,Pi?"1":"0")}catch{}},[Pi]),w.useEffect(()=>{try{window.localStorage.setItem(F2,JSON.stringify(xo))}catch{}},[xo]),w.useEffect(()=>{try{window.localStorage.setItem(D2,Gs)}catch{}},[Gs]);const ap=w.useCallback(T=>{yc(A=>A.some(X=>X.id===T.id)?A:[...A,T]),Fi(A=>{if(!A.has(T.id))return A;const X=new Set(A);return X.delete(T.id),X})},[]),pd=w.useCallback((T,A)=>{const X=A.trim();!X||X.length>Lu||yc(te=>te.map(ye=>ye.id===T?{...ye,name:X}:ye))},[]),md=w.useCallback(T=>{yc(A=>A.filter(X=>X.id!==T)),Di(A=>zV(A,T)),Fi(A=>{if(!A.has(T))return A;const X=new Set(A);return X.delete(T),X})},[]),bo=w.useCallback(T=>{const A=B2(T),X=Ks.has(A);T===Gs&&!X||(X&&Fi(te=>{const ye=new Set(te);return ye.delete(A),ye}),Di(T),dd(te=>te+1))},[Gs,Ks]),ko=w.useCallback((T,A)=>{const X=B2(T);Fi(te=>{if(te.has(X)===A)return te;const _e=new Set(te);return A?_e.add(X):_e.delete(X),_e})},[]);w.useEffect(()=>{const T=document.querySelector('meta[name="theme-color"]'),A=Xr["--panel"];T&&A&&T.setAttribute("content",A)},[Xr]);const hr=w.useCallback((T,A)=>{if(Ch({durationMs:A,documentHidden:document.hidden})){e.setViewport(T,{duration:A});return}const{d3Zoom:X,d3Selection:te}=r.getState(),ye=te==null?void 0:te.property("__zoom");if(X&&te&&ye&&ye.k>0&&T.zoom>0){X.transform(te,ye.scale(T.zoom/ye.k).translate((T.x-ye.x)/T.zoom,(T.y-ye.y)/T.zoom));return}e.setViewport(T,{duration:0})},[e,r]),Zr=w.useRef(null),No=w.useRef(0),So=w.useRef(null),qi=w.useRef(()=>{});w.useEffect(()=>{if(!Oi)return;const T=window.setTimeout(()=>{try{hr(Oi,0)}catch{}Ys.current=Date.now()},60);return()=>window.clearTimeout(T)},[hr,Oi]);const Bi=w.useRef(!0),[_a,vc]=w.useState(null);w.useEffect(()=>{const T=new EventSource("/events"),A=YK(m,{now:()=>Date.now(),setTimeout:(_e,Oe)=>window.setTimeout(_e,Oe),clearTimeout:_e=>window.clearTimeout(_e)});let X=!1;const te=typeof BroadcastChannel=="function"?sY(new BroadcastChannel(nY),Math.random().toString(36).slice(2),()=>X):null,ye=window.setInterval(()=>{X||!te||te.ask(600).then(_e=>{X||Hr(rY(_e))})},3e3);return T.addEventListener("open",()=>{Zt(!0),sp(!0)}),T.addEventListener("error",()=>{Zt(!1),vc(null)}),T.addEventListener("open",()=>{X=!0,Hr(!1)}),T.addEventListener("error",()=>{X=!1}),T.addEventListener("replay-end",()=>{Bi.current=!1,A.flush(),vc(Date.now())}),T.addEventListener("desktop-update",_e=>{if(hu())try{const Oe=rR(JSON.parse(_e.data));Oe&&(Rt.current++,Wr(Oe),Oe.status!=="ready"&&(cr.current++,window.clearTimeout(br.current),Nt.current=!1,Ns(!1)))}catch{}}),T.addEventListener("hook",_e=>{var Oe;try{const Ve=JSON.parse(_e.data);if(!En.accept(Ve))return;l.current=zN(l.current,Ve);const it=Ve.replay===!0||Bi.current||Date.now()-Ve.receivedAt>3e4;it?A.replay():A.live();const Ze=vV(Ve,it);Ze&&((Oe=Ut.current)==null||Oe.play(Ze))}catch{}}),()=>{T.close(),A.cancel(),window.clearInterval(ye),te==null||te.leave()}},[m]),w.useEffect(()=>{const T=setInterval(()=>{const A=Date.now();Ln(A);const{changed:X,forgotten:te}=T9(l.current,A);te.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:te})}).catch(()=>{}),b(ye=>_9(ye,l.current.agents)),k(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),q(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),O(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),X&&m()},250);return()=>clearInterval(T)},[m]);const zi=w.useRef(null),Ys=w.useRef(0),gd=420,Yn=w.useCallback((T=500)=>{const A=r0,X=1,te=.2,ye=s0;try{const _e=document.querySelector(".canvas-wrap"),Oe=Array.from(document.querySelectorAll(".react-flow__node")).filter(Ct=>Ct.offsetWidth>0);if(!_e||Oe.length===0)return;const Ve=_e.getBoundingClientRect(),it=e.getViewport();if(!Number.isFinite(it.zoom)||it.zoom<=0)return;const Ze=Ct=>(Ct-Ve.left-it.x)/it.zoom,vt=Ct=>(Ct-Ve.top-it.y)/it.zoom,Et=Oe.map(Ct=>Ct.getBoundingClientRect()),kn=Math.min(...Et.map(Ct=>Ze(Ct.left))),Jn=Math.max(...Et.map(Ct=>Ze(Ct.right))),Oa=Math.min(...Et.map(Ct=>vt(Ct.top))),Ed=Math.max(...Et.map(Ct=>vt(Ct.bottom))),Rr=Jn-kn,Ar=Ed-Oa;if(!(Rr>0&&Ar>0))return;const ll=yR(_e),Dc=Ct=>Math.max(te,Math.min(X,(Ve.width-ll-A*2)/(Rr+Ct)*ye,(Ve.height-A*2)/Ar*ye)),Is=$Y(Dc(gd),Dc(0)),La={x:A-kn*Is,y:Math.max(A,(Ve.height-Ar*Is)/2)-Oa*Is,zoom:Is},Ho=++No.current;hr(La,T),Ys.current=Date.now(),Zr.current=Ch({durationMs:T,documentHidden:document.hidden})?{target:La,until:Date.now()+T+60}:null,window.setTimeout(()=>{var Ct;try{if(((Ct=Zr.current)==null?void 0:Ct.target)===La&&(Zr.current=null),No.current!==Ho)return;const Pa=e.getViewport();(Math.abs(Pa.zoom-Is)>.01||Math.abs(Pa.x-La.x)>2)&&hr(La,0)}catch{}},T+60)}catch{}},[e,hr]);w.useEffect(()=>{const T=()=>{if(!document.hidden)return;const A=Zr.current;if(Zr.current=null,!(!A||Date.now()>A.until)){try{hr(A.target,0)}catch{}Ys.current=Date.now()}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[hr]);const xc=w.useRef(""),bc=w.useRef(null),Xn=w.useRef(0),_s=w.useCallback(()=>{Xn.current=Date.now()},[]),Ui=w.useRef(null),kc=w.useRef(0),Hi=w.useCallback(()=>{kc.current=Date.now()},[]),Wi=w.useCallback(T=>({hasSourceEvent:!!T,at:Date.now(),lastDeckFitAt:Ys.current,lastCanvasInputAt:kc.current}),[]),Nc="agent-dag.autoFitDisabled",Xs=w.useRef(!1),[Sc,Zs]=w.useState(!1);w.useEffect(()=>{try{window.localStorage.removeItem(Nc)}catch{}},[]);const Qs=w.useCallback(()=>{Xs.current||(Xs.current=!0,Zs(!0))},[]),Ea=w.useCallback(()=>{Xs.current=!1,Zs(!1),Yn(400)},[e,Yn]);w.useEffect(()=>{const T=setInterval(()=>{if(Xs.current||Date.now()-Xn.current<800)return;const A=l.current,X=Date.now(),te=[];for(const _e of A.agents.values())Z0(_e,X)&&te.push({id:_e.id});if(te.length===0)return;const ye=[];for(const{id:_e}of te){const Oe=Sr.current.get(_e),Ve=Gt.current.get(_e)??Kt.current.get(_e);!Oe||!Ve||ye.push({x:Ve.x,y:Ve.y,width:Oe.width,height:Oe.height})}CY({pane:Ui.current,viewport:e.getViewport(),boxes:ye})&&Yn(600)},1500);return()=>clearInterval(T)},[e]);const Ca=w.useRef(!1),Sr=w.useRef(new Map),Ta=w.useRef(0),Ra=w.useCallback(T=>{const A=Sr.current;let X=!1;for(const te of T.nodeInternals.values()){const ye=te.width,_e=te.height;if(ye==null||_e==null)continue;const Oe=A.get(te.id);Oe?(Math.abs(Oe.height-_e)>4||Math.abs(Oe.width-ye)>4)&&(A.set(te.id,{width:ye,height:_e}),X=!0):(A.set(te.id,{width:ye,height:_e}),X=!0)}return X&&(Ta.current+=1),Ta.current},[]),Vi=Tt(Ra),[jc,Gi]=w.useState(0);w.useEffect(()=>{let T=0;const A=()=>{const te=Sr.current;let ye=!1;for(const _e of document.querySelectorAll(".react-flow__node[data-id]")){const Oe=_e.getAttribute("data-id");if(!Oe)continue;const Ve=_e.offsetWidth,it=_e.offsetHeight;if(!Ve||!it)continue;const Ze=te.get(Oe);(!Ze||Math.abs(Ze.width-Ve)>4||Math.abs(Ze.height-it)>4)&&(te.set(Oe,{width:Ve,height:it}),ye=!0)}ye&&Gi(_e=>_e+1)};if(Ca.current)return;let X=0;return document.visibilityState==="hidden"?X=window.setTimeout(A,32):T=requestAnimationFrame(A),()=>{cancelAnimationFrame(T),window.clearTimeout(X)}});const Kt=w.useRef(pc.positions),_c=w.useRef(new Set),jo=w.useRef(""),jr=w.useMemo(()=>OK(l.current.agents.values(),c),[l.current,l.current.revision,c]),Js=w.useMemo(()=>{const T=[];for(const A of l.current.agents.values())!Z0(A,Jt)||jr.has(A.id)||T.push(A.id+(A.parentId?`>${A.parentId}`:""));return T.sort(),`${T.join("|")}#sv${Vi}.${jc}`},[l.current,l.current.revision,Jt,Vi,jc,jr]),Aa=w.useRef(null);w.useEffect(()=>(Aa.current!=null&&window.clearTimeout(Aa.current),Aa.current=window.setTimeout(()=>{Ah(Kt.current,Gt.current)},1500),()=>{Aa.current!=null&&window.clearTimeout(Aa.current)}),[Js]),w.useEffect(()=>{if(xc.current===Js)return;const T=xc.current;if(xc.current=Js,!T||Xs.current)return;Date.now()-Ys.current>1200&&Yn(400),zi.current&&window.clearTimeout(zi.current),zi.current=window.setTimeout(()=>{Xs.current||Yn(500)},280)},[Js,e,Yn]);const _r=w.useMemo(()=>VK(l.current,S),[l.current,l.current.revision,S]),_o=w.useMemo(()=>{const T=fY(l.current,Jt);for(const A of jr)T.delete(A);return T},[l.current,l.current.revision,Jt,jr]),Er=w.useRef(null),[Eo,yd]=w.useState({w:0,h:0});w.useEffect(()=>{const T=Er.current;if(!T||typeof ResizeObserver>"u")return;const A=new ResizeObserver(X=>{var ye;const te=(ye=X[0])==null?void 0:ye.contentRect;te&&(Ui.current={width:te.width,height:te.height},yd(_e=>Math.abs(_e.w-te.width)>40||Math.abs(_e.h-te.height)>40?{w:te.width,h:te.height}:_e))});return A.observe(T),Ui.current={width:T.clientWidth,height:T.clientHeight},yd({w:T.clientWidth,h:T.clientHeight}),()=>A.disconnect()},[]);const Co=w.useCallback(T=>{var X,te;const A=T.target;!(A!=null&&A.closest)||A.closest(yX)!==T.currentTarget||(T.preventDefault(),(te=(X=document.activeElement)==null?void 0:X.blur)==null||te.call(X))},[]),op=w.useRef(new Map),[To,wd]=w.useState(!1);w.useEffect(()=>{const T=window.setTimeout(()=>wd(!0),2500);return()=>window.clearTimeout(T)},[]);const[$t,Ro]=w.useState(!1),fr=w.useRef(null),[Qr,Ec]=w.useState(!1),[Ki,Ma]=w.useState(!1),[Yi,Ia]=w.useState(""),[Ao,vd]=w.useState("far"),xd=w.useRef(null),Cc=gh(Ki,140),Mo=w.useCallback(T=>{var te;const A=(te=xd.current)==null?void 0:te.getBoundingClientRect(),X=HK(T);return A&&X?UK(X,A):"far"},[]),[Xi,Tc]=w.useState("detail"),Jr=w.useRef(null),Io=w.useRef(null),Rc=w.useCallback(()=>{var te;const T=Ta.current;if(((te=Io.current)==null?void 0:te.version)===T)return Io.current.card;const A=[];for(const ye of l.current.agents.keys()){const _e=Sr.current.get(ye);_e&&A.push(_e)}const X=RY(A);return Io.current={version:T,card:X},X},[]),ip=w.useCallback(()=>{fr.current&&(window.clearTimeout(fr.current),fr.current=null),Ro(!1)},[]),bd=w.useCallback(T=>{T.length!==0&&queueMicrotask(()=>{Ro(!0),fr.current&&window.clearTimeout(fr.current),fr.current=window.setTimeout(()=>Ro(!1),wX+80)})},[]);w.useEffect(()=>()=>{fr.current&&window.clearTimeout(fr.current)},[]);const Cn=_?l.current.agents.get(_):null,kd=y&&Cn!=null,[$o,Es]=w.useState(0);w.useEffect(()=>{const T=yR(Er.current);Es(A=>Math.abs(A-T)>40?T:A)},[Be,Pe,W,kd,Eo.w]);const Zi=w.useRef($o);Zi.current=$o;const es=Eo.w>0?Math.max(0,(Eo.w-$o-r0*2)*s0):0,Dn=Eo.h>0?Math.max(0,(Eo.h-r0*2)*s0):0,Oo=fF(),{nodes:mn,edges:Qi}=w.useMemo(()=>{const T=I9(l.current,Jt,es,Dn,Gt.current,Sr.current,op.current,bd,To,Qr,Kt.current,_c.current,Js,jo,S,_r,_o,$);return LK(T.nodes,T.edges,c)},[l.current,l.current.revision,Jt,es,Dn,To,Qr,Js,S,_r,_o,$,ep,Oo,c]),lp=w.useState(TX)[0],Nd=w.useRef(lp);w.useEffect(()=>{if(!To||Qr)return;const T={width:es,height:Dn};if(!(T.width>0&&T.height>0))return;const A=Nd.current;if(Nd.current=T,RX(T),!A||A.width===T.width&&A.height===T.height)return;const X={direction:"LR",pinned:Gt.current,measured:Sr.current,lanes:z0(l.current)};if(!p9(mn,Qi,X,A,T))return;const te=So.current&&Date.now()-So.current.at<1500?So.current.id:null,ye=te??Rs.current,_e=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;for(const Oe of Array.from(Kt.current.keys()))Gt.current.has(Oe)||Kt.current.delete(Oe);_c.current.clear(),jo.current="",m(),window.setTimeout(()=>{if(Ah(Kt.current,Gt.current),Xs.current){if(te){qi.current(te);return}const Oe=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;if(_e&&Oe&&(Oe.x!==_e.x||Oe.y!==_e.y)){const Ve=e.getViewport();No.current+=1,hr({x:Ve.x-(Oe.x-_e.x)*Ve.zoom,y:Ve.y-(Oe.y-_e.y)*Ve.zoom,zoom:Ve.zoom},0),Ys.current=Date.now()}return}Yn(500)},80)},[es,Dn,To,Qr,m,Yn,e,hr]);const Cs=w.useMemo(()=>{const T=new Map;for(const X of mn){const te=X.data;if(!(te!=null&&te.sessionId)||te.exitAt!=null)continue;const ye=X.width,_e=X.height;if(ye==null||_e==null)continue;const Oe=X.position.x,Ve=X.position.y,it=Oe+ye,Ze=Ve+_e,vt=T.get(te.sessionId);vt?(vt.minX=Math.min(vt.minX,Oe),vt.minY=Math.min(vt.minY,Ve),vt.maxX=Math.max(vt.maxX,it),vt.maxY=Math.max(vt.maxY,Ze)):T.set(te.sessionId,{minX:Oe,minY:Ve,maxX:it,maxY:Ze})}const A=[];for(const[X,te]of T){const ye=te.maxX-te.minX+Th*2,_e=te.maxY-te.minY+Th*2;A.push({id:`group:${X}`,type:j$,position:{x:te.minX-Th,y:te.minY-Th},data:{sessionId:X,w:ye,h:_e},width:ye,height:_e,style:{width:ye,height:_e},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return A},[mn]),Lo=w.useMemo(()=>{const T=[...Cs,...mn],A=wa.current;return!A||A.size===0?T:T.map(X=>{const te=A.get(X.id);return te?{...X,position:te}:X})},[Cs,mn,js]),ts=w.useMemo(()=>{const T=new Set;for(const A of l.current.agents.values())for(const X of A.tools)T.add(z$(X.name));return Object.keys(B$).filter(A=>T.has(A))},[l.current,l.current.revision]);w.useEffect(()=>{if(ts.length<=1){Ti(!1);return}let T=0;const A=()=>{const X=Ei.current;if(X&&!document.hidden){const te=X.getBoundingClientRect(),ye=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Oe=>Oe.getBoundingClientRect()),_e=mY(te,ye,8);Ti(Oe=>Oe===_e?Oe:_e)}T=window.setTimeout(A,300)};return A(),()=>window.clearTimeout(T)},[ts.length]);const Ji=w.useCallback(T=>{gc(A=>{const X=new Set(A);return X.has(T)?X.delete(T):X.add(T),X})},[]),Po=j?K5(l.current.agents,j):null,ea=w.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}l.current=S0(),Gt.current.clear(),Sr.current.clear(),Kt.current.clear(),jo.current="",kR(),u(new Set),p(null);try{window.localStorage.removeItem(uk)}catch{}R(),m()},[m,R]),Cr=w.useCallback(T=>{const A=l.current.agents.get(T);A&&(u(X=>{const te=new Set(X);return te.add(T),sR(window.localStorage,te),te}),p({id:T,label:A.label}),Gt.current.delete(T),Kt.current.delete(T),R())},[R]),At=w.useCallback(()=>{_&&Cr(_)},[_,Cr]),Mt=f&&c.has(f.id)?f:null;w.useEffect(()=>{var T;f&&((T=Er.current)==null||T.focus())},[f]);const Zn=w.useCallback(T=>{const A=[...T];u(X=>{const te=PK(X,A);return te!==X&&sR(window.localStorage,te),te})},[]),an=w.useRef(V);an.current=V;const bn=w.useRef(ee);bn.current=ee;const ns=w.useRef(!1);ns.current=Po!=null||Kr||H!=null||Z||I!=null||ga||ee||ur!=null;const rs=w.useCallback(T=>{const A=D9(T,{confirmOpen:an.current,modalOpen:ns.current});A==="confirm"?ne(!0):A==="clear"&&(ne(!1),ea())},[ea]),gn=w.useCallback(()=>{Gt.current.clear(),Kt.current.clear(),jo.current="",kR(),m(),window.setTimeout(()=>Yn(500),80)},[m,e,Yn]),Do=w.useCallback(()=>Yn(500),[Yn]),Ts=w.useRef(mn);Ts.current=mn;const Fn=w.useCallback(T=>{var vt;const A=Er.current,X=l.current.agents.get(T);if(!A||!X)return;const te=z0(l.current),ye=(Et,kn)=>{const Jn=Sr.current.get(Et.id);if(!Jn)return null;const Oa=kn&&te.has(Et.id)?gd:0;return{x:Et.position.x,y:Et.position.y,width:Jn.width+Oa,height:Jn.height}},_e=Ts.current.find(Et=>Et.id===T),Oe=_e?ye(_e,!1):null;if(!Oe)return;const Ve=[];for(const Et of Ts.current){if(Et.type!=="agent"&&Et.type!=="recapNote"||((vt=Et.data)==null?void 0:vt.sessionId)!==X.sessionId)continue;const kn=ye(Et,Et.type==="agent");kn&&Ve.push(kn)}const it=A.getBoundingClientRect(),Ze=PY({pane:{width:it.width,height:it.height},insets:{top:56,left:72,bottom:32,right:Zi.current+32},context:DY(Ve)??Oe,anchor:Oe});Ka(),Qs(),So.current={id:T,at:Date.now()},No.current+=1,hr(Ze,a0),Ys.current=Date.now(),Zr.current=Ch({durationMs:a0,documentHidden:document.hidden})?{target:Ze,until:Date.now()+a0+60}:null},[hr,Qs]);qi.current=Fn;const el=w.useCallback(T=>{const A=Ts.current.find(X=>X.id===T&&X.type==="agent");return A?A.data:void 0},[]),Sd=w.useCallback(T=>{var A;return(A=l.current.agents.get(T))==null?void 0:A.label},[]),ss=w.useCallback(T=>{var te;const A=Ts.current.find(ye=>ye.id===T&&ye.type==="recapNote");if(!A)return;const X=A.data;return{recap:X.recap,hue:X.hue,sessionLabel:(te=l.current.agents.get(X.parentId))==null?void 0:te.label}},[]),tl=w.useCallback(()=>{var X;const T=(X=Er.current)==null?void 0:X.getBoundingClientRect(),A=document.documentElement;return T?{width:T.right-Zi.current,height:T.bottom}:{width:A.clientWidth,height:A.clientHeight}},[]),Rs=w.useRef(_);Rs.current=_;const Ac=w.useRef(At);Ac.current=At;const nl=w.useCallback(T=>{const A=Ts.current.filter(_e=>_e.type==="agent"),X=TK(A.map(_e=>({id:_e.id,x:_e.position.x,y:_e.position.y})),Rs.current,T),te=X?A.find(_e=>_e.id===X):void 0;if(!te)return;const ye=n0(document.activeElement);C(te.id,!1),window.setTimeout(()=>{try{Fn(te.id)}catch{}ye&&gX(te.id)},30)},[C,Fn]),Tr=w.useRef(null),Qn=w.useCallback(T=>{C(T,!1),window.setTimeout(()=>{try{Fn(T)}catch{}},60)},[C,Fn]),$a=w.useCallback(T=>{jr.has(T)&&Zn([T]),Qn(T)},[jr,Zn,Qn]),Fo=w.useRef(null);w.useEffect(()=>{let T=-1/0;const A=()=>{T=performance.now()},X=te=>{Fo.current=performance.now()-T<250?te.target:null};return window.addEventListener("pointerdown",A,!0),window.addEventListener("focusin",X,!0),()=>{window.removeEventListener("pointerdown",A,!0),window.removeEventListener("focusin",X,!0)}},[]),w.useEffect(()=>{const T=A=>{var Ve,it;const X=A.target,te={tagName:X==null?void 0:X.tagName,isContentEditable:X==null?void 0:X.isContentEditable,role:(Ve=X==null?void 0:X.getAttribute)==null?void 0:Ve.call(X,"role"),type:X==null?void 0:X.type,pointerFocused:X!=null&&X===Fo.current};if(A.key==="Escape"){const Ze=P6({overlayOpen:pu.depth()>0,typing:Sf(te)});Ze==="dismiss"?pu.dismissTop():Ze==="blur"?X==null||X.blur():(IK(te)&&(X==null||X.blur()),R());return}if(Nf(A))return;const ye=n0(X)?(it=X==null?void 0:X.getAttribute)==null?void 0:it.call(X,"data-id"):null,_e=ye&&Ts.current.some(Ze=>Ze.id===ye)?ye:null,Oe=AK(A,_e);if(Oe.kind==="activate"){A.preventDefault(),C(Oe.nodeId,Oe.additive);return}if(Oe.kind!=="node"&&!(Oe.nodeId==null&&V6(te,A.key))&&!G6({key:A.key,modalOpen:K6({appModal:ns.current,dialogDepth:pu.dialogDepth()}),sheetOpen:bn.current})){if(A.key===" "&&(A.preventDefault(),va()),(A.key==="c"||A.key==="C")&&rs("shortcut"),(A.key==="r"||A.key==="R")&&gn(),(A.key==="f"||A.key==="F")&&Do(),(A.key==="z"||A.key==="Z")&&Rs.current&&Fn(Rs.current),A.key==="Delete"&&Ac.current(),(A.key==="l"||A.key==="L")&&fo(),A.key==="d"||A.key==="D")if(Rs.current)v(Ze=>!Ze);else{const Ze=vm(l.current.agents.values());Ze.length>0?Qn(Ze[0].id):nl(1)}if((A.key==="h"||A.key==="H")&&kr(Ze=>!Ze),(A.key==="u"||A.key==="U")&&F(Ze=>!Ze),(A.key==="a"||A.key==="A")&&Si.current.claude&&Gr(),(A.key==="j"||A.key==="J")&&nl(1),(A.key==="k"||A.key==="K")&&nl(-1),A.key==="w"||A.key==="W"){const Ze=_6(vm(l.current.agents.values()),Tr.current);Ze&&(Tr.current=Ze.id,Qn(Ze.id))}(A.key==="t"||A.key==="T")&&ld(Ze=>Ze==="dark"?"light":"dark"),(A.key==="m"||A.key==="M")&&Si.current.claude&&be.current!==null&&se.current(A.shiftKey),(A.key==="s"||A.key==="S")&&le(Ze=>!Ze),(A.key==="b"||A.key==="B")&&Ws(Ze=>!Ze),(A.key==="v"||A.key==="V")&&Si.current.claude&&be.current!==null&&rn(Ze=>!Ze),A.key==="?"&&M(Ze=>!Ze)}};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[rs,gn,Do,R,C,nl,Qn,Fn,va]);const qo=l.current.agents.size,_t=w.useMemo(()=>vm(l.current.agents.values()),[l.current,l.current.revision]);w.useEffect(()=>{const T=DK(_t,jr);T.length>0&&Zn(T)},[_t,jr,Zn]);const qn=w.useMemo(()=>E6(l.current.agents.values()),[l.current,l.current.revision]),As=w.useRef(null);w.useEffect(()=>{const T=aY({waiting:_t.length,running:qn,connected:Lt}),A=As.current;if(As.current=T,(A==null?void 0:A.title)!==T.title&&(document.title=T.title),(A==null?void 0:A.icon)!==T.icon){const X=document.querySelector('link[rel="icon"]');X&&(X.href=oY[T.icon])}},[_t.length,qn,Lt]);const[as,os]=w.useState(""),Ms=lY(_t);w.useEffect(()=>{os(T=>aR(T,Ms))},[Ms]);const[jd,rl]=w.useState(""),sl=dr>0?`Browser watch has ${dr} unread ${dr===1?"finding":"findings"}.`:"";w.useEffect(()=>{rl(T=>aR(T,sl,"Browser watch has no unread findings."))},[sl]);const[yn,Bn]=w.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[St,zn]=w.useState(null),[Bo,al]=w.useState(!1),[Mc,ol]=w.useState(!1);w.useEffect(()=>{let T=!0;return fetch("/api/prefs").then(A=>A.ok?A.json():null).then(A=>{var X,te,ye;if(!(!T||!(A!=null&&A.ok))){if(!ba.current){let _e=!1;try{_e=window.localStorage.getItem(Rh)==="0",window.localStorage.removeItem(Rh)}catch{}_e&&((X=A.prefs)==null?void 0:X.autoUpdate)!==!1?(xa(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):xa(((te=A.prefs)==null?void 0:te.autoUpdate)!==!1)}al(((ye=A.prefs)==null?void 0:ye.notifications)===!0),ol(A.notificationsVetoed===!0)}}).catch(()=>{}),()=>{T=!1}},[]);const Ic=w.useRef(()=>{}),il=w.useCallback(()=>{const T=!Bo;al(T),T&&typeof Notification<"u"&&Notification.permission==="default"&&Ic.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:T})}).then(A=>A.ok?A.json():null).then(A=>{var X;A!=null&&A.ok&&(al(((X=A.prefs)==null?void 0:X.notifications)===!0),ol(A.notificationsVetoed===!0))}).catch(()=>{})},[Bo]),_d=typeof Notification<"u";w.useEffect(()=>{if(!St)return;const A=setTimeout(()=>zn(null),St==="blocked"?8e3:4e3);return()=>clearTimeout(A)},[St]);const ta=w.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(T=>{const A=T;Bn(A),A==="granted"?zn("on"):A==="denied"&&zn("blocked")})},[]);Ic.current=ta;const na=w.useRef(new Set),$c=w.useRef(null),zo=_t.map(T=>kf(T.id,T.waiting)).join("|");w.useEffect(()=>{A6($c.current,yn)&&($c.current=yn,na.current=xm(_t))},[yn]);const Uo=w.useRef(!1);return w.useEffect(()=>{M6(Uo.current,_a)&&(Uo.current=!0,na.current=xm(_t))},[_a]),w.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!I6($c.current,_a))return;const T=typeof document>"u"||!document.hidden,A=T6(_t,na.current,T,Bo);for(const X of A)try{const te=new Notification(X.title,{body:X.body,tag:X.key});te.onclick=()=>{window.focus(),Qn(X.sessionId),te.close()}}catch{}na.current=T?xm(_t):R6(_t,A,na.current)},[zo,_a]),o.jsxs("div",{className:"app",children:[o.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),o.jsxs("header",{className:"topbar",children:[o.jsxs("div",{className:"readout",children:[o.jsxs("div",{className:"brand",children:[o.jsx("span",{className:"logo"}),o.jsx("h1",{children:dn}),Qt?(()=>{const T=SK(kK()??io,Qt.version);return o.jsxs("button",{type:"button",className:"v ready",onClick:pa,"aria-haspopup":"dialog","aria-label":T.label,title:T.title,children:[T.text,o.jsx("span",{className:"v-dot","aria-hidden":!0})]})})():ht?o.jsxs("button",{type:"button",className:"v stale",onClick:()=>{pa(),oc()},"aria-haspopup":"dialog","aria-label":ZY({...ht,open:ma}),title:ht.kind==="restart"?`Running v${ht.from}; v${ht.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${ht.from}; v${ht.to} is on npm · click for what's new`,children:["v",ht.from,o.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const T={running:io,latest:xe==null?void 0:xe.latest,latestPending:xe==null?void 0:xe.latestPending,checkedAgo:xe!=null&&xe.checkedAt?Ph(Jt-xe.checkedAt):null,checkFailedAgo:xe!=null&&xe.checkFailedAt&&xe.checkFailedAt>(xe.checkedAt??0)?Ph(Jt-xe.checkFailedAt):null,checkDisabled:xe==null?void 0:xe.checkDisabled,checking:tt};return o.jsxs("button",{type:"button",className:tt?"v checking":"v",onClick:()=>{pa(),gt(!0)},"aria-busy":tt||void 0,"aria-haspopup":"dialog","aria-label":XY(T),title:YY(T),children:["v",T.running]})})()]}),o.jsxs("span",{className:"status",children:[(()=>{const T=dX({connected:Lt,paused:go,held:En.size,dropped:En.dropped});return T.resting?null:o.jsx("span",{className:`pill ${T.tone}`,title:T.title,children:o.jsxs("span",{className:"pill-box",children:[o.jsx("span",{className:"pill-widest","aria-hidden":!0,children:T.widest}),o.jsx("span",{className:"pill-label",children:T.label})]})})})(),o.jsxs("span",{ref:z,className:"month-usage",title:G?`${G.tokens.toLocaleString()} tokens · ${fR(G.cost)} spent since the 1st of this local calendar month`:U?"Monthly usage is unavailable — ccusage could not be read":"Loading usage since the 1st of this local calendar month",children:[o.jsx("span",{className:"month-usage-label",children:"this month"}),G?o.jsxs(o.Fragment,{children:[o.jsx("b",{children:Bt(G.tokens)}),o.jsx("span",{className:"month-usage-unit",children:"tokens"}),o.jsx("span",{className:"month-usage-sep","aria-hidden":!0,children:"·"}),o.jsx("b",{children:fR(G.cost)})]}):o.jsx("span",{className:"month-usage-pending",children:U?"unavailable":"…"})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:as}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:jd}),_t.length>0&&o.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{Tr.current=_t[0].id,Qn(_t[0].id)},title:`Blocked waiting for you — click, or press W, to go to the one that has been stuck longest:
|
|
290
|
+
Click to set the volume and the sound of each tone, and to hear either one.`}function df(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const mR=99;function iX(e){const t=Math.max(0,Math.floor(e));return t>mR?`${mR}+`:String(t)}const lX="Pause the canvas";function cX(e){if(!e.paused)return"Pause live updates — events keep arriving and are applied when you resume (Space)";const t=Math.max(0,Math.floor(e.dropped??0));return t>0?`The pause is full — ${df(e.held)} held and ${t} older ${t===1?"one":"ones"} already dropped. Resume to follow the canvas again (Space)`:e.held<=0?"Nothing has arrived since you paused. Resume to follow the canvas again (Space)":`${df(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function uX(e){return e.connected||!e.paused?null:"The canvas is paused as well — Space resumes it, but nothing new arrives until the stream is back."}const O$="paused · full",dX=(e,t)=>t>0?O$:e>0?`paused · ${iX(e)}`:"paused";function hX(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:dX(e.held,t),widest:O$,title:t>0?`Connected — the pause is full at ${df(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${df(e.held)} held until you resume (Space)`:"Connected — updates held until you resume (Space)"}:{tone:"live",resting:!0,label:"live",widest:"live",title:"Receiving events"}:{tone:"dead",resting:!1,label:"offline",widest:"offline",title:e.paused?"SSE disconnected — and the canvas is paused, so resuming will not bring events back until it reconnects":"SSE disconnected"}}const fX=w.lazy(()=>nb(()=>import("./UsageHistoryModal-Dk5zag6g.js"),[])),pX=w.lazy(()=>nb(()=>import("./BrowserWatchModal-RXK8WXaU.js"),[]));function gR(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const mX={agent:eq,sessionGroup:Mq,recapNote:$q},gX={recapTie:Oq},L$="react-flow__node";function n0(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,L$))===!0}const r0=80,s0=.86;function yR(e){if(!e)return 0;const t=e.getBoundingClientRect();let n=t.right;for(const r of document.querySelectorAll(".sysdetail:not(.leaving), .usage-panel:not(.leaving)")){const s=r.getBoundingClientRect();s.width>0&&s.left>t.left&&(n=Math.min(n,s.left))}return Math.max(0,t.right-n)}function yX(e){try{const t=document.querySelector(`.${L$}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const wX=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),vX=420,Th=18,wR=400,a0=450,hk="agent-dag.layout",fk="agent-dag.layoutFrame",pk="agent-dag.viewport",P$="agent-dag.sessionListOpen",D$="agent-dag.detailOpen",F$="agent-dag.usagePanelOpen",q$="agent-dag.systemPanelOpen",vR="agent-dag.accountsPanelOpen",o0="agent-dag.versionNoticeDismissed",xR="agent-dag.oldNameNoticeDismissed",xX=15*6e4,i0={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:",retired_name:"this install came from a name that is no longer published — run:"},Rh="agent-dag.autoRestart",bR="agent-dag.bundleReloadedFor";function bX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(P$)==="1"}catch{return!1}}function kX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(P$,e?"1":"0")}catch{}}function NX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(D$)==="1"}catch{return!1}}function SX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(D$,e?"1":"0")}catch{}}function jX(){const e=yr(F$);return e===null?!0:e==="1"}function _X(e){if(!(typeof window>"u"))try{window.localStorage.setItem(F$,e?"1":"0")}catch{}}function EX(){const e=yr(q$);return e===null?!0:e==="1"}function CX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(q$,e?"1":"0")}catch{}}function TX(){if(typeof window>"u")return{positions:[],pins:[]};try{return bY(window.localStorage.getItem(hk))}catch{return{positions:[],pins:[]}}}function Ah(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(hk,kY(e,t))}catch{}}function RX(){if(typeof window>"u")return null;try{return NY(window.localStorage.getItem(fk))}catch{return null}}function AX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(fk,JSON.stringify(e))}catch{}}function MX(){if(typeof window>"u")return null;try{return SY(window.localStorage.getItem(pk))}catch{return null}}function IX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(pk,JSON.stringify(e))}catch{}}function kR(){if(!(typeof window>"u")){try{window.localStorage.removeItem(hk)}catch{}try{window.localStorage.removeItem(pk)}catch{}try{window.localStorage.removeItem(fk)}catch{}}}function $X(e,t){const n=P9(e,t,new Date().toISOString());if(!n)return;const r=JSON.stringify(n,null,2),s=new Blob([r],{type:"application/json"}),l=URL.createObjectURL(s),c=document.createElement("a");c.href=l,c.download=D9(n.label,t),document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(l),1e3)}const B$={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},OX={file:"M3.4 1.8h4.5l2.7 2.7v7.7H3.4z M7.9 1.8v2.7h2.7",shell:"M2.4 3.8 5.6 7l-3.2 3.2 M7.4 10.6h4.2",web:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M1.8 7h10.4 M7 1.8c-1.5 1.4-2.3 3.1-2.3 5.2s.8 3.8 2.3 5.2c1.5-1.4 2.3-3.1 2.3-5.2S8.5 3.2 7 1.8z",agent:"M3.3 4.8h7.4a1.2 1.2 0 0 1 1.2 1.2v4.8a1.2 1.2 0 0 1-1.2 1.2H3.3a1.2 1.2 0 0 1-1.2-1.2V6a1.2 1.2 0 0 1 1.2-1.2z M7 4.8V2.4 M5.3 8.2h.01 M8.7 8.2h.01",task:"M2.2 4l1.2 1.2 2-2.2 M7.4 4.2h4.4 M2.2 9.4l1.2 1.2 2-2.2 M7.4 9.6h4.4",plan:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M9 5 8 8 5 9l1-3z",mcp:"M5 1.8v2.6 M9 1.8v2.6 M3.6 4.4h6.8v2.2a3.4 3.4 0 0 1-6.8 0z M7 10v2.2",other:"M3.5 7h.01 M7 7h.01 M10.5 7h.01"};function LX({cat:e}){return o.jsx("svg",{className:"cat-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:OX[e]})})}const hf={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},z$=mM;function PX(){return o.jsx(xb,{children:o.jsx(qX,{})})}const DX=e=>e.transform[2]>=e.maxZoom,FX=e=>e.transform[2]<=e.minZoom;function qX(){var Oc,Lc,ra,Pc;const e=xf(),t=Tt(DX),n=Tt(FX),r=tn(),s=w.useState(S0)[0],l=w.useRef(s),[c,u]=w.useState(()=>OK(typeof window>"u"?null:window.localStorage)),[f,p]=w.useState(null),[,h]=w.useState(0),m=w.useCallback(()=>h(T=>T+1),[]),[y,v]=w.useState(NX);w.useEffect(()=>{SX(y)},[y]);const[S,b]=w.useState(()=>new Set),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useCallback((T,A,X=!A)=>{b(te=>{if(!A)return new Set([T]);const ye=new Set(te);return ye.has(T)?ye.delete(T):ye.add(T),ye}),k(te=>A&&te===T?te:T),!A&&X&&v(!0)},[]),R=w.useCallback(()=>{b(new Set),k(null)},[]),[I,O]=w.useState(null),[H,q]=w.useState(null),$=w.useCallback(T=>q(T),[]),[V,ne]=w.useState(!1),[ee,M]=w.useState(!1),[Z,K]=w.useState(!1),D=w.useRef(null),[P,B]=w.useState(bX);w.useEffect(()=>{kX(P)},[P]);const[W,F]=w.useState(jX);w.useEffect(()=>{_X(W)},[W]);const[G,re]=w.useState(null),[U,Y]=w.useState(!1),z=w.useRef(null);w.useEffect(()=>{let T=!0,A=!1,X=null,te=null,ye="";const _e=vt=>{T&&(Y(!0),vt!==ye&&re(null))},Oe=()=>{if(A)return;A=!0,X=Date.now();const vt=hR();te=vt,fetch(`/api/ccusage?since=${vt}`).then(Et=>Et.ok?Et.json():null).then(Et=>{if(T){if(!(Et!=null&&Et.ok)){_e(vt);return}ye=vt,re(KY(Et)),Y(!1)}}).catch(()=>_e(vt)).finally(()=>{A=!1})},Ve=()=>{const vt=z.current;GY({shown:!!vt&&vt.getClientRects().length>0,tabVisible:document.visibilityState==="visible",lastSince:te,since:hR(),lastReadAt:X,now:Date.now()})&&Oe()};Ve();const it=window.setInterval(Ve,VY);document.addEventListener("visibilitychange",Ve);let Ze=null;return z.current&&typeof ResizeObserver<"u"&&(Ze=new ResizeObserver(Ve),Ze.observe(z.current)),()=>{T=!1,window.clearInterval(it),document.removeEventListener("visibilitychange",Ve),Ze==null||Ze.disconnect()}},[]);const[ie,le]=w.useState(EX);w.useEffect(()=>{CX(ie)},[ie]);const ge=w.useRef(!1),[Ne,Ie]=w.useState(()=>{const T=(()=>{try{const A=window.localStorage.getItem(vR);return A===null?!0:A==="1"}catch{return!0}})();return T&&P?(ge.current=!0,!1):T});w.useEffect(()=>{if(!(!Ne&&ge.current))try{window.localStorage.setItem(vR,Ne?"1":"0")}catch{}},[Ne]),w.useEffect(()=>{!P&&ge.current&&(ge.current=!1,Ie(!0))},[P]);const Ge=gh(Ne,200),Pe=gh(W,130),Be=gh(ie,130),[Te,st]=w.useState(null);w.useEffect(()=>{let T=null;try{T=localStorage.getItem("agent-dag.sound")}catch{}st(T===null?!0:T==="on")},[]);const de=w.useCallback(()=>{st(T=>{var X;const A=T!==!0;try{localStorage.setItem("agent-dag.sound",A?"on":"off")}catch{}return A&&((X=Ut.current)==null||X.unlock()),A})},[]),ue=w.useCallback(T=>{de()},[de]),se=w.useRef(ue);se.current=ue;const be=w.useRef(Te);be.current=Te;const[Le,ce]=w.useState(()=>vV(yr)),pe=w.useRef(Le);pe.current=Le;const[Ae,fe]=w.useState(()=>X9(yr)),Se=w.useRef(Ae);Se.current=Ae;const[Ye,qe]=w.useState([]),ke=w.useCallback(T=>{fe(A=>{const X={...A,[T]:null};return Se.current=X,X});try{localStorage.removeItem(yu[T])}catch{}},[]),Re=w.useCallback((T,A)=>{const X=Se.current[T];if(!(A&&X!==A)){ke(T),ce(te=>{const ye={...te,[T]:{...te[T],figure:wr}};return pe.current=ye,ye});try{localStorage.setItem(Bh[T],wr)}catch{}}},[ke]),ze=w.useRef(Re);ze.current=Re,w.useEffect(()=>{let T=!0;return iV().then(A=>{if(!T)return;qe(A);const X=new Set(A.map(te=>te.id));for(const te of qh){const ye=Se.current[te];ye&&!X.has(ye)&&ze.current(te,ye)}},()=>{}),()=>{T=!1}},[]);const Fe=w.useRef(null),We=w.useCallback((T,A=!1)=>{var X,te;if((X=Ut.current)==null||X.unlock(),Fe.current!==null&&clearTimeout(Fe.current),Fe.current=null,!A){(te=Ut.current)==null||te.play(T,!0);return}Fe.current=setTimeout(()=>{var ye;Fe.current=null,(ye=Ut.current)==null||ye.play(T,!0)},pV)},[]),rt=w.useCallback((T,A)=>{ce(X=>{const te={level:Kl(A.level??X[T].level),figure:s$(T,A.figure??X[T].figure)};try{localStorage.setItem(i$[T],String(te.level)),localStorage.setItem(Bh[T],te.figure)}catch{}return{...X,[T]:te}}),We(T,!0)},[We]),dt=w.useCallback((T,A)=>{if(!Ye.some(te=>te.id===A))return;const X={...Se.current,[T]:A};Se.current=X,fe(X);try{localStorage.setItem(yu[T],A)}catch{}We(T,!0)},[Ye,We]),ct=w.useCallback(async T=>{var ye;const A=H0(Ye.length);if(A)throw new Error(A);const X=window.AudioContext??window.webkitAudioContext;if(!X)throw new Error("This browser cannot decode audio files.");const te=new X;try{const _e=await nV(T,Ve=>te.decodeAudioData(Ve));await I2(_e);const Oe=Ou(_e);qe(Ve=>[...Ve.filter(it=>it.id!==Oe.id),Oe])}finally{(ye=te.close)==null||ye.call(te)}},[Ye.length]),yt=w.useCallback(async T=>{const A=H0(Ye.length);if(A)throw new Error(A);const X=rV(T);await I2(X);const te=Ou(X);qe(ye=>[...ye.filter(_e=>_e.id!==te.id),te])},[Ye.length]),Ot=w.useCallback(async(T,A)=>{const X=Ye.find(ye=>ye.id===T),te=A.trim().slice(0,80);!X||!te||te===X.name||(await cV(T,te),qe(ye=>ye.map(_e=>_e.id===T?{..._e,name:te}:_e)))},[Ye]),zt=w.useCallback(async T=>{await uV(T),qe(ye=>ye.filter(_e=>_e.id!==T));const A=Se.current,X=Z9(A,T);Se.current=X,fe(X);const te=qh.filter(ye=>A[ye]===T);for(const ye of te)try{localStorage.removeItem(yu[ye]),localStorage.setItem(Bh[ye],wr)}catch{}te.length>0&&ce(ye=>{const _e={...ye};for(const Oe of te)_e[Oe]={..._e[Oe],figure:wr};return pe.current=_e,_e})},[]),Xt=w.useCallback(T=>{var te,ye;const A=qh.find(_e=>Se.current[_e]===T),X=A?pe.current[A].level:gi;(te=Ut.current)==null||te.unlock(),(ye=Ut.current)==null||ye.previewCustom(T,X)},[]);w.useEffect(()=>()=>{Fe.current!==null&&clearTimeout(Fe.current)},[]);const[Dt,rn]=w.useState(!1),je=w.useRef(null),[xt,bt]=w.useState(!1),_n=w.useRef(null);w.useEffect(()=>{Dt&&bt(!1)},[Dt]);const Ut=w.useRef(null),[Vn,Vt]=w.useState("locked");w.useEffect(()=>{const T=bV({enabled:()=>be.current===!0,prefs:()=>pe.current,customSelection:()=>Se.current,loadCustom:lV,onCustomFailure:(X,te)=>ze.current(X,te),onState:Vt});Ut.current=T,Vt(T.state());const A=()=>T.unlock();return window.addEventListener("pointerdown",A,{once:!0,capture:!0}),window.addEventListener("keydown",A,{once:!0,capture:!0}),()=>{window.removeEventListener("pointerdown",A,{capture:!0}),window.removeEventListener("keydown",A,{capture:!0})}},[]);const[Lt,Zt]=w.useState(!1),[In,Hr]=w.useState(!1),[xe,lr]=w.useState(null),[ks,Wr]=w.useState(null),[fa,Ns]=w.useState(!1),[xr,$n]=w.useState(null),[Hs,Q]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(o0)??""}catch{return""}}),[De,et]=w.useState(!1),Ue=w.useRef(0),[tt,wt]=w.useState(!1),gt=w.useCallback((T=!1)=>(T&&(Ue.current=Date.now(),wt(!0)),fetch(T?"/api/version?refresh=1":"/api/version").then(A=>A.ok?A.json():null).then(A=>{A&&lr(A)}).catch(()=>{}).finally(()=>{T&&wt(!1)})),[]),It=w.useCallback(()=>{gt(Date.now()-Ue.current>=xX)},[gt]);w.useEffect(()=>{gt();const T=window.setInterval(It,5*6e4),A=()=>{document.visibilityState==="visible"&&It()};return document.addEventListener("visibilitychange",A),()=>{window.clearInterval(T),document.removeEventListener("visibilitychange",A)}},[gt,It]),w.useEffect(()=>{Lt&>()},[Lt,gt]);const Rt=w.useRef(0);w.useEffect(()=>{if(!Lt||!hu())return;let T=!1;const A=Rt.current;return fetch("/api/desktop-update").then(X=>X.ok?X.json():null).then(X=>{if(T||Rt.current!==A)return;const te=rR(X);te&&Wr(te)}).catch(()=>{}),()=>{T=!0}},[Lt]);const Qt=kK(ks),Nt=w.useRef(!1),br=w.useRef(0),cr=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(br.current),[]);const ki=w.useCallback(async T=>{if(!Ps(Nt.current))return;const A=++cr.current;window.clearTimeout(br.current),Nt.current=!0,Ns(!0),$n(null);const X=te=>{A===cr.current&&(window.clearTimeout(br.current),Nt.current=!1,Ns(!1),$n({failure:te,version:T}))};try{const te=await fetch("/api/desktop-update/restart",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:T})});if(!te.ok)return X(_K(await te.json().catch(()=>null)))}catch{return X("unreachable")}A===cr.current&&(br.current=window.setTimeout(()=>X("timeout"),b$))},[]);w.useEffect(()=>{const T=sK();let A=null;const X=Oe=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:T,looking:Oe}),keepalive:!0}).catch(()=>{})},te=()=>{const Oe=nK(document);rK(A,Oe)&&X(Oe),A=Oe},ye=()=>{A&&X(!1),A=!1};te();const _e=window.setInterval(te,tK);return window.addEventListener("focus",te),window.addEventListener("blur",te),document.addEventListener("visibilitychange",te),window.addEventListener("pagehide",ye),()=>{window.clearInterval(_e),window.removeEventListener("focus",te),window.removeEventListener("blur",te),document.removeEventListener("visibilitychange",te),window.removeEventListener("pagehide",ye),ye()}},[]);const ht=(xe==null?void 0:xe.notice)??null,[ur,sn]=w.useState(null),Vr=ur&&Qt?Qt.version:null,Gn=w.useRef(null);w.useEffect(()=>{!Vr||Gn.current===Vr||(Gn.current=Vr,fetch("/api/desktop-update/seen",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:Vr})}).catch(()=>{}))},[Vr]);const Xu=w.useRef(!1);w.useEffect(()=>{if(Xu.current)return;const T=nR(),A=fK(T),X=vK({stored:A,running:(xe==null?void 0:xe.running)??null,notes:tR,remembers:pK(T)});if(X.reason==="no-version")return;Xu.current=!0,X.record&&mK(T,X.record);let te=!0;return(async()=>{var it;let _e=gK(T);if(hu())try{const Ze=await fetch("/api/prefs");if(!Ze.ok)throw new Error("desktop tour preferences unavailable");const vt=await Ze.json();if(!(vt!=null&&vt.ok))throw new Error("desktop tour preferences unavailable");const Et=((it=vt.prefs)==null?void 0:it.tourSeen)===!0;_e&&!Et&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{}),_e=_e||Et}catch{_e=!0}if(!te)return;const Oe=wK({tourSeen:_e,decision:X}),Ve=X.show.length?{entries:X.show,since:A,firstRun:!1}:null;Oe.tour&&K(!0),Oe.notes==="now"?sn(Ve):Oe.notes==="after"&&(D.current=Ve)})(),()=>{te=!1}},[xe==null?void 0:xe.running]);const io=(xe==null?void 0:xe.running)??"3.29.3",Zu=w.useMemo(()=>w$(tR,null,io),[io]),pa=w.useCallback(()=>{sn({entries:Zu,since:null,firstRun:!1})},[Zu]),[Ni,lo]=w.useState(null),[Kn,Zf]=w.useState(eb);w.useEffect(()=>{let T=!1;return fetch("/api/health").then(A=>A.ok?A.json():null).then(A=>{T||(Zf(tX(A)),!(!A||typeof A.workspace!="string")&&lo(A.workspace))}).catch(()=>{}),()=>{T=!0}},[Lt]);const Si=w.useRef(Kn);Si.current=Kn;const co=$$(ht),ma=JY(ht,Hs),oc=w.useCallback(()=>{Q("");try{window.localStorage.setItem(o0,"")}catch{}},[]),uo=w.useCallback(()=>{if(ht){Q(co);try{window.localStorage.setItem(o0,co)}catch{}}},[ht,co]),[Qf,ic]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(xR)??""}catch{return""}}),ft=xe!=null&&xe.invokedAs&&xe.invokedAs!==dn?xe.invokedAs:null,Qu=ft!=null&&Qf!==ft,Ju=w.useCallback(()=>{if(ft){ic(ft);try{window.localStorage.setItem(xR,ft)}catch{}}},[ft]),On=((Oc=xe==null?void 0:xe.upgrade)==null?void 0:Oc.state)??"idle",ho=BU(xe==null?void 0:xe.upgrade),ji=w.useRef(!1),ed=w.useCallback(async()=>{if(Ps(ji.current||On==="running")){ji.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await gt(),ji.current=!1}},[On,gt]);w.useEffect(()=>{if(On!=="running")return;const T=window.setInterval(gt,3e3);return()=>window.clearInterval(T)},[On,gt]);const lc=w.useCallback(async()=>{const T=xe==null?void 0:xe.command;!T||!await hi(T)||(et(!0),window.setTimeout(()=>et(!1),1600))},[xe==null?void 0:xe.command]),fo=w.useCallback(()=>{B(T=>(T||Ie(A=>(A&&(ge.current=!0),!1)),!T))},[]),Gr=w.useCallback(()=>{ge.current=!1,Ie(T=>(T||B(!1),!T))},[]),[Kr,kr]=w.useState(!1),[ga,Ws]=w.useState(!1),[Yr,Jf]=w.useState(()=>{try{return Number(localStorage.getItem(oR))||0}catch{return 0}}),[cc,po]=w.useState([]),[uc,dc]=w.useState(!1);w.useEffect(()=>{let T=!0;const A=()=>{fetch("/api/browser-watch?live=0").then(te=>te.ok?te.json():null).then(te=>{var ye;!T||!(te!=null&&te.ok)||(po(te.episodes??[]),dc(((ye=te.settings)==null?void 0:ye.enabled)===!0))}).catch(()=>{})};A();const X=setInterval(A,5*6e4);return()=>{T=!1,clearInterval(X)}},[]);const[_i,mo]=w.useState([]),td=w.useRef(new Set),[Ss,ya]=w.useState(null);w.useEffect(()=>{let T=!0,A=0;const X=()=>{fetch("/api/lan").then(te=>te.ok?te.json():null).then(te=>T?(te!=null&&te.ok&&mo(JS(Array.isArray(te.pending)?te.pending:[],te.aliases)),te):null).catch(()=>null).then(te=>{T&&(A=window.setTimeout(X,(te==null?void 0:te.enabled)===!0?q0:VM))})};return X(),()=>{T=!1,window.clearTimeout(A)}},[]);const Vs=w.useCallback(async(T,A)=>{if(!Ss){ya(T);try{const te=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:T,fp:A})})).json().catch(()=>null);te&&Array.isArray(te.pending)?mo(JS(te.pending,te.aliases)):mo(ye=>ye.filter(_e=>_e.fp!==A))}catch{}finally{ya(null)}}},[Ss]),dr=w.useMemo(()=>uY(cc,Yr).length,[cc,Yr]),[ep,nd]=w.useState(0),Ei=w.useRef(null),[Ci,Ti]=w.useState(!1),wa=w.useRef(null),[js,Ri]=w.useState(0),En=w.useState(()=>QK({protect:T=>n6(l.current,T)}))[0],[go,Ai]=w.useState(!1),va=w.useCallback(()=>{const T=En.paused&&En.dropped>0,A=En.setPaused(!En.paused);T&&r6(l.current);for(const X of A)l.current=zN(l.current,X);Ai(En.paused)},[En]),[Jt,Ln]=w.useState(Date.now()),[Pn,xa]=w.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Rh)!=="0"}catch{return!0}}),ba=w.useRef(!1),tp=w.useCallback(()=>{const T=!Pn;ba.current=!0;try{window.localStorage.removeItem(Rh)}catch{}xa(T),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:T})}).then(A=>A.ok?A.json():null).then(A=>{var X;A!=null&&A.ok&&xa(((X=A.prefs)==null?void 0:X.autoUpdate)!==!1)}).catch(()=>{})},[Pn]),[Nr,ka]=w.useState(!1),[yo,Mi]=w.useState("restart"),[hc,rd]=w.useState(null),Na=w.useRef(!1),sd=w.useRef(null),Ii=w.useRef(0),wo=w.useCallback(async T=>{if(!Ps(Na.current))return;const A=(T==null?void 0:T.upgrade)===!0;Na.current=!0,sd.current=ho;const X=++Ii.current;Mi(A?"npx":"restart"),ka(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(ht==null?void 0:ht.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:A})})}catch{}window.setTimeout(()=>{if(Ii.current===X&&Na.current){Na.current=!1,ka(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},A?18e4:3e4)},[ht==null?void 0:ht.to,ho]),fc=w.useRef(null);w.useEffect(()=>{const T=aj(l.current.agents.values())>0,A=VU({enabled:Pn,kind:ht==null?void 0:ht.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ma,visible:document.visibilityState==="visible",busy:T,idleSince:fc.current,now:Jt});fc.current=A.idleSince,A.restart&&wo()},[Pn,ht==null?void 0:ht.kind,xe==null?void 0:xe.canRestart,ma,Jt,wo]);const ad=aj(l.current.agents.values()),od=WU(ad),id=XM({enabled:Pn,kind:ht==null?void 0:ht.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ma,visible:document.visibilityState==="visible",busy:ad>0,idleSince:fc.current,now:Jt});w.useEffect(()=>{const T=xe==null?void 0:xe.running;let A=null,X=null;try{A=window.sessionStorage.getItem("agent-dag.restartPending"),X=window.sessionStorage.getItem(bR)}catch{return}const te=qU({bundle:"3.29.3",running:T,pending:A,lastTried:X});if(te==="reload"){try{window.sessionStorage.setItem(bR,T??"")}catch{return}window.location.reload();return}if(te!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Na.current=!1,ka(!1),rd(T??null);const ye=window.setTimeout(()=>rd(null),6e3);return()=>window.clearTimeout(ye)},[xe==null?void 0:xe.running]),w.useEffect(()=>{if(Nr&&zU({asked:sd.current,reported:ho})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Na.current=!1,ka(!1)}},[Nr,ho]);const pc=w.useState(()=>xY(TX()))[0],Gt=w.useRef(pc.pinned),$i=w.useRef(null),Oi=w.useState(()=>MX())[0],[mc,gc]=w.useState(()=>new Set),[Sa,ld]=w.useState(tY),[vo,cd]=w.useState(MV),[Li,np]=w.useState($V),[xo,yc]=w.useState(()=>BV(yr(F2))),[Pi,rp]=w.useState(()=>qV(yr(q2))),[Gs,Di]=w.useState(()=>zV(yr(D2),xo,RV)),[Ks,Fi]=w.useState(()=>new Set),[ud,dd]=w.useState(0),[Xr,hd]=w.useState(()=>iR(gR)),wc=w.useMemo(()=>wY(Xr),[Xr]),ja=w.useCallback(T=>yY(T,wc),[wc]),[fd,sp]=w.useState(!1);w.useEffect(()=>{document.documentElement.dataset.theme=Sa;try{window.localStorage.setItem(S$,Sa)}catch{}hd(T=>{const A=iR(gR);return vY(T,A)?T:A})},[Sa]),w.useEffect(()=>{try{window.localStorage.setItem(l$,vo?"1":"0")}catch{}},[vo]),w.useEffect(()=>{try{window.localStorage.setItem(c$,String(Li))}catch{}},[Li]),w.useEffect(()=>{try{window.localStorage.setItem(q2,Pi?"1":"0")}catch{}},[Pi]),w.useEffect(()=>{try{window.localStorage.setItem(F2,JSON.stringify(xo))}catch{}},[xo]),w.useEffect(()=>{try{window.localStorage.setItem(D2,Gs)}catch{}},[Gs]);const ap=w.useCallback(T=>{yc(A=>A.some(X=>X.id===T.id)?A:[...A,T]),Fi(A=>{if(!A.has(T.id))return A;const X=new Set(A);return X.delete(T.id),X})},[]),pd=w.useCallback((T,A)=>{const X=A.trim();!X||X.length>Lu||yc(te=>te.map(ye=>ye.id===T?{...ye,name:X}:ye))},[]),md=w.useCallback(T=>{yc(A=>A.filter(X=>X.id!==T)),Di(A=>UV(A,T)),Fi(A=>{if(!A.has(T))return A;const X=new Set(A);return X.delete(T),X})},[]),bo=w.useCallback(T=>{const A=B2(T),X=Ks.has(A);T===Gs&&!X||(X&&Fi(te=>{const ye=new Set(te);return ye.delete(A),ye}),Di(T),dd(te=>te+1))},[Gs,Ks]),ko=w.useCallback((T,A)=>{const X=B2(T);Fi(te=>{if(te.has(X)===A)return te;const _e=new Set(te);return A?_e.add(X):_e.delete(X),_e})},[]);w.useEffect(()=>{const T=document.querySelector('meta[name="theme-color"]'),A=Xr["--panel"];T&&A&&T.setAttribute("content",A)},[Xr]);const hr=w.useCallback((T,A)=>{if(Ch({durationMs:A,documentHidden:document.hidden})){e.setViewport(T,{duration:A});return}const{d3Zoom:X,d3Selection:te}=r.getState(),ye=te==null?void 0:te.property("__zoom");if(X&&te&&ye&&ye.k>0&&T.zoom>0){X.transform(te,ye.scale(T.zoom/ye.k).translate((T.x-ye.x)/T.zoom,(T.y-ye.y)/T.zoom));return}e.setViewport(T,{duration:0})},[e,r]),Zr=w.useRef(null),No=w.useRef(0),So=w.useRef(null),qi=w.useRef(()=>{});w.useEffect(()=>{if(!Oi)return;const T=window.setTimeout(()=>{try{hr(Oi,0)}catch{}Ys.current=Date.now()},60);return()=>window.clearTimeout(T)},[hr,Oi]);const Bi=w.useRef(!0),[_a,vc]=w.useState(null);w.useEffect(()=>{const T=new EventSource("/events"),A=XK(m,{now:()=>Date.now(),setTimeout:(_e,Oe)=>window.setTimeout(_e,Oe),clearTimeout:_e=>window.clearTimeout(_e)});let X=!1;const te=typeof BroadcastChannel=="function"?aY(new BroadcastChannel(rY),Math.random().toString(36).slice(2),()=>X):null,ye=window.setInterval(()=>{X||!te||te.ask(600).then(_e=>{X||Hr(sY(_e))})},3e3);return T.addEventListener("open",()=>{Zt(!0),sp(!0)}),T.addEventListener("error",()=>{Zt(!1),vc(null)}),T.addEventListener("open",()=>{X=!0,Hr(!1)}),T.addEventListener("error",()=>{X=!1}),T.addEventListener("replay-end",()=>{Bi.current=!1,A.flush(),vc(Date.now())}),T.addEventListener("desktop-update",_e=>{if(hu())try{const Oe=rR(JSON.parse(_e.data));Oe&&(Rt.current++,Wr(Oe),Oe.status!=="ready"&&(cr.current++,window.clearTimeout(br.current),Nt.current=!1,Ns(!1)))}catch{}}),T.addEventListener("hook",_e=>{var Oe;try{const Ve=JSON.parse(_e.data);if(!En.accept(Ve))return;l.current=zN(l.current,Ve);const it=Ve.replay===!0||Bi.current||Date.now()-Ve.receivedAt>3e4;it?A.replay():A.live();const Ze=xV(Ve,it);Ze&&((Oe=Ut.current)==null||Oe.play(Ze))}catch{}}),()=>{T.close(),A.cancel(),window.clearInterval(ye),te==null||te.leave()}},[m]),w.useEffect(()=>{const T=setInterval(()=>{const A=Date.now();Ln(A);const{changed:X,forgotten:te}=R9(l.current,A);te.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:te})}).catch(()=>{}),b(ye=>E9(ye,l.current.agents)),k(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),q(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),O(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),X&&m()},250);return()=>clearInterval(T)},[m]);const zi=w.useRef(null),Ys=w.useRef(0),gd=420,Yn=w.useCallback((T=500)=>{const A=r0,X=1,te=.2,ye=s0;try{const _e=document.querySelector(".canvas-wrap"),Oe=Array.from(document.querySelectorAll(".react-flow__node")).filter(Ct=>Ct.offsetWidth>0);if(!_e||Oe.length===0)return;const Ve=_e.getBoundingClientRect(),it=e.getViewport();if(!Number.isFinite(it.zoom)||it.zoom<=0)return;const Ze=Ct=>(Ct-Ve.left-it.x)/it.zoom,vt=Ct=>(Ct-Ve.top-it.y)/it.zoom,Et=Oe.map(Ct=>Ct.getBoundingClientRect()),kn=Math.min(...Et.map(Ct=>Ze(Ct.left))),Jn=Math.max(...Et.map(Ct=>Ze(Ct.right))),Oa=Math.min(...Et.map(Ct=>vt(Ct.top))),Ed=Math.max(...Et.map(Ct=>vt(Ct.bottom))),Rr=Jn-kn,Ar=Ed-Oa;if(!(Rr>0&&Ar>0))return;const ll=yR(_e),Dc=Ct=>Math.max(te,Math.min(X,(Ve.width-ll-A*2)/(Rr+Ct)*ye,(Ve.height-A*2)/Ar*ye)),Is=OY(Dc(gd),Dc(0)),La={x:A-kn*Is,y:Math.max(A,(Ve.height-Ar*Is)/2)-Oa*Is,zoom:Is},Ho=++No.current;hr(La,T),Ys.current=Date.now(),Zr.current=Ch({durationMs:T,documentHidden:document.hidden})?{target:La,until:Date.now()+T+60}:null,window.setTimeout(()=>{var Ct;try{if(((Ct=Zr.current)==null?void 0:Ct.target)===La&&(Zr.current=null),No.current!==Ho)return;const Pa=e.getViewport();(Math.abs(Pa.zoom-Is)>.01||Math.abs(Pa.x-La.x)>2)&&hr(La,0)}catch{}},T+60)}catch{}},[e,hr]);w.useEffect(()=>{const T=()=>{if(!document.hidden)return;const A=Zr.current;if(Zr.current=null,!(!A||Date.now()>A.until)){try{hr(A.target,0)}catch{}Ys.current=Date.now()}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[hr]);const xc=w.useRef(""),bc=w.useRef(null),Xn=w.useRef(0),_s=w.useCallback(()=>{Xn.current=Date.now()},[]),Ui=w.useRef(null),kc=w.useRef(0),Hi=w.useCallback(()=>{kc.current=Date.now()},[]),Wi=w.useCallback(T=>({hasSourceEvent:!!T,at:Date.now(),lastDeckFitAt:Ys.current,lastCanvasInputAt:kc.current}),[]),Nc="agent-dag.autoFitDisabled",Xs=w.useRef(!1),[Sc,Zs]=w.useState(!1);w.useEffect(()=>{try{window.localStorage.removeItem(Nc)}catch{}},[]);const Qs=w.useCallback(()=>{Xs.current||(Xs.current=!0,Zs(!0))},[]),Ea=w.useCallback(()=>{Xs.current=!1,Zs(!1),Yn(400)},[e,Yn]);w.useEffect(()=>{const T=setInterval(()=>{if(Xs.current||Date.now()-Xn.current<800)return;const A=l.current,X=Date.now(),te=[];for(const _e of A.agents.values())Z0(_e,X)&&te.push({id:_e.id});if(te.length===0)return;const ye=[];for(const{id:_e}of te){const Oe=Sr.current.get(_e),Ve=Gt.current.get(_e)??Kt.current.get(_e);!Oe||!Ve||ye.push({x:Ve.x,y:Ve.y,width:Oe.width,height:Oe.height})}TY({pane:Ui.current,viewport:e.getViewport(),boxes:ye})&&Yn(600)},1500);return()=>clearInterval(T)},[e]);const Ca=w.useRef(!1),Sr=w.useRef(new Map),Ta=w.useRef(0),Ra=w.useCallback(T=>{const A=Sr.current;let X=!1;for(const te of T.nodeInternals.values()){const ye=te.width,_e=te.height;if(ye==null||_e==null)continue;const Oe=A.get(te.id);Oe?(Math.abs(Oe.height-_e)>4||Math.abs(Oe.width-ye)>4)&&(A.set(te.id,{width:ye,height:_e}),X=!0):(A.set(te.id,{width:ye,height:_e}),X=!0)}return X&&(Ta.current+=1),Ta.current},[]),Vi=Tt(Ra),[jc,Gi]=w.useState(0);w.useEffect(()=>{let T=0;const A=()=>{const te=Sr.current;let ye=!1;for(const _e of document.querySelectorAll(".react-flow__node[data-id]")){const Oe=_e.getAttribute("data-id");if(!Oe)continue;const Ve=_e.offsetWidth,it=_e.offsetHeight;if(!Ve||!it)continue;const Ze=te.get(Oe);(!Ze||Math.abs(Ze.width-Ve)>4||Math.abs(Ze.height-it)>4)&&(te.set(Oe,{width:Ve,height:it}),ye=!0)}ye&&Gi(_e=>_e+1)};if(Ca.current)return;let X=0;return document.visibilityState==="hidden"?X=window.setTimeout(A,32):T=requestAnimationFrame(A),()=>{cancelAnimationFrame(T),window.clearTimeout(X)}});const Kt=w.useRef(pc.positions),_c=w.useRef(new Set),jo=w.useRef(""),jr=w.useMemo(()=>LK(l.current.agents.values(),c),[l.current,l.current.revision,c]),Js=w.useMemo(()=>{const T=[];for(const A of l.current.agents.values())!Z0(A,Jt)||jr.has(A.id)||T.push(A.id+(A.parentId?`>${A.parentId}`:""));return T.sort(),`${T.join("|")}#sv${Vi}.${jc}`},[l.current,l.current.revision,Jt,Vi,jc,jr]),Aa=w.useRef(null);w.useEffect(()=>(Aa.current!=null&&window.clearTimeout(Aa.current),Aa.current=window.setTimeout(()=>{Ah(Kt.current,Gt.current)},1500),()=>{Aa.current!=null&&window.clearTimeout(Aa.current)}),[Js]),w.useEffect(()=>{if(xc.current===Js)return;const T=xc.current;if(xc.current=Js,!T||Xs.current)return;Date.now()-Ys.current>1200&&Yn(400),zi.current&&window.clearTimeout(zi.current),zi.current=window.setTimeout(()=>{Xs.current||Yn(500)},280)},[Js,e,Yn]);const _r=w.useMemo(()=>GK(l.current,S),[l.current,l.current.revision,S]),_o=w.useMemo(()=>{const T=pY(l.current,Jt);for(const A of jr)T.delete(A);return T},[l.current,l.current.revision,Jt,jr]),Er=w.useRef(null),[Eo,yd]=w.useState({w:0,h:0});w.useEffect(()=>{const T=Er.current;if(!T||typeof ResizeObserver>"u")return;const A=new ResizeObserver(X=>{var ye;const te=(ye=X[0])==null?void 0:ye.contentRect;te&&(Ui.current={width:te.width,height:te.height},yd(_e=>Math.abs(_e.w-te.width)>40||Math.abs(_e.h-te.height)>40?{w:te.width,h:te.height}:_e))});return A.observe(T),Ui.current={width:T.clientWidth,height:T.clientHeight},yd({w:T.clientWidth,h:T.clientHeight}),()=>A.disconnect()},[]);const Co=w.useCallback(T=>{var X,te;const A=T.target;!(A!=null&&A.closest)||A.closest(wX)!==T.currentTarget||(T.preventDefault(),(te=(X=document.activeElement)==null?void 0:X.blur)==null||te.call(X))},[]),op=w.useRef(new Map),[To,wd]=w.useState(!1);w.useEffect(()=>{const T=window.setTimeout(()=>wd(!0),2500);return()=>window.clearTimeout(T)},[]);const[$t,Ro]=w.useState(!1),fr=w.useRef(null),[Qr,Ec]=w.useState(!1),[Ki,Ma]=w.useState(!1),[Yi,Ia]=w.useState(""),[Ao,vd]=w.useState("far"),xd=w.useRef(null),Cc=gh(Ki,140),Mo=w.useCallback(T=>{var te;const A=(te=xd.current)==null?void 0:te.getBoundingClientRect(),X=WK(T);return A&&X?HK(X,A):"far"},[]),[Xi,Tc]=w.useState("detail"),Jr=w.useRef(null),Io=w.useRef(null),Rc=w.useCallback(()=>{var te;const T=Ta.current;if(((te=Io.current)==null?void 0:te.version)===T)return Io.current.card;const A=[];for(const ye of l.current.agents.keys()){const _e=Sr.current.get(ye);_e&&A.push(_e)}const X=AY(A);return Io.current={version:T,card:X},X},[]),ip=w.useCallback(()=>{fr.current&&(window.clearTimeout(fr.current),fr.current=null),Ro(!1)},[]),bd=w.useCallback(T=>{T.length!==0&&queueMicrotask(()=>{Ro(!0),fr.current&&window.clearTimeout(fr.current),fr.current=window.setTimeout(()=>Ro(!1),vX+80)})},[]);w.useEffect(()=>()=>{fr.current&&window.clearTimeout(fr.current)},[]);const Cn=_?l.current.agents.get(_):null,kd=y&&Cn!=null,[$o,Es]=w.useState(0);w.useEffect(()=>{const T=yR(Er.current);Es(A=>Math.abs(A-T)>40?T:A)},[Be,Pe,W,kd,Eo.w]);const Zi=w.useRef($o);Zi.current=$o;const es=Eo.w>0?Math.max(0,(Eo.w-$o-r0*2)*s0):0,Dn=Eo.h>0?Math.max(0,(Eo.h-r0*2)*s0):0,Oo=fF(),{nodes:mn,edges:Qi}=w.useMemo(()=>{const T=$9(l.current,Jt,es,Dn,Gt.current,Sr.current,op.current,bd,To,Qr,Kt.current,_c.current,Js,jo,S,_r,_o,$);return PK(T.nodes,T.edges,c)},[l.current,l.current.revision,Jt,es,Dn,To,Qr,Js,S,_r,_o,$,ep,Oo,c]),lp=w.useState(RX)[0],Nd=w.useRef(lp);w.useEffect(()=>{if(!To||Qr)return;const T={width:es,height:Dn};if(!(T.width>0&&T.height>0))return;const A=Nd.current;if(Nd.current=T,AX(T),!A||A.width===T.width&&A.height===T.height)return;const X={direction:"LR",pinned:Gt.current,measured:Sr.current,lanes:z0(l.current)};if(!m9(mn,Qi,X,A,T))return;const te=So.current&&Date.now()-So.current.at<1500?So.current.id:null,ye=te??Rs.current,_e=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;for(const Oe of Array.from(Kt.current.keys()))Gt.current.has(Oe)||Kt.current.delete(Oe);_c.current.clear(),jo.current="",m(),window.setTimeout(()=>{if(Ah(Kt.current,Gt.current),Xs.current){if(te){qi.current(te);return}const Oe=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;if(_e&&Oe&&(Oe.x!==_e.x||Oe.y!==_e.y)){const Ve=e.getViewport();No.current+=1,hr({x:Ve.x-(Oe.x-_e.x)*Ve.zoom,y:Ve.y-(Oe.y-_e.y)*Ve.zoom,zoom:Ve.zoom},0),Ys.current=Date.now()}return}Yn(500)},80)},[es,Dn,To,Qr,m,Yn,e,hr]);const Cs=w.useMemo(()=>{const T=new Map;for(const X of mn){const te=X.data;if(!(te!=null&&te.sessionId)||te.exitAt!=null)continue;const ye=X.width,_e=X.height;if(ye==null||_e==null)continue;const Oe=X.position.x,Ve=X.position.y,it=Oe+ye,Ze=Ve+_e,vt=T.get(te.sessionId);vt?(vt.minX=Math.min(vt.minX,Oe),vt.minY=Math.min(vt.minY,Ve),vt.maxX=Math.max(vt.maxX,it),vt.maxY=Math.max(vt.maxY,Ze)):T.set(te.sessionId,{minX:Oe,minY:Ve,maxX:it,maxY:Ze})}const A=[];for(const[X,te]of T){const ye=te.maxX-te.minX+Th*2,_e=te.maxY-te.minY+Th*2;A.push({id:`group:${X}`,type:j$,position:{x:te.minX-Th,y:te.minY-Th},data:{sessionId:X,w:ye,h:_e},width:ye,height:_e,style:{width:ye,height:_e},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return A},[mn]),Lo=w.useMemo(()=>{const T=[...Cs,...mn],A=wa.current;return!A||A.size===0?T:T.map(X=>{const te=A.get(X.id);return te?{...X,position:te}:X})},[Cs,mn,js]),ts=w.useMemo(()=>{const T=new Set;for(const A of l.current.agents.values())for(const X of A.tools)T.add(z$(X.name));return Object.keys(B$).filter(A=>T.has(A))},[l.current,l.current.revision]);w.useEffect(()=>{if(ts.length<=1){Ti(!1);return}let T=0;const A=()=>{const X=Ei.current;if(X&&!document.hidden){const te=X.getBoundingClientRect(),ye=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Oe=>Oe.getBoundingClientRect()),_e=gY(te,ye,8);Ti(Oe=>Oe===_e?Oe:_e)}T=window.setTimeout(A,300)};return A(),()=>window.clearTimeout(T)},[ts.length]);const Ji=w.useCallback(T=>{gc(A=>{const X=new Set(A);return X.has(T)?X.delete(T):X.add(T),X})},[]),Po=j?K5(l.current.agents,j):null,ea=w.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}l.current=S0(),Gt.current.clear(),Sr.current.clear(),Kt.current.clear(),jo.current="",kR(),u(new Set),p(null);try{window.localStorage.removeItem(uk)}catch{}R(),m()},[m,R]),Cr=w.useCallback(T=>{const A=l.current.agents.get(T);A&&(u(X=>{const te=new Set(X);return te.add(T),sR(window.localStorage,te),te}),p({id:T,label:A.label}),Gt.current.delete(T),Kt.current.delete(T),R())},[R]),At=w.useCallback(()=>{_&&Cr(_)},[_,Cr]),Mt=f&&c.has(f.id)?f:null;w.useEffect(()=>{var T;f&&((T=Er.current)==null||T.focus())},[f]);const Zn=w.useCallback(T=>{const A=[...T];u(X=>{const te=DK(X,A);return te!==X&&sR(window.localStorage,te),te})},[]),an=w.useRef(V);an.current=V;const bn=w.useRef(ee);bn.current=ee;const ns=w.useRef(!1);ns.current=Po!=null||Kr||H!=null||Z||I!=null||ga||ee||ur!=null;const rs=w.useCallback(T=>{const A=F9(T,{confirmOpen:an.current,modalOpen:ns.current});A==="confirm"?ne(!0):A==="clear"&&(ne(!1),ea())},[ea]),gn=w.useCallback(()=>{Gt.current.clear(),Kt.current.clear(),jo.current="",kR(),m(),window.setTimeout(()=>Yn(500),80)},[m,e,Yn]),Do=w.useCallback(()=>Yn(500),[Yn]),Ts=w.useRef(mn);Ts.current=mn;const Fn=w.useCallback(T=>{var vt;const A=Er.current,X=l.current.agents.get(T);if(!A||!X)return;const te=z0(l.current),ye=(Et,kn)=>{const Jn=Sr.current.get(Et.id);if(!Jn)return null;const Oa=kn&&te.has(Et.id)?gd:0;return{x:Et.position.x,y:Et.position.y,width:Jn.width+Oa,height:Jn.height}},_e=Ts.current.find(Et=>Et.id===T),Oe=_e?ye(_e,!1):null;if(!Oe)return;const Ve=[];for(const Et of Ts.current){if(Et.type!=="agent"&&Et.type!=="recapNote"||((vt=Et.data)==null?void 0:vt.sessionId)!==X.sessionId)continue;const kn=ye(Et,Et.type==="agent");kn&&Ve.push(kn)}const it=A.getBoundingClientRect(),Ze=DY({pane:{width:it.width,height:it.height},insets:{top:56,left:72,bottom:32,right:Zi.current+32},context:FY(Ve)??Oe,anchor:Oe});Ka(),Qs(),So.current={id:T,at:Date.now()},No.current+=1,hr(Ze,a0),Ys.current=Date.now(),Zr.current=Ch({durationMs:a0,documentHidden:document.hidden})?{target:Ze,until:Date.now()+a0+60}:null},[hr,Qs]);qi.current=Fn;const el=w.useCallback(T=>{const A=Ts.current.find(X=>X.id===T&&X.type==="agent");return A?A.data:void 0},[]),Sd=w.useCallback(T=>{var A;return(A=l.current.agents.get(T))==null?void 0:A.label},[]),ss=w.useCallback(T=>{var te;const A=Ts.current.find(ye=>ye.id===T&&ye.type==="recapNote");if(!A)return;const X=A.data;return{recap:X.recap,hue:X.hue,sessionLabel:(te=l.current.agents.get(X.parentId))==null?void 0:te.label}},[]),tl=w.useCallback(()=>{var X;const T=(X=Er.current)==null?void 0:X.getBoundingClientRect(),A=document.documentElement;return T?{width:T.right-Zi.current,height:T.bottom}:{width:A.clientWidth,height:A.clientHeight}},[]),Rs=w.useRef(_);Rs.current=_;const Ac=w.useRef(At);Ac.current=At;const nl=w.useCallback(T=>{const A=Ts.current.filter(_e=>_e.type==="agent"),X=RK(A.map(_e=>({id:_e.id,x:_e.position.x,y:_e.position.y})),Rs.current,T),te=X?A.find(_e=>_e.id===X):void 0;if(!te)return;const ye=n0(document.activeElement);C(te.id,!1),window.setTimeout(()=>{try{Fn(te.id)}catch{}ye&&yX(te.id)},30)},[C,Fn]),Tr=w.useRef(null),Qn=w.useCallback(T=>{C(T,!1),window.setTimeout(()=>{try{Fn(T)}catch{}},60)},[C,Fn]),$a=w.useCallback(T=>{jr.has(T)&&Zn([T]),Qn(T)},[jr,Zn,Qn]),Fo=w.useRef(null);w.useEffect(()=>{let T=-1/0;const A=()=>{T=performance.now()},X=te=>{Fo.current=performance.now()-T<250?te.target:null};return window.addEventListener("pointerdown",A,!0),window.addEventListener("focusin",X,!0),()=>{window.removeEventListener("pointerdown",A,!0),window.removeEventListener("focusin",X,!0)}},[]),w.useEffect(()=>{const T=A=>{var Ve,it;const X=A.target,te={tagName:X==null?void 0:X.tagName,isContentEditable:X==null?void 0:X.isContentEditable,role:(Ve=X==null?void 0:X.getAttribute)==null?void 0:Ve.call(X,"role"),type:X==null?void 0:X.type,pointerFocused:X!=null&&X===Fo.current};if(A.key==="Escape"){const Ze=P6({overlayOpen:pu.depth()>0,typing:Sf(te)});Ze==="dismiss"?pu.dismissTop():Ze==="blur"?X==null||X.blur():($K(te)&&(X==null||X.blur()),R());return}if(Nf(A))return;const ye=n0(X)?(it=X==null?void 0:X.getAttribute)==null?void 0:it.call(X,"data-id"):null,_e=ye&&Ts.current.some(Ze=>Ze.id===ye)?ye:null,Oe=MK(A,_e);if(Oe.kind==="activate"){A.preventDefault(),C(Oe.nodeId,Oe.additive);return}if(Oe.kind!=="node"&&!(Oe.nodeId==null&&V6(te,A.key))&&!G6({key:A.key,modalOpen:K6({appModal:ns.current,dialogDepth:pu.dialogDepth()}),sheetOpen:bn.current})){if(A.key===" "&&(A.preventDefault(),va()),(A.key==="c"||A.key==="C")&&rs("shortcut"),(A.key==="r"||A.key==="R")&&gn(),(A.key==="f"||A.key==="F")&&Do(),(A.key==="z"||A.key==="Z")&&Rs.current&&Fn(Rs.current),A.key==="Delete"&&Ac.current(),(A.key==="l"||A.key==="L")&&fo(),A.key==="d"||A.key==="D")if(Rs.current)v(Ze=>!Ze);else{const Ze=vm(l.current.agents.values());Ze.length>0?Qn(Ze[0].id):nl(1)}if((A.key==="h"||A.key==="H")&&kr(Ze=>!Ze),(A.key==="u"||A.key==="U")&&F(Ze=>!Ze),(A.key==="a"||A.key==="A")&&Si.current.claude&&Gr(),(A.key==="j"||A.key==="J")&&nl(1),(A.key==="k"||A.key==="K")&&nl(-1),A.key==="w"||A.key==="W"){const Ze=_6(vm(l.current.agents.values()),Tr.current);Ze&&(Tr.current=Ze.id,Qn(Ze.id))}(A.key==="t"||A.key==="T")&&ld(Ze=>Ze==="dark"?"light":"dark"),(A.key==="m"||A.key==="M")&&Si.current.claude&&be.current!==null&&se.current(A.shiftKey),(A.key==="s"||A.key==="S")&&le(Ze=>!Ze),(A.key==="b"||A.key==="B")&&Ws(Ze=>!Ze),(A.key==="v"||A.key==="V")&&Si.current.claude&&be.current!==null&&rn(Ze=>!Ze),A.key==="?"&&M(Ze=>!Ze)}};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[rs,gn,Do,R,C,nl,Qn,Fn,va]);const qo=l.current.agents.size,_t=w.useMemo(()=>vm(l.current.agents.values()),[l.current,l.current.revision]);w.useEffect(()=>{const T=FK(_t,jr);T.length>0&&Zn(T)},[_t,jr,Zn]);const qn=w.useMemo(()=>E6(l.current.agents.values()),[l.current,l.current.revision]),As=w.useRef(null);w.useEffect(()=>{const T=oY({waiting:_t.length,running:qn,connected:Lt}),A=As.current;if(As.current=T,(A==null?void 0:A.title)!==T.title&&(document.title=T.title),(A==null?void 0:A.icon)!==T.icon){const X=document.querySelector('link[rel="icon"]');X&&(X.href=iY[T.icon])}},[_t.length,qn,Lt]);const[as,os]=w.useState(""),Ms=cY(_t);w.useEffect(()=>{os(T=>aR(T,Ms))},[Ms]);const[jd,rl]=w.useState(""),sl=dr>0?`Browser watch has ${dr} unread ${dr===1?"finding":"findings"}.`:"";w.useEffect(()=>{rl(T=>aR(T,sl,"Browser watch has no unread findings."))},[sl]);const[yn,Bn]=w.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[St,zn]=w.useState(null),[Bo,al]=w.useState(!1),[Mc,ol]=w.useState(!1);w.useEffect(()=>{let T=!0;return fetch("/api/prefs").then(A=>A.ok?A.json():null).then(A=>{var X,te,ye;if(!(!T||!(A!=null&&A.ok))){if(!ba.current){let _e=!1;try{_e=window.localStorage.getItem(Rh)==="0",window.localStorage.removeItem(Rh)}catch{}_e&&((X=A.prefs)==null?void 0:X.autoUpdate)!==!1?(xa(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):xa(((te=A.prefs)==null?void 0:te.autoUpdate)!==!1)}al(((ye=A.prefs)==null?void 0:ye.notifications)===!0),ol(A.notificationsVetoed===!0)}}).catch(()=>{}),()=>{T=!1}},[]);const Ic=w.useRef(()=>{}),il=w.useCallback(()=>{const T=!Bo;al(T),T&&typeof Notification<"u"&&Notification.permission==="default"&&Ic.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:T})}).then(A=>A.ok?A.json():null).then(A=>{var X;A!=null&&A.ok&&(al(((X=A.prefs)==null?void 0:X.notifications)===!0),ol(A.notificationsVetoed===!0))}).catch(()=>{})},[Bo]),_d=typeof Notification<"u";w.useEffect(()=>{if(!St)return;const A=setTimeout(()=>zn(null),St==="blocked"?8e3:4e3);return()=>clearTimeout(A)},[St]);const ta=w.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(T=>{const A=T;Bn(A),A==="granted"?zn("on"):A==="denied"&&zn("blocked")})},[]);Ic.current=ta;const na=w.useRef(new Set),$c=w.useRef(null),zo=_t.map(T=>kf(T.id,T.waiting)).join("|");w.useEffect(()=>{A6($c.current,yn)&&($c.current=yn,na.current=xm(_t))},[yn]);const Uo=w.useRef(!1);return w.useEffect(()=>{M6(Uo.current,_a)&&(Uo.current=!0,na.current=xm(_t))},[_a]),w.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!I6($c.current,_a))return;const T=typeof document>"u"||!document.hidden,A=T6(_t,na.current,T,Bo);for(const X of A)try{const te=new Notification(X.title,{body:X.body,tag:X.key});te.onclick=()=>{window.focus(),Qn(X.sessionId),te.close()}}catch{}na.current=T?xm(_t):R6(_t,A,na.current)},[zo,_a]),o.jsxs("div",{className:"app",children:[o.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),o.jsxs("header",{className:"topbar",children:[o.jsxs("div",{className:"readout",children:[o.jsxs("div",{className:"brand",children:[o.jsx("span",{className:"logo"}),o.jsx("h1",{children:dn}),Qt?(()=>{const T=jK(NK()??io,Qt.version);return o.jsxs("button",{type:"button",className:"v ready",onClick:pa,"aria-haspopup":"dialog","aria-label":T.label,title:T.title,children:[T.text,o.jsx("span",{className:"v-dot","aria-hidden":!0})]})})():ht?o.jsxs("button",{type:"button",className:"v stale",onClick:()=>{pa(),oc()},"aria-haspopup":"dialog","aria-label":QY({...ht,open:ma}),title:ht.kind==="restart"?`Running v${ht.from}; v${ht.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${ht.from}; v${ht.to} is on npm · click for what's new`,children:["v",ht.from,o.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const T={running:io,latest:xe==null?void 0:xe.latest,latestPending:xe==null?void 0:xe.latestPending,checkedAgo:xe!=null&&xe.checkedAt?Ph(Jt-xe.checkedAt):null,checkFailedAgo:xe!=null&&xe.checkFailedAt&&xe.checkFailedAt>(xe.checkedAt??0)?Ph(Jt-xe.checkFailedAt):null,checkDisabled:xe==null?void 0:xe.checkDisabled,checking:tt};return o.jsxs("button",{type:"button",className:tt?"v checking":"v",onClick:()=>{pa(),gt(!0)},"aria-busy":tt||void 0,"aria-haspopup":"dialog","aria-label":ZY(T),title:XY(T),children:["v",T.running]})})()]}),o.jsxs("span",{className:"status",children:[(()=>{const T=hX({connected:Lt,paused:go,held:En.size,dropped:En.dropped});return T.resting?null:o.jsx("span",{className:`pill ${T.tone}`,title:T.title,children:o.jsxs("span",{className:"pill-box",children:[o.jsx("span",{className:"pill-widest","aria-hidden":!0,children:T.widest}),o.jsx("span",{className:"pill-label",children:T.label})]})})})(),o.jsxs("span",{ref:z,className:"month-usage",title:G?`${G.tokens.toLocaleString()} tokens · ${fR(G.cost)} spent since the 1st of this local calendar month`:U?"Monthly usage is unavailable — ccusage could not be read":"Loading usage since the 1st of this local calendar month",children:[o.jsx("span",{className:"month-usage-label",children:"this month"}),G?o.jsxs(o.Fragment,{children:[o.jsx("b",{children:Bt(G.tokens)}),o.jsx("span",{className:"month-usage-unit",children:"tokens"}),o.jsx("span",{className:"month-usage-sep","aria-hidden":!0,children:"·"}),o.jsx("b",{children:fR(G.cost)})]}):o.jsx("span",{className:"month-usage-pending",children:U?"unavailable":"…"})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:as}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:jd}),_t.length>0&&o.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{Tr.current=_t[0].id,Qn(_t[0].id)},title:`Blocked waiting for you — click, or press W, to go to the one that has been stuck longest:
|
|
291
291
|
${_t.map(T=>` ${T.label}: ${Vl(T.waiting)} (${Ph(Jt-T.waiting.since)})`).join(`
|
|
292
292
|
`)}`,"aria-label":`${_t.length} session${_t.length===1?"":"s"} waiting for you`,children:[o.jsx("span",{className:"ap-pulse","aria-hidden":!0}),o.jsx("b",{children:_t.length})," ",o.jsx("span",{className:"ws-word",children:"waiting"})]}),St&&o.jsx("span",{className:St==="on"?"notify-said":"notify-said notify-said-blocked",role:"status",title:St==="on"?"The deck will raise a system notification when a session blocks on you and this tab is in the background":"Notifications are blocked for this page. Only your browser can undo that — its site settings for this address",children:St==="on"?"notifications on":"notifications blocked"})]}),Cn&&(()=>{const T=ir(Cn),A=Math.max(0,((Cn.endedAt??Jt)-Cn.startedAt)/1e3),X=Cn.state==="active"?Nb(T.total,A):null,te=S.size-1;return o.jsxs("button",{type:"button",className:"selected-ribbon",title:`Zoom to ${Cn.label} and its session (Z)${T.total>0?`
|
|
293
|
-
${ut(T.total)} spent${X?` · ${X}`:""}`:""}`,onClick:()=>{try{Fn(Cn.id)}catch{}},children:[o.jsx("span",{className:`state-pill state-${Cn.state}`,children:Cn.state==="active"?"live":Cn.state}),o.jsx("span",{className:"selected-label",children:Cn.label}),T.total>0&&o.jsxs("span",{className:"selected-cost",children:[ut(T.total),X?o.jsxs("span",{className:"selected-rate",children:[" · ",X]}):null]}),te>0&&o.jsxs("span",{className:"selected-extra",children:["+",te]}),o.jsx("span",{"aria-hidden":!0,className:"selected-close",onClick:ye=>{ye.stopPropagation(),R()},children:"×"})]})})(),o.jsxs("div",{className:"actions",children:[o.jsxs("div",{className:"action-run",children:[o.jsxs("button",{className:"btn icon-btn",onClick:fo,title:`${P?"Hide":"Show"} session list (L)`,"aria-label":"Toggle session list","aria-expanded":P,"aria-controls":P?"session-list":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M5.4 3.6h6.6M5.4 7h6.6M5.4 10.4h6.6"}),o.jsx("path",{d:"M2.2 3.6h.2M2.2 7h.2M2.2 10.4h.2"})]}),o.jsx("span",{className:"tb-word",children:"Session list"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>F(T=>!T),title:`${W?"Hide":"Show"} usage panel (U)`,"aria-label":"Toggle usage panel","aria-expanded":W,"aria-controls":W?"usage-panel":void 0,children:[o.jsxs("svg",{className:"tb-glyph-narrow",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M9.4 4.5C9 3.6 8.1 3.1 7 3.1c-1.4 0-2.4.8-2.4 1.9 0 1.2 1.2 1.6 2.4 2s2.4.8 2.4 2c0 1.1-1 1.9-2.4 1.9-1.1 0-2-.5-2.4-1.4"}),o.jsx("path",{d:"M7 1.6v1.5M7 10.9v1.5"})]}),o.jsx("span",{className:"tb-word",children:"Usage"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>kr(T=>!T),title:"Usage history — ccusage (H)","aria-label":"Open usage history","aria-haspopup":"dialog",children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("line",{x1:"3",y1:"11.5",x2:"3",y2:"7"}),o.jsx("line",{x1:"7",y1:"11.5",x2:"7",y2:"3"}),o.jsx("line",{x1:"11",y1:"11.5",x2:"11",y2:"8.5"})]}),o.jsx("span",{className:"tb-word",children:"History"})]})]}),o.jsxs("div",{className:"action-run",children:[Kn.claude&&o.jsxs("button",{className:"btn icon-btn",onClick:Gr,title:`${Ne?"Hide":"Show"} accounts (A)`,"aria-label":"Toggle accounts panel","aria-expanded":Ne,"aria-controls":Ne?"accounts-panel":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"4.6",r:"2.4"}),o.jsx("path",{d:"M2.4 12c0-2.3 2.1-3.7 4.6-3.7s4.6 1.4 4.6 3.7"})]}),o.jsx("span",{className:"tb-word",children:"Accounts"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>le(T=>!T),title:`${ie?"Hide":"Show"} this machine — cores, memory, temperature (S)`,"aria-label":"Toggle machine detail","aria-expanded":ie,"aria-controls":ie?"system-panel":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"3.6",y:"3.6",width:"6.8",height:"6.8",rx:"1.2"}),o.jsx("path",{d:"M5.8 1.4v2.2M8.2 1.4v2.2M5.8 10.4v2.2M8.2 10.4v2.2M1.4 5.8h2.2M1.4 8.2h2.2M10.4 5.8h2.2M10.4 8.2h2.2"})]}),o.jsx("span",{className:"tb-word",children:"Machine"})]}),o.jsxs("button",{className:"btn icon-btn bw-btn",onClick:()=>Ws(T=>!T),title:uc?"Browser watch — watching; the deck is keeping its own copy (B)":"Browser watch — not watching; reading the browser's history live (B)","aria-label":`Browser watch, ${uc?"watching":"not watching"}`+(dr>0?`, ${dr} unread`:""),"aria-haspopup":"dialog",children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M0.9 7s2.2-4 6.1-4 6.1 4 6.1 4-2.2 4-6.1 4S0.9 7 0.9 7Z"}),uc||dr>0?o.jsx("circle",{cx:"7",cy:"7",r:"1.8",fill:"currentColor",stroke:"none"}):o.jsx("line",{x1:"2.4",y1:"11.6",x2:"11.6",y2:"2.4"})]}),o.jsx("span",{className:"tb-word",children:"Browser watch"}),dr>0&&o.jsx("span",{className:"bw-badge","aria-hidden":!0,children:dr})]})]}),o.jsxs("div",{className:"action-run action-run-utility",children:[Kn.claude&&Te!==null&&o.jsxs("div",{className:"sound-slot",children:[o.jsxs("button",{ref:je,className:"btn icon-btn",onClick:()=>rn(T=>!T),...Qa(!1),title:
|
|
293
|
+
${ut(T.total)} spent${X?` · ${X}`:""}`:""}`,onClick:()=>{try{Fn(Cn.id)}catch{}},children:[o.jsx("span",{className:`state-pill state-${Cn.state}`,children:Cn.state==="active"?"live":Cn.state}),o.jsx("span",{className:"selected-label",children:Cn.label}),T.total>0&&o.jsxs("span",{className:"selected-cost",children:[ut(T.total),X?o.jsxs("span",{className:"selected-rate",children:[" · ",X]}):null]}),te>0&&o.jsxs("span",{className:"selected-extra",children:["+",te]}),o.jsx("span",{"aria-hidden":!0,className:"selected-close",onClick:ye=>{ye.stopPropagation(),R()},children:"×"})]})})(),o.jsxs("div",{className:"actions",children:[o.jsxs("div",{className:"action-run",children:[o.jsxs("button",{className:"btn icon-btn",onClick:fo,title:`${P?"Hide":"Show"} session list (L)`,"aria-label":"Toggle session list","aria-expanded":P,"aria-controls":P?"session-list":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M5.4 3.6h6.6M5.4 7h6.6M5.4 10.4h6.6"}),o.jsx("path",{d:"M2.2 3.6h.2M2.2 7h.2M2.2 10.4h.2"})]}),o.jsx("span",{className:"tb-word",children:"Session list"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>F(T=>!T),title:`${W?"Hide":"Show"} usage panel (U)`,"aria-label":"Toggle usage panel","aria-expanded":W,"aria-controls":W?"usage-panel":void 0,children:[o.jsxs("svg",{className:"tb-glyph-narrow",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M9.4 4.5C9 3.6 8.1 3.1 7 3.1c-1.4 0-2.4.8-2.4 1.9 0 1.2 1.2 1.6 2.4 2s2.4.8 2.4 2c0 1.1-1 1.9-2.4 1.9-1.1 0-2-.5-2.4-1.4"}),o.jsx("path",{d:"M7 1.6v1.5M7 10.9v1.5"})]}),o.jsx("span",{className:"tb-word",children:"Usage"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>kr(T=>!T),title:"Usage history — ccusage (H)","aria-label":"Open usage history","aria-haspopup":"dialog",children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("line",{x1:"3",y1:"11.5",x2:"3",y2:"7"}),o.jsx("line",{x1:"7",y1:"11.5",x2:"7",y2:"3"}),o.jsx("line",{x1:"11",y1:"11.5",x2:"11",y2:"8.5"})]}),o.jsx("span",{className:"tb-word",children:"History"})]})]}),o.jsxs("div",{className:"action-run",children:[Kn.claude&&o.jsxs("button",{className:"btn icon-btn",onClick:Gr,title:`${Ne?"Hide":"Show"} accounts (A)`,"aria-label":"Toggle accounts panel","aria-expanded":Ne,"aria-controls":Ne?"accounts-panel":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"4.6",r:"2.4"}),o.jsx("path",{d:"M2.4 12c0-2.3 2.1-3.7 4.6-3.7s4.6 1.4 4.6 3.7"})]}),o.jsx("span",{className:"tb-word",children:"Accounts"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>le(T=>!T),title:`${ie?"Hide":"Show"} this machine — cores, memory, temperature (S)`,"aria-label":"Toggle machine detail","aria-expanded":ie,"aria-controls":ie?"system-panel":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"3.6",y:"3.6",width:"6.8",height:"6.8",rx:"1.2"}),o.jsx("path",{d:"M5.8 1.4v2.2M8.2 1.4v2.2M5.8 10.4v2.2M8.2 10.4v2.2M1.4 5.8h2.2M1.4 8.2h2.2M10.4 5.8h2.2M10.4 8.2h2.2"})]}),o.jsx("span",{className:"tb-word",children:"Machine"})]}),o.jsxs("button",{className:"btn icon-btn bw-btn",onClick:()=>Ws(T=>!T),title:uc?"Browser watch — watching; the deck is keeping its own copy (B)":"Browser watch — not watching; reading the browser's history live (B)","aria-label":`Browser watch, ${uc?"watching":"not watching"}`+(dr>0?`, ${dr} unread`:""),"aria-haspopup":"dialog",children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M0.9 7s2.2-4 6.1-4 6.1 4 6.1 4-2.2 4-6.1 4S0.9 7 0.9 7Z"}),uc||dr>0?o.jsx("circle",{cx:"7",cy:"7",r:"1.8",fill:"currentColor",stroke:"none"}):o.jsx("line",{x1:"2.4",y1:"11.6",x2:"11.6",y2:"2.4"})]}),o.jsx("span",{className:"tb-word",children:"Browser watch"}),dr>0&&o.jsx("span",{className:"bw-badge","aria-hidden":!0,children:dr})]})]}),o.jsxs("div",{className:"action-run action-run-utility",children:[Kn.claude&&Te!==null&&o.jsxs("div",{className:"sound-slot",children:[o.jsxs("button",{ref:je,className:"btn icon-btn",onClick:()=>rn(T=>!T),...Qa(!1),title:oX(Kn,{on:Te===!0,locked:Vn==="locked",prefs:Le}),"aria-label":`Sound settings, ${Te?"on":"off"}`,"aria-haspopup":"dialog","aria-expanded":Dt,"aria-controls":Dt?"sound-menu":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M3.2 5.2h2L7.8 3v8L5.2 8.8h-2z"}),Te?o.jsxs(o.Fragment,{children:[o.jsx("path",{d:"M9.8 5.4a2.4 2.4 0 0 1 0 3.2"}),o.jsx("path",{d:"M11.3 3.9a4.6 4.6 0 0 1 0 6.2"})]}):o.jsxs(o.Fragment,{children:[o.jsx("path",{d:"M10 5.6l2.6 2.8"}),o.jsx("path",{d:"M12.6 5.6L10 8.4"})]})]}),o.jsx("span",{className:"tb-word",children:"Sound"})]}),Dt&&o.jsx(CV,{onClose:()=>rn(!1),soundOn:Te===!0,onToggleSound:de,prefs:Le,onLevel:(T,A)=>rt(T,{level:A}),onFigure:(T,A)=>rt(T,{figure:A}),onPreview:T=>We(T),customAssets:Ye,customSelections:Ae,onBuiltInSelected:ke,onCustomSelected:dt,onImportCustom:ct,onCreateVoice:yt,onRenameCustom:Ot,onPreviewCustom:Xt,onDeleteCustom:zt,notifyOn:Bo,onToggleNotify:il,notifyVetoed:Mc,notifyPermission:_d?yn:"unsupported",onAskNotify:ta,openerRef:je})]}),o.jsxs("div",{className:"appearance-slot",children:[o.jsx("button",{ref:_n,className:"btn icon-btn",onClick:()=>{rn(!1),bt(T=>!T)},title:"Appearance settings","aria-label":`Appearance settings, ${Sa} theme, character ${vo?"shown":"hidden"}`,"aria-haspopup":"dialog","aria-expanded":xt,"aria-controls":xt?"appearance-menu":void 0,children:Sa==="dark"?o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"7",r:"2.5"}),o.jsx("path",{d:"M7 1.5v1.2M7 11.3v1.2M1.5 7h1.2M11.3 7h1.2M3.1 3.1l.85.85M10.05 10.05l.85.85M3.1 10.9l.85-.85M10.05 3.95l.85-.85"})]}):o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M11.8 8.4A5 5 0 1 1 5.6 2.2a4 4 0 0 0 6.2 6.2Z"})})}),xt&&o.jsx(YV,{theme:Sa,onTheme:ld,characterEnabled:vo,onToggleCharacter:()=>cd(T=>!T),fmVolume:Li,onFmVolume:np,fmMuted:Pi,onFmMuted:()=>rp(T=>!T),fmSource:Gs,onFmSource:bo,customFmStations:xo,unavailableFmStations:Ks,onAddFmStation:ap,onRenameFmStation:pd,onRemoveFmStation:md,onClose:()=>bt(!1)})]})]})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Mt?`${Mt.label} removed from the board.`:""}),hc?o.jsxs("div",{className:"ver-banner done",role:"status",children:[o.jsx("span",{className:"ver-dot"}),o.jsxs("strong",{children:["Restarted — now running v",hc,"."]}),o.jsx("span",{className:"ver-sub",children:"The canvas replayed from the event log."})]}):fd&&!Lt?o.jsxs("div",{className:"conn-banner",role:"alert",children:[o.jsx("span",{className:"conn-dot"}),Nr?yo==="npx"?"Fetching the new version with npx — this can take a minute…":`Restarting ${dn}…`:(()=>{const T=uX({connected:Lt,paused:go});return o.jsxs(o.Fragment,{children:[`Lost connection to the ${dn} server. Reconnecting…`,T&&o.jsx("span",{className:"conn-sub",children:T})]})})()]}):ma&&ht?o.jsxs("div",{className:`ver-banner ${ht.kind}`,role:"status",children:[o.jsx("span",{className:`ver-dot${id==null?"":" armed"}`}),ht.kind==="restart"?o.jsxs(o.Fragment,{children:[o.jsxs("strong",{children:["v",ht.to," is installed — this deck still runs v",ht.from,"."]}),xe!=null&&xe.canRestart?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"ver-act",onClick:()=>wo(),...Qa(Nr),title:`Stop this process and bring it back on the same port. The canvas replays from the event log.
|
|
294
294
|
|
|
295
|
-
Node loads every module once, at startup. An upgrade replaces the files on disk but not the code already in memory, so this process keeps running the old version until it is restarted.`,children:Nr?"restarting…":od.label}),!Nr&&o.jsx("span",{className:"ver-sub",children:od.clause}),o.jsxs("label",{className:"ver-auto",children:[o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":Pn,onClick:tp,"aria-label":"Auto-restart when idle",title:Pn?"Updates on its own. While you are here it restarts once nothing has been running for 30 seconds; while you are away it also installs the new version first. Click to require a click instead.":"Only updates when you click. Click to let it update itself when idle or while you are away.",children:o.jsx("span",{className:"switch-knob"})}),o.jsx("span",{"aria-hidden":!0,children:UU(Pn,id)})]})]}):o.jsx("span",{className:"ver-sub",title:"Node loads every module once, at startup. An upgrade replaces the files on disk but not the code already in memory, so this process keeps running the old version until it is restarted.",children:"Restart it to pick up the new code."})]}):o.jsxs(o.Fragment,{children:[o.jsxs("strong",{children:[dn," v",ht.to," is out — you are on v",ht.from,"."]}),(xe==null?void 0:xe.upgradeMode)==="install"&&On!=="failed"&&o.jsx("button",{type:"button",className:"ver-act",onClick:ed,...Qa(On==="running",On==="done"),title:`Runs ${((Lc=xe==null?void 0:xe.upgrade)==null?void 0:Lc.command)??(xe==null?void 0:xe.command)??"npm i -g"} here, then restarts once nothing is running.`,children:On==="running"?"installing…":On==="done"?"installed":"Update now"}),(xe==null?void 0:xe.upgradeMode)==="npx"&&(xe==null?void 0:xe.canRestart)&&o.jsx("button",{type:"button",className:"ver-act",onClick:()=>wo({upgrade:!0}),...Qa(Nr),title:`Runs ${xe==null?void 0:xe.command} and hands it this port. Nothing is installed globally — npx unpacks its own copy.`,children:Nr?"fetching…":On==="failed"?"Retry update":"Update & restart"}),On==="failed"?o.jsxs("span",{className:"ver-sub fail",title:((ra=xe==null?void 0:xe.upgrade)==null?void 0:ra.error)??"",children:[(xe==null?void 0:xe.upgradeMode)==="npx"?"update failed":"install failed",": ",((Pc=xe==null?void 0:xe.upgrade)==null?void 0:Pc.error)??"unknown error"," — run it yourself:"]}):(xe==null?void 0:xe.upgradeMode)==="npx"?o.jsx("span",{className:"ver-sub",children:xe!=null&&xe.canRestart?"npx cannot upgrade in place, so the deck re-runs:":i0.npx}):xe!=null&&xe.upgradeBlocked?o.jsx("span",{className:"ver-sub",children:Object.hasOwn(i0,xe.upgradeBlocked)?i0[xe.upgradeBlocked]:"cannot install from here"}):null,o.jsxs("button",{type:"button",className:"ver-cmd",onClick:lc,title:"Copy to clipboard",children:[o.jsx("code",{children:xe==null?void 0:xe.command}),o.jsx("span",{className:"ver-cmd-hint",children:De?"copied":"copy"})]})]}),o.jsx("button",{type:"button","aria-label":"Dismiss",className:"ver-close",onClick:uo,children:"×"})]}):Qu&&ft?o.jsxs("div",{className:"ver-banner",role:"status",children:[o.jsx("span",{className:"ver-dot"}),o.jsxs("strong",{children:[ft," still works — the deck is called ",dn," now."]}),xe!=null&&xe.renameFix?o.jsx("span",{className:"ver-sub",children:xe.renameFix}):null,o.jsx("button",{type:"button","aria-label":"Dismiss",className:"ver-close",onClick:Ju,children:"×"})]}):null,mh(Ge)&&Kn.claude&&o.jsx(LU,{leaving:Ge==="leaving",onClose:()=>Ie(!1)}),P&&o.jsx(Wq,{state:l.current,now:Jt,selectedIds:S,onSelect:$a,onClose:()=>B(!1),removedIds:jr,onBringBackAll:()=>{Zn([...c]),p(null)}}),o.jsxs("main",{id:"canvas",tabIndex:-1,className:`canvas-wrap${$t?" bubbling":""}${Qr?" dragging-any":""}${Ki&&Ao==="over"?" trash-hover":""}`,"data-lod":Xi,ref:Er,onMouseDownCapture:Co,onPointerDownCapture:Hi,onPointerUpCapture:Hi,onWheelCapture:Hi,onFocusCapture:T=>{const A=T.target;if(!n0(A)||Jr.current==null||Jr.current==="detail")return;const X=A.getAttribute("data-id");X&&l.current.agents.has(X)&&A.matches(":focus-visible")&&dR(X,A,"focus")},onBlurCapture:T=>{var X,te;const A=(te=(X=T.target).getAttribute)==null?void 0:te.call(X,"data-id");A&&Ka(A)},children:[qo===0&&(!Lt&&In?o.jsx(qX,{}):o.jsx(BX,{live:Lt,everConnected:fd,providers:Kn,workspace:Ni,onTour:()=>K(!0)})),(ts.length>1||mc.size>0)&&o.jsx("div",{ref:Ei,className:`cat-filter-bar${Ci?" occluded":""}`,role:"group","aria-label":"Filter tools by category",children:ts.map(T=>{const A=mc.has(T);return o.jsxs("button",{type:"button",className:`cat-filter${A?" off":""}`,onClick:()=>Ji(T),"aria-pressed":!A,title:`${A?"Show":"Hide"} ${hf[T]} tools`,children:[o.jsx(OX,{cat:T}),o.jsx("span",{className:"cat-name",children:hf[T]})]},T)})}),o.jsxs(qA,{nodes:Lo,edges:Qi,nodeTypes:pX,edgesFocusable:!1,edgeTypes:mX,fitView:!Oi,fitViewOptions:{padding:.25,duration:Ch({durationMs:wR,documentHidden:document.hidden})?wR:0},minZoom:E$,maxZoom:C$,panOnScroll:!0,nodesDraggable:!0,nodesConnectable:!1,selectionOnDrag:!1,nodeDragThreshold:5,disableKeyboardA11y:!0,deleteKeyCode:null,onNodeClick:(T,A)=>{if(A.type==="sessionGroup"){R();return}const X=A.type==="recapNote"?A.data.parentId:A.id;C(X,T.shiftKey,!1),!T.shiftKey&&(y&&v(!1),kd?window.setTimeout(()=>{try{Fn(X)}catch{}},80):Fn(X))},onPaneClick:()=>{Ka(),R()},onNodeDoubleClick:(T,A)=>{if(A.type!=="agent"&&A.type!=="recapNote")return;const X=A.type==="recapNote"?A.data.parentId:A.id;C(X,!1),window.setTimeout(()=>{try{Fn(X)}catch{}},80)},onNodeMouseEnter:(T,A)=>{A.type!=="agent"&&A.type!=="recapNote"||Ca.current||Jr.current==null||Jr.current==="detail"||dR(A.id,T.currentTarget)},onNodeMouseLeave:(T,A)=>Ka(A.id),onMoveStart:T=>{Ka(),Jx(Wi(T))&&(No.current+=1),Jx(Wi(T))&&Qs()},onMove:(T,A)=>{var te,ye;_s(),Jx(Wi(T))&&Qs(),(te=Er.current)==null||te.style.setProperty("--zoom",String(A.zoom));const X=AY(Jr.current,A.zoom,Rc());X!==Jr.current&&(Jr.current=X,(ye=Er.current)==null||ye.setAttribute("data-lod",X),Tc(X),X==="detail"&&Ka()),bc.current&&window.clearTimeout(bc.current),bc.current=window.setTimeout(()=>MX(A),250)},onNodeDragStart:(T,A)=>{var X,te;if(Ka(),ip(),Ca.current=!0,wa.current=new Map,Ec(!0),A.type==="agent"&&(Ia(((X=l.current.agents.get(A.id))==null?void 0:X.label)??""),Ma(!0)),vd("far"),_s(),Qs(),A.type==="sessionGroup"){const ye=(te=A.data)==null?void 0:te.sessionId,_e=new Map;if(ye)for(const Oe of mn){const Ve=Oe.data;(Ve==null?void 0:Ve.sessionId)===ye&&_e.set(Oe.id,{x:Oe.position.x,y:Oe.position.y})}$i.current={start:{x:A.position.x,y:A.position.y},members:_e};return}Gt.current.set(A.id,{x:A.position.x,y:A.position.y})},onNodeDrag:(T,A)=>{var X;if(_s(),A.type==="agent"&&vd(Mo(T)),A.type==="sessionGroup"){const te=$i.current;if(!te)return;const ye=A.position.x-te.start.x,_e=A.position.y-te.start.y;for(const[Ve,it]of te.members){const Ze={x:it.x+ye,y:it.y+_e};Gt.current.set(Ve,Ze),Kt.current.set(Ve,Ze)}const Oe=wa.current;if(Oe){for(const[Ve,it]of te.members)Oe.set(Ve,{x:it.x+ye,y:it.y+_e});Oe.set(A.id,{x:A.position.x,y:A.position.y})}Ri(Ve=>Ve+1);return}Gt.current.set(A.id,{x:A.position.x,y:A.position.y}),Kt.current.set(A.id,{x:A.position.x,y:A.position.y}),(X=wa.current)==null||X.set(A.id,{x:A.position.x,y:A.position.y}),Ri(te=>te+1)},onNodeDragStop:(T,A)=>{_s();const X=A.type==="agent"&&Mo(T)==="over";if(Ca.current=!1,wa.current=null,Ec(!1),Ma(!1),nd(te=>te+1),A.type==="sessionGroup"){const te=$i.current;if(te){const ye=A.position.x-te.start.x,_e=A.position.y-te.start.y;for(const[Oe,Ve]of te.members){const it={x:Ve.x+ye,y:Ve.y+_e};Gt.current.set(Oe,it),Kt.current.set(Oe,it)}}$i.current=null,Ah(Kt.current,Gt.current),nd(ye=>ye+1);return}if(Gt.current.set(A.id,{x:A.position.x,y:A.position.y}),Kt.current.set(A.id,{x:A.position.x,y:A.position.y}),X){Cr(A.id);return}Ah(Kt.current,Gt.current)},children:[o.jsx(M5,{gap:28,size:1,color:Xr["--grid-line"]}),o.jsx(Rq,{onFocusSession:Fn}),o.jsx(YF,{agents:l.current.agents,visibleAgentIds:_o,positions:Kt.current,pinned:Gt.current,measured:Sr.current,spotlight:_r,hiddenCategories:mc,now:Jt,onOpenTool:E}),Sc&&o.jsxs("div",{className:"autofit-chip",children:[o.jsx("span",{className:"autofit-state",title:"New sessions are not brought into view while you are moving it yourself",children:"Auto-fit off"}),o.jsx("button",{type:"button",className:"autofit-resume",onClick:Ea,title:"Bring new sessions into view again","aria-label":"Resume auto-fit",children:"Resume"})]}),o.jsxs(_5,{showInteractive:!1,showFitView:!1,showZoom:!1,children:[o.jsx(Lr,{onClick:()=>e.zoomIn(),title:"Zoom in","aria-label":"Zoom in",disabled:t,children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:o.jsx("path",{d:"M12 5v14M5 12h14",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})})}),o.jsx(Lr,{onClick:()=>e.zoomOut(),title:"Zoom out","aria-label":"Zoom out",disabled:n,children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:o.jsx("path",{d:"M5 12h14",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})})}),o.jsx(Lr,{onClick:Ea,title:Sc?"Recenter view + re-enable autofit":"Recenter view (autofit already on)","aria-label":"Recenter view","data-nudge":Sc?"":void 0,children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:[o.jsx("circle",{cx:"12",cy:"12",r:"3.5",fill:"none",stroke:"currentColor",strokeWidth:"2"}),o.jsx("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})]})}),o.jsx(Lr,{"data-group-start":"",onClick:va,title:lX({paused:go,held:En.size,dropped:En.dropped}),"aria-label":iX,"aria-pressed":go,children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:o.jsx("path",{d:"M9 5.5v13M15 5.5v13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})})}),o.jsx(Lr,{onClick:gn,title:"Auto-arrange — clear pins (R)","aria-label":"Re-arrange the canvas",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:[o.jsx("rect",{x:"8.5",y:"2",width:"7",height:"5",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"2"}),o.jsx("rect",{x:"1.5",y:"17",width:"7",height:"5",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"2"}),o.jsx("rect",{x:"15.5",y:"17",width:"7",height:"5",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"2"}),o.jsx("path",{d:"M12 7v6.5M5 17v-3.5h14V17",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}),o.jsx(Lr,{"data-group-start":"","data-danger":"",onClick:()=>rs("button"),title:"Clear the canvas and the server's event log — asks first (C)","aria-label":"Clear the canvas",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:[o.jsx("path",{d:"M4 6.2h16",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"}),o.jsx("path",{d:"M9 6.2V4.4a1.6 1.6 0 0 1 1.6-1.6h2.8a1.6 1.6 0 0 1 1.6 1.6v1.8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),o.jsx("path",{d:"M17.4 6.4 16.7 20a2 2 0 0 1-2 1.9H9.3a2 2 0 0 1-2-1.9L6.6 6.4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),o.jsx("path",{d:"M10.3 10.6v6.8M13.7 10.6v6.8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})]})}),o.jsx(Lr,{"data-group-start":"",onClick:()=>M(T=>!T),title:"Keyboard shortcuts (?)","aria-label":"Open the keyboard shortcuts","aria-haspopup":"dialog",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:[o.jsx("path",{d:"M8.6 8.4a3.5 3.5 0 1 1 4.6 3.35c-.85.3-1.2 1-1.2 1.85v1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),o.jsx("path",{d:"M12 18.4v.2",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",fill:"none"})]})})]}),o.jsx(v5,{zoomable:!0,pannable:!0,nodeColor:ja,nodeStrokeWidth:2,maskColor:Xr["--minimap-mask"],maskStrokeColor:Xr["--line"]}),vo&&o.jsx(JG,{volume:Li,muted:Pi,source:Gs,playRequest:ud,customStation:xo.find(T=>yi(T.id)===Gs),onAvailabilityChange:ko})]}),mh(Cc)&&o.jsxs("div",{ref:xd,className:`drag-trash-zone ${Ao}${Cc==="leaving"?" leaving":""}`,role:"status",children:[o.jsx("svg",{className:"drag-trash-icon",viewBox:"0 0 24 24","aria-hidden":"true",children:o.jsx("path",{d:"M8 7V5.8C8 4.8 8.8 4 9.8 4h4.4c1 0 1.8.8 1.8 1.8V7m-10 0h12M8 10v8m4-8v8m4-8v8M7 7l.7 13h8.6L17 7"})}),o.jsxs("span",{className:"drag-trash-copy",children:[o.jsx("span",{className:"drag-trash-text",children:Ao==="over"?o.jsxs(o.Fragment,{children:["Release to remove ",o.jsx("strong",{className:"drag-trash-name",children:Yi||"this card"})]}):"Drop here to remove from the board"}),o.jsx("span",{className:"drag-trash-hint",children:Ao==="over"?"The session list (L) brings it back":"The session keeps running"})]})]}),o.jsx(BY,{agentFor:el,recapFor:ss,labelFor:Sd,bounds:tl})]}),mh(Pe)&&o.jsx(j8,{state:l.current,now:Jt,providers:Kn,liveSince:_a,leaving:Pe==="leaving",onClose:()=>F(!1)}),mh(Be)&&o.jsx(sB,{usageOpen:W,leaving:Be==="leaving",onClose:()=>le(!1)}),y&&Cn?o.jsxs("aside",{className:"detail","aria-label":"Detail",children:[o.jsx("button",{type:"button",className:"glyph-btn detail-close",title:"Close panel","aria-label":"Close detail panel",onClick:()=>v(!1),children:"×"}),o.jsx(UX,{agent:Cn,now:Jt,onOpenTool:E,onShowSummary:O,onExportSession:T=>IX(l.current,T),onRemove:At})]}):null,Po&&o.jsx(vq,{tool:Po,onClose:()=>E(null)}),Kr&&o.jsx(w.Suspense,{fallback:null,children:o.jsx(hX,{providers:Kn,onClose:()=>kr(!1)})}),ga&&o.jsx(w.Suspense,{fallback:null,children:o.jsx(fX,{onClose:()=>Ws(!1),onSeen:T=>{rl(""),Jf(T);try{localStorage.setItem(oR,String(T))}catch{}},onWatching:dc,palette:Xr})}),H&&(()=>{const T=l.current.agents.get(H);return T?o.jsx(eF,{agent:T,onClose:()=>q(null)}):null})(),I&&o.jsx(zq,{state:l.current,sessionId:I,onClose:()=>O(null)}),ur&&o.jsx(EK,{entries:ur.entries,since:ur.since,firstRun:ur.firstRun,running:io,onClose:()=>sn(null),onTour:()=>{sn(null),K(!0)},updateVersion:Qt==null?void 0:Qt.version,updateBusy:fa,updateFailure:xr&&(!Qt||Qt.version===xr.version)?_K(xr.failure,xr.version):void 0,onUpdateRestart:Qt?()=>{ki(Qt.version)}:void 0,onRestart:!Qt&&(xe!=null&&xe.canRestart)?()=>{sn(null),wo()}:void 0}),(()=>{const{request:T,waiting:A}=uY(_i,td.current);return T?o.jsx(dY,{request:T,waiting:A,busy:Ss,now:Date.now(),onAccept:()=>void Vs("accept",T.fp),onDecline:()=>void Vs("dismiss",T.fp),onLater:()=>{Ss||(td.current.add(T.fp),mo(X=>[...X]))}}):null})(),ee&&o.jsx(W9,{onClose:()=>M(!1),onTour:()=>{M(!1),K(!0)}}),Z&&o.jsx(UM,{title:"What the deck shows you",steps:gz,onClose:()=>{K(!1),gK(nR()),hu()&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{});const T=D.current;D.current=null,T&&sn(T)}}),V&&o.jsx(z9,{agentCount:qo,onConfirm:()=>rs("confirmation"),onCancel:()=>ne(!1)})]})}function qX(){return o.jsxs("div",{className:"empty-hero",children:[o.jsxs("div",{className:"orbit-stack","aria-hidden":!0,children:[o.jsx("div",{className:"core"}),o.jsxs("div",{className:"orbit r1",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]}),o.jsxs("div",{className:"orbit r2",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]}),o.jsxs("div",{className:"orbit r3",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]})]}),o.jsxs("h2",{children:["Too many ",dn," tabs are open"]}),o.jsxs("p",{children:["This browser keeps at most six live connections to one address, and other ",o.jsx("code",{children:dn})," tabs are holding them. Close one and this tab connects on its own."]})]})}function BX({live:e,everConnected:t,providers:n,workspace:r,onTour:s}){const l=!e;return o.jsxs("div",{className:"empty-hero",children:[o.jsxs("div",{className:"orbit-stack","aria-hidden":!0,children:[o.jsx("div",{className:"core"}),o.jsxs("div",{className:"orbit r1",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]}),o.jsxs("div",{className:"orbit r2",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]}),o.jsxs("div",{className:"orbit r3",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]})]}),l?o.jsxs(o.Fragment,{children:[o.jsx("h2",{children:t?"Disconnected from server":"Server unreachable"}),o.jsxs("p",{children:[t?"This page lost its connection to ":"This page cannot reach ",o.jsx("code",{children:dn}),". Check that it is still running in your terminal — the page picks up again on its own."]})]}):zX(n,r),!l&&o.jsx("button",{type:"button",className:"btn empty-tour",onClick:s,children:"Take the tour"})]})}function zX(e,t){const n=JY(t);return o.jsxs(o.Fragment,{children:[o.jsx("h2",{children:"Waiting for Claude Code or Codex"}),n.kind==="scoped"?o.jsxs("p",{children:[n.lead," ",o.jsx("code",{children:n.workspace}),n.tail]}):o.jsxs("p",{children:["Run ",o.jsx("code",{children:"claude"})," or ",o.jsx("code",{children:"codex"})," in any folder. As soon as a session sends an event, a node appears here and grows as subagents fork and tools are called."]}),sX(e).map(r=>o.jsx("p",{className:"hint-row",children:r.spans.map((s,l)=>s.code?o.jsx("code",{children:s.text},l):o.jsx("span",{children:s.text},l))},r.provider))]})}function UX({agent:e,now:t,onOpenTool:n,onShowSummary:r,onExportSession:s,onRemove:l}){const c=`${e.synthetic?"≥ ":""}${Ul(e.startedAt,e.endedAt,t)}`,u=ir(e),f=u.total>0,p=e.usage.inputTokens+e.usage.outputTokens,h=new Map;for(const b of e.tools){const _=z$(b.name);h.set(_,(h.get(_)??0)+1)}const m=e.tools.filter(b=>b.ok===!1).length,y=e.tools.filter(b=>!b.endedAt).length,v=Array.from(h.entries()).sort((b,_)=>_[1]-b[1]),S=h.has("mcp")?HF(e.tools.map(b=>b.name)):null;return o.jsxs(o.Fragment,{children:[o.jsxs("header",{className:"detail-hero",children:[o.jsxs("div",{className:"hero-line",children:[o.jsx("span",{className:`state-pill state-${e.state}`,children:e.state==="active"?"live":e.state}),o.jsx("h2",{className:"hero-title",title:e.cwd??e.label,children:e.label})]}),o.jsxs("div",{className:"hero-meta",children:[o.jsx("span",{className:"hero-meta-item",children:e.kind==="root"?"session":"subagent"}),o.jsx("span",{className:"hero-sep",children:"·"}),o.jsx("span",{className:"hero-meta-item",title:`started ${new Date(e.startedAt).toLocaleString()}`,children:c}),e.model&&(()=>{const b=rM(e);return o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"hero-sep",children:"·"}),o.jsxs("span",{className:"model-chip","data-family":bf(e.model),title:b.length>0?`${e.model}
|
|
295
|
+
Node loads every module once, at startup. An upgrade replaces the files on disk but not the code already in memory, so this process keeps running the old version until it is restarted.`,children:Nr?"restarting…":od.label}),!Nr&&o.jsx("span",{className:"ver-sub",children:od.clause}),o.jsxs("label",{className:"ver-auto",children:[o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":Pn,onClick:tp,"aria-label":"Auto-restart when idle",title:Pn?"Updates on its own. While you are here it restarts once nothing has been running for 30 seconds; while you are away it also installs the new version first. Click to require a click instead.":"Only updates when you click. Click to let it update itself when idle or while you are away.",children:o.jsx("span",{className:"switch-knob"})}),o.jsx("span",{"aria-hidden":!0,children:HU(Pn,id)})]})]}):o.jsx("span",{className:"ver-sub",title:"Node loads every module once, at startup. An upgrade replaces the files on disk but not the code already in memory, so this process keeps running the old version until it is restarted.",children:"Restart it to pick up the new code."})]}):o.jsxs(o.Fragment,{children:[o.jsxs("strong",{children:[dn," v",ht.to," is out — you are on v",ht.from,"."]}),(xe==null?void 0:xe.upgradeMode)==="install"&&On!=="failed"&&o.jsx("button",{type:"button",className:"ver-act",onClick:ed,...Qa(On==="running",On==="done"),title:`Runs ${((Lc=xe==null?void 0:xe.upgrade)==null?void 0:Lc.command)??(xe==null?void 0:xe.command)??"npm i -g"} here, then restarts once nothing is running.`,children:On==="running"?"installing…":On==="done"?"installed":"Update now"}),(xe==null?void 0:xe.upgradeMode)==="npx"&&(xe==null?void 0:xe.canRestart)&&o.jsx("button",{type:"button",className:"ver-act",onClick:()=>wo({upgrade:!0}),...Qa(Nr),title:`Runs ${xe==null?void 0:xe.command} and hands it this port. Nothing is installed globally — npx unpacks its own copy.`,children:Nr?"fetching…":On==="failed"?"Retry update":"Update & restart"}),On==="failed"?o.jsxs("span",{className:"ver-sub fail",title:((ra=xe==null?void 0:xe.upgrade)==null?void 0:ra.error)??"",children:[(xe==null?void 0:xe.upgradeMode)==="npx"?"update failed":"install failed",": ",((Pc=xe==null?void 0:xe.upgrade)==null?void 0:Pc.error)??"unknown error"," — run it yourself:"]}):(xe==null?void 0:xe.upgradeMode)==="npx"?o.jsx("span",{className:"ver-sub",children:xe!=null&&xe.canRestart?"npx cannot upgrade in place, so the deck re-runs:":i0.npx}):xe!=null&&xe.upgradeBlocked?o.jsx("span",{className:"ver-sub",children:Object.hasOwn(i0,xe.upgradeBlocked)?i0[xe.upgradeBlocked]:"cannot install from here"}):null,o.jsxs("button",{type:"button",className:"ver-cmd",onClick:lc,title:"Copy to clipboard",children:[o.jsx("code",{children:xe==null?void 0:xe.command}),o.jsx("span",{className:"ver-cmd-hint",children:De?"copied":"copy"})]})]}),o.jsx("button",{type:"button","aria-label":"Dismiss",className:"ver-close",onClick:uo,children:"×"})]}):Qu&&ft?o.jsxs("div",{className:"ver-banner",role:"status",children:[o.jsx("span",{className:"ver-dot"}),o.jsxs("strong",{children:[ft," still works — the deck is called ",dn," now."]}),xe!=null&&xe.renameFix?o.jsx("span",{className:"ver-sub",children:xe.renameFix}):null,o.jsx("button",{type:"button","aria-label":"Dismiss",className:"ver-close",onClick:Ju,children:"×"})]}):null,mh(Ge)&&Kn.claude&&o.jsx(PU,{leaving:Ge==="leaving",onClose:()=>Ie(!1)}),P&&o.jsx(Wq,{state:l.current,now:Jt,selectedIds:S,onSelect:$a,onClose:()=>B(!1),removedIds:jr,onBringBackAll:()=>{Zn([...c]),p(null)}}),o.jsxs("main",{id:"canvas",tabIndex:-1,className:`canvas-wrap${$t?" bubbling":""}${Qr?" dragging-any":""}${Ki&&Ao==="over"?" trash-hover":""}`,"data-lod":Xi,ref:Er,onMouseDownCapture:Co,onPointerDownCapture:Hi,onPointerUpCapture:Hi,onWheelCapture:Hi,onFocusCapture:T=>{const A=T.target;if(!n0(A)||Jr.current==null||Jr.current==="detail")return;const X=A.getAttribute("data-id");X&&l.current.agents.has(X)&&A.matches(":focus-visible")&&dR(X,A,"focus")},onBlurCapture:T=>{var X,te;const A=(te=(X=T.target).getAttribute)==null?void 0:te.call(X,"data-id");A&&Ka(A)},children:[qo===0&&(!Lt&&In?o.jsx(BX,{}):o.jsx(zX,{live:Lt,everConnected:fd,providers:Kn,workspace:Ni,onTour:()=>K(!0)})),(ts.length>1||mc.size>0)&&o.jsx("div",{ref:Ei,className:`cat-filter-bar${Ci?" occluded":""}`,role:"group","aria-label":"Filter tools by category",children:ts.map(T=>{const A=mc.has(T);return o.jsxs("button",{type:"button",className:`cat-filter${A?" off":""}`,onClick:()=>Ji(T),"aria-pressed":!A,title:`${A?"Show":"Hide"} ${hf[T]} tools`,children:[o.jsx(LX,{cat:T}),o.jsx("span",{className:"cat-name",children:hf[T]})]},T)})}),o.jsxs(qA,{nodes:Lo,edges:Qi,nodeTypes:mX,edgesFocusable:!1,edgeTypes:gX,fitView:!Oi,fitViewOptions:{padding:.25,duration:Ch({durationMs:wR,documentHidden:document.hidden})?wR:0},minZoom:E$,maxZoom:C$,panOnScroll:!0,nodesDraggable:!0,nodesConnectable:!1,selectionOnDrag:!1,nodeDragThreshold:5,disableKeyboardA11y:!0,deleteKeyCode:null,onNodeClick:(T,A)=>{if(A.type==="sessionGroup"){R();return}const X=A.type==="recapNote"?A.data.parentId:A.id;C(X,T.shiftKey,!1),!T.shiftKey&&(y&&v(!1),kd?window.setTimeout(()=>{try{Fn(X)}catch{}},80):Fn(X))},onPaneClick:()=>{Ka(),R()},onNodeDoubleClick:(T,A)=>{if(A.type!=="agent"&&A.type!=="recapNote")return;const X=A.type==="recapNote"?A.data.parentId:A.id;C(X,!1),window.setTimeout(()=>{try{Fn(X)}catch{}},80)},onNodeMouseEnter:(T,A)=>{A.type!=="agent"&&A.type!=="recapNote"||Ca.current||Jr.current==null||Jr.current==="detail"||dR(A.id,T.currentTarget)},onNodeMouseLeave:(T,A)=>Ka(A.id),onMoveStart:T=>{Ka(),Jx(Wi(T))&&(No.current+=1),Jx(Wi(T))&&Qs()},onMove:(T,A)=>{var te,ye;_s(),Jx(Wi(T))&&Qs(),(te=Er.current)==null||te.style.setProperty("--zoom",String(A.zoom));const X=MY(Jr.current,A.zoom,Rc());X!==Jr.current&&(Jr.current=X,(ye=Er.current)==null||ye.setAttribute("data-lod",X),Tc(X),X==="detail"&&Ka()),bc.current&&window.clearTimeout(bc.current),bc.current=window.setTimeout(()=>IX(A),250)},onNodeDragStart:(T,A)=>{var X,te;if(Ka(),ip(),Ca.current=!0,wa.current=new Map,Ec(!0),A.type==="agent"&&(Ia(((X=l.current.agents.get(A.id))==null?void 0:X.label)??""),Ma(!0)),vd("far"),_s(),Qs(),A.type==="sessionGroup"){const ye=(te=A.data)==null?void 0:te.sessionId,_e=new Map;if(ye)for(const Oe of mn){const Ve=Oe.data;(Ve==null?void 0:Ve.sessionId)===ye&&_e.set(Oe.id,{x:Oe.position.x,y:Oe.position.y})}$i.current={start:{x:A.position.x,y:A.position.y},members:_e};return}Gt.current.set(A.id,{x:A.position.x,y:A.position.y})},onNodeDrag:(T,A)=>{var X;if(_s(),A.type==="agent"&&vd(Mo(T)),A.type==="sessionGroup"){const te=$i.current;if(!te)return;const ye=A.position.x-te.start.x,_e=A.position.y-te.start.y;for(const[Ve,it]of te.members){const Ze={x:it.x+ye,y:it.y+_e};Gt.current.set(Ve,Ze),Kt.current.set(Ve,Ze)}const Oe=wa.current;if(Oe){for(const[Ve,it]of te.members)Oe.set(Ve,{x:it.x+ye,y:it.y+_e});Oe.set(A.id,{x:A.position.x,y:A.position.y})}Ri(Ve=>Ve+1);return}Gt.current.set(A.id,{x:A.position.x,y:A.position.y}),Kt.current.set(A.id,{x:A.position.x,y:A.position.y}),(X=wa.current)==null||X.set(A.id,{x:A.position.x,y:A.position.y}),Ri(te=>te+1)},onNodeDragStop:(T,A)=>{_s();const X=A.type==="agent"&&Mo(T)==="over";if(Ca.current=!1,wa.current=null,Ec(!1),Ma(!1),nd(te=>te+1),A.type==="sessionGroup"){const te=$i.current;if(te){const ye=A.position.x-te.start.x,_e=A.position.y-te.start.y;for(const[Oe,Ve]of te.members){const it={x:Ve.x+ye,y:Ve.y+_e};Gt.current.set(Oe,it),Kt.current.set(Oe,it)}}$i.current=null,Ah(Kt.current,Gt.current),nd(ye=>ye+1);return}if(Gt.current.set(A.id,{x:A.position.x,y:A.position.y}),Kt.current.set(A.id,{x:A.position.x,y:A.position.y}),X){Cr(A.id);return}Ah(Kt.current,Gt.current)},children:[o.jsx(M5,{gap:28,size:1,color:Xr["--grid-line"]}),o.jsx(Rq,{onFocusSession:Fn}),o.jsx(YF,{agents:l.current.agents,visibleAgentIds:_o,positions:Kt.current,pinned:Gt.current,measured:Sr.current,spotlight:_r,hiddenCategories:mc,now:Jt,onOpenTool:E}),Sc&&o.jsxs("div",{className:"autofit-chip",children:[o.jsx("span",{className:"autofit-state",title:"New sessions are not brought into view while you are moving it yourself",children:"Auto-fit off"}),o.jsx("button",{type:"button",className:"autofit-resume",onClick:Ea,title:"Bring new sessions into view again","aria-label":"Resume auto-fit",children:"Resume"})]}),o.jsxs(_5,{showInteractive:!1,showFitView:!1,showZoom:!1,children:[o.jsx(Lr,{onClick:()=>e.zoomIn(),title:"Zoom in","aria-label":"Zoom in",disabled:t,children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:o.jsx("path",{d:"M12 5v14M5 12h14",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})})}),o.jsx(Lr,{onClick:()=>e.zoomOut(),title:"Zoom out","aria-label":"Zoom out",disabled:n,children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:o.jsx("path",{d:"M5 12h14",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})})}),o.jsx(Lr,{onClick:Ea,title:Sc?"Recenter view + re-enable autofit":"Recenter view (autofit already on)","aria-label":"Recenter view","data-nudge":Sc?"":void 0,children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:[o.jsx("circle",{cx:"12",cy:"12",r:"3.5",fill:"none",stroke:"currentColor",strokeWidth:"2"}),o.jsx("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})]})}),o.jsx(Lr,{"data-group-start":"",onClick:va,title:cX({paused:go,held:En.size,dropped:En.dropped}),"aria-label":lX,"aria-pressed":go,children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:o.jsx("path",{d:"M9 5.5v13M15 5.5v13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})})}),o.jsx(Lr,{onClick:gn,title:"Auto-arrange — clear pins (R)","aria-label":"Re-arrange the canvas",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:[o.jsx("rect",{x:"8.5",y:"2",width:"7",height:"5",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"2"}),o.jsx("rect",{x:"1.5",y:"17",width:"7",height:"5",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"2"}),o.jsx("rect",{x:"15.5",y:"17",width:"7",height:"5",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"2"}),o.jsx("path",{d:"M12 7v6.5M5 17v-3.5h14V17",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}),o.jsx(Lr,{"data-group-start":"","data-danger":"",onClick:()=>rs("button"),title:"Clear the canvas and the server's event log — asks first (C)","aria-label":"Clear the canvas",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:[o.jsx("path",{d:"M4 6.2h16",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"}),o.jsx("path",{d:"M9 6.2V4.4a1.6 1.6 0 0 1 1.6-1.6h2.8a1.6 1.6 0 0 1 1.6 1.6v1.8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),o.jsx("path",{d:"M17.4 6.4 16.7 20a2 2 0 0 1-2 1.9H9.3a2 2 0 0 1-2-1.9L6.6 6.4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),o.jsx("path",{d:"M10.3 10.6v6.8M13.7 10.6v6.8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",fill:"none"})]})}),o.jsx(Lr,{"data-group-start":"",onClick:()=>M(T=>!T),title:"Keyboard shortcuts (?)","aria-label":"Open the keyboard shortcuts","aria-haspopup":"dialog",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24","aria-hidden":!0,children:[o.jsx("path",{d:"M8.6 8.4a3.5 3.5 0 1 1 4.6 3.35c-.85.3-1.2 1-1.2 1.85v1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),o.jsx("path",{d:"M12 18.4v.2",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",fill:"none"})]})})]}),o.jsx(v5,{zoomable:!0,pannable:!0,nodeColor:ja,nodeStrokeWidth:2,maskColor:Xr["--minimap-mask"],maskStrokeColor:Xr["--line"]}),vo&&o.jsx(eK,{volume:Li,muted:Pi,source:Gs,playRequest:ud,customStation:xo.find(T=>yi(T.id)===Gs),onAvailabilityChange:ko})]}),mh(Cc)&&o.jsxs("div",{ref:xd,className:`drag-trash-zone ${Ao}${Cc==="leaving"?" leaving":""}`,role:"status",children:[o.jsx("svg",{className:"drag-trash-icon",viewBox:"0 0 24 24","aria-hidden":"true",children:o.jsx("path",{d:"M8 7V5.8C8 4.8 8.8 4 9.8 4h4.4c1 0 1.8.8 1.8 1.8V7m-10 0h12M8 10v8m4-8v8m4-8v8M7 7l.7 13h8.6L17 7"})}),o.jsxs("span",{className:"drag-trash-copy",children:[o.jsx("span",{className:"drag-trash-text",children:Ao==="over"?o.jsxs(o.Fragment,{children:["Release to remove ",o.jsx("strong",{className:"drag-trash-name",children:Yi||"this card"})]}):"Drop here to remove from the board"}),o.jsx("span",{className:"drag-trash-hint",children:Ao==="over"?"The session list (L) brings it back":"The session keeps running"})]})]}),o.jsx(zY,{agentFor:el,recapFor:ss,labelFor:Sd,bounds:tl})]}),mh(Pe)&&o.jsx(j8,{state:l.current,now:Jt,providers:Kn,liveSince:_a,leaving:Pe==="leaving",onClose:()=>F(!1)}),mh(Be)&&o.jsx(sB,{usageOpen:W,leaving:Be==="leaving",onClose:()=>le(!1)}),y&&Cn?o.jsxs("aside",{className:"detail","aria-label":"Detail",children:[o.jsx("button",{type:"button",className:"glyph-btn detail-close",title:"Close panel","aria-label":"Close detail panel",onClick:()=>v(!1),children:"×"}),o.jsx(HX,{agent:Cn,now:Jt,onOpenTool:E,onShowSummary:O,onExportSession:T=>$X(l.current,T),onRemove:At})]}):null,Po&&o.jsx(vq,{tool:Po,onClose:()=>E(null)}),Kr&&o.jsx(w.Suspense,{fallback:null,children:o.jsx(fX,{providers:Kn,onClose:()=>kr(!1)})}),ga&&o.jsx(w.Suspense,{fallback:null,children:o.jsx(pX,{onClose:()=>Ws(!1),onSeen:T=>{rl(""),Jf(T);try{localStorage.setItem(oR,String(T))}catch{}},onWatching:dc,palette:Xr})}),H&&(()=>{const T=l.current.agents.get(H);return T?o.jsx(eF,{agent:T,onClose:()=>q(null)}):null})(),I&&o.jsx(zq,{state:l.current,sessionId:I,onClose:()=>O(null)}),ur&&o.jsx(CK,{entries:ur.entries,since:ur.since,firstRun:ur.firstRun,running:io,onClose:()=>sn(null),onTour:()=>{sn(null),K(!0)},updateVersion:Qt==null?void 0:Qt.version,updateBusy:fa,updateFailure:xr&&(!Qt||Qt.version===xr.version)?EK(xr.failure,xr.version):void 0,onUpdateRestart:Qt?()=>{ki(Qt.version)}:void 0,onRestart:!Qt&&(xe!=null&&xe.canRestart)?()=>{sn(null),wo()}:void 0}),(()=>{const{request:T,waiting:A}=dY(_i,td.current);return T?o.jsx(hY,{request:T,waiting:A,busy:Ss,now:Date.now(),onAccept:()=>void Vs("accept",T.fp),onDecline:()=>void Vs("dismiss",T.fp),onLater:()=>{Ss||(td.current.add(T.fp),mo(X=>[...X]))}}):null})(),ee&&o.jsx(V9,{onClose:()=>M(!1),onTour:()=>{M(!1),K(!0)}}),Z&&o.jsx(UM,{title:"What the deck shows you",steps:gz,onClose:()=>{K(!1),yK(nR()),hu()&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{});const T=D.current;D.current=null,T&&sn(T)}}),V&&o.jsx(U9,{agentCount:qo,onConfirm:()=>rs("confirmation"),onCancel:()=>ne(!1)})]})}function BX(){return o.jsxs("div",{className:"empty-hero",children:[o.jsxs("div",{className:"orbit-stack","aria-hidden":!0,children:[o.jsx("div",{className:"core"}),o.jsxs("div",{className:"orbit r1",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]}),o.jsxs("div",{className:"orbit r2",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]}),o.jsxs("div",{className:"orbit r3",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]})]}),o.jsxs("h2",{children:["Too many ",dn," tabs are open"]}),o.jsxs("p",{children:["This browser keeps at most six live connections to one address, and other ",o.jsx("code",{children:dn})," tabs are holding them. Close one and this tab connects on its own."]})]})}function zX({live:e,everConnected:t,providers:n,workspace:r,onTour:s}){const l=!e;return o.jsxs("div",{className:"empty-hero",children:[o.jsxs("div",{className:"orbit-stack","aria-hidden":!0,children:[o.jsx("div",{className:"core"}),o.jsxs("div",{className:"orbit r1",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]}),o.jsxs("div",{className:"orbit r2",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]}),o.jsxs("div",{className:"orbit r3",children:[o.jsx("span",{className:"dot"}),o.jsx("span",{className:"dot b"})]})]}),l?o.jsxs(o.Fragment,{children:[o.jsx("h2",{children:t?"Disconnected from server":"Server unreachable"}),o.jsxs("p",{children:[t?"This page lost its connection to ":"This page cannot reach ",o.jsx("code",{children:dn}),". Check that it is still running in your terminal — the page picks up again on its own."]})]}):UX(n,r),!l&&o.jsx("button",{type:"button",className:"btn empty-tour",onClick:s,children:"Take the tour"})]})}function UX(e,t){const n=eX(t);return o.jsxs(o.Fragment,{children:[o.jsx("h2",{children:"Waiting for Claude Code or Codex"}),n.kind==="scoped"?o.jsxs("p",{children:[n.lead," ",o.jsx("code",{children:n.workspace}),n.tail]}):o.jsxs("p",{children:["Run ",o.jsx("code",{children:"claude"})," or ",o.jsx("code",{children:"codex"})," in any folder. As soon as a session sends an event, a node appears here and grows as subagents fork and tools are called."]}),aX(e).map(r=>o.jsx("p",{className:"hint-row",children:r.spans.map((s,l)=>s.code?o.jsx("code",{children:s.text},l):o.jsx("span",{children:s.text},l))},r.provider))]})}function HX({agent:e,now:t,onOpenTool:n,onShowSummary:r,onExportSession:s,onRemove:l}){const c=`${e.synthetic?"≥ ":""}${Ul(e.startedAt,e.endedAt,t)}`,u=ir(e),f=u.total>0,p=e.usage.inputTokens+e.usage.outputTokens,h=new Map;for(const b of e.tools){const _=z$(b.name);h.set(_,(h.get(_)??0)+1)}const m=e.tools.filter(b=>b.ok===!1).length,y=e.tools.filter(b=>!b.endedAt).length,v=Array.from(h.entries()).sort((b,_)=>_[1]-b[1]),S=h.has("mcp")?HF(e.tools.map(b=>b.name)):null;return o.jsxs(o.Fragment,{children:[o.jsxs("header",{className:"detail-hero",children:[o.jsxs("div",{className:"hero-line",children:[o.jsx("span",{className:`state-pill state-${e.state}`,children:e.state==="active"?"live":e.state}),o.jsx("h2",{className:"hero-title",title:e.cwd??e.label,children:e.label})]}),o.jsxs("div",{className:"hero-meta",children:[o.jsx("span",{className:"hero-meta-item",children:e.kind==="root"?"session":"subagent"}),o.jsx("span",{className:"hero-sep",children:"·"}),o.jsx("span",{className:"hero-meta-item",title:`started ${new Date(e.startedAt).toLocaleString()}`,children:c}),e.model&&(()=>{const b=rM(e);return o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"hero-sep",children:"·"}),o.jsxs("span",{className:"model-chip","data-family":bf(e.model),title:b.length>0?`${e.model}
|
|
296
296
|
spend on this panel also covers:
|
|
297
297
|
${b.join(`
|
|
298
|
-
`)}`:e.model,children:[so(e.model),b.length>0?` +${b.length}`:""]})]})})()]}),f&&o.jsxs("div",{className:"hero-cost",children:[o.jsxs("div",{className:"hero-cost-headline",children:[o.jsx("span",{className:"hero-cost-value",children:ut(u.total)}),o.jsx("span",{className:"hero-cost-label",children:"spend"})]}),o.jsx(Ab,{cost:u})]}),o.jsxs("div",{className:"hero-actions",children:[e.kind==="root"&&e.state==="done"&&r&&o.jsx("button",{type:"button",className:"btn hero-action-btn",onClick:()=>r(e.sessionId),title:"Reopen the end-of-session recap modal",children:"Show recap"}),s&&o.jsx("button",{type:"button",className:"btn hero-action-btn",onClick:()=>s(e.sessionId),title:"Download this session as JSON",children:"Export JSON"}),l&&o.jsx("button",{type:"button",className:"btn hero-action-btn",onClick:l,title:e.kind==="root"?"Take this session's cards off the board (Delete). The session carries on; the session list (L) brings it back":"Take this card and the ones under it off the board (Delete). The session list (L) brings it back",children:"Remove from board"})]})]}),(()=>{const b=jf(e);if(!b)return null;const _=Jh(b.at,t);return o.jsxs("section",{className:"detail-section",children:[o.jsxs("h3",{children:["Recap ",o.jsx("span",{className:"section-count",title:_.title,children:_.label})]}),o.jsx("p",{className:"detail-recap",children:b.text})]})})(),e.tools.length>0&&o.jsxs("section",{className:"detail-section",children:[o.jsx("h3",{children:"Activity"}),o.jsxs("div",{className:"activity-row",children:[o.jsxs("div",{className:"activity-counters",children:[o.jsxs("span",{className:"ac-item",children:[o.jsx("b",{children:e.toolCount})," calls"]}),y>0&&o.jsxs("span",{className:"ac-item ac-live",children:[o.jsx("b",{children:y})," live"]}),m>0&&o.jsxs("span",{className:"ac-item ac-err",children:[o.jsx("b",{children:m})," err"]})]}),o.jsx("div",{className:"cat-strip",children:v.map(([b,_])=>{const k=b==="mcp"?S:null,j=k==null?void 0:k.hue,E=`${_} ${hf[b]} call${_===1?"":"s"}`;return o.jsxs("span",{className:`cat-chip cat-${b}${j!=null?" mcp-hue":""}`,style:j!=null?{"--mcp-hue":j}:void 0,title:k?`${E}, all to ${k.label}`:E,children:[o.jsx("span",{className:"cat-emoji","aria-hidden":!0,children:B$[b]}),o.jsx("span",{className:"cat-name",children:hf[b]}),o.jsx("span",{className:"cat-count",children:_}),k&&o.jsx("span",{className:"cat-server",children:k.label})]},b)})})]})]}),p>0&&o.jsxs("section",{className:"detail-section",children:[o.jsx("h3",{children:"Tokens"}),o.jsxs("div",{className:"tokens-grid",children:[o.jsxs("div",{children:[o.jsx("span",{className:"k",children:"in"}),o.jsx("b",{title:e.usage.inputTokens.toLocaleString(),children:Bt(e.usage.inputTokens)})]}),o.jsxs("div",{children:[o.jsx("span",{className:"k",children:"out"}),o.jsx("b",{title:e.usage.outputTokens.toLocaleString(),children:Bt(e.usage.outputTokens)})]}),o.jsxs("div",{children:[o.jsx("span",{className:"k",children:"cache r"}),o.jsx("b",{title:e.usage.cacheReadTokens.toLocaleString(),children:Bt(e.usage.cacheReadTokens)})]}),o.jsxs("div",{children:[o.jsx("span",{className:"k",children:"cache c"}),o.jsx("b",{title:e.usage.cacheCreateTokens.toLocaleString(),children:Bt(e.usage.cacheCreateTokens)})]})]})]}),o.jsxs("section",{className:"detail-section",children:[o.jsx("h3",{children:"Identity"}),o.jsxs("div",{children:[e.cwd&&o.jsxs("div",{className:"row",children:[o.jsx("span",{className:"k",children:"cwd"}),o.jsx("span",{className:"v",title:e.cwd,children:e.cwd})]}),o.jsxs("div",{className:"row",children:[o.jsx("span",{className:"k",children:"session"}),o.jsxs("span",{className:"v",children:[e.sessionId.slice(0,12),"…"]})]}),e.parentId&&o.jsxs("div",{className:"row",children:[o.jsx("span",{className:"k",children:"parent"}),o.jsxs("span",{className:"v",children:[e.parentId.slice(0,12),"…"]})]})]})]}),e.prompts.length>0&&o.jsxs("section",{className:"detail-section",children:[o.jsxs("h3",{children:["Prompts ",o.jsx("span",{className:"section-count",children:VA(e.prompts).length})]}),o.jsx("div",{className:"prompts",children:e.prompts.slice().reverse().map((b,_)=>{const k=Jh(b.at,t),j=bb(b.text);return j?o.jsxs("details",{className:"prompt-entry prompt-injected",children:[o.jsxs("summary",{children:[o.jsx("span",{className:"prompt-time",title:k.title,children:k.label}),o.jsx("span",{className:"prompt-injected-label",children:j.label})]}),j.detail&&o.jsx("div",{className:"prompt-injected-detail",children:j.detail})]},_):o.jsxs("div",{className:"prompt-entry",children:[o.jsx("div",{className:"prompt-time",title:k.title,children:k.label}),o.jsx("div",{className:"prompt-text",children:b.text})]},_)})})]}),o.jsxs("section",{className:"detail-section",children:[o.jsxs("h3",{children:["Tool calls ",o.jsx("span",{className:"section-count",children:e.tools.length})]}),e.tools.length===0&&o.jsx("div",{className:"empty",children:"No tool calls yet."}),o.jsx("div",{children:e.tools.slice().reverse().map(b=>o.jsx(
|
|
298
|
+
`)}`:e.model,children:[so(e.model),b.length>0?` +${b.length}`:""]})]})})()]}),f&&o.jsxs("div",{className:"hero-cost",children:[o.jsxs("div",{className:"hero-cost-headline",children:[o.jsx("span",{className:"hero-cost-value",children:ut(u.total)}),o.jsx("span",{className:"hero-cost-label",children:"spend"})]}),o.jsx(Ab,{cost:u})]}),o.jsxs("div",{className:"hero-actions",children:[e.kind==="root"&&e.state==="done"&&r&&o.jsx("button",{type:"button",className:"btn hero-action-btn",onClick:()=>r(e.sessionId),title:"Reopen the end-of-session recap modal",children:"Show recap"}),s&&o.jsx("button",{type:"button",className:"btn hero-action-btn",onClick:()=>s(e.sessionId),title:"Download this session as JSON",children:"Export JSON"}),l&&o.jsx("button",{type:"button",className:"btn hero-action-btn",onClick:l,title:e.kind==="root"?"Take this session's cards off the board (Delete). The session carries on; the session list (L) brings it back":"Take this card and the ones under it off the board (Delete). The session list (L) brings it back",children:"Remove from board"})]})]}),(()=>{const b=jf(e);if(!b)return null;const _=Jh(b.at,t);return o.jsxs("section",{className:"detail-section",children:[o.jsxs("h3",{children:["Recap ",o.jsx("span",{className:"section-count",title:_.title,children:_.label})]}),o.jsx("p",{className:"detail-recap",children:b.text})]})})(),e.tools.length>0&&o.jsxs("section",{className:"detail-section",children:[o.jsx("h3",{children:"Activity"}),o.jsxs("div",{className:"activity-row",children:[o.jsxs("div",{className:"activity-counters",children:[o.jsxs("span",{className:"ac-item",children:[o.jsx("b",{children:e.toolCount})," calls"]}),y>0&&o.jsxs("span",{className:"ac-item ac-live",children:[o.jsx("b",{children:y})," live"]}),m>0&&o.jsxs("span",{className:"ac-item ac-err",children:[o.jsx("b",{children:m})," err"]})]}),o.jsx("div",{className:"cat-strip",children:v.map(([b,_])=>{const k=b==="mcp"?S:null,j=k==null?void 0:k.hue,E=`${_} ${hf[b]} call${_===1?"":"s"}`;return o.jsxs("span",{className:`cat-chip cat-${b}${j!=null?" mcp-hue":""}`,style:j!=null?{"--mcp-hue":j}:void 0,title:k?`${E}, all to ${k.label}`:E,children:[o.jsx("span",{className:"cat-emoji","aria-hidden":!0,children:B$[b]}),o.jsx("span",{className:"cat-name",children:hf[b]}),o.jsx("span",{className:"cat-count",children:_}),k&&o.jsx("span",{className:"cat-server",children:k.label})]},b)})})]})]}),p>0&&o.jsxs("section",{className:"detail-section",children:[o.jsx("h3",{children:"Tokens"}),o.jsxs("div",{className:"tokens-grid",children:[o.jsxs("div",{children:[o.jsx("span",{className:"k",children:"in"}),o.jsx("b",{title:e.usage.inputTokens.toLocaleString(),children:Bt(e.usage.inputTokens)})]}),o.jsxs("div",{children:[o.jsx("span",{className:"k",children:"out"}),o.jsx("b",{title:e.usage.outputTokens.toLocaleString(),children:Bt(e.usage.outputTokens)})]}),o.jsxs("div",{children:[o.jsx("span",{className:"k",children:"cache r"}),o.jsx("b",{title:e.usage.cacheReadTokens.toLocaleString(),children:Bt(e.usage.cacheReadTokens)})]}),o.jsxs("div",{children:[o.jsx("span",{className:"k",children:"cache c"}),o.jsx("b",{title:e.usage.cacheCreateTokens.toLocaleString(),children:Bt(e.usage.cacheCreateTokens)})]})]})]}),o.jsxs("section",{className:"detail-section",children:[o.jsx("h3",{children:"Identity"}),o.jsxs("div",{children:[e.cwd&&o.jsxs("div",{className:"row",children:[o.jsx("span",{className:"k",children:"cwd"}),o.jsx("span",{className:"v",title:e.cwd,children:e.cwd})]}),o.jsxs("div",{className:"row",children:[o.jsx("span",{className:"k",children:"session"}),o.jsxs("span",{className:"v",children:[e.sessionId.slice(0,12),"…"]})]}),e.parentId&&o.jsxs("div",{className:"row",children:[o.jsx("span",{className:"k",children:"parent"}),o.jsxs("span",{className:"v",children:[e.parentId.slice(0,12),"…"]})]})]})]}),e.prompts.length>0&&o.jsxs("section",{className:"detail-section",children:[o.jsxs("h3",{children:["Prompts ",o.jsx("span",{className:"section-count",children:VA(e.prompts).length})]}),o.jsx("div",{className:"prompts",children:e.prompts.slice().reverse().map((b,_)=>{const k=Jh(b.at,t),j=bb(b.text);return j?o.jsxs("details",{className:"prompt-entry prompt-injected",children:[o.jsxs("summary",{children:[o.jsx("span",{className:"prompt-time",title:k.title,children:k.label}),o.jsx("span",{className:"prompt-injected-label",children:j.label})]}),j.detail&&o.jsx("div",{className:"prompt-injected-detail",children:j.detail})]},_):o.jsxs("div",{className:"prompt-entry",children:[o.jsx("div",{className:"prompt-time",title:k.title,children:k.label}),o.jsx("div",{className:"prompt-text",children:b.text})]},_)})})]}),o.jsxs("section",{className:"detail-section",children:[o.jsxs("h3",{children:["Tool calls ",o.jsx("span",{className:"section-count",children:e.tools.length})]}),e.tools.length===0&&o.jsx("div",{className:"empty",children:"No tool calls yet."}),o.jsx("div",{children:e.tools.slice().reverse().map(b=>o.jsx(VX,{t:b,onClick:()=>n(b.id)},b.id))})]})]})}const WX={inflight:"in-flight",done:"done",err:"error"};function VX({t:e,onClick:t}){const n=e.endedAt==null?"inflight":e.ok===!1?"err":"done",r=aM(e,"…");return o.jsxs("button",{className:"tool clickable",title:e.inputPreview||e.name,onClick:t,children:[o.jsxs("span",{className:"name",children:[o.jsx("span",{className:`status-dot ${n}`,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:WX[n]}),e.name]}),o.jsx("span",{style:{color:"var(--muted)"},children:r})]})}try{oF(window.localStorage)}catch{}const GX=TO.createRoot(document.getElementById("root"));GX.render(o.jsx(PX,{}));export{oR as S,rX as a,YX as b,Au as c,Bt as d,KX as e,ut as f,so as g,Ps as h,hi as i,o as j,uY as k,jS as p,w as r,Qa as s,pn as u};
|